Otter
Blueprints
Otter
Upstream Blueprint Tested
RPG Combat Starter Blueprint
Connect actor creation, damage calculation, defeat conditions, and rewards.
Architecture & Runtime Preview
Otter >=1.0.1Data flows from enemyInit and attack into game-entity.applyDamage. The remaining health is evaluated by a conditional defeat check, which activates victory reward output when health is at most 0.
- 1Spawn Enemy (pack-call: game-entity.createActor)
- 2Player Attack (input)
- 3Apply Combat Damage (pack-call: game-entity.applyDamage)
- 4Check Defeat Condition (condition)
- 5Grant Victory Reward (output)
Source Code (4 files)
{
"schemaVersion": 1,
"id": "otter-official/game-combat",
"version": "1.0.0",
"title": "RPG Combat Starter",
"summary": "Connect actor creation, damage calculation, defeat conditions, and rewards.",
"targets": ["console", "game"],
"requiresOtter": ">=1.0.1",
"packs": [
{ "id": "otter-official/math-utils", "version": "1.0.1" },
{ "id": "otter-official/game-entity", "version": "1.1.0" }
],
"configuration": [
{
"id": "startingHealth",
"label": "Enemy Starting Health",
"type": "number",
"default": 100,
"minimum": 1,
"description": "Initial health pool of the combat opponent"
},
{
"id": "baseAttackDamage",
"label": "Player Base Attack Damage",
"type": "number",
"default": 35,
"minimum": 1,
"description": "Base damage dealt before defense or level multipliers"
}
],
"nodes": [
{
"id": "enemyInit",
"title": "Spawn Enemy",
"kind": "pack-call",
"capability": "game-entity.createActor",
"inputs": [],
"outputs": [{ "name": "enemy", "type": "object" }],
"description": "Instantiate the opponent entity with starting health"
},
{
"id": "attack",
"title": "Player Attack",
"kind": "input",
"inputs": [],
"outputs": [{ "name": "damage", "type": "number" }],
"description": "Player triggers an attack delivering base damage"
},
{
"id": "applyDamage",
"title": "Apply Combat Damage",
"kind": "pack-call",
"capability": "game-entity.applyDamage",
"inputs": [
{ "name": "actor", "type": "object", "required": true },
{ "name": "amount", "type": "number", "required": true }
],
"outputs": [{ "name": "remainingHealth", "type": "number" }],
"description": "Deduct damage from enemy health and update alive state"
},
{
"id": "defeatCheck",
"title": "Check Defeat Condition",
"kind": "condition",
"inputs": [
{ "name": "health", "type": "number", "required": true }
],
"outputs": [{ "name": "isDefeated", "type": "boolean" }],
"description": "Branch when enemy health drops to or below zero"
},
{
"id": "reward",
"title": "Grant Victory Reward",
"kind": "output",
"inputs": [
{ "name": "isDefeated", "type": "boolean", "required": true }
],
"outputs": [],
"description": "Display battle outcome and grant experience points"
}
],
"edges": [
{ "from": "enemyInit.enemy", "to": "applyDamage.actor", "label": "target" },
{ "from": "attack.damage", "to": "applyDamage.amount", "label": "damage amount" },
{ "from": "applyDamage.remainingHealth", "to": "defeatCheck.health", "label": "remaining hp" },
{ "from": "defeatCheck.isDefeated", "to": "reward.isDefeated", "label": "victory flag" }
],
"generatedFiles": [
{
"path": "src/combat.ot",
"template": "templates/combat.ot.tmpl"
}
],
"explanations": {
"beginner": "This blueprint sets up a game combat fight. It spawns an enemy with 100 health, deals 35 damage with an attack, checks if the enemy was defeated, and prints the result.",
"intermediate": "Data flows from enemyInit and attack into game-entity.applyDamage. The remaining health is evaluated by a conditional defeat check, which activates victory reward output when health is at most 0.",
"advanced": "Composes otter-official/game-entity Actor state and applyDamage pure mutation with otter-official/math-utils. Emits idiomatic relative imports: use \".otter/packages/otter-official/game-entity/src/main.ot\"."
},
"tests": [
"tests/test.ot"
]
}
# Generated by Otter Blueprint: otter-official/game-combat 1.0.0
# Standard editable Otter 1.0.1 source code
use "${import:otter-official/game-entity}"
use "${import:otter-official/math-utils}"
# Step 1: Spawn Opponent
enemyHp is ${startingHealth}
enemy is createActor "Dungeon Goblin" enemyHp 1
say "Enemy encountered:" name of enemy "with" health of enemy "HP"
# Step 2: Player Attack
attackDmg is ${baseAttackDamage}
say "Player attacks for" attackDmg "damage!"
# Step 3: Apply Combat Damage
remHp is applyDamage enemy attackDmg
say name of enemy "remaining HP:" remHp
# Step 4: Check Defeat Condition and Grant Reward
if remHp is at most 0
say "Victory! The enemy has been defeated."
say "Experience awarded: 100 XP"
otherwise
say "The battle continues! Enemy is still standing."
.
# Integration tests for game-combat Blueprint
use "../../../../packs/otter-official/game-entity/src/main.ot"
use "../../../../packs/otter-official/math-utils/src/main.ot"
# Test 1: Spawn Opponent
enemyHp is 100
enemy is createActor "Dungeon Goblin" enemyHp 1
if health of enemy is 100
say "test 1 passed: enemy spawned with configured hp"
.
# Test 2: Apply Damage
attackDmg is 35
remHp is applyDamage enemy attackDmg
if remHp is 65
say "test 2 passed: damage deducted accurately"
.
# Test 3: Defeat condition
fatalDmg is 70
remAfterFatal is applyDamage enemy fatalDmg
if remAfterFatal is 0 and isAlive of enemy is false
say "test 3 passed: defeat condition triggers properly"
.
say "All game-combat tests passed."
# Demo for game-combat Blueprint
use "../../../../packs/otter-official/game-entity/src/main.ot"
use "../../../../packs/otter-official/math-utils/src/main.ot"
say "=== RPG Combat Blueprint Demo ==="
# Step 1: Spawn Opponent
enemyHp is 100
enemy is createActor "Dungeon Goblin" enemyHp 1
say "Enemy encountered:" name of enemy "with" health of enemy "HP"
# Step 2: Player Attack
attackDmg is 35
say "Player attacks for" attackDmg "damage!"
# Step 3: Apply Combat Damage
remHp is applyDamage enemy attackDmg
say name of enemy "remaining HP:" remHp
# Step 4: Check Defeat Condition
if remHp is at most 0
say "Victory! The enemy has been defeated."
otherwise
say "The battle continues! Enemy is still standing."
.
Installation & Usage
otter blueprint explain otter-official/game-combat
otter blueprint apply otter-official/game-combat --project ./my-app
This blueprint sets up a game combat fight. It spawns an enemy with 100 health, deals 35 damage with an attack, checks if the enemy was defeated, and prints the result.