aboutsummaryrefslogtreecommitdiff
path: root/internal/combat/state_test.go
blob: d21bc0d6e7c867e9c0a28cdc3e7d1f6f734cec9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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")
	}
}