feat: checkpoint scripted battle decisions

This commit is contained in:
MaxTomahawk
2026-08-11 08:58:33 +02:00
parent 79ed37699e
commit 882763cfe1
12 changed files with 371 additions and 30 deletions
+25
View File
@@ -3394,6 +3394,7 @@ function OverworldState:showMapText(textConst, npc, onDone)
-- the winning contribution's rows run as their owner (09 §4.4): mod:
-- field routing, strict dispatch and error reports all read the source
self.runner:run(script, { npc = npc, onDone = onDone,
checkpointOnDone = onDone and "release_npc" or nil,
source = mapScripts.talkSource(self.map.id, textConst) })
return
end
@@ -4066,6 +4067,30 @@ function OverworldState:restoreBattleContinuation(battle, origin)
battle.onFinish = function(result) self:afterBattle(result, battle) end
return true
end
if origin.kind == "script_battle" then
if origin.battleKind ~= battle.kind
or (battle.kind == "trainer" and (origin.trainerClass ~= battle.oppClass
or origin.partyIndex ~= (battle.partyIndex or 1)))
or type(origin.script) ~= "table" or type(origin.pc) ~= "number" then
return false
end
local npc = origin.npcId and self.npcPool and self.npcPool[origin.npcId] or nil
if origin.npcId and not npc then return false end
battle.onFinish = function(result)
local runner = self.runner
if not runner or runner:isRunning() then
runner = ScriptRunner.new(game, self)
self.runner = runner
end
runner:run(origin.script, {
npc = npc,
source = origin.source,
resumeBattle = { result = result, battle = battle },
}, origin.pc)
end
battle.checkpointScriptContinuation = true
return true
end
if origin.kind ~= "trainer_encounter" or battle.kind ~= "trainer"
or origin.trainerClass ~= battle.oppClass
or origin.partyIndex ~= (battle.partyIndex or 1)