diff options
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 |
