diff --git a/game/engines/default/engine/Level.lua b/game/engines/default/engine/Level.lua index 5f319611a432f6c4594143fdd64dc98f051aaec6..d0ee99eb87992e2311a1ebba2712790a51137788 100644 --- a/game/engines/default/engine/Level.lua +++ b/game/engines/default/engine/Level.lua @@ -98,7 +98,7 @@ function _M:addEntity(e, after) end --- Removes an entity from the level -function _M:removeEntity(e) +function _M:removeEntity(e, force) if e._fake_level_entity then -- Tells it to delete itself if needed if e.deleteFromMap then e:deleteFromMap(self.map) end @@ -107,7 +107,7 @@ function _M:removeEntity(e) return end - if not self.entities[e.uid] then error("Entity "..e.uid.."("..e.name..") not present on the level") end + if not self.entities[e.uid] and not force then error("Entity "..e.uid.."("..e.name..") not present on the level") end self.entities[e.uid] = nil for i = 1, #self.e_array do if self.e_array[i] == e then diff --git a/game/modules/tome/data/zones/eidolon-plane/zone.lua b/game/modules/tome/data/zones/eidolon-plane/zone.lua index af16cf665d01d531f932f6926318d9035e0cc9c6..7b036155e71e7e36c5bcaee961f5fb61c4c8827d 100644 --- a/game/modules/tome/data/zones/eidolon-plane/zone.lua +++ b/game/modules/tome/data/zones/eidolon-plane/zone.lua @@ -75,6 +75,24 @@ return { who:addObject(who.INVEN_INVEN, o) end, + on_turn = function() + local eidolon = nil + for uid, e in pairs(game.level.entities) do + if e.define_as == "EIDOLON" then eidolon = e end + end + if not eidolon then + eidolon = game.zone:makeEntityByName(game.level, "actor", "EIDOLON") + local x, y = util.findFreeGrid(game.player.x, game.player.y, 10, true, {[engine.Map.ACTOR] = true}) + if x and y then game.zone:addEntity(game.level, eidolon, "actor", x, y) end + elseif not eidolon.x or game.level.map(eidolon.x, eidolon.y, engine.Map.ACTOR) ~= eidolon then + eidolon.deleteFromMap = false + game.level:removeEntity(eidolon, true) + local x, y = util.findFreeGrid(game.player.x, game.player.y, 10, true, {[engine.Map.ACTOR] = true}) + if x and y then game.zone:addEntity(game.level, eidolon, "actor", x, y) end + eidolon.deleteFromMap = nil + end + end, + eidolon_exit = function(to_worldmap) game:onTickEnd(function() local oldzone = game.zone