aboutsummaryrefslogtreecommitdiff
path: root/internal/game/sys_escape_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/sys_escape_test.go')
-rw-r--r--internal/game/sys_escape_test.go38
1 files changed, 17 insertions, 21 deletions
diff --git a/internal/game/sys_escape_test.go b/internal/game/sys_escape_test.go
index fd4c9ab..aff37ae 100644
--- a/internal/game/sys_escape_test.go
+++ b/internal/game/sys_escape_test.go
@@ -1,7 +1,6 @@
package game
import (
- "os"
"testing"
"time"
@@ -29,11 +28,8 @@ func (c *escapeTestConn) SetReadDeadline(time.Time) error { return nil }
func (c *escapeTestConn) Close() error { return nil }
func (c *escapeTestConn) SetEcho(bool) error { return nil }
-func escapeTestGame() *Game {
- tmpDir, err := os.MkdirTemp("", "escape_test")
- if err != nil {
- panic(err)
- }
+func escapeTestGame(t *testing.T) *Game {
+ t.Helper()
dataDir := "../../data"
return &Game{
Combat: combat.NewTracker(),
@@ -44,7 +40,7 @@ func escapeTestGame() *Game {
World: world.New(dataDir),
MobStore: world.NewMobStore(dataDir),
ItemStore: item.NewItemStore(dataDir),
- AccountStore: player.NewAccountStore(tmpDir),
+ AccountStore: player.NewAccountStore(t.TempDir()),
Ticks: engine.New(),
},
}
@@ -84,7 +80,7 @@ func TestClearMoveStateClearsEscape(t *testing.T) {
}
func TestBeginEscapeMoveWithEnergy(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("run")
p.EscapeDir = "north"
p.EscapeTarget = 10
@@ -108,7 +104,7 @@ func TestBeginEscapeMoveWithEnergy(t *testing.T) {
}
func TestBeginEscapeMoveWithoutEnergy(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("walk")
p.RunEnergy = 0
p.EscapeDir = "east"
@@ -126,7 +122,7 @@ func TestBeginEscapeMoveWithoutEnergy(t *testing.T) {
}
func TestBeginEscapeMoveWithCapeOfAgility(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("cape")
p.Equipment[item.SlotBack] = capeOfAgilityID
@@ -140,7 +136,7 @@ func TestBeginEscapeMoveWithCapeOfAgility(t *testing.T) {
}
func TestApplyMobHitCancelsEscape(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("ouch")
p.EscapeDir = "south"
p.EscapeTarget = 3
@@ -172,7 +168,7 @@ func TestApplyMobHitCancelsEscape(t *testing.T) {
}
func TestApplyMobMissFiresEscape(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("lucky")
p.EscapeDir = "east"
p.EscapeTarget = 8
@@ -217,7 +213,7 @@ func TestEscapeReaimSilently(t *testing.T) {
}
func TestDoAttackAbortsFlee(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("attacker")
p.EscapeDir = "west"
p.EscapeTarget = 4
@@ -247,7 +243,7 @@ func TestEscapeClearedOnStop(t *testing.T) {
// TestPlayerActionDisplayNoPreparingToFlee verifies the
// "preparing to flee" display branch has been removed.
func TestPlayerActionDisplayNoPreparingToFlee(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("fleer")
p.EscapeDir = "north"
@@ -261,7 +257,7 @@ func TestPlayerActionDisplayNoPreparingToFlee(t *testing.T) {
// consecutive escape-canceling mob hit in the same combat triggers the flee
// as if the mob had missed, instead of cancelling.
func TestEscapeReliefFiresOnThirdHit(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("relief")
p.HP = 100
p.EscapeDir = "north"
@@ -298,7 +294,7 @@ func TestEscapeReliefFiresOnThirdHit(t *testing.T) {
// TestEscapeReliefDoesNotFireBeforeThirdHit verifies the relief waits until
// the 3rd hit; the 1st and 2nd should still cancel normally.
func TestEscapeReliefDoesNotFireBeforeThirdHit(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("patient")
p.HP = 100
p.EscapeDir = "north"
@@ -343,7 +339,7 @@ func TestEscapeReliefDoesNotFireBeforeThirdHit(t *testing.T) {
// after a successful flee path (miss) — so the next flee attempt in the same
// combat starts fresh at 0.
func TestEscapeFailCountResetsOnSuccessfulMissFlee(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("reclucky")
p.HP = 100
@@ -382,7 +378,7 @@ func TestEscapeFailCountResetsOnSuccessfulMissFlee(t *testing.T) {
// TestEscapeFailCountResetsOnCombatEntry verifies the counter resets when a
// new combat starts (startCombat), so a fresh engagement begins at 0.
func TestEscapeFailCountResetsOnCombatEntry(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("reset")
p.HP = 100
p.EscapeFailCount = 7 // carryover from prior engagement
@@ -404,7 +400,7 @@ func TestEscapeFailCountResetsOnCombatEntry(t *testing.T) {
// TestEscapeReliefSuppressedOnKillingBlow verifies that when the 3rd hit
// would kill the player, the relief is suppressed.
func TestEscapeReliefSuppressedOnKillingBlow(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("doomed")
p.HP = 3 // exactly enough to absorb three maxHit==1 (deterministic) hits
@@ -439,7 +435,7 @@ func TestEscapeReliefSuppressedOnKillingBlow(t *testing.T) {
}
func TestEndCombatFiresEscapeOnMobDeath(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("finisher")
p.EscapeDir = "east"
p.EscapeTarget = 10
@@ -466,7 +462,7 @@ func TestEndCombatFiresEscapeOnMobDeath(t *testing.T) {
}
func TestEndCombatDoesNotFireEscapeIfMobAlive(t *testing.T) {
- g := escapeTestGame()
+ g := escapeTestGame(t)
p := player.New("patient")
p.EscapeDir = "east"
p.EscapeTarget = 10