-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworldboss_test.go
More file actions
103 lines (96 loc) · 3.04 KB
/
Copy pathworldboss_test.go
File metadata and controls
103 lines (96 loc) · 3.04 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package idlerpg
import (
"context"
"strings"
"testing"
)
func TestWorldBossSpawnAndSlay(t *testing.T) {
m, r, st := newMgr()
ctx := context.Background()
m.Handle(chanMsg("alice", "!rpg"))
st.HSet(ctx, sheetKey("net|alice"), "level", 5)
st.HSet(ctx, sheetKey("net|alice"), itemField("weapon"), 100000) // huge contribution → quick kill
m.spawnWorldBoss(ctx, "net", "#chan")
if !r.has("WORLD BOSS rises") {
t.Fatalf("spawn should announce, got %v", r.lines)
}
if bv, _ := ReadWorldBoss(ctx, st); bv == nil || bv.HP <= 0 {
t.Fatal("a raid should exist with positive HP")
}
for i := 0; i < 50; i++ {
m.worldBossTick(ctx)
if bv, _ := ReadWorldBoss(ctx, st); bv == nil {
break // slain and cleared
}
}
if bv, _ := ReadWorldBoss(ctx, st); bv != nil {
t.Fatal("the raid should be slain and cleared")
}
if !r.has("is SLAIN") {
t.Fatalf("victory should announce, got %v", r.lines)
}
if s, _ := st.HGetAll(ctx, sheetKey("net|alice")); s["gold"] <= 0 || s["kills"] < 1 {
t.Fatalf("a participant should be rewarded, sheet=%v", s)
}
}
func TestWorldBossDeparts(t *testing.T) {
m, r, st := newMgr()
ctx := context.Background()
m.Handle(chanMsg("alice", "!rpg"))
m.spawnWorldBoss(ctx, "net", "#chan")
m.bmu.Lock()
m.boss.Deadline = m.now().Unix() - 1 // already expired
m.bmu.Unlock()
m.worldBossTick(ctx)
if !r.has("departs unbroken") {
t.Fatalf("an expired raid should depart, got %v", r.lines)
}
if bv, _ := ReadWorldBoss(ctx, st); bv != nil {
t.Fatal("a departed raid should be cleared")
}
}
func TestRaidAdminSummons(t *testing.T) {
m, r, _ := newMgr()
m.SetAuthz(allowAll)
m.Handle(chanMsg("alice", "!rpg")) // someone online to scale against
m.Handle(chanMsg("boss", "!rpg raid"))
if !r.has("WORLD BOSS rises") {
t.Fatalf("admin raid should summon a world boss, got %v", r.lines)
}
// a second summon is refused while one is active
m.Handle(chanMsg("boss", "!rpg raid"))
if !r.has("already stalks the realm") {
t.Fatalf("double raid should be refused, got %q", r.last())
}
}
func TestInfoShowsWorldBoss(t *testing.T) {
m, _, _ := newMgr()
m.Handle(chanMsg("alice", "!rpg"))
if got := m.info(); strings.Contains(got, "WORLD BOSS") {
t.Fatalf("no raid yet, info should not mention one: %q", got)
}
m.spawnWorldBoss(context.Background(), "net", "#chan")
if got := m.info(); !strings.Contains(got, "WORLD BOSS") {
t.Fatalf("active raid should show in info, got %q", got)
}
}
func TestWorldBossTracksTopDamager(t *testing.T) {
m, r, st := newMgr()
ctx := context.Background()
m.Handle(chanMsg("alice", "!rpg"))
m.Handle(chanMsg("bob", "!rpg"))
// alice hits far harder than bob
st.HSet(ctx, sheetKey("net|alice"), itemField("weapon"), 100000)
st.HSet(ctx, sheetKey("net|alice"), "ttl", 100000)
st.HSet(ctx, sheetKey("net|bob"), "ttl", 100000)
m.spawnWorldBoss(ctx, "net", "#chan")
for i := 0; i < 50; i++ {
m.worldBossTick(ctx)
if bv, _ := ReadWorldBoss(ctx, st); bv == nil {
break
}
}
if !r.has("struck the hardest") || !r.has("alice") {
t.Fatalf("victory should crown the top damager (alice), got %v", r.lines)
}
}