Skip to content

Commit

Permalink
fix: update monster name on "Monster:setType"
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Jan 15, 2025
1 parent cb1e3d5 commit 120f57a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10066,6 +10066,19 @@ void Game::removeMonster(const std::shared_ptr<Monster> &monster) {
}
}

void Game::updateMonster(const std::shared_ptr<Monster> &monster, const std::string &oldName, uint32_t oldId) {
if (!monster) {
return;
}

const auto &newName = monster->getLowerName();
monstersNameIndex.erase(oldName);
monstersNameIndex[newName] = monsters.size() - 1;

monstersIdIndex.erase(oldId);
monstersIdIndex[monster->getID()] = monsters.size() - 1;
}

std::shared_ptr<Guild> Game::getGuild(uint32_t id, bool allowOffline /* = flase */) const {
auto it = guilds.find(id);
if (it == guilds.end()) {
Expand Down
1 change: 1 addition & 0 deletions src/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ class Game {

void addMonster(const std::shared_ptr<Monster> &monster);
void removeMonster(const std::shared_ptr<Monster> &monster);
void updateMonster(const std::shared_ptr<Monster> &monster, const std::string &oldName, uint32_t oldId);

std::shared_ptr<Guild> getGuild(uint32_t id, bool allowOffline = false) const;
std::shared_ptr<Guild> getGuildByName(const std::string &name, bool allowOffline = false) const;
Expand Down
6 changes: 6 additions & 0 deletions src/lua/functions/creatures/monster/monster_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ int MonsterFunctions::luaMonsterSetType(lua_State* L) {
g_logger().warn("[Warning - MonsterFunctions::luaMonsterSetType] Unknown event name: {}", scriptName);
}
}

// Update created monster
const std::string oldName = monster->getLowerName();
uint32_t oldId = monster->getID();
g_game().updateMonster(monster, oldName, oldId);

// Assign new MonsterType
monster->mType = mType;
monster->nameDescription = asLowerCaseString(mType->nameDescription);
Expand Down

0 comments on commit 120f57a

Please sign in to comment.