diff options
Diffstat (limited to 'internal/world/world.go')
| -rw-r--r-- | internal/world/world.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/internal/world/world.go b/internal/world/world.go index cb53b77..7a91894 100644 --- a/internal/world/world.go +++ b/internal/world/world.go @@ -3,6 +3,7 @@ package world import ( "fmt" "log" + "math" "os" "path/filepath" "strconv" @@ -120,7 +121,7 @@ func (w *World) SeedGroundItems(roomID int) { e.quantity += s.Quantity e.respawnQty += s.Quantity e.isSpawn = true - e.respawnDelay = int(s.RespawnTicks) + e.respawnDelay = spawnRespawnDelay(s.RespawnTicks) merged = true break } @@ -130,7 +131,7 @@ func (w *World) SeedGroundItems(roomID int) { itemID: s.ID, quantity: s.Quantity, isSpawn: true, - respawnDelay: int(s.RespawnTicks), + respawnDelay: spawnRespawnDelay(s.RespawnTicks), respawnQty: s.Quantity, } w.groundItems[roomID] = append(w.groundItems[roomID], e) @@ -138,6 +139,20 @@ func (w *World) SeedGroundItems(roomID int) { } } +// spawnRespawnDelay converts a fractional respawn_ticks value to whole ticks. +// Truncating (the old int(v)) turned any 0 < v < 1 into a one-shot spawn that +// never returned; round instead and floor a positive value at one tick. +func spawnRespawnDelay(ticks float64) int { + if ticks <= 0 { + return 0 + } + delay := int(math.Round(ticks)) + if delay < 1 { + delay = 1 + } + return delay +} + func (w *World) RoomIndex() map[int]bool { w.mu.Lock() defer w.mu.Unlock() @@ -255,6 +270,9 @@ func (w *World) RekeyRooms(idMap map[int]int) { // from the renamed room (and TickObjWander then creates a second // entry for the same state). Remap wander rooms like MobStore does. m.st.RoomID = m.newID + if mapped, ok := idMap[m.st.HomeRoomID]; ok && mapped != m.st.HomeRoomID { + m.st.HomeRoomID = mapped + } for i, room := range m.st.WanderRooms { if mapped, ok := idMap[room]; ok && mapped != room { m.st.WanderRooms[i] = mapped |
