aboutsummaryrefslogtreecommitdiff
path: root/internal/game/sys_triggers.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/sys_triggers.go')
-rw-r--r--internal/game/sys_triggers.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/internal/game/sys_triggers.go b/internal/game/sys_triggers.go
index 312fe50..8bba630 100644
--- a/internal/game/sys_triggers.go
+++ b/internal/game/sys_triggers.go
@@ -151,6 +151,7 @@ func (g *Game) advanceSequence(seq *sequence) {
if len(seq.steps) == 0 {
g.completePlayerSequence(seq, p)
}
+ g.syncPendingSequence(seq, p)
return
}
@@ -172,6 +173,7 @@ func (g *Game) advanceSequence(seq *sequence) {
if len(seq.steps) == 0 {
g.completePlayerSequence(seq, p)
}
+ g.syncPendingSequence(seq, p)
return
}
@@ -220,6 +222,22 @@ func (g *Game) completePlayerSequence(seq *sequence, p *player.Player) {
}
}
+// syncPendingSequence keeps a locked sequence's persisted snapshot in step
+// with the live sequence as it advances, so a crash before the next clean
+// disconnect/shutdown cannot replay already-fired steps (and re-grant their
+// rewards) on reconnect. It is a no-op for unlocked/completed sequences.
+func (g *Game) syncPendingSequence(seq *sequence, p *player.Player) {
+ if p == nil || !seq.locked || p.PendingSequence == nil || p.PendingSequence.Key != seq.key {
+ return
+ }
+ if len(seq.steps) == 0 {
+ return
+ }
+ p.PendingSequence.Steps = append([]behavior.Step(nil), seq.steps...)
+ p.PendingSequence.Wait = seq.wait
+ g.saveCharacter(p)
+}
+
func (g *Game) completeGlobalSequence(seq *sequence) {
g.removeSequence(seq)
}