aboutsummaryrefslogtreecommitdiff
path: root/internal/game/sys_combat.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-07-17 19:54:21 -0400
committerhistoria <[not public]>2026-07-17 19:54:21 -0400
commitc23c87b56fd568956d263bb8b8c5d26fbd8d01ee (patch)
tree58737f94d5417e11a7d94b2a250d28ae05a25c58 /internal/game/sys_combat.go
parentd553a976dd2f899e28dc8e023ee4ca2eb8951c38 (diff)
downloadthehouseoficarus-c23c87b56fd568956d263bb8b8c5d26fbd8d01ee.tar.gz
feat: add test for mob aggro
Diffstat (limited to 'internal/game/sys_combat.go')
-rw-r--r--internal/game/sys_combat.go19
1 files changed, 5 insertions, 14 deletions
diff --git a/internal/game/sys_combat.go b/internal/game/sys_combat.go
index e23d94b..e05cfed 100644
--- a/internal/game/sys_combat.go
+++ b/internal/game/sys_combat.go
@@ -68,14 +68,12 @@ func (g *Game) dropItemsOnDeath(p *player.Player) {
}
}
-// aggroChancePerTick is the probability per engine tick that an aggressive mob
-// in the player's room initiates combat against them. The first roll happens
-// inline on arrival (so a player who enters and immediately moves again — the
-// 1-tick single-move case — still risks being caught ~33% of the time); if the
-// initial roll fails, a per-tick retry subscriber keeps rolling for any
-// subsequent tick the player lingers in the room.
+// aggroChancePerTick is the probability per engine tick that an aggressive
+// mob in the player's room initiates combat.
const aggroChancePerTick = 0.33
+var rollAggroRand = rand.Float64
+
func (g *Game) checkAggro(sess *net.Session) {
p := sess.Player
@@ -106,13 +104,6 @@ func (g *Game) checkAggro(sess *net.Session) {
}
aggMob := mob
- // rollAggro attempts to start combat this instant. It returns true
- // when aggro should stop retrying that mob for this player — either
- // because it succeeded, because the mob/player is no longer eligible,
- // or because the roll failed and the caller subscribed a per-tick
- // retry. The retry subscriber returns the negation of the inline
- // call's "stop" so it stays subscribed only while the player is
- // still a valid target the roll hasn't yet hit.
rollAggro := func() (stop bool) {
if g.Combat.Get(p.Name) != nil {
return true
@@ -123,7 +114,7 @@ func (g *Game) checkAggro(sess *net.Session) {
if g.Combat.IsMobInCombat(aggMob.InstanceID) {
return true
}
- if rand.Float64() >= aggroChancePerTick {
+ if rollAggroRand() >= aggroChancePerTick {
return false
}
attacker := aggMob.Name