From c23c87b56fd568956d263bb8b8c5d26fbd8d01ee Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Fri, 17 Jul 2026 19:54:21 -0400 Subject: feat: add test for mob aggro --- internal/game/sys_combat.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'internal/game/sys_combat.go') 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 -- cgit v1.2.3