diff options
Diffstat (limited to 'internal/world/world.go')
| -rw-r--r-- | internal/world/world.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/internal/world/world.go b/internal/world/world.go index 6a0313d..7475ce0 100644 --- a/internal/world/world.go +++ b/internal/world/world.go @@ -217,6 +217,7 @@ func (w *World) RekeyRooms(idMap map[int]int) { type objKeyMove struct { oldKey, newKey string st *ObjState + newID int } var moves []objKeyMove for k, st := range w.objStates { @@ -233,12 +234,23 @@ func (w *World) RekeyRooms(idMap map[int]int) { continue } newKey := fmt.Sprintf("%d:%s", newID, k[len(roomStr)+1:]) - moves = append(moves, objKeyMove{k, newKey, st}) + moves = append(moves, objKeyMove{k, newKey, st, newID}) } for _, m := range moves { delete(w.objStates, m.oldKey) } for _, m := range moves { + // Keep the package invariant mapKey == ObjStateKey(st.RoomID, ...): + // object lookups filter on st.RoomID while GetObjState looks up the + // key, so a rekey that leaves RoomID stale makes the object vanish + // 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 + for i, room := range m.st.WanderRooms { + if mapped, ok := idMap[room]; ok && mapped != room { + m.st.WanderRooms[i] = mapped + } + } w.objStates[m.newKey] = m.st } } |
