feat(scripting): Phase 2 (onTick/onDeath) + Phase 3 (usable items) #203
No reviewers
Labels
No labels
alpha:wave-0
alpha:wave-1
alpha:wave-2
alpha:wave-3
area:assets
area:combat
area:ecology
area:infra
area:render
area:scripting
area:ui
area:world
enhancement
epic
migration
post-alpha
roadmap
tech-debt
type:bug
type:chore
type:design
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
marco/IsoMmo!203
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/scripting-phase2-3"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Phase 2 (#195) + Phase 3 (#196) on top of the Lua scripting layer (#193): scripted creatures now act on their own and react to death, and usable items (potions/scrolls) are content.
mobile{}can declareonTick(npc)— a periodic "think" the engine fires onGameOptions.ScriptTickCadence(~3s), so an NPC does things without being clicked. The rat now chatters ambiently.onDeath(npc, killer, x, y)fires as a scripted creature dies, with who slew it + where it fell — reward the killer, drop loot. The rat drops a coin on death.item{}). A non-weapon item isitem{ kind, graphic, …, onUse = function(user) … end }, dropped into the existing use pipeline (backpack items are now usable). A Lua potion (Items.Consumables.Potion) heals on use.heal(mobile, n)(+ a Healed floaty) andspawnItem(kind, x, y)(loot).Itemhandle added;Playeris now aMobilein the generatedapi.d.lua.Deferred (noted in #197 / the issues):
onEnterTile(needs spatial indexing),onQuestStep(built from flags), one-shotscheduletimers (onTick covers the periodic case), consuming a potion on use.Invariants Check (delta)
healvia the intrinsic clamp setter;spawnItemrejects off-map/unknown kind); triggers dispatch committed content, never client input.TickResult.Deathslist (the accepted per-tick event pattern);Worldstays scripting-unaware. Handlers are instruction-budgeted + isolated (a bad handler never tears down the tick).MobileSaid,Healed,ItemSpawned); no new wire shape.SystemMessageId.RatSniffs+Messages.Creatures.RatSniffs(typed).ScriptTriggervalues + one emission site;item{}auto-discovered; no switch.healviaMobile.Heal; onTick cadence a field on the creature (LastThinkTick), not a side dict.[ScriptHandler]on the def) somobile.onUse(npc,player)anditem.onUse(user)get correct signatures;api.d.luaregenerated (drift-check green); host validates against the same model.✗.Screenshots / recording
Captured via the debug harness from a fresh DB.
onTick — the rat chatters on its own (heartbeat), no interaction:
The Lua potion (
item{}), placed in the world (+ the rat's ambient chatter):The heal floaty (drinking the potion) and onDeath loot are covered by integration/unit tests below — capturing the heal floaty via the harness needs damaging the player through GM targeting, which is fragile to drive blind, so it's asserted in an integration test instead of screenshotted.
How it was tested
IsoMmo.Scripting, fake context): onTick routing; onDeath receives(npc, killer, x, y)and canspawnItem; itemonUsecanheal(user, …); per-registration handler signatures + theapi.d.luadrift-check.World):healraises Hits + buffers aHealedfloaty to AoI observers;spawnItemrejects off-map and drops a ground item on-map.Use(Healed 15); a scripted NPC chatters on its heartbeat (RatSniffsdelivered to a nearby player).just lint(CSharpier + build, zero warnings), whole-solution build,dotnet testall green (543),lua-lint(luacheck + lua-language-server) clean,check-docsclean.Checklist
just lintpasses (zero warnings)just testis green (543)