From 62f3615769a392eeac2dec314a2c7048c1ef1fa0 Mon Sep 17 00:00:00 2001 From: MillhioreBT Date: Sun, 8 Oct 2023 10:50:08 -0400 Subject: [PATCH] ayeye --- src/creature.cpp | 6 +++++- src/game.cpp | 15 ++++++++------- src/luascript.cpp | 5 +++++ src/monster.cpp | 2 +- src/spells.cpp | 12 ++++++------ src/spells.h | 2 +- src/talkaction.cpp | 15 ++++++--------- src/talkaction.h | 10 +++++----- 8 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/creature.cpp b/src/creature.cpp index 5b7b2eb..0eac385 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -719,6 +719,10 @@ void Creature::onDeath() if (master) { setMaster(nullptr); + + if (getMonster()) { + decrementReferenceCounter(); + } } if (droppedCorpse) { @@ -808,7 +812,7 @@ void Creature::changeHealth(int32_t healthChange, bool sendHealthChange /* = tru g_game.addCreatureHealth(this); } - if (health <= 0) { + if (isDead()) { g_dispatcher.addTask([id = getID()]() { g_game.executeDeath(id); }); } } diff --git a/src/game.cpp b/src/game.cpp index ed46c22..2ce4133 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -374,7 +374,7 @@ Creature* Game::getCreatureByName(const std::string& s) } auto equalCreatureName = [&](const std::pair& it) { - auto name = it.second->getName(); + auto& name = it.second->getName(); return lowerCaseName.size() == name.size() && std::equal(lowerCaseName.begin(), lowerCaseName.end(), name.begin(), [](char a, char b) { return a == std::tolower(b); }); @@ -1530,7 +1530,7 @@ bool Game::removeMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0* const uint32_t worth = moneyEntry.first / item->getItemCount(); const uint32_t removeCount = std::ceil(money / static_cast(worth)); - addMoney(cylinder, (worth * removeCount) - money, flags); + addMoney(cylinder, static_cast(worth * removeCount) - money, flags); internalRemoveItem(item, removeCount); break; } else { @@ -3399,22 +3399,22 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, s bool Game::playerSaySpell(Player* player, SpeakClasses type, std::string_view text) { - TalkActionResult_t result = g_talkActions->playerSaySpell(player, type, text); - if (result == TALKACTION_BREAK) { + TalkActionResult result = g_talkActions->playerSaySpell(player, type, text); + if (result == TalkActionResult::BREAK) { return true; } std::string words{text}; result = g_spells->playerSaySpell(player, words); - if (result == TALKACTION_BREAK) { + if (result == TalkActionResult::BREAK) { if (!g_config[ConfigKeysBoolean::EMOTE_SPELLS]) { return internalCreatureSay(player, TALKTYPE_SAY, words, false); } else { return internalCreatureSay(player, TALKTYPE_MONSTER_SAY, words, false); } - } else if (result == TALKACTION_FAILED) { + } else if (result == TalkActionResult::FAILED) { return true; } @@ -4569,7 +4569,8 @@ void Game::checkDecay() ReleaseItem(item); } else if (duration < EVENT_DECAYINTERVAL * EVENT_DECAY_BUCKETS) { it = decayItems[bucket].erase(it); - size_t newBucket = (bucket + ((duration + EVENT_DECAYINTERVAL / 2) / 1000)) % EVENT_DECAY_BUCKETS; + size_t newBucket = + (bucket + static_cast((duration + EVENT_DECAYINTERVAL / 2) / 1000)) % EVENT_DECAY_BUCKETS; if (newBucket == bucket) { internalDecayItem(item); ReleaseItem(item); diff --git a/src/luascript.cpp b/src/luascript.cpp index 6fff1a7..6dd4502 100644 --- a/src/luascript.cpp +++ b/src/luascript.cpp @@ -1977,6 +1977,11 @@ void LuaScriptInterface::registerFunctions() registerEnum(DECAYING_TRUE); registerEnum(DECAYING_PENDING); + registerEnum(VARIANT_NUMBER); + registerEnum(VARIANT_POSITION); + registerEnum(VARIANT_TARGETPOSITION); + registerEnum(VARIANT_STRING); + // _G registerGlobalVariable("INDEX_WHEREEVER", INDEX_WHEREEVER); registerGlobalBoolean("VIRTUAL_PARENT", true); diff --git a/src/monster.cpp b/src/monster.cpp index 2c702ef..1fa448c 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -1833,7 +1833,7 @@ void Monster::death(Creature*) for (Creature* summon : summons) { summon->changeHealth(-summon->getHealth()); - summon->removeMaster(); + //summon->removeMaster(); } summons.clear(); diff --git a/src/spells.cpp b/src/spells.cpp index 8eb591f..ad00c92 100644 --- a/src/spells.cpp +++ b/src/spells.cpp @@ -22,7 +22,7 @@ Spells::Spells() { scriptInterface.initState(); } Spells::~Spells() { clear(false); } -TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words) +TalkActionResult Spells::playerSaySpell(Player* player, std::string& words) { std::string str_words = words; @@ -31,7 +31,7 @@ TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words) InstantSpell* instantSpell = getInstantSpell(str_words); if (!instantSpell) { - return TALKACTION_CONTINUE; + return TalkActionResult::CONTINUE; } std::string param; @@ -47,7 +47,7 @@ TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words) if (loc2 == std::string::npos) { loc2 = paramText.length(); } else if (paramText.find_last_not_of(' ') != loc2) { - return TALKACTION_CONTINUE; + return TalkActionResult::CONTINUE; } param = paramText.substr(loc1 + 1, loc2 - loc1 - 1); @@ -57,7 +57,7 @@ TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words) if (loc1 == std::string::npos) { param = paramText; } else { - return TALKACTION_CONTINUE; + return TalkActionResult::CONTINUE; } } } @@ -70,10 +70,10 @@ TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words) words += " \"" + param + "\""; } - return TALKACTION_BREAK; + return TalkActionResult::BREAK; } - return TALKACTION_FAILED; + return TalkActionResult::FAILED; } void Spells::clearMaps(bool fromLua) diff --git a/src/spells.h b/src/spells.h index 38f5b4d..70fdf53 100644 --- a/src/spells.h +++ b/src/spells.h @@ -36,7 +36,7 @@ class Spells final : public BaseEvents InstantSpell* getInstantSpell(std::string_view words); InstantSpell* getInstantSpellByName(std::string_view name); - TalkActionResult_t playerSaySpell(Player* player, std::string& words); + TalkActionResult playerSaySpell(Player* player, std::string& words); static Position getCasterPosition(Creature* creature, Direction dir); std::string_view getScriptBaseName() const override; diff --git a/src/talkaction.cpp b/src/talkaction.cpp index f4134a1..1bbc44d 100644 --- a/src/talkaction.cpp +++ b/src/talkaction.cpp @@ -64,7 +64,7 @@ bool TalkActions::registerLuaEvent(TalkAction* event) return true; } -TalkActionResult_t TalkActions::playerSaySpell(Player* player, SpeakClasses type, std::string_view words) const +TalkActionResult TalkActions::playerSaySpell(Player* player, SpeakClasses type, std::string_view words) const { size_t wordsLength = words.length(); for (auto it = talkActions.begin(); it != talkActions.end();) { @@ -97,23 +97,20 @@ TalkActionResult_t TalkActions::playerSaySpell(Player* player, SpeakClasses type } if (it->second.getNeedAccess() && !player->isAccessPlayer()) { - std::cout << player->getGroup()->access << std::endl; - return TALKACTION_CONTINUE; + return TalkActionResult::CONTINUE; } if (player->getAccountType() < it->second.getRequiredAccountType()) { - std::cout << static_cast(player->getAccountType()) << " - " - << static_cast(it->second.getRequiredAccountType()) << std::endl; - return TALKACTION_CONTINUE; + return TalkActionResult::CONTINUE; } if (it->second.executeSay(player, words, param, type)) { - return TALKACTION_CONTINUE; + return TalkActionResult::CONTINUE; } else { - return TALKACTION_BREAK; + return TalkActionResult::BREAK; } } - return TALKACTION_CONTINUE; + return TalkActionResult::CONTINUE; } bool TalkAction::configureEvent(const pugi::xml_node& node) diff --git a/src/talkaction.h b/src/talkaction.h index 35cd211..a1b5218 100644 --- a/src/talkaction.h +++ b/src/talkaction.h @@ -11,11 +11,11 @@ class TalkAction; using TalkAction_ptr = std::unique_ptr; -enum TalkActionResult_t +enum class TalkActionResult { - TALKACTION_CONTINUE, - TALKACTION_BREAK, - TALKACTION_FAILED, + CONTINUE, + BREAK, + FAILED, }; class TalkAction : public Event @@ -71,7 +71,7 @@ class TalkActions final : public BaseEvents TalkActions(const TalkActions&) = delete; TalkActions& operator=(const TalkActions&) = delete; - TalkActionResult_t playerSaySpell(Player* player, SpeakClasses type, std::string_view words) const; + TalkActionResult playerSaySpell(Player* player, SpeakClasses type, std::string_view words) const; bool registerLuaEvent(TalkAction* event); void clear(bool fromLua) override final;