diff options
| author | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
| commit | 9666676766bf21364f4fc4d0d1d336e72f2a91b4 (patch) | |
| tree | 0cade34091d7602790dc38cd44053f0b74bbadf2 /internal/world/mob.go | |
| parent | 4bc1daaf259e0c19c5fe4a12ec8bc7f6e5a735c1 (diff) | |
| download | thehouseoficarus-9666676766bf21364f4fc4d0d1d336e72f2a91b4.tar.gz | |
refactor: split casino.go, dedup helpers, remove audit docs
Diffstat (limited to 'internal/world/mob.go')
| -rw-r--r-- | internal/world/mob.go | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/internal/world/mob.go b/internal/world/mob.go index 4441108..10759f8 100644 --- a/internal/world/mob.go +++ b/internal/world/mob.go @@ -241,6 +241,9 @@ func NewMobInstance(def *MobDef, instanceID string, roomID int, wanderRooms []in if def.Combat != nil { aggressive = def.Combat.Aggressive respawnTicks = def.Combat.RespawnTicks + if respawnTicks <= 0 { + respawnTicks = 30 + } attackType = append([]string(nil), def.Combat.AttackTypes...) cs := def.Combat.Stats @@ -723,12 +726,20 @@ func (s *MobStore) SeedMobs(roomID int, entries []RoomMob) { s.mu.Lock() defer s.mu.Unlock() - for i, dw := range defs { + // Instance keys use a per-defID occurrence counter, not the slice index: + // reordering a room's mobs: list must not orphan the old instances and + // spawn duplicates. Two entries of the same defID get suffixes 0 and 1. + declared := make(map[string]bool, len(entries)) + occurrence := make(map[string]int) + for _, dw := range defs { + defID := dw.rm.ID + n := occurrence[defID] + occurrence[defID]++ + instID := fmt.Sprintf("%s_%d_%d", defID, roomID, n) + declared[instID] = true if dw.err != nil { continue } - defID := dw.rm.ID - instID := fmt.Sprintf("%s_%d_%d", defID, roomID, i) if _, exists := s.instances[instID]; exists { continue } @@ -736,6 +747,15 @@ func (s *MobStore) SeedMobs(roomID int, entries []RoomMob) { inst.IdleDescription = pickIdleDescription(dw.def.IdleDescriptions) s.instances[instID] = inst } + // Drop seeded instances this room no longer declares. Trigger-spawned and + // wandered-away instances are never pruned here: a declared mob that has + // wandered keeps its deterministic key, and transient mobs are owned by + // the trigger system. + for id, inst := range s.instances { + if inst.HomeRoomID == roomID && !inst.SpawnedByTrigger && !declared[id] { + delete(s.instances, id) + } + } } // RekeyRooms remaps every live mob instance's RoomID and HomeRoomID per |
