diff --git a/modules/client/client.lua b/modules/client/client.lua index ca7725a8..d0d5a078 100644 --- a/modules/client/client.lua +++ b/modules/client/client.lua @@ -1,7 +1,7 @@ Client = {} function Client.reloadScripts() - dofile 'otclientrc.lua' + dofile '/otclientrc' reloadModules() TextMessage.displayEventAdvance('All modules and scripts were reloaded.') print('All modules and scripts were reloaded.') diff --git a/modules/client_entergame/characterlist.lua b/modules/client_entergame/characterlist.lua index d867cf35..7904e89e 100644 --- a/modules/client_entergame/characterlist.lua +++ b/modules/client_entergame/characterlist.lua @@ -4,6 +4,7 @@ CharacterList = { } local charactersWindow local loadBox local characterList +local errorBox -- private functions local function onCharactersWindowKeyPress(self, keyCode, keyboardModifiers) @@ -54,14 +55,20 @@ end function onGameLoginError(message) CharacterList.destroyLoadBox() - local errorBox = displayErrorBox("Login Error", "Login error: " .. message) - errorBox.onOk = CharacterList.showAgain + errorBox = displayErrorBox("Login Error", "Login error: " .. message) + errorBox.onOk = function() + errorBox = nil + CharacterList.showAgain() + end end function onGameConnectionError(message) CharacterList.destroyLoadBox() - local errorBox = displayErrorBox("Login Error", "Connection error: " .. message) - errorBox.onOk = CharacterList.showAgain + errorBox = displayErrorBox("Login Error", "Connection error: " .. message) + errorBox.onOk = function() + errorBox = nil + CharacterList.showAgain() + end end -- public functions @@ -137,7 +144,7 @@ function CharacterList.destroy() end function CharacterList.show() - if not loadBox then + if not loadBox and not errorBox then charactersWindow:show() charactersWindow:raise() charactersWindow:focus() diff --git a/src/framework/graphics/animatedtexture.cpp b/src/framework/graphics/animatedtexture.cpp index de972762..2f27d96b 100644 --- a/src/framework/graphics/animatedtexture.cpp +++ b/src/framework/graphics/animatedtexture.cpp @@ -70,6 +70,6 @@ void AnimatedTexture::processAnimation() AnimatedTexturePtr self = asAnimatedTexture(); // continue to animate only if something still referencing this texture - if(self.use_count() > 2) + if(self.use_count() > 1) g_eventDispatcher.scheduleEvent(std::bind(&AnimatedTexture::processAnimation, self), m_framesDelay[m_currentFrame]); } diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index fe08268a..64eecd4e 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -55,6 +55,7 @@ Creature::Creature() : Thing() m_emblem = Otc::EmblemNone; m_shieldBlink = false; m_showShieldTexture = true; + m_removed = false; m_informationFont = g_fonts.getFont("verdana-11px-rounded"); } diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index 329983bd..1d7ad994 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -59,6 +59,7 @@ public: void setShieldTexture(const std::string& filename, bool blink); void setEmblemTexture(const std::string& filename); void setPassable(bool passable) { m_passable = passable; } + void setRemoved(bool removed) { m_removed = removed; } void addTimedSquare(uint8 color); void removeTimedSquare() { m_showTimedSquare = false; } @@ -88,6 +89,7 @@ public: virtual void stopWalk(); bool isWalking() { return m_walking; } + bool isRemoved() { return m_removed; } CreaturePtr asCreature() { return std::static_pointer_cast(shared_from_this()); } @@ -120,6 +122,7 @@ protected: Color m_staticSquareColor; bool m_showTimedSquare; bool m_showStaticSquare; + bool m_removed; FontPtr m_informationFont; Color m_informationColor; diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 0a98bb8e..abf8aac9 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -115,6 +115,9 @@ void Game::processGameEnd() // reset game state resetGameStates(); + + // clean map creatures + g_map.cleanDynamicThings(); } void Game::processLogin() @@ -336,7 +339,7 @@ void Game::forceLogout() if(!isOnline()) return; - //m_protocolGame->sendLogout(); + m_protocolGame->sendLogout(); processDisconnect(); } diff --git a/src/otclient/core/map.cpp b/src/otclient/core/map.cpp index ef30cc65..4c8d04b1 100644 --- a/src/otclient/core/map.cpp +++ b/src/otclient/core/map.cpp @@ -109,8 +109,18 @@ void Map::save() void Map::clean() { + cleanDynamicThings(); m_tiles.clear(); - m_knownCreatures.clear(); +} + +void Map::cleanDynamicThings() +{ + for(const auto& pair : m_knownCreatures) { + const CreaturePtr& creature = pair.second; + removeThing(creature); + creature->setRemoved(true); + } + for(int i=0;i<=Otc::MAX_Z;++i) m_floorMissiles[i].clear(); m_animatedTexts.clear(); @@ -261,12 +271,14 @@ void Map::removeCreatureById(uint32 id) { if(id == 0) return; + if(CreaturePtr creature = m_knownCreatures[id]) + creature->setRemoved(true); m_knownCreatures.erase(id); } void Map::setCentralPosition(const Position& centralPosition) { - bool teleported = !m_centralPosition.isInRange(centralPosition, 1,1); + bool teleported = !m_centralPosition.isInRange(centralPosition, 1, 1); m_centralPosition = centralPosition; // remove all creatures when teleporting, the server will resend them again diff --git a/src/otclient/core/map.h b/src/otclient/core/map.h index a403fc0d..a0940501 100644 --- a/src/otclient/core/map.h +++ b/src/otclient/core/map.h @@ -37,6 +37,7 @@ public: void load(); void save(); void clean(); + void cleanDynamicThings(); // thing related void addThing(const ThingPtr& thing, const Position& pos, int stackPos = -1); diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index e26abb3e..e63c7b72 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -100,6 +100,8 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags) if(drawFlags & Otc::DrawCreatures) { if(animate) { for(const CreaturePtr& creature : m_walkingCreatures) { + if(creature->isRemoved()) + continue; creature->draw(Point(dest.x + ((creature->getPosition().x - m_position.x)*Otc::TILE_PIXELS - m_drawElevation)*scaleFactor, dest.y + ((creature->getPosition().y - m_position.y)*Otc::TILE_PIXELS - m_drawElevation)*scaleFactor), scaleFactor, animate);