Otter
Recipes
Otter
Upstream Recipe Tested
RPG Adventure Game Engine Recipe
Complete RPG adventure featuring combat with ability cooldowns, inventory equipment, enemy loot drops, and experience progression.
Architecture & Runtime Preview
Otter >=1.0.1Composes `otter-official/game-entity` actors, inventory, and cooldown systems with `otter-official/math-utils`. Evaluates turn damage including equipment bonuses, manages skill readiness via timestamp differences, and levels up upon defeating the enemy.
- 1spawn-entities: Initialize player hero and enemy boss actors (otter-official/game-entity)
- 2resolve-combat-loop: Execute attack sequence applying equipment bonuses and ability cooldowns (otter-official/game-entity)
- 3award-loot-and-exp: Grant loot drop into inventory and level up hero upon victory (otter-official/game-entity)
Source Code (4 files)
{
"schemaVersion": 1,
"id": "otter-official/rpg-adventure",
"version": "1.0.0",
"title": "RPG Adventure Game Engine",
"summary": "Complete RPG adventure featuring combat with ability cooldowns, inventory equipment, enemy loot drops, and experience progression.",
"target": "console",
"requiresOtter": ">=1.0.1",
"capabilities": ["game", "files"],
"packs": [
{ "id": "otter-official/game-entity", "version": "1.1.0" },
{ "id": "otter-official/math-utils", "version": "1.0.1" },
{ "id": "otter-official/file-helpers", "version": "1.0.1" }
],
"blueprints": [
{ "id": "otter-official/game-combat", "version": "1.0.0" }
],
"configuration": [
{ "id": "heroName", "title": "Hero Name", "type": "text", "default": "Aria", "description": "Name of the playable hero" },
{ "id": "enemyName", "title": "Boss Opponent Name", "type": "text", "default": "Dungeon Dragon", "description": "Name of the boss monster" },
{ "id": "startingEnemyHp", "title": "Enemy Starting Health", "type": "number", "default": 120, "description": "Starting health of the boss opponent" }
],
"steps": [
{
"id": "spawn-entities",
"kind": "pack-call",
"description": "Initialize player hero and enemy boss actors",
"source": "otter-official/game-entity",
"inputs": [{ "name": "name", "type": "text" }, { "name": "hp", "type": "number" }, { "name": "lvl", "type": "number" }],
"outputs": [{ "name": "actor", "type": "object" }]
},
{
"id": "resolve-combat-loop",
"kind": "pack-call",
"description": "Execute attack sequence applying equipment bonuses and ability cooldowns",
"source": "otter-official/game-entity",
"inputs": [{ "name": "enemy", "type": "object" }, { "name": "damage", "type": "number" }],
"outputs": [{ "name": "remainingHp", "type": "number" }]
},
{
"id": "award-loot-and-exp",
"kind": "pack-call",
"description": "Grant loot drop into inventory and level up hero upon victory",
"source": "otter-official/game-entity",
"inputs": [{ "name": "hero", "type": "object" }, { "name": "xp", "type": "number" }],
"outputs": [{ "name": "newLevel", "type": "number" }]
}
],
"generatedFiles": [
{ "path": "src/game.ot", "template": "templates/game.ot.tmpl" }
],
"tests": [
"tests/test.ot"
],
"explanations": {
"beginner": "This application creates an RPG battle game. Your hero fights monsters using special abilities with cooldowns, collects weapons into an inventory, equips items for extra power, and levels up when enemies are defeated.",
"intermediate": "Composes `otter-official/game-entity` actors, inventory, and cooldown systems with `otter-official/math-utils`. Evaluates turn damage including equipment bonuses, manages skill readiness via timestamp differences, and levels up upon defeating the enemy.",
"advanced": "Architected as a composable RPG engine. Blueprints provide the base combat math while recipe orchestration adds weapon equipment slots, loot tables, ability cooldown timers, and serialized save states via `file-helpers`."
}
}
# ==============================================================================
# Generated by Otter Application Recipe: rpg-adventure 1.0.0
# Target: Complete RPG Game Engine with Combat, Inventory, Cooldowns & XP
# ==============================================================================
use "${import:otter-official/game-entity}"
use "${import:otter-official/math-utils}"
use "${import:otter-official/file-helpers}"
# 1. Initialize Hero and Inventory
hero is createActor "${config:heroName}" 100 1
bag is createInventory 8
starterSword is createItem "Iron Broadsword" "weapon" 15
addItemToInventory bag starterSword
potion is createItem "Health Elixir" "consumable" 25
addItemToInventory bag potion
say "=== RPG Adventure ==="
say "Hero:"
say name of hero
say "Level:"
say level of hero
say "Health:"
say health of hero
# 2. Setup Ability Cooldown
meteorSkill is createCooldown "Meteor Strike" 10
battleTime is 100
# 3. Spawn Boss Opponent
enemy is createActor "${config:enemyName}" ${config:startingEnemyHp} 3
say "A wild monster appears:"
say name of enemy
say "Enemy HP:"
say health of enemy
# 4. Turn 1: Special Ability Check & Execution
canCast is isCooldownReady meteorSkill battleTime
if canCast is true
triggerCooldown meteorSkill battleTime
spellDmg is 50
say "Hero casts Meteor Strike for damage:"
say spellDmg
remHp is applyDamage enemy spellDmg
say "Enemy HP after spell:"
say remHp
.
# 5. Turn 2: Weapon Strike with Equipment Bonus
baseAttack is 25
weaponBonus is itemPower of starterSword
totalAttack is baseAttack plus weaponBonus
say "Hero strikes with weapon for total damage:"
say totalAttack
remHp is applyDamage enemy totalAttack
say "Enemy HP after strike:"
say remHp
# 6. Turn 3: Finishing Blow
finishingDmg is 50
remHp is applyDamage enemy finishingDmg
say "Finishing blow damage:"
say finishingDmg
# 7. Defeat Condition, Loot Reward, and Level Progression
if isAlive of enemy is false
say "VICTORY! Enemy defeated:"
say name of enemy
# Drop loot and add to bag
bossLoot is createItem "Dragon Scale Shield" "armor" 30
addItemToInventory bag bossLoot
say "Loot acquired:"
say itemName of bossLoot
say "Inventory item count:"
say currentCount of bag
# Hero Level Up
newLevel is levelUp hero
say "HERO LEVELED UP! New Level:"
say newLevel
say "New Max Health:"
say maxHealth of hero
.
# 8. Save Game State
a SaveRecord has
heroName
heroLevel
heroHp
invSlots
.
saveRecord is a SaveRecord
heroName of saveRecord is name of hero
heroLevel of saveRecord is level of hero
heroHp of saveRecord is health of hero
invSlots of saveRecord is currentCount of bag
writeJsonObject "rpg_savegame.json" saveRecord
say "Game progress saved to rpg_savegame.json."
say "RPG Adventure loop completed successfully."
# ==============================================================================
# Test: RPG Adventure Game Mechanics
# ==============================================================================
use "../../../../packs/otter-official/game-entity/src/main.ot"
use "../../../../packs/otter-official/math-utils/src/main.ot"
use "../../../../packs/otter-official/file-helpers/src/main.ot"
# Test 1: Actor creation and damage
hero is createActor "Aria" 100 1
enemy is createActor "Goblin Chief" 80 2
if health of hero is not 100
say "FAIL: expected hero hp 100"
.
if isAlive of enemy is not true
say "FAIL: expected enemy alive"
.
# Test 2: Damage application and defeat condition
remHp is applyDamage enemy 50
if remHp is not 30
say "FAIL: expected 30 remaining enemy hp"
.
remHp2 is applyDamage enemy 40
if remHp2 is not 0
say "FAIL: expected 0 hp after fatal damage"
.
if isAlive of enemy is not false
say "FAIL: expected enemy defeated"
.
# Test 3: Ability cooldown timing
skill is createCooldown "Lightning" 5
readyAt0 is isCooldownReady skill 10
if readyAt0 is not true
say "FAIL: expected skill to be ready initially"
.
triggerCooldown skill 10
readyAt12 is isCooldownReady skill 12
if readyAt12 is not false
say "FAIL: expected skill to be on cooldown at +2s"
.
readyAt16 is isCooldownReady skill 16
if readyAt16 is not true
say "FAIL: expected skill ready after 6s (cd=5s)"
.
# Test 4: Inventory management and loot
inv is createInventory 4
sword is createItem "Excalibur" "weapon" 50
shield is createItem "Aegis" "armor" 25
addOk1 is addItemToInventory inv sword
addOk2 is addItemToInventory inv shield
if addOk1 is not true
say "FAIL: expected item 1 added"
.
if currentCount of inv is not 2
say "FAIL: expected 2 inventory items"
.
# Test 5: Hero level up progression
lvlBefore is level of hero
maxHpBefore is maxHealth of hero
newLvl is levelUp hero
if newLvl is not 2
say "FAIL: expected level 2 after levelUp"
.
if maxHealth of hero is not 120
say "FAIL: expected 120 maxHealth after levelUp"
.
# Test 6: Persistence of game state
saveFile is "test_rpg_save.json"
a SaveRecord has
heroLevel
heroHealth
.
saveRecord is a SaveRecord
heroLevel of saveRecord is level of hero
heroHealth of saveRecord is health of hero
writeJsonObject saveFile saveRecord
loadedRecord is readJsonObject saveFile
if heroLevel of loadedRecord is not 2
say "FAIL: expected loaded hero level 2"
.
writeSafe saveFile ""
say "RPG adventure tests passed."
# ==============================================================================
# Demo: RPG Adventure Mechanics
# ==============================================================================
use "../../../../packs/otter-official/game-entity/src/main.ot"
use "../../../../packs/otter-official/math-utils/src/main.ot"
use "../../../../packs/otter-official/file-helpers/src/main.ot"
say "=== RPG Adventure Combat Demo ==="
hero is createActor "Aria" 100 1
boss is createActor "Shadow Knight" 90 2
inv is createInventory 6
starterDagger is createItem "Rune Dagger" "weapon" 20
addItemToInventory inv starterDagger
strikeSkill is createCooldown "Shadow Strike" 8
say "Hero entered the dungeon with:"
say itemName of starterDagger
# Strike 1 with skill
canStrike is isCooldownReady strikeSkill 50
if canStrike is true
triggerCooldown strikeSkill 50
dmg is 45
rem is applyDamage boss dmg
say "Hero executes Shadow Strike! Boss HP remaining:"
say rem
.
# Strike 2 with weapon
wAtk is 25 plus itemPower of starterDagger
rem2 is applyDamage boss wAtk
say "Hero strikes with weapon! Boss HP remaining:"
remClamped is maxVal rem2 0
say remClamped
# Defeat check and reward
if isAlive of boss is false
say "Boss defeated! Granting loot and XP."
loot is createItem "Dark Knight Armor" "armor" 35
addItemToInventory inv loot
say "Acquired:"
say itemName of loot
lvl is levelUp hero
say "Hero reached level:"
say lvl
.
say "RPG adventure demo finished successfully."
Installation & Usage
otter recipe inspect otter-official/rpg-adventure
otter recipe apply otter-official/rpg-adventure --project ./my-app
This application creates an RPG battle game. Your hero fights monsters using special abilities with cooldowns, collects weapons into an inventory, equips items for extra power, and levels up when enemies are defeated.