diff --git a/src/otclient/core/effect.cpp b/src/otclient/core/effect.cpp index 0e15b733..c4736c83 100644 --- a/src/otclient/core/effect.cpp +++ b/src/otclient/core/effect.cpp @@ -17,7 +17,7 @@ void Effect::draw(int x, int y) if(g_platform.getTicks() - m_lastTicks > 75) { const ThingAttributes& attributes = getAttributes(); if(m_animation+1 == attributes.animcount) { - //g_dispatcher.addEvent(std::bind(&Map::removeThing, &g_map, asThing())); + g_dispatcher.addEvent(std::bind(&Map::removeThingByPtr, &g_map, asThing())); m_finished = true; } else diff --git a/src/otclient/core/map.cpp b/src/otclient/core/map.cpp index 929070e3..c305c7ea 100644 --- a/src/otclient/core/map.cpp +++ b/src/otclient/core/map.cpp @@ -56,6 +56,9 @@ void Map::draw(int x, int y) void Map::addThing(ThingPtr thing, uint8 stackpos) { + if(!thing) + return; + TilePtr& tile = m_tiles[thing->getPosition()]; if(!tile) { tile = TilePtr(new Tile()); @@ -82,6 +85,16 @@ void Map::removeThing(const Position& pos, uint8 stackpos) } } +void Map::removeThingByPtr(ThingPtr thing) +{ + if(!thing) + return; + + if(TilePtr& tile = m_tiles[thing->getPosition()]) { + tile->removeThingByPtr(thing); + } +} + void Map::clean() { m_tiles.clear(); diff --git a/src/otclient/core/map.h b/src/otclient/core/map.h index 36bf820d..a2482b0d 100644 --- a/src/otclient/core/map.h +++ b/src/otclient/core/map.h @@ -13,6 +13,7 @@ public: void addThing(ThingPtr thing, uint8 stackpos = 0); ThingPtr getThing(const Position& pos, uint8 stackpos); void removeThing(const Position& pos, uint8 stackpos); + void removeThingByPtr(ThingPtr thing); void clean(); void cleanTile(const Position& pos); diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index 1ae88773..dee7afde 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -99,6 +99,51 @@ void Tile::removeThing(uint8 stackpos) logDebug("Invalid stackpos."); } +void Tile::removeThingByPtr(ThingPtr thing) +{ + // Items + if(thing->asItem()) { + const ThingAttributes& thingAttributes = thing->getAttributes(); + + if(!thingAttributes.alwaysOnTop) { + for(auto it = m_itemsBottom.begin(), end = m_itemsBottom.end(); it != end; ++it) { + if(*it == thing) { + m_itemsBottom.erase(it); + break; + } + } + } + else { + for(auto it = m_itemsTop.begin(), end = m_itemsTop.end(); it != end; ++it) { + if(*it == thing) { + m_itemsTop.erase(it); + break; + } + } + } + } + + // Creatures + else if(thing->asCreature()) { + for(auto it = m_creatures.begin(), end = m_creatures.end(); it != end; ++it) { + if(*it == thing) { + m_creatures.erase(it); + break; + } + } + } + + // Effects + else if(thing->asEffect()) { + for(auto it = m_effects.begin(), end = m_effects.end(); it != end; ++it) { + if(*it == thing) { + m_effects.erase(it); + break; + } + } + } +} + void Tile::clean() { for(const ThingPtr& thing : m_creatures) diff --git a/src/otclient/core/tile.h b/src/otclient/core/tile.h index e2df6552..0127cfda 100644 --- a/src/otclient/core/tile.h +++ b/src/otclient/core/tile.h @@ -14,6 +14,7 @@ public: void addThing(ThingPtr thing, uint8 stackpos); ThingPtr getThing(uint8 stackpos); void removeThing(uint8 stackpos); + void removeThingByPtr(ThingPtr thing); void clean();