Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Game Actor Combat & Damage
Declare RPG entity state and compute clamped damage with death detection.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Game & Simulation). Copy the parameterized template or run the self-contained example.
- 1Category: Game & Simulation
- 2Attribution: Otter Reusable Library (Official)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
a Entity has
name
health
isAlive
.
to takeDamage entity amount
cur is health of entity
newHp is cur minus amount
if newHp is at most 0
health of entity is 0
isAlive of entity is false
return 0
.
health of entity is newHp
return newHp
.
a Entity has
name
health
isAlive
.
to takeDamage entity amount
cur is health of entity
newHp is cur minus amount
if newHp is at most 0
health of entity is 0
isAlive of entity is false
return 0
.
health of entity is newHp
return newHp
.
boss is a Entity
name of boss is "Ancient Dragon"
health of boss is 100
isAlive of boss is true
remHp is takeDamage boss 40
say "Remaining HP:" health of boss
if remHp is not 60
fail with "damage calculation mismatch: expected 60"
.
if health of boss is not 60
fail with "boss health state mismatch: expected 60"
.
fatalHp is takeDamage boss 80
if fatalHp is not 0
fail with "overkill health mismatch: expected 0"
.
if isAlive of boss is not false
fail with "boss alive state mismatch after lethal damage"
.
Installation & Usage
otter snippet inspect game-actor-damage
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.