package combat import "testing" // Regression: re-entering combat must release the previous mob, or that mob // stays "in combat" forever and no other player can attack it. func TestTrackerEnterReleasesPreviousMob(t *testing.T) { tr := NewTracker() tr.Enter("alice", "mobA") tr.Enter("alice", "mobB") if tr.IsMobInCombat("mobA") { t.Fatal("mobA still marked in combat after alice switched targets") } if !tr.IsMobInCombat("mobB") { t.Fatal("mobB not marked in combat") } tr.Leave("alice") if tr.IsMobInCombat("mobB") { t.Fatal("mobB still marked in combat after leave") } } // Regression: two players claiming the same mob must not leave a dangling // combatants entry for the displaced player; otherwise that player's later // Leave deletes the new owner's mobTargets claim and unlocks a live fight. func TestTrackerEnterDisplacesOtherPlayer(t *testing.T) { tr := NewTracker() tr.Enter("alice", "mobA") tr.Enter("bob", "mobA") if !tr.IsMobInCombat("mobA") { t.Fatal("mobA should still be in combat after the second claim") } if tr.MobTarget("mobA") != "bob" { t.Fatalf("mobTarget = %q, want bob", tr.MobTarget("mobA")) } // Alice was displaced; her leave must not unlock Bob's fight. tr.Leave("alice") if !tr.IsMobInCombat("mobA") || tr.MobTarget("mobA") != "bob" { t.Fatal("alice's leave unlocked the mob bob is still fighting") } }