From 4a31b830dd77091e8aec70dc8d6b3012a5946341 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sun, 10 Sep 2023 23:06:38 -0700 Subject: [PATCH 01/67] improve: migrate Thing and derivatives to shared_ptr --- src/canary_server.cpp | 74 +- src/creatures/combat/combat.cpp | 178 ++- src/creatures/combat/combat.hpp | 103 +- src/creatures/combat/condition.cpp | 174 +-- src/creatures/combat/condition.hpp | 132 +- src/creatures/combat/spells.cpp | 64 +- src/creatures/combat/spells.hpp | 56 +- src/creatures/creature.cpp | 238 ++- src/creatures/creature.hpp | 158 +- src/creatures/interactions/chat.cpp | 128 +- src/creatures/interactions/chat.hpp | 42 +- src/creatures/monsters/monster.cpp | 205 ++- src/creatures/monsters/monster.hpp | 77 +- .../monsters/spawns/spawn_monster.cpp | 15 +- .../monsters/spawns/spawn_monster.hpp | 4 +- src/creatures/npcs/npc.cpp | 110 +- src/creatures/npcs/npc.hpp | 53 +- src/creatures/npcs/spawns/spawn_npc.cpp | 15 +- src/creatures/npcs/spawns/spawn_npc.hpp | 4 +- src/creatures/players/grouping/guild.cpp | 8 +- src/creatures/players/grouping/guild.hpp | 8 +- src/creatures/players/grouping/party.cpp | 173 ++- src/creatures/players/grouping/party.hpp | 56 +- .../players/imbuements/imbuements.cpp | 2 +- .../players/imbuements/imbuements.hpp | 2 +- src/creatures/players/management/waitlist.cpp | 6 +- src/creatures/players/management/waitlist.hpp | 6 +- src/creatures/players/player.cpp | 1046 +++++++------ src/creatures/players/player.hpp | 379 +++-- src/creatures/players/wheel/player_wheel.cpp | 52 +- src/creatures/players/wheel/player_wheel.hpp | 9 +- src/game/bank/bank.cpp | 6 +- src/game/bank/bank.hpp | 4 +- src/game/game.cpp | 1309 ++++++++--------- src/game/game.hpp | 298 ++-- src/game/movement/teleport.cpp | 36 +- src/game/movement/teleport.hpp | 31 +- src/game/scheduling/dispatcher.cpp | 8 +- src/game/scheduling/dispatcher.hpp | 4 +- src/game/zones/zone.cpp | 40 +- src/game/zones/zone.hpp | 28 +- src/io/functions/iologindata_load_player.cpp | 108 +- src/io/functions/iologindata_load_player.hpp | 58 +- src/io/functions/iologindata_save_player.cpp | 48 +- src/io/functions/iologindata_save_player.hpp | 38 +- src/io/io_bosstiary.cpp | 8 +- src/io/io_bosstiary.hpp | 8 +- src/io/io_wheel.cpp | 82 +- src/io/io_wheel.hpp | 80 +- src/io/iobestiary.cpp | 22 +- src/io/iobestiary.hpp | 22 +- src/io/iologindata.cpp | 10 +- src/io/iologindata.hpp | 12 +- src/io/iomapserialize.cpp | 44 +- src/io/iomapserialize.hpp | 8 +- src/io/iomarket.cpp | 17 +- src/io/ioprey.cpp | 6 +- src/io/ioprey.hpp | 6 +- src/items/bed.cpp | 46 +- src/items/bed.hpp | 23 +- src/items/containers/container.cpp | 248 ++-- src/items/containers/container.hpp | 104 +- src/items/containers/depot/depotchest.cpp | 20 +- src/items/containers/depot/depotchest.hpp | 10 +- src/items/containers/depot/depotlocker.cpp | 8 +- src/items/containers/depot/depotlocker.hpp | 15 +- src/items/containers/inbox/inbox.cpp | 20 +- src/items/containers/inbox/inbox.hpp | 10 +- src/items/containers/mailbox/mailbox.cpp | 45 +- src/items/containers/mailbox/mailbox.hpp | 35 +- src/items/containers/rewards/reward.cpp | 16 +- src/items/containers/rewards/reward.hpp | 17 +- src/items/containers/rewards/rewardchest.cpp | 8 +- src/items/containers/rewards/rewardchest.hpp | 15 +- src/items/cylinder.cpp | 10 +- src/items/cylinder.hpp | 58 +- src/items/decay/decay.cpp | 16 +- src/items/decay/decay.hpp | 8 +- src/items/functions/item/item_parse.cpp | 1 - src/items/item.cpp | 149 +- src/items/item.hpp | 102 +- src/items/thing.cpp | 14 +- src/items/thing.hpp | 29 +- src/items/tile.cpp | 298 ++-- src/items/tile.hpp | 119 +- src/items/trashholder.cpp | 30 +- src/items/trashholder.hpp | 29 +- src/items/weapons/weapons.cpp | 64 +- src/items/weapons/weapons.hpp | 52 +- src/lua/callbacks/creaturecallback.cpp | 10 +- src/lua/callbacks/creaturecallback.hpp | 10 +- src/lua/callbacks/event_callback.cpp | 82 +- src/lua/callbacks/event_callback.hpp | 78 +- src/lua/creature/actions.cpp | 40 +- src/lua/creature/actions.hpp | 26 +- src/lua/creature/creatureevent.cpp | 30 +- src/lua/creature/creatureevent.hpp | 30 +- src/lua/creature/events.cpp | 70 +- src/lua/creature/events.hpp | 66 +- src/lua/creature/movement.cpp | 146 +- src/lua/creature/movement.hpp | 54 +- src/lua/creature/raids.cpp | 9 +- src/lua/creature/talkaction.cpp | 6 +- src/lua/creature/talkaction.hpp | 6 +- .../functions/core/game/bank_functions.cpp | 14 +- .../functions/core/game/game_functions.cpp | 39 +- .../functions/core/game/global_functions.cpp | 54 +- .../core/game/modal_window_functions.cpp | 2 +- .../network/network_message_functions.cpp | 6 +- .../creatures/combat/combat_functions.cpp | 6 +- .../creatures/combat/variant_functions.cpp | 2 +- .../creatures/creature_functions.cpp | 166 +-- .../creatures/monster/monster_functions.cpp | 102 +- .../functions/creatures/npc/npc_functions.cpp | 92 +- .../creatures/player/guild_functions.cpp | 2 +- .../creatures/player/party_functions.cpp | 24 +- .../creatures/player/player_functions.cpp | 552 +++---- .../functions/items/container_functions.cpp | 45 +- src/lua/functions/items/item_functions.cpp | 126 +- src/lua/functions/lua_functions_loader.cpp | 42 +- src/lua/functions/lua_functions_loader.hpp | 14 +- src/lua/functions/map/house_functions.cpp | 22 +- src/lua/functions/map/position_functions.cpp | 10 +- src/lua/functions/map/teleport_functions.cpp | 6 +- src/lua/functions/map/tile_functions.cpp | 122 +- src/lua/modules/modules.cpp | 4 +- src/lua/modules/modules.hpp | 2 +- src/lua/scripts/lua_environment.cpp | 1 - src/lua/scripts/luascript.cpp | 2 +- src/lua/scripts/script_environment.cpp | 28 +- src/lua/scripts/script_environment.hpp | 24 +- src/map/house/house.cpp | 116 +- src/map/house/house.hpp | 59 +- src/map/house/housetile.cpp | 44 +- src/map/house/housetile.hpp | 12 +- src/map/map.cpp | 110 +- src/map/map.hpp | 20 +- src/map/mapcache.cpp | 28 +- src/map/mapcache.hpp | 34 +- src/map/utils/astarnodes.cpp | 12 +- src/map/utils/astarnodes.hpp | 2 +- src/map/utils/qtreenode.cpp | 4 +- src/map/utils/qtreenode.hpp | 9 +- src/server/network/protocol/protocolgame.cpp | 257 ++-- src/server/network/protocol/protocolgame.hpp | 112 +- .../fixture/lib/logging/in_memory_logger.hpp | 104 +- tests/fixture/test_injection.hpp | 14 +- tests/unit/lib/di/soft_singleton_test.cpp | 40 +- tests/unit/lib/logging/in_memory_logger.hpp | 104 +- tests/unit/main.cpp | 2 +- tests/unit/security/rsa_test.cpp | 23 +- tests/unit/utils/position_functions_test.cpp | 52 +- tests/unit/utils/string_functions_test.cpp | 12 +- 153 files changed, 5359 insertions(+), 5520 deletions(-) diff --git a/src/canary_server.cpp b/src/canary_server.cpp index 49678c298ac..d14bb30fc0e 100644 --- a/src/canary_server.cpp +++ b/src/canary_server.cpp @@ -52,57 +52,59 @@ CanaryServer::CanaryServer( } int CanaryServer::run() { - g_dispatcher().addTask([this] { - try { - loadConfigLua(); + g_dispatcher().addTask( + [this] { + try { + loadConfigLua(); - logger.info("Server protocol: {}.{}{}", CLIENT_VERSION_UPPER, CLIENT_VERSION_LOWER, g_configManager().getBoolean(OLD_PROTOCOL) ? " and 10x allowed!" : ""); + logger.info("Server protocol: {}.{}{}", CLIENT_VERSION_UPPER, CLIENT_VERSION_LOWER, g_configManager().getBoolean(OLD_PROTOCOL) ? " and 10x allowed!" : ""); - rsa.start(); - initializeDatabase(); - loadModules(); - setWorldType(); - loadMaps(); + rsa.start(); + initializeDatabase(); + loadModules(); + setWorldType(); + loadMaps(); - logger.info("Initializing gamestate..."); - g_game().setGameState(GAME_STATE_INIT); + logger.info("Initializing gamestate..."); + g_game().setGameState(GAME_STATE_INIT); - setupHousesRent(); + setupHousesRent(); - IOMarket::checkExpiredOffers(); - IOMarket::getInstance().updateStatistics(); + IOMarket::checkExpiredOffers(); + IOMarket::getInstance().updateStatistics(); - logger.info("Loaded all modules, server starting up..."); + logger.info("Loaded all modules, server starting up..."); #ifndef _WIN32 - if (getuid() == 0 || geteuid() == 0) { - logger.warn("{} has been executed as root user, " - "please consider running it as a normal user", - STATUS_SERVER_NAME); - } + if (getuid() == 0 || geteuid() == 0) { + logger.warn("{} has been executed as root user, " + "please consider running it as a normal user", + STATUS_SERVER_NAME); + } #endif - g_game().start(&serviceManager); - g_game().setGameState(GAME_STATE_NORMAL); + g_game().start(&serviceManager); + g_game().setGameState(GAME_STATE_NORMAL); - g_webhook().sendMessage("Server is now online", "Server has successfully started.", WEBHOOK_COLOR_ONLINE); + g_webhook().sendMessage("Server is now online", "Server has successfully started.", WEBHOOK_COLOR_ONLINE); - loaderDone = true; - loaderSignal.notify_all(); - } catch (FailedToInitializeCanary &err) { - loadFailed = true; - logger.error(err.what()); + loaderDone = true; + loaderSignal.notify_all(); + } catch (FailedToInitializeCanary &err) { + loadFailed = true; + logger.error(err.what()); - logger.error("The program will close after pressing the enter key..."); + logger.error("The program will close after pressing the enter key..."); - if (isatty(STDIN_FILENO)) { - getchar(); - } + if (isatty(STDIN_FILENO)) { + getchar(); + } - loaderSignal.notify_all(); - } - }, - "CanaryServer::run"); + loaderSignal.notify_all(); + } + }, + "CanaryServer::run" + ); loaderSignal.wait(loaderUniqueLock, [this] { return loaderDone || loadFailed; }); diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index 6b5b1a9ae5c..10c7b2ee67d 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -19,7 +19,7 @@ #include "creatures/monsters/monsters.hpp" #include "items/weapons/weapons.hpp" -int32_t Combat::getLevelFormula(const Player* player, const std::shared_ptr wheelSpell, const CombatDamage &damage) const { +int32_t Combat::getLevelFormula(std::shared_ptr player, const std::shared_ptr wheelSpell, const CombatDamage &damage) const { if (!player) { return 0; } @@ -38,7 +38,7 @@ int32_t Combat::getLevelFormula(const Player* player, const std::shared_ptr creature, std::shared_ptr target) const { CombatDamage damage; damage.origin = params.origin; damage.primary.type = params.combatType; @@ -47,7 +47,7 @@ CombatDamage Combat::getCombatDamage(Creature* creature, Creature* target) const damage.runeSpellName = runeSpellName; // Wheel of destiny std::shared_ptr wheelSpell = nullptr; - Player* attackerPlayer = creature ? creature->getPlayer() : nullptr; + std::shared_ptr attackerPlayer = creature ? creature->getPlayer() : nullptr; if (attackerPlayer) { wheelSpell = attackerPlayer->wheel()->getCombatDataSpell(damage); } @@ -61,7 +61,7 @@ CombatDamage Combat::getCombatDamage(Creature* creature, Creature* target) const int32_t min, max; if (creature->getCombatValues(min, max)) { damage.primary.value = normal_random(min, max); - } else if (Player* player = creature->getPlayer()) { + } else if (std::shared_ptr player = creature->getPlayer()) { if (params.valueCallback) { params.valueCallback->getMinMaxValues(player, damage, params.useCharges); } else if (formulaType == COMBAT_FORMULA_LEVELMAGIC) { @@ -71,7 +71,7 @@ CombatDamage Combat::getCombatDamage(Creature* creature, Creature* target) const static_cast(levelFormula * maxa + maxb) ); } else if (formulaType == COMBAT_FORMULA_SKILL) { - Item* tool = player->getWeapon(); + std::shared_ptr tool = player->getWeapon(); const Weapon* weapon = g_weapons().getWeapon(tool); if (weapon) { damage.primary.value = normal_random( @@ -99,7 +99,7 @@ CombatDamage Combat::getCombatDamage(Creature* creature, Creature* target) const return damage; } -void Combat::getCombatArea(const Position ¢erPos, const Position &targetPos, const AreaCombat* area, std::forward_list &list) { +void Combat::getCombatArea(const Position ¢erPos, const Position &targetPos, const AreaCombat* area, std::forward_list> &list) { if (targetPos.z >= MAP_MAX_LAYERS) { return; } @@ -175,7 +175,7 @@ ConditionType_t Combat::DamageToConditionType(CombatType_t type) { } } -bool Combat::isPlayerCombat(const Creature* target) { +bool Combat::isPlayerCombat(std::shared_ptr target) { if (target->getPlayer()) { return true; } @@ -187,7 +187,7 @@ bool Combat::isPlayerCombat(const Creature* target) { return false; } -ReturnValue Combat::canTargetCreature(Player* player, Creature* target) { +ReturnValue Combat::canTargetCreature(std::shared_ptr player, std::shared_ptr target) { if (player == target) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } @@ -235,7 +235,7 @@ ReturnValue Combat::canTargetCreature(Player* player, Creature* target) { return Combat::canDoCombat(player, target, true); } -ReturnValue Combat::canDoCombat(Creature* caster, Tile* tile, bool aggressive) { +ReturnValue Combat::canDoCombat(std::shared_ptr caster, std::shared_ptr tile, bool aggressive) { if (tile->hasProperty(CONST_PROP_BLOCKPROJECTILE)) { return RETURNVALUE_NOTENOUGHROOM; } @@ -260,7 +260,7 @@ ReturnValue Combat::canDoCombat(Creature* caster, Tile* tile, bool aggressive) { return RETURNVALUE_FIRSTGOUPSTAIRS; } - if (const Player* player = caster->getPlayer()) { + if (std::shared_ptr player = caster->getPlayer()) { if (player->hasFlag(PlayerFlags_t::IgnoreProtectionZone)) { return RETURNVALUE_NOERROR; } @@ -270,11 +270,11 @@ ReturnValue Combat::canDoCombat(Creature* caster, Tile* tile, bool aggressive) { return g_events().eventCreatureOnAreaCombat(caster, tile, aggressive); } -bool Combat::isInPvpZone(const Creature* attacker, const Creature* target) { +bool Combat::isInPvpZone(std::shared_ptr attacker, std::shared_ptr target) { return attacker->getZoneType() == ZONE_PVP && target->getZoneType() == ZONE_PVP; } -bool Combat::isProtected(const Player* attacker, const Player* target) { +bool Combat::isProtected(std::shared_ptr attacker, std::shared_ptr target) { uint32_t protectionLevel = g_configManager().getNumber(PROTECTION_LEVEL); if (target->getLevel() < protectionLevel || attacker->getLevel() < protectionLevel) { return true; @@ -291,13 +291,13 @@ bool Combat::isProtected(const Player* attacker, const Player* target) { return false; } -ReturnValue Combat::canDoCombat(Creature* attacker, Creature* target, bool aggressive) { +ReturnValue Combat::canDoCombat(std::shared_ptr attacker, std::shared_ptr target, bool aggressive) { if (!aggressive) { return RETURNVALUE_NOERROR; } if (target) { - const Tile* tile = target->getTile(); + std::shared_ptr tile = target->getTile(); if (tile->hasProperty(CONST_PROP_BLOCKPROJECTILE)) { return RETURNVALUE_NOTENOUGHROOM; } @@ -307,16 +307,16 @@ ReturnValue Combat::canDoCombat(Creature* attacker, Creature* target, bool aggre } if (attacker) { - const Creature* attackerMaster = attacker->getMaster(); + const std::shared_ptr attackerMaster = attacker->getMaster(); auto targetPlayer = target ? target->getPlayer() : nullptr; if (targetPlayer) { if (targetPlayer->hasFlag(PlayerFlags_t::CannotBeAttacked)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } - const Tile* targetPlayerTile = targetPlayer->getTile(); + const std::shared_ptr targetPlayerTile = targetPlayer->getTile(); - if (const Player* attackerPlayer = attacker->getPlayer()) { + if (const std::shared_ptr attackerPlayer = attacker->getPlayer()) { if (attackerPlayer->hasFlag(PlayerFlags_t::CannotAttackPlayer)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } @@ -339,7 +339,7 @@ ReturnValue Combat::canDoCombat(Creature* attacker, Creature* target, bool aggre } if (attackerMaster) { - if (const Player* masterAttackerPlayer = attackerMaster->getPlayer()) { + if (const std::shared_ptr masterAttackerPlayer = attackerMaster->getPlayer()) { if (masterAttackerPlayer->hasFlag(PlayerFlags_t::CannotAttackPlayer)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } @@ -364,7 +364,7 @@ ReturnValue Combat::canDoCombat(Creature* attacker, Creature* target, bool aggre return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE; } - if (const Player* attackerPlayer = attacker->getPlayer()) { + if (const std::shared_ptr attackerPlayer = attacker->getPlayer()) { if (attackerPlayer->hasFlag(PlayerFlags_t::CannotAttackMonster)) { return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE; } @@ -373,7 +373,7 @@ ReturnValue Combat::canDoCombat(Creature* attacker, Creature* target, bool aggre return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE; } } else if (attacker->getMonster()) { - const Creature* targetMaster = target->getMaster(); + const std::shared_ptr targetMaster = target->getMaster(); if ((!targetMaster || !targetMaster->getPlayer()) && attacker->getFaction() == FACTION_DEFAULT) { if (!attackerMaster || !attackerMaster->getPlayer()) { @@ -543,32 +543,32 @@ CallBack* Combat::getCallback(CallBackParam_t key) { return nullptr; } -void Combat::CombatHealthFunc(Creature* caster, Creature* target, const CombatParams ¶ms, CombatDamage* data) { +void Combat::CombatHealthFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data) { assert(data); CombatDamage damage = *data; - Player* attackerPlayer = nullptr; + std::shared_ptr attackerPlayer = nullptr; if (caster) { attackerPlayer = caster->getPlayer(); } - Monster* targetMonster = nullptr; + std::shared_ptr targetMonster = nullptr; if (target) { targetMonster = target->getMonster(); } - Monster* attackerMonster = nullptr; + std::shared_ptr attackerMonster = nullptr; if (caster) { attackerMonster = caster->getMonster(); } - Player* targetPlayer = nullptr; + std::shared_ptr targetPlayer = nullptr; if (target) { targetPlayer = target->getPlayer(); } if (caster && attackerPlayer) { - Item* item = attackerPlayer->getWeapon(); + std::shared_ptr item = attackerPlayer->getWeapon(); damage = applyImbuementElementalDamage(attackerPlayer, item, damage); g_events().eventPlayerOnCombat(attackerPlayer, target, item, damage); @@ -610,7 +610,7 @@ void Combat::CombatHealthFunc(Creature* caster, Creature* target, const CombatPa } } -CombatDamage Combat::applyImbuementElementalDamage(Player* attackerPlayer, Item* item, CombatDamage damage) { +CombatDamage Combat::applyImbuementElementalDamage(std::shared_ptr attackerPlayer, std::shared_ptr item, CombatDamage damage) { if (!item) { return damage; } @@ -648,7 +648,7 @@ CombatDamage Combat::applyImbuementElementalDamage(Player* attackerPlayer, Item* return damage; } -void Combat::CombatManaFunc(Creature* caster, Creature* target, const CombatParams ¶ms, CombatDamage* data) { +void Combat::CombatManaFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data) { assert(data); CombatDamage damage = *data; if (damage.primary.value < 0) { @@ -662,7 +662,7 @@ void Combat::CombatManaFunc(Creature* caster, Creature* target, const CombatPara } } -bool Combat::checkFearConditionAffected(Player* player) { +bool Combat::checkFearConditionAffected(std::shared_ptr player) { if (player->isImmuneFear()) { return false; } @@ -690,13 +690,13 @@ bool Combat::checkFearConditionAffected(Player* player) { return true; } -void Combat::CombatConditionFunc(Creature* caster, Creature* target, const CombatParams ¶ms, CombatDamage* data) { +void Combat::CombatConditionFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data) { if (params.origin == ORIGIN_MELEE && data && data->primary.value == 0 && data->secondary.value == 0) { return; } for (const auto &condition : params.conditionList) { - Player* player = nullptr; + std::shared_ptr player = nullptr; if (target) { player = target->getPlayer(); } @@ -743,18 +743,18 @@ void Combat::CombatConditionFunc(Creature* caster, Creature* target, const Comba } } -void Combat::CombatDispelFunc(Creature*, Creature* target, const CombatParams ¶ms, CombatDamage*) { +void Combat::CombatDispelFunc(std::shared_ptr, std::shared_ptr target, const CombatParams ¶ms, CombatDamage*) { if (target) { target->removeCombatCondition(params.dispelType); } } -void Combat::CombatNullFunc(Creature* caster, Creature* target, const CombatParams ¶ms, CombatDamage*) { +void Combat::CombatNullFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage*) { CombatConditionFunc(caster, target, params, nullptr); CombatDispelFunc(caster, target, params, nullptr); } -void Combat::combatTileEffects(const SpectatorHashSet &spectators, Creature* caster, Tile* tile, const CombatParams ¶ms) { +void Combat::combatTileEffects(const SpectatorHashSet &spectators, std::shared_ptr caster, std::shared_ptr tile, const CombatParams ¶ms) { if (params.itemId != 0) { uint16_t itemId = params.itemId; switch (itemId) { @@ -791,7 +791,7 @@ void Combat::combatTileEffects(const SpectatorHashSet &spectators, Creature* cas } if (caster) { - Player* casterPlayer; + std::shared_ptr casterPlayer; if (caster->isSummon()) { casterPlayer = caster->getMaster()->getPlayer(); } else { @@ -817,7 +817,7 @@ void Combat::combatTileEffects(const SpectatorHashSet &spectators, Creature* cas } } - Item* item = Item::CreateItem(itemId); + std::shared_ptr item = Item::CreateItem(itemId); if (caster) { item->setAttribute(ItemAttribute_t::OWNER, caster->getID()); } @@ -825,8 +825,6 @@ void Combat::combatTileEffects(const SpectatorHashSet &spectators, Creature* cas ReturnValue ret = g_game().internalAddItem(tile, item); if (ret == RETURNVALUE_NOERROR) { item->startDecaying(); - } else { - delete item; } } @@ -845,7 +843,7 @@ void Combat::combatTileEffects(const SpectatorHashSet &spectators, Creature* cas } } -void Combat::postCombatEffects(Creature* caster, const Position &origin, const Position &pos, const CombatParams ¶ms) { +void Combat::postCombatEffects(std::shared_ptr caster, const Position &origin, const Position &pos, const CombatParams ¶ms) { if (caster && params.distanceEffect != CONST_ANI_NONE) { addDistanceEffect(caster, origin, pos, params.distanceEffect); } @@ -857,13 +855,13 @@ void Combat::postCombatEffects(Creature* caster, const Position &origin, const P } } -void Combat::addDistanceEffect(Creature* caster, const Position &fromPos, const Position &toPos, uint16_t effect) { +void Combat::addDistanceEffect(std::shared_ptr caster, const Position &fromPos, const Position &toPos, uint16_t effect) { if (effect == CONST_ANI_WEAPONTYPE) { if (!caster) { return; } - Player* player = caster->getPlayer(); + std::shared_ptr player = caster->getPlayer(); if (!player) { return; } @@ -915,7 +913,7 @@ void Combat::doChainEffect(const Position &origin, const Position &dest, uint8_t } } -bool Combat::doCombatChain(Creature* caster, Creature* target, bool aggressive) const { +bool Combat::doCombatChain(std::shared_ptr caster, std::shared_ptr target, bool aggressive) const { if (!params.chainCallback) { return false; } @@ -946,7 +944,7 @@ bool Combat::doCombatChain(Creature* caster, Creature* target, bool aggressive) return true; } -bool Combat::doCombat(Creature* caster, Creature* target) const { +bool Combat::doCombat(std::shared_ptr caster, std::shared_ptr target) const { if (caster != nullptr && params.chainCallback) { return doCombatChain(caster, target, params.aggressive); } @@ -954,7 +952,7 @@ bool Combat::doCombat(Creature* caster, Creature* target) const { return doCombat(caster, target, caster != nullptr ? caster->getPosition() : Position()); } -bool Combat::doCombat(Creature* caster, Creature* target, const Position &origin) const { +bool Combat::doCombat(std::shared_ptr caster, std::shared_ptr target, const Position &origin) const { // target combat callback function if (params.combatType != COMBAT_NONE) { CombatDamage damage = getCombatDamage(caster, target); @@ -970,7 +968,7 @@ bool Combat::doCombat(Creature* caster, Creature* target, const Position &origin return true; } -bool Combat::doCombat(Creature* caster, const Position &position) const { +bool Combat::doCombat(std::shared_ptr caster, const Position &position) const { if (caster != nullptr && params.chainCallback) { return doCombatChain(caster, caster, params.aggressive); } @@ -991,8 +989,8 @@ bool Combat::doCombat(Creature* caster, const Position &position) const { return true; } -void Combat::CombatFunc(Creature* caster, const Position &origin, const Position &pos, const AreaCombat* area, const CombatParams ¶ms, CombatFunction func, CombatDamage* data) { - std::forward_list tileList; +void Combat::CombatFunc(std::shared_ptr caster, const Position &origin, const Position &pos, const AreaCombat* area, const CombatParams ¶ms, CombatFunction func, CombatDamage* data) { + std::forward_list> tileList; if (caster) { getCombatArea(caster->getPosition(), pos, area, tileList); @@ -1005,7 +1003,7 @@ void Combat::CombatFunc(Creature* caster, const Position &origin, const Position uint32_t maxY = 0; // calculate the max viewable range - for (Tile* tile : tileList) { + for (std::shared_ptr tile : tileList) { const Position &tilePos = tile->getPosition(); uint32_t diff = Position::getDistanceX(tilePos, pos); @@ -1024,14 +1022,14 @@ void Combat::CombatFunc(Creature* caster, const Position &origin, const Position g_game().map.getSpectators(spectators, pos, true, true, rangeX, rangeX, rangeY, rangeY); int affected = 0; - for (Tile* tile : tileList) { + for (std::shared_ptr tile : tileList) { if (canDoCombat(caster, tile, params.aggressive) != RETURNVALUE_NOERROR) { continue; } if (CreatureVector* creatures = tile->getCreatures()) { - const Creature* topCreature = tile->getTopCreature(); - for (Creature* creature : *creatures) { + const std::shared_ptr topCreature = tile->getTopCreature(); + for (auto &creature : *creatures) { if (params.targetCasterOrTopMost) { if (caster && caster->getTile() == tile) { if (creature != caster) { @@ -1073,19 +1071,19 @@ void Combat::CombatFunc(Creature* caster, const Position &origin, const Position } // Wheel of destiny get beam affected total - Player* casterPlayer = caster ? caster->getPlayer() : nullptr; + std::shared_ptr casterPlayer = caster ? caster->getPlayer() : nullptr; uint8_t beamAffectedTotal = casterPlayer ? casterPlayer->wheel()->getBeamAffectedTotal(tmpDamage) : 0; uint8_t beamAffectedCurrent = 0; tmpDamage.affected = affected; - for (Tile* tile : tileList) { + for (std::shared_ptr tile : tileList) { if (canDoCombat(caster, tile, params.aggressive) != RETURNVALUE_NOERROR) { continue; } if (CreatureVector* creatures = tile->getCreatures()) { - const Creature* topCreature = tile->getTopCreature(); - for (Creature* creature : *creatures) { + const std::shared_ptr topCreature = tile->getTopCreature(); + for (auto &creature : *creatures) { if (params.targetCasterOrTopMost) { if (caster && caster->getTile() == tile) { if (creature != caster) { @@ -1123,11 +1121,11 @@ void Combat::CombatFunc(Creature* caster, const Position &origin, const Position postCombatEffects(caster, origin, pos, params); } -void Combat::doCombatHealth(Creature* caster, Creature* target, CombatDamage &damage, const CombatParams ¶ms) { +void Combat::doCombatHealth(std::shared_ptr caster, std::shared_ptr target, CombatDamage &damage, const CombatParams ¶ms) { doCombatHealth(caster, target, caster ? caster->getPosition() : Position(), damage, params); } -void Combat::doCombatHealth(Creature* caster, Creature* target, const Position &origin, CombatDamage &damage, const CombatParams ¶ms) { +void Combat::doCombatHealth(std::shared_ptr caster, std::shared_ptr target, const Position &origin, CombatDamage &damage, const CombatParams ¶ms) { bool canCombat = !params.aggressive || (caster != target && Combat::canDoCombat(caster, target, params.aggressive) == RETURNVALUE_NOERROR); if ((caster && target) && (caster == target || canCombat) @@ -1195,7 +1193,7 @@ void Combat::doCombatHealth(Creature* caster, Creature* target, const Position & } } -void Combat::doCombatHealth(Creature* caster, const Position &position, const AreaCombat* area, CombatDamage &damage, const CombatParams ¶ms) { +void Combat::doCombatHealth(std::shared_ptr caster, const Position &position, const AreaCombat* area, CombatDamage &damage, const CombatParams ¶ms) { if (caster && caster->getPlayer()) { // Critical damage uint16_t chance = caster->getPlayer()->getSkillLevel(SKILL_CRITICAL_HIT_CHANCE) + (uint16_t)damage.criticalChance; @@ -1221,11 +1219,11 @@ void Combat::doCombatHealth(Creature* caster, const Position &position, const Ar CombatFunc(caster, origin, position, area, params, CombatHealthFunc, &damage); } -void Combat::doCombatMana(Creature* caster, Creature* target, CombatDamage &damage, const CombatParams ¶ms) { +void Combat::doCombatMana(std::shared_ptr caster, std::shared_ptr target, CombatDamage &damage, const CombatParams ¶ms) { doCombatMana(caster, target, caster ? caster->getPosition() : Position(), damage, params); } -void Combat::doCombatMana(Creature* caster, Creature* target, const Position &origin, CombatDamage &damage, const CombatParams ¶ms) { +void Combat::doCombatMana(std::shared_ptr caster, std::shared_ptr target, const Position &origin, CombatDamage &damage, const CombatParams ¶ms) { bool canCombat = !params.aggressive || (caster != target && Combat::canDoCombat(caster, target, params.aggressive) == RETURNVALUE_NOERROR); if ((caster && target) && (caster == target || canCombat) @@ -1261,7 +1259,7 @@ void Combat::doCombatMana(Creature* caster, Creature* target, const Position &or } } -void Combat::doCombatMana(Creature* caster, const Position &position, const AreaCombat* area, CombatDamage &damage, const CombatParams ¶ms) { +void Combat::doCombatMana(std::shared_ptr caster, const Position &position, const AreaCombat* area, CombatDamage &damage, const CombatParams ¶ms) { if (caster && caster->getPlayer()) { // Critical damage uint16_t chance = caster->getPlayer()->getSkillLevel(SKILL_CRITICAL_HIT_CHANCE) + (uint16_t)damage.criticalChance; @@ -1275,12 +1273,12 @@ void Combat::doCombatMana(Creature* caster, const Position &position, const Area CombatFunc(caster, origin, position, area, params, CombatManaFunc, &damage); } -void Combat::doCombatCondition(Creature* caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms) { +void Combat::doCombatCondition(std::shared_ptr caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms) { const auto &origin = caster ? caster->getPosition() : Position(); CombatFunc(caster, origin, position, area, params, CombatConditionFunc, nullptr); } -void Combat::doCombatCondition(Creature* caster, Creature* target, const CombatParams ¶ms) { +void Combat::doCombatCondition(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms) { bool canCombat = !params.aggressive || (caster != target && Combat::canDoCombat(caster, target, params.aggressive) == RETURNVALUE_NOERROR); if ((caster == target || canCombat) && params.impactEffect != CONST_ME_NONE) { g_game().addMagicEffect(target->getPosition(), params.impactEffect); @@ -1304,12 +1302,12 @@ void Combat::doCombatCondition(Creature* caster, Creature* target, const CombatP } } -void Combat::doCombatDispel(Creature* caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms) { +void Combat::doCombatDispel(std::shared_ptr caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms) { const auto &origin = caster ? caster->getPosition() : Position(); CombatFunc(caster, origin, position, area, params, CombatDispelFunc, nullptr); } -void Combat::doCombatDispel(Creature* caster, Creature* target, const CombatParams ¶ms) { +void Combat::doCombatDispel(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms) { bool canCombat = !params.aggressive || (caster != target && Combat::canDoCombat(caster, target, params.aggressive) == RETURNVALUE_NOERROR); if ((caster && target) && (caster == target || canCombat) @@ -1335,11 +1333,11 @@ void Combat::doCombatDispel(Creature* caster, Creature* target, const CombatPara } } -void Combat::doCombatDefault(Creature* caster, Creature* target, const CombatParams ¶ms) { +void Combat::doCombatDefault(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms) { doCombatDefault(caster, target, caster ? caster->getPosition() : Position(), params); } -void Combat::doCombatDefault(Creature* caster, Creature* target, const Position &origin, const CombatParams ¶ms) { +void Combat::doCombatDefault(std::shared_ptr caster, std::shared_ptr target, const Position &origin, const CombatParams ¶ms) { if (!params.aggressive || (caster != target && Combat::canDoCombat(caster, target, params.aggressive) == RETURNVALUE_NOERROR)) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, target->getPosition(), true, true); @@ -1377,13 +1375,13 @@ void Combat::setRuneSpellName(const std::string &value) { runeSpellName = value; } -std::vector>> Combat::pickChainTargets(Creature* caster, const CombatParams ¶ms, uint8_t chainDistance, uint8_t maxTargets, bool backtracking, bool aggressive, Creature* initialTarget /* = nullptr */) { +std::vector>> Combat::pickChainTargets(std::shared_ptr caster, const CombatParams ¶ms, uint8_t chainDistance, uint8_t maxTargets, bool backtracking, bool aggressive, std::shared_ptr initialTarget /* = nullptr */) { if (!caster) { return {}; } std::vector>> resultMap; - std::vector targets; + std::vector> targets; std::set visited; if (initialTarget && initialTarget != caster) { @@ -1397,14 +1395,14 @@ std::vector>> Combat::pickChainTargets const int maxBacktrackingAttempts = 10; // Can be adjusted as needed while (!targets.empty() && targets.size() <= maxTargets) { - Creature* currentTarget = targets.back(); + auto currentTarget = targets.back(); SpectatorHashSet spectators; g_game().map.getSpectators(spectators, currentTarget->getPosition(), false, false, chainDistance, chainDistance, chainDistance, chainDistance); g_logger().debug("Combat::pickChainTargets: currentTarget: {}, spectators: {}", currentTarget->getName(), spectators.size()); double closestDistance = std::numeric_limits::max(); - Creature* closestSpectator = nullptr; - for (Creature* spectator : spectators) { + std::shared_ptr closestSpectator = nullptr; + for (std::shared_ptr spectator : spectators) { if (!spectator || visited.contains(spectator->getID())) { continue; } @@ -1450,7 +1448,7 @@ std::vector>> Combat::pickChainTargets return resultMap; } -bool Combat::isValidChainTarget(Creature* caster, Creature* currentTarget, Creature* potentialTarget, const CombatParams ¶ms, bool aggressive) { +bool Combat::isValidChainTarget(std::shared_ptr caster, std::shared_ptr currentTarget, std::shared_ptr potentialTarget, const CombatParams ¶ms, bool aggressive) { bool canCombat = canDoCombat(caster, potentialTarget, aggressive) == RETURNVALUE_NOERROR; bool pick = params.chainPickerCallback ? params.chainPickerCallback->onChainCombat(caster, potentialTarget) : true; bool hasSight = g_game().isSightClear(currentTarget->getPosition(), potentialTarget->getPosition(), true); @@ -1459,7 +1457,7 @@ bool Combat::isValidChainTarget(Creature* caster, Creature* currentTarget, Creat //**********************************************************// -uint32_t ValueCallback::getMagicLevelSkill(const Player* player, const CombatDamage &damage) const { +uint32_t ValueCallback::getMagicLevelSkill(std::shared_ptr player, const CombatDamage &damage) const { if (!player) { return 0; } @@ -1479,7 +1477,7 @@ uint32_t ValueCallback::getMagicLevelSkill(const Player* player, const CombatDam return magicLevelSkill + player->getSpecializedMagicLevel(damage.primary.type, true); } -void ValueCallback::getMinMaxValues(Player* player, CombatDamage &damage, bool useCharges) const { +void ValueCallback::getMinMaxValues(std::shared_ptr player, CombatDamage &damage, bool useCharges) const { // onGetPlayerMinMaxValues(...) if (!scriptInterface->reserveScriptEnv()) { g_logger().error("[ValueCallback::getMinMaxValues - Player {} formula {}] " @@ -1517,9 +1515,9 @@ void ValueCallback::getMinMaxValues(Player* player, CombatDamage &damage, bool u case COMBAT_FORMULA_SKILL: { // onGetPlayerMinMaxValues(player, attackSkill, attackValue, attackFactor) - Item* tool = player->getWeapon(); + std::shared_ptr tool = player->getWeapon(); const Weapon* weapon = g_weapons().getWeapon(tool); - Item* item = nullptr; + std::shared_ptr item = nullptr; if (weapon) { attackValue = tool->getAttack(); @@ -1598,7 +1596,7 @@ void ValueCallback::getMinMaxValues(Player* player, CombatDamage &damage, bool u //**********************************************************// -void TileCallback::onTileCombat(Creature* creature, Tile* tile) const { +void TileCallback::onTileCombat(std::shared_ptr creature, std::shared_ptr tile) const { // onTileCombat(creature, pos) if (!scriptInterface->reserveScriptEnv()) { g_logger().error("[TileCallback::onTileCombat - Creature {} type {} on tile x: {} y: {} z: {}] " @@ -1629,7 +1627,7 @@ void TileCallback::onTileCombat(Creature* creature, Tile* tile) const { //**********************************************************// -void TargetCallback::onTargetCombat(Creature* creature, Creature* target) const { +void TargetCallback::onTargetCombat(std::shared_ptr creature, std::shared_ptr target) const { // onTargetCombat(creature, target) if (!scriptInterface->reserveScriptEnv()) { g_logger().error("[TargetCallback::onTargetCombat - Creature {}] " @@ -1677,7 +1675,7 @@ void TargetCallback::onTargetCombat(Creature* creature, Creature* target) const //**********************************************************// -void ChainCallback::onChainCombat(Creature* creature, uint8_t &maxTargets, uint8_t &chainDistance, bool &backtracking) const { +void ChainCallback::onChainCombat(std::shared_ptr creature, uint8_t &maxTargets, uint8_t &chainDistance, bool &backtracking) const { // onChainCombat(creature) if (!scriptInterface->reserveScriptEnv()) { g_logger().error("[ChainCallback::onTargetCombat - Creature {}] " @@ -1719,7 +1717,7 @@ void ChainCallback::onChainCombat(Creature* creature, uint8_t &maxTargets, uint8 scriptInterface->resetScriptEnv(); } -bool ChainPickerCallback::onChainCombat(Creature* creature, Creature* target) const { +bool ChainPickerCallback::onChainCombat(std::shared_ptr creature, std::shared_ptr target) const { // onChainCombat(creature, target) if (!scriptInterface->reserveScriptEnv()) { g_logger().error("[ChainPickerCallback::onTargetCombat - Creature {}] " @@ -1785,7 +1783,7 @@ AreaCombat::AreaCombat(const AreaCombat &rhs) { } } -void AreaCombat::getList(const Position ¢erPos, const Position &targetPos, std::forward_list &list) const { +void AreaCombat::getList(const Position ¢erPos, const Position &targetPos, std::forward_list> &list) const { const MatrixArea* area = getArea(centerPos, targetPos); if (!area) { return; @@ -2044,11 +2042,11 @@ void AreaCombat::setupExtArea(const std::list &list, uint32_t rows) { //**********************************************************// -void MagicField::onStepInField(Creature &creature) { +void MagicField::onStepInField(const std::shared_ptr &creature) { // remove magic walls/wild growth if (!isBlocking() && g_game().getWorldType() == WORLD_TYPE_NO_PVP && id == ITEM_MAGICWALL_SAFE || id == ITEM_WILDGROWTH_SAFE) { - if (!creature.isInGhostMode()) { - g_game().internalRemoveItem(this, 1); + if (!creature->isInGhostMode()) { + g_game().internalRemoveItem(static_self_cast(), 1); } return; @@ -2062,7 +2060,7 @@ void MagicField::onStepInField(Creature &creature) { bool harmfulField = true; auto itemTile = getTile(); if (g_game().getWorldType() == WORLD_TYPE_NO_PVP || itemTile && itemTile->hasFlag(TILESTATE_NOPVPZONE)) { - Creature* owner = g_game().getCreatureByID(ownerId); + std::shared_ptr owner = g_game().getCreatureByID(ownerId); if (owner) { if (owner->getPlayer() || (owner->isSummon() && owner->getMaster()->getPlayer())) { harmfulField = false; @@ -2070,9 +2068,9 @@ void MagicField::onStepInField(Creature &creature) { } } - Player* targetPlayer = creature.getPlayer(); + std::shared_ptr targetPlayer = creature->getPlayer(); if (targetPlayer) { - const Player* attackerPlayer = g_game().getPlayerByID(ownerId); + const std::shared_ptr attackerPlayer = g_game().getPlayerByID(ownerId); if (attackerPlayer) { if (Combat::isProtected(attackerPlayer, targetPlayer)) { harmfulField = false; @@ -2080,11 +2078,11 @@ void MagicField::onStepInField(Creature &creature) { } } - if (!harmfulField || (OTSYS_TIME() - createTime <= 5000) || creature.hasBeenAttacked(ownerId)) { + if (!harmfulField || (OTSYS_TIME() - createTime <= 5000) || creature->hasBeenAttacked(ownerId)) { conditionCopy->setParam(CONDITION_PARAM_OWNER, ownerId); } } - creature.addCondition(conditionCopy); + creature->addCondition(conditionCopy); } } diff --git a/src/creatures/combat/combat.hpp b/src/creatures/combat/combat.hpp index 241d1c05f63..780b1b5eb2c 100644 --- a/src/creatures/combat/combat.hpp +++ b/src/creatures/combat/combat.hpp @@ -33,8 +33,8 @@ class ValueCallback final : public CallBack { * @param damage The combat damage information. * @return The magic level skill of the player. */ - uint32_t getMagicLevelSkill(const Player* player, const CombatDamage &damage) const; - void getMinMaxValues(Player* player, CombatDamage &damage, bool useCharges) const; + uint32_t getMagicLevelSkill(std::shared_ptr player, const CombatDamage &damage) const; + void getMinMaxValues(std::shared_ptr player, CombatDamage &damage, bool useCharges) const; private: formulaType_t type; @@ -42,7 +42,7 @@ class ValueCallback final : public CallBack { class TileCallback final : public CallBack { public: - void onTileCombat(Creature* creature, Tile* tile) const; + void onTileCombat(std::shared_ptr creature, std::shared_ptr tile) const; protected: formulaType_t type; @@ -50,7 +50,7 @@ class TileCallback final : public CallBack { class TargetCallback final : public CallBack { public: - void onTargetCombat(Creature* creature, Creature* target) const; + void onTargetCombat(std::shared_ptr creature, std::shared_ptr target) const; protected: formulaType_t type; @@ -58,12 +58,12 @@ class TargetCallback final : public CallBack { class ChainCallback final : public CallBack { public: - void onChainCombat(Creature* creature, uint8_t &chainTargets, uint8_t &chainDistance, bool &backtracking) const; + void onChainCombat(std::shared_ptr creature, uint8_t &chainTargets, uint8_t &chainDistance, bool &backtracking) const; }; class ChainPickerCallback final : public CallBack { public: - bool onChainCombat(Creature* creature, Creature* target) const; + bool onChainCombat(std::shared_ptr creature, std::shared_ptr target) const; }; struct CombatParams { @@ -96,7 +96,7 @@ struct CombatParams { uint8_t chainEffect = CONST_ME_NONE; }; -using CombatFunction = std::function; +using CombatFunction = std::function, std::shared_ptr, const CombatParams &, CombatDamage*)>; class MatrixArea { public: @@ -197,7 +197,7 @@ class AreaCombat { // non-assignable AreaCombat &operator=(const AreaCombat &) = delete; - void getList(const Position ¢erPos, const Position &targetPos, std::forward_list &list) const; + void getList(const Position ¢erPos, const Position &targetPos, std::forward_list> &list) const; void setupArea(const std::list &list, uint32_t rows); void setupArea(int32_t length, int32_t spread); @@ -256,35 +256,35 @@ class Combat { Combat(const Combat &) = delete; Combat &operator=(const Combat &) = delete; - static void doCombatHealth(Creature* caster, Creature* target, CombatDamage &damage, const CombatParams ¶ms); - static void doCombatHealth(Creature* caster, const Position &position, const AreaCombat* area, CombatDamage &damage, const CombatParams ¶ms); + static void doCombatHealth(std::shared_ptr caster, std::shared_ptr target, CombatDamage &damage, const CombatParams ¶ms); + static void doCombatHealth(std::shared_ptr caster, const Position &position, const AreaCombat* area, CombatDamage &damage, const CombatParams ¶ms); - static void doCombatMana(Creature* caster, Creature* target, CombatDamage &damage, const CombatParams ¶ms); - static void doCombatMana(Creature* caster, const Position &position, const AreaCombat* area, CombatDamage &damage, const CombatParams ¶ms); + static void doCombatMana(std::shared_ptr caster, std::shared_ptr target, CombatDamage &damage, const CombatParams ¶ms); + static void doCombatMana(std::shared_ptr caster, const Position &position, const AreaCombat* area, CombatDamage &damage, const CombatParams ¶ms); - static void doCombatCondition(Creature* caster, Creature* target, const CombatParams ¶ms); - static void doCombatCondition(Creature* caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms); + static void doCombatCondition(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms); + static void doCombatCondition(std::shared_ptr caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms); - static void doCombatDispel(Creature* caster, Creature* target, const CombatParams ¶ms); - static void doCombatDispel(Creature* caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms); + static void doCombatDispel(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms); + static void doCombatDispel(std::shared_ptr caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms); - static void getCombatArea(const Position ¢erPos, const Position &targetPos, const AreaCombat* area, std::forward_list &list); + static void getCombatArea(const Position ¢erPos, const Position &targetPos, const AreaCombat* area, std::forward_list> &list); - static bool isInPvpZone(const Creature* attacker, const Creature* target); - static bool isProtected(const Player* attacker, const Player* target); - static bool isPlayerCombat(const Creature* target); + static bool isInPvpZone(std::shared_ptr attacker, std::shared_ptr target); + static bool isProtected(std::shared_ptr attacker, std::shared_ptr target); + static bool isPlayerCombat(std::shared_ptr target); static CombatType_t ConditionToDamageType(ConditionType_t type); static ConditionType_t DamageToConditionType(CombatType_t type); - static ReturnValue canTargetCreature(Player* attacker, Creature* target); - static ReturnValue canDoCombat(Creature* caster, Tile* tile, bool aggressive); - static ReturnValue canDoCombat(Creature* attacker, Creature* target, bool aggressive); - static void postCombatEffects(Creature* caster, const Position &origin, const Position &pos, const CombatParams ¶ms); + static ReturnValue canTargetCreature(std::shared_ptr attacker, std::shared_ptr target); + static ReturnValue canDoCombat(std::shared_ptr caster, std::shared_ptr tile, bool aggressive); + static ReturnValue canDoCombat(std::shared_ptr attacker, std::shared_ptr target, bool aggressive); + static void postCombatEffects(std::shared_ptr caster, const Position &origin, const Position &pos, const CombatParams ¶ms); - static void addDistanceEffect(Creature* caster, const Position &fromPos, const Position &toPos, uint16_t effect); + static void addDistanceEffect(std::shared_ptr caster, const Position &fromPos, const Position &toPos, uint16_t effect); - bool doCombat(Creature* caster, Creature* target) const; - bool doCombat(Creature* caster, Creature* target, const Position &origin) const; - bool doCombat(Creature* caster, const Position &pos) const; + bool doCombat(std::shared_ptr caster, std::shared_ptr target) const; + bool doCombat(std::shared_ptr caster, std::shared_ptr target, const Position &origin) const; + bool doCombat(std::shared_ptr caster, const Position &pos) const; bool setCallback(CallBackParam_t key); CallBack* getCallback(CallBackParam_t key); @@ -300,7 +300,7 @@ class Combat { params.conditionList.emplace_front(condition); } void setPlayerCombatValues(formulaType_t formulaType, double mina, double minb, double maxa, double maxb); - void postCombatEffects(Creature* caster, const Position &origin, const Position &pos) const { + void postCombatEffects(std::shared_ptr caster, const Position &origin, const Position &pos) const { postCombatEffects(caster, origin, pos, params); } @@ -324,20 +324,20 @@ class Combat { private: static void doChainEffect(const Position &origin, const Position &pos, uint8_t effect); - static std::vector>> pickChainTargets(Creature* caster, const CombatParams ¶ms, uint8_t chainDistance, uint8_t maxTargets, bool aggressive, bool backtracking, Creature* initialTarget = nullptr); - static bool isValidChainTarget(Creature* caster, Creature* currentTarget, Creature* potentialTarget, const CombatParams ¶ms, bool aggressive); + static std::vector>> pickChainTargets(std::shared_ptr caster, const CombatParams ¶ms, uint8_t chainDistance, uint8_t maxTargets, bool aggressive, bool backtracking, std::shared_ptr initialTarget = nullptr); + static bool isValidChainTarget(std::shared_ptr caster, std::shared_ptr currentTarget, std::shared_ptr potentialTarget, const CombatParams ¶ms, bool aggressive); - static void doCombatDefault(Creature* caster, Creature* target, const CombatParams ¶ms); + static void doCombatDefault(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms); - static void doCombatHealth(Creature* caster, Creature* target, const Position &origin, CombatDamage &damage, const CombatParams ¶ms); - static void doCombatMana(Creature* caster, Creature* target, const Position &origin, CombatDamage &damage, const CombatParams ¶ms); - static void doCombatDefault(Creature* caster, Creature* target, const Position &origin, const CombatParams ¶ms); + static void doCombatHealth(std::shared_ptr caster, std::shared_ptr target, const Position &origin, CombatDamage &damage, const CombatParams ¶ms); + static void doCombatMana(std::shared_ptr caster, std::shared_ptr target, const Position &origin, CombatDamage &damage, const CombatParams ¶ms); + static void doCombatDefault(std::shared_ptr caster, std::shared_ptr target, const Position &origin, const CombatParams ¶ms); - static void CombatFunc(Creature* caster, const Position &origin, const Position &pos, const AreaCombat* area, const CombatParams ¶ms, CombatFunction func, CombatDamage* data); + static void CombatFunc(std::shared_ptr caster, const Position &origin, const Position &pos, const AreaCombat* area, const CombatParams ¶ms, CombatFunction func, CombatDamage* data); - static void CombatHealthFunc(Creature* caster, Creature* target, const CombatParams ¶ms, CombatDamage* data); - static CombatDamage applyImbuementElementalDamage(Player* attackerPlayer, Item* item, CombatDamage damage); - static void CombatManaFunc(Creature* caster, Creature* target, const CombatParams ¶ms, CombatDamage* damage); + static void CombatHealthFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); + static CombatDamage applyImbuementElementalDamage(std::shared_ptr attackerPlayer, std::shared_ptr item, CombatDamage damage); + static void CombatManaFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* damage); /** * @brief Checks if a fear condition can be applied to a player. * @@ -352,12 +352,12 @@ class Combat { * @param player Pointer to the Player object to be checked. * @return true if the fear condition can be applied, false otherwise. */ - static bool checkFearConditionAffected(Player* player); - static void CombatConditionFunc(Creature* caster, Creature* target, const CombatParams ¶ms, CombatDamage* data); - static void CombatDispelFunc(Creature* caster, Creature* target, const CombatParams ¶ms, CombatDamage* data); - static void CombatNullFunc(Creature* caster, Creature* target, const CombatParams ¶ms, CombatDamage* data); + static bool checkFearConditionAffected(std::shared_ptr player); + static void CombatConditionFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); + static void CombatDispelFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); + static void CombatNullFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); - static void combatTileEffects(const SpectatorHashSet &spectators, Creature* caster, Tile* tile, const CombatParams ¶ms); + static void combatTileEffects(const SpectatorHashSet &spectators, std::shared_ptr caster, std::shared_ptr tile, const CombatParams ¶ms); /** * @brief Calculate the level formula for combat. @@ -367,10 +367,10 @@ class Combat { * @param damage The combat damage. * @return The calculated level formula. */ - int32_t getLevelFormula(const Player* player, const std::shared_ptr wheelSpell, const CombatDamage &damage) const; - CombatDamage getCombatDamage(Creature* creature, Creature* target) const; + int32_t getLevelFormula(std::shared_ptr player, const std::shared_ptr wheelSpell, const CombatDamage &damage) const; + CombatDamage getCombatDamage(std::shared_ptr creature, std::shared_ptr target) const; - bool doCombatChain(Creature* caster, Creature* target, bool aggressive) const; + bool doCombatChain(std::shared_ptr caster, std::shared_ptr target, bool aggressive) const; // configureable CombatParams params; @@ -393,11 +393,8 @@ class MagicField final : public Item { explicit MagicField(uint16_t type) : Item(type), createTime(OTSYS_TIME()) { } - MagicField* getMagicField() override { - return this; - } - const MagicField* getMagicField() const override { - return this; + std::shared_ptr getMagicField() override { + return static_self_cast(); } bool isReplaceable() const { @@ -414,7 +411,7 @@ class MagicField final : public Item { } return 0; } - void onStepInField(Creature &creature); + void onStepInField(const std::shared_ptr &creature); private: int64_t createTime; diff --git a/src/creatures/combat/condition.cpp b/src/creatures/combat/condition.cpp index f7c1f4810a0..b4e09da0d58 100644 --- a/src/creatures/combat/condition.cpp +++ b/src/creatures/combat/condition.cpp @@ -166,7 +166,7 @@ void Condition::setTicks(int32_t newTicks) { endTime = ticks + OTSYS_TIME(); } -bool Condition::executeCondition(Creature* creature, int32_t interval) { +bool Condition::executeCondition(std::shared_ptr creature, int32_t interval) { if (ticks == -1) { return true; } @@ -297,7 +297,7 @@ Condition* Condition::createCondition(PropStream &propStream) { return createCondition(static_cast(id), static_cast(type), ticks, 0, buff != 0, subId); } -bool Condition::startCondition(Creature*) { +bool Condition::startCondition(std::shared_ptr) { if (ticks > 0) { endTime = ticks + OTSYS_TIME(); } @@ -352,19 +352,19 @@ bool Condition::updateCondition(const Condition* addCondition) { * ConditionGeneric */ -bool ConditionGeneric::startCondition(Creature* creature) { +bool ConditionGeneric::startCondition(std::shared_ptr creature) { return Condition::startCondition(creature); } -bool ConditionGeneric::executeCondition(Creature* creature, int32_t interval) { +bool ConditionGeneric::executeCondition(std::shared_ptr creature, int32_t interval) { return Condition::executeCondition(creature, interval); } -void ConditionGeneric::endCondition(Creature*) { +void ConditionGeneric::endCondition(std::shared_ptr) { // } -void ConditionGeneric::addCondition(Creature* creature, const Condition* addCondition) { +void ConditionGeneric::addCondition(std::shared_ptr creature, const Condition* addCondition) { if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); @@ -401,7 +401,7 @@ uint32_t ConditionGeneric::getIcons() const { * ConditionAttributes */ -void ConditionAttributes::addCondition(Creature* creature, const Condition* addCondition) { +void ConditionAttributes::addCondition(std::shared_ptr creature, const Condition* addCondition) { if (!creature) { return; } @@ -437,7 +437,7 @@ void ConditionAttributes::addCondition(Creature* creature, const Condition* addC updateCharmChanceModifier(creature); disableDefense = conditionAttrs.disableDefense; - if (Player* player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { updatePercentSkills(player); updateSkills(player); updatePercentStats(player); @@ -527,7 +527,7 @@ void ConditionAttributes::serialize(PropWriteStream &propWriteStream) { propWriteStream.write(charmChanceModifier); } -bool ConditionAttributes::startCondition(Creature* creature) { +bool ConditionAttributes::startCondition(std::shared_ptr creature) { if (!Condition::startCondition(creature)) { return false; } @@ -541,7 +541,7 @@ bool ConditionAttributes::startCondition(Creature* creature) { updatePercentIncreases(creature); updateIncreases(creature); updateCharmChanceModifier(creature); - if (Player* player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { updatePercentSkills(player); updateSkills(player); updatePercentStats(player); @@ -551,7 +551,7 @@ bool ConditionAttributes::startCondition(Creature* creature) { return true; } -void ConditionAttributes::updatePercentStats(Player* player) { +void ConditionAttributes::updatePercentStats(std::shared_ptr player) { for (int32_t i = STAT_FIRST; i <= STAT_LAST; ++i) { if (statsPercent[i] == 0) { continue; @@ -577,7 +577,7 @@ void ConditionAttributes::updatePercentStats(Player* player) { } } -void ConditionAttributes::updateStats(Player* player) { +void ConditionAttributes::updateStats(std::shared_ptr player) { bool needUpdate = false; for (int32_t i = STAT_FIRST; i <= STAT_LAST; ++i) { @@ -593,7 +593,7 @@ void ConditionAttributes::updateStats(Player* player) { } } -void ConditionAttributes::updatePercentSkills(Player* player) { +void ConditionAttributes::updatePercentSkills(std::shared_ptr player) { for (uint8_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { skills_t skill = static_cast(i); if (skillsPercent[skill] == 0) { @@ -605,7 +605,7 @@ void ConditionAttributes::updatePercentSkills(Player* player) { } } -void ConditionAttributes::updateSkills(Player* player) { +void ConditionAttributes::updateSkills(std::shared_ptr player) { bool needUpdateSkills = false; for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { @@ -620,7 +620,7 @@ void ConditionAttributes::updateSkills(Player* player) { } } -void ConditionAttributes::updatePercentAbsorbs(const Creature* creature) { +void ConditionAttributes::updatePercentAbsorbs(std::shared_ptr creature) { for (uint8_t i = 0; i < COMBAT_COUNT; i++) { auto value = getAbsorbPercentByIndex(i); if (value == 0) { @@ -630,7 +630,7 @@ void ConditionAttributes::updatePercentAbsorbs(const Creature* creature) { } } -void ConditionAttributes::updateAbsorbs(Creature* creature) const { +void ConditionAttributes::updateAbsorbs(std::shared_ptr creature) const { for (uint8_t i = 0; i < COMBAT_COUNT; i++) { auto value = getAbsorbByIndex(i); if (value == 0) { @@ -641,7 +641,7 @@ void ConditionAttributes::updateAbsorbs(Creature* creature) const { } } -void ConditionAttributes::updatePercentIncreases(const Creature* creature) { +void ConditionAttributes::updatePercentIncreases(std::shared_ptr creature) { for (uint8_t i = 0; i < COMBAT_COUNT; i++) { auto increasePercentValue = getIncreasePercentById(i); if (increasePercentValue == 0) { @@ -651,7 +651,7 @@ void ConditionAttributes::updatePercentIncreases(const Creature* creature) { } } -void ConditionAttributes::updateIncreases(Creature* creature) const { +void ConditionAttributes::updateIncreases(std::shared_ptr creature) const { for (uint8_t i = 0; i < COMBAT_COUNT; i++) { auto increaseValue = getIncreaseByIndex(i); if (increaseValue == 0) { @@ -661,11 +661,11 @@ void ConditionAttributes::updateIncreases(Creature* creature) const { } } -void ConditionAttributes::updateCharmChanceModifier(Creature* creature) const { +void ConditionAttributes::updateCharmChanceModifier(std::shared_ptr creature) const { creature->setCharmChanceModifier(creature->getCharmChanceModifier() + charmChanceModifier); } -void ConditionAttributes::updatePercentBuffs(Creature* creature) { +void ConditionAttributes::updatePercentBuffs(std::shared_ptr creature) { for (int32_t i = BUFF_FIRST; i <= BUFF_LAST; ++i) { if (buffsPercent[i] == 0) { continue; @@ -676,7 +676,7 @@ void ConditionAttributes::updatePercentBuffs(Creature* creature) { } } -void ConditionAttributes::updateBuffs(Creature* creature) { +void ConditionAttributes::updateBuffs(std::shared_ptr creature) { bool needUpdate = false; for (int32_t i = BUFF_FIRST; i <= BUFF_LAST; ++i) { if (buffs[i]) { @@ -689,12 +689,12 @@ void ConditionAttributes::updateBuffs(Creature* creature) { } } -bool ConditionAttributes::executeCondition(Creature* creature, int32_t interval) { +bool ConditionAttributes::executeCondition(std::shared_ptr creature, int32_t interval) { return ConditionGeneric::executeCondition(creature, interval); } -void ConditionAttributes::endCondition(Creature* creature) { - Player* player = creature->getPlayer(); +void ConditionAttributes::endCondition(std::shared_ptr creature) { + std::shared_ptr player = creature->getPlayer(); if (player) { bool needUpdate = false; @@ -1096,24 +1096,24 @@ void ConditionAttributes::setIncreasePercent(uint8_t index, int32_t value) { * ConditionRegeneration */ -bool ConditionRegeneration::startCondition(Creature* creature) { +bool ConditionRegeneration::startCondition(std::shared_ptr creature) { if (!Condition::startCondition(creature)) { return false; } - if (Player* player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->sendStats(); } return true; } -void ConditionRegeneration::endCondition(Creature* creature) { - if (Player* player = creature->getPlayer()) { +void ConditionRegeneration::endCondition(std::shared_ptr creature) { + if (std::shared_ptr player = creature->getPlayer()) { player->sendStats(); } } -void ConditionRegeneration::addCondition(Creature* creature, const Condition* addCondition) { +void ConditionRegeneration::addCondition(std::shared_ptr creature, const Condition* addCondition) { if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); @@ -1126,7 +1126,7 @@ void ConditionRegeneration::addCondition(Creature* creature, const Condition* ad manaGain = conditionRegen.manaGain; } - if (Player* player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->sendStats(); } } @@ -1160,10 +1160,10 @@ void ConditionRegeneration::serialize(PropWriteStream &propWriteStream) { propWriteStream.write(manaGain); } -bool ConditionRegeneration::executeCondition(Creature* creature, int32_t interval) { +bool ConditionRegeneration::executeCondition(std::shared_ptr creature, int32_t interval) { internalHealthTicks += interval; internalManaTicks += interval; - Player* player = creature->getPlayer(); + auto player = creature->getPlayer(); int32_t PlayerdailyStreak = 0; if (player) { PlayerdailyStreak = player->getStorageValue(STORAGEVALUE_DAILYREWARD); @@ -1196,7 +1196,7 @@ bool ConditionRegeneration::executeCondition(Creature* creature, int32_t interva if (!spectators.empty()) { message.type = MESSAGE_HEALED_OTHERS; message.text = player->getName() + " was healed for " + healString; - for (Creature* spectator : spectators) { + for (std::shared_ptr spectator : spectators) { spectator->getPlayer()->sendTextMessage(message); } } @@ -1244,8 +1244,8 @@ bool ConditionRegeneration::setParam(ConditionParam_t param, int32_t value) { } } -uint32_t ConditionRegeneration::getHealthTicks(Creature* creature) const { - const Player* player = creature->getPlayer(); +uint32_t ConditionRegeneration::getHealthTicks(std::shared_ptr creature) const { + std::shared_ptr player = creature->getPlayer(); if (player != nullptr && isBuff) { return healthTicks / g_configManager().getFloat(RATE_SPELL_COOLDOWN); @@ -1254,8 +1254,8 @@ uint32_t ConditionRegeneration::getHealthTicks(Creature* creature) const { return healthTicks; } -uint32_t ConditionRegeneration::getManaTicks(Creature* creature) const { - const Player* player = creature->getPlayer(); +uint32_t ConditionRegeneration::getManaTicks(std::shared_ptr creature) const { + std::shared_ptr player = creature->getPlayer(); if (player != nullptr && isBuff) { return manaTicks / g_configManager().getFloat(RATE_SPELL_COOLDOWN); @@ -1268,7 +1268,7 @@ uint32_t ConditionRegeneration::getManaTicks(Creature* creature) const { * ConditionManaShield */ -bool ConditionManaShield::startCondition(Creature* creature) { +bool ConditionManaShield::startCondition(std::shared_ptr creature) { if (!Condition::startCondition(creature)) { return false; } @@ -1276,22 +1276,22 @@ bool ConditionManaShield::startCondition(Creature* creature) { creature->setManaShield(manaShield); creature->setMaxManaShield(manaShield); - if (Player* player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->sendStats(); } return true; } -void ConditionManaShield::endCondition(Creature* creature) { +void ConditionManaShield::endCondition(std::shared_ptr creature) { creature->setManaShield(0); creature->setMaxManaShield(0); - if (Player* player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->sendStats(); } } -void ConditionManaShield::addCondition(Creature* creature, const Condition* addCondition) { +void ConditionManaShield::addCondition(std::shared_ptr creature, const Condition* addCondition) { endCondition(creature); setTicks(addCondition->getTicks()); @@ -1301,7 +1301,7 @@ void ConditionManaShield::addCondition(Creature* creature, const Condition* addC creature->setManaShield(manaShield); creature->setMaxManaShield(manaShield); - if (Player* player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->sendStats(); } } @@ -1346,7 +1346,7 @@ uint32_t ConditionManaShield::getIcons() const { * ConditionSoul */ -void ConditionSoul::addCondition(Creature*, const Condition* addCondition) { +void ConditionSoul::addCondition(std::shared_ptr, const Condition* addCondition) { if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); @@ -1376,10 +1376,10 @@ void ConditionSoul::serialize(PropWriteStream &propWriteStream) { propWriteStream.write(soulTicks); } -bool ConditionSoul::executeCondition(Creature* creature, int32_t interval) { +bool ConditionSoul::executeCondition(std::shared_ptr creature, int32_t interval) { internalSoulTicks += interval; - if (Player* player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { if (player->getZoneType() != ZONE_PROTECTION) { if (internalSoulTicks >= soulTicks) { internalSoulTicks = 0; @@ -1571,7 +1571,7 @@ bool ConditionDamage::init() { return !damageList.empty(); } -bool ConditionDamage::startCondition(Creature* creature) { +bool ConditionDamage::startCondition(std::shared_ptr creature) { if (!Condition::startCondition(creature)) { return false; } @@ -1589,7 +1589,7 @@ bool ConditionDamage::startCondition(Creature* creature) { return true; } -bool ConditionDamage::executeCondition(Creature* creature, int32_t interval) { +bool ConditionDamage::executeCondition(std::shared_ptr creature, int32_t interval) { if (periodDamage != 0) { periodDamageTick += interval; @@ -1643,7 +1643,7 @@ bool ConditionDamage::getNextDamage(int32_t &damage) { return false; } -bool ConditionDamage::doDamage(Creature* creature, int32_t healthChange) { +bool ConditionDamage::doDamage(std::shared_ptr creature, int32_t healthChange) { if (creature->isSuppress(getType())) { return true; } @@ -1653,7 +1653,7 @@ bool ConditionDamage::doDamage(Creature* creature, int32_t healthChange) { damage.primary.value = healthChange; damage.primary.type = Combat::ConditionToDamageType(conditionType); - Creature* attacker = g_game().getCreatureByID(owner); + std::shared_ptr attacker = g_game().getCreatureByID(owner); if (field && creature->getPlayer() && attacker && attacker->getPlayer()) { damage.primary.value = static_cast(std::round(damage.primary.value / 2.)); } @@ -1676,11 +1676,11 @@ bool ConditionDamage::doDamage(Creature* creature, int32_t healthChange) { return g_game().combatChangeHealth(attacker, creature, damage); } -void ConditionDamage::endCondition(Creature*) { +void ConditionDamage::endCondition(std::shared_ptr) { // } -void ConditionDamage::addCondition(Creature* creature, const Condition* addCondition) { +void ConditionDamage::addCondition(std::shared_ptr creature, const Condition* addCondition) { if (addCondition->getType() != conditionType) { return; } @@ -1801,7 +1801,7 @@ void ConditionDamage::generateDamageList(int32_t amount, int32_t start, std::lis /** * ConditionFeared */ -bool ConditionFeared::isStuck(Creature* creature, Position pos) const { +bool ConditionFeared::isStuck(std::shared_ptr creature, Position pos) const { for (Direction dir : m_directionsVector) { if (canWalkTo(creature, pos, dir)) { return false; @@ -1811,7 +1811,7 @@ bool ConditionFeared::isStuck(Creature* creature, Position pos) const { return true; } -bool ConditionFeared::getRandomDirection(Creature* creature, Position pos) { +bool ConditionFeared::getRandomDirection(std::shared_ptr creature, Position pos) { static std::vector directions { DIRECTION_NORTH, DIRECTION_NORTHEAST, @@ -1834,16 +1834,16 @@ bool ConditionFeared::getRandomDirection(Creature* creature, Position pos) { return false; } -bool ConditionFeared::canWalkTo(const Creature* creature, Position pos, Direction moveDirection) const { +bool ConditionFeared::canWalkTo(std::shared_ptr creature, Position pos, Direction moveDirection) const { pos = getNextPosition(moveDirection, pos); if (!creature) { g_logger().error("[{}] creature is nullptr", __FUNCTION__); return false; } - const Tile* tile = g_game().map.getTile(pos); - if (tile && tile->getTopVisibleCreature(creature) == nullptr && tile->queryAdd(0, *creature, 1, FLAG_PATHFINDING) == RETURNVALUE_NOERROR) { - const MagicField* field = tile->getFieldItem(); + auto tile = g_game().map.getTile(pos); + if (tile && tile->getTopVisibleCreature(creature) == nullptr && tile->queryAdd(0, creature, 1, FLAG_PATHFINDING) == RETURNVALUE_NOERROR) { + std::shared_ptr field = tile->getFieldItem(); if (field && !field->isBlocking() && field->getDamage() != 0) { return false; } @@ -1853,7 +1853,7 @@ bool ConditionFeared::canWalkTo(const Creature* creature, Position pos, Directio return false; } -bool ConditionFeared::getFleeDirection(Creature* creature) { +bool ConditionFeared::getFleeDirection(std::shared_ptr creature) { Position creaturePos = creature->getPosition(); int_fast32_t offx = Position::getOffsetX(creaturePos, fleeingFromPos); @@ -1929,7 +1929,7 @@ bool ConditionFeared::getFleeDirection(Creature* creature) { return false; } -bool ConditionFeared::getFleePath(Creature* creature, const Position &pos, std::forward_list &dirList) { +bool ConditionFeared::getFleePath(std::shared_ptr creature, const Position &pos, std::forward_list &dirList) { const std::vector walkSize { 15, 9, 3, 1 }; bool found = false; std::ptrdiff_t found_size = 0; @@ -2021,14 +2021,14 @@ bool ConditionFeared::setPositionParam(ConditionParam_t param, const Position &p return false; } -bool ConditionFeared::startCondition(Creature* creature) { +bool ConditionFeared::startCondition(std::shared_ptr creature) { g_logger().debug("[ConditionFeared::executeCondition] Condition started for {}", creature->getName()); getFleeDirection(creature); g_logger().debug("[ConditionFeared::executeCondition] Flee from {}", fleeingFromPos.toString()); return Condition::startCondition(creature); } -bool ConditionFeared::executeCondition(Creature* creature, int32_t interval) { +bool ConditionFeared::executeCondition(std::shared_ptr creature, int32_t interval) { Position currentPos = creature->getPosition(); std::forward_list listDir; @@ -2048,18 +2048,18 @@ bool ConditionFeared::executeCondition(Creature* creature, int32_t interval) { return Condition::executeCondition(creature, interval); } -void ConditionFeared::endCondition(Creature* creature) { +void ConditionFeared::endCondition(std::shared_ptr creature) { creature->stopEventWalk(); /* * After a player is feared there's a 10 seconds before he can feared again. */ - Player* player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->setImmuneFear(); } } -void ConditionFeared::addCondition(Creature*, const Condition* addCondition) { +void ConditionFeared::addCondition(std::shared_ptr, const Condition* addCondition) { if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); } @@ -2139,7 +2139,7 @@ void ConditionSpeed::serialize(PropWriteStream &propWriteStream) { propWriteStream.write(maxb); } -bool ConditionSpeed::startCondition(Creature* creature) { +bool ConditionSpeed::startCondition(std::shared_ptr creature) { if (!Condition::startCondition(creature)) { return false; } @@ -2154,15 +2154,15 @@ bool ConditionSpeed::startCondition(Creature* creature) { return true; } -bool ConditionSpeed::executeCondition(Creature* creature, int32_t interval) { +bool ConditionSpeed::executeCondition(std::shared_ptr creature, int32_t interval) { return Condition::executeCondition(creature, interval); } -void ConditionSpeed::endCondition(Creature* creature) { +void ConditionSpeed::endCondition(std::shared_ptr creature) { g_game().changeSpeed(creature, -speedDelta); } -void ConditionSpeed::addCondition(Creature* creature, const Condition* addCondition) { +void ConditionSpeed::addCondition(std::shared_ptr creature, const Condition* addCondition) { if (conditionType != addCondition->getType()) { return; } @@ -2215,7 +2215,7 @@ uint32_t ConditionSpeed::getIcons() const { * ConditionInvisible */ -bool ConditionInvisible::startCondition(Creature* creature) { +bool ConditionInvisible::startCondition(std::shared_ptr creature) { if (!Condition::startCondition(creature)) { return false; } @@ -2224,7 +2224,7 @@ bool ConditionInvisible::startCondition(Creature* creature) { return true; } -void ConditionInvisible::endCondition(Creature* creature) { +void ConditionInvisible::endCondition(std::shared_ptr creature) { if (!creature->isInvisible()) { g_game().internalCreatureChangeVisible(creature, true); } @@ -2256,7 +2256,7 @@ void ConditionOutfit::serialize(PropWriteStream &propWriteStream) { propWriteStream.write(outfit); } -bool ConditionOutfit::startCondition(Creature* creature) { +bool ConditionOutfit::startCondition(std::shared_ptr creature) { if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && outfit.lookType != 0 && !g_game().isLookTypeRegistered(outfit.lookType)) { g_logger().warn("[ConditionOutfit::startCondition] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", outfit.lookType); return false; @@ -2280,15 +2280,15 @@ bool ConditionOutfit::startCondition(Creature* creature) { return true; } -bool ConditionOutfit::executeCondition(Creature* creature, int32_t interval) { +bool ConditionOutfit::executeCondition(std::shared_ptr creature, int32_t interval) { return Condition::executeCondition(creature, interval); } -void ConditionOutfit::endCondition(Creature* creature) { +void ConditionOutfit::endCondition(std::shared_ptr creature) { g_game().internalCreatureChangeOutfit(creature, creature->getDefaultOutfit()); } -void ConditionOutfit::addCondition(Creature* creature, const Condition* addCondition) { +void ConditionOutfit::addCondition(std::shared_ptr creature, const Condition* addCondition) { if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && outfit.lookType != 0 && !g_game().isLookTypeRegistered(outfit.lookType)) { g_logger().warn("[ConditionOutfit::addCondition] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", outfit.lookType); return; @@ -2318,7 +2318,7 @@ void ConditionOutfit::addCondition(Creature* creature, const Condition* addCondi * ConditionLight */ -bool ConditionLight::startCondition(Creature* creature) { +bool ConditionLight::startCondition(std::shared_ptr creature) { if (!Condition::startCondition(creature)) { return false; } @@ -2330,7 +2330,7 @@ bool ConditionLight::startCondition(Creature* creature) { return true; } -bool ConditionLight::executeCondition(Creature* creature, int32_t interval) { +bool ConditionLight::executeCondition(std::shared_ptr creature, int32_t interval) { internalLightTicks += interval; if (internalLightTicks >= lightChangeInterval) { @@ -2347,12 +2347,12 @@ bool ConditionLight::executeCondition(Creature* creature, int32_t interval) { return Condition::executeCondition(creature, interval); } -void ConditionLight::endCondition(Creature* creature) { +void ConditionLight::endCondition(std::shared_ptr creature) { creature->setNormalCreatureLight(); g_game().changeLight(creature); } -void ConditionLight::addCondition(Creature* creature, const Condition* condition) { +void ConditionLight::addCondition(std::shared_ptr creature, const Condition* condition) { if (updateCondition(condition)) { setTicks(condition->getTicks()); @@ -2434,12 +2434,12 @@ void ConditionLight::serialize(PropWriteStream &propWriteStream) { * ConditionSpellCooldown */ -void ConditionSpellCooldown::addCondition(Creature* creature, const Condition* addCondition) { +void ConditionSpellCooldown::addCondition(std::shared_ptr creature, const Condition* addCondition) { if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); if (subId != 0 && ticks > 0) { - Player* player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->sendSpellCooldown(subId, ticks); } @@ -2447,13 +2447,13 @@ void ConditionSpellCooldown::addCondition(Creature* creature, const Condition* a } } -bool ConditionSpellCooldown::startCondition(Creature* creature) { +bool ConditionSpellCooldown::startCondition(std::shared_ptr creature) { if (!Condition::startCondition(creature)) { return false; } if (subId != 0 && ticks > 0) { - Player* player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->sendSpellCooldown(subId, ticks); } @@ -2465,12 +2465,12 @@ bool ConditionSpellCooldown::startCondition(Creature* creature) { * ConditionSpellGroupCooldown */ -void ConditionSpellGroupCooldown::addCondition(Creature* creature, const Condition* addCondition) { +void ConditionSpellGroupCooldown::addCondition(std::shared_ptr creature, const Condition* addCondition) { if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); if (subId != 0 && ticks > 0) { - Player* player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->sendSpellGroupCooldown(static_cast(subId), ticks); } @@ -2478,13 +2478,13 @@ void ConditionSpellGroupCooldown::addCondition(Creature* creature, const Conditi } } -bool ConditionSpellGroupCooldown::startCondition(Creature* creature) { +bool ConditionSpellGroupCooldown::startCondition(std::shared_ptr creature) { if (!Condition::startCondition(creature)) { return false; } if (subId != 0 && ticks > 0) { - Player* player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->sendSpellGroupCooldown(static_cast(subId), ticks); } diff --git a/src/creatures/combat/condition.hpp b/src/creatures/combat/condition.hpp index 2d1f08a9b7e..d2704c4c49d 100644 --- a/src/creatures/combat/condition.hpp +++ b/src/creatures/combat/condition.hpp @@ -24,10 +24,10 @@ class Condition { subId(initSubId), ticks(initTicks), conditionType(initType), id(initId), isBuff(initBuff) { } virtual ~Condition() = default; - virtual bool startCondition(Creature* creature); - virtual bool executeCondition(Creature* creature, int32_t interval); - virtual void endCondition(Creature* creature) = 0; - virtual void addCondition(Creature* creature, const Condition* condition) = 0; + virtual bool startCondition(std::shared_ptr creature); + virtual bool executeCondition(std::shared_ptr creature, int32_t interval); + virtual void endCondition(std::shared_ptr creature) = 0; + virtual void addCondition(std::shared_ptr creature, const Condition* condition) = 0; virtual uint32_t getIcons() const; ConditionId_t getId() const { return id; @@ -87,10 +87,10 @@ class ConditionGeneric : public Condition { ConditionGeneric(ConditionId_t initId, ConditionType_t initType, int32_t initTicks, bool initBuff = false, uint32_t initSubId = 0) : Condition(initId, initType, initTicks, initBuff, initSubId) { } - bool startCondition(Creature* creature) override; - bool executeCondition(Creature* creature, int32_t interval) override; - void endCondition(Creature* creature) override; - void addCondition(Creature* creature, const Condition* condition) override; + bool startCondition(std::shared_ptr creature) override; + bool executeCondition(std::shared_ptr creature, int32_t interval) override; + void endCondition(std::shared_ptr creature) override; + void addCondition(std::shared_ptr creature, const Condition* condition) override; uint32_t getIcons() const override; ConditionGeneric* clone() const override { @@ -103,10 +103,10 @@ class ConditionAttributes final : public ConditionGeneric { ConditionAttributes(ConditionId_t initId, ConditionType_t initType, int32_t initTicks, bool initBuff = false, uint32_t initSubId = 0) : ConditionGeneric(initId, initType, initTicks, initBuff, initSubId) { } - bool startCondition(Creature* creature) final; - bool executeCondition(Creature* creature, int32_t interval) final; - void endCondition(Creature* creature) final; - void addCondition(Creature* creature, const Condition* condition) final; + bool startCondition(std::shared_ptr creature) final; + bool executeCondition(std::shared_ptr creature, int32_t interval) final; + void endCondition(std::shared_ptr creature) final; + void addCondition(std::shared_ptr creature, const Condition* condition) final; bool setParam(ConditionParam_t param, int32_t value) final; @@ -150,19 +150,19 @@ class ConditionAttributes final : public ConditionGeneric { bool disableDefense = false; - void updatePercentStats(Player* player); - void updateStats(Player* player); - void updatePercentSkills(Player* player); - void updateSkills(Player* player); - void updateBuffs(Creature* creature); + void updatePercentStats(std::shared_ptr player); + void updateStats(std::shared_ptr player); + void updatePercentSkills(std::shared_ptr player); + void updateSkills(std::shared_ptr player); + void updateBuffs(std::shared_ptr creature); // 12.72 mechanics - void updatePercentAbsorbs(const Creature* creature); - void updateAbsorbs(Creature* creature) const; - void updatePercentIncreases(const Creature* creature); - void updateIncreases(Creature* creature) const; - void updateCharmChanceModifier(Creature* creature) const; - void updatePercentBuffs(Creature* creature); + void updatePercentAbsorbs(std::shared_ptr creature); + void updateAbsorbs(std::shared_ptr creature) const; + void updatePercentIncreases(std::shared_ptr creature); + void updateIncreases(std::shared_ptr creature) const; + void updateCharmChanceModifier(std::shared_ptr creature) const; + void updatePercentBuffs(std::shared_ptr creature); }; class ConditionRegeneration final : public ConditionGeneric { @@ -170,15 +170,15 @@ class ConditionRegeneration final : public ConditionGeneric { ConditionRegeneration(ConditionId_t initId, ConditionType_t initType, int32_t iniTicks, bool initBuff = false, uint32_t initSubId = 0) : ConditionGeneric(initId, initType, iniTicks, initBuff, initSubId) { } - bool startCondition(Creature* creature) override; - void endCondition(Creature* creature) override; - void addCondition(Creature* creature, const Condition* addCondition) override; - bool executeCondition(Creature* creature, int32_t interval) override; + bool startCondition(std::shared_ptr creature) override; + void endCondition(std::shared_ptr creature) override; + void addCondition(std::shared_ptr creature, const Condition* addCondition) override; + bool executeCondition(std::shared_ptr creature, int32_t interval) override; bool setParam(ConditionParam_t param, int32_t value) override; - uint32_t getHealthTicks(Creature* creature) const; - uint32_t getManaTicks(Creature* creature) const; + uint32_t getHealthTicks(std::shared_ptr creature) const; + uint32_t getManaTicks(std::shared_ptr creature) const; ConditionRegeneration* clone() const override { return new ConditionRegeneration(*this); @@ -203,9 +203,9 @@ class ConditionManaShield final : public Condition { ConditionManaShield(ConditionId_t initId, ConditionType_t initType, int32_t iniTicks, bool initBuff = false, uint32_t initSubId = 0) : Condition(initId, initType, iniTicks, initBuff, initSubId) { } - bool startCondition(Creature* creature) override; - void endCondition(Creature* creature) override; - void addCondition(Creature* creature, const Condition* addCondition) override; + bool startCondition(std::shared_ptr creature) override; + void endCondition(std::shared_ptr creature) override; + void addCondition(std::shared_ptr creature, const Condition* addCondition) override; uint32_t getIcons() const override; bool setParam(ConditionParam_t param, int32_t value) override; @@ -227,8 +227,8 @@ class ConditionSoul final : public ConditionGeneric { ConditionSoul(ConditionId_t initId, ConditionType_t initType, int32_t iniTicks, bool initBuff = false, uint32_t initSubId = 0) : ConditionGeneric(initId, initType, iniTicks, initBuff, initSubId) { } - void addCondition(Creature* creature, const Condition* addCondition) override; - bool executeCondition(Creature* creature, int32_t interval) override; + void addCondition(std::shared_ptr creature, const Condition* addCondition) override; + bool executeCondition(std::shared_ptr creature, int32_t interval) override; bool setParam(ConditionParam_t param, int32_t value) override; @@ -251,8 +251,8 @@ class ConditionInvisible final : public ConditionGeneric { ConditionInvisible(ConditionId_t initId, ConditionType_t initType, int32_t initTicks, bool initBuff = false, uint32_t initSubId = 0) : ConditionGeneric(initId, initType, initTicks, initBuff, initSubId) { } - bool startCondition(Creature* creature) override; - void endCondition(Creature* creature) override; + bool startCondition(std::shared_ptr creature) override; + void endCondition(std::shared_ptr creature) override; ConditionInvisible* clone() const override { return new ConditionInvisible(*this); @@ -267,10 +267,10 @@ class ConditionDamage final : public Condition { static void generateDamageList(int32_t amount, int32_t start, std::list &list); - bool startCondition(Creature* creature) override; - bool executeCondition(Creature* creature, int32_t interval) override; - void endCondition(Creature* creature) override; - void addCondition(Creature* creature, const Condition* condition) override; + bool startCondition(std::shared_ptr creature) override; + bool executeCondition(std::shared_ptr creature, int32_t interval) override; + void endCondition(std::shared_ptr creature) override; + void addCondition(std::shared_ptr creature, const Condition* condition) override; uint32_t getIcons() const override; ConditionDamage* clone() const override { @@ -307,7 +307,7 @@ class ConditionDamage final : public Condition { std::list damageList; bool getNextDamage(int32_t &damage); - bool doDamage(Creature* creature, int32_t healthChange); + bool doDamage(std::shared_ptr creature, int32_t healthChange); bool updateCondition(const Condition* addCondition) override; }; @@ -318,10 +318,10 @@ class ConditionFeared final : public Condition { ConditionFeared(ConditionId_t intiId, ConditionType_t initType, int32_t initTicks, bool initBuff, uint32_t initSubId) : Condition(intiId, initType, initTicks, initBuff, initSubId) { } - bool startCondition(Creature* creature) override; - bool executeCondition(Creature* creature, int32_t interval) override; - void endCondition(Creature* creature) override; - void addCondition(Creature* creature, const Condition* condition) override; + bool startCondition(std::shared_ptr creature) override; + bool executeCondition(std::shared_ptr creature, int32_t interval) override; + void endCondition(std::shared_ptr creature) override; + void addCondition(std::shared_ptr creature, const Condition* condition) override; uint32_t getIcons() const override; ConditionFeared* clone() const override { @@ -331,11 +331,11 @@ class ConditionFeared final : public Condition { bool setPositionParam(ConditionParam_t param, const Position &pos) override; private: - bool canWalkTo(const Creature* creature, Position pos, Direction moveDirection) const; - bool getFleeDirection(Creature* creature); - bool getFleePath(Creature* creature, const Position &pos, std::forward_list &dirList); - bool getRandomDirection(Creature* creature, Position pos); - bool isStuck(Creature* creature, Position pos) const; + bool canWalkTo(std::shared_ptr creature, Position pos, Direction moveDirection) const; + bool getFleeDirection(std::shared_ptr creature); + bool getFleePath(std::shared_ptr creature, const Position &pos, std::forward_list &dirList); + bool getRandomDirection(std::shared_ptr creature, Position pos); + bool isStuck(std::shared_ptr creature, Position pos) const; std::vector m_directionsVector { DIRECTION_NORTH, @@ -357,10 +357,10 @@ class ConditionSpeed final : public Condition { ConditionSpeed(ConditionId_t initId, ConditionType_t initType, int32_t initTicks, bool initBuff, uint32_t initSubId, int32_t initChangeSpeed) : Condition(initId, initType, initTicks, initBuff, initSubId), speedDelta(initChangeSpeed) { } - bool startCondition(Creature* creature) override; - bool executeCondition(Creature* creature, int32_t interval) override; - void endCondition(Creature* creature) override; - void addCondition(Creature* creature, const Condition* condition) override; + bool startCondition(std::shared_ptr creature) override; + bool executeCondition(std::shared_ptr creature, int32_t interval) override; + void endCondition(std::shared_ptr creature) override; + void addCondition(std::shared_ptr creature, const Condition* condition) override; uint32_t getIcons() const override; ConditionSpeed* clone() const override { @@ -392,10 +392,10 @@ class ConditionOutfit final : public Condition { ConditionOutfit(ConditionId_t initId, ConditionType_t initType, int32_t initTicks, bool initBuff = false, uint32_t initSubId = 0) : Condition(initId, initType, initTicks, initBuff, initSubId) { } - bool startCondition(Creature* creature) override; - bool executeCondition(Creature* creature, int32_t interval) override; - void endCondition(Creature* creature) override; - void addCondition(Creature* creature, const Condition* condition) override; + bool startCondition(std::shared_ptr creature) override; + bool executeCondition(std::shared_ptr creature, int32_t interval) override; + void endCondition(std::shared_ptr creature) override; + void addCondition(std::shared_ptr creature, const Condition* condition) override; ConditionOutfit* clone() const override { return new ConditionOutfit(*this); @@ -418,10 +418,10 @@ class ConditionLight final : public Condition { ConditionLight(ConditionId_t initId, ConditionType_t initType, int32_t initTicks, bool initBuff, uint32_t initSubId, uint8_t initLightlevel, uint8_t initLightcolor) : Condition(initId, initType, initTicks, initBuff, initSubId), lightInfo(initLightlevel, initLightcolor) { } - bool startCondition(Creature* creature) override; - bool executeCondition(Creature* creature, int32_t interval) override; - void endCondition(Creature* creature) override; - void addCondition(Creature* creature, const Condition* addCondition) override; + bool startCondition(std::shared_ptr creature) override; + bool executeCondition(std::shared_ptr creature, int32_t interval) override; + void endCondition(std::shared_ptr creature) override; + void addCondition(std::shared_ptr creature, const Condition* addCondition) override; ConditionLight* clone() const override { return new ConditionLight(*this); @@ -444,8 +444,8 @@ class ConditionSpellCooldown final : public ConditionGeneric { ConditionSpellCooldown(ConditionId_t initId, ConditionType_t initType, int32_t initTicks, bool initBuff = false, uint32_t initSubId = 0) : ConditionGeneric(initId, initType, initTicks, initBuff, initSubId) { } - bool startCondition(Creature* creature) override; - void addCondition(Creature* creature, const Condition* condition) override; + bool startCondition(std::shared_ptr creature) override; + void addCondition(std::shared_ptr creature, const Condition* condition) override; ConditionSpellCooldown* clone() const override { return new ConditionSpellCooldown(*this); @@ -457,8 +457,8 @@ class ConditionSpellGroupCooldown final : public ConditionGeneric { ConditionSpellGroupCooldown(ConditionId_t initId, ConditionType_t initType, int32_t initTicks, bool initBuff = false, uint32_t initSubId = 0) : ConditionGeneric(initId, initType, initTicks, initBuff, initSubId) { } - bool startCondition(Creature* creature) override; - void addCondition(Creature* creature, const Condition* condition) override; + bool startCondition(std::shared_ptr creature) override; + void addCondition(std::shared_ptr creature, const Condition* condition) override; ConditionSpellGroupCooldown* clone() const override { return new ConditionSpellGroupCooldown(*this); diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index ae2dad64894..018df87982b 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -19,7 +19,7 @@ Spells::Spells() = default; Spells::~Spells() = default; -TalkActionResult_t Spells::playerSaySpell(Player* player, std::string &words) { +TalkActionResult_t Spells::playerSaySpell(std::shared_ptr player, std::string &words) { std::string str_words = words; if (player->hasCondition(CONDITION_FEARED)) { @@ -232,7 +232,7 @@ std::shared_ptr Spells::getInstantSpellByName(const std::string &n return nullptr; } -Position Spells::getCasterPosition(Creature* creature, Direction dir) { +Position Spells::getCasterPosition(std::shared_ptr creature, Direction dir) { return getNextPosition(dir, creature->getPosition()); } @@ -249,7 +249,7 @@ bool CombatSpell::loadScriptCombat() { return combat != nullptr; } -bool CombatSpell::castSpell(Creature* creature) { +bool CombatSpell::castSpell(std::shared_ptr creature) { if (isLoadedCallback()) { LuaVariant var; var.type = VARIANT_POSITION; @@ -282,7 +282,7 @@ bool CombatSpell::castSpell(Creature* creature) { return true; } -bool CombatSpell::castSpell(Creature* creature, Creature* target) { +bool CombatSpell::castSpell(std::shared_ptr creature, std::shared_ptr target) { if (isLoadedCallback()) { LuaVariant var; @@ -324,7 +324,7 @@ bool CombatSpell::castSpell(Creature* creature, Creature* target) { return true; } -bool CombatSpell::executeCastSpell(Creature* creature, const LuaVariant &var) const { +bool CombatSpell::executeCastSpell(std::shared_ptr creature, const LuaVariant &var) const { // onCastSpell(creature, var) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CombatSpell::executeCastSpell - Creature {}] " @@ -348,7 +348,7 @@ bool CombatSpell::executeCastSpell(Creature* creature, const LuaVariant &var) co return getScriptInterface()->callFunction(2); } -bool Spell::playerSpellCheck(Player* player) const { +bool Spell::playerSpellCheck(std::shared_ptr player) const { if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) { return false; } @@ -452,7 +452,7 @@ bool Spell::playerSpellCheck(Player* player) const { return true; } -bool Spell::playerInstantSpellCheck(Player* player, const Position &toPos) const { +bool Spell::playerInstantSpellCheck(std::shared_ptr player, const Position &toPos) const { if (toPos.x == 0xFFFF) { return true; } @@ -492,7 +492,7 @@ bool Spell::playerInstantSpellCheck(Player* player, const Position &toPos) const return true; } -bool Spell::playerRuneSpellCheck(Player* player, const Position &toPos) { +bool Spell::playerRuneSpellCheck(std::shared_ptr player, const Position &toPos) { if (!playerSpellCheck(player)) { return false; } @@ -512,7 +512,7 @@ bool Spell::playerRuneSpellCheck(Player* player, const Position &toPos) { return false; } - Tile* tile = g_game().map.getTile(toPos); + std::shared_ptr tile = g_game().map.getTile(toPos); if (!tile) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); g_game().addMagicEffect(player->getPosition(), CONST_ME_POFF); @@ -532,7 +532,7 @@ bool Spell::playerRuneSpellCheck(Player* player, const Position &toPos) { return false; } - const Creature* topVisibleCreature = tile->getBottomVisibleCreature(player); + const std::shared_ptr topVisibleCreature = tile->getBottomVisibleCreature(player); if (blockingCreature && topVisibleCreature) { player->sendCancelMessage(RETURNVALUE_NOTENOUGHROOM); g_game().addMagicEffect(player->getPosition(), CONST_ME_POFF); @@ -550,7 +550,7 @@ bool Spell::playerRuneSpellCheck(Player* player, const Position &toPos) { } if (aggressive && needTarget && topVisibleCreature && player->hasSecureMode()) { - const Player* targetPlayer = topVisibleCreature->getPlayer(); + const std::shared_ptr targetPlayer = topVisibleCreature->getPlayer(); if (targetPlayer && targetPlayer != player && player->getSkullClient(targetPlayer) == SKULL_NONE && !Combat::isInPvpZone(player, targetPlayer)) { player->sendCancelMessage(RETURNVALUE_TURNSECUREMODETOATTACKUNMARKEDPLAYERS); g_game().addMagicEffect(player->getPosition(), CONST_ME_POFF); @@ -597,7 +597,7 @@ void Spell::setWheelOfDestinyBoost(WheelSpellBoost_t boost, WheelSpellGrade_t gr } } -void Spell::applyCooldownConditions(Player* player) const { +void Spell::applyCooldownConditions(std::shared_ptr player) const { WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0; auto rate_cooldown = (int32_t)g_configManager().getFloat(RATE_SPELL_COOLDOWN); @@ -635,7 +635,7 @@ void Spell::applyCooldownConditions(Player* player) const { } } -void Spell::postCastSpell(Player* player, bool finishedCast /*= true*/, bool payCost /*= true*/) const { +void Spell::postCastSpell(std::shared_ptr player, bool finishedCast /*= true*/, bool payCost /*= true*/) const { if (finishedCast) { if (!player->hasFlag(PlayerFlags_t::HasNoExhaustion)) { applyCooldownConditions(player); @@ -655,7 +655,7 @@ void Spell::postCastSpell(Player* player, bool finishedCast /*= true*/, bool pay } } -void Spell::postCastSpell(Player* player, uint32_t manaCost, uint32_t soulCost) { +void Spell::postCastSpell(std::shared_ptr player, uint32_t manaCost, uint32_t soulCost) { if (manaCost > 0) { player->addManaSpent(manaCost); player->changeMana(-static_cast(manaCost)); @@ -668,7 +668,7 @@ void Spell::postCastSpell(Player* player, uint32_t manaCost, uint32_t soulCost) } } -uint32_t Spell::getManaCost(const Player* player) const { +uint32_t Spell::getManaCost(std::shared_ptr player) const { if (mana != 0) { WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); if (getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0) { @@ -698,20 +698,20 @@ uint32_t Spell::getManaCost(const Player* player) const { return 0; } -bool InstantSpell::playerCastInstant(Player* player, std::string ¶m) { +bool InstantSpell::playerCastInstant(std::shared_ptr player, std::string ¶m) { if (!playerSpellCheck(player)) { return false; } LuaVariant var; var.instantName = getName(); - Player* playerTarget = nullptr; + std::shared_ptr playerTarget = nullptr; if (selfTarget) { var.type = VARIANT_NUMBER; var.number = player->getID(); } else if (needTarget || casterTargetOrDirection) { - Creature* target = nullptr; + std::shared_ptr target = nullptr; bool useDirection = false; if (hasParam) { @@ -819,7 +819,7 @@ bool InstantSpell::playerCastInstant(Player* player, std::string ¶m) { return result; } -bool InstantSpell::canThrowSpell(const Creature* creature, const Creature* target) const { +bool InstantSpell::canThrowSpell(std::shared_ptr creature, std::shared_ptr target) const { const Position &fromPos = creature->getPosition(); const Position &toPos = target->getPosition(); if (fromPos.z != toPos.z || (range == -1 && !g_game().canThrowObjectTo(fromPos, toPos, checkLineOfSight)) || (range != -1 && !g_game().canThrowObjectTo(fromPos, toPos, checkLineOfSight, range, range))) { @@ -828,12 +828,12 @@ bool InstantSpell::canThrowSpell(const Creature* creature, const Creature* targe return true; } -bool InstantSpell::castSpell(Creature* creature) { +bool InstantSpell::castSpell(std::shared_ptr creature) { LuaVariant var; var.instantName = getName(); if (casterTargetOrDirection) { - Creature* target = creature->getAttackedCreature(); + std::shared_ptr target = creature->getAttackedCreature(); if (target && target->getHealth() > 0) { if (!canThrowSpell(creature, target)) { return false; @@ -857,7 +857,7 @@ bool InstantSpell::castSpell(Creature* creature) { return executeCastSpell(creature, var); } -bool InstantSpell::castSpell(Creature* creature, Creature* target) { +bool InstantSpell::castSpell(std::shared_ptr creature, std::shared_ptr target) { if (needTarget) { LuaVariant var; var.type = VARIANT_NUMBER; @@ -868,7 +868,7 @@ bool InstantSpell::castSpell(Creature* creature, Creature* target) { } } -bool InstantSpell::executeCastSpell(Creature* creature, const LuaVariant &var) const { +bool InstantSpell::executeCastSpell(std::shared_ptr creature, const LuaVariant &var) const { // onCastSpell(creature, var) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[InstantSpell::executeCastSpell - Creature {} words {}] " @@ -892,7 +892,7 @@ bool InstantSpell::executeCastSpell(Creature* creature, const LuaVariant &var) c return getScriptInterface()->callFunction(2); } -bool InstantSpell::canCast(const Player* player) const { +bool InstantSpell::canCast(std::shared_ptr player) const { if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) { return false; } @@ -914,7 +914,7 @@ bool InstantSpell::canCast(const Player* player) const { return false; } -ReturnValue RuneSpell::canExecuteAction(const Player* player, const Position &toPos) { +ReturnValue RuneSpell::canExecuteAction(std::shared_ptr player, const Position &toPos) { if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) { return RETURNVALUE_CANNOTUSETHISOBJECT; } @@ -935,7 +935,7 @@ ReturnValue RuneSpell::canExecuteAction(const Player* player, const Position &to return RETURNVALUE_NOERROR; } -bool RuneSpell::executeUse(Player* player, Item* item, const Position &, Thing* target, const Position &toPosition, bool isHotkey) { +bool RuneSpell::executeUse(std::shared_ptr player, std::shared_ptr item, const Position &, std::shared_ptr target, const Position &toPosition, bool isHotkey) { if (!playerRuneSpellCheck(player, toPosition)) { return false; } @@ -952,9 +952,9 @@ bool RuneSpell::executeUse(Player* player, Item* item, const Position &, Thing* var.type = VARIANT_NUMBER; if (target == nullptr) { - const Tile* toTile = g_game().map.getTile(toPosition); + std::shared_ptr toTile = g_game().map.getTile(toPosition); if (toTile) { - const Creature* visibleCreature = toTile->getBottomVisibleCreature(player); + std::shared_ptr visibleCreature = toTile->getBottomVisibleCreature(player); if (visibleCreature) { var.number = visibleCreature->getID(); } @@ -986,7 +986,7 @@ bool RuneSpell::executeUse(Player* player, Item* item, const Position &, Thing* return true; } -bool RuneSpell::castSpell(Creature* creature) { +bool RuneSpell::castSpell(std::shared_ptr creature) { LuaVariant var; var.type = VARIANT_NUMBER; var.number = creature->getID(); @@ -994,7 +994,7 @@ bool RuneSpell::castSpell(Creature* creature) { return internalCastSpell(creature, var, false); } -bool RuneSpell::castSpell(Creature* creature, Creature* target) { +bool RuneSpell::castSpell(std::shared_ptr creature, std::shared_ptr target) { LuaVariant var; var.type = VARIANT_NUMBER; var.number = target->getID(); @@ -1002,7 +1002,7 @@ bool RuneSpell::castSpell(Creature* creature, Creature* target) { return internalCastSpell(creature, var, false); } -bool RuneSpell::internalCastSpell(Creature* creature, const LuaVariant &var, bool isHotkey) { +bool RuneSpell::internalCastSpell(std::shared_ptr creature, const LuaVariant &var, bool isHotkey) { bool result; if (isLoadedCallback()) { result = executeCastSpell(creature, var, isHotkey); @@ -1012,7 +1012,7 @@ bool RuneSpell::internalCastSpell(Creature* creature, const LuaVariant &var, boo return result; } -bool RuneSpell::executeCastSpell(Creature* creature, const LuaVariant &var, bool isHotkey) const { +bool RuneSpell::executeCastSpell(std::shared_ptr creature, const LuaVariant &var, bool isHotkey) const { // onCastSpell(creature, var, isHotkey) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[RuneSpell::executeCastSpell - Creature {} runeId {}] " diff --git a/src/creatures/combat/spells.hpp b/src/creatures/combat/spells.hpp index 10c3295f3a2..a158cddeb2d 100644 --- a/src/creatures/combat/spells.hpp +++ b/src/creatures/combat/spells.hpp @@ -44,9 +44,9 @@ class Spells final : public Scripts { std::shared_ptr getInstantSpellById(uint16_t spellId); - TalkActionResult_t playerSaySpell(Player* player, std::string &words); + TalkActionResult_t playerSaySpell(std::shared_ptr player, std::string &words); - static Position getCasterPosition(Creature* creature, Direction dir); + static Position getCasterPosition(std::shared_ptr creature, Direction dir); std::list getSpellsByVocation(uint16_t vocationId); @@ -73,15 +73,15 @@ class Spells final : public Scripts { constexpr auto g_spells = Spells::getInstance; -using RuneSpellFunction = std::function spell, Player* player, const Position &posTo)>; +using RuneSpellFunction = std::function spell, std::shared_ptr player, const Position &posTo)>; class BaseSpell { public: constexpr BaseSpell() = default; virtual ~BaseSpell() = default; - virtual bool castSpell(Creature* creature) = 0; - virtual bool castSpell(Creature* creature, Creature* target) = 0; + virtual bool castSpell(std::shared_ptr creature) = 0; + virtual bool castSpell(std::shared_ptr creature, std::shared_ptr target) = 0; SoundEffect_t soundImpactEffect = SoundEffect_t::SILENCE; SoundEffect_t soundCastEffect = SoundEffect_t::SPELL_OR_RUNE; @@ -96,11 +96,11 @@ class CombatSpell final : public Script, public BaseSpell, public std::enable_sh CombatSpell(const CombatSpell &) = delete; CombatSpell &operator=(const CombatSpell &) = delete; - bool castSpell(Creature* creature) override; - bool castSpell(Creature* creature, Creature* target) override; + bool castSpell(std::shared_ptr creature) override; + bool castSpell(std::shared_ptr creature, std::shared_ptr target) override; // Scripting spell - bool executeCastSpell(Creature* creature, const LuaVariant &var) const; + bool executeCastSpell(std::shared_ptr creature, const LuaVariant &var) const; bool loadScriptCombat(); std::shared_ptr getCombat() { @@ -135,14 +135,14 @@ class Spell : public BaseSpell { spellId = id; } - void postCastSpell(Player* player, bool finishedCast = true, bool payCost = true) const; - static void postCastSpell(Player* player, uint32_t manaCost, uint32_t soulCost); + void postCastSpell(std::shared_ptr player, bool finishedCast = true, bool payCost = true) const; + static void postCastSpell(std::shared_ptr player, uint32_t manaCost, uint32_t soulCost); [[nodiscard]] virtual bool isInstant() const = 0; [[nodiscard]] bool isLearnable() const { return learnable; } - uint32_t getManaCost(const Player* player) const; + uint32_t getManaCost(std::shared_ptr player) const; [[nodiscard]] uint32_t getSoulCost() const { return soul; } @@ -338,10 +338,10 @@ class Spell : public BaseSpell { } protected: - void applyCooldownConditions(Player* player) const; - bool playerSpellCheck(Player* player) const; - bool playerInstantSpellCheck(Player* player, const Position &toPos) const; - bool playerRuneSpellCheck(Player* player, const Position &toPos); + void applyCooldownConditions(std::shared_ptr player) const; + bool playerSpellCheck(std::shared_ptr player) const; + bool playerInstantSpellCheck(std::shared_ptr player, const Position &toPos) const; + bool playerRuneSpellCheck(std::shared_ptr player, const Position &toPos); VocSpellMap vocSpellMap; @@ -388,13 +388,13 @@ class InstantSpell final : public Script, public Spell { public: using Script::Script; - virtual bool playerCastInstant(Player* player, std::string ¶m); + virtual bool playerCastInstant(std::shared_ptr player, std::string ¶m); - bool castSpell(Creature* creature) override; - bool castSpell(Creature* creature, Creature* target) override; + bool castSpell(std::shared_ptr creature) override; + bool castSpell(std::shared_ptr creature, std::shared_ptr target) override; // Scripting spell - bool executeCastSpell(Creature* creature, const LuaVariant &var) const; + bool executeCastSpell(std::shared_ptr creature, const LuaVariant &var) const; [[nodiscard]] bool isInstant() const override { return true; @@ -429,8 +429,8 @@ class InstantSpell final : public Script, public Spell { void setBlockWalls(bool w) { checkLineOfSight = w; } - bool canCast(const Player* player) const; - bool canThrowSpell(const Creature* creature, const Creature* target) const; + bool canCast(std::shared_ptr player) const; + bool canThrowSpell(std::shared_ptr creature, std::shared_ptr target) const; private: [[nodiscard]] std::string getScriptTypeName() const override { @@ -448,21 +448,21 @@ class RuneSpell final : public Action, public Spell { public: using Action::Action; - ReturnValue canExecuteAction(const Player* player, const Position &toPos) override; + ReturnValue canExecuteAction(std::shared_ptr player, const Position &toPos) override; bool hasOwnErrorHandler() override { return true; } - Thing* getTarget(Player*, Creature* targetCreature, const Position &, uint8_t) const override { + std::shared_ptr getTarget(std::shared_ptr, std::shared_ptr targetCreature, const Position &, uint8_t) const override { return targetCreature; } - bool executeUse(Player* player, Item* item, const Position &fromPosition, Thing* target, const Position &toPosition, bool isHotkey) override; + bool executeUse(std::shared_ptr player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey) override; - bool castSpell(Creature* creature) override; - bool castSpell(Creature* creature, Creature* target) override; + bool castSpell(std::shared_ptr creature) override; + bool castSpell(std::shared_ptr creature, std::shared_ptr target) override; // Scripting spell - bool executeCastSpell(Creature* creature, const LuaVariant &var, bool isHotkey) const; + bool executeCastSpell(std::shared_ptr creature, const LuaVariant &var, bool isHotkey) const; [[nodiscard]] bool isInstant() const override { return false; @@ -488,7 +488,7 @@ class RuneSpell final : public Action, public Spell { return "onCastSpell"; } - bool internalCastSpell(Creature* creature, const LuaVariant &var, bool isHotkey); + bool internalCastSpell(std::shared_ptr creature, const LuaVariant &var, bool isHotkey); uint16_t runeId = 0; uint32_t charges = 0; diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 78d7720bf57..30f7cf3ac06 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -26,14 +26,13 @@ Creature::Creature() { } Creature::~Creature() { - for (Creature* summon : summons) { + for (std::shared_ptr summon : summons) { summon->setAttackedCreature(nullptr); summon->removeMaster(); } for (Condition* condition : conditions) { - condition->endCondition(this); - delete condition; + condition->endCondition(static_self_cast()); } } @@ -57,11 +56,11 @@ bool Creature::canSee(const Position &myPos, const Position &pos, int32_t viewRa && (pos.getY() >= myPos.getY() - viewRangeY + offsetz) && (pos.getY() <= myPos.getY() + viewRangeY + offsetz); } -bool Creature::canSee(const Position &pos) const { +bool Creature::canSee(const Position &pos) { return canSee(getPosition(), pos, MAP_MAX_VIEW_PORT_X, MAP_MAX_VIEW_PORT_Y); } -bool Creature::canSeeCreature(const Creature* creature) const { +bool Creature::canSeeCreature(std::shared_ptr creature) const { if (!canSeeInvisibility() && creature->isInvisible()) { return false; } @@ -70,7 +69,7 @@ bool Creature::canSeeCreature(const Creature* creature) const { void Creature::setSkull(Skulls_t newSkull) { skull = newSkull; - g_game().updateCreatureSkull(this); + g_game().updateCreatureSkull(static_self_cast()); } int64_t Creature::getTimeSinceLastMove() const { @@ -80,7 +79,7 @@ int64_t Creature::getTimeSinceLastMove() const { return std::numeric_limits::max(); } -int32_t Creature::getWalkDelay(Direction dir) const { +int32_t Creature::getWalkDelay(Direction dir) { if (lastStep == 0) { return 0; } @@ -90,7 +89,7 @@ int32_t Creature::getWalkDelay(Direction dir) const { return stepDuration - (ct - lastStep); } -int32_t Creature::getWalkDelay() const { +int32_t Creature::getWalkDelay() { // Used for auto-walking if (lastStep == 0) { return 0; @@ -143,7 +142,7 @@ void Creature::onThink(uint32_t interval) { // scripting event - onThink const CreatureEventList &thinkEvents = getCreatureEvents(CREATURE_EVENT_THINK); for (const auto creatureEventPtr : thinkEvents) { - creatureEventPtr->executeOnThink(this, interval); + creatureEventPtr->executeOnThink(static_self_cast(), interval); } } @@ -172,9 +171,9 @@ void Creature::onCreatureWalk() { Direction dir; uint32_t flags = FLAG_IGNOREFIELDDAMAGE; if (getNextStep(dir, flags)) { - ReturnValue ret = g_game().internalMoveCreature(this, dir, flags); + ReturnValue ret = g_game().internalMoveCreature(static_self_cast(), dir, flags); if (ret != RETURNVALUE_NOERROR) { - if (Player* player = getPlayer()) { + if (std::shared_ptr player = getPlayer()) { player->sendCancelMessage(ret); player->sendCancelWalk(); } @@ -209,7 +208,7 @@ void Creature::onWalk(Direction &dir) { if (r < DIRECTION_DIAGONAL_MASK) { dir = static_cast(r); } - g_game().internalCreatureSay(this, TALKTYPE_MONSTER_SAY, "Hicks!", false); + g_game().internalCreatureSay(static_self_cast(), TALKTYPE_MONSTER_SAY, "Hicks!", false); } } } @@ -274,7 +273,7 @@ void Creature::stopEventWalk() { } void Creature::updateMapCache() { - Tile* newTile; + std::shared_ptr newTile; const Position &myPos = getPosition(); Position pos(0, 0, myPos.z); @@ -288,13 +287,13 @@ void Creature::updateMapCache() { } } -void Creature::updateTileCache(const Tile* newTile, int32_t dx, int32_t dy) { +void Creature::updateTileCache(std::shared_ptr newTile, int32_t dx, int32_t dy) { if (std::abs(dx) <= maxWalkCacheWidth && std::abs(dy) <= maxWalkCacheHeight) { - localMapCache[maxWalkCacheHeight + dy][maxWalkCacheWidth + dx] = newTile && newTile->queryAdd(0, *this, 1, FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) == RETURNVALUE_NOERROR; + localMapCache[maxWalkCacheHeight + dy][maxWalkCacheWidth + dx] = newTile && newTile->queryAdd(0, getCreature(), 1, FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) == RETURNVALUE_NOERROR; } } -void Creature::updateTileCache(const Tile* upTile, const Position &pos) { +void Creature::updateTileCache(std::shared_ptr upTile, const Position &pos) { const Position &myPos = getPosition(); if (pos.z == myPos.z) { int32_t dx = Position::getOffsetX(pos, myPos); @@ -303,7 +302,7 @@ void Creature::updateTileCache(const Tile* upTile, const Position &pos) { } } -int32_t Creature::getWalkCache(const Position &pos) const { +int32_t Creature::getWalkCache(const Position &pos) { if (!useCacheMap()) { return 2; } @@ -333,13 +332,13 @@ int32_t Creature::getWalkCache(const Position &pos) const { return 2; } -void Creature::onAddTileItem(const Tile* tileItem, const Position &pos) { +void Creature::onAddTileItem(std::shared_ptr tileItem, const Position &pos) { if (isMapLoaded && pos.z == getPosition().z) { updateTileCache(tileItem, pos); } } -void Creature::onUpdateTileItem(const Tile* updateTile, const Position &pos, const Item*, const ItemType &oldType, const Item*, const ItemType &newType) { +void Creature::onUpdateTileItem(std::shared_ptr updateTile, const Position &pos, std::shared_ptr, const ItemType &oldType, std::shared_ptr, const ItemType &newType) { if (!isMapLoaded) { return; } @@ -351,7 +350,7 @@ void Creature::onUpdateTileItem(const Tile* updateTile, const Position &pos, con } } -void Creature::onRemoveTileItem(const Tile* updateTile, const Position &pos, const ItemType &iType, const Item*) { +void Creature::onRemoveTileItem(std::shared_ptr updateTile, const Position &pos, const ItemType &iType, std::shared_ptr) { if (!isMapLoaded) { return; } @@ -363,8 +362,8 @@ void Creature::onRemoveTileItem(const Tile* updateTile, const Position &pos, con } } -void Creature::onCreatureAppear(Creature* creature, bool isLogin) { - if (creature == this) { +void Creature::onCreatureAppear(std::shared_ptr creature, bool isLogin) { + if (creature == getCreature()) { if (useCacheMap()) { isMapLoaded = true; updateMapCache(); @@ -380,9 +379,9 @@ void Creature::onCreatureAppear(Creature* creature, bool isLogin) { } } -void Creature::onRemoveCreature(Creature* creature, bool) { +void Creature::onRemoveCreature(std::shared_ptr creature, bool) { onCreatureDisappear(creature, true); - if (creature != this && isMapLoaded) { + if (creature != getCreature() && isMapLoaded) { if (creature->getPosition().z == getPosition().z) { updateTileCache(creature->getTile(), creature->getPosition()); } @@ -395,7 +394,7 @@ void Creature::onRemoveCreature(Creature* creature, bool) { } } -void Creature::onCreatureDisappear(const Creature* creature, bool isLogout) { +void Creature::onCreatureDisappear(std::shared_ptr creature, bool isLogout) { if (attackedCreature == creature) { setAttackedCreature(nullptr); onAttackedCreatureDisappear(isLogout); @@ -421,14 +420,14 @@ void Creature::onAttackedCreatureChangeZone(ZoneType_t zone) { void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) const { if (hasSummons()) { - std::vector despawnMonsterList; - for (Creature* creature : getSummons()) { + std::vector> despawnMonsterList; + for (std::shared_ptr creature : getSummons()) { if (!creature) { continue; } const Position &pos = creature->getPosition(); - const Monster* monster = creature->getMonster(); + std::shared_ptr monster = creature->getMonster(); bool protectionZoneCheck = tile ? tile->hasFlag(TILESTATE_PROTECTIONZONE) : false; // Check if any of our summons is out of range (+/- 0 floors or 15 tiles away) bool checkSummonDist = Position::getDistanceZ(newPos, pos) > 0 || (std::max(Position::getDistanceX(newPos, pos), Position::getDistanceY(newPos, pos)) > 15); @@ -441,7 +440,7 @@ void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) cons continue; } - if (Tile* masterTile = creatureMaster->getTile()) { + if (std::shared_ptr masterTile = creatureMaster->getTile()) { if (masterTile->hasFlag(TILESTATE_TELEPORT)) { g_logger().warn("[{}] cannot teleport summon, position has teleport. {}", __FUNCTION__, creatureMaster->getPosition().toString()); } else { @@ -456,7 +455,7 @@ void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) cons } } - for (Creature* despawnCreature : despawnMonsterList) { + for (std::shared_ptr despawnCreature : despawnMonsterList) { if (!despawnMonsterList.empty()) { g_game().removeCreature(despawnCreature, true); } @@ -464,8 +463,8 @@ void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) cons } } -void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Position &newPos, const Tile* oldTile, const Position &oldPos, bool teleport) { - if (creature == this) { +void Creature::onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport) { + if (creature == getCreature()) { lastStep = OTSYS_TIME(); lastStepCost = 1; @@ -487,7 +486,7 @@ void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Pos handleLostSummon(configTeleportSummons); } - if (Player* player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { if (player->isExerciseTraining()) { player->setTraining(false); } @@ -512,7 +511,7 @@ void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Pos // update 0 for (int32_t x = -maxWalkCacheWidth; x <= maxWalkCacheWidth; ++x) { - const Tile* cacheTile = g_game().map.getTile(static_cast(myPos.getX() + x), static_cast(myPos.getY() - maxWalkCacheHeight), myPos.z); + std::shared_ptr cacheTile = g_game().map.getTile(static_cast(myPos.getX() + x), static_cast(myPos.getY() - maxWalkCacheHeight), myPos.z); updateTileCache(cacheTile, x, -maxWalkCacheHeight); } } else if (oldPos.y < newPos.y) { // south @@ -523,7 +522,7 @@ void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Pos // update mapWalkHeight - 1 for (int32_t x = -maxWalkCacheWidth; x <= maxWalkCacheWidth; ++x) { - const Tile* cacheTile = g_game().map.getTile(static_cast(myPos.getX() + x), static_cast(myPos.getY() + maxWalkCacheHeight), myPos.z); + std::shared_ptr cacheTile = g_game().map.getTile(static_cast(myPos.getX() + x), static_cast(myPos.getY() + maxWalkCacheHeight), myPos.z); updateTileCache(cacheTile, x, maxWalkCacheHeight); } } @@ -548,7 +547,7 @@ void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Pos // update mapWalkWidth - 1 for (int32_t y = -maxWalkCacheHeight; y <= maxWalkCacheHeight; ++y) { - const Tile* cacheTile = g_game().map.getTile(myPos.x + maxWalkCacheWidth, static_cast(myPos.y + y), myPos.z); + std::shared_ptr cacheTile = g_game().map.getTile(myPos.x + maxWalkCacheWidth, static_cast(myPos.y + y), myPos.z); updateTileCache(cacheTile, maxWalkCacheWidth, y); } } else if (oldPos.x > newPos.x) { // west @@ -571,7 +570,7 @@ void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Pos // update 0 for (int32_t y = -maxWalkCacheHeight; y <= maxWalkCacheHeight; ++y) { - const Tile* cacheTile = g_game().map.getTile(myPos.x - maxWalkCacheWidth, static_cast(myPos.y + y), myPos.z); + std::shared_ptr cacheTile = g_game().map.getTile(myPos.x - maxWalkCacheWidth, static_cast(myPos.y + y), myPos.z); updateTileCache(cacheTile, -maxWalkCacheWidth, y); } } @@ -593,7 +592,7 @@ void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Pos } } - if (followCreature && (creature == this || creature == followCreature)) { + if (followCreature && (creature == getCreature() || creature == followCreature)) { if (hasFollowPath) { isUpdatingPath = true; g_dispatcher().addTask(std::bind(&Game::updateCreatureWalk, &g_game(), getID()), "Game::updateCreatureWalk"); @@ -604,7 +603,7 @@ void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Pos } } - if (creature == attackedCreature || (creature == this && attackedCreature)) { + if (creature == attackedCreature || (creature == getCreature() && attackedCreature)) { if (newPos.z != oldPos.z || !canSee(attackedCreature->getPosition())) { onCreatureDisappear(attackedCreature, false); } else { @@ -623,32 +622,32 @@ void Creature::onCreatureMove(Creature* creature, const Tile* newTile, const Pos void Creature::onDeath() { bool lastHitUnjustified = false; bool mostDamageUnjustified = false; - Creature* lastHitCreature = g_game().getCreatureByID(lastHitCreatureId); - Creature* lastHitCreatureMaster; + std::shared_ptr lastHitCreature = g_game().getCreatureByID(lastHitCreatureId); + std::shared_ptr lastHitCreatureMaster; if (lastHitCreature) { - lastHitUnjustified = lastHitCreature->onKilledCreature(this, true); + lastHitUnjustified = lastHitCreature->onKilledCreature(static_self_cast(), true); lastHitCreatureMaster = lastHitCreature->getMaster(); } else { lastHitCreatureMaster = nullptr; } - Creature* mostDamageCreature = nullptr; + std::shared_ptr mostDamageCreature = nullptr; const int64_t timeNow = OTSYS_TIME(); const uint32_t inFightTicks = g_configManager().getNumber(PZ_LOCKED); int32_t mostDamage = 0; - std::map experienceMap; + std::map, uint64_t> experienceMap; for (const auto &it : damageMap) { - if (Creature* attacker = g_game().getCreatureByID(it.first)) { + if (std::shared_ptr attacker = g_game().getCreatureByID(it.first)) { CountBlock_t cb = it.second; if ((cb.total > mostDamage && (timeNow - cb.ticks <= inFightTicks))) { mostDamage = cb.total; mostDamageCreature = attacker; } - if (attacker != this) { + if (attacker != getCreature()) { uint64_t gainExp = getGainedExperience(attacker); - if (Player* attackerPlayer = attacker->getPlayer()) { + if (std::shared_ptr attackerPlayer = attacker->getPlayer()) { attackerPlayer->removeAttacked(getPlayer()); Party* party = attackerPlayer->getParty(); @@ -669,14 +668,14 @@ void Creature::onDeath() { } for (const auto &it : experienceMap) { - it.first->onGainExperience(it.second, this); + it.first->onGainExperience(it.second, getCreature()); } if (mostDamageCreature) { if (mostDamageCreature != lastHitCreature && mostDamageCreature != lastHitCreatureMaster) { - Creature* mostDamageCreatureMaster = mostDamageCreature->getMaster(); + auto mostDamageCreatureMaster = mostDamageCreature->getMaster(); if (lastHitCreature != mostDamageCreatureMaster && (lastHitCreatureMaster == nullptr || mostDamageCreatureMaster != lastHitCreatureMaster)) { - mostDamageUnjustified = mostDamageCreature->onKilledCreature(this, false); + mostDamageUnjustified = mostDamageCreature->onKilledCreature(static_self_cast(), false); } } } @@ -685,7 +684,7 @@ void Creature::onDeath() { death(lastHitCreature); if (droppedCorpse && !getPlayer()) { - g_game().removeCreature(this, false); + g_game().removeCreature(static_self_cast(), false); } if (master) { @@ -693,19 +692,19 @@ void Creature::onDeath() { } } -bool Creature::dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified) { +bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared_ptr mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified) { if (!lootDrop && getMonster()) { if (master) { // Scripting event onDeath const CreatureEventList &deathEvents = getCreatureEvents(CREATURE_EVENT_DEATH); for (const auto deathEventPtr : deathEvents) { - deathEventPtr->executeOnDeath(this, nullptr, lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified); + deathEventPtr->executeOnDeath(static_self_cast(), nullptr, lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified); } } g_game().addMagicEffect(getPosition(), CONST_ME_POFF); } else { - Item* splash; + std::shared_ptr splash; switch (getRace()) { case RACE_VENOM: splash = Item::CreateItem(ITEM_FULLSPLASH, FLUID_SLIME); @@ -724,20 +723,20 @@ bool Creature::dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreatur break; } - Tile* tile = getTile(); + std::shared_ptr tile = getTile(); if (tile && splash) { g_game().internalAddItem(tile, splash, INDEX_WHEREEVER, FLAG_NOLIMIT); splash->startDecaying(); } - Item* corpse = getCorpse(lastHitCreature, mostDamageCreature); + std::shared_ptr corpse = getCorpse(lastHitCreature, mostDamageCreature); if (tile && corpse) { g_game().internalAddItem(tile, corpse, INDEX_WHEREEVER, FLAG_NOLIMIT); dropLoot(corpse->getContainer(), lastHitCreature); corpse->startDecaying(); bool corpses = corpse->isRewardCorpse() || (corpse->getID() == ITEM_MALE_CORPSE || corpse->getID() == ITEM_FEMALE_CORPSE); if (corpse->getContainer() && mostDamageCreature && mostDamageCreature->getPlayer() && !corpses) { - Player* player = mostDamageCreature->getPlayer(); + auto player = mostDamageCreature->getPlayer(); std::ostringstream lootMessage; lootMessage << "Loot of " << getNameDescription() << ": " << corpse->getContainer()->getContentDescription(player->getProtocolVersion() < 1200); auto suffix = corpse->getContainer()->getAttribute(ItemAttribute_t::LOOTMESSAGE_SUFFIX); @@ -759,7 +758,7 @@ bool Creature::dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreatur // Scripting event onDeath for (const auto deathEventPtr : getCreatureEvents(CREATURE_EVENT_DEATH)) { if (deathEventPtr) { - deathEventPtr->executeOnDeath(this, corpse, lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified); + deathEventPtr->executeOnDeath(static_self_cast(), corpse, lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified); } } } @@ -775,7 +774,7 @@ bool Creature::hasBeenAttacked(uint32_t attackerId) { return (OTSYS_TIME() - it->second.ticks) <= g_configManager().getNumber(PZ_LOCKED); } -Item* Creature::getCorpse(Creature*, Creature*) { +std::shared_ptr Creature::getCorpse(std::shared_ptr, std::shared_ptr) { if (getLookCorpse() != 0) { return Item::CreateItem(getLookCorpse()); } @@ -792,7 +791,7 @@ void Creature::changeHealth(int32_t healthChange, bool sendHealthChange /* = tru } if (sendHealthChange && oldHealth != health) { - g_game().addCreatureHealth(this); + g_game().addCreatureHealth(static_self_cast()); } if (health <= 0) { g_dispatcher().addTask(std::bind(&Game::executeDeath, &g_game(), getID()), "Game::executeDeath"); @@ -807,22 +806,22 @@ void Creature::changeMana(int32_t manaChange) { } } -void Creature::gainHealth(Creature* healer, int32_t healthGain) { +void Creature::gainHealth(std::shared_ptr healer, int32_t healthGain) { changeHealth(healthGain); if (healer) { - healer->onTargetCreatureGainHealth(this, healthGain); + healer->onTargetCreatureGainHealth(static_self_cast(), healthGain); } } -void Creature::drainHealth(Creature* attacker, int32_t damage) { +void Creature::drainHealth(std::shared_ptr attacker, int32_t damage) { changeHealth(-damage, false); if (attacker) { - attacker->onAttackedCreatureDrainHealth(this, damage); + attacker->onAttackedCreatureDrainHealth(static_self_cast(), damage); } } -void Creature::drainMana(Creature* attacker, int32_t manaLoss) { +void Creature::drainMana(std::shared_ptr attacker, int32_t manaLoss) { onAttacked(); changeMana(-manaLoss); @@ -845,7 +844,7 @@ void Creature::mitigateDamage(const CombatType_t &combatType, BlockType_t &block } } -void Creature::applyAbsorbDamageModifications(const Creature* attacker, int32_t &damage, CombatType_t combatType) const { +void Creature::applyAbsorbDamageModifications(std::shared_ptr attacker, int32_t &damage, CombatType_t combatType) const { if (combatType != COMBAT_HEALING && damage != 0) { int32_t value = getAbsorbPercent(combatType); if (value != 0) { @@ -865,7 +864,7 @@ void Creature::applyAbsorbDamageModifications(const Creature* attacker, int32_t } } -BlockType_t Creature::blockHit(Creature* attacker, CombatType_t combatType, int32_t &damage, bool checkDefense /* = false */, bool checkArmor /* = false */, bool /* field = false */) { +BlockType_t Creature::blockHit(std::shared_ptr attacker, CombatType_t combatType, int32_t &damage, bool checkDefense /* = false */, bool checkArmor /* = false */, bool /* field = false */) { BlockType_t blockType = BLOCK_NONE; // Apply skills 12.72 absorbs damage @@ -912,7 +911,7 @@ BlockType_t Creature::blockHit(Creature* attacker, CombatType_t combatType, int3 } if (attacker) { - attacker->onAttackedCreature(this); + attacker->onAttackedCreature(static_self_cast()); attacker->onAttackedCreatureBlockHit(blockType); } @@ -922,7 +921,7 @@ BlockType_t Creature::blockHit(Creature* attacker, CombatType_t combatType, int3 return blockType; } -bool Creature::setAttackedCreature(Creature* creature) { +bool Creature::setAttackedCreature(std::shared_ptr creature) { if (creature) { auto monster = getMonster(); if (monster && monster->isFamiliar() && tile && tile->hasFlag(TILESTATE_PROTECTIONZONE)) { @@ -942,13 +941,13 @@ bool Creature::setAttackedCreature(Creature* creature) { attackedCreature = nullptr; } - for (Creature* summon : summons) { + for (std::shared_ptr summon : summons) { summon->setAttackedCreature(creature); } return true; } -void Creature::getPathSearchParams(const Creature*, FindPathParams &fpp) const { +void Creature::getPathSearchParams(std::shared_ptr, FindPathParams &fpp) { fpp.fullPathSearch = !hasFollowPath; fpp.clearSight = true; fpp.maxSearchDist = 12; @@ -965,7 +964,7 @@ void Creature::goToFollowCreature() { FindPathParams fpp; getPathSearchParams(followCreature, fpp); - Monster* monster = getMonster(); + std::shared_ptr monster = getMonster(); if (monster && !monster->getMaster() && (monster->isFleeing() || fpp.maxTargetDist > 1)) { Direction dir = DIRECTION_NONE; @@ -1011,7 +1010,7 @@ bool Creature::canFollowMaster() const { return tile && !tile->hasFlag(TILESTATE_PROTECTIONZONE) && (canSeeInvisibility() || !master->isInvisible()); } -bool Creature::setFollowCreature(Creature* creature) { +bool Creature::setFollowCreature(std::shared_ptr creature) { if (creature) { if (followCreature == creature) { return true; @@ -1046,7 +1045,7 @@ bool Creature::setFollowCreature(Creature* creature) { return true; } -double Creature::getDamageRatio(Creature* attacker) const { +double Creature::getDamageRatio(std::shared_ptr attacker) const { uint32_t totalDamage = 0; uint32_t attackerDamage = 0; @@ -1065,11 +1064,11 @@ double Creature::getDamageRatio(Creature* attacker) const { return (static_cast(attackerDamage) / totalDamage); } -uint64_t Creature::getGainedExperience(Creature* attacker) const { +uint64_t Creature::getGainedExperience(std::shared_ptr attacker) const { return std::floor(getDamageRatio(attacker) * getLostExperience()); } -void Creature::addDamagePoints(Creature* attacker, int32_t damagePoints) { +void Creature::addDamagePoints(std::shared_ptr attacker, int32_t damagePoints) { if (damagePoints <= 0) { return; } @@ -1107,7 +1106,7 @@ void Creature::onEndCondition(ConditionType_t) { } void Creature::onTickCondition(ConditionType_t type, bool &bRemove) { - const MagicField* field = tile ? tile->getFieldItem() : nullptr; + std::shared_ptr field = tile ? tile->getFieldItem() : nullptr; if (!field) { return; } @@ -1150,18 +1149,18 @@ void Creature::onAttacked() { // } -void Creature::onAttackedCreatureDrainHealth(Creature* target, int32_t points) { - target->addDamagePoints(this, points); +void Creature::onAttackedCreatureDrainHealth(std::shared_ptr target, int32_t points) { + target->addDamagePoints(static_self_cast(), points); } -void Creature::onAttackedCreatureKilled(Creature* target) { - if (target != this) { - uint64_t gainExp = target->getGainedExperience(this); +void Creature::onAttackedCreatureKilled(std::shared_ptr target) { + if (target != getCreature()) { + uint64_t gainExp = target->getGainedExperience(static_self_cast()); onGainExperience(gainExp, target); } } -bool Creature::onKilledCreature(Creature* target, bool lastHit) { +bool Creature::onKilledCreature(std::shared_ptr target, bool lastHit) { if (master) { master->onKilledCreature(target, lastHit); } @@ -1169,17 +1168,17 @@ bool Creature::onKilledCreature(Creature* target, bool lastHit) { // scripting event - onKill const CreatureEventList &killEvents = getCreatureEvents(CREATURE_EVENT_KILL); for (const auto killEventPtr : killEvents) { - killEventPtr->executeOnKill(this, target, lastHit); + killEventPtr->executeOnKill(static_self_cast(), target, lastHit); } return false; } -void Creature::onGainExperience(uint64_t gainExp, Creature* target) { +void Creature::onGainExperience(uint64_t gainExp, std::shared_ptr target) { if (gainExp == 0 || !master) { return; } - Monster* m = getMonster(); + std::shared_ptr m = getMonster(); if (!m->isFamiliar()) { gainExp /= 2; } @@ -1198,13 +1197,13 @@ void Creature::onGainExperience(uint64_t gainExp, Creature* target) { message.primary.color = TEXTCOLOR_WHITE_EXP; message.primary.value = gainExp; - for (Creature* spectator : spectators) { + for (std::shared_ptr spectator : spectators) { spectator->getPlayer()->sendTextMessage(message); } } } -bool Creature::setMaster(Creature* newMaster, bool reloadCreature /* = false*/) { +bool Creature::setMaster(std::shared_ptr newMaster, bool reloadCreature /* = false*/) { // Persists if this creature has ever been a summon this->summoned = true; @@ -1217,18 +1216,18 @@ bool Creature::setMaster(Creature* newMaster, bool reloadCreature /* = false*/) setFollowCreature(nullptr); setDropLoot(false); setSkillLoss(false); - g_game().reloadCreature(this); + g_game().reloadCreature(static_self_cast()); } if (newMaster) { incrementReferenceCounter(); - newMaster->summons.push_back(this); + newMaster->summons.push_back(static_self_cast()); } - Creature* oldMaster = master; + std::shared_ptr oldMaster = master; master = newMaster; if (oldMaster) { - auto summon = std::find(oldMaster->summons.begin(), oldMaster->summons.end(), this); + auto summon = std::find(oldMaster->summons.begin(), oldMaster->summons.end(), getCreature()); if (summon != oldMaster->summons.end()) { oldMaster->summons.erase(summon); decrementReferenceCounter(); @@ -1244,18 +1243,17 @@ bool Creature::addCondition(Condition* condition) { Condition* prevCond = getCondition(condition->getType(), condition->getId(), condition->getSubId()); if (prevCond) { - prevCond->addCondition(this, condition); - delete condition; + prevCond->addCondition(static_self_cast(), condition); + return true; } - if (condition->startCondition(this)) { + if (condition->startCondition(static_self_cast())) { conditions.push_back(condition); onAddCondition(condition->getType()); return true; } - delete condition; return false; } @@ -1282,8 +1280,7 @@ void Creature::removeCondition(ConditionType_t type) { it = conditions.erase(it); - condition->endCondition(this); - delete condition; + condition->endCondition(static_self_cast()); onEndCondition(type); } @@ -1312,8 +1309,7 @@ void Creature::removeCondition(ConditionType_t conditionType, ConditionId_t cond it = conditions.erase(it); - condition->endCondition(this); - delete condition; + condition->endCondition(static_self_cast()); onEndCondition(conditionType); } @@ -1340,9 +1336,8 @@ void Creature::removeCondition(Condition* condition) { conditions.erase(it); - condition->endCondition(this); + condition->endCondition(static_self_cast()); onEndCondition(condition->getType()); - delete condition; } Condition* Creature::getCondition(ConditionType_t type) const { @@ -1377,13 +1372,12 @@ void Creature::executeConditions(uint32_t interval) { auto it = conditions.begin(), end = conditions.end(); while (it != end) { Condition* condition = *it; - if (!condition->executeCondition(this, interval)) { + if (!condition->executeCondition(static_self_cast(), interval)) { ConditionType_t type = condition->getType(); it = conditions.erase(it); - condition->endCondition(this); - delete condition; + condition->endCondition(static_self_cast()); onEndCondition(type); } else { @@ -1410,7 +1404,7 @@ bool Creature::hasCondition(ConditionType_t type, uint32_t subId /* = 0*/) const return false; } -int64_t Creature::getStepDuration(Direction dir) const { +int64_t Creature::getStepDuration(Direction dir) { int64_t stepDuration = getStepDuration(); if ((dir & DIRECTION_DIAGONAL_MASK) != 0) { stepDuration *= 3; @@ -1418,7 +1412,7 @@ int64_t Creature::getStepDuration(Direction dir) const { return stepDuration; } -int64_t Creature::getStepDuration() const { +int64_t Creature::getStepDuration() { if (isRemoved()) { return 0; } @@ -1429,7 +1423,7 @@ int64_t Creature::getStepDuration() const { uint32_t groundSpeed = 150; if (tile && tile->getGround()) { - Item* ground = tile->getGround(); + std::shared_ptr ground = tile->getGround(); const ItemType &it = Item::items[ground->getID()]; groundSpeed = it.speed > 0 ? it.speed : groundSpeed; } @@ -1437,7 +1431,7 @@ int64_t Creature::getStepDuration() const { double duration = std::floor(1000 * groundSpeed / calculatedStepSpeed); int64_t stepDuration = std::ceil(duration / 50) * 50; - const Monster* monster = getMonster(); + std::shared_ptr monster = getMonster(); if (monster && monster->isTargetNearby() && !monster->isFleeing() && !monster->getMaster()) { stepDuration *= 2; } @@ -1445,7 +1439,7 @@ int64_t Creature::getStepDuration() const { return stepDuration; } -int64_t Creature::getEventStepTicks(bool onlyDelay) const { +int64_t Creature::getEventStepTicks(bool onlyDelay) { int64_t ret = getWalkDelay(); if (ret <= 0) { int64_t stepDuration = getStepDuration(); @@ -1639,11 +1633,11 @@ bool Creature::isInvisible() const { != conditions.end(); } -bool Creature::getPathTo(const Position &targetPos, std::forward_list &dirList, const FindPathParams &fpp) const { - return g_game().map.getPathMatching(*this, dirList, FrozenPathingConditionCall(targetPos), fpp); +bool Creature::getPathTo(const Position &targetPos, std::forward_list &dirList, const FindPathParams &fpp) { + return g_game().map.getPathMatching(getCreature(), dirList, FrozenPathingConditionCall(targetPos), fpp); } -bool Creature::getPathTo(const Position &targetPos, std::forward_list &dirList, int32_t minTargetDist, int32_t maxTargetDist, bool fullPathSearch /*= true*/, bool clearSight /*= true*/, int32_t maxSearchDist /*= 7*/) const { +bool Creature::getPathTo(const Position &targetPos, std::forward_list &dirList, int32_t minTargetDist, int32_t maxTargetDist, bool fullPathSearch /*= true*/, bool clearSight /*= true*/, int32_t maxSearchDist /*= 7*/) { FindPathParams fpp; fpp.fullPathSearch = fullPathSearch; fpp.maxSearchDist = maxSearchDist; @@ -1653,7 +1647,7 @@ bool Creature::getPathTo(const Position &targetPos, std::forward_list return getPathTo(targetPos, dirList, fpp); } -void Creature::turnToCreature(Creature* creature) { +void Creature::turnToCreature(std::shared_ptr creature) { const Position &creaturePos = creature->getPosition(); const auto dx = Position::getOffsetX(position, creaturePos); const auto dy = Position::getOffsetY(position, creaturePos); @@ -1679,10 +1673,10 @@ void Creature::turnToCreature(Creature* creature) { dir = DIRECTION_SOUTH; } } - g_game().internalCreatureTurn(this, dir); + g_game().internalCreatureTurn(static_self_cast(), dir); } -bool Creature::isLostSummon() const { +bool Creature::isLostSummon() { if (!isSummon()) { return false; } @@ -1692,9 +1686,9 @@ bool Creature::isLostSummon() const { void Creature::handleLostSummon(bool teleportSummons) { if (teleportSummons) { - g_game().internalTeleport(this, getMaster()->getPosition(), true); + g_game().internalTeleport(static_self_cast(), getMaster()->getPosition(), true); } else { - g_game().removeCreature(this, true); + g_game().removeCreature(static_self_cast(), true); } g_game().addMagicEffect(getPosition(), CONST_ME_POFF); } @@ -1788,21 +1782,21 @@ const phmap::parallel_flat_hash_set> Creature::getZones() return Zone::getZones(getPosition()); } -void Creature::iconChanged() const { +void Creature::iconChanged() { if (!tile) { return; } SpectatorHashSet spectators; g_game().map.getSpectators(spectators, tile->getPosition(), true); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { if (!spectator) { continue; } - Player* player = spectator->getPlayer(); + auto player = spectator->getPlayer(); if (player) { - player->sendCreatureIcon(this); + player->sendCreatureIcon(getCreature()); } } } diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index 3349ddb83a9..f4ea157372f 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -51,7 +51,7 @@ class FrozenPathingConditionCall { // Defines the Base class for all creatures and base functions which // every creature has -class Creature : virtual public Thing { +class Creature : virtual public Thing, public SharedObject { protected: Creature(); @@ -64,28 +64,16 @@ class Creature : virtual public Thing { Creature(const Creature &) = delete; Creature &operator=(const Creature &) = delete; - Creature* getCreature() override final { - return this; + std::shared_ptr getCreature() override final { + return static_self_cast(); } - const Creature* getCreature() const override final { - return this; - } - virtual Player* getPlayer() { - return nullptr; - } - virtual const Player* getPlayer() const { - return nullptr; - } - virtual Npc* getNpc() { + virtual std::shared_ptr getPlayer() { return nullptr; } - virtual const Npc* getNpc() const { + virtual std::shared_ptr getNpc() { return nullptr; } - virtual Monster* getMonster() { - return nullptr; - } - virtual const Monster* getMonster() const { + virtual std::shared_ptr getMonster() { return nullptr; } @@ -107,8 +95,8 @@ class Creature : virtual public Thing { virtual void removeList() = 0; virtual void addList() = 0; - virtual bool canSee(const Position &pos) const; - virtual bool canSeeCreature(const Creature* creature) const; + virtual bool canSee(const Position &pos); + virtual bool canSeeCreature(std::shared_ptr creature) const; virtual RaceType_t getRace() const { return RACE_NONE; @@ -116,7 +104,7 @@ class Creature : virtual public Thing { virtual Skulls_t getSkull() const { return skull; } - virtual Skulls_t getSkullClient(const Creature* creature) const { + virtual Skulls_t getSkullClient(std::shared_ptr creature) { return creature->getSkull(); } void setSkull(Skulls_t newSkull); @@ -144,7 +132,7 @@ class Creature : virtual public Thing { int32_t getThrowRange() const override final { return 1; } - bool isPushable() const override { + bool isPushable() override { return getWalkDelay() <= 0; } bool isRemoved() const override final { @@ -159,13 +147,13 @@ class Creature : virtual public Thing { int32_t getWalkSize(); - int32_t getWalkDelay(Direction dir) const; - int32_t getWalkDelay() const; + int32_t getWalkDelay(Direction dir); + int32_t getWalkDelay(); int64_t getTimeSinceLastMove() const; - int64_t getEventStepTicks(bool onlyDelay = false) const; - int64_t getStepDuration(Direction dir) const; - int64_t getStepDuration() const; + int64_t getEventStepTicks(bool onlyDelay = false); + int64_t getStepDuration(Direction dir); + int64_t getStepDuration(); virtual uint16_t getStepSpeed() const { return getSpeed(); } @@ -255,7 +243,7 @@ class Creature : virtual public Thing { iconChanged(); } - void iconChanged() const; + void iconChanged(); const Outfit_t getCurrentOutfit() const { return currentOutfit; @@ -268,7 +256,7 @@ class Creature : virtual public Thing { } bool isInvisible() const; ZoneType_t getZoneType() const { - if (getTile()) { + if (tile) { return tile->getZoneType(); } @@ -289,20 +277,20 @@ class Creature : virtual public Thing { virtual void onWalkComplete() { } // follow functions - Creature* getFollowCreature() const { + std::shared_ptr getFollowCreature() const { return followCreature; } - virtual bool setFollowCreature(Creature* creature); + virtual bool setFollowCreature(std::shared_ptr creature); // follow events - virtual void onFollowCreature(const Creature*) { } - virtual void onFollowCreatureComplete(const Creature*) { } + virtual void onFollowCreature(std::shared_ptr) { } + virtual void onFollowCreatureComplete(std::shared_ptr) { } // combat functions - Creature* getAttackedCreature() { + std::shared_ptr getAttackedCreature() { return attackedCreature; } - virtual bool setAttackedCreature(Creature* creature); + virtual bool setAttackedCreature(std::shared_ptr creature); /** * @brief Mitigates damage inflicted on a creature. @@ -317,11 +305,11 @@ class Creature : virtual public Thing { * @param damage Reference to the amount of damage inflicted, which will be reduced by the creature's mitigation factor. */ void mitigateDamage(const CombatType_t &combatType, BlockType_t &blockType, int32_t &damage) const; - virtual BlockType_t blockHit(Creature* attacker, CombatType_t combatType, int32_t &damage, bool checkDefense = false, bool checkArmor = false, bool field = false); + virtual BlockType_t blockHit(std::shared_ptr attacker, CombatType_t combatType, int32_t &damage, bool checkDefense = false, bool checkArmor = false, bool field = false); - void applyAbsorbDamageModifications(const Creature* attacker, int32_t &damage, CombatType_t combatType) const; + void applyAbsorbDamageModifications(std::shared_ptr attacker, int32_t &damage, CombatType_t combatType) const; - bool setMaster(Creature* newMaster, bool reloadCreature = false); + bool setMaster(std::shared_ptr newMaster, bool reloadCreature = false); void removeMaster() { if (master) { @@ -340,11 +328,11 @@ class Creature : virtual public Thing { bool hasBeenSummoned() const { return summoned; } - Creature* getMaster() const { + std::shared_ptr getMaster() const { return master; } - const std::list &getSummons() const { + const std::list> &getSummons() const { return summons; } @@ -400,17 +388,17 @@ class Creature : virtual public Thing { virtual void changeHealth(int32_t healthChange, bool sendHealthChange = true); virtual void changeMana(int32_t manaChange); - void gainHealth(Creature* attacker, int32_t healthGain); - virtual void drainHealth(Creature* attacker, int32_t damage); - virtual void drainMana(Creature* attacker, int32_t manaLoss); + void gainHealth(std::shared_ptr attacker, int32_t healthGain); + virtual void drainHealth(std::shared_ptr attacker, int32_t damage); + virtual void drainMana(std::shared_ptr attacker, int32_t manaLoss); - virtual bool challengeCreature(Creature*, int targetChangeCooldown) { + virtual bool challengeCreature(std::shared_ptr, int targetChangeCooldown) { return false; } void onDeath(); - virtual uint64_t getGainedExperience(Creature* attacker) const; - void addDamagePoints(Creature* attacker, int32_t damagePoints); + virtual uint64_t getGainedExperience(std::shared_ptr attacker) const; + void addDamagePoints(std::shared_ptr attacker, int32_t damagePoints); bool hasBeenAttacked(uint32_t attackerId); // combat event functions @@ -419,13 +407,13 @@ class Creature : virtual public Thing { virtual void onEndCondition(ConditionType_t type); void onTickCondition(ConditionType_t type, bool &bRemove); virtual void onCombatRemoveCondition(Condition* condition); - virtual void onAttackedCreature(Creature*) { } + virtual void onAttackedCreature(std::shared_ptr) { } virtual void onAttacked(); - virtual void onAttackedCreatureDrainHealth(Creature* target, int32_t points); - virtual void onTargetCreatureGainHealth(Creature*, int32_t) { } - void onAttackedCreatureKilled(Creature* target); - virtual bool onKilledCreature(Creature* target, bool lastHit = true); - virtual void onGainExperience(uint64_t gainExp, Creature* target); + virtual void onAttackedCreatureDrainHealth(std::shared_ptr target, int32_t points); + virtual void onTargetCreatureGainHealth(std::shared_ptr, int32_t) { } + void onAttackedCreatureKilled(std::shared_ptr target); + virtual bool onKilledCreature(std::shared_ptr target, bool lastHit = true); + virtual void onGainExperience(uint64_t gainExp, std::shared_ptr target); virtual void onAttackedCreatureBlockHit(BlockType_t) { } virtual void onBlockHit() { } virtual void onChangeZone(ZoneType_t zone); @@ -441,14 +429,14 @@ class Creature : virtual public Thing { virtual void onCreatureWalk(); virtual bool getNextStep(Direction &dir, uint32_t &flags); - virtual void turnToCreature(Creature* creature); + virtual void turnToCreature(std::shared_ptr creature); - void onAddTileItem(const Tile* tile, const Position &pos); - virtual void onUpdateTileItem(const Tile* tile, const Position &pos, const Item* oldItem, const ItemType &oldType, const Item* newItem, const ItemType &newType); - virtual void onRemoveTileItem(const Tile* tile, const Position &pos, const ItemType &iType, const Item* item); + void onAddTileItem(std::shared_ptr tile, const Position &pos); + virtual void onUpdateTileItem(std::shared_ptr tile, const Position &pos, std::shared_ptr oldItem, const ItemType &oldType, std::shared_ptr newItem, const ItemType &newType); + virtual void onRemoveTileItem(std::shared_ptr tile, const Position &pos, const ItemType &iType, std::shared_ptr item); - virtual void onCreatureAppear(Creature* creature, bool isLogin); - virtual void onRemoveCreature(Creature* creature, bool isLogout); + virtual void onCreatureAppear(std::shared_ptr creature, bool isLogin); + virtual void onRemoveCreature(std::shared_ptr creature, bool isLogout); /** * @brief Check if the summon can move/spawn and if the familiar can teleport to the master @@ -459,12 +447,12 @@ class Creature : virtual public Thing { * @return false */ void checkSummonMove(const Position &newPos, bool teleportSummon = false) const; - virtual void onCreatureMove(Creature* creature, const Tile* newTile, const Position &newPos, const Tile* oldTile, const Position &oldPos, bool teleport); + virtual void onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport); virtual void onAttackedCreatureDisappear(bool) { } virtual void onFollowCreatureDisappear(bool) { } - virtual void onCreatureSay(Creature*, SpeakClasses, const std::string &) { } + virtual void onCreatureSay(std::shared_ptr, SpeakClasses, const std::string &) { } virtual void onPlacedCreature() { } @@ -503,26 +491,23 @@ class Creature : virtual public Thing { bool registerCreatureEvent(const std::string &name); bool unregisterCreatureEvent(const std::string &name); - Cylinder* getParent() const override final { + std::shared_ptr getParent() const override final { return tile; } - void setParent(Cylinder* cylinder) override final { - tile = static_cast(cylinder); + void setParent(std::shared_ptr cylinder) override final { + tile = std::static_pointer_cast(cylinder); position = tile->getPosition(); } - const Position &getPosition() const override final { + const Position &getPosition() override final { return position; } - Tile* getTile() override final { - return tile; - } - const Tile* getTile() const override final { + std::shared_ptr getTile() override final { return tile; } - int32_t getWalkCache(const Position &pos) const; + int32_t getWalkCache(const Position &pos); const Position &getLastPosition() const { return lastPosition; @@ -533,17 +518,16 @@ class Creature : virtual public Thing { static bool canSee(const Position &myPos, const Position &pos, int32_t viewRangeX, int32_t viewRangeY); - double getDamageRatio(Creature* attacker) const; + double getDamageRatio(std::shared_ptr attacker) const; - bool getPathTo(const Position &targetPos, std::forward_list &dirList, const FindPathParams &fpp) const; - bool getPathTo(const Position &targetPos, std::forward_list &dirList, int32_t minTargetDist, int32_t maxTargetDist, bool fullPathSearch = true, bool clearSight = true, int32_t maxSearchDist = 7) const; + bool getPathTo(const Position &targetPos, std::forward_list &dirList, const FindPathParams &fpp); + bool getPathTo(const Position &targetPos, std::forward_list &dirList, int32_t minTargetDist, int32_t maxTargetDist, bool fullPathSearch = true, bool clearSight = true, int32_t maxSearchDist = 7); void incrementReferenceCounter() { ++referenceCounter; } void decrementReferenceCounter() { if (--referenceCounter == 0) { - delete this; } } struct CountBlock_t { @@ -675,16 +659,16 @@ class Creature : virtual public Thing { CountMap damageMap; - std::list summons; + std::list> summons; CreatureEventList eventsList; ConditionList conditions; std::forward_list listWalkDir; - Tile* tile = nullptr; - Creature* attackedCreature = nullptr; - Creature* master = nullptr; - Creature* followCreature = nullptr; + std::shared_ptr tile = nullptr; + std::shared_ptr attackedCreature = nullptr; + std::shared_ptr master = nullptr; + std::shared_ptr followCreature = nullptr; /** * We need to persist if this creature is summon or not because when we @@ -761,9 +745,9 @@ class Creature : virtual public Thing { CreatureEventList getCreatureEvents(CreatureEventType_t type); void updateMapCache(); - void updateTileCache(const Tile* tile, int32_t dx, int32_t dy); - void updateTileCache(const Tile* tile, const Position &pos); - void onCreatureDisappear(const Creature* creature, bool isLogout); + void updateTileCache(std::shared_ptr tile, int32_t dx, int32_t dy); + void updateTileCache(std::shared_ptr tile, const Position &pos); + void onCreatureDisappear(std::shared_ptr creature, bool isLogout); virtual void doAttacking(uint32_t) { } virtual bool hasExtraSwing() { return false; @@ -772,14 +756,14 @@ class Creature : virtual public Thing { virtual uint64_t getLostExperience() const { return 0; } - virtual void dropLoot(Container*, Creature*) { } + virtual void dropLoot(std::shared_ptr, std::shared_ptr) { } virtual uint16_t getLookCorpse() const { return 0; } - virtual void getPathSearchParams(const Creature* creature, FindPathParams &fpp) const; - virtual void death(Creature*) { } - virtual bool dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified); - virtual Item* getCorpse(Creature* lastHitCreature, Creature* mostDamageCreature); + virtual void getPathSearchParams(std::shared_ptr creature, FindPathParams &fpp); + virtual void death(std::shared_ptr) { } + virtual bool dropCorpse(std::shared_ptr lastHitCreature, std::shared_ptr mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified); + virtual std::shared_ptr getCorpse(std::shared_ptr lastHitCreature, std::shared_ptr mostDamageCreature); friend class Game; friend class Map; @@ -787,6 +771,6 @@ class Creature : virtual public Thing { private: bool canFollowMaster() const; - bool isLostSummon() const; + bool isLostSummon(); void handleLostSummon(bool teleportSummons); }; diff --git a/src/creatures/interactions/chat.cpp b/src/creatures/interactions/chat.cpp index 1e6dab2d701..6aaf7390e91 100644 --- a/src/creatures/interactions/chat.cpp +++ b/src/creatures/interactions/chat.cpp @@ -25,40 +25,40 @@ bool PrivateChatChannel::removeInvite(uint32_t guid) { return invites.erase(guid) != 0; } -void PrivateChatChannel::invitePlayer(const Player &player, Player &invitePlayer) { - auto result = invites.emplace(invitePlayer.getGUID(), &invitePlayer); +void PrivateChatChannel::invitePlayer(const std::shared_ptr &player, const std::shared_ptr &invitePlayer) { + auto result = invites.emplace(invitePlayer->getGUID(), invitePlayer); if (!result.second) { return; } std::ostringstream ss; - ss << player.getName() << " invites you to " << player.getPossessivePronoun() << " private chat channel."; - invitePlayer.sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); + ss << player->getName() << " invites you to " << player->getPossessivePronoun() << " private chat channel."; + invitePlayer->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); ss.str(std::string()); - ss << invitePlayer.getName() << " has been invited."; - player.sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); + ss << invitePlayer->getName() << " has been invited."; + player->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); for (const auto &it : users) { - it.second->sendChannelEvent(id, invitePlayer.getName(), CHANNELEVENT_INVITE); + it.second->sendChannelEvent(id, invitePlayer->getName(), CHANNELEVENT_INVITE); } } -void PrivateChatChannel::excludePlayer(const Player &player, Player &excludePlayer) { - if (!removeInvite(excludePlayer.getGUID())) { +void PrivateChatChannel::excludePlayer(const std::shared_ptr &player, const std::shared_ptr &excludePlayer) { + if (!removeInvite(excludePlayer->getGUID())) { return; } removeUser(excludePlayer); std::ostringstream ss; - ss << excludePlayer.getName() << " has been excluded."; - player.sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); + ss << excludePlayer->getName() << " has been excluded."; + player->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); - excludePlayer.sendClosePrivate(id); + excludePlayer->sendClosePrivate(id); for (const auto &it : users) { - it.second->sendChannelEvent(id, excludePlayer.getName(), CHANNELEVENT_EXCLUDE); + it.second->sendChannelEvent(id, excludePlayer->getName(), CHANNELEVENT_EXCLUDE); } } @@ -68,8 +68,8 @@ void PrivateChatChannel::closeChannel() const { } } -bool ChatChannel::addUser(Player &player) { - if (users.find(player.getID()) != users.end()) { +bool ChatChannel::addUser(const std::shared_ptr &player) { + if (users.find(player->getID()) != users.end()) { return false; } @@ -79,24 +79,24 @@ bool ChatChannel::addUser(Player &player) { // TODO: Move to script when guild channels can be scripted if (id == CHANNEL_GUILD) { - const auto guild = player.getGuild(); + const auto guild = player->getGuild(); if (guild && !guild->getMotd().empty()) { - g_scheduler().addEvent(150, std::bind(&Game::sendGuildMotd, &g_game(), player.getID()), "Game::sendGuildMotd"); + g_scheduler().addEvent(150, std::bind(&Game::sendGuildMotd, &g_game(), player->getID()), "Game::sendGuildMotd"); } } if (!publicChannel) { for (const auto &it : users) { - it.second->sendChannelEvent(id, player.getName(), CHANNELEVENT_JOIN); + it.second->sendChannelEvent(id, player->getName(), CHANNELEVENT_JOIN); } } - users[player.getID()] = &player; + users[player->getID()] = player; return true; } -bool ChatChannel::removeUser(const Player &player) { - auto iter = users.find(player.getID()); +bool ChatChannel::removeUser(const std::shared_ptr &player) { + auto iter = users.find(player->getID()); if (iter == users.end()) { return false; } @@ -105,7 +105,7 @@ bool ChatChannel::removeUser(const Player &player) { if (!publicChannel) { for (const auto &it : users) { - it.second->sendChannelEvent(id, player.getName(), CHANNELEVENT_LEAVE); + it.second->sendChannelEvent(id, player->getName(), CHANNELEVENT_LEAVE); } } @@ -113,8 +113,8 @@ bool ChatChannel::removeUser(const Player &player) { return true; } -bool ChatChannel::hasUser(const Player &player) { - return users.find(player.getID()) != users.end(); +bool ChatChannel::hasUser(const std::shared_ptr &player) { + return users.find(player->getID()) != users.end(); } void ChatChannel::sendToAll(const std::string &message, SpeakClasses type) const { @@ -123,18 +123,18 @@ void ChatChannel::sendToAll(const std::string &message, SpeakClasses type) const } } -bool ChatChannel::talk(const Player &fromPlayer, SpeakClasses type, const std::string &text) { - if (users.find(fromPlayer.getID()) == users.end()) { +bool ChatChannel::talk(const std::shared_ptr &fromPlayer, SpeakClasses type, const std::string &text) { + if (users.find(fromPlayer->getID()) == users.end()) { return false; } for (const auto &it : users) { - it.second->sendToChannel(&fromPlayer, type, text, id); + it.second->sendToChannel(fromPlayer, type, text, id); } return true; } -bool ChatChannel::executeCanJoinEvent(const Player &player) { +bool ChatChannel::executeCanJoinEvent(const std::shared_ptr &player) { if (canJoinEvent == -1) { return true; } @@ -144,7 +144,7 @@ bool ChatChannel::executeCanJoinEvent(const Player &player) { if (!scriptInterface->reserveScriptEnv()) { g_logger().error("[CanJoinChannelEvent::execute - Player {}, on channel {}] " "Call stack overflow. Too many lua script calls being nested.", - player.getName(), getName()); + player->getName(), getName()); return false; } @@ -160,7 +160,7 @@ bool ChatChannel::executeCanJoinEvent(const Player &player) { return scriptInterface->callFunction(1); } -bool ChatChannel::executeOnJoinEvent(const Player &player) { +bool ChatChannel::executeOnJoinEvent(const std::shared_ptr &player) { if (onJoinEvent == -1) { return true; } @@ -170,7 +170,7 @@ bool ChatChannel::executeOnJoinEvent(const Player &player) { if (!scriptInterface->reserveScriptEnv()) { g_logger().error("[OnJoinChannelEvent::execute - Player {}, on channel {}] " "Call stack overflow. Too many lua script calls being nested", - player.getName(), getName()); + player->getName(), getName()); return false; } @@ -186,7 +186,7 @@ bool ChatChannel::executeOnJoinEvent(const Player &player) { return scriptInterface->callFunction(1); } -bool ChatChannel::executeOnLeaveEvent(const Player &player) { +bool ChatChannel::executeOnLeaveEvent(const std::shared_ptr &player) { if (onLeaveEvent == -1) { return true; } @@ -196,7 +196,7 @@ bool ChatChannel::executeOnLeaveEvent(const Player &player) { if (!scriptInterface->reserveScriptEnv()) { g_logger().error("[OnLeaveChannelEvent::execute - Player {}, on channel {}] " "Call stack overflow. Too many lua script calls being nested.", - player.getName(), getName()); + player->getName(), getName()); return false; } @@ -212,7 +212,7 @@ bool ChatChannel::executeOnLeaveEvent(const Player &player) { return scriptInterface->callFunction(1); } -bool ChatChannel::executeOnSpeakEvent(const Player &player, SpeakClasses &type, const std::string &message) { +bool ChatChannel::executeOnSpeakEvent(const std::shared_ptr &player, SpeakClasses &type, const std::string &message) { if (onSpeakEvent == -1) { return true; } @@ -222,7 +222,7 @@ bool ChatChannel::executeOnSpeakEvent(const Player &player, SpeakClasses &type, if (!scriptInterface->reserveScriptEnv()) { g_logger().error("[OnSpeakChannelEvent::execute - Player {}, type {}] " "Call stack overflow. Too many lua script calls being nested.", - player.getName(), fmt::underlying(type)); + player->getName(), fmt::underlying(type)); return false; } @@ -301,7 +301,7 @@ bool Chat::load() { UsersMap tempUserMap = std::move(channel.users); for (const auto &pair : tempUserMap) { - channel.addUser(*pair.second); + channel.addUser(pair.second); } continue; } @@ -325,14 +325,14 @@ bool Chat::load() { return true; } -ChatChannel* Chat::createChannel(const Player &player, uint16_t channelId) { +ChatChannel* Chat::createChannel(const std::shared_ptr &player, uint16_t channelId) { if (getChannel(player, channelId) != nullptr) { return nullptr; } switch (channelId) { case CHANNEL_GUILD: { - const auto guild = player.getGuild(); + const auto guild = player->getGuild(); if (guild != nullptr) { auto ret = guildChannels.emplace(std::make_pair(guild->getId(), ChatChannel(channelId, guild->getName()))); return &ret.first->second; @@ -341,7 +341,7 @@ ChatChannel* Chat::createChannel(const Player &player, uint16_t channelId) { } case CHANNEL_PARTY: { - Party* party = player.getParty(); + Party* party = player->getParty(); if (party != nullptr) { auto ret = partyChannels.emplace(std::make_pair(party, ChatChannel(channelId, "Party"))); return &ret.first->second; @@ -351,16 +351,16 @@ ChatChannel* Chat::createChannel(const Player &player, uint16_t channelId) { case CHANNEL_PRIVATE: { // only 1 private channel for each premium player - if (!player.isPremium() || (getPrivateChannel(player) != nullptr)) { + if (!player->isPremium() || (getPrivateChannel(player) != nullptr)) { return nullptr; } // find a free private channel slot for (uint16_t i = 100; i < 10000; ++i) { - auto ret = privateChannels.emplace(std::make_pair(i, PrivateChatChannel(i, player.getName() + "'s Channel"))); + auto ret = privateChannels.emplace(std::make_pair(i, PrivateChatChannel(i, player->getName() + "'s Channel"))); if (ret.second) { // second is a bool that indicates that a new channel has been placed in the map auto &newChannel = (*ret.first).second; - newChannel.setOwner(player.getGUID()); + newChannel.setOwner(player->getGUID()); return &newChannel; } } @@ -373,10 +373,10 @@ ChatChannel* Chat::createChannel(const Player &player, uint16_t channelId) { return nullptr; } -bool Chat::deleteChannel(const Player &player, uint16_t channelId) { +bool Chat::deleteChannel(const std::shared_ptr &player, uint16_t channelId) { switch (channelId) { case CHANNEL_GUILD: { - const auto guild = player.getGuild(); + const auto guild = player->getGuild(); if (guild == nullptr) { return false; } @@ -391,7 +391,7 @@ bool Chat::deleteChannel(const Player &player, uint16_t channelId) { } case CHANNEL_PARTY: { - Party* party = player.getParty(); + Party* party = player->getParty(); if (party == nullptr) { return false; } @@ -420,7 +420,7 @@ bool Chat::deleteChannel(const Player &player, uint16_t channelId) { return true; } -ChatChannel* Chat::addUserToChannel(Player &player, uint16_t channelId) { +ChatChannel* Chat::addUserToChannel(const std::shared_ptr &player, uint16_t channelId) { ChatChannel* channel = getChannel(player, channelId); if ((channel != nullptr) && channel->addUser(player)) { return channel; @@ -428,19 +428,19 @@ ChatChannel* Chat::addUserToChannel(Player &player, uint16_t channelId) { return nullptr; } -bool Chat::removeUserFromChannel(const Player &player, uint16_t channelId) { +bool Chat::removeUserFromChannel(const std::shared_ptr &player, uint16_t channelId) { ChatChannel* channel = getChannel(player, channelId); if ((channel == nullptr) || !channel->removeUser(player)) { return false; } - if (channel->getOwner() == player.getGUID()) { + if (channel->getOwner() == player->getGUID()) { deleteChannel(player, channelId); } return true; } -void Chat::removeUserFromAllChannels(const Player &player) { +void Chat::removeUserFromAllChannels(const std::shared_ptr &player) { for (auto &it : normalChannels) { it.second.removeUser(player); } @@ -456,9 +456,9 @@ void Chat::removeUserFromAllChannels(const Player &player) { auto it = privateChannels.begin(); while (it != privateChannels.end()) { PrivateChatChannel* channel = &it->second; - channel->removeInvite(player.getGUID()); + channel->removeInvite(player->getGUID()); channel->removeUser(player); - if (channel->getOwner() == player.getGUID()) { + if (channel->getOwner() == player->getGUID()) { channel->closeChannel(); it = privateChannels.erase(it); } else { @@ -467,14 +467,14 @@ void Chat::removeUserFromAllChannels(const Player &player) { } } -bool Chat::talkToChannel(const Player &player, SpeakClasses type, const std::string &text, uint16_t channelId) { +bool Chat::talkToChannel(const std::shared_ptr &player, SpeakClasses type, const std::string &text, uint16_t channelId) { ChatChannel* channel = getChannel(player, channelId); if (channel == nullptr) { return false; } if (channelId == CHANNEL_GUILD) { - GuildRank_ptr rank = player.getGuildRank(); + GuildRank_ptr rank = player->getGuildRank(); if (rank && rank->level > 1) { type = TALKTYPE_CHANNEL_O; } else if (type != TALKTYPE_CHANNEL_Y) { @@ -491,9 +491,9 @@ bool Chat::talkToChannel(const Player &player, SpeakClasses type, const std::str return channel->talk(player, type, text); } -ChannelList Chat::getChannelList(const Player &player) { +ChannelList Chat::getChannelList(const std::shared_ptr &player) { ChannelList list; - if (player.getGuild()) { + if (player->getGuild()) { ChatChannel* channel = getChannel(player, CHANNEL_GUILD); if (channel) { list.push_back(channel); @@ -505,7 +505,7 @@ ChannelList Chat::getChannelList(const Player &player) { } } - if (player.getParty()) { + if (player->getParty()) { ChatChannel* channel = getChannel(player, CHANNEL_PARTY); if (channel) { list.push_back(channel); @@ -527,7 +527,7 @@ ChannelList Chat::getChannelList(const Player &player) { bool hasPrivate = false; for (auto &it : privateChannels) { if (PrivateChatChannel* channel = &it.second) { - uint32_t guid = player.getGUID(); + uint32_t guid = player->getGUID(); if (channel->isInvited(guid)) { list.push_back(channel); } @@ -538,16 +538,16 @@ ChannelList Chat::getChannelList(const Player &player) { } } - if (!hasPrivate && player.isPremium()) { + if (!hasPrivate && player->isPremium()) { list.push_front(&dummyPrivate); } return list; } -ChatChannel* Chat::getChannel(const Player &player, uint16_t channelId) { +ChatChannel* Chat::getChannel(const std::shared_ptr &player, uint16_t channelId) { switch (channelId) { case CHANNEL_GUILD: { - const auto guild = player.getGuild(); + const auto guild = player->getGuild(); if (guild != nullptr) { auto it = guildChannels.find(guild->getId()); if (it != guildChannels.end()) { @@ -558,7 +558,7 @@ ChatChannel* Chat::getChannel(const Player &player, uint16_t channelId) { } case CHANNEL_PARTY: { - Party* party = player.getParty(); + Party* party = player->getParty(); if (party != nullptr) { auto it = partyChannels.find(party); if (it != partyChannels.end()) { @@ -579,7 +579,7 @@ ChatChannel* Chat::getChannel(const Player &player, uint16_t channelId) { } auto it2 = privateChannels.find(channelId); - if (it2 != privateChannels.end() && it2->second.isInvited(player.getGUID())) { + if (it2 != privateChannels.end() && it2->second.isInvited(player->getGUID())) { return &it2->second; } break; @@ -604,9 +604,9 @@ ChatChannel* Chat::getChannelById(uint16_t channelId) { return &it->second; } -PrivateChatChannel* Chat::getPrivateChannel(const Player &player) { +PrivateChatChannel* Chat::getPrivateChannel(const std::shared_ptr &player) { for (auto &it : privateChannels) { - if (it.second.getOwner() == player.getGUID()) { + if (it.second.getOwner() == player->getGUID()) { return &it.second; } } diff --git a/src/creatures/interactions/chat.hpp b/src/creatures/interactions/chat.hpp index dad87d87986..fcacca6865c 100644 --- a/src/creatures/interactions/chat.hpp +++ b/src/creatures/interactions/chat.hpp @@ -16,8 +16,8 @@ class Party; class Player; -using UsersMap = std::map; -using InvitedMap = std::map; +using UsersMap = std::map>; +using InvitedMap = std::map>; class ChatChannel { public: @@ -28,11 +28,11 @@ class ChatChannel { virtual ~ChatChannel() = default; - bool addUser(Player &player); - bool removeUser(const Player &player); - bool hasUser(const Player &player); + bool addUser(const std::shared_ptr &player); + bool removeUser(const std::shared_ptr &player); + bool hasUser(const std::shared_ptr &player); - bool talk(const Player &fromPlayer, SpeakClasses type, const std::string &text); + bool talk(const std::shared_ptr &fromPlayer, SpeakClasses type, const std::string &text); void sendToAll(const std::string &message, SpeakClasses type) const; const std::string &getName() const { @@ -56,10 +56,10 @@ class ChatChannel { return publicChannel; } - bool executeOnJoinEvent(const Player &player); - bool executeCanJoinEvent(const Player &player); - bool executeOnLeaveEvent(const Player &player); - bool executeOnSpeakEvent(const Player &player, SpeakClasses &type, const std::string &message); + bool executeOnJoinEvent(const std::shared_ptr &player); + bool executeCanJoinEvent(const std::shared_ptr &player); + bool executeOnLeaveEvent(const std::shared_ptr &player); + bool executeOnSpeakEvent(const std::shared_ptr &player, SpeakClasses &type, const std::string &message); protected: UsersMap users; @@ -91,8 +91,8 @@ class PrivateChatChannel final : public ChatChannel { bool isInvited(uint32_t guid) const; - void invitePlayer(const Player &player, Player &invitePlayer); - void excludePlayer(const Player &player, Player &excludePlayer); + void invitePlayer(const std::shared_ptr &player, const std::shared_ptr &invitePlayer); + void excludePlayer(const std::shared_ptr &player, const std::shared_ptr &excludePlayer); bool removeInvite(uint32_t guid); @@ -123,21 +123,21 @@ class Chat { bool load(); - ChatChannel* createChannel(const Player &player, uint16_t channelId); - bool deleteChannel(const Player &player, uint16_t channelId); + ChatChannel* createChannel(const std::shared_ptr &player, uint16_t channelId); + bool deleteChannel(const std::shared_ptr &player, uint16_t channelId); - ChatChannel* addUserToChannel(Player &player, uint16_t channelId); - bool removeUserFromChannel(const Player &player, uint16_t channelId); - void removeUserFromAllChannels(const Player &player); + ChatChannel* addUserToChannel(const std::shared_ptr &player, uint16_t channelId); + bool removeUserFromChannel(const std::shared_ptr &player, uint16_t channelId); + void removeUserFromAllChannels(const std::shared_ptr &player); - bool talkToChannel(const Player &player, SpeakClasses type, const std::string &text, uint16_t channelId); + bool talkToChannel(const std::shared_ptr &player, SpeakClasses type, const std::string &text, uint16_t channelId); - ChannelList getChannelList(const Player &player); + ChannelList getChannelList(const std::shared_ptr &player); - ChatChannel* getChannel(const Player &player, uint16_t channelId); + ChatChannel* getChannel(const std::shared_ptr &player, uint16_t channelId); ChatChannel* getChannelById(uint16_t channelId); ChatChannel* getGuildChannelById(uint32_t guildId); - PrivateChatChannel* getPrivateChannel(const Player &player); + PrivateChatChannel* getPrivateChannel(const std::shared_ptr &player); LuaScriptInterface* getScriptInterface() { return &scriptInterface; diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 43d41567bfa..b1e11ccd79a 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -23,12 +23,12 @@ int32_t Monster::despawnRadius; uint32_t Monster::monsterAutoID = 0x50000001; -Monster* Monster::createMonster(const std::string &name) { +std::shared_ptr Monster::createMonster(const std::string &name) { const auto mType = g_monsters().getMonsterType(name); if (!mType) { return nullptr; } - return new Monster(mType); + return std::make_shared(mType); } Monster::Monster(const std::shared_ptr mType) : @@ -62,11 +62,11 @@ Monster::~Monster() { } void Monster::addList() { - g_game().addMonster(this); + g_game().addMonster(static_self_cast()); } void Monster::removeList() { - g_game().removeMonster(this); + g_game().removeMonster(static_self_cast()); } bool Monster::canWalkOnFieldType(CombatType_t combatType) const { @@ -104,7 +104,7 @@ void Monster::onAttackedCreatureDisappear(bool) { extraMeleeAttack = true; } -void Monster::onCreatureAppear(Creature* creature, bool isLogin) { +void Monster::onCreatureAppear(std::shared_ptr creature, bool isLogin) { Creature::onCreatureAppear(creature, isLogin); if (mType->info.creatureAppearEvent != -1) { @@ -123,7 +123,7 @@ void Monster::onCreatureAppear(Creature* creature, bool isLogin) { lua_State* L = scriptInterface->getLuaState(); scriptInterface->pushFunction(mType->info.creatureAppearEvent); - LuaScriptInterface::pushUserdata(L, this); + LuaScriptInterface::pushUserdata(L, getMonster()); LuaScriptInterface::setMetatable(L, -1, "Monster"); LuaScriptInterface::pushUserdata(L, creature); @@ -134,7 +134,7 @@ void Monster::onCreatureAppear(Creature* creature, bool isLogin) { } } - if (creature == this) { + if (creature.get() == this) { updateTargetList(); updateIdleStatus(); } else { @@ -142,7 +142,7 @@ void Monster::onCreatureAppear(Creature* creature, bool isLogin) { } } -void Monster::onRemoveCreature(Creature* creature, bool isLogout) { +void Monster::onRemoveCreature(std::shared_ptr creature, bool isLogout) { Creature::onRemoveCreature(creature, isLogout); if (mType->info.creatureDisappearEvent != -1) { @@ -161,7 +161,7 @@ void Monster::onRemoveCreature(Creature* creature, bool isLogout) { lua_State* L = scriptInterface->getLuaState(); scriptInterface->pushFunction(mType->info.creatureDisappearEvent); - LuaScriptInterface::pushUserdata(L, this); + LuaScriptInterface::pushUserdata(L, getMonster()); LuaScriptInterface::setMetatable(L, -1, "Monster"); LuaScriptInterface::pushUserdata(L, creature); @@ -172,7 +172,7 @@ void Monster::onRemoveCreature(Creature* creature, bool isLogout) { } } - if (creature == this) { + if (creature.get() == this) { if (spawnMonster) { spawnMonster->startSpawnMonsterCheck(); } @@ -183,7 +183,7 @@ void Monster::onRemoveCreature(Creature* creature, bool isLogout) { } } -void Monster::onCreatureMove(Creature* creature, const Tile* newTile, const Position &newPos, const Tile* oldTile, const Position &oldPos, bool teleport) { +void Monster::onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport) { Creature::onCreatureMove(creature, newTile, newPos, oldTile, oldPos, teleport); if (mType->info.creatureMoveEvent != -1) { @@ -202,7 +202,7 @@ void Monster::onCreatureMove(Creature* creature, const Tile* newTile, const Posi lua_State* L = scriptInterface->getLuaState(); scriptInterface->pushFunction(mType->info.creatureMoveEvent); - LuaScriptInterface::pushUserdata(L, this); + LuaScriptInterface::pushUserdata(L, getMonster()); LuaScriptInterface::setMetatable(L, -1, "Monster"); LuaScriptInterface::pushUserdata(L, creature); @@ -216,7 +216,7 @@ void Monster::onCreatureMove(Creature* creature, const Tile* newTile, const Posi } } - if (creature == this) { + if (creature.get() == this) { updateTargetList(); updateIdleStatus(); } else { @@ -242,9 +242,9 @@ void Monster::onCreatureMove(Creature* creature, const Tile* newTile, const Posi Direction dir = getDirectionTo(pos, followPosition); const Position &checkPosition = getNextPosition(dir, pos); - const Tile* nextTile = g_game().map.getTile(checkPosition); + auto nextTile = g_game().map.getTile(checkPosition); if (nextTile) { - Creature* topCreature = nextTile->getTopCreature(); + auto topCreature = nextTile->getTopCreature(); if (topCreature && followCreature != topCreature && isOpponent(topCreature)) { selectTarget(topCreature); } @@ -258,7 +258,7 @@ void Monster::onCreatureMove(Creature* creature, const Tile* newTile, const Posi } } -void Monster::onCreatureSay(Creature* creature, SpeakClasses type, const std::string &text) { +void Monster::onCreatureSay(std::shared_ptr creature, SpeakClasses type, const std::string &text) { Creature::onCreatureSay(creature, type, text); if (mType->info.creatureSayEvent != -1) { @@ -277,7 +277,7 @@ void Monster::onCreatureSay(Creature* creature, SpeakClasses type, const std::st lua_State* L = scriptInterface->getLuaState(); scriptInterface->pushFunction(mType->info.creatureSayEvent); - LuaScriptInterface::pushUserdata(L, this); + LuaScriptInterface::pushUserdata(L, getMonster()); LuaScriptInterface::setMetatable(L, -1, "Monster"); LuaScriptInterface::pushUserdata(L, creature); @@ -290,15 +290,15 @@ void Monster::onCreatureSay(Creature* creature, SpeakClasses type, const std::st } } -void Monster::addFriend(Creature* creature) { - assert(creature != this); +void Monster::addFriend(std::shared_ptr creature) { + assert(creature.get() != this); auto result = friendList.insert(creature); if (result.second) { creature->incrementReferenceCounter(); } } -void Monster::removeFriend(Creature* creature) { +void Monster::removeFriend(std::shared_ptr creature) { auto it = friendList.find(creature); if (it != friendList.end()) { creature->decrementReferenceCounter(); @@ -306,8 +306,8 @@ void Monster::removeFriend(Creature* creature) { } } -void Monster::addTarget(Creature* creature, bool pushFront /* = false*/) { - assert(creature != this); +void Monster::addTarget(std::shared_ptr creature, bool pushFront /* = false*/) { + assert(creature.get() != this); if (std::find(targetList.begin(), targetList.end(), creature) == targetList.end()) { creature->incrementReferenceCounter(); if (pushFront) { @@ -321,7 +321,7 @@ void Monster::addTarget(Creature* creature, bool pushFront /* = false*/) { } } -void Monster::removeTarget(Creature* creature) { +void Monster::removeTarget(std::shared_ptr creature) { if (!creature) { return; } @@ -340,7 +340,7 @@ void Monster::removeTarget(Creature* creature) { void Monster::updateTargetList() { auto friendIterator = friendList.begin(); while (friendIterator != friendList.end()) { - Creature* creature = *friendIterator; + std::shared_ptr creature = *friendIterator; if (creature->getHealth() <= 0 || !canSee(creature->getPosition())) { creature->decrementReferenceCounter(); friendIterator = friendList.erase(friendIterator); @@ -351,7 +351,7 @@ void Monster::updateTargetList() { auto targetIterator = targetList.begin(); while (targetIterator != targetList.end()) { - Creature* creature = *targetIterator; + std::shared_ptr creature = *targetIterator; if (creature->getHealth() <= 0 || !canSee(creature->getPosition())) { creature->decrementReferenceCounter(); targetIterator = targetList.erase(targetIterator); @@ -363,7 +363,7 @@ void Monster::updateTargetList() { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, position, true); spectators.erase(this); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { if (canSee(spectator->getPosition())) { onCreatureFound(spectator); } @@ -371,20 +371,20 @@ void Monster::updateTargetList() { } void Monster::clearTargetList() { - for (Creature* creature : targetList) { + for (std::shared_ptr creature : targetList) { creature->decrementReferenceCounter(); } targetList.clear(); } void Monster::clearFriendList() { - for (Creature* creature : friendList) { + for (std::shared_ptr creature : friendList) { creature->decrementReferenceCounter(); } friendList.clear(); } -void Monster::onCreatureFound(Creature* creature, bool pushFront /* = false*/) { +void Monster::onCreatureFound(std::shared_ptr creature, bool pushFront /* = false*/) { if (isFriend(creature)) { addFriend(creature); } @@ -396,19 +396,19 @@ void Monster::onCreatureFound(Creature* creature, bool pushFront /* = false*/) { updateIdleStatus(); } -void Monster::onCreatureEnter(Creature* creature) { +void Monster::onCreatureEnter(std::shared_ptr creature) { onCreatureFound(creature, true); } -bool Monster::isFriend(const Creature* creature) const { +bool Monster::isFriend(std::shared_ptr creature) const { if (isSummon() && getMaster()->getPlayer()) { - const Player* masterPlayer = getMaster()->getPlayer(); - const Player* tmpPlayer = nullptr; + std::shared_ptr masterPlayer = getMaster()->getPlayer(); + std::shared_ptr tmpPlayer = nullptr; if (creature->getPlayer()) { tmpPlayer = creature->getPlayer(); } else { - const Creature* creatureMaster = creature->getMaster(); + std::shared_ptr creatureMaster = creature->getMaster(); if (creatureMaster && creatureMaster->getPlayer()) { tmpPlayer = creatureMaster->getPlayer(); @@ -425,7 +425,7 @@ bool Monster::isFriend(const Creature* creature) const { return false; } -bool Monster::isOpponent(const Creature* creature) const { +bool Monster::isOpponent(std::shared_ptr creature) const { if (isSummon() && getMaster()->getPlayer()) { if (creature != getMaster()) { return true; @@ -444,7 +444,7 @@ bool Monster::isOpponent(const Creature* creature) const { return false; } -void Monster::onCreatureLeave(Creature* creature) { +void Monster::onCreatureLeave(std::shared_ptr creature) { // update friendList if (isFriend(creature)) { removeFriend(creature); @@ -480,12 +480,12 @@ bool Monster::searchTarget(TargetSearchType_t searchType /*= TARGETSEARCH_DEFAUL } } - std::list resultList; + std::list> resultList; const Position &myPos = getPosition(); - for (Creature* creature : targetList) { + for (std::shared_ptr creature : targetList) { if (isTarget(creature)) { - if ((this->targetDistance == 1) || canUseAttack(myPos, creature)) { + if ((static_self_cast()->targetDistance == 1) || canUseAttack(myPos, creature)) { resultList.push_back(creature); } } @@ -495,7 +495,7 @@ bool Monster::searchTarget(TargetSearchType_t searchType /*= TARGETSEARCH_DEFAUL return false; } - Creature* getTarget = nullptr; + std::shared_ptr getTarget = nullptr; switch (searchType) { case TARGETSEARCH_NEAREST: { @@ -519,7 +519,7 @@ bool Monster::searchTarget(TargetSearchType_t searchType /*= TARGETSEARCH_DEFAUL } } else { int32_t minRange = std::numeric_limits::max(); - for (Creature* creature : targetList) { + for (std::shared_ptr creature : targetList) { if (!isTarget(creature)) { continue; } @@ -594,7 +594,7 @@ bool Monster::searchTarget(TargetSearchType_t searchType /*= TARGETSEARCH_DEFAUL } // lets just pick the first target in the list - for (Creature* target : targetList) { + for (std::shared_ptr target : targetList) { if (selectTarget(target)) { return true; } @@ -602,11 +602,11 @@ bool Monster::searchTarget(TargetSearchType_t searchType /*= TARGETSEARCH_DEFAUL return false; } -void Monster::onFollowCreatureComplete(const Creature* creature) { +void Monster::onFollowCreatureComplete(std::shared_ptr creature) { if (creature) { auto it = std::find(targetList.begin(), targetList.end(), creature); if (it != targetList.end()) { - Creature* target = (*it); + std::shared_ptr target = (*it); targetList.erase(it); if (hasFollowPath) { @@ -620,7 +620,7 @@ void Monster::onFollowCreatureComplete(const Creature* creature) { } } -BlockType_t Monster::blockHit(Creature* attacker, CombatType_t combatType, int32_t &damage, bool checkDefense /* = false*/, bool checkArmor /* = false*/, bool /* field = false */) { +BlockType_t Monster::blockHit(std::shared_ptr attacker, CombatType_t combatType, int32_t &damage, bool checkDefense /* = false*/, bool checkArmor /* = false*/, bool /* field = false */) { BlockType_t blockType = Creature::blockHit(attacker, combatType, damage, checkDefense, checkArmor); if (damage != 0) { @@ -631,7 +631,7 @@ BlockType_t Monster::blockHit(Creature* attacker, CombatType_t combatType, int32 } // Wheel of destiny - Player* player = attacker ? attacker->getPlayer() : nullptr; + std::shared_ptr player = attacker ? attacker->getPlayer() : nullptr; if (player && player->wheel()->getInstant("Ballistic Mastery")) { elementMod -= player->wheel()->checkElementSensitiveReduction(combatType); } @@ -648,7 +648,7 @@ BlockType_t Monster::blockHit(Creature* attacker, CombatType_t combatType, int32 return blockType; } -bool Monster::isTarget(const Creature* creature) const { +bool Monster::isTarget(std::shared_ptr creature) { if (creature->isRemoved() || !creature->isAttackable() || creature->getZoneType() == ZONE_PROTECTION || !canSeeCreature(creature)) { return false; } @@ -663,7 +663,7 @@ bool Monster::isTarget(const Creature* creature) const { return true; } -bool Monster::selectTarget(Creature* creature) { +bool Monster::selectTarget(std::shared_ptr creature) { if (!isTarget(creature)) { return false; } @@ -690,12 +690,12 @@ void Monster::setIdle(bool idle) { isIdle = idle; if (!isIdle) { - g_game().addCreatureCheck(this); + g_game().addCreatureCheck(static_self_cast()); } else { onIdleStatus(); clearTargetList(); clearFriendList(); - Game::removeCreatureCheck(this); + Game::removeCreatureCheck(static_self_cast()); } } @@ -747,7 +747,7 @@ void Monster::onThink(uint32_t interval) { lua_State* L = scriptInterface->getLuaState(); scriptInterface->pushFunction(mType->info.thinkEvent); - LuaScriptInterface::pushUserdata(L, this); + LuaScriptInterface::pushUserdata(L, getMonster()); LuaScriptInterface::setMetatable(L, -1, "Monster"); lua_pushnumber(L, interval); @@ -762,16 +762,16 @@ void Monster::onThink(uint32_t interval) { if (challengeMeleeDuration <= 0) { challengeMeleeDuration = 0; targetDistance = mType->info.targetDistance; - g_game().updateCreatureIcon(this); + g_game().updateCreatureIcon(static_self_cast()); } } if (!mType->canSpawn(position)) { - g_game().removeCreature(this); + g_game().removeCreature(static_self_cast()); } if (!isInSpawnRange(position)) { - g_game().internalTeleport(this, masterPos); + g_game().internalTeleport(static_self_cast(), masterPos); setIdle(true); } else { updateIdleStatus(); @@ -788,7 +788,7 @@ void Monster::onThink(uint32_t interval) { // Our master has not ordered us to attack anything, lets follow him around instead. setFollowCreature(getMaster()); } - } else if (attackedCreature == this) { + } else if (attackedCreature.get() == this) { setFollowCreature(nullptr); } else if (followCreature != attackedCreature) { // This happens just after a master orders an attack, so lets follow it aswell. @@ -813,7 +813,7 @@ void Monster::onThink(uint32_t interval) { } void Monster::doAttacking(uint32_t interval) { - if (!attackedCreature || (isSummon() && attackedCreature == this)) { + if (!attackedCreature || (isSummon() && attackedCreature.get() == this)) { return; } @@ -867,7 +867,7 @@ void Monster::doAttacking(uint32_t interval) { continue; } - spellBlock.spell->castSpell(this, attackedCreature); + spellBlock.spell->castSpell(static_self_cast(), attackedCreature); if (spellBlock.isMelee) { extraMeleeAttack = false; @@ -890,7 +890,7 @@ void Monster::doAttacking(uint32_t interval) { } } -bool Monster::canUseAttack(const Position &pos, const Creature* target) const { +bool Monster::canUseAttack(const Position &pos, std::shared_ptr target) const { if (isHostile()) { const Position &targetPos = target->getPosition(); uint32_t distance = std::max(Position::getDistanceX(pos, targetPos), Position::getDistanceY(pos, targetPos)); @@ -1003,7 +1003,7 @@ void Monster::onThinkDefense(uint32_t interval) { if ((spellBlock.chance >= static_cast(uniform_random(1, 100)))) { minCombatValue = spellBlock.minCombatValue; maxCombatValue = spellBlock.maxCombatValue; - spellBlock.spell->castSpell(this, this); + spellBlock.spell->castSpell(getMonster(), getMonster()); } } @@ -1024,7 +1024,7 @@ void Monster::onThinkDefense(uint32_t interval) { } uint32_t summonCount = 0; - for (Creature* summon : summons) { + for (std::shared_ptr summon : summons) { if (summon->getName() == summonBlock.name) { ++summonCount; } @@ -1038,15 +1038,14 @@ void Monster::onThinkDefense(uint32_t interval) { continue; } - Monster* summon = Monster::createMonster(summonBlock.name); + std::shared_ptr summon = Monster::createMonster(summonBlock.name); if (summon) { if (g_game().placeCreature(summon, getPosition(), false, summonBlock.force)) { - summon->setMaster(this, true); + summon->setMaster(static_self_cast(), true); g_game().addMagicEffect(getPosition(), CONST_ME_MAGIC_BLUE); g_game().addMagicEffect(summon->getPosition(), CONST_ME_TELEPORT); - g_game().sendSingleSoundEffect(summon->getPosition(), SoundEffect_t::MONSTER_SPELL_SUMMON, this); + g_game().sendSingleSoundEffect(summon->getPosition(), SoundEffect_t::MONSTER_SPELL_SUMMON, getMonster()); } else { - delete summon; } } } @@ -1071,9 +1070,9 @@ void Monster::onThinkYell(uint32_t interval) { const voiceBlock_t &vb = mType->info.voiceVector[index]; if (vb.yellText) { - g_game().internalCreatureSay(this, TALKTYPE_MONSTER_YELL, vb.text, false); + g_game().internalCreatureSay(static_self_cast(), TALKTYPE_MONSTER_YELL, vb.text, false); } else { - g_game().internalCreatureSay(this, TALKTYPE_MONSTER_SAY, vb.text, false); + g_game().internalCreatureSay(static_self_cast(), TALKTYPE_MONSTER_SAY, vb.text, false); } } } @@ -1090,16 +1089,16 @@ void Monster::onThinkSound(uint32_t interval) { if (!mType->info.soundVector.empty() && (mType->info.soundChance >= static_cast(uniform_random(1, 100)))) { int64_t index = uniform_random(0, static_cast(mType->info.soundVector.size() - 1)); - g_game().sendSingleSoundEffect(this->getPosition(), mType->info.soundVector[index], this); + g_game().sendSingleSoundEffect(static_self_cast()->getPosition(), mType->info.soundVector[index], getMonster()); } } } -bool Monster::pushItem(Item* item, const Direction &nextDirection) { +bool Monster::pushItem(std::shared_ptr item, const Direction &nextDirection) { const Position ¢erPos = item->getPosition(); for (const auto &[x, y] : getPushItemLocationOptions(nextDirection)) { Position tryPos(centerPos.x + x, centerPos.y + y, centerPos.z); - Tile* tile = g_game().map.getTile(tryPos); + std::shared_ptr tile = g_game().map.getTile(tryPos); if (tile && g_game().canThrowObjectTo(centerPos, tryPos) && g_game().internalMoveItem(item->getParent(), tile, INDEX_WHEREEVER, item, item->getItemCount(), nullptr) == RETURNVALUE_NOERROR) { return true; } @@ -1107,7 +1106,7 @@ bool Monster::pushItem(Item* item, const Direction &nextDirection) { return false; } -void Monster::pushItems(Tile* tile, const Direction &nextDirection) { +void Monster::pushItems(std::shared_ptr tile, const Direction &nextDirection) { // We can not use iterators here since we can push the item to another tile // which will invalidate the iterator. // start from the end to minimize the amount of traffic @@ -1119,7 +1118,7 @@ void Monster::pushItems(Tile* tile, const Direction &nextDirection) { uint32_t removeCount = 0; auto it = items->begin(); while (it != items->end()) { - Item* item = *it; + std::shared_ptr item = *it; if (item && item->hasProperty(CONST_PROP_MOVEABLE) && (item->hasProperty(CONST_PROP_BLOCKPATH) || item->hasProperty(CONST_PROP_BLOCKSOLID)) && item->getAttribute(ItemAttribute_t::ACTIONID) != IMMOVABLE_ACTION_ID) { if (moveCount < 20 && pushItem(item, nextDirection)) { ++moveCount; @@ -1135,7 +1134,7 @@ void Monster::pushItems(Tile* tile, const Direction &nextDirection) { } } -bool Monster::pushCreature(Creature* creature) { +bool Monster::pushCreature(std::shared_ptr creature) { static std::vector dirList { DIRECTION_NORTH, DIRECTION_WEST, DIRECTION_EAST, @@ -1145,7 +1144,7 @@ bool Monster::pushCreature(Creature* creature) { for (Direction dir : dirList) { const Position &tryPos = Spells::getCasterPosition(creature, dir); - const Tile* toTile = g_game().map.getTile(tryPos); + const auto toTile = g_game().map.getTile(tryPos); if (toTile && !toTile->hasFlag(TILESTATE_BLOCKPATH) && g_game().internalMoveCreature(creature, dir) == RETURNVALUE_NOERROR) { return true; } @@ -1153,15 +1152,15 @@ bool Monster::pushCreature(Creature* creature) { return false; } -void Monster::pushCreatures(Tile* tile) { +void Monster::pushCreatures(std::shared_ptr tile) { // We can not use iterators here since we can push a creature to another tile // which will invalidate the iterator. if (CreatureVector* creatures = tile->getCreatures()) { uint32_t removeCount = 0; - Monster* lastPushedMonster = nullptr; + std::shared_ptr lastPushedMonster = nullptr; for (size_t i = 0; i < creatures->size();) { - Monster* monster = creatures->at(i)->getMonster(); + std::shared_ptr monster = creatures->at(i)->getMonster(); if (monster && monster->isPushable()) { if (monster != lastPushedMonster && Monster::pushCreature(monster)) { lastPushedMonster = monster; @@ -1199,7 +1198,7 @@ bool Monster::getNextStep(Direction &nextDirection, uint32_t &flags) { if (result && (canPushItems() || canPushCreatures())) { const Position &pos = getNextPosition(nextDirection, getPosition()); - Tile* posTile = g_game().map.getTile(pos); + auto posTile = g_game().map.getTile(pos); if (posTile) { if (canPushItems()) { Monster::pushItems(posTile, nextDirection); @@ -1242,7 +1241,7 @@ void Monster::doFollowCreature(uint32_t &flags, Direction &nextDirection, bool & } } -bool Monster::getRandomStep(const Position &creaturePos, Direction &moveDirection) const { +bool Monster::getRandomStep(const Position &creaturePos, Direction &moveDirection) { static std::vector dirList { DIRECTION_NORTH, DIRECTION_WEST, DIRECTION_EAST, @@ -1840,28 +1839,28 @@ bool Monster::getDistanceStep(const Position &targetPos, Direction &moveDirectio return true; } -bool Monster::canWalkTo(Position pos, Direction moveDirection) const { +bool Monster::canWalkTo(Position pos, Direction moveDirection) { pos = getNextPosition(moveDirection, pos); if (isInSpawnRange(pos)) { if (getWalkCache(pos) == 0) { return false; } - const Tile* tile = g_game().map.getTile(pos); - if (tile && tile->getTopVisibleCreature(this) == nullptr && tile->queryAdd(0, *this, 1, FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) == RETURNVALUE_NOERROR) { + const auto tile = g_game().map.getTile(pos); + if (tile && tile->getTopVisibleCreature(getMonster()) == nullptr && tile->queryAdd(0, getMonster(), 1, FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) == RETURNVALUE_NOERROR) { return true; } } return false; } -void Monster::death(Creature*) { +void Monster::death(std::shared_ptr) { if (monsterForgeClassification > ForgeClassifications_t::FORGE_NORMAL_MONSTER) { g_game().removeForgeMonster(getID(), monsterForgeClassification, true); } setAttackedCreature(nullptr); - for (Creature* summon : summons) { + for (std::shared_ptr summon : summons) { summon->changeHealth(-summon->getHealth()); summon->removeMaster(); } @@ -1872,18 +1871,18 @@ void Monster::death(Creature*) { onIdleStatus(); if (mType) { - g_game().sendSingleSoundEffect(this->getPosition(), mType->info.deathSound, this); + g_game().sendSingleSoundEffect(static_self_cast()->getPosition(), mType->info.deathSound, getMonster()); } } -Item* Monster::getCorpse(Creature* lastHitCreature, Creature* mostDamageCreature) { - Item* corpse = Creature::getCorpse(lastHitCreature, mostDamageCreature); +std::shared_ptr Monster::getCorpse(std::shared_ptr lastHitCreature, std::shared_ptr mostDamageCreature) { + std::shared_ptr corpse = Creature::getCorpse(lastHitCreature, mostDamageCreature); if (corpse) { if (mostDamageCreature) { if (mostDamageCreature->getPlayer()) { corpse->setAttribute(ItemAttribute_t::CORPSEOWNER, mostDamageCreature->getID()); } else { - const Creature* mostDamageCreatureMaster = mostDamageCreature->getMaster(); + std::shared_ptr mostDamageCreatureMaster = mostDamageCreature->getMaster(); if (mostDamageCreatureMaster && mostDamageCreatureMaster->getPlayer()) { corpse->setAttribute(ItemAttribute_t::CORPSEOWNER, mostDamageCreatureMaster->getID()); } @@ -1988,10 +1987,10 @@ void Monster::updateLookDirection() { } } } - g_game().internalCreatureTurn(this, newDir); + g_game().internalCreatureTurn(static_self_cast(), newDir); } -void Monster::dropLoot(Container* corpse, Creature*) { +void Monster::dropLoot(std::shared_ptr corpse, std::shared_ptr) { if (corpse && lootDrop) { // Only fiendish drops sliver if (ForgeClassifications_t classification = getMonsterForgeClassification(); @@ -2002,14 +2001,14 @@ void Monster::dropLoot(Container* corpse, Creature*) { auto sliverCount = static_cast(uniform_random(minSlivers, maxSlivers)); - Item* sliver = Item::CreateItem(ITEM_FORGE_SLIVER, sliverCount); + std::shared_ptr sliver = Item::CreateItem(ITEM_FORGE_SLIVER, sliverCount); if (g_game().internalAddItem(corpse, sliver) != RETURNVALUE_NOERROR) { corpse->internalAddThing(sliver); } } if (!this->isRewardBoss() && g_configManager().getNumber(RATE_LOOT) > 0) { - g_callbacks().executeCallback(EventCallback_t::monsterOnDropLoot, &EventCallback::monsterOnDropLoot, this, corpse); - g_callbacks().executeCallback(EventCallback_t::monsterPostDropLoot, &EventCallback::monsterPostDropLoot, this, corpse); + g_callbacks().executeCallback(EventCallback_t::monsterOnDropLoot, &EventCallback::monsterOnDropLoot, getMonster(), corpse); + g_callbacks().executeCallback(EventCallback_t::monsterPostDropLoot, &EventCallback::monsterPostDropLoot, getMonster(), corpse); } } } @@ -2018,7 +2017,7 @@ void Monster::setNormalCreatureLight() { internalLight = mType->info.light; } -void Monster::drainHealth(Creature* attacker, int32_t damage) { +void Monster::drainHealth(std::shared_ptr attacker, int32_t damage) { Creature::drainHealth(attacker, damage); if (damage > 0 && randomStepping) { @@ -2034,7 +2033,7 @@ void Monster::drainHealth(Creature* attacker, int32_t damage) { void Monster::changeHealth(int32_t healthChange, bool sendHealthChange /* = true*/) { if (mType && !mType->info.soundVector.empty() && mType->info.soundChance >= static_cast(uniform_random(1, 100))) { auto index = uniform_random(0, mType->info.soundVector.size() - 1); - g_game().sendSingleSoundEffect(this->getPosition(), mType->info.soundVector[index], this); + g_game().sendSingleSoundEffect(static_self_cast()->getPosition(), mType->info.soundVector[index], getMonster()); } // In case a player with ignore flag set attacks the monster @@ -2042,7 +2041,7 @@ void Monster::changeHealth(int32_t healthChange, bool sendHealthChange /* = true Creature::changeHealth(healthChange, sendHealthChange); } -bool Monster::challengeCreature(Creature* creature, int targetChangeCooldown) { +bool Monster::challengeCreature(std::shared_ptr creature, int targetChangeCooldown) { if (isSummon()) { return false; } @@ -2052,7 +2051,7 @@ bool Monster::challengeCreature(Creature* creature, int targetChangeCooldown) { challengeFocusDuration = targetChangeCooldown; targetChangeTicks = 0; // Wheel of destiny - Player* player = creature ? creature->getPlayer() : nullptr; + std::shared_ptr player = creature ? creature->getPlayer() : nullptr; if (player && !player->isRemoved()) { player->wheel()->healIfBattleHealingActive(); } @@ -2074,7 +2073,7 @@ bool Monster::changeTargetDistance(int32_t distance, uint32_t duration /* = 1200 targetDistance = distance; if (shouldUpdate) { - g_game().updateCreatureIcon(this); + g_game().updateCreatureIcon(static_self_cast()); } return true; } @@ -2087,7 +2086,7 @@ bool Monster::isImmune(CombatType_t combatType) const { return mType->info.m_damageImmunities[combatTypeToIndex(combatType)]; } -void Monster::getPathSearchParams(const Creature* creature, FindPathParams &fpp) const { +void Monster::getPathSearchParams(std::shared_ptr creature, FindPathParams &fpp) { Creature::getPathSearchParams(creature, fpp); fpp.minTargetDist = 1; @@ -2123,12 +2122,12 @@ void Monster::configureForgeSystem() { if (monsterForgeClassification == ForgeClassifications_t::FORGE_FIENDISH_MONSTER) { setForgeStack(15); setIcon("forge", CreatureIcon(CreatureIconModifications_t::Fiendish, 0 /* don't show stacks on fiends */)); - g_game().updateCreatureIcon(this); + g_game().updateCreatureIcon(static_self_cast()); } else if (monsterForgeClassification == ForgeClassifications_t::FORGE_INFLUENCED_MONSTER) { auto stack = static_cast(normal_random(1, 5)); setForgeStack(stack); setIcon("forge", CreatureIcon(CreatureIconModifications_t::Influenced, stack)); - g_game().updateCreatureIcon(this); + g_game().updateCreatureIcon(static_self_cast()); } // Change health based in stacks @@ -2142,7 +2141,7 @@ void Monster::configureForgeSystem() { const std::string &Eventname = "ForgeSystemMonster"; registerCreatureEvent(Eventname); - g_game().sendUpdateCreature(this); + g_game().sendUpdateCreature(static_self_cast()); } void Monster::clearFiendishStatus() { @@ -2154,8 +2153,8 @@ void Monster::clearFiendishStatus() { healthMax = mType->info.healthMax * mType->getHealthMultiplier(); removeIcon("forge"); - g_game().updateCreatureIcon(this); - g_game().sendUpdateCreature(this); + g_game().updateCreatureIcon(static_self_cast()); + g_game().sendUpdateCreature(static_self_cast()); } bool Monster::canDropLoot() const { diff --git a/src/creatures/monsters/monster.hpp b/src/creatures/monsters/monster.hpp index a479b494a9a..a71a981077b 100644 --- a/src/creatures/monsters/monster.hpp +++ b/src/creatures/monsters/monster.hpp @@ -17,12 +17,12 @@ class Creature; class Game; class Spawn; -using CreatureHashSet = phmap::flat_hash_set; -using CreatureList = std::list; +using CreatureHashSet = phmap::flat_hash_set>; +using CreatureList = std::list>; class Monster final : public Creature { public: - static Monster* createMonster(const std::string &name); + static std::shared_ptr createMonster(const std::string &name); static int32_t despawnRange; static int32_t despawnRadius; @@ -33,11 +33,8 @@ class Monster final : public Creature { Monster(const Monster &) = delete; Monster &operator=(const Monster &) = delete; - Monster* getMonster() override { - return this; - } - const Monster* getMonster() const override { - return this; + std::shared_ptr getMonster() override { + return static_self_cast(); } void setID() override { @@ -59,7 +56,7 @@ class Monster final : public Creature { const std::string &getNameDescription() const override { return mType->nameDescription; } - std::string getDescription(int32_t) const override { + std::string getDescription(int32_t) override { return strDescription + '.'; } @@ -101,7 +98,7 @@ class Monster final : public Creature { return mType->info.enemyFactions.empty() ? false : mType->info.enemyFactions.find(faction) != mType->info.enemyFactions.end(); } - bool isPushable() const override { + bool isPushable() override { return mType->info.pushable && baseSpeed != 0; } bool isAttackable() const override { @@ -141,19 +138,19 @@ class Monster final : public Creature { bool canWalkOnFieldType(CombatType_t combatType) const; void onAttackedCreatureDisappear(bool isLogout) override; - void onCreatureAppear(Creature* creature, bool isLogin) override; - void onRemoveCreature(Creature* creature, bool isLogout) override; - void onCreatureMove(Creature* creature, const Tile* newTile, const Position &newPos, const Tile* oldTile, const Position &oldPos, bool teleport) override; - void onCreatureSay(Creature* creature, SpeakClasses type, const std::string &text) override; + void onCreatureAppear(std::shared_ptr creature, bool isLogin) override; + void onRemoveCreature(std::shared_ptr creature, bool isLogout) override; + void onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport) override; + void onCreatureSay(std::shared_ptr creature, SpeakClasses type, const std::string &text) override; - void drainHealth(Creature* attacker, int32_t damage) override; + void drainHealth(std::shared_ptr attacker, int32_t damage) override; void changeHealth(int32_t healthChange, bool sendHealthChange = true) override; bool getNextStep(Direction &direction, uint32_t &flags) override; - void onFollowCreatureComplete(const Creature* creature) override; + void onFollowCreatureComplete(std::shared_ptr creature) override; void onThink(uint32_t interval) override; - bool challengeCreature(Creature* creature, int targetChangeCooldown) override; + bool challengeCreature(std::shared_ptr creature, int targetChangeCooldown) override; bool changeTargetDistance(int32_t distance, uint32_t duration = 12000); bool isChallenged() const { @@ -184,7 +181,7 @@ class Monster final : public Creature { } bool searchTarget(TargetSearchType_t searchType = TARGETSEARCH_DEFAULT); - bool selectTarget(Creature* creature); + bool selectTarget(std::shared_ptr creature); const CreatureList &getTargetList() const { return targetList; @@ -193,7 +190,7 @@ class Monster final : public Creature { return friendList; } - bool isTarget(const Creature* creature) const; + bool isTarget(std::shared_ptr creature); bool isFleeing() const { return !isSummon() && getHealth() <= runAwayHealth && challengeFocusDuration <= 0 && challengeMeleeDuration <= 0; } @@ -252,7 +249,7 @@ class Monster final : public Creature { void clearTargetList(); void clearFriendList(); - BlockType_t blockHit(Creature* attacker, CombatType_t combatType, int32_t &damage, bool checkDefense = false, bool checkArmor = false, bool field = false) override; + BlockType_t blockHit(std::shared_ptr attacker, CombatType_t combatType, int32_t &damage, bool checkDefense = false, bool checkArmor = false, bool field = false) override; static uint32_t monsterAutoID; @@ -350,19 +347,19 @@ class Monster final : public Creature { bool hazardDodge = false; bool hazardDamageBoost = false; - void onCreatureEnter(Creature* creature); - void onCreatureLeave(Creature* creature); - void onCreatureFound(Creature* creature, bool pushFront = false); + void onCreatureEnter(std::shared_ptr creature); + void onCreatureLeave(std::shared_ptr creature); + void onCreatureFound(std::shared_ptr creature, bool pushFront = false); void updateLookDirection(); - void addFriend(Creature* creature); - void removeFriend(Creature* creature); - void addTarget(Creature* creature, bool pushFront = false); - void removeTarget(Creature* creature); + void addFriend(std::shared_ptr creature); + void removeFriend(std::shared_ptr creature); + void addTarget(std::shared_ptr creature, bool pushFront = false); + void removeTarget(std::shared_ptr creature); - void death(Creature* lastHitCreature) override; - Item* getCorpse(Creature* lastHitCreature, Creature* mostDamageCreature) override; + void death(std::shared_ptr lastHitCreature) override; + std::shared_ptr getCorpse(std::shared_ptr lastHitCreature, std::shared_ptr mostDamageCreature) override; void setIdle(bool idle); void updateIdleStatus(); @@ -373,25 +370,25 @@ class Monster final : public Creature { void onAddCondition(ConditionType_t type) override; void onEndCondition(ConditionType_t type) override; - bool canUseAttack(const Position &pos, const Creature* target) const; + bool canUseAttack(const Position &pos, std::shared_ptr target) const; bool canUseSpell(const Position &pos, const Position &targetPos, const spellBlock_t &sb, uint32_t interval, bool &inRange, bool &resetTicks); - bool getRandomStep(const Position &creaturePos, Direction &direction) const; + bool getRandomStep(const Position &creaturePos, Direction &direction); bool getDanceStep(const Position &creaturePos, Direction &direction, bool keepAttack = true, bool keepDistance = true); bool isInSpawnRange(const Position &pos) const; - bool canWalkTo(Position pos, Direction direction) const; + bool canWalkTo(Position pos, Direction direction); - static bool pushItem(Item* item, const Direction &nextDirection); - static void pushItems(Tile* tile, const Direction &nextDirection); - static bool pushCreature(Creature* creature); - static void pushCreatures(Tile* tile); + static bool pushItem(std::shared_ptr item, const Direction &nextDirection); + static void pushItems(std::shared_ptr tile, const Direction &nextDirection); + static bool pushCreature(std::shared_ptr creature); + static void pushCreatures(std::shared_ptr tile); void onThinkTarget(uint32_t interval); void onThinkYell(uint32_t interval); void onThinkDefense(uint32_t interval); void onThinkSound(uint32_t interval); - bool isFriend(const Creature* creature) const; - bool isOpponent(const Creature* creature) const; + bool isFriend(std::shared_ptr creature) const; + bool isOpponent(std::shared_ptr creature) const; uint64_t getLostExperience() const override { return skillLoss ? mType->info.experience : 0; @@ -399,8 +396,8 @@ class Monster final : public Creature { uint16_t getLookCorpse() const override { return mType->info.lookcorpse; } - void dropLoot(Container* corpse, Creature* lastHitCreature) override; - void getPathSearchParams(const Creature* creature, FindPathParams &fpp) const override; + void dropLoot(std::shared_ptr corpse, std::shared_ptr lastHitCreature) override; + void getPathSearchParams(std::shared_ptr creature, FindPathParams &fpp) override; bool useCacheMap() const override { return !randomStepping; } diff --git a/src/creatures/monsters/spawns/spawn_monster.cpp b/src/creatures/monsters/spawns/spawn_monster.cpp index 5f02435cf5a..4e39623723d 100644 --- a/src/creatures/monsters/spawns/spawn_monster.cpp +++ b/src/creatures/monsters/spawns/spawn_monster.cpp @@ -149,7 +149,7 @@ void SpawnMonster::startSpawnMonsterCheck() { SpawnMonster::~SpawnMonster() { for (const auto &it : spawnedMonsterMap) { - Monster* monster = it.second; + std::shared_ptr monster = it.second; monster->setSpawnMonster(nullptr); monster->decrementReferenceCounter(); } @@ -158,7 +158,7 @@ SpawnMonster::~SpawnMonster() { bool SpawnMonster::findPlayer(const Position &pos) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, pos, false, true); - for (Creature* spectator : spectators) { + for (std::shared_ptr spectator : spectators) { if (!spectator->getPlayer()->hasFlag(PlayerFlags_t::IgnoredByMonsters)) { return true; } @@ -171,19 +171,18 @@ bool SpawnMonster::isInSpawnMonsterZone(const Position &pos) { } bool SpawnMonster::spawnMonster(uint32_t spawnMonsterId, const std::shared_ptr monsterType, const Position &pos, Direction dir, bool startup /*= false*/) { - std::unique_ptr monster_ptr(new Monster(monsterType)); + auto monster = std::make_shared(monsterType); if (startup) { // No need to send out events to the surrounding since there is no one out there to listen! - if (!g_game().internalPlaceCreature(monster_ptr.get(), pos, true)) { + if (!g_game().internalPlaceCreature(monster, pos, true)) { return false; } } else { - if (!g_game().placeCreature(monster_ptr.get(), pos, false, true)) { + if (!g_game().placeCreature(monster, pos, false, true)) { return false; } } - Monster* monster = monster_ptr.release(); monster->setDirection(dir); monster->setSpawnMonster(this); monster->setMasterPos(pos); @@ -259,7 +258,7 @@ void SpawnMonster::cleanup() { auto it = spawnedMonsterMap.begin(); while (it != spawnedMonsterMap.end()) { uint32_t spawnMonsterId = it->first; - Monster* monster = it->second; + std::shared_ptr monster = it->second; if (monster->isRemoved()) { spawnMonsterMap[spawnMonsterId].lastSpawn = OTSYS_TIME(); monster->decrementReferenceCounter(); @@ -291,7 +290,7 @@ bool SpawnMonster::addMonster(const std::string &name, const Position &pos, Dire return true; } -void SpawnMonster::removeMonster(Monster* monster) { +void SpawnMonster::removeMonster(std::shared_ptr monster) { for (auto it = spawnedMonsterMap.begin(), end = spawnedMonsterMap.end(); it != end; ++it) { if (it->second == monster) { monster->decrementReferenceCounter(); diff --git a/src/creatures/monsters/spawns/spawn_monster.hpp b/src/creatures/monsters/spawns/spawn_monster.hpp index 17ad00a9a5b..3c361f95634 100644 --- a/src/creatures/monsters/spawns/spawn_monster.hpp +++ b/src/creatures/monsters/spawns/spawn_monster.hpp @@ -34,7 +34,7 @@ class SpawnMonster { SpawnMonster &operator=(const SpawnMonster &) = delete; bool addMonster(const std::string &name, const Position &pos, Direction dir, uint32_t interval); - void removeMonster(Monster* monster); + void removeMonster(std::shared_ptr monster); uint32_t getInterval() const { return interval; @@ -49,7 +49,7 @@ class SpawnMonster { private: // map of the spawned creatures - using SpawnedMap = std::multimap; + using SpawnedMap = std::multimap>; using spawned_pair = SpawnedMap::value_type; SpawnedMap spawnedMonsterMap; diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index 9d95a2e916c..f15b0578ec4 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -22,12 +22,12 @@ int32_t Npc::despawnRadius; uint32_t Npc::npcAutoID = 0x80000000; -Npc* Npc::createNpc(const std::string &name) { +std::shared_ptr Npc::createNpc(const std::string &name) { NpcType* npcType = g_npcs().getNpcType(name); if (!npcType) { return nullptr; } - return new Npc(npcType); + return std::make_shared(npcType); } Npc::Npc(NpcType* npcType) : @@ -55,21 +55,21 @@ Npc::~Npc() { } void Npc::addList() { - g_game().addNpc(this); + g_game().addNpc(static_self_cast()); } void Npc::removeList() { - g_game().removeNpc(this); + g_game().removeNpc(static_self_cast()); } -bool Npc::canInteract(const Position &pos, uint32_t range /* = 4 */) const { +bool Npc::canInteract(const Position &pos, uint32_t range /* = 4 */) { if (pos.z != getPosition().z) { return false; } return Creature::canSee(getPosition(), pos, range, range); } -void Npc::onCreatureAppear(Creature* creature, bool isLogin) { +void Npc::onCreatureAppear(std::shared_ptr creature, bool isLogin) { Creature::onCreatureAppear(creature, isLogin); if (auto player = creature->getPlayer()) { @@ -77,9 +77,9 @@ void Npc::onCreatureAppear(Creature* creature, bool isLogin) { } // onCreatureAppear(self, creature) - CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, this); + CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, getNpc()); if (callback.startScriptInterface(npcType->info.creatureAppearEvent)) { - callback.pushSpecificCreature(this); + callback.pushSpecificCreature(static_self_cast()); callback.pushCreature(creature); } @@ -88,13 +88,13 @@ void Npc::onCreatureAppear(Creature* creature, bool isLogin) { } } -void Npc::onRemoveCreature(Creature* creature, bool isLogout) { +void Npc::onRemoveCreature(std::shared_ptr creature, bool isLogout) { Creature::onRemoveCreature(creature, isLogout); // onCreatureDisappear(self, creature) - CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, this); + CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, getNpc()); if (callback.startScriptInterface(npcType->info.creatureDisappearEvent)) { - callback.pushSpecificCreature(this); + callback.pushSpecificCreature(static_self_cast()); callback.pushCreature(creature); } @@ -113,13 +113,13 @@ void Npc::onRemoveCreature(Creature* creature, bool isLogout) { shopPlayerSet.clear(); } -void Npc::onCreatureMove(Creature* creature, const Tile* newTile, const Position &newPos, const Tile* oldTile, const Position &oldPos, bool teleport) { +void Npc::onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport) { Creature::onCreatureMove(creature, newTile, newPos, oldTile, oldPos, teleport); // onCreatureMove(self, creature, oldPosition, newPosition) - CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, this); + CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, getNpc()); if (callback.startScriptInterface(npcType->info.creatureMoveEvent)) { - callback.pushSpecificCreature(this); + callback.pushSpecificCreature(static_self_cast()); callback.pushCreature(creature); callback.pushPosition(oldPos); callback.pushPosition(newPos); @@ -129,7 +129,7 @@ void Npc::onCreatureMove(Creature* creature, const Tile* newTile, const Position return; } - if (creature == this && !canInteract(oldPos)) { + if (creature == getNpc() && !canInteract(oldPos)) { resetPlayerInteractions(); closeAllShopWindows(); } @@ -141,13 +141,13 @@ void Npc::onCreatureMove(Creature* creature, const Tile* newTile, const Position void Npc::manageIdle() { if (creatureCheck && playerSpectators.empty()) { - Game::removeCreatureCheck(this); + Game::removeCreatureCheck(static_self_cast()); } else if (!creatureCheck) { - g_game().addCreatureCheck(this); + g_game().addCreatureCheck(static_self_cast()); } } -void Npc::onPlayerAppear(Player* player) { +void Npc::onPlayerAppear(std::shared_ptr player) { if (player->hasFlag(PlayerFlags_t::IgnoredByNpcs) || playerSpectators.contains(player)) { return; } @@ -155,7 +155,7 @@ void Npc::onPlayerAppear(Player* player) { manageIdle(); } -void Npc::onPlayerDisappear(Player* player) { +void Npc::onPlayerDisappear(std::shared_ptr player) { removePlayerInteraction(player); if (!player->hasFlag(PlayerFlags_t::IgnoredByNpcs) && playerSpectators.contains(player)) { playerSpectators.erase(player); @@ -163,7 +163,7 @@ void Npc::onPlayerDisappear(Player* player) { } } -void Npc::onCreatureSay(Creature* creature, SpeakClasses type, const std::string &text) { +void Npc::onCreatureSay(std::shared_ptr creature, SpeakClasses type, const std::string &text) { Creature::onCreatureSay(creature, type, text); if (!creature->getPlayer()) { @@ -171,9 +171,9 @@ void Npc::onCreatureSay(Creature* creature, SpeakClasses type, const std::string } // onCreatureSay(self, creature, type, message) - CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, this); + CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, getNpc()); if (callback.startScriptInterface(npcType->info.creatureSayEvent)) { - callback.pushSpecificCreature(this); + callback.pushSpecificCreature(static_self_cast()); callback.pushCreature(creature); callback.pushNumber(type); callback.pushString(text); @@ -195,7 +195,7 @@ void Npc::onThinkSound(uint32_t interval) { if (!npcType->info.soundVector.empty() && (npcType->info.soundChance >= static_cast(uniform_random(1, 100)))) { auto index = uniform_random(0, npcType->info.soundVector.size() - 1); - g_game().sendSingleSoundEffect(this->getPosition(), npcType->info.soundVector[index], this); + g_game().sendSingleSoundEffect(static_self_cast()->getPosition(), npcType->info.soundVector[index], getNpc()); } } } @@ -204,9 +204,9 @@ void Npc::onThink(uint32_t interval) { Creature::onThink(interval); // onThink(self, interval) - CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, this); + CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, getNpc()); if (callback.startScriptInterface(npcType->info.thinkEvent)) { - callback.pushSpecificCreature(this); + callback.pushSpecificCreature(static_self_cast()); callback.pushNumber(interval); } @@ -215,11 +215,11 @@ void Npc::onThink(uint32_t interval) { } if (!npcType->canSpawn(position)) { - g_game().removeCreature(this); + g_game().removeCreature(static_self_cast()); } if (!isInSpawnRange(position)) { - g_game().internalTeleport(this, masterPos); + g_game().internalTeleport(static_self_cast(), masterPos); resetPlayerInteractions(); closeAllShopWindows(); } @@ -231,7 +231,7 @@ void Npc::onThink(uint32_t interval) { } } -void Npc::onPlayerBuyItem(Player* player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore, bool inBackpacks) { +void Npc::onPlayerBuyItem(std::shared_ptr player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore, bool inBackpacks) { if (player == nullptr) { g_logger().error("[Npc::onPlayerBuyItem] - Player is nullptr"); return; @@ -246,7 +246,7 @@ void Npc::onPlayerBuyItem(Player* player, uint16_t itemId, uint8_t subType, uint uint32_t shoppingBagPrice = 20; uint32_t shoppingBagSlots = 20; const ItemType &itemType = Item::items[itemId]; - if (const Tile* tile = ignore ? player->getTile() : nullptr; tile) { + if (std::shared_ptr tile = ignore ? player->getTile() : nullptr; tile) { double slotsNedeed = 0; if (itemType.stackable) { slotsNedeed = inBackpacks ? std::ceil(std::ceil(static_cast(amount) / 100) / shoppingBagSlots) : std::ceil(static_cast(amount) / 100); @@ -287,9 +287,9 @@ void Npc::onPlayerBuyItem(Player* player, uint16_t itemId, uint8_t subType, uint } // npc:onBuyItem(player, itemId, subType, amount, ignore, inBackpacks, totalCost) - CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, this); + CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, getNpc()); if (callback.startScriptInterface(npcType->info.playerBuyEvent)) { - callback.pushSpecificCreature(this); + callback.pushSpecificCreature(static_self_cast()); callback.pushCreature(player); callback.pushNumber(itemId); callback.pushNumber(subType); @@ -304,13 +304,13 @@ void Npc::onPlayerBuyItem(Player* player, uint16_t itemId, uint8_t subType, uint } } -void Npc::onPlayerSellItem(Player* player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore) { +void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore) { uint64_t totalPrice = 0; onPlayerSellItem(player, itemId, subType, amount, ignore, totalPrice); } void Npc::onPlayerSellAllLoot(uint32_t playerId, uint16_t itemId, bool ignore, uint64_t totalPrice) { - Player* player = g_game().getPlayerByID(playerId); + std::shared_ptr player = g_game().getPlayerByID(playerId); if (!player) { return; } @@ -359,7 +359,7 @@ void Npc::onPlayerSellAllLoot(uint32_t playerId, uint16_t itemId, bool ignore, u } } -void Npc::onPlayerSellItem(Player* player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore, uint64_t &totalPrice, Cylinder* parent /*= nullptr*/) { +void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore, uint64_t &totalPrice, std::shared_ptr parent /*= nullptr*/) { if (!player) { return; } @@ -417,16 +417,16 @@ void Npc::onPlayerSellItem(Player* player, uint16_t itemId, uint8_t subType, uin g_game().addMoney(player, totalCost); } } else { - Item* newItem = Item::CreateItem(getCurrency(), totalCost); + std::shared_ptr newItem = Item::CreateItem(getCurrency(), totalCost); if (newItem) { g_game().internalPlayerAddItem(player, newItem, true); } } // npc:onSellItem(player, itemId, subType, amount, ignore, itemName, totalCost) - CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, this); + CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, getNpc()); if (callback.startScriptInterface(npcType->info.playerSellEvent)) { - callback.pushSpecificCreature(this); + callback.pushSpecificCreature(static_self_cast()); callback.pushCreature(player); callback.pushNumber(itemType.id); callback.pushNumber(subType); @@ -441,16 +441,16 @@ void Npc::onPlayerSellItem(Player* player, uint16_t itemId, uint8_t subType, uin } } -void Npc::onPlayerCheckItem(Player* player, uint16_t itemId, uint8_t subType) { +void Npc::onPlayerCheckItem(std::shared_ptr player, uint16_t itemId, uint8_t subType) { if (!player) { return; } const ItemType &itemType = Item::items[itemId]; // onPlayerCheckItem(self, player, itemId, subType) - CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, this); + CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, getNpc()); if (callback.startScriptInterface(npcType->info.playerLookEvent)) { - callback.pushSpecificCreature(this); + callback.pushSpecificCreature(static_self_cast()); callback.pushCreature(player); callback.pushNumber(itemId); callback.pushNumber(subType); @@ -461,16 +461,16 @@ void Npc::onPlayerCheckItem(Player* player, uint16_t itemId, uint8_t subType) { } } -void Npc::onPlayerCloseChannel(Creature* creature) { - Player* player = creature->getPlayer(); +void Npc::onPlayerCloseChannel(std::shared_ptr creature) { + std::shared_ptr player = creature->getPlayer(); if (!player) { return; } // onPlayerCloseChannel(npc, player) - CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, this); + CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, getNpc()); if (callback.startScriptInterface(npcType->info.playerCloseChannel)) { - callback.pushSpecificCreature(this); + callback.pushSpecificCreature(static_self_cast()); callback.pushCreature(player); } @@ -495,9 +495,9 @@ void Npc::onThinkYell(uint32_t interval) { const voiceBlock_t &vb = npcType->info.voiceVector[index]; if (vb.yellText) { - g_game().internalCreatureSay(this, TALKTYPE_YELL, vb.text, false); + g_game().internalCreatureSay(static_self_cast(), TALKTYPE_YELL, vb.text, false); } else { - g_game().internalCreatureSay(this, TALKTYPE_SAY, vb.text, false); + g_game().internalCreatureSay(static_self_cast(), TALKTYPE_SAY, vb.text, false); } } } @@ -573,7 +573,7 @@ bool Npc::isInSpawnRange(const Position &pos) const { } void Npc::setPlayerInteraction(uint32_t playerId, uint16_t topicId /*= 0*/) { - Creature* creature = g_game().getCreatureByID(playerId); + std::shared_ptr creature = g_game().getCreatureByID(playerId); if (!creature) { return; } @@ -583,7 +583,7 @@ void Npc::setPlayerInteraction(uint32_t playerId, uint16_t topicId /*= 0*/) { playerInteractions[playerId] = topicId; } -void Npc::removePlayerInteraction(Player* player) { +void Npc::removePlayerInteraction(std::shared_ptr player) { if (playerInteractions.contains(player->getID())) { playerInteractions.erase(player->getID()); player->closeShopWindow(true); @@ -594,7 +594,7 @@ void Npc::resetPlayerInteractions() { playerInteractions.clear(); } -bool Npc::canWalkTo(const Position &fromPos, Direction dir) const { +bool Npc::canWalkTo(const Position &fromPos, Direction dir) { if (npcType->info.walkRadius == 0) { return false; } @@ -604,8 +604,8 @@ bool Npc::canWalkTo(const Position &fromPos, Direction dir) const { return false; } - const Tile* toTile = g_game().map.getTile(toPos); - if (!toTile || toTile->queryAdd(0, *this, 1, 0) != RETURNVALUE_NOERROR) { + std::shared_ptr toTile = g_game().map.getTile(toPos); + if (!toTile || toTile->queryAdd(0, getNpc(), 1, 0) != RETURNVALUE_NOERROR) { return false; } @@ -624,7 +624,7 @@ bool Npc::getNextStep(Direction &nextDirection, uint32_t &flags) { return Creature::getNextStep(nextDirection, flags); } -bool Npc::getRandomStep(Direction &moveDirection) const { +bool Npc::getRandomStep(Direction &moveDirection) { static std::vector directionvector { Direction::DIRECTION_NORTH, Direction::DIRECTION_WEST, @@ -643,11 +643,11 @@ bool Npc::getRandomStep(Direction &moveDirection) const { return false; } -void Npc::addShopPlayer(Player* player) { +void Npc::addShopPlayer(std::shared_ptr player) { shopPlayerSet.insert(player); } -void Npc::removeShopPlayer(Player* player) { +void Npc::removeShopPlayer(std::shared_ptr player) { if (player) { shopPlayerSet.erase(player); } @@ -662,7 +662,7 @@ void Npc::closeAllShopWindows() { shopPlayerSet.clear(); } -void Npc::handlePlayerMove(Player* player, const Position &newPos) { +void Npc::handlePlayerMove(std::shared_ptr player, const Position &newPos) { if (!canInteract(newPos)) { removePlayerInteraction(player); } diff --git a/src/creatures/npcs/npc.hpp b/src/creatures/npcs/npc.hpp index e0c8c728685..6ad97ea20a2 100644 --- a/src/creatures/npcs/npc.hpp +++ b/src/creatures/npcs/npc.hpp @@ -20,7 +20,7 @@ class SpawnNpc; class Npc final : public Creature { public: - static Npc* createNpc(const std::string &name); + static std::shared_ptr createNpc(const std::string &name); static int32_t despawnRange; static int32_t despawnRadius; @@ -30,17 +30,14 @@ class Npc final : public Creature { // Singleton - ensures we don't accidentally copy it Npc(const Npc &) = delete; - void operator=(const Npc &) = delete; + void operator=(const std::shared_ptr &) = delete; static Npc &getInstance() { return inject(); } - Npc* getNpc() override { - return this; - } - const Npc* getNpc() const override { - return this; + std::shared_ptr getNpc() override { + return static_self_cast(); } void setID() override { @@ -62,7 +59,7 @@ class Npc final : public Creature { const std::string &getNameDescription() const override { return npcType->nameDescription; } - std::string getDescription(int32_t) const override { + std::string getDescription(int32_t) override { return strDescription + '.'; } @@ -99,7 +96,7 @@ class Npc final : public Creature { return npcType->info.shopItemVector; } - bool isPushable() const override { + bool isPushable() override { return npcType->info.pushable; } @@ -107,7 +104,7 @@ class Npc final : public Creature { return false; } - bool canInteract(const Position &pos, uint32_t range = 4) const; + bool canInteract(const Position &pos, uint32_t range = 4) ; bool canSeeInvisibility() const override { return true; } @@ -119,7 +116,7 @@ class Npc final : public Creature { } void setPlayerInteraction(uint32_t playerId, uint16_t topicId = 0); - void removePlayerInteraction(Player* player); + void removePlayerInteraction(std::shared_ptr player); void resetPlayerInteractions(); bool isInteractingWithPlayer(uint32_t playerId) { @@ -137,29 +134,29 @@ class Npc final : public Creature { return it->second == topicId; } - void onCreatureAppear(Creature* creature, bool isLogin) override; - void onRemoveCreature(Creature* creature, bool isLogout) override; - void onCreatureMove(Creature* creature, const Tile* newTile, const Position &newPos, const Tile* oldTile, const Position &oldPos, bool teleport) override; - void onCreatureSay(Creature* creature, SpeakClasses type, const std::string &text) override; + void onCreatureAppear(std::shared_ptr creature, bool isLogin) override; + void onRemoveCreature(std::shared_ptr creature, bool isLogout) override; + void onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport) override; + void onCreatureSay(std::shared_ptr creature, SpeakClasses type, const std::string &text) override; void onThink(uint32_t interval) override; - void onPlayerBuyItem(Player* player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore, bool inBackpacks); + void onPlayerBuyItem(std::shared_ptr player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore, bool inBackpacks); void onPlayerSellAllLoot(uint32_t playerId, uint16_t itemid, bool ignore, uint64_t totalPrice); - void onPlayerSellItem(Player* player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore); - void onPlayerSellItem(Player* player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore, uint64_t &totalPrice, Cylinder* parent = nullptr); - void onPlayerCheckItem(Player* player, uint16_t itemid, uint8_t count); - void onPlayerCloseChannel(Creature* creature); + void onPlayerSellItem(std::shared_ptr player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore); + void onPlayerSellItem(std::shared_ptr player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore, uint64_t &totalPrice, std::shared_ptr parent = nullptr); + void onPlayerCheckItem(std::shared_ptr player, uint16_t itemid, uint8_t count); + void onPlayerCloseChannel(std::shared_ptr creature); void onPlacedCreature() override; - bool canWalkTo(const Position &fromPos, Direction dir) const; + bool canWalkTo(const Position &fromPos, Direction dir); bool getNextStep(Direction &nextDirection, uint32_t &flags) override; - bool getRandomStep(Direction &moveDirection) const; + bool getRandomStep(Direction &moveDirection); void setNormalCreatureLight() override { internalLight = npcType->info.light; } - void addShopPlayer(Player* player); - void removeShopPlayer(Player* player); + void addShopPlayer(std::shared_ptr player); + void removeShopPlayer(std::shared_ptr player); void closeAllShopWindows(); static uint32_t npcAutoID; @@ -177,7 +174,7 @@ class Npc final : public Creature { std::map playerInteractions; - std::set shopPlayerSet; + std::set> shopPlayerSet; NpcType* npcType; SpawnNpc* spawnNpc = nullptr; @@ -196,10 +193,10 @@ class Npc final : public Creature { friend class LuaScriptInterface; friend class Map; - void onPlayerAppear(Player* player); - void onPlayerDisappear(Player* player); + void onPlayerAppear(std::shared_ptr player); + void onPlayerDisappear(std::shared_ptr player); void manageIdle(); - void handlePlayerMove(Player* player, const Position &newPos); + void handlePlayerMove(std::shared_ptr player, const Position &newPos); void loadPlayerSpectators(); }; diff --git a/src/creatures/npcs/spawns/spawn_npc.cpp b/src/creatures/npcs/spawns/spawn_npc.cpp index 20ae9ba9127..db98fe59bbd 100644 --- a/src/creatures/npcs/spawns/spawn_npc.cpp +++ b/src/creatures/npcs/spawns/spawn_npc.cpp @@ -137,7 +137,7 @@ void SpawnNpc::startSpawnNpcCheck() { SpawnNpc::~SpawnNpc() { for (const auto &it : spawnedNpcMap) { - Npc* npc = it.second; + auto npc = it.second; npc->setSpawnNpc(nullptr); npc->decrementReferenceCounter(); } @@ -146,7 +146,7 @@ SpawnNpc::~SpawnNpc() { bool SpawnNpc::findPlayer(const Position &pos) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, pos, false, true); - for (Creature* spectator : spectators) { + for (std::shared_ptr spectator : spectators) { if (!spectator->getPlayer()->hasFlag(PlayerFlags_t::IgnoredByNpcs)) { return true; } @@ -159,19 +159,18 @@ bool SpawnNpc::isInSpawnNpcZone(const Position &pos) { } bool SpawnNpc::spawnNpc(uint32_t spawnId, NpcType* npcType, const Position &pos, Direction dir, bool startup /*= false*/) { - std::unique_ptr npc_ptr(new Npc(npcType)); + auto npc = std::make_shared(npcType); if (startup) { // No need to send out events to the surrounding since there is no one out there to listen! - if (!g_game().internalPlaceCreature(npc_ptr.get(), pos, true, false)) { + if (!g_game().internalPlaceCreature(npc, pos, true, false)) { return false; } } else { - if (!g_game().placeCreature(npc_ptr.get(), pos, false, true)) { + if (!g_game().placeCreature(npc, pos, false, true)) { return false; } } - Npc* npc = npc_ptr.release(); npc->setDirection(dir); npc->setSpawnNpc(this); npc->setMasterPos(pos); @@ -238,7 +237,7 @@ void SpawnNpc::cleanup() { auto it = spawnedNpcMap.begin(); while (it != spawnedNpcMap.end()) { uint32_t spawnId = it->first; - Npc* npc = it->second; + auto npc = it->second; if (npc->isRemoved()) { spawnNpcMap[spawnId].lastSpawnNpc = OTSYS_TIME(); npc->decrementReferenceCounter(); @@ -270,7 +269,7 @@ bool SpawnNpc::addNpc(const std::string &name, const Position &pos, Direction di return true; } -void SpawnNpc::removeNpc(Npc* npc) { +void SpawnNpc::removeNpc(std::shared_ptr npc) { for (auto it = spawnedNpcMap.begin(), end = spawnedNpcMap.end(); it != end; ++it) { if (it->second == npc) { npc->decrementReferenceCounter(); diff --git a/src/creatures/npcs/spawns/spawn_npc.hpp b/src/creatures/npcs/spawns/spawn_npc.hpp index 697cdf9289e..4926d2c8d09 100644 --- a/src/creatures/npcs/spawns/spawn_npc.hpp +++ b/src/creatures/npcs/spawns/spawn_npc.hpp @@ -34,7 +34,7 @@ class SpawnNpc { SpawnNpc &operator=(const SpawnNpc &) = delete; bool addNpc(const std::string &name, const Position &pos, Direction dir, uint32_t interval); - void removeNpc(Npc* npc); + void removeNpc(std::shared_ptr npc); uint32_t getInterval() const { return interval; @@ -49,7 +49,7 @@ class SpawnNpc { private: // map of the spawned npcs - using SpawnedNpcMap = std::multimap; + using SpawnedNpcMap = std::multimap>; using spawned_pair = SpawnedNpcMap::value_type; SpawnedNpcMap spawnedNpcMap; diff --git a/src/creatures/players/grouping/guild.cpp b/src/creatures/players/grouping/guild.cpp index 995f4936b7d..c7af6c2a613 100644 --- a/src/creatures/players/grouping/guild.cpp +++ b/src/creatures/players/grouping/guild.cpp @@ -12,16 +12,16 @@ #include "creatures/players/grouping/guild.hpp" #include "game/game.hpp" -void Guild::addMember(Player* player) { +void Guild::addMember(std::shared_ptr player) { membersOnline.push_back(player); - for (Player* member : membersOnline) { + for (std::shared_ptr member : membersOnline) { g_game().updatePlayerHelpers(member); } } -void Guild::removeMember(Player* player) { +void Guild::removeMember(std::shared_ptr player) { membersOnline.remove(player); - for (Player* member : membersOnline) { + for (std::shared_ptr member : membersOnline) { g_game().updatePlayerHelpers(member); } diff --git a/src/creatures/players/grouping/guild.hpp b/src/creatures/players/grouping/guild.hpp index 497d8363566..497ff49f52b 100644 --- a/src/creatures/players/grouping/guild.hpp +++ b/src/creatures/players/grouping/guild.hpp @@ -29,8 +29,8 @@ class Guild : public Bankable { Guild(uint32_t initId, std::string initName) : name(std::move(initName)), id(initId) { } - void addMember(Player* player); - void removeMember(Player* player); + void addMember(std::shared_ptr player); + void removeMember(std::shared_ptr player); bool isGuild() { return true; @@ -48,7 +48,7 @@ class Guild : public Bankable { const std::string &getName() const { return name; } - const std::list &getMembersOnline() const { + const std::list> &getMembersOnline() const { return membersOnline; } uint32_t getMemberCount() const { @@ -81,7 +81,7 @@ class Guild : public Bankable { } private: - std::list membersOnline; + std::list> membersOnline; std::vector ranks; std::string name; uint64_t bankBalance = 0; diff --git a/src/creatures/players/grouping/party.cpp b/src/creatures/players/grouping/party.cpp index 55dc1a67860..ad765f0545b 100644 --- a/src/creatures/players/grouping/party.cpp +++ b/src/creatures/players/grouping/party.cpp @@ -15,7 +15,7 @@ #include "lua/callbacks/event_callback.hpp" #include "lua/callbacks/events_callbacks.hpp" -Party::Party(Player* initLeader) : +Party::Party(std::shared_ptr initLeader) : leader(initLeader) { leader->setParty(this); if (g_configManager().getBoolean(PARTY_AUTO_SHARE_EXPERIENCE)) { @@ -32,7 +32,7 @@ void Party::disband() { return; } - Player* currentLeader = leader; + std::shared_ptr currentLeader = leader; leader = nullptr; currentLeader->setParty(nullptr); @@ -42,22 +42,22 @@ void Party::disband() { currentLeader->sendCreatureSkull(currentLeader); currentLeader->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, "Your party has been disbanded."); - for (Player* invitee : inviteList) { + for (std::shared_ptr invitee : inviteList) { invitee->removePartyInvitation(this); currentLeader->sendCreatureShield(invitee); } inviteList.clear(); - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { member->setParty(nullptr); member->sendClosePrivate(CHANNEL_PARTY); member->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, "Your party has been disbanded."); } - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { g_game().updatePlayerShield(member); - for (Player* otherMember : memberList) { + for (std::shared_ptr otherMember : memberList) { otherMember->sendCreatureSkull(member); } @@ -68,13 +68,11 @@ void Party::disband() { memberList.clear(); for (PartyAnalyzer* analyzer : membersData) { - delete analyzer; } membersData.clear(); - delete this; } -bool Party::leaveParty(Player* player) { +bool Party::leaveParty(std::shared_ptr player) { if (!player) { return false; } @@ -115,7 +113,7 @@ bool Party::leaveParty(Player* player) { g_game().updatePlayerShield(player); g_game().updatePlayerHelpers(player); - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { member->sendCreatureSkull(player); player->sendPlayerPartyIcons(member); member->sendPartyCreatureUpdate(player); @@ -144,7 +142,7 @@ bool Party::leaveParty(Player* player) { return true; } -bool Party::passPartyLeadership(Player* player) { +bool Party::passPartyLeadership(std::shared_ptr player) { if (!player || leader == player || player->getParty() != this) { return false; } @@ -159,7 +157,7 @@ bool Party::passPartyLeadership(Player* player) { ss << player->getName() << " is now the leader of the party."; broadcastPartyMessage(MESSAGE_PARTY_MANAGEMENT, ss.str(), true); - Player* oldLeader = leader; + std::shared_ptr oldLeader = leader; leader = player; memberList.insert(memberList.begin(), oldLeader); @@ -167,12 +165,12 @@ bool Party::passPartyLeadership(Player* player) { updateSharedExperience(); updateTrackerAnalyzer(); - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { member->sendPartyCreatureShield(oldLeader); member->sendPartyCreatureShield(leader); } - for (Player* invitee : inviteList) { + for (std::shared_ptr invitee : inviteList) { invitee->sendCreatureShield(oldLeader); invitee->sendCreatureShield(leader); } @@ -184,16 +182,16 @@ bool Party::passPartyLeadership(Player* player) { return true; } -bool Party::joinParty(Player &player) { - if (!g_events().eventPartyOnJoin(this, &player)) { +bool Party::joinParty(const std::shared_ptr &player) { + if (!g_events().eventPartyOnJoin(this, player)) { return false; } - if (!g_callbacks().checkCallback(EventCallback_t::partyOnJoin, &EventCallback::partyOnJoin, this, &player)) { + if (!g_callbacks().checkCallback(EventCallback_t::partyOnJoin, &EventCallback::partyOnJoin, this, player)) { return false; } - auto it = std::find(inviteList.begin(), inviteList.end(), &player); + auto it = std::find(inviteList.begin(), inviteList.end(), player); if (it == inviteList.end()) { return false; } @@ -201,58 +199,58 @@ bool Party::joinParty(Player &player) { inviteList.erase(it); std::ostringstream ss; - ss << player.getName() << " has joined the party."; + ss << player->getName() << " has joined the party."; broadcastPartyMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); - player.setParty(this); + player->setParty(this); - g_game().updatePlayerShield(&player); + g_game().updatePlayerShield(player); - for (Player* member : memberList) { - member->sendCreatureSkull(&player); - player.sendPlayerPartyIcons(member); + for (std::shared_ptr member : memberList) { + member->sendCreatureSkull(player); + player->sendPlayerPartyIcons(member); } - player.sendCreatureSkull(&player); - leader->sendCreatureSkull(&player); - player.sendPlayerPartyIcons(leader); + player->sendCreatureSkull(player); + leader->sendCreatureSkull(player); + player->sendPlayerPartyIcons(leader); - memberList.push_back(&player); + memberList.push_back(player); - g_game().updatePlayerHelpers(&player); + g_game().updatePlayerHelpers(player); - updatePlayerStatus(&player); + updatePlayerStatus(player); - player.removePartyInvitation(this); + player->removePartyInvitation(this); updateSharedExperience(); const std::string &leaderName = leader->getName(); ss.str(std::string()); ss << "You have joined " << leaderName << "'" << (leaderName.back() == 's' ? "" : "s") << " party. Open the party channel to communicate with your companions."; - player.sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); + player->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); updateTrackerAnalyzer(); return true; } -bool Party::removeInvite(Player &player, bool removeFromPlayer /* = true*/) { - auto it = std::find(inviteList.begin(), inviteList.end(), &player); +bool Party::removeInvite(const std::shared_ptr &player, bool removeFromPlayer /* = true*/) { + auto it = std::find(inviteList.begin(), inviteList.end(), player); if (it == inviteList.end()) { return false; } inviteList.erase(it); - leader->sendCreatureShield(&player); - player.sendCreatureShield(leader); + leader->sendCreatureShield(player); + player->sendCreatureShield(leader); if (removeFromPlayer) { - player.removePartyInvitation(this); + player->removePartyInvitation(this); } if (empty()) { disband(); } else { - for (Player* member : memberList) { + for (auto member : memberList) { g_game().updatePlayerHelpers(member); } @@ -262,25 +260,25 @@ bool Party::removeInvite(Player &player, bool removeFromPlayer /* = true*/) { return true; } -void Party::revokeInvitation(Player &player) { +void Party::revokeInvitation(const std::shared_ptr &player) { std::ostringstream ss; ss << leader->getName() << " has revoked " << leader->getPossessivePronoun() << " invitation."; - player.sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); + player->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); ss.str(std::string()); - ss << "Invitation for " << player.getName() << " has been revoked."; + ss << "Invitation for " << player->getName() << " has been revoked."; leader->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); removeInvite(player); } -bool Party::invitePlayer(Player &player) { - if (isPlayerInvited(&player)) { +bool Party::invitePlayer(const std::shared_ptr &player) { + if (isPlayerInvited(player)) { return false; } std::ostringstream ss; - ss << player.getName() << " has been invited to join the party (Share range: " << getMinLevel() << "-" << getMaxLevel() << ")."; + ss << player->getName() << " has been invited to join the party (Share range: " << getMinLevel() << "-" << getMaxLevel() << ")."; if (empty()) { ss << " Open the party channel to communicate with your members."; @@ -290,32 +288,32 @@ bool Party::invitePlayer(Player &player) { leader->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); - inviteList.push_back(&player); + inviteList.push_back(player); - for (Player* member : memberList) { + for (auto member : memberList) { g_game().updatePlayerHelpers(member); } g_game().updatePlayerHelpers(leader); - leader->sendCreatureShield(&player); - player.sendCreatureShield(leader); + leader->sendCreatureShield(player); + player->sendCreatureShield(leader); - player.addPartyInvitation(this); + player->addPartyInvitation(this); ss.str(std::string()); ss << leader->getName() << " has invited you to " << leader->getPossessivePronoun() << " party (Share range: " << getMinLevel() << "-" << getMaxLevel() << ")."; - player.sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); + player->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); return true; } -bool Party::isPlayerInvited(const Player* player) const { +bool Party::isPlayerInvited(std::shared_ptr player) const { return std::find(inviteList.begin(), inviteList.end(), player) != inviteList.end(); } void Party::updateAllPartyIcons() { - for (Player* member : memberList) { - for (Player* otherMember : memberList) { + for (std::shared_ptr member : memberList) { + for (std::shared_ptr otherMember : memberList) { member->sendPartyCreatureShield(otherMember); } @@ -327,14 +325,14 @@ void Party::updateAllPartyIcons() { } void Party::broadcastPartyMessage(MessageClasses msgClass, const std::string &msg, bool sendToInvitations /*= false*/) { - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { member->sendTextMessage(msgClass, msg); } leader->sendTextMessage(msgClass, msg); if (sendToInvitations) { - for (Player* invitee : inviteList) { + for (std::shared_ptr invitee : inviteList) { invitee->sendTextMessage(msgClass, msg); } } @@ -367,7 +365,7 @@ const char* Party::getSharedExpReturnMessage(SharedExpStatus_t value) { } } -bool Party::setSharedExperience(Player* player, bool newSharedExpActive, bool silent /*= false*/) { +bool Party::setSharedExperience(std::shared_ptr player, bool newSharedExpActive, bool silent /*= false*/) { if (!player || leader != player) { return false; } @@ -394,22 +392,22 @@ bool Party::setSharedExperience(Player* player, bool newSharedExpActive, bool si return true; } -void Party::shareExperience(uint64_t experience, Creature* target /* = nullptr*/) { +void Party::shareExperience(uint64_t experience, std::shared_ptr target /* = nullptr*/) { uint64_t shareExperience = experience; g_events().eventPartyOnShareExperience(this, shareExperience); g_callbacks().executeCallback(EventCallback_t::partyOnShareExperience, &EventCallback::partyOnShareExperience, this, shareExperience); - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { member->onGainSharedExperience(shareExperience, target); } leader->onGainSharedExperience(shareExperience, target); } -bool Party::canUseSharedExperience(const Player* player) const { +bool Party::canUseSharedExperience(std::shared_ptr player) const { return getMemberSharedExperienceStatus(player) == SHAREDEXP_OK; } -SharedExpStatus_t Party::getMemberSharedExperienceStatus(const Player* player) const { +SharedExpStatus_t Party::getMemberSharedExperienceStatus(std::shared_ptr player) const { if (memberList.empty()) { return SHAREDEXP_EMPTYPARTY; } @@ -434,7 +432,7 @@ SharedExpStatus_t Party::getMemberSharedExperienceStatus(const Player* player) c uint32_t Party::getHighestLevel() const { uint32_t highestLevel = leader->getLevel(); - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { if (member->getLevel() > highestLevel) { highestLevel = member->getLevel(); } @@ -448,7 +446,7 @@ uint32_t Party::getMinLevel() const { uint32_t Party::getLowestLevel() const { uint32_t lowestLevel = leader->getLevel(); - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { if (member->getLevel() < lowestLevel) { lowestLevel = member->getLevel(); } @@ -460,7 +458,7 @@ uint32_t Party::getMaxLevel() const { return static_cast(std::floor((static_cast(getLowestLevel()) * 3) / 2)); } -bool Party::isPlayerActive(const Player* player) const { +bool Party::isPlayerActive(std::shared_ptr player) const { auto it = ticksMap.find(player->getID()); if (it == ticksMap.end()) { return false; @@ -476,7 +474,7 @@ SharedExpStatus_t Party::getSharedExperienceStatus() { return leaderStatus; } - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { SharedExpStatus_t memberStatus = getMemberSharedExperienceStatus(member); if (memberStatus != SHAREDEXP_OK) { return memberStatus; @@ -485,14 +483,14 @@ SharedExpStatus_t Party::getSharedExperienceStatus() { return SHAREDEXP_OK; } -void Party::updatePlayerTicks(Player* player, uint32_t points) { +void Party::updatePlayerTicks(std::shared_ptr player, uint32_t points) { if (points != 0 && !player->hasFlag(PlayerFlags_t::NotGainInFight)) { ticksMap[player->getID()] = OTSYS_TIME(); updateSharedExperience(); } } -void Party::clearPlayerPoints(Player* player) { +void Party::clearPlayerPoints(std::shared_ptr player) { auto it = ticksMap.find(player->getID()); if (it != ticksMap.end()) { ticksMap.erase(it); @@ -501,21 +499,21 @@ void Party::clearPlayerPoints(Player* player) { } bool Party::canOpenCorpse(uint32_t ownerId) const { - if (const Player* player = g_game().getPlayerByID(ownerId)) { + if (std::shared_ptr player = g_game().getPlayerByID(ownerId)) { return leader->getID() == ownerId || player->getParty() == this; } return false; } -void Party::showPlayerStatus(Player* player, Player* member, bool showStatus) { +void Party::showPlayerStatus(std::shared_ptr player, std::shared_ptr member, bool showStatus) { player->sendPartyCreatureShowStatus(member, showStatus); member->sendPartyCreatureShowStatus(player, showStatus); if (showStatus) { - for (Creature* summon : member->getSummons()) { + for (std::shared_ptr summon : member->getSummons()) { player->sendPartyCreatureShowStatus(summon, showStatus); player->sendPartyCreatureHealth(summon, std::ceil((static_cast(summon->getHealth()) / std::max(summon->getMaxHealth(), 1)) * 100)); } - for (Creature* summon : player->getSummons()) { + for (std::shared_ptr summon : player->getSummons()) { member->sendPartyCreatureShowStatus(summon, showStatus); member->sendPartyCreatureHealth(summon, std::ceil((static_cast(summon->getHealth()) / std::max(summon->getMaxHealth(), 1)) * 100)); } @@ -524,18 +522,18 @@ void Party::showPlayerStatus(Player* player, Player* member, bool showStatus) { player->sendPartyPlayerMana(member, std::ceil((static_cast(member->getMana()) / std::max(member->getMaxMana(), 1)) * 100)); member->sendPartyPlayerMana(player, std::ceil((static_cast(player->getMana()) / std::max(player->getMaxMana(), 1)) * 100)); } else { - for (Creature* summon : player->getSummons()) { + for (std::shared_ptr summon : player->getSummons()) { member->sendPartyCreatureShowStatus(summon, showStatus); } - for (Creature* summon : member->getSummons()) { + for (std::shared_ptr summon : member->getSummons()) { player->sendPartyCreatureShowStatus(summon, showStatus); } } } -void Party::updatePlayerStatus(Player* player) { +void Party::updatePlayerStatus(std::shared_ptr player) { int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE); - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { bool condition = (maxDistance == 0 || (Position::getDistanceX(player->getPosition(), member->getPosition()) <= maxDistance && Position::getDistanceY(player->getPosition(), member->getPosition()) <= maxDistance)); if (condition) { showPlayerStatus(player, member, true); @@ -551,10 +549,10 @@ void Party::updatePlayerStatus(Player* player) { } } -void Party::updatePlayerStatus(Player* player, const Position &oldPos, const Position &newPos) { +void Party::updatePlayerStatus(std::shared_ptr player, const Position &oldPos, const Position &newPos) { int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE); if (maxDistance != 0) { - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { bool condition1 = (Position::getDistanceX(oldPos, member->getPosition()) <= maxDistance && Position::getDistanceY(oldPos, member->getPosition()) <= maxDistance); bool condition2 = (Position::getDistanceX(newPos, member->getPosition()) <= maxDistance && Position::getDistanceY(newPos, member->getPosition()) <= maxDistance); if (condition1 && !condition2) { @@ -574,9 +572,9 @@ void Party::updatePlayerStatus(Player* player, const Position &oldPos, const Pos } } -void Party::updatePlayerHealth(const Player* player, const Creature* target, uint8_t healthPercent) { +void Party::updatePlayerHealth(std::shared_ptr player, std::shared_ptr target, uint8_t healthPercent) { int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE); - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { bool condition = (maxDistance == 0 || (Position::getDistanceX(player->getPosition(), member->getPosition()) <= maxDistance && Position::getDistanceY(player->getPosition(), member->getPosition()) <= maxDistance)); if (condition) { member->sendPartyCreatureHealth(target, healthPercent); @@ -588,9 +586,9 @@ void Party::updatePlayerHealth(const Player* player, const Creature* target, uin } } -void Party::updatePlayerMana(const Player* player, uint8_t manaPercent) { +void Party::updatePlayerMana(std::shared_ptr player, uint8_t manaPercent) { int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE); - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { bool condition = (maxDistance == 0 || (Position::getDistanceX(player->getPosition(), member->getPosition()) <= maxDistance && Position::getDistanceY(player->getPosition(), member->getPosition()) <= maxDistance)); if (condition) { member->sendPartyPlayerMana(player, manaPercent); @@ -602,9 +600,9 @@ void Party::updatePlayerMana(const Player* player, uint8_t manaPercent) { } } -void Party::updatePlayerVocation(const Player* player) { +void Party::updatePlayerVocation(std::shared_ptr player) { int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE); - for (Player* member : memberList) { + for (std::shared_ptr member : memberList) { bool condition = (maxDistance == 0 || (Position::getDistanceX(player->getPosition(), member->getPosition()) <= maxDistance && Position::getDistanceY(player->getPosition(), member->getPosition()) <= maxDistance)); if (condition) { member->sendPartyPlayerVocation(player); @@ -617,7 +615,7 @@ void Party::updatePlayerVocation(const Player* player) { } void Party::updateTrackerAnalyzer() const { - for (const Player* member : memberList) { + for (std::shared_ptr member : memberList) { member->updatePartyTrackerAnalyzer(); } @@ -626,7 +624,7 @@ void Party::updateTrackerAnalyzer() const { } } -void Party::addPlayerLoot(const Player* player, const Item* item) { +void Party::addPlayerLoot(std::shared_ptr player, std::shared_ptr item) { PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); @@ -649,7 +647,7 @@ void Party::addPlayerLoot(const Player* player, const Item* item) { updateTrackerAnalyzer(); } -void Party::addPlayerSupply(const Player* player, const Item* item) { +void Party::addPlayerSupply(std::shared_ptr player, std::shared_ptr item) { PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); @@ -671,7 +669,7 @@ void Party::addPlayerSupply(const Player* player, const Item* item) { updateTrackerAnalyzer(); } -void Party::addPlayerDamage(const Player* player, uint64_t amount) { +void Party::addPlayerDamage(std::shared_ptr player, uint64_t amount) { PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); @@ -682,7 +680,7 @@ void Party::addPlayerDamage(const Player* player, uint64_t amount) { updateTrackerAnalyzer(); } -void Party::addPlayerHealing(const Player* player, uint64_t amount) { +void Party::addPlayerHealing(std::shared_ptr player, uint64_t amount) { PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); @@ -706,7 +704,6 @@ void Party::switchAnalyzerPriceType() { void Party::resetAnalyzer() { trackerTime = time(nullptr); for (PartyAnalyzer* analyzer : membersData) { - delete analyzer; } membersData.clear(); diff --git a/src/creatures/players/grouping/party.hpp b/src/creatures/players/grouping/party.hpp index c89a6eb65b9..aaebabb4d9c 100644 --- a/src/creatures/players/grouping/party.hpp +++ b/src/creatures/players/grouping/party.hpp @@ -24,13 +24,13 @@ enum SharedExpStatus_t : uint8_t { class Player; class Party; -using PlayerVector = std::vector; +using PlayerVector = std::vector>; class Party { public: - explicit Party(Player* leader); + explicit Party(std::shared_ptr leader); - Player* getLeader() const { + std::shared_ptr getLeader() const { return leader; } PlayerVector &getMembers() { @@ -47,15 +47,15 @@ class Party { } void disband(); - bool invitePlayer(Player &player); - bool joinParty(Player &player); - void revokeInvitation(Player &player); - bool passPartyLeadership(Player* player); - bool leaveParty(Player* player); + bool invitePlayer(const std::shared_ptr &player); + bool joinParty(const std::shared_ptr &player); + void revokeInvitation(const std::shared_ptr &player); + bool passPartyLeadership(std::shared_ptr player); + bool leaveParty(std::shared_ptr player); - bool removeInvite(Player &player, bool removeFromPlayer = true); + bool removeInvite(const std::shared_ptr &player, bool removeFromPlayer = true); - bool isPlayerInvited(const Player* player) const; + bool isPlayerInvited(std::shared_ptr player) const; void updateAllPartyIcons(); void broadcastPartyMessage(MessageClasses msgClass, const std::string &msg, bool sendToInvitations = false); bool empty() const { @@ -63,33 +63,33 @@ class Party { } bool canOpenCorpse(uint32_t ownerId) const; - void shareExperience(uint64_t experience, Creature* target = nullptr); - bool setSharedExperience(Player* player, bool sharedExpActive, bool silent = false); + void shareExperience(uint64_t experience, std::shared_ptr target = nullptr); + bool setSharedExperience(std::shared_ptr player, bool sharedExpActive, bool silent = false); bool isSharedExperienceActive() const { return sharedExpActive; } bool isSharedExperienceEnabled() const { return sharedExpEnabled; } - bool canUseSharedExperience(const Player* player) const; - SharedExpStatus_t getMemberSharedExperienceStatus(const Player* player) const; + bool canUseSharedExperience(std::shared_ptr player) const; + SharedExpStatus_t getMemberSharedExperienceStatus(std::shared_ptr player) const; void updateSharedExperience(); - void updatePlayerTicks(Player* player, uint32_t points); - void clearPlayerPoints(Player* player); + void updatePlayerTicks(std::shared_ptr player, uint32_t points); + void clearPlayerPoints(std::shared_ptr player); - void showPlayerStatus(Player* player, Player* member, bool showStatus); - void updatePlayerStatus(Player* player); - void updatePlayerStatus(Player* player, const Position &oldPos, const Position &newPos); - void updatePlayerHealth(const Player* player, const Creature* target, uint8_t healthPercent); - void updatePlayerMana(const Player* player, uint8_t manaPercent); - void updatePlayerVocation(const Player* player); + void showPlayerStatus(std::shared_ptr player, std::shared_ptr member, bool showStatus); + void updatePlayerStatus(std::shared_ptr player); + void updatePlayerStatus(std::shared_ptr player, const Position &oldPos, const Position &newPos); + void updatePlayerHealth(std::shared_ptr player, std::shared_ptr target, uint8_t healthPercent); + void updatePlayerMana(std::shared_ptr player, uint8_t manaPercent); + void updatePlayerVocation(std::shared_ptr player); void updateTrackerAnalyzer() const; - void addPlayerLoot(const Player* player, const Item* item); - void addPlayerSupply(const Player* player, const Item* item); - void addPlayerDamage(const Player* player, uint64_t amount); - void addPlayerHealing(const Player* player, uint64_t amount); + void addPlayerLoot(std::shared_ptr player, std::shared_ptr item); + void addPlayerSupply(std::shared_ptr player, std::shared_ptr item); + void addPlayerDamage(std::shared_ptr player, uint64_t amount); + void addPlayerHealing(std::shared_ptr player, uint64_t amount); void switchAnalyzerPriceType(); void resetAnalyzer(); void reloadPrices(); @@ -117,7 +117,7 @@ class Party { private: const char* getSharedExpReturnMessage(SharedExpStatus_t value); - bool isPlayerActive(const Player* player) const; + bool isPlayerActive(std::shared_ptr player) const; SharedExpStatus_t getSharedExperienceStatus(); uint32_t getHighestLevel() const; uint32_t getLowestLevel() const; @@ -129,7 +129,7 @@ class Party { PlayerVector memberList; PlayerVector inviteList; - Player* leader; + std::shared_ptr leader; bool sharedExpActive = false; bool sharedExpEnabled = false; diff --git a/src/creatures/players/imbuements/imbuements.cpp b/src/creatures/players/imbuements/imbuements.cpp index 664e2bd09e6..2d27d15bb3a 100644 --- a/src/creatures/players/imbuements/imbuements.cpp +++ b/src/creatures/players/imbuements/imbuements.cpp @@ -336,7 +336,7 @@ CategoryImbuement* Imbuements::getCategoryByID(uint16_t id) { return categoryImbuements != categoriesImbuement.end() ? &*categoryImbuements : nullptr; } -std::vector Imbuements::getImbuements(const Player* player, Item* item) { +std::vector Imbuements::getImbuements(std::shared_ptr player, std::shared_ptr item) { std::vector imbuements; for (auto &[key, value] : imbuementMap) { diff --git a/src/creatures/players/imbuements/imbuements.hpp b/src/creatures/players/imbuements/imbuements.hpp index 828dfd67b70..69c5219a0d8 100644 --- a/src/creatures/players/imbuements/imbuements.hpp +++ b/src/creatures/players/imbuements/imbuements.hpp @@ -60,7 +60,7 @@ class Imbuements { BaseImbuement* getBaseByID(uint16_t id); CategoryImbuement* getCategoryByID(uint16_t id); - std::vector getImbuements(const Player* player, Item* item); + std::vector getImbuements(std::shared_ptr player, std::shared_ptr item); protected: friend class Imbuement; diff --git a/src/creatures/players/management/waitlist.cpp b/src/creatures/players/management/waitlist.cpp index f5179daf0ae..ff1ad2b00bd 100644 --- a/src/creatures/players/management/waitlist.cpp +++ b/src/creatures/players/management/waitlist.cpp @@ -59,7 +59,7 @@ std::size_t WaitingList::getTime(std::size_t slot) { } } -bool WaitingList::clientLogin(const Player* player) { +bool WaitingList::clientLogin(std::shared_ptr player) { if (player->hasFlag(PlayerFlags_t::CanAlwaysLogin) || player->getAccountType() >= account::ACCOUNT_TYPE_GAMEMASTER) { return true; } @@ -85,7 +85,7 @@ bool WaitingList::clientLogin(const Player* player) { return false; } -void WaitingList::addPlayerToList(const Player* player) { +void WaitingList::addPlayerToList(std::shared_ptr player) { auto it = info->playerReferences.find(player->getGUID()); if (it != info->playerReferences.end()) { std::size_t slot; @@ -111,7 +111,7 @@ void WaitingList::addPlayerToList(const Player* player) { } } -std::size_t WaitingList::getClientSlot(const Player* player) { +std::size_t WaitingList::getClientSlot(std::shared_ptr player) { auto it = info->playerReferences.find(player->getGUID()); if (it == info->playerReferences.end()) { return 0; diff --git a/src/creatures/players/management/waitlist.hpp b/src/creatures/players/management/waitlist.hpp index 2203a1ebb85..28b65c7cad0 100644 --- a/src/creatures/players/management/waitlist.hpp +++ b/src/creatures/players/management/waitlist.hpp @@ -34,13 +34,13 @@ class WaitingList { public: WaitingList(); static WaitingList &getInstance(); - bool clientLogin(const Player* player); - std::size_t getClientSlot(const Player* player); + bool clientLogin(std::shared_ptr player); + std::size_t getClientSlot(std::shared_ptr player); static std::size_t getTime(std::size_t slot); private: void cleanupList(WaitList &list); std::size_t getTimeout(std::size_t slot); - void addPlayerToList(const Player* player); + void addPlayerToList(std::shared_ptr player); std::unique_ptr info; }; diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 9d9a5e9c54d..1d89d59d137 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -37,14 +37,14 @@ Player::Player(ProtocolGame_ptr p) : Creature(), lastPing(OTSYS_TIME()), lastPong(lastPing), - inbox(new Inbox(ITEM_INBOX)), + inbox(std::make_shared(ITEM_INBOX)), client(std::move(p)) { inbox->incrementReferenceCounter(); m_wheelPlayer = std::make_unique(*this); } Player::~Player() { - for (Item* item : inventory) { + for (std::shared_ptr item : inventory) { if (item) { item->setParent(nullptr); item->stopDecaying(); @@ -68,13 +68,11 @@ Player::~Player() { for (PreySlot* slot : preys) { if (slot) { - delete slot; } } for (TaskHuntingSlot* slot : taskHunting) { if (slot) { - delete slot; } } @@ -94,11 +92,11 @@ bool Player::setVocation(uint16_t vocId) { vocation = voc; updateRegeneration(); - g_game().addPlayerVocation(this); + g_game().addPlayerVocation(static_self_cast()); return true; } -bool Player::isPushable() const { +bool Player::isPushable() { if (hasFlag(PlayerFlags_t::CannotBePushed)) { return false; } @@ -128,7 +126,7 @@ void Player::setID() { } } -std::string Player::getDescription(int32_t lookDistance) const { +std::string Player::getDescription(int32_t lookDistance) { std::ostringstream s; std::string subjectPronoun = getSubjectPronoun(); capitalizeWords(subjectPronoun); @@ -230,7 +228,7 @@ std::string Player::getDescription(int32_t lookDistance) const { return s.str(); } -Item* Player::getInventoryItem(Slots_t slot) const { +std::shared_ptr Player::getInventoryItem(Slots_t slot) const { if (slot < CONST_SLOT_FIRST || slot > CONST_SLOT_LAST) { return nullptr; } @@ -251,8 +249,8 @@ void Player::removeConditionSuppressions() { m_conditionSuppressions.reset(); } -Item* Player::getWeapon(Slots_t slot, bool ignoreAmmo) const { - Item* item = inventory[slot]; +std::shared_ptr Player::getWeapon(Slots_t slot, bool ignoreAmmo) const { + std::shared_ptr item = inventory[slot]; if (!item) { return nullptr; } @@ -273,23 +271,23 @@ Item* Player::getWeapon(Slots_t slot, bool ignoreAmmo) const { } bool Player::hasQuiverEquipped() const { - Item* quiver = inventory[CONST_SLOT_RIGHT]; + std::shared_ptr quiver = inventory[CONST_SLOT_RIGHT]; return quiver && quiver->isQuiver() && quiver->getContainer(); } bool Player::hasWeaponDistanceEquipped() const { - const Item* item = inventory[CONST_SLOT_LEFT]; + std::shared_ptr item = inventory[CONST_SLOT_LEFT]; return item && item->getWeaponType() == WEAPON_DISTANCE; } -Item* Player::getQuiverAmmoOfType(const ItemType &it) const { +std::shared_ptr Player::getQuiverAmmoOfType(const ItemType &it) const { if (!hasQuiverEquipped()) { return nullptr; } - Item* quiver = inventory[CONST_SLOT_RIGHT]; - for (const Container* container = quiver->getContainer(); - Item * ammoItem : container->getItemList()) { + std::shared_ptr quiver = inventory[CONST_SLOT_RIGHT]; + for (std::shared_ptr container = quiver->getContainer(); + auto ammoItem : container->getItemList()) { if (ammoItem->getAmmoType() == it.ammoType) { if (level >= Item::items[ammoItem->getID()].minReqLevel) { return ammoItem; @@ -299,8 +297,8 @@ Item* Player::getQuiverAmmoOfType(const ItemType &it) const { return nullptr; } -Item* Player::getWeapon(bool ignoreAmmo /* = false*/) const { - Item* item = getWeapon(CONST_SLOT_LEFT, ignoreAmmo); +std::shared_ptr Player::getWeapon(bool ignoreAmmo /* = false*/) const { + std::shared_ptr item = getWeapon(CONST_SLOT_LEFT, ignoreAmmo); if (item) { return item; } @@ -313,14 +311,14 @@ Item* Player::getWeapon(bool ignoreAmmo /* = false*/) const { } WeaponType_t Player::getWeaponType() const { - Item* item = getWeapon(); + std::shared_ptr item = getWeapon(); if (!item) { return WEAPON_NONE; } return item->getWeaponType(); } -int32_t Player::getWeaponSkill(const Item* item) const { +int32_t Player::getWeaponSkill(std::shared_ptr item) const { if (!item) { return getSkillLevel(SKILL_FIST); } @@ -363,7 +361,7 @@ int32_t Player::getArmor() const { static const Slots_t armorSlots[] = { CONST_SLOT_HEAD, CONST_SLOT_NECKLACE, CONST_SLOT_ARMOR, CONST_SLOT_LEGS, CONST_SLOT_FEET, CONST_SLOT_RING }; for (Slots_t slot : armorSlots) { - Item* inventoryItem = inventory[slot]; + std::shared_ptr inventoryItem = inventory[slot]; if (inventoryItem) { armor += inventoryItem->getArmor(); } @@ -371,12 +369,12 @@ int32_t Player::getArmor() const { return static_cast(armor * vocation->armorMultiplier); } -void Player::getShieldAndWeapon(const Item*&shield, const Item*&weapon) const { +void Player::getShieldAndWeapon(std::shared_ptr &shield, std::shared_ptr &weapon) const { shield = nullptr; weapon = nullptr; for (uint32_t slot = CONST_SLOT_RIGHT; slot <= CONST_SLOT_LEFT; slot++) { - Item* item = inventory[slot]; + std::shared_ptr item = inventory[slot]; if (!item) { continue; } @@ -407,8 +405,8 @@ float Player::getMitigation() const { int32_t Player::getDefense() const { int32_t defenseSkill = getSkillLevel(SKILL_FIST); int32_t defenseValue = 7; - const Item* weapon; - const Item* shield; + std::shared_ptr weapon; + std::shared_ptr shield; try { getShieldAndWeapon(shield, weapon); } catch (const std::exception &e) { @@ -563,7 +561,7 @@ void Player::updateInventoryWeight() { inventoryWeight = 0; for (int i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; ++i) { - const Item* item = inventory[i]; + std::shared_ptr item = inventory[i]; if (item) { inventoryWeight += item->getWeight(); } @@ -572,7 +570,7 @@ void Player::updateInventoryWeight() { void Player::updateInventoryImbuement() { // Get the tile the player is currently on - const Tile* playerTile = getTile(); + std::shared_ptr playerTile = getTile(); // Check if the player is in a protection zone bool isInProtectionZone = playerTile && playerTile->hasFlag(TILESTATE_PROTECTIONZONE); // Check if the player is in fight mode @@ -603,7 +601,7 @@ void Player::updateInventoryImbuement() { continue; } // If the item is not in the backpack slot and it's not a agressive imbuement, ignore it. - if (categoryImbuement && !categoryImbuement->agressive && parent && parent != this) { + if (categoryImbuement && !categoryImbuement->agressive && parent && parent != getPlayer()) { continue; } @@ -632,7 +630,7 @@ void Player::updateInventoryImbuement() { void Player::setTraining(bool value) { for (const auto &[key, player] : g_game().getPlayers()) { if (!this->isInGhostMode() || player->isAccessPlayer()) { - player->notifyStatusChange(this, value ? VIPSTATUS_TRAINING : VIPSTATUS_ONLINE, false); + player->notifyStatusChange(static_self_cast(), value ? VIPSTATUS_TRAINING : VIPSTATUS_ONLINE, false); } } this->statusVipList = VIPSTATUS_TRAINING; @@ -674,8 +672,8 @@ void Player::addSkillAdvance(skills_t skill, uint64_t count) { return; } - g_events().eventPlayerOnGainSkillTries(this, skill, count); - g_callbacks().executeCallback(EventCallback_t::playerOnGainSkillTries, &EventCallback::playerOnGainSkillTries, this, skill, count); + g_events().eventPlayerOnGainSkillTries(static_self_cast(), skill, count); + g_callbacks().executeCallback(EventCallback_t::playerOnGainSkillTries, &EventCallback::playerOnGainSkillTries, getPlayer(), skill, count); if (count == 0) { return; } @@ -691,7 +689,7 @@ void Player::addSkillAdvance(skills_t skill, uint64_t count) { ss << "You advanced to " << getSkillName(skill) << " level " << skills[skill].level << '.'; sendTextMessage(MESSAGE_EVENT_ADVANCE, ss.str()); - g_creatureEvents().playerAdvance(this, skill, (skills[skill].level - 1), skills[skill].level); + g_creatureEvents().playerAdvance(static_self_cast(), skill, (skills[skill].level - 1), skills[skill].level); sendUpdateSkills = true; currReqTries = nextReqTries; @@ -730,7 +728,7 @@ void Player::setVarStats(stats_t stat, int32_t modifier) { if (getHealth() > getMaxHealth()) { Creature::changeHealth(getMaxHealth() - getHealth()); } else { - g_game().addCreatureHealth(this); + g_game().addCreatureHealth(static_self_cast()); } break; } @@ -739,7 +737,7 @@ void Player::setVarStats(stats_t stat, int32_t modifier) { if (getMana() > getMaxMana()) { Creature::changeMana(getMaxMana() - getMana()); } else { - g_game().addPlayerMana(this); + g_game().addPlayerMana(static_self_cast()); } break; } @@ -763,7 +761,7 @@ int32_t Player::getDefaultStats(stats_t stat) const { } } -void Player::addContainer(uint8_t cid, Container* container) { +void Player::addContainer(uint8_t cid, std::shared_ptr container) { if (cid > 0xF) { return; } @@ -779,7 +777,7 @@ void Player::addContainer(uint8_t cid, Container* container) { auto it = openContainers.find(cid); if (it != openContainers.end()) { OpenContainer &openContainer = it->second; - Container* oldContainer = openContainer.container; + auto oldContainer = openContainer.container; if (oldContainer->getID() == ITEM_BROWSEFIELD) { oldContainer->decrementReferenceCounter(); } @@ -801,7 +799,7 @@ void Player::closeContainer(uint8_t cid) { } OpenContainer openContainer = it->second; - Container* container = openContainer.container; + std::shared_ptr container = openContainer.container; openContainers.erase(it); if (container && container->getID() == ITEM_BROWSEFIELD) { @@ -817,7 +815,7 @@ void Player::setContainerIndex(uint8_t cid, uint16_t index) { it->second.index = index; } -Container* Player::getContainerByID(uint8_t cid) { +std::shared_ptr Player::getContainerByID(uint8_t cid) { auto it = openContainers.find(cid); if (it == openContainers.end()) { return nullptr; @@ -825,7 +823,7 @@ Container* Player::getContainerByID(uint8_t cid) { return it->second.container; } -int8_t Player::getContainerID(const Container* container) const { +int8_t Player::getContainerID(std::shared_ptr container) const { for (const auto &it : openContainers) { if (it.second.container == container) { return it.first; @@ -880,8 +878,8 @@ void Player::addStorageValue(const uint32_t key, const int32_t value, const bool if (!isLogin) { auto currentFrameTime = g_dispatcher().getDispatcherCycle(); - g_events().eventOnStorageUpdate(this, key, value, getStorageValue(key), currentFrameTime); - g_callbacks().executeCallback(EventCallback_t::playerOnStorageUpdate, &EventCallback::playerOnStorageUpdate, this, key, value, getStorageValue(key), currentFrameTime); + g_events().eventOnStorageUpdate(static_self_cast(), key, value, getStorageValue(key), currentFrameTime); + g_callbacks().executeCallback(EventCallback_t::playerOnStorageUpdate, &EventCallback::playerOnStorageUpdate, getPlayer(), key, value, getStorageValue(key), currentFrameTime); } } else { storageMap.erase(key); @@ -919,15 +917,15 @@ void Player::addStorageValueByName(const std::string &storageName, const int32_t addStorageValue(key, value, isLogin); } -bool Player::canSee(const Position &pos) const { +bool Player::canSee(const Position &pos) { if (!client) { return false; } return client->canSee(pos); } -bool Player::canSeeCreature(const Creature* creature) const { - if (creature == this) { +bool Player::canSeeCreature(std::shared_ptr creature) const { + if (creature.get() == this) { return true; } @@ -941,14 +939,14 @@ bool Player::canSeeCreature(const Creature* creature) const { return true; } -bool Player::canWalkthrough(const Creature* creature) const { +bool Player::canWalkthrough(std::shared_ptr creature) { if (group->access || creature->isInGhostMode()) { return true; } - const Player* player = creature->getPlayer(); - const Monster* monster = creature->getMonster(); - const Npc* npc = creature->getNpc(); + std::shared_ptr player = creature->getPlayer(); + std::shared_ptr monster = creature->getMonster(); + std::shared_ptr npc = creature->getNpc(); if (monster) { if (!monster->isFamiliar()) { return false; @@ -957,17 +955,17 @@ bool Player::canWalkthrough(const Creature* creature) const { } if (player) { - const Tile* playerTile = player->getTile(); + std::shared_ptr playerTile = player->getTile(); if (!playerTile || (!playerTile->hasFlag(TILESTATE_NOPVPZONE) && !playerTile->hasFlag(TILESTATE_PROTECTIONZONE) && player->getLevel() > static_cast(g_configManager().getNumber(PROTECTION_LEVEL)) && g_game().getWorldType() != WORLD_TYPE_NO_PVP)) { return false; } - const Item* playerTileGround = playerTile->getGround(); + std::shared_ptr playerTileGround = playerTile->getGround(); if (!playerTileGround || !playerTileGround->hasWalkStack()) { return false; } - Player* thisPlayer = const_cast(this); + std::shared_ptr thisPlayer = getPlayer(); if ((OTSYS_TIME() - lastWalkthroughAttempt) > 2000) { thisPlayer->setLastWalkthroughAttempt(OTSYS_TIME()); return false; @@ -981,20 +979,20 @@ bool Player::canWalkthrough(const Creature* creature) const { thisPlayer->setLastWalkthroughPosition(creature->getPosition()); return true; } else if (npc) { - const Tile* tile = npc->getTile(); - const HouseTile* houseTile = dynamic_cast(tile); + std::shared_ptr tile = npc->getTile(); + std::shared_ptr houseTile = std::dynamic_pointer_cast(tile); return (houseTile != nullptr); } return false; } -bool Player::canWalkthroughEx(const Creature* creature) const { +bool Player::canWalkthroughEx(std::shared_ptr creature) { if (group->access) { return true; } - const Monster* monster = creature->getMonster(); + std::shared_ptr monster = creature->getMonster(); if (monster) { if (!monster->isFamiliar()) { return false; @@ -1002,28 +1000,28 @@ bool Player::canWalkthroughEx(const Creature* creature) const { return true; } - const Player* player = creature->getPlayer(); - const Npc* npc = creature->getNpc(); + std::shared_ptr player = creature->getPlayer(); + std::shared_ptr npc = creature->getNpc(); if (player) { - const Tile* playerTile = player->getTile(); + std::shared_ptr playerTile = player->getTile(); return playerTile && (playerTile->hasFlag(TILESTATE_NOPVPZONE) || playerTile->hasFlag(TILESTATE_PROTECTIONZONE) || player->getLevel() <= static_cast(g_configManager().getNumber(PROTECTION_LEVEL)) || g_game().getWorldType() == WORLD_TYPE_NO_PVP); } else if (npc) { - const Tile* tile = npc->getTile(); - const HouseTile* houseTile = dynamic_cast(tile); + std::shared_ptr tile = npc->getTile(); + std::shared_ptr houseTile = std::dynamic_pointer_cast(tile); return (houseTile != nullptr); } else { return false; } } -void Player::onReceiveMail() const { +void Player::onReceiveMail() { if (isNearDepotBox()) { sendTextMessage(MESSAGE_EVENT_ADVANCE, "New mail has arrived."); } } -Container* Player::setLootContainer(ObjectCategory_t category, Container* container, bool loading /* = false*/) { - Container* previousContainer = nullptr; +std::shared_ptr Player::setLootContainer(ObjectCategory_t category, std::shared_ptr container, bool loading /* = false*/) { + std::shared_ptr previousContainer = nullptr; if (auto it = quickLootContainers.find(category); it != quickLootContainers.end() && !loading) { previousContainer = (*it).second; @@ -1054,7 +1052,7 @@ Container* Player::setLootContainer(ObjectCategory_t category, Container* contai return nullptr; } -Container* Player::getLootContainer(ObjectCategory_t category) const { +std::shared_ptr Player::getLootContainer(ObjectCategory_t category) const { if (category != OBJECTCATEGORY_DEFAULT && !isPremium()) { category = OBJECTCATEGORY_DEFAULT; } @@ -1072,12 +1070,12 @@ Container* Player::getLootContainer(ObjectCategory_t category) const { return nullptr; } -void Player::checkLootContainers(const Item* item) { +void Player::checkLootContainers(std::shared_ptr item) { if (!item) { return; } - const Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (!container) { return; } @@ -1086,10 +1084,10 @@ void Player::checkLootContainers(const Item* item) { auto it = quickLootContainers.begin(); while (it != quickLootContainers.end()) { - Container* lootContainer = (*it).second; + std::shared_ptr lootContainer = (*it).second; bool remove = false; - if (item->getHoldingPlayer() != this && (item == lootContainer || container->isHoldingItem(lootContainer))) { + if (item->getHoldingPlayer() != getPlayer() && (item == lootContainer || container->isHoldingItem(lootContainer))) { remove = true; } @@ -1108,21 +1106,21 @@ void Player::checkLootContainers(const Item* item) { } } -void Player::sendLootStats(Item* item, uint8_t count) const { +void Player::sendLootStats(std::shared_ptr item, uint8_t count) { if (client) { client->sendLootStats(item, count); } if (party) { - party->addPlayerLoot(this, item); + party->addPlayerLoot(getPlayer(), item); } } -bool Player::isNearDepotBox() const { +bool Player::isNearDepotBox() { const Position &pos = getPosition(); for (int32_t cx = -1; cx <= 1; ++cx) { for (int32_t cy = -1; cy <= 1; ++cy) { - const Tile* posTile = g_game().map.getTile(static_cast(pos.x + cx), static_cast(pos.y + cy), pos.z); + std::shared_ptr posTile = g_game().map.getTile(static_cast(pos.x + cx), static_cast(pos.y + cy), pos.z); if (!posTile) { continue; } @@ -1135,7 +1133,7 @@ bool Player::isNearDepotBox() const { return false; } -DepotChest* Player::getDepotChest(uint32_t depotId, bool autoCreate) { +std::shared_ptr Player::getDepotChest(uint32_t depotId, bool autoCreate) { auto it = depotChests.find(depotId); if (it != depotChests.end()) { return it->second; @@ -1145,15 +1143,15 @@ DepotChest* Player::getDepotChest(uint32_t depotId, bool autoCreate) { return nullptr; } - DepotChest* depotChest; + std::shared_ptr depotChest; if (depotId > 0 && depotId < 18) { - depotChest = new DepotChest(ITEM_DEPOT_NULL + depotId); + depotChest = std::make_shared(ITEM_DEPOT_NULL + depotId); } else if (depotId == 18) { - depotChest = new DepotChest(ITEM_DEPOT_XVIII); + depotChest = std::make_shared(ITEM_DEPOT_XVIII); } else if (depotId == 19) { - depotChest = new DepotChest(ITEM_DEPOT_XIX); + depotChest = std::make_shared(ITEM_DEPOT_XIX); } else { - depotChest = new DepotChest(ITEM_DEPOT_XX); + depotChest = std::make_shared(ITEM_DEPOT_XX); } depotChest->incrementReferenceCounter(); @@ -1161,12 +1159,12 @@ DepotChest* Player::getDepotChest(uint32_t depotId, bool autoCreate) { return depotChest; } -DepotLocker* Player::getDepotLocker(uint32_t depotId) { +std::shared_ptr Player::getDepotLocker(uint32_t depotId) { auto it = depotLockerMap.find(depotId); if (it != depotLockerMap.end()) { inbox->setParent(it->second); for (uint32_t i = g_configManager().getNumber(DEPOT_BOXES); i > 0; i--) { - if (DepotChest* depotBox = getDepotChest(i, false)) { + if (std::shared_ptr depotBox = getDepotChest(i, false)) { depotBox->setParent(it->second->getItemByIndex(0)->getContainer()); } } @@ -1176,16 +1174,16 @@ DepotLocker* Player::getDepotLocker(uint32_t depotId) { // We need to make room for supply stash on 12+ protocol versions and remove it for 10x. bool createSupplyStash = !client->oldProtocol; - DepotLocker* depotLocker = new DepotLocker(ITEM_LOCKER, createSupplyStash ? 4 : 3); + std::shared_ptr depotLocker = std::make_shared(ITEM_LOCKER, createSupplyStash ? 4 : 3); depotLocker->setDepotId(depotId); depotLocker->internalAddThing(Item::CreateItem(ITEM_MARKET)); depotLocker->internalAddThing(inbox); if (createSupplyStash) { depotLocker->internalAddThing(Item::CreateItem(ITEM_SUPPLY_STASH)); } - Container* depotChest = Item::CreateItemAsContainer(ITEM_DEPOT, static_cast(g_configManager().getNumber(DEPOT_BOXES))); + std::shared_ptr depotChest = Item::CreateItemAsContainer(ITEM_DEPOT, static_cast(g_configManager().getNumber(DEPOT_BOXES))); for (uint32_t i = g_configManager().getNumber(DEPOT_BOXES); i > 0; i--) { - DepotChest* depotBox = getDepotChest(i, true); + std::shared_ptr depotBox = getDepotChest(i, true); depotChest->internalAddThing(depotBox); depotBox->setParent(depotChest); } @@ -1194,16 +1192,16 @@ DepotLocker* Player::getDepotLocker(uint32_t depotId) { return depotLocker; } -RewardChest* Player::getRewardChest() { +std::shared_ptr Player::getRewardChest() { if (rewardChest != nullptr) { return rewardChest; } - rewardChest = new RewardChest(ITEM_REWARD_CHEST); + rewardChest = std::make_shared(ITEM_REWARD_CHEST); return rewardChest; } -Reward* Player::getReward(const uint64_t rewardId, const bool autoCreate) { +std::shared_ptr Player::getReward(const uint64_t rewardId, const bool autoCreate) { auto it = rewardMap.find(rewardId); if (it != rewardMap.end()) { return it->second; @@ -1212,7 +1210,7 @@ Reward* Player::getReward(const uint64_t rewardId, const bool autoCreate) { return nullptr; } - auto reward = new Reward(); + auto reward = std::make_shared(); reward->incrementReferenceCounter(); reward->setAttribute(ItemAttribute_t::DATE, rewardId); rewardMap[rewardId] = reward; @@ -1232,8 +1230,8 @@ void Player::getRewardList(std::vector &rewards) const { } } -std::vector Player::getRewardsFromContainer(const Container* container) const { - std::vector rewardItemsVector; +std::vector> Player::getRewardsFromContainer(std::shared_ptr container) const { + std::vector> rewardItemsVector; if (container) { for (auto item : container->getItems(false)) { if (item->getID() == ITEM_REWARD_CONTAINER) { @@ -1259,13 +1257,13 @@ void Player::sendStats() { } } -void Player::updateSupplyTracker(const Item* item) const { +void Player::updateSupplyTracker(std::shared_ptr item) { if (client) { client->sendUpdateSupplyTracker(item); } if (party) { - party->addPlayerSupply(this, item); + party->addPlayerSupply(getPlayer(), item); } } @@ -1293,22 +1291,22 @@ void Player::sendPing() { setAttackedCreature(nullptr); } - if (noPongTime >= 60000 && canLogout() && g_creatureEvents().playerLogout(this)) { + if (noPongTime >= 60000 && canLogout() && g_creatureEvents().playerLogout(static_self_cast())) { if (client) { client->logout(true, true); } else { - g_game().removeCreature(this, true); + g_game().removeCreature(static_self_cast(), true); } } } -Item* Player::getWriteItem(uint32_t &retWindowTextId, uint16_t &retMaxWriteLen) { +std::shared_ptr Player::getWriteItem(uint32_t &retWindowTextId, uint16_t &retMaxWriteLen) { retWindowTextId = this->windowTextId; retMaxWriteLen = this->maxWriteLen; return writeItem; } -void Player::setImbuingItem(Item* item) { +void Player::setImbuingItem(std::shared_ptr item) { if (imbuingItem) { imbuingItem->decrementReferenceCounter(); } @@ -1320,7 +1318,7 @@ void Player::setImbuingItem(Item* item) { imbuingItem = item; } -void Player::setWriteItem(Item* item, uint16_t maxWriteLength /*= 0*/) { +void Player::setWriteItem(std::shared_ptr item, uint16_t maxWriteLength /*= 0*/) { windowTextId++; if (writeItem) { @@ -1360,7 +1358,7 @@ void Player::sendHouseWindow(House* house, uint32_t listId) const { } } -void Player::onApplyImbuement(Imbuement* imbuement, Item* item, uint8_t slot, bool protectionCharm) { +void Player::onApplyImbuement(Imbuement* imbuement, std::shared_ptr item, uint8_t slot, bool protectionCharm) { if (!imbuement || !item) { return; } @@ -1375,7 +1373,7 @@ void Player::onApplyImbuement(Imbuement* imbuement, Item* item, uint8_t slot, bo const auto &items = imbuement->getItems(); for (auto &[key, value] : items) { const ItemType &itemType = Item::items[key]; - if (this->getItemTypeCount(key) + this->getStashItemCount(itemType.id) < value) { + if (static_self_cast()->getItemTypeCount(key) + this->getStashItemCount(itemType.id) < value) { this->sendImbuementResult("You don't have all necessary items."); return; } @@ -1389,7 +1387,7 @@ void Player::onApplyImbuement(Imbuement* imbuement, Item* item, uint8_t slot, bo uint32_t price = baseImbuement->price; price += protectionCharm ? baseImbuement->protectionPrice : 0; - if (!g_game().removeMoney(this, price, 0, true)) { + if (!g_game().removeMoney(static_self_cast(), price, 0, true)) { std::string message = fmt::format("You don't have {} gold coins.", price); g_logger().error("[Player::onApplyImbuement] - An error occurred while player with name {} try to apply imbuement, player do not have money", this->getName()); @@ -1426,7 +1424,7 @@ void Player::onApplyImbuement(Imbuement* imbuement, Item* item, uint8_t slot, bo } // Update imbuement stats item if the item is equipped - if (item->getParent() == this) { + if (item->getParent() == getPlayer()) { addItemImbuementStats(imbuement); } @@ -1434,7 +1432,7 @@ void Player::onApplyImbuement(Imbuement* imbuement, Item* item, uint8_t slot, bo openImbuementWindow(item); } -void Player::onClearImbuement(Item* item, uint8_t slot) { +void Player::onClearImbuement(std::shared_ptr item, uint8_t slot) { if (!item) { return; } @@ -1451,7 +1449,7 @@ void Player::onClearImbuement(Item* item, uint8_t slot) { return; } - if (!g_game().removeMoney(this, baseImbuement->removeCost, 0, true)) { + if (!g_game().removeMoney(static_self_cast(), baseImbuement->removeCost, 0, true)) { std::string message = fmt::format("You don't have {} gold coins.", baseImbuement->removeCost); g_logger().error("[Player::onClearImbuement] - An error occurred while player with name {} try to apply imbuement, player do not have money", this->getName()); @@ -1460,7 +1458,7 @@ void Player::onClearImbuement(Item* item, uint8_t slot) { return; } - if (item->getParent() == this) { + if (item->getParent() == getPlayer()) { removeItemImbuementStats(imbuementInfo.imbuement); } @@ -1468,7 +1466,7 @@ void Player::onClearImbuement(Item* item, uint8_t slot) { this->openImbuementWindow(item); } -void Player::openImbuementWindow(Item* item) { +void Player::openImbuementWindow(std::shared_ptr item) { if (!client || !item) { return; } @@ -1479,7 +1477,7 @@ void Player::openImbuementWindow(Item* item) { } auto itemParent = item->getTopParent(); - if (itemParent && itemParent != this) { + if (itemParent && itemParent != getPlayer()) { this->sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have to pick up the item to imbue it."); return; } @@ -1496,7 +1494,7 @@ void Player::sendMarketEnter(uint32_t depotId) { } // container -void Player::sendAddContainerItem(const Container* container, const Item* item) { +void Player::sendAddContainerItem(std::shared_ptr container, std::shared_ptr item) { if (!client) { return; } @@ -1528,7 +1526,7 @@ void Player::sendAddContainerItem(const Container* container, const Item* item) } } -void Player::sendUpdateContainerItem(const Container* container, uint16_t slot, const Item* newItem) { +void Player::sendUpdateContainerItem(std::shared_ptr container, uint16_t slot, std::shared_ptr newItem) { if (!client) { return; } @@ -1552,7 +1550,7 @@ void Player::sendUpdateContainerItem(const Container* container, uint16_t slot, } } -void Player::sendRemoveContainerItem(const Container* container, uint16_t slot) { +void Player::sendRemoveContainerItem(std::shared_ptr container, uint16_t slot) { if (!client) { return; } @@ -1577,7 +1575,7 @@ void Player::sendRemoveContainerItem(const Container* container, uint16_t slot) } } -void Player::onUpdateTileItem(const Tile* updateTile, const Position &pos, const Item* oldItem, const ItemType &oldType, const Item* newItem, const ItemType &newType) { +void Player::onUpdateTileItem(std::shared_ptr updateTile, const Position &pos, std::shared_ptr oldItem, const ItemType &oldType, std::shared_ptr newItem, const ItemType &newType) { Creature::onUpdateTileItem(updateTile, pos, oldItem, oldType, newItem, newType); if (oldItem != newItem) { @@ -1586,21 +1584,21 @@ void Player::onUpdateTileItem(const Tile* updateTile, const Position &pos, const if (tradeState != TRADE_TRANSFER) { if (tradeItem && oldItem == tradeItem) { - g_game().internalCloseTrade(this); + g_game().internalCloseTrade(getPlayer()); } } } -void Player::onRemoveTileItem(const Tile* fromTile, const Position &pos, const ItemType &iType, const Item* item) { +void Player::onRemoveTileItem(std::shared_ptr fromTile, const Position &pos, const ItemType &iType, std::shared_ptr item) { Creature::onRemoveTileItem(fromTile, pos, iType, item); if (tradeState != TRADE_TRANSFER) { checkTradeState(item); if (tradeItem) { - const Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container && container->isHoldingItem(tradeItem)) { - g_game().internalCloseTrade(this); + g_game().internalCloseTrade(static_self_cast()); } } } @@ -1608,15 +1606,15 @@ void Player::onRemoveTileItem(const Tile* fromTile, const Position &pos, const I checkLootContainers(item); } -void Player::onCreatureAppear(Creature* creature, bool isLogin) { +void Player::onCreatureAppear(std::shared_ptr creature, bool isLogin) { Creature::onCreatureAppear(creature, isLogin); - if (isLogin && creature == this) { + if (isLogin && creature == getPlayer()) { for (int32_t slot = CONST_SLOT_FIRST; slot <= CONST_SLOT_LAST; ++slot) { - Item* item = inventory[slot]; + std::shared_ptr item = inventory[slot]; if (item) { item->startDecaying(); - g_moveEvents().onPlayerEquip(*this, *item, static_cast(slot), false); + g_moveEvents().onPlayerEquip(getPlayer(), item, static_cast(slot), false); } } @@ -1627,16 +1625,16 @@ void Player::onCreatureAppear(Creature* creature, bool isLogin) { updateRegeneration(); - BedItem* bed = g_game().getBedBySleeper(guid); + std::shared_ptr bed = g_game().getBedBySleeper(guid); if (bed) { - bed->wakeUp(this); + bed->wakeUp(static_self_cast()); } auto version = client->oldProtocol ? getProtocolVersion() : CLIENT_VERSION; g_logger().info("{} has logged in. (Protocol: {})", name, version); if (guild) { - guild->addMember(this); + guild->addMember(static_self_cast()); } int32_t offlineTime; @@ -1692,7 +1690,7 @@ void Player::onChangeZone(ZoneType_t zone) { if (!group->access && isMounted()) { dismount(); - g_game().internalCreatureChangeOutfit(this, defaultOutfit); + g_game().internalCreatureChangeOutfit(getPlayer(), defaultOutfit); wasMounted = true; } } else { @@ -1705,11 +1703,11 @@ void Player::onChangeZone(ZoneType_t zone) { updateImbuementTrackerStats(); wheel()->onThink(true); wheel()->sendGiftOfLifeCooldown(); - g_game().updateCreatureWalkthrough(this); + g_game().updateCreatureWalkthrough(static_self_cast()); sendIcons(); - g_events().eventPlayerOnChangeZone(this, zone); + g_events().eventPlayerOnChangeZone(static_self_cast(), zone); - g_callbacks().executeCallback(EventCallback_t::playerOnChangeZone, &EventCallback::playerOnChangeZone, this, zone); + g_callbacks().executeCallback(EventCallback_t::playerOnChangeZone, &EventCallback::playerOnChangeZone, getPlayer(), zone); } void Player::onAttackedCreatureChangeZone(ZoneType_t zone) { @@ -1734,23 +1732,23 @@ void Player::onAttackedCreatureChangeZone(ZoneType_t zone) { } } -void Player::onRemoveCreature(Creature* creature, bool isLogout) { +void Player::onRemoveCreature(std::shared_ptr creature, bool isLogout) { Creature::onRemoveCreature(creature, isLogout); - if (creature == this) { + if (creature == getPlayer()) { if (isLogout) { if (party) { - party->leaveParty(this); + party->leaveParty(static_self_cast()); } if (guild) { - guild->removeMember(this); + guild->removeMember(static_self_cast()); } - g_game().removePlayerUniqueLogin(this); + g_game().removePlayerUniqueLogin(static_self_cast()); loginPosition = getPosition(); lastLogout = time(nullptr); g_logger().info("{} has logged out", getName()); - g_chat().removeUserFromAllChannels(*this); + g_chat().removeUserFromAllChannels(getPlayer()); clearPartyInvitations(); IOLoginData::updateOnlineStatus(guid, false); } @@ -1760,13 +1758,13 @@ void Player::onRemoveCreature(Creature* creature, bool isLogout) { } if (tradePartner) { - g_game().internalCloseTrade(this); + g_game().internalCloseTrade(static_self_cast()); } closeShopWindow(); for (uint32_t tries = 0; tries < 3; ++tries) { - if (IOLoginData::savePlayer(this)) { + if (IOLoginData::savePlayer(static_self_cast())) { break; } } @@ -1778,14 +1776,14 @@ void Player::onRemoveCreature(Creature* creature, bool isLogout) { } } -bool Player::openShopWindow(Npc* npc) { +bool Player::openShopWindow(std::shared_ptr npc) { if (!npc) { g_logger().error("[Player::openShopWindow] - Npc is wrong or nullptr"); return false; } setShopOwner(npc); - npc->addShopPlayer(this); + npc->addShopPlayer(static_self_cast()); sendShop(npc); std::map inventoryMap; @@ -1798,7 +1796,7 @@ bool Player::closeShopWindow(bool sendCloseShopWindow /*= true*/) { return false; } - shopOwner->removeShopPlayer(this); + shopOwner->removeShopPlayer(static_self_cast()); setShopOwner(nullptr); if (sendCloseShopWindow) { @@ -1812,9 +1810,9 @@ void Player::onWalk(Direction &dir) { if (hasCondition(CONDITION_FEARED)) { Position pos = getNextPosition(dir, getPosition()); - const Tile* tile = g_game().map.getTile(pos); + std::shared_ptr tile = g_game().map.getTile(pos); if (tile) { - const MagicField* field = tile->getFieldItem(); + std::shared_ptr field = tile->getFieldItem(); if (field && !field->isBlocking() && field->getDamage() != 0) { setNextActionTask(nullptr); setNextAction(OTSYS_TIME() + getStepDuration(dir)); @@ -1828,26 +1826,26 @@ void Player::onWalk(Direction &dir) { setNextAction(OTSYS_TIME() + getStepDuration(dir)); } -void Player::onCreatureMove(Creature* creature, const Tile* newTile, const Position &newPos, const Tile* oldTile, const Position &oldPos, bool teleport) { +void Player::onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport) { Creature::onCreatureMove(creature, newTile, newPos, oldTile, oldPos, teleport); - if (hasFollowPath && (creature == followCreature || (creature == this && followCreature))) { + if (hasFollowPath && (creature == followCreature || (creature.get() == this && followCreature))) { isUpdatingPath = false; g_dispatcher().addTask(std::bind(&Game::updateCreatureWalk, &g_game(), getID()), "Game::updateCreatureWalk"); } - if (creature != this) { + if (creature != getPlayer()) { return; } if (tradeState != TRADE_TRANSFER) { // check if we should close trade if (tradeItem && !Position::areInRange<1, 1, 0>(tradeItem->getPosition(), getPosition())) { - g_game().internalCloseTrade(this); + g_game().internalCloseTrade(getPlayer()); } if (tradePartner && !Position::areInRange<2, 2, 0>(tradePartner->getPosition(), getPosition())) { - g_game().internalCloseTrade(this); + g_game().internalCloseTrade(static_self_cast()); } } @@ -1870,7 +1868,7 @@ void Player::onCreatureMove(Creature* creature, const Tile* newTile, const Posit if (party) { party->updateSharedExperience(); - party->updatePlayerStatus(this, oldPos, newPos); + party->updatePlayerStatus(static_self_cast(), oldPos, newPos); } if (teleport || oldPos.z != newPos.z) { @@ -1884,11 +1882,11 @@ void Player::onCreatureMove(Creature* creature, const Tile* newTile, const Posit } // container -void Player::onAddContainerItem(const Item* item) { +void Player::onAddContainerItem(std::shared_ptr item) { checkTradeState(item); } -void Player::onUpdateContainerItem(const Container* container, const Item* oldItem, const Item* newItem) { +void Player::onUpdateContainerItem(std::shared_ptr container, std::shared_ptr oldItem, std::shared_ptr newItem) { if (oldItem != newItem) { onRemoveContainerItem(container, oldItem); } @@ -1898,13 +1896,13 @@ void Player::onUpdateContainerItem(const Container* container, const Item* oldIt } } -void Player::onRemoveContainerItem(const Container* container, const Item* item) { +void Player::onRemoveContainerItem(std::shared_ptr container, std::shared_ptr item) { if (tradeState != TRADE_TRANSFER) { checkTradeState(item); if (tradeItem) { if (tradeItem->getParent() != container && container->isHoldingItem(tradeItem)) { - g_game().internalCloseTrade(this); + g_game().internalCloseTrade(static_self_cast()); } } } @@ -1912,7 +1910,7 @@ void Player::onRemoveContainerItem(const Container* container, const Item* item) checkLootContainers(item); } -void Player::onCloseContainer(const Container* container) { +void Player::onCloseContainer(std::shared_ptr container) { if (!client) { return; } @@ -1924,7 +1922,7 @@ void Player::onCloseContainer(const Container* container) { } } -void Player::onSendContainer(const Container* container) { +void Player::onSendContainer(std::shared_ptr container) { if (!client || !container) { return; } @@ -1939,7 +1937,7 @@ void Player::onSendContainer(const Container* container) { } // inventory -void Player::onUpdateInventoryItem(Item* oldItem, Item* newItem) { +void Player::onUpdateInventoryItem(std::shared_ptr oldItem, std::shared_ptr newItem) { if (oldItem != newItem) { onRemoveInventoryItem(oldItem); } @@ -1949,14 +1947,14 @@ void Player::onUpdateInventoryItem(Item* oldItem, Item* newItem) { } } -void Player::onRemoveInventoryItem(Item* item) { +void Player::onRemoveInventoryItem(std::shared_ptr item) { if (tradeState != TRADE_TRANSFER) { checkTradeState(item); if (tradeItem) { - const Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container && container->isHoldingItem(tradeItem)) { - g_game().internalCloseTrade(this); + g_game().internalCloseTrade(static_self_cast()); } } } @@ -1964,22 +1962,22 @@ void Player::onRemoveInventoryItem(Item* item) { checkLootContainers(item); } -void Player::checkTradeState(const Item* item) { +void Player::checkTradeState(std::shared_ptr item) { if (!tradeItem || tradeState == TRADE_TRANSFER) { return; } if (tradeItem == item) { - g_game().internalCloseTrade(this); + g_game().internalCloseTrade(static_self_cast()); } else { - const Container* container = dynamic_cast(item->getParent()); + std::shared_ptr container = std::dynamic_pointer_cast(item->getParent()); while (container) { if (container == tradeItem) { - g_game().internalCloseTrade(this); + g_game().internalCloseTrade(static_self_cast()); break; } - container = dynamic_cast(container->getParent()); + container = std::dynamic_pointer_cast(container->getParent()); } } } @@ -2150,16 +2148,16 @@ void Player::removeMessageBuffer() { } } -void Player::drainHealth(Creature* attacker, int32_t damage) { +void Player::drainHealth(std::shared_ptr attacker, int32_t damage) { if (PLAYER_SOUND_HEALTH_CHANGE >= static_cast(uniform_random(1, 100))) { - g_game().sendSingleSoundEffect(this->getPosition(), sex == PLAYERSEX_FEMALE ? SoundEffect_t::HUMAN_FEMALE_BARK : SoundEffect_t::HUMAN_MALE_BARK, this); + g_game().sendSingleSoundEffect(static_self_cast()->getPosition(), sex == PLAYERSEX_FEMALE ? SoundEffect_t::HUMAN_FEMALE_BARK : SoundEffect_t::HUMAN_MALE_BARK, getPlayer()); } Creature::drainHealth(attacker, damage); sendStats(); } -void Player::drainMana(Creature* attacker, int32_t manaLoss) { +void Player::drainMana(std::shared_ptr attacker, int32_t manaLoss) { Creature::drainMana(attacker, manaLoss); sendStats(); } @@ -2176,8 +2174,8 @@ void Player::addManaSpent(uint64_t amount) { return; } - g_events().eventPlayerOnGainSkillTries(this, SKILL_MAGLEVEL, amount); - g_callbacks().executeCallback(EventCallback_t::playerOnGainSkillTries, &EventCallback::playerOnGainSkillTries, this, SKILL_MAGLEVEL, amount); + g_events().eventPlayerOnGainSkillTries(static_self_cast(), SKILL_MAGLEVEL, amount); + g_callbacks().executeCallback(EventCallback_t::playerOnGainSkillTries, &EventCallback::playerOnGainSkillTries, getPlayer(), SKILL_MAGLEVEL, amount); if (amount == 0) { return; } @@ -2193,7 +2191,7 @@ void Player::addManaSpent(uint64_t amount) { ss << "You advanced to magic level " << magLevel << '.'; sendTextMessage(MESSAGE_EVENT_ADVANCE, ss.str()); - g_creatureEvents().playerAdvance(this, SKILL_MAGLEVEL, magLevel - 1, magLevel); + g_creatureEvents().playerAdvance(static_self_cast(), SKILL_MAGLEVEL, magLevel - 1, magLevel); sendUpdateStats = true; currReqMana = nextReqMana; @@ -2222,7 +2220,7 @@ void Player::addManaSpent(uint64_t amount) { } } -void Player::addExperience(Creature* target, uint64_t exp, bool sendText /* = false*/) { +void Player::addExperience(std::shared_ptr target, uint64_t exp, bool sendText /* = false*/) { uint64_t currLevelExp = Player::getExpForLevel(level); uint64_t nextLevelExp = Player::getExpForLevel(level + 1); uint64_t rawExp = exp; @@ -2233,15 +2231,15 @@ void Player::addExperience(Creature* target, uint64_t exp, bool sendText /* = fa return; } - g_callbacks().executeCallback(EventCallback_t::playerOnGainExperience, &EventCallback::playerOnGainExperience, this, target, exp, rawExp); + g_callbacks().executeCallback(EventCallback_t::playerOnGainExperience, &EventCallback::playerOnGainExperience, getPlayer(), target, exp, rawExp); - g_events().eventPlayerOnGainExperience(this, target, exp, rawExp); + g_events().eventPlayerOnGainExperience(static_self_cast(), target, exp, rawExp); if (exp == 0) { return; } // Hazard system experience - const Monster* monster = target && target->getMonster() ? target->getMonster() : nullptr; + std::shared_ptr monster = target && target->getMonster() ? target->getMonster() : nullptr; bool handleHazardExperience = monster && monster->getHazard() && getHazardSystemPoints() > 0; if (handleHazardExperience) { exp += (exp * (1.75 * getHazardSystemPoints() * g_configManager().getNumber(HAZARD_EXP_BONUS_MULTIPLIER))) / 100.; @@ -2266,11 +2264,11 @@ void Player::addExperience(Creature* target, uint64_t exp, bool sendText /* = fa SpectatorHashSet spectators; g_game().map.getSpectators(spectators, position, false, true); - spectators.erase(this); + spectators.erase(static_self_cast()); if (!spectators.empty()) { message.type = MESSAGE_EXPERIENCE_OTHERS; message.text = getName() + " gained " + expString; - for (Creature* spectator : spectators) { + for (std::shared_ptr spectator : spectators) { spectator->getPlayer()->sendTextMessage(message); } } @@ -2309,15 +2307,15 @@ void Player::addExperience(Creature* target, uint64_t exp, bool sendText /* = fa updateBaseSpeed(); setBaseSpeed(getBaseSpeed()); - g_game().changeSpeed(this, 0); - g_game().addCreatureHealth(this); - g_game().addPlayerMana(this); + g_game().changeSpeed(static_self_cast(), 0); + g_game().addCreatureHealth(static_self_cast()); + g_game().addPlayerMana(static_self_cast()); if (party) { party->updateSharedExperience(); } - g_creatureEvents().playerAdvance(this, SKILL_LEVEL, prevLevel, level); + g_creatureEvents().playerAdvance(static_self_cast(), SKILL_LEVEL, prevLevel, level); std::ostringstream ss; ss << "You advanced from Level " << prevLevel << " to Level " << level << '.'; @@ -2338,8 +2336,8 @@ void Player::removeExperience(uint64_t exp, bool sendText /* = false*/) { return; } - g_events().eventPlayerOnLoseExperience(this, exp); - g_callbacks().executeCallback(EventCallback_t::playerOnLoseExperience, &EventCallback::playerOnLoseExperience, this, exp); + g_events().eventPlayerOnLoseExperience(static_self_cast(), exp); + g_callbacks().executeCallback(EventCallback_t::playerOnLoseExperience, &EventCallback::playerOnLoseExperience, getPlayer(), exp); if (exp == 0) { return; } @@ -2360,11 +2358,11 @@ void Player::removeExperience(uint64_t exp, bool sendText /* = false*/) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, position, false, true); - spectators.erase(this); + spectators.erase(static_self_cast()); if (!spectators.empty()) { message.type = MESSAGE_EXPERIENCE_OTHERS; message.text = getName() + " lost " + expString; - for (Creature* spectator : spectators) { + for (std::shared_ptr spectator : spectators) { spectator->getPlayer()->sendTextMessage(message); } } @@ -2396,9 +2394,9 @@ void Player::removeExperience(uint64_t exp, bool sendText /* = false*/) { updateBaseSpeed(); setBaseSpeed(getBaseSpeed()); - g_game().changeSpeed(this, 0); - g_game().addCreatureHealth(this); - g_game().addPlayerMana(this); + g_game().changeSpeed(static_self_cast(), 0); + g_game().addCreatureHealth(static_self_cast()); + g_game().addPlayerMana(static_self_cast()); if (party) { party->updateSharedExperience(); @@ -2472,7 +2470,7 @@ void Player::onAttackedCreatureBlockHit(BlockType_t blockType) { } bool Player::hasShield() const { - Item* item = inventory[CONST_SLOT_LEFT]; + std::shared_ptr item = inventory[CONST_SLOT_LEFT]; if (item && item->getWeaponType() == WEAPON_SHIELD) { return true; } @@ -2484,7 +2482,7 @@ bool Player::hasShield() const { return false; } -BlockType_t Player::blockHit(Creature* attacker, CombatType_t combatType, int32_t &damage, bool checkDefense /* = false*/, bool checkArmor /* = false*/, bool field /* = false*/) { +BlockType_t Player::blockHit(std::shared_ptr attacker, CombatType_t combatType, int32_t &damage, bool checkDefense /* = false*/, bool checkArmor /* = false*/, bool field /* = false*/) { BlockType_t blockType = Creature::blockHit(attacker, combatType, damage, checkDefense, checkArmor, field); if (attacker) { sendCreatureSquare(attacker, SQ_COLOR_BLACK); @@ -2500,7 +2498,7 @@ BlockType_t Player::blockHit(Creature* attacker, CombatType_t combatType, int32_ continue; } - Item* item = inventory[slot]; + std::shared_ptr item = inventory[slot]; if (!item) { continue; } @@ -2561,10 +2559,10 @@ uint32_t Player::getIP() const { return 0; } -void Player::death(Creature* lastHitCreature) { +void Player::death(std::shared_ptr lastHitCreature) { loginPosition = town->getTemplePosition(); - g_game().sendSingleSoundEffect(this->getPosition(), sex == PLAYERSEX_FEMALE ? SoundEffect_t::HUMAN_FEMALE_DEATH : SoundEffect_t::HUMAN_MALE_DEATH, this); + g_game().sendSingleSoundEffect(static_self_cast()->getPosition(), sex == PLAYERSEX_FEMALE ? SoundEffect_t::HUMAN_FEMALE_DEATH : SoundEffect_t::HUMAN_MALE_DEATH, getPlayer()); if (skillLoss) { uint8_t unfairFightReduction = 100; int playerDmg = 0; @@ -2574,7 +2572,7 @@ void Player::death(Creature* lastHitCreature) { for (const auto &it : damageMap) { CountBlock_t cb = it.second; if ((OTSYS_TIME() - cb.ticks) <= inFightTicks) { - const Player* damageDealer = g_game().getPlayerByID(it.first); + std::shared_ptr damageDealer = g_game().getPlayerByID(it.first); if (damageDealer) { playerDmg += cb.total; sumLevels += damageDealer->getLevel(); @@ -2634,8 +2632,8 @@ void Player::death(Creature* lastHitCreature) { // Level loss uint64_t expLoss = static_cast(experience * deathLossPercent); - g_events().eventPlayerOnLoseExperience(this, expLoss); - g_callbacks().executeCallback(EventCallback_t::playerOnLoseExperience, &EventCallback::playerOnLoseExperience, this, expLoss); + g_events().eventPlayerOnLoseExperience(static_self_cast(), expLoss); + g_callbacks().executeCallback(EventCallback_t::playerOnLoseExperience, &EventCallback::playerOnLoseExperience, getPlayer(), expLoss); sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are dead."); std::ostringstream lostExp; @@ -2747,9 +2745,9 @@ void Player::death(Creature* lastHitCreature) { if (condition->isPersistent() && condition->isRemovableOnDeath()) { it = conditions.erase(it); - condition->endCondition(this); + condition->endCondition(static_self_cast()); onEndCondition(condition->getType()); - delete condition; + } else { ++it; } @@ -2763,18 +2761,18 @@ void Player::death(Creature* lastHitCreature) { if (condition->isPersistent()) { it = conditions.erase(it); - condition->endCondition(this); + condition->endCondition(static_self_cast()); onEndCondition(condition->getType()); - delete condition; + } else { ++it; } } health = healthMax; - g_game().internalTeleport(this, getTemplePosition(), true); - g_game().addCreatureHealth(this); - g_game().addPlayerMana(this); + g_game().internalTeleport(static_self_cast(), getTemplePosition(), true); + g_game().addCreatureHealth(static_self_cast()); + g_game().addPlayerMana(static_self_cast()); onThink(EVENT_CREATURE_THINK_INTERVAL); onIdleStatus(); sendStats(); @@ -2788,27 +2786,27 @@ bool Player::spawn() { const Position &pos = getLoginPosition(); - if (!g_game().map.placeCreature(pos, this, false, true)) { + if (!g_game().map.placeCreature(pos, getPlayer(), false, true)) { return false; } SpectatorHashSet spectators; g_game().map.getSpectators(spectators, position, true); - for (Creature* spectator : spectators) { + for (std::shared_ptr spectator : spectators) { if (!spectator) { continue; } - if (Player* tmpPlayer = spectator->getPlayer()) { - tmpPlayer->sendCreatureAppear(this, pos, true); + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { + tmpPlayer->sendCreatureAppear(static_self_cast(), pos, true); } - spectator->onCreatureAppear(this, false); + spectator->onCreatureAppear(static_self_cast(), false); } - getParent()->postAddNotification(this, nullptr, 0); - g_game().addCreatureCheck(this); - g_game().addPlayer(this); + getParent()->postAddNotification(static_self_cast(), nullptr, 0); + g_game().addCreatureCheck(static_self_cast()); + g_game().addPlayer(static_self_cast()); return true; } @@ -2821,14 +2819,14 @@ void Player::despawn() { stopEventWalk(); onWalkAborted(); closeAllExternalContainers(); - g_game().playerSetAttackedCreature(this->getID(), 0); - g_game().playerFollowCreature(this->getID(), 0); + g_game().playerSetAttackedCreature(static_self_cast()->getID(), 0); + g_game().playerFollowCreature(static_self_cast()->getID(), 0); // remove check - Game::removeCreatureCheck(this); + Game::removeCreatureCheck(static_self_cast()); // remove from map - Tile* tile = getTile(); + std::shared_ptr tile = getTile(); if (!tile) { return; } @@ -2838,36 +2836,36 @@ void Player::despawn() { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, tile->getPosition(), true); size_t i = 0; - for (Creature* spectator : spectators) { + for (std::shared_ptr spectator : spectators) { if (!spectator) { continue; } - if (const Player* player = spectator->getPlayer()) { - oldStackPosVector.push_back(player->canSeeCreature(this) ? tile->getStackposOfCreature(player, this) : -1); + if (const auto player = spectator->getPlayer()) { + oldStackPosVector.push_back(player->canSeeCreature(static_self_cast()) ? tile->getStackposOfCreature(player, getPlayer()) : -1); } - if (Player* player = spectator->getPlayer()) { + if (auto player = spectator->getPlayer()) { player->sendRemoveTileThing(tile->getPosition(), oldStackPosVector[i++]); } - spectator->onRemoveCreature(this, false); + spectator->onRemoveCreature(static_self_cast(), false); } - tile->removeCreature(this); + tile->removeCreature(static_self_cast()); - getParent()->postRemoveNotification(this, nullptr, 0); + getParent()->postRemoveNotification(static_self_cast(), nullptr, 0); - g_game().removePlayer(this); + g_game().removePlayer(static_self_cast()); // show player as pending for (const auto &[key, player] : g_game().getPlayers()) { - player->notifyStatusChange(this, VIPSTATUS_PENDING, false); + player->notifyStatusChange(static_self_cast(), VIPSTATUS_PENDING, false); } setDead(true); } -bool Player::dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified) { +bool Player::dropCorpse(std::shared_ptr lastHitCreature, std::shared_ptr mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified) { if (getZoneType() != ZONE_PVP || !Player::lastHitIsPlayer(lastHitCreature)) { return Creature::dropCorpse(lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified); } @@ -2876,8 +2874,8 @@ bool Player::dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, return false; } -Item* Player::getCorpse(Creature* lastHitCreature, Creature* mostDamageCreature) { - Item* corpse = Creature::getCorpse(lastHitCreature, mostDamageCreature); +std::shared_ptr Player::getCorpse(std::shared_ptr lastHitCreature, std::shared_ptr mostDamageCreature) { + std::shared_ptr corpse = Creature::getCorpse(lastHitCreature, mostDamageCreature); if (corpse && corpse->getContainer()) { std::ostringstream ss; if (lastHitCreature) { @@ -2912,31 +2910,31 @@ void Player::addInFightTicks(bool pzlock /*= false*/) { } void Player::removeList() { - g_game().removePlayer(this); + g_game().removePlayer(static_self_cast()); for (const auto &[key, player] : g_game().getPlayers()) { - player->notifyStatusChange(this, VIPSTATUS_OFFLINE); + player->notifyStatusChange(static_self_cast(), VIPSTATUS_OFFLINE); } } void Player::addList() { for (const auto &[key, player] : g_game().getPlayers()) { - player->notifyStatusChange(this, this->statusVipList); + player->notifyStatusChange(static_self_cast(), this->statusVipList); } - g_game().addPlayer(this); + g_game().addPlayer(static_self_cast()); } void Player::removePlayer(bool displayEffect, bool forced /*= true*/) { - g_creatureEvents().playerLogout(this); + g_creatureEvents().playerLogout(static_self_cast()); if (client) { client->logout(displayEffect, forced); } else { - g_game().removeCreature(this); + g_game().removeCreature(static_self_cast()); } } -void Player::notifyStatusChange(Player* loginPlayer, VipStatus_t status, bool message) { +void Player::notifyStatusChange(std::shared_ptr loginPlayer, VipStatus_t status, bool message) { if (!client) { return; } @@ -3014,17 +3012,17 @@ bool Player::editVIP(uint32_t vipGuid, const std::string &description, uint32_t } // close container and its child containers -void Player::autoCloseContainers(const Container* container) { +void Player::autoCloseContainers(std::shared_ptr container) { std::vector closeList; for (const auto &it : openContainers) { - Container* tmpContainer = it.second.container; + std::shared_ptr tmpContainer = it.second.container; while (tmpContainer) { if (tmpContainer->isRemoved() || tmpContainer == container) { closeList.push_back(it.first); break; } - tmpContainer = dynamic_cast(tmpContainer->getParent()); + tmpContainer = std::dynamic_pointer_cast(tmpContainer->getParent()); } } @@ -3036,12 +3034,12 @@ void Player::autoCloseContainers(const Container* container) { } } -bool Player::hasCapacity(const Item* item, uint32_t count) const { +bool Player::hasCapacity(std::shared_ptr item, uint32_t count) const { if (hasFlag(PlayerFlags_t::CannotPickupItem)) { return false; } - if (hasFlag(PlayerFlags_t::HasInfiniteCapacity) || item->getTopParent() == this) { + if (hasFlag(PlayerFlags_t::HasInfiniteCapacity) || item->getTopParent().get() == this) { return true; } @@ -3052,8 +3050,8 @@ bool Player::hasCapacity(const Item* item, uint32_t count) const { return itemWeight <= getFreeCapacity(); } -ReturnValue Player::queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature*) const { - const Item* item = thing.getItem(); +ReturnValue Player::queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr) { + std::shared_ptr item = thing->getItem(); if (item == nullptr) { g_logger().error("[Player::queryAdd] - Item is nullptr"); return RETURNVALUE_NOTPOSSIBLE; @@ -3118,7 +3116,7 @@ ReturnValue Player::queryAdd(int32_t index, const Thing &thing, uint32_t count, if (item->getWeaponType() != WEAPON_SHIELD && !item->isQuiver()) { ret = RETURNVALUE_CANNOTBEDRESSED; } else { - const Item* leftItem = inventory[CONST_SLOT_LEFT]; + std::shared_ptr leftItem = inventory[CONST_SLOT_LEFT]; if (leftItem) { if ((leftItem->getSlotPosition() | slotPosition) & SLOTP_TWO_HAND) { if (item->isQuiver() && leftItem->getWeaponType() == WEAPON_DISTANCE) { @@ -3140,7 +3138,7 @@ ReturnValue Player::queryAdd(int32_t index, const Thing &thing, uint32_t count, ret = RETURNVALUE_NOERROR; } } else if (inventory[CONST_SLOT_LEFT]) { - const Item* leftItem = inventory[CONST_SLOT_LEFT]; + std::shared_ptr leftItem = inventory[CONST_SLOT_LEFT]; WeaponType_t type = item->getWeaponType(), leftType = leftItem->getWeaponType(); if (leftItem->getSlotPosition() & SLOTP_TWO_HAND) { @@ -3181,7 +3179,7 @@ ReturnValue Player::queryAdd(int32_t index, const Thing &thing, uint32_t count, ret = RETURNVALUE_NOERROR; } } else if (inventory[CONST_SLOT_RIGHT]) { - const Item* rightItem = inventory[CONST_SLOT_RIGHT]; + std::shared_ptr rightItem = inventory[CONST_SLOT_RIGHT]; WeaponType_t type = item->getWeaponType(), rightType = rightItem->getWeaponType(); if (rightItem->getSlotPosition() & SLOTP_TWO_HAND) { @@ -3241,7 +3239,7 @@ ReturnValue Player::queryAdd(int32_t index, const Thing &thing, uint32_t count, if (ret == RETURNVALUE_NOERROR || ret == RETURNVALUE_NOTENOUGHROOM) { // need an exchange with source? - const Item* inventoryItem = getInventoryItem(static_cast(index)); + std::shared_ptr inventoryItem = getInventoryItem(static_cast(index)); if (inventoryItem && (!inventoryItem->isStackable() || inventoryItem->getID() != item->getID())) { return RETURNVALUE_NEEDEXCHANGE; } @@ -3251,7 +3249,7 @@ ReturnValue Player::queryAdd(int32_t index, const Thing &thing, uint32_t count, return RETURNVALUE_NOTENOUGHCAPACITY; } - if (!g_moveEvents().onPlayerEquip(const_cast(*this), const_cast(*item), static_cast(index), true)) { + if (!g_moveEvents().onPlayerEquip(getPlayer(), item, static_cast(index), true)) { return RETURNVALUE_CANNOTBEDRESSED; } } @@ -3259,8 +3257,8 @@ ReturnValue Player::queryAdd(int32_t index, const Thing &thing, uint32_t count, return ret; } -ReturnValue Player::queryMaxCount(int32_t index, const Thing &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) const { - const Item* item = thing.getItem(); +ReturnValue Player::queryMaxCount(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) { + auto item = thing->getItem(); if (item == nullptr) { maxQueryCount = 0; return RETURNVALUE_NOTPOSSIBLE; @@ -3269,29 +3267,29 @@ ReturnValue Player::queryMaxCount(int32_t index, const Thing &thing, uint32_t co if (index == INDEX_WHEREEVER) { uint32_t n = 0; for (int32_t slotIndex = CONST_SLOT_FIRST; slotIndex <= CONST_SLOT_LAST; ++slotIndex) { - Item* inventoryItem = inventory[slotIndex]; + std::shared_ptr inventoryItem = inventory[slotIndex]; if (inventoryItem) { - if (Container* subContainer = inventoryItem->getContainer()) { + if (std::shared_ptr subContainer = inventoryItem->getContainer()) { uint32_t queryCount = 0; - subContainer->queryMaxCount(INDEX_WHEREEVER, *item, item->getItemCount(), queryCount, flags); + subContainer->queryMaxCount(INDEX_WHEREEVER, item, item->getItemCount(), queryCount, flags); n += queryCount; // iterate through all items, including sub-containers (deep search) for (ContainerIterator it = subContainer->iterator(); it.hasNext(); it.advance()) { - if (Container* tmpContainer = (*it)->getContainer()) { + if (std::shared_ptr tmpContainer = (*it)->getContainer()) { queryCount = 0; - tmpContainer->queryMaxCount(INDEX_WHEREEVER, *item, item->getItemCount(), queryCount, flags); + tmpContainer->queryMaxCount(INDEX_WHEREEVER, item, item->getItemCount(), queryCount, flags); n += queryCount; } } } else if (inventoryItem->isStackable() && item->equals(inventoryItem) && inventoryItem->getItemCount() < inventoryItem->getStackSize()) { uint32_t remainder = (inventoryItem->getStackSize() - inventoryItem->getItemCount()); - if (queryAdd(slotIndex, *item, remainder, flags) == RETURNVALUE_NOERROR) { + if (queryAdd(slotIndex, item, remainder, flags) == RETURNVALUE_NOERROR) { n += remainder; } } - } else if (queryAdd(slotIndex, *item, item->getItemCount(), flags) == RETURNVALUE_NOERROR) { // empty slot + } else if (queryAdd(slotIndex, item, item->getItemCount(), flags) == RETURNVALUE_NOERROR) { // empty slot if (item->isStackable()) { n += item->getStackSize(); } else { @@ -3302,9 +3300,9 @@ ReturnValue Player::queryMaxCount(int32_t index, const Thing &thing, uint32_t co maxQueryCount = n; } else { - const Item* destItem = nullptr; + std::shared_ptr destItem = nullptr; - const Thing* destThing = getThing(index); + std::shared_ptr destThing = getThing(index); if (destThing) { destItem = destThing->getItem(); } @@ -3315,7 +3313,7 @@ ReturnValue Player::queryMaxCount(int32_t index, const Thing &thing, uint32_t co } else { maxQueryCount = 0; } - } else if (queryAdd(index, *item, count, flags) == RETURNVALUE_NOERROR) { // empty slot + } else if (queryAdd(index, item, count, flags) == RETURNVALUE_NOERROR) { // empty slot if (item->isStackable()) { maxQueryCount = item->getStackSize(); } else { @@ -3333,13 +3331,13 @@ ReturnValue Player::queryMaxCount(int32_t index, const Thing &thing, uint32_t co } } -ReturnValue Player::queryRemove(const Thing &thing, uint32_t count, uint32_t flags, Creature* /*= nullptr*/) const { - int32_t index = getThingIndex(&thing); +ReturnValue Player::queryRemove(const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr /*= nullptr*/) { + int32_t index = getThingIndex(thing); if (index == -1) { return RETURNVALUE_NOTPOSSIBLE; } - const Item* item = thing.getItem(); + std::shared_ptr item = thing->getItem(); if (item == nullptr) { return RETURNVALUE_NOTPOSSIBLE; } @@ -3355,22 +3353,22 @@ ReturnValue Player::queryRemove(const Thing &thing, uint32_t count, uint32_t fla return RETURNVALUE_NOERROR; } -Cylinder* Player::queryDestination(int32_t &index, const Thing &thing, Item** destItem, uint32_t &flags) { +std::shared_ptr Player::queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &flags) { if (index == 0 /*drop to capacity window*/ || index == INDEX_WHEREEVER) { *destItem = nullptr; - const Item* item = thing.getItem(); + std::shared_ptr item = thing->getItem(); if (item == nullptr) { - return this; + return getPlayer(); } bool autoStack = !((flags & FLAG_IGNOREAUTOSTACK) == FLAG_IGNOREAUTOSTACK); bool isStackable = item->isStackable(); - std::vector containers; + std::vector> containers; for (uint32_t slotIndex = CONST_SLOT_FIRST; slotIndex <= CONST_SLOT_AMMO; ++slotIndex) { - Item* inventoryItem = inventory[slotIndex]; + std::shared_ptr inventoryItem = inventory[slotIndex]; if (inventoryItem) { if (inventoryItem == tradeItem) { continue; @@ -3382,35 +3380,35 @@ Cylinder* Player::queryDestination(int32_t &index, const Thing &thing, Item** de if (autoStack && isStackable) { // try find an already existing item to stack with - if (queryAdd(slotIndex, *item, item->getItemCount(), 0) == RETURNVALUE_NOERROR) { + if (queryAdd(slotIndex, item, item->getItemCount(), 0) == RETURNVALUE_NOERROR) { if (inventoryItem->equals(item) && inventoryItem->getItemCount() < inventoryItem->getStackSize()) { index = slotIndex; *destItem = inventoryItem; - return this; + return getPlayer(); } } - if (Container* subContainer = inventoryItem->getContainer()) { + if (std::shared_ptr subContainer = inventoryItem->getContainer()) { containers.push_back(subContainer); } - } else if (Container* subContainer = inventoryItem->getContainer()) { + } else if (std::shared_ptr subContainer = inventoryItem->getContainer()) { containers.push_back(subContainer); } - } else if (queryAdd(slotIndex, *item, item->getItemCount(), flags) == RETURNVALUE_NOERROR) { // empty slot + } else if (queryAdd(slotIndex, item, item->getItemCount(), flags) == RETURNVALUE_NOERROR) { // empty slot index = slotIndex; *destItem = nullptr; - return this; + return getPlayer(); } } size_t i = 0; while (i < containers.size()) { - Container* tmpContainer = containers[i++]; + std::shared_ptr tmpContainer = containers[i++]; if (!autoStack || !isStackable) { // we need to find first empty container as fast as we can for non-stackable items uint32_t n = tmpContainer->capacity() - tmpContainer->size(); while (n) { - if (tmpContainer->queryAdd(tmpContainer->capacity() - n, *item, item->getItemCount(), flags) == RETURNVALUE_NOERROR) { + if (tmpContainer->queryAdd(tmpContainer->capacity() - n, item, item->getItemCount(), flags) == RETURNVALUE_NOERROR) { index = tmpContainer->capacity() - n; *destItem = nullptr; return tmpContainer; @@ -3419,8 +3417,8 @@ Cylinder* Player::queryDestination(int32_t &index, const Thing &thing, Item** de n--; } - for (Item* tmpContainerItem : tmpContainer->getItemList()) { - if (Container* subContainer = tmpContainerItem->getContainer()) { + for (std::shared_ptr tmpContainerItem : tmpContainer->getItemList()) { + if (std::shared_ptr subContainer = tmpContainerItem->getContainer()) { containers.push_back(subContainer); } } @@ -3430,7 +3428,7 @@ Cylinder* Player::queryDestination(int32_t &index, const Thing &thing, Item** de uint32_t n = 0; - for (Item* tmpItem : tmpContainer->getItemList()) { + for (std::shared_ptr tmpItem : tmpContainer->getItemList()) { if (tmpItem == tradeItem) { continue; } @@ -3446,46 +3444,46 @@ Cylinder* Player::queryDestination(int32_t &index, const Thing &thing, Item** de return tmpContainer; } - if (Container* subContainer = tmpItem->getContainer()) { + if (std::shared_ptr subContainer = tmpItem->getContainer()) { containers.push_back(subContainer); } n++; } - if (n < tmpContainer->capacity() && tmpContainer->queryAdd(n, *item, item->getItemCount(), flags) == RETURNVALUE_NOERROR) { + if (n < tmpContainer->capacity() && tmpContainer->queryAdd(n, item, item->getItemCount(), flags) == RETURNVALUE_NOERROR) { index = n; *destItem = nullptr; return tmpContainer; } } - return this; + return getPlayer(); } - Thing* destThing = getThing(index); + std::shared_ptr destThing = getThing(index); if (destThing) { *destItem = destThing->getItem(); } - const Item* item = thing.getItem(); + std::shared_ptr item = thing->getItem(); bool movingAmmoToQuiver = item && *destItem && (*destItem)->isQuiver() && item->isAmmo(); // force shield any slot right to player cylinder if (index == CONST_SLOT_RIGHT && !movingAmmoToQuiver) { - return this; + return getPlayer(); } - Cylinder* subCylinder = dynamic_cast(destThing); + std::shared_ptr subCylinder = std::dynamic_pointer_cast(destThing); if (subCylinder) { index = INDEX_WHEREEVER; *destItem = nullptr; return subCylinder; } else { - return this; + return getPlayer(); } } -void Player::addThing(int32_t index, Thing* thing) { +void Player::addThing(int32_t index, std::shared_ptr thing) { if (!thing) { return /*RETURNVALUE_NOTPOSSIBLE*/; } @@ -3494,25 +3492,25 @@ void Player::addThing(int32_t index, Thing* thing) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - item->setParent(this); + item->setParent(static_self_cast()); inventory[index] = item; // send to client sendInventoryItem(static_cast(index), item); } -void Player::updateThing(Thing* thing, uint16_t itemId, uint32_t count) { +void Player::updateThing(std::shared_ptr thing, uint16_t itemId, uint32_t count) { int32_t index = getThingIndex(thing); if (index == -1) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item) { return /*RETURNVALUE_NOTPOSSIBLE*/; } @@ -3527,17 +3525,17 @@ void Player::updateThing(Thing* thing, uint16_t itemId, uint32_t count) { onUpdateInventoryItem(item, item); } -void Player::replaceThing(uint32_t index, Thing* thing) { +void Player::replaceThing(uint32_t index, std::shared_ptr thing) { if (index > CONST_SLOT_LAST) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - Item* oldItem = getInventoryItem(static_cast(index)); + std::shared_ptr oldItem = getInventoryItem(static_cast(index)); if (!oldItem) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item) { return /*RETURNVALUE_NOTPOSSIBLE*/; } @@ -3548,13 +3546,13 @@ void Player::replaceThing(uint32_t index, Thing* thing) { // event methods onUpdateInventoryItem(oldItem, item); - item->setParent(this); + item->setParent(static_self_cast()); inventory[index] = item; } -void Player::removeThing(Thing* thing, uint32_t count) { - Item* item = thing->getItem(); +void Player::removeThing(std::shared_ptr thing, uint32_t count) { + std::shared_ptr item = thing->getItem(); if (!item) { return /*RETURNVALUE_NOTPOSSIBLE*/; } @@ -3596,7 +3594,7 @@ void Player::removeThing(Thing* thing, uint32_t count) { } } -int32_t Player::getThingIndex(const Thing* thing) const { +int32_t Player::getThingIndex(std::shared_ptr thing) const { for (uint8_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; ++i) { if (inventory[i] == thing) { return i; @@ -3616,7 +3614,7 @@ size_t Player::getLastIndex() const { uint32_t Player::getItemTypeCount(uint16_t itemId, int32_t subType /*= -1*/) const { uint32_t count = 0; for (int32_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; i++) { - Item* item = inventory[i]; + std::shared_ptr item = inventory[i]; if (!item) { continue; } @@ -3625,7 +3623,7 @@ uint32_t Player::getItemTypeCount(uint16_t itemId, int32_t subType /*= -1*/) con count += Item::countByType(item, subType); } - if (Container* container = item->getContainer()) { + if (std::shared_ptr container = item->getContainer()) { for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { if ((*it)->getID() == itemId) { count += Item::countByType(*it, subType); @@ -3651,7 +3649,7 @@ void Player::stashContainer(StashContainerList itemDict) { } if (getStashSize(stashItemDict) > g_configManager().getNumber(STASH_ITEMS)) { - sendCancelMessage("You don't have capacity in the Supply Stash to stow all this item."); + sendCancelMessage("You don't have capacity in the Supply Stash to stow all this item->"); return; } @@ -3692,11 +3690,11 @@ bool Player::removeItemOfType(uint16_t itemId, uint32_t amount, int32_t subType, return true; } - std::vector itemList; + std::vector> itemList; uint32_t count = 0; for (int32_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; i++) { - Item* item = inventory[i]; + std::shared_ptr item = inventory[i]; if (!item) { continue; } @@ -3714,9 +3712,9 @@ bool Player::removeItemOfType(uint16_t itemId, uint32_t amount, int32_t subType, g_game().internalRemoveItems(std::move(itemList), amount, Item::items[itemId].stackable); return true; } - } else if (Container* container = item->getContainer()) { + } else if (std::shared_ptr container = item->getContainer()) { for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { - Item* containerItem = *it; + std::shared_ptr containerItem = *it; if (containerItem->getID() == itemId) { uint32_t itemCount = Item::countByType(containerItem, subType); if (itemCount == 0) { @@ -3744,7 +3742,7 @@ bool Player::removeItemOfType(uint16_t itemId, uint32_t amount, int32_t subType, bool Player::hasItemCountById(uint16_t itemId, uint32_t itemAmount, bool checkStash) const { uint32_t newCount = 0; // Check items from inventory - for (const auto* item : getAllInventoryItems()) { + for (const auto item : getAllInventoryItems()) { if (!item || item->getID() != itemId) { continue; } @@ -3775,7 +3773,7 @@ bool Player::removeItemCountById(uint16_t itemId, uint32_t itemAmount, bool remo uint32_t amountToRemove = itemAmount; // Check items from inventory - for (auto* item : getAllInventoryItems()) { + for (auto item : getAllInventoryItems()) { if (!item || item->getID() != itemId) { continue; } @@ -3802,13 +3800,13 @@ bool Player::removeItemCountById(uint16_t itemId, uint32_t itemAmount, bool remo ItemsTierCountList Player::getInventoryItemsId() const { ItemsTierCountList itemMap; for (int32_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; i++) { - Item* item = inventory[i]; + std::shared_ptr item = inventory[i]; if (!item) { continue; } (itemMap[item->getID()])[item->getTier()] += Item::countByType(item, -1); - if (Container* container = item->getContainer()) { + if (std::shared_ptr container = item->getContainer()) { for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { auto containerItem = *it; (itemMap[containerItem->getID()])[containerItem->getTier()] += Item::countByType(containerItem, -1); @@ -3818,10 +3816,10 @@ ItemsTierCountList Player::getInventoryItemsId() const { return itemMap; } -std::vector Player::getInventoryItemsFromId(uint16_t itemId, bool ignore /*= true*/) const { - std::vector itemVector; +std::vector> Player::getInventoryItemsFromId(uint16_t itemId, bool ignore /*= true*/) const { + std::vector> itemVector; for (int i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; ++i) { - Item* item = inventory[i]; + std::shared_ptr item = inventory[i]; if (!item) { continue; } @@ -3830,7 +3828,7 @@ std::vector Player::getInventoryItemsFromId(uint16_t itemId, bool ignore itemVector.push_back(item); } - if (Container* container = item->getContainer()) { + if (std::shared_ptr container = item->getContainer()) { for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { auto containerItem = *it; if (containerItem->getID() == itemId) { @@ -3859,14 +3857,14 @@ std::array Player::getFinalDamageReduction() const { void Player::calculateDamageReductionFromEquipedItems(std::array &combatReductionArray) const { for (uint8_t slot = CONST_SLOT_FIRST; slot <= CONST_SLOT_LAST; ++slot) { - Item* item = inventory[slot]; + std::shared_ptr item = inventory[slot]; if (item) { calculateDamageReductionFromItem(combatReductionArray, item); } } } -void Player::calculateDamageReductionFromItem(std::array &combatReductionArray, Item* item) const { +void Player::calculateDamageReductionFromItem(std::array &combatReductionArray, std::shared_ptr item) const { for (uint16_t combatTypeIndex = 0; combatTypeIndex < COMBAT_COUNT; combatTypeIndex++) { updateDamageReductionFromItemImbuement(combatReductionArray, item, combatTypeIndex); updateDamageReductionFromItemAbility(combatReductionArray, item, combatTypeIndex); @@ -3874,7 +3872,7 @@ void Player::calculateDamageReductionFromItem(std::array } void Player::updateDamageReductionFromItemImbuement( - std::array &combatReductionArray, Item* item, uint16_t combatTypeIndex + std::array &combatReductionArray, std::shared_ptr item, uint16_t combatTypeIndex ) const { for (uint8_t imbueSlotId = 0; imbueSlotId < item->getImbuementSlot(); imbueSlotId++) { ImbuementInfo imbuementInfo; @@ -3888,7 +3886,7 @@ void Player::updateDamageReductionFromItemImbuement( } void Player::updateDamageReductionFromItemAbility( - std::array &combatReductionArray, const Item* item, uint16_t combatTypeIndex + std::array &combatReductionArray, std::shared_ptr item, uint16_t combatTypeIndex ) const { if (!item) { return; @@ -3907,10 +3905,10 @@ double_t Player::calculateDamageReduction(double_t currentTotal, int16_t resista return (100 - currentTotal) / 100.0 * resistance + currentTotal; } -std::vector Player::getAllInventoryItems(bool ignoreEquiped /*= false*/, bool ignoreItemWithTier /* false*/) const { - std::vector itemVector; +std::vector> Player::getAllInventoryItems(bool ignoreEquiped /*= false*/, bool ignoreItemWithTier /* false*/) const { + std::vector> itemVector; for (int i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; ++i) { - Item* item = inventory[i]; + std::shared_ptr item = inventory[i]; if (!item) { continue; } @@ -3919,7 +3917,7 @@ std::vector Player::getAllInventoryItems(bool ignoreEquiped /*= false*/, if (!ignoreEquiped) { itemVector.push_back(item); } - if (Container* container = item->getContainer()) { + if (std::shared_ptr container = item->getContainer()) { for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { if (ignoreItemWithTier && (*it)->getTier() > 0) { continue; @@ -3933,7 +3931,7 @@ std::vector Player::getAllInventoryItems(bool ignoreEquiped /*= false*/, return itemVector; } -std::vector Player::getEquippedItems() const { +std::vector> Player::getEquippedItems() const { std::vector valid_slots { CONST_SLOT_HEAD, CONST_SLOT_NECKLACE, @@ -3946,9 +3944,9 @@ std::vector Player::getEquippedItems() const { CONST_SLOT_RING, }; - std::vector valid_items; + std::vector> valid_items; for (const auto &slot : valid_slots) { - Item* item = inventory[slot]; + std::shared_ptr item = inventory[slot]; if (!item) { continue; } @@ -3987,7 +3985,7 @@ void Player::getAllItemTypeCountAndSubtype(std::map &countMa } } -Item* Player::getForgeItemFromId(uint16_t itemId, uint8_t tier) { +std::shared_ptr Player::getForgeItemFromId(uint16_t itemId, uint8_t tier) { for (auto item : getAllInventoryItems(true)) { if (item->hasImbuements()) { continue; @@ -4001,32 +3999,32 @@ Item* Player::getForgeItemFromId(uint16_t itemId, uint8_t tier) { return nullptr; } -Thing* Player::getThing(size_t index) const { +std::shared_ptr Player::getThing(size_t index) const { if (index >= CONST_SLOT_FIRST && index <= CONST_SLOT_LAST) { return inventory[index]; } return nullptr; } -void Player::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link /*= LINK_OWNER*/) { +void Player::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link /*= LINK_OWNER*/) { if (link == LINK_OWNER) { // calling movement scripts - g_moveEvents().onPlayerEquip(*this, *thing->getItem(), static_cast(index), false); + g_moveEvents().onPlayerEquip(getPlayer(), thing->getItem(), static_cast(index), false); } bool requireListUpdate = true; if (link == LINK_OWNER || link == LINK_TOPPARENT) { - const Item* i = (oldParent ? oldParent->getItem() : nullptr); + std::shared_ptr i = (oldParent ? oldParent->getItem() : nullptr); // Check if we owned the old container too, so we don't need to do anything, // as the list was updated in postRemoveNotification assert(i ? i->getContainer() != nullptr : true); if (i) { - requireListUpdate = i->getContainer()->getHoldingPlayer() != this; + requireListUpdate = i->getContainer()->getHoldingPlayer() != getPlayer(); } else { - requireListUpdate = oldParent != this; + requireListUpdate = oldParent != getPlayer(); } updateInventoryWeight(); @@ -4035,21 +4033,21 @@ void Player::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_ sendStats(); } - if (const Item* item = thing->getItem()) { - if (const Container* container = item->getContainer()) { + if (std::shared_ptr item = thing->getItem()) { + if (std::shared_ptr container = item->getContainer()) { onSendContainer(container); } if (shopOwner && !scheduledSaleUpdate && requireListUpdate) { updateSaleShopList(item); } - } else if (const Creature* creature = thing->getCreature()) { - if (creature == this) { + } else if (std::shared_ptr creature = thing->getCreature()) { + if (creature == getPlayer()) { // check containers - std::vector containers; + std::vector> containers; for (const auto &it : openContainers) { - Container* container = it.second.container; + std::shared_ptr container = it.second.container; if (container == nullptr) { continue; } @@ -4059,32 +4057,32 @@ void Player::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_ } } - for (const Container* container : containers) { + for (std::shared_ptr container : containers) { autoCloseContainers(container); } } } } -void Player::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link /*= LINK_OWNER*/) { +void Player::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link /*= LINK_OWNER*/) { if (link == LINK_OWNER) { // calling movement scripts - g_moveEvents().onPlayerDeEquip(*this, *thing->getItem(), static_cast(index)); + g_moveEvents().onPlayerDeEquip(getPlayer(), thing->getItem(), static_cast(index)); } bool requireListUpdate = true; if (link == LINK_OWNER || link == LINK_TOPPARENT) { - const Item* i = (newParent ? newParent->getItem() : nullptr); + std::shared_ptr i = (newParent ? newParent->getItem() : nullptr); // Check if we owned the old container too, so we don't need to do anything, // as the list was updated in postRemoveNotification assert(i ? i->getContainer() != nullptr : true); if (i) { - requireListUpdate = i->getContainer()->getHoldingPlayer() != this; + requireListUpdate = i->getContainer()->getHoldingPlayer() != getPlayer(); } else { - requireListUpdate = newParent != this; + requireListUpdate = newParent != getPlayer(); } updateInventoryWeight(); @@ -4093,16 +4091,16 @@ void Player::postRemoveNotification(Thing* thing, const Cylinder* newParent, int sendStats(); } - if (const Item* item = thing->getItem()) { - if (const Container* container = item->getContainer()) { + if (std::shared_ptr item = thing->getItem()) { + if (std::shared_ptr container = item->getContainer()) { checkLootContainers(container); if (container->isRemoved() || !Position::areInRange<1, 1, 0>(getPosition(), container->getPosition())) { autoCloseContainers(container); - } else if (container->getTopParent() == this) { + } else if (container->getTopParent() == getPlayer()) { onSendContainer(container); - } else if (const Container* topContainer = dynamic_cast(container->getTopParent())) { - if (const DepotChest* depotChest = dynamic_cast(topContainer)) { + } else if (std::shared_ptr topContainer = std::dynamic_pointer_cast(container->getTopParent())) { + if (std::shared_ptr depotChest = std::dynamic_pointer_cast(topContainer)) { bool isOwner = false; for (const auto &it : depotChests) { @@ -4136,7 +4134,7 @@ void Player::postRemoveNotification(Thing* thing, const Cylinder* newParent, int } // i will keep this function so it can be reviewed -bool Player::updateSaleShopList(const Item* item) { +bool Player::updateSaleShopList(std::shared_ptr item) { uint16_t itemId = item->getID(); if (!itemId || !item) { return true; @@ -4159,16 +4157,16 @@ bool Player::hasShopItemForSale(uint16_t itemId, uint8_t subType) const { }); } -void Player::internalAddThing(Thing* thing) { +void Player::internalAddThing(std::shared_ptr thing) { internalAddThing(0, thing); } -void Player::internalAddThing(uint32_t index, Thing* thing) { +void Player::internalAddThing(uint32_t index, std::shared_ptr thing) { if (!thing) { return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item) { return; } @@ -4180,11 +4178,11 @@ void Player::internalAddThing(uint32_t index, Thing* thing) { } inventory[index] = item; - item->setParent(this); + item->setParent(static_self_cast()); } } -bool Player::setFollowCreature(Creature* creature) { +bool Player::setFollowCreature(std::shared_ptr creature) { if (!Creature::setFollowCreature(creature)) { setFollowCreature(nullptr); setAttackedCreature(nullptr); @@ -4197,7 +4195,7 @@ bool Player::setFollowCreature(Creature* creature) { return true; } -bool Player::setAttackedCreature(Creature* creature) { +bool Player::setAttackedCreature(std::shared_ptr creature) { if (!Creature::setAttackedCreature(creature)) { sendCancelTarget(); return false; @@ -4232,7 +4230,7 @@ void Player::goToFollowCreature() { } } -void Player::getPathSearchParams(const Creature* creature, FindPathParams &fpp) const { +void Player::getPathSearchParams(std::shared_ptr creature, FindPathParams &fpp) { Creature::getPathSearchParams(creature, fpp); fpp.fullPathSearch = true; } @@ -4249,23 +4247,23 @@ void Player::doAttacking(uint32_t) { if ((OTSYS_TIME() - lastAttack) >= getAttackSpeed()) { bool result = false; - Item* tool = getWeapon(); + std::shared_ptr tool = getWeapon(); const Weapon* weapon = g_weapons().getWeapon(tool); uint32_t delay = getAttackSpeed(); bool classicSpeed = g_configManager().getBoolean(CLASSIC_ATTACK_SPEED); if (weapon) { if (!weapon->interruptSwing()) { - result = weapon->useWeapon(this, tool, attackedCreature); + result = weapon->useWeapon(static_self_cast(), tool, attackedCreature); } else if (!classicSpeed && !canDoAction()) { delay = getNextActionTime(); } else { - result = weapon->useWeapon(this, tool, attackedCreature); + result = weapon->useWeapon(static_self_cast(), tool, attackedCreature); } } else if (hasWeaponDistanceEquipped()) { return; } else { - result = Weapon::useFist(this, attackedCreature); + result = Weapon::useFist(static_self_cast(), attackedCreature); } std::shared_ptr task = createPlayerTask(std::max(SCHEDULER_MINTICKS, delay), std::bind(&Game::checkCreatureAttack, &g_game(), getID()), "Game::checkCreatureAttack"); @@ -4281,17 +4279,17 @@ void Player::doAttacking(uint32_t) { } } -uint64_t Player::getGainedExperience(Creature* attacker) const { +uint64_t Player::getGainedExperience(std::shared_ptr attacker) const { if (g_configManager().getBoolean(EXPERIENCE_FROM_PLAYERS)) { - Player* attackerPlayer = attacker->getPlayer(); - if (attackerPlayer && attackerPlayer != this && skillLoss && std::abs(static_cast(attackerPlayer->getLevel() - level)) <= g_configManager().getNumber(EXP_FROM_PLAYERS_LEVEL_RANGE)) { + auto attackerPlayer = attacker->getPlayer(); + if (attackerPlayer && attackerPlayer.get() != this && skillLoss && std::abs(static_cast(attackerPlayer->getLevel() - level)) <= g_configManager().getNumber(EXP_FROM_PLAYERS_LEVEL_RANGE)) { return std::max(0, std::floor(getLostExperience() * getDamageRatio(attacker) * 0.75)); } } return 0; } -void Player::onFollowCreature(const Creature* creature) { +void Player::onFollowCreature(std::shared_ptr creature) { if (!creature) { stopWalk(); } @@ -4329,7 +4327,7 @@ void Player::onWalkComplete() { g_logger().debug("[Player::onWalkComplete] Executing feared conditions as players completed it's walk."); Condition* f = getCondition(CONDITION_FEARED); - f->executeCondition(this, 0); + f->executeCondition(static_self_cast(), 0); } if (walkTask) { @@ -4353,7 +4351,7 @@ void Player::updateItemsLight(bool internal /*=false*/) { LightInfo maxLight; for (int32_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; ++i) { - Item* item = inventory[i]; + std::shared_ptr item = inventory[i]; if (item) { LightInfo curLight = item->getLightInfo(); @@ -4367,7 +4365,7 @@ void Player::updateItemsLight(bool internal /*=false*/) { itemsLight = maxLight; if (!internal) { - g_game().changeLight(this); + g_game().changeLight(static_self_cast()); } } } @@ -4458,7 +4456,7 @@ void Player::onCombatRemoveCondition(Condition* condition) { if (condition->getId() > 0) { // Means the condition is from an item, id == slot if (g_game().getWorldType() == WORLD_TYPE_PVP_ENFORCED) { - Item* item = getInventoryItem(static_cast(condition->getId())); + std::shared_ptr item = getInventoryItem(static_cast(condition->getId())); if (item) { // 25% chance to destroy the item if (25 >= uniform_random(1, 100)) { @@ -4481,14 +4479,14 @@ void Player::onCombatRemoveCondition(Condition* condition) { } } -void Player::onAttackedCreature(Creature* target) { +void Player::onAttackedCreature(std::shared_ptr target) { Creature::onAttackedCreature(target); if (target->getZoneType() == ZONE_PVP) { return; } - if (target == this) { + if (target == getPlayer()) { addInFightTicks(); return; } @@ -4497,7 +4495,7 @@ void Player::onAttackedCreature(Creature* target) { return; } - Player* targetPlayer = target->getPlayer(); + auto targetPlayer = target->getPlayer(); if (targetPlayer && !isPartner(targetPlayer) && !isGuildMate(targetPlayer)) { if (!pzLocked && g_game().getWorldType() == WORLD_TYPE_PVP_ENFORCED) { pzLocked = true; @@ -4506,22 +4504,22 @@ void Player::onAttackedCreature(Creature* target) { if (getSkull() == SKULL_NONE && getSkullClient(targetPlayer) == SKULL_YELLOW) { addAttacked(targetPlayer); - targetPlayer->sendCreatureSkull(this); - } else if (!targetPlayer->hasAttacked(this)) { + targetPlayer->sendCreatureSkull(static_self_cast()); + } else if (!targetPlayer->hasAttacked(static_self_cast())) { if (!pzLocked) { pzLocked = true; sendIcons(); } - if (!Combat::isInPvpZone(this, targetPlayer) && !isInWar(targetPlayer)) { + if (!Combat::isInPvpZone(static_self_cast(), targetPlayer) && !isInWar(targetPlayer)) { addAttacked(targetPlayer); - if (targetPlayer->getSkull() == SKULL_NONE && getSkull() == SKULL_NONE && !targetPlayer->hasKilled(this)) { + if (targetPlayer->getSkull() == SKULL_NONE && getSkull() == SKULL_NONE && !targetPlayer->hasKilled(static_self_cast())) { setSkull(SKULL_WHITE); } if (getSkull() == SKULL_NONE) { - targetPlayer->sendCreatureSkull(this); + targetPlayer->sendCreatureSkull(static_self_cast()); } } } @@ -4540,52 +4538,52 @@ void Player::onIdleStatus() { Creature::onIdleStatus(); if (party) { - party->clearPlayerPoints(this); + party->clearPlayerPoints(static_self_cast()); } } void Player::onPlacedCreature() { // scripting event - onLogin - if (!g_creatureEvents().playerLogin(this)) { + if (!g_creatureEvents().playerLogin(static_self_cast())) { removePlayer(true); } sendUnjustifiedPoints(); } -void Player::onAttackedCreatureDrainHealth(Creature* target, int32_t points) { +void Player::onAttackedCreatureDrainHealth(std::shared_ptr target, int32_t points) { Creature::onAttackedCreatureDrainHealth(target, points); if (target) { if (party && !Combat::isPlayerCombat(target)) { - Monster* tmpMonster = target->getMonster(); + auto tmpMonster = target->getMonster(); if (tmpMonster && tmpMonster->isHostile()) { // We have fulfilled a requirement for shared experience - party->updatePlayerTicks(this, points); + party->updatePlayerTicks(static_self_cast(), points); } } } } -void Player::onTargetCreatureGainHealth(Creature* target, int32_t points) { +void Player::onTargetCreatureGainHealth(std::shared_ptr target, int32_t points) { if (target && party) { - Player* tmpPlayer = nullptr; + std::shared_ptr tmpPlayer = nullptr; - if (isPartner(tmpPlayer) && (tmpPlayer != this)) { + if (isPartner(tmpPlayer) && (tmpPlayer != getPlayer())) { tmpPlayer = target->getPlayer(); - } else if (Creature* targetMaster = target->getMaster()) { - if (Player* targetMasterPlayer = targetMaster->getPlayer()) { + } else if (std::shared_ptr targetMaster = target->getMaster()) { + if (std::shared_ptr targetMasterPlayer = targetMaster->getPlayer()) { tmpPlayer = targetMasterPlayer; } } if (isPartner(tmpPlayer)) { - party->updatePlayerTicks(this, points); + party->updatePlayerTicks(static_self_cast(), points); } } } -bool Player::onKilledCreature(Creature* target, bool lastHit /* = true*/) { +bool Player::onKilledCreature(std::shared_ptr target, bool lastHit /* = true*/) { bool unjustified = false; if (hasFlag(PlayerFlags_t::NotGenerateLoot)) { @@ -4594,13 +4592,13 @@ bool Player::onKilledCreature(Creature* target, bool lastHit /* = true*/) { Creature::onKilledCreature(target, lastHit); - if (Player* targetPlayer = target->getPlayer()) { + if (auto targetPlayer = target->getPlayer()) { if (targetPlayer && targetPlayer->getZoneType() == ZONE_PVP) { targetPlayer->setDropLoot(false); targetPlayer->setSkillLoss(false); } else if (!hasFlag(PlayerFlags_t::NotGainInFight) && !isPartner(targetPlayer)) { - if (!Combat::isInPvpZone(this, targetPlayer) && hasAttacked(targetPlayer) && !targetPlayer->hasAttacked(this) && !isGuildMate(targetPlayer) && targetPlayer != this) { - if (targetPlayer->hasKilled(this)) { + if (!Combat::isInPvpZone(getPlayer(), targetPlayer) && hasAttacked(targetPlayer) && !targetPlayer->hasAttacked(getPlayer()) && !isGuildMate(targetPlayer) && targetPlayer != getPlayer()) { + if (targetPlayer->hasKilled(getPlayer())) { for (auto &kill : targetPlayer->unjustifiedKills) { if (kill.target == getGUID() && kill.unavenged) { kill.unavenged = false; @@ -4621,7 +4619,7 @@ bool Player::onKilledCreature(Creature* target, bool lastHit /* = true*/) { } } } - } else if (const Monster* monster = target->getMonster()) { + } else if (std::shared_ptr monster = target->getMonster()) { // Access to the monster's map damage to check if the player attacked it for (auto [playerId, damage] : monster->getDamageMap()) { auto damagePlayer = g_game().getPlayerByID(playerId); @@ -4632,7 +4630,7 @@ bool Player::onKilledCreature(Creature* target, bool lastHit /* = true*/) { // If the player is not in a party and sharing exp active and enabled // And it's not the player killing the creature, then we ignore everything else auto damageParty = damagePlayer->getParty(); - if (this->getID() != damagePlayer->getID() && (!damageParty || !damageParty->isSharedExperienceActive() || !damageParty->isSharedExperienceEnabled())) { + if (static_self_cast()->getID() != damagePlayer->getID() && (!damageParty || !damageParty->isSharedExperienceActive() || !damageParty->isSharedExperienceEnabled())) { continue; } @@ -4656,7 +4654,7 @@ bool Player::onKilledCreature(Creature* target, bool lastHit /* = true*/) { return unjustified; } -void Player::gainExperience(uint64_t gainExp, Creature* target) { +void Player::gainExperience(uint64_t gainExp, std::shared_ptr target) { if (hasFlag(PlayerFlags_t::NotGainExperience) || gainExp == 0 || staminaMinutes == 0) { return; } @@ -4664,7 +4662,7 @@ void Player::gainExperience(uint64_t gainExp, Creature* target) { addExperience(target, gainExp, true); } -void Player::onGainExperience(uint64_t gainExp, Creature* target) { +void Player::onGainExperience(uint64_t gainExp, std::shared_ptr target) { if (hasFlag(PlayerFlags_t::NotGainExperience)) { return; } @@ -4679,7 +4677,7 @@ void Player::onGainExperience(uint64_t gainExp, Creature* target) { gainExperience(gainExp, target); } -void Player::onGainSharedExperience(uint64_t gainExp, Creature* target) { +void Player::onGainSharedExperience(uint64_t gainExp, std::shared_ptr target) { gainExperience(gainExp, target); } @@ -4702,7 +4700,7 @@ bool Player::isAttackable() const { return !hasFlag(PlayerFlags_t::CannotBeAttacked); } -bool Player::lastHitIsPlayer(Creature* lastHitCreature) { +bool Player::lastHitIsPlayer(std::shared_ptr lastHitCreature) { if (!lastHitCreature) { return false; } @@ -4711,7 +4709,7 @@ bool Player::lastHitIsPlayer(Creature* lastHitCreature) { return true; } - Creature* lastHitMaster = lastHitCreature->getMaster(); + std::shared_ptr lastHitMaster = lastHitCreature->getMaster(); return lastHitMaster && lastHitMaster->getPlayer(); } @@ -4724,7 +4722,7 @@ void Player::changeMana(int32_t manaChange) { if (!hasFlag(PlayerFlags_t::HasInfiniteMana)) { Creature::changeMana(manaChange); } - g_game().addPlayerMana(this); + g_game().addPlayerMana(static_self_cast()); sendStats(); } @@ -4947,14 +4945,14 @@ Skulls_t Player::getSkull() const { return skull; } -Skulls_t Player::getSkullClient(const Creature* creature) const { +Skulls_t Player::getSkullClient(std::shared_ptr creature) { if (!creature || g_game().getWorldType() != WORLD_TYPE_PVP) { return SKULL_NONE; } - const Player* player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player && player->getSkull() == SKULL_NONE) { - if (player == this) { + if (player.get() == this) { for (const auto &kill : unjustifiedKills) { if (kill.unavenged && (time(nullptr) - kill.time) < g_configManager().getNumber(ORANGE_SKULL_DURATION) * 24 * 60 * 60) { return SKULL_ORANGE; @@ -4962,11 +4960,11 @@ Skulls_t Player::getSkullClient(const Creature* creature) const { } } - if (player->hasKilled(this)) { + if (player->hasKilled(getPlayer())) { return SKULL_ORANGE; } - if (player->hasAttacked(this)) { + if (player->hasAttacked(getPlayer())) { return SKULL_YELLOW; } @@ -4977,7 +4975,7 @@ Skulls_t Player::getSkullClient(const Creature* creature) const { return Creature::getSkullClient(creature); } -bool Player::hasKilled(const Player* player) const { +bool Player::hasKilled(std::shared_ptr player) const { for (const auto &kill : unjustifiedKills) { if (kill.target == player->getGUID() && (time(nullptr) - kill.time) < g_configManager().getNumber(ORANGE_SKULL_DURATION) * 24 * 60 * 60 && kill.unavenged) { return true; @@ -4987,7 +4985,7 @@ bool Player::hasKilled(const Player* player) const { return false; } -bool Player::hasAttacked(const Player* attacked) const { +bool Player::hasAttacked(std::shared_ptr attacked) const { if (hasFlag(PlayerFlags_t::NotGainInFight) || !attacked) { return false; } @@ -4995,16 +4993,16 @@ bool Player::hasAttacked(const Player* attacked) const { return attackedSet.find(attacked->guid) != attackedSet.end(); } -void Player::addAttacked(const Player* attacked) { - if (hasFlag(PlayerFlags_t::NotGainInFight) || !attacked || attacked == this) { +void Player::addAttacked(std::shared_ptr attacked) { + if (hasFlag(PlayerFlags_t::NotGainInFight) || !attacked || attacked == getPlayer()) { return; } attackedSet.insert(attacked->guid); } -void Player::removeAttacked(const Player* attacked) { - if (!attacked || attacked == this) { +void Player::removeAttacked(std::shared_ptr attacked) { + if (!attacked || attacked == getPlayer()) { return; } @@ -5018,8 +5016,8 @@ void Player::clearAttacked() { attackedSet.clear(); } -void Player::addUnjustifiedDead(const Player* attacked) { - if (hasFlag(PlayerFlags_t::NotGainInFight) || attacked == this || g_game().getWorldType() == WORLD_TYPE_PVP_ENFORCED) { +void Player::addUnjustifiedDead(std::shared_ptr attacked) { + if (hasFlag(PlayerFlags_t::NotGainInFight) || attacked == getPlayer() || g_game().getWorldType() == WORLD_TYPE_PVP_ENFORCED) { return; } @@ -5140,7 +5138,7 @@ bool Player::hasLearnedInstantSpell(const std::string &spellName) const { return false; } -bool Player::isInWar(const Player* player) const { +bool Player::isInWar(std::shared_ptr player) const { if (!player || !guild) { return false; } @@ -5419,7 +5417,7 @@ void Player::setTransferableTibiaCoins(int32_t v) { coinTransferableBalance = v; } -PartyShields_t Player::getPartyShield(const Player* player) const { +PartyShields_t Player::getPartyShield(std::shared_ptr player) { if (!player) { return SHIELD_NONE; } @@ -5462,7 +5460,7 @@ PartyShields_t Player::getPartyShield(const Player* player) const { } } - if (player->isInviting(this)) { + if (player->isInviting(getPlayer())) { return SHIELD_WHITEYELLOW; } @@ -5473,28 +5471,28 @@ PartyShields_t Player::getPartyShield(const Player* player) const { return SHIELD_NONE; } -bool Player::isInviting(const Player* player) const { - if (!player || !party || party->getLeader() != this) { +bool Player::isInviting(std::shared_ptr player) const { + if (!player || !party || party->getLeader().get() != this) { return false; } return party->isPlayerInvited(player); } -bool Player::isPartner(const Player* player) const { - if (!player || !party || player == this) { +bool Player::isPartner(std::shared_ptr player) const { + if (!player || !party || player.get() == this) { return false; } return party == player->party; } -bool Player::isGuildMate(const Player* player) const { +bool Player::isGuildMate(std::shared_ptr player) const { if (!player || !guild) { return false; } return guild == player->guild; } -void Player::sendPlayerPartyIcons(Player* player) { +void Player::sendPlayerPartyIcons(std::shared_ptr player) { sendPartyCreatureShield(player); sendPartyCreatureSkull(player); } @@ -5515,12 +5513,12 @@ void Player::removePartyInvitation(Party* remParty) { void Player::clearPartyInvitations() { for (Party* invitingParty : invitePartyList) { - invitingParty->removeInvite(*this, false); + invitingParty->removeInvite(getPlayer(), false); } invitePartyList.clear(); } -GuildEmblems_t Player::getGuildEmblem(const Player* player) const { +GuildEmblems_t Player::getGuildEmblem(std::shared_ptr player) const { if (!player) { return GUILDEMBLEM_NONE; } @@ -5673,7 +5671,7 @@ bool Player::toggleMount(bool mount) { setCurrentMount(currentMount->id); if (currentMount->speed != 0) { - g_game().changeSpeed(this, currentMount->speed); + g_game().changeSpeed(static_self_cast(), currentMount->speed); } } else { if (!isMounted()) { @@ -5683,7 +5681,7 @@ bool Player::toggleMount(bool mount) { dismount(); } - g_game().internalCreatureChangeOutfit(this, defaultOutfit); + g_game().internalCreatureChangeOutfit(static_self_cast(), defaultOutfit); lastToggleMount = OTSYS_TIME(); return true; } @@ -5726,7 +5724,7 @@ bool Player::untameMount(uint8_t mountId) { if (getCurrentMount() == mountId) { if (isMounted()) { dismount(); - g_game().internalCreatureChangeOutfit(this, defaultOutfit); + g_game().internalCreatureChangeOutfit(static_self_cast(), defaultOutfit); } setCurrentMount(0); @@ -5757,7 +5755,7 @@ bool Player::hasMount(const std::shared_ptr mount) const { void Player::dismount() { const auto mount = g_game().mounts.getMountByID(getCurrentMount()); if (mount && mount->speed > 0) { - g_game().changeSpeed(this, -mount->speed); + g_game().changeSpeed(static_self_cast(), -mount->speed); } defaultOutfit.lookMount = 0; @@ -5783,8 +5781,8 @@ bool Player::addOfflineTrainingTries(skills_t skill, uint64_t tries) { oldSkillValue = magLevel; oldPercentToNextLevel = static_cast(manaSpent * 100) / nextReqMana; - g_events().eventPlayerOnGainSkillTries(this, SKILL_MAGLEVEL, tries); - g_callbacks().executeCallback(EventCallback_t::playerOnGainSkillTries, &EventCallback::playerOnGainSkillTries, this, SKILL_MAGLEVEL, tries); + g_events().eventPlayerOnGainSkillTries(static_self_cast(), SKILL_MAGLEVEL, tries); + g_callbacks().executeCallback(EventCallback_t::playerOnGainSkillTries, &EventCallback::playerOnGainSkillTries, getPlayer(), SKILL_MAGLEVEL, tries); uint32_t currMagLevel = magLevel; while ((manaSpent + tries) >= nextReqMana) { @@ -5793,7 +5791,7 @@ bool Player::addOfflineTrainingTries(skills_t skill, uint64_t tries) { magLevel++; manaSpent = 0; - g_creatureEvents().playerAdvance(this, SKILL_MAGLEVEL, magLevel - 1, magLevel); + g_creatureEvents().playerAdvance(static_self_cast(), SKILL_MAGLEVEL, magLevel - 1, magLevel); sendUpdate = true; currReqMana = nextReqMana; @@ -5838,8 +5836,8 @@ bool Player::addOfflineTrainingTries(skills_t skill, uint64_t tries) { oldSkillValue = skills[skill].level; oldPercentToNextLevel = static_cast(skills[skill].tries * 100) / nextReqTries; - g_events().eventPlayerOnGainSkillTries(this, skill, tries); - g_callbacks().executeCallback(EventCallback_t::playerOnGainSkillTries, &EventCallback::playerOnGainSkillTries, this, skill, tries); + g_events().eventPlayerOnGainSkillTries(static_self_cast(), skill, tries); + g_callbacks().executeCallback(EventCallback_t::playerOnGainSkillTries, &EventCallback::playerOnGainSkillTries, getPlayer(), skill, tries); uint32_t currSkillLevel = skills[skill].level; while ((skills[skill].tries + tries) >= nextReqTries) { @@ -5849,7 +5847,7 @@ bool Player::addOfflineTrainingTries(skills_t skill, uint64_t tries) { skills[skill].tries = 0; skills[skill].percent = 0; - g_creatureEvents().playerAdvance(this, skill, (skills[skill].level - 1), skills[skill].level); + g_creatureEvents().playerAdvance(static_self_cast(), skill, (skills[skill].level - 1), skills[skill].level); sendUpdate = true; currReqTries = nextReqTries; @@ -5931,7 +5929,7 @@ uint16_t Player::getHelpers() const { uint16_t helpers; if (guild && party) { - phmap::flat_hash_set helperSet; + phmap::flat_hash_set> helperSet; const auto guildMembers = guild->getMembersOnline(); helperSet.insert(guildMembers.begin(), guildMembers.end()); @@ -5958,7 +5956,7 @@ uint16_t Player::getHelpers() const { void Player::sendClosePrivate(uint16_t channelId) { if (channelId == CHANNEL_GUILD || channelId == CHANNEL_PARTY) { - g_chat().removeUserFromChannel(*this, channelId); + g_chat().removeUserFromChannel(getPlayer(), channelId); } if (client) { @@ -5967,16 +5965,16 @@ void Player::sendClosePrivate(uint16_t channelId) { } uint64_t Player::getMoney() const { - std::vector containers; + std::vector> containers; uint64_t moneyCount = 0; for (int32_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; ++i) { - Item* item = inventory[i]; + std::shared_ptr item = inventory[i]; if (!item) { continue; } - const Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container) { containers.push_back(container); } else { @@ -5986,9 +5984,9 @@ uint64_t Player::getMoney() const { size_t i = 0; while (i < containers.size()) { - const Container* container = containers[i++]; - for (const Item* item : container->getItemList()) { - const Container* tmpContainer = item->getContainer(); + std::shared_ptr container = containers[i++]; + for (std::shared_ptr item : container->getItemList()) { + std::shared_ptr tmpContainer = item->getContainer(); if (tmpContainer) { containers.push_back(tmpContainer); } else { @@ -6004,7 +6002,7 @@ std::pair Player::getForgeSliversAndCores() const { uint64_t coreCount = 0; // Check items from inventory - for (const auto* item : getAllInventoryItems()) { + for (const auto item : getAllInventoryItems()) { if (!item) { continue; } @@ -6068,7 +6066,7 @@ void Player::setGuild(const std::shared_ptr newGuild) { } if (guild) { - guild->removeMember(this); + guild->removeMember(static_self_cast()); guild = nullptr; } @@ -6083,7 +6081,7 @@ void Player::setGuild(const std::shared_ptr newGuild) { guild = newGuild; guildRank = rank; - newGuild->addMember(this); + newGuild->addMember(static_self_cast()); } } @@ -6131,12 +6129,12 @@ uint64_t Player::getItemCustomPrice(uint16_t itemId, bool buyPrice /* = false*/) } uint16_t Player::getFreeBackpackSlots() const { - Thing* thing = getThing(CONST_SLOT_BACKPACK); + std::shared_ptr thing = getThing(CONST_SLOT_BACKPACK); if (!thing) { return 0; } - Container* backpack = thing->getContainer(); + std::shared_ptr backpack = thing->getContainer(); if (!backpack) { return 0; } @@ -6166,7 +6164,7 @@ void Player::addItemImbuementStats(const Imbuement* imbuement) { // Add imbuement speed if (imbuement->speed != 0) { - g_game().changeSpeed(this, imbuement->speed); + g_game().changeSpeed(static_self_cast(), imbuement->speed); } // Add imbuement capacity @@ -6205,7 +6203,7 @@ void Player::removeItemImbuementStats(const Imbuement* imbuement) { // Remove imbuement speed if (imbuement->speed != 0) { - g_game().changeSpeed(this, -imbuement->speed); + g_game().changeSpeed(static_self_cast(), -imbuement->speed); } // Remove imbuement capacity @@ -6232,10 +6230,10 @@ bool Player::addItemFromStash(uint16_t itemId, uint32_t itemCount) { while (itemCount > 0) { auto addValue = itemCount > stackCount ? stackCount : itemCount; itemCount -= addValue; - Item* newItem = Item::CreateItem(itemId, addValue); + std::shared_ptr newItem = Item::CreateItem(itemId, addValue); - if (!g_game().tryRetrieveStashItems(this, newItem)) { - g_game().internalPlayerAddItem(this, newItem, true); + if (!g_game().tryRetrieveStashItems(static_self_cast(), newItem)) { + g_game().internalPlayerAddItem(static_self_cast(), newItem, true); } } @@ -6247,21 +6245,21 @@ bool Player::addItemFromStash(uint16_t itemId, uint32_t itemCount) { return true; } -void sendStowItems(Item &item, Item &stowItem, StashContainerList &itemDict) { - if (stowItem.getID() == item.getID()) { - itemDict.push_back(std::pair(&stowItem, stowItem.getItemCount())); +void sendStowItems(const std::shared_ptr &item, const std::shared_ptr &stowItem, StashContainerList &itemDict) { + if (stowItem->getID() == item->getID()) { + itemDict.push_back(std::pair, uint32_t>(stowItem, stowItem->getItemCount())); } - if (auto container = stowItem.getContainer()) { + if (auto container = stowItem->getContainer()) { for (auto stowable_it : container->getStowableItems()) { - if ((stowable_it.first)->getID() == item.getID()) { + if ((stowable_it.first)->getID() == item->getID()) { itemDict.push_back(stowable_it); } } } } -void Player::stowItem(Item* item, uint32_t count, bool allItems) { +void Player::stowItem(std::shared_ptr item, uint32_t count, bool allItems) { if (!item || !item->isItemStorable()) { sendCancelMessage("This item cannot be stowed here."); return; @@ -6272,19 +6270,19 @@ void Player::stowItem(Item* item, uint32_t count, bool allItems) { if (!item->isInsideDepot(true)) { // Stow "all items" from player backpack if (auto backpack = getInventoryItem(CONST_SLOT_BACKPACK)) { - sendStowItems(*item, *backpack, itemDict); + sendStowItems(item, backpack, itemDict); } // Stow "all items" from loot pouch auto itemParent = item->getParent(); auto lootPouch = itemParent->getItem(); if (itemParent && lootPouch && lootPouch->getID() == ITEM_GOLD_POUCH) { - sendStowItems(*item, *lootPouch, itemDict); + sendStowItems(item, lootPouch, itemDict); } } // Stow locker items - DepotLocker* depotLocker = getDepotLocker(getLastDepotId()); + std::shared_ptr depotLocker = getDepotLocker(getLastDepotId()); auto [itemVector, itemMap] = requestLockerItems(depotLocker); for (auto lockerItem : itemVector) { if (lockerItem == nullptr) { @@ -6292,12 +6290,12 @@ void Player::stowItem(Item* item, uint32_t count, bool allItems) { } if (item->isInsideDepot(true)) { - sendStowItems(*item, *lockerItem, itemDict); + sendStowItems(item, lockerItem, itemDict); } } } else if (item->getContainer()) { itemDict = item->getContainer()->getStowableItems(); - for (Item* containerItem : item->getContainer()->getItems(true)) { + for (std::shared_ptr containerItem : item->getContainer()->getItems(true)) { uint32_t depotChest = g_configManager().getNumber(DEPOTCHEST); bool validDepot = depotChest > 0 && depotChest < 21; if (g_configManager().getBoolean(STASH_MOVING) && containerItem && !containerItem->isStackable() && validDepot) { @@ -6307,7 +6305,7 @@ void Player::stowItem(Item* item, uint32_t count, bool allItems) { } } } else { - itemDict.push_back(std::pair(item, count)); + itemDict.push_back(std::pair, uint32_t>(item, count)); } if (itemDict.size() == 0) { @@ -6319,22 +6317,22 @@ void Player::stowItem(Item* item, uint32_t count, bool allItems) { } void Player::openPlayerContainers() { - std::vector> openContainersList; + std::vector>> openContainersList; for (int32_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; i++) { - Item* item = inventory[i]; + std::shared_ptr item = inventory[i]; if (!item) { continue; } - Container* itemContainer = item->getContainer(); + std::shared_ptr itemContainer = item->getContainer(); if (itemContainer) { auto cid = item->getAttribute(ItemAttribute_t::OPENCONTAINER); if (cid > 0) { openContainersList.emplace_back(std::make_pair(cid, itemContainer)); } for (ContainerIterator it = itemContainer->iterator(); it.hasNext(); it.advance()) { - Container* subContainer = (*it)->getContainer(); + std::shared_ptr subContainer = (*it)->getContainer(); if (subContainer) { auto subcid = (*it)->getAttribute(ItemAttribute_t::OPENCONTAINER); if (subcid > 0) { @@ -6345,7 +6343,7 @@ void Player::openPlayerContainers() { } } - std::sort(openContainersList.begin(), openContainersList.end(), [](const std::pair &left, const std::pair &right) { + std::sort(openContainersList.begin(), openContainersList.end(), [](const std::pair> &left, const std::pair> &right) { return left.first < right.first; }); @@ -6510,13 +6508,13 @@ void Player::clearCooldowns() { void Player::requestDepotItems() { ItemsTierCountList itemMap; uint16_t count = 0; - const DepotLocker* depotLocker = getDepotLocker(getLastDepotId()); + std::shared_ptr depotLocker = getDepotLocker(getLastDepotId()); if (!depotLocker) { return; } - for (Item* locker : depotLocker->getItemList()) { - const Container* c = locker->getContainer(); + for (std::shared_ptr locker : depotLocker->getItemList()) { + std::shared_ptr c = locker->getContainer(); if (!c || c->empty()) { continue; } @@ -6576,19 +6574,19 @@ void Player::requestDepotSearchItem(uint16_t itemId, uint8_t tier) { stashCount = getStashItemCount(itemId); } - const DepotLocker* depotLocker = getDepotLocker(getLastDepotId()); + std::shared_ptr depotLocker = getDepotLocker(getLastDepotId()); if (!depotLocker) { return; } - for (Item* locker : depotLocker->getItemList()) { - const Container* c = locker->getContainer(); + for (std::shared_ptr locker : depotLocker->getItemList()) { + std::shared_ptr c = locker->getContainer(); if (!c || c->empty()) { continue; } for (ContainerIterator it = c->iterator(); it.hasNext(); it.advance()) { - Item* item = *it; + std::shared_ptr item = *it; if (!item || item->getID() != itemId || item->getTier() != tier) { continue; } @@ -6612,14 +6610,14 @@ void Player::requestDepotSearchItem(uint16_t itemId, uint8_t tier) { } void Player::retrieveAllItemsFromDepotSearch(uint16_t itemId, uint8_t tier, bool isDepot) { - const DepotLocker* depotLocker = getDepotLocker(getLastDepotId()); + std::shared_ptr depotLocker = getDepotLocker(getLastDepotId()); if (!depotLocker) { return; } - std::vector itemsVector; - for (Item* locker : depotLocker->getItemList()) { - const Container* c = locker->getContainer(); + std::vector> itemsVector; + for (std::shared_ptr locker : depotLocker->getItemList()) { + std::shared_ptr c = locker->getContainer(); if (!c || c->empty() || // Retrieve from inbox. (c->isInbox() && isDepot) || @@ -6629,7 +6627,7 @@ void Player::retrieveAllItemsFromDepotSearch(uint16_t itemId, uint8_t tier, bool } for (ContainerIterator it = c->iterator(); it.hasNext(); it.advance()) { - Item* item = *it; + std::shared_ptr item = *it; if (!item) { continue; } @@ -6641,14 +6639,14 @@ void Player::retrieveAllItemsFromDepotSearch(uint16_t itemId, uint8_t tier, bool } ReturnValue ret = RETURNVALUE_NOERROR; - for (Item* item : itemsVector) { + for (std::shared_ptr item : itemsVector) { // First lets try to retrieve the item to the stash retrieve container. - if (g_game().tryRetrieveStashItems(this, item)) { + if (g_game().tryRetrieveStashItems(static_self_cast(), item)) { continue; } // If the retrieve fails to move the item to the stash retrieve container, let's add the item anywhere. - if (ret = g_game().internalMoveItem(item->getParent(), this, INDEX_WHEREEVER, item, item->getItemCount(), nullptr); ret == RETURNVALUE_NOERROR) { + if (ret = g_game().internalMoveItem(item->getParent(), getPlayer(), INDEX_WHEREEVER, item, item->getItemCount(), nullptr); ret == RETURNVALUE_NOERROR) { continue; } @@ -6665,37 +6663,37 @@ void Player::openContainerFromDepotSearch(const Position &pos) { return; } - const Item* item = getItemFromDepotSearch(depotSearchOnItem.first, pos); + std::shared_ptr item = getItemFromDepotSearch(depotSearchOnItem.first, pos); if (!item) { sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; } - Container* container = item->getParent() ? item->getParent()->getContainer() : nullptr; + std::shared_ptr container = item->getParent() ? item->getParent()->getContainer() : nullptr; if (!container) { sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; } - g_actions().useItem(this, pos, 0, container, false); + g_actions().useItem(static_self_cast(), pos, 0, container, false); } -Item* Player::getItemFromDepotSearch(uint16_t itemId, const Position &pos) { - const DepotLocker* depotLocker = getDepotLocker(getLastDepotId()); +std::shared_ptr Player::getItemFromDepotSearch(uint16_t itemId, const Position &pos) { + std::shared_ptr depotLocker = getDepotLocker(getLastDepotId()); if (!depotLocker) { return nullptr; } uint8_t index = 0; - for (Item* locker : depotLocker->getItemList()) { - const Container* c = locker->getContainer(); + for (std::shared_ptr locker : depotLocker->getItemList()) { + std::shared_ptr c = locker->getContainer(); if (!c || c->empty() || (c->isInbox() && pos.y != 0x21) || // From inbox. (!c->isInbox() && pos.y != 0x20)) { // From depot. continue; } for (ContainerIterator it = c->iterator(); it.hasNext(); it.advance()) { - Item* item = *it; + std::shared_ptr item = *it; if (!item || item->getID() != itemId || item->getTier() != depotSearchOnItem.second) { continue; } @@ -6710,23 +6708,23 @@ Item* Player::getItemFromDepotSearch(uint16_t itemId, const Position &pos) { return nullptr; } -std::pair, std::map>> Player::requestLockerItems(DepotLocker* depotLocker, bool sendToClient /*= false*/, uint8_t tier /*= 0*/) const { +std::pair>, std::map>> Player::requestLockerItems(std::shared_ptr depotLocker, bool sendToClient /*= false*/, uint8_t tier /*= 0*/) const { if (depotLocker == nullptr) { g_logger().error("{} - Depot locker is nullptr", __FUNCTION__); return {}; } std::map> lockerItems; - std::vector itemVector; - std::vector containers { depotLocker }; + std::vector> itemVector; + std::vector> containers { depotLocker }; size_t size = 0; do { - const Container* container = containers[size]; + std::shared_ptr container = containers[size]; size++; - for (Item* item : container->getItemList()) { - Container* lockerContainers = item->getContainer(); + for (std::shared_ptr item : container->getItemList()) { + std::shared_ptr lockerContainers = item->getContainer(); if (lockerContainers && !lockerContainers->empty()) { containers.push_back(lockerContainers); continue; @@ -6774,9 +6772,9 @@ std::pair, std::map>> P return std::make_pair(itemVector, lockerItems); } -std::pair, uint16_t> Player::getLockerItemsAndCountById(DepotLocker &depotLocker, uint8_t tier, uint16_t itemId) { - std::vector lockerItems; - auto [itemVector, itemMap] = requestLockerItems(&depotLocker, false, tier); +std::pair>, uint16_t> Player::getLockerItemsAndCountById(const std::shared_ptr &depotLocker, uint8_t tier, uint16_t itemId) { + std::vector> lockerItems; + auto [itemVector, itemMap] = requestLockerItems(depotLocker, false, tier); uint16_t totalCount = 0; for (auto item : itemVector) { if (!item || item->getID() != itemId) { @@ -6824,30 +6822,30 @@ bool Player::saySpell( int32_t valueEmote = 0; // Send to client - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (std::shared_ptr spectator : spectators) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { valueEmote = tmpPlayer->getStorageValue(STORAGEVALUE_EMOTE); - if (!ghostMode || tmpPlayer->canSeeCreature(this)) { + if (!ghostMode || tmpPlayer->canSeeCreature(static_self_cast())) { if (valueEmote == 1) { - tmpPlayer->sendCreatureSay(this, TALKTYPE_MONSTER_SAY, text, pos); + tmpPlayer->sendCreatureSay(static_self_cast(), TALKTYPE_MONSTER_SAY, text, pos); } else { - tmpPlayer->sendCreatureSay(this, TALKTYPE_SPELL_USE, text, pos); + tmpPlayer->sendCreatureSay(static_self_cast(), TALKTYPE_SPELL_USE, text, pos); } } } } // Execute lua event method - for (Creature* spectator : spectators) { + for (std::shared_ptr spectator : spectators) { auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; } - tmpPlayer->onCreatureSay(this, type, text); - if (this != tmpPlayer) { - g_events().eventCreatureOnHear(tmpPlayer, this, text, type); - g_callbacks().executeCallback(EventCallback_t::creatureOnHear, &EventCallback::creatureOnHear, tmpPlayer, this, text, type); + tmpPlayer->onCreatureSay(static_self_cast(), type, text); + if (static_self_cast() != tmpPlayer) { + g_events().eventCreatureOnHear(tmpPlayer, getPlayer(), text, type); + g_callbacks().executeCallback(EventCallback_t::creatureOnHear, &EventCallback::creatureOnHear, tmpPlayer, getPlayer(), text, type); } } return true; @@ -6901,7 +6899,7 @@ void Player::forgeFuseItems(uint16_t itemId, uint8_t tier, bool success, bool re return; } - Item* firstForgedItem = Item::CreateItem(itemId, 1); + std::shared_ptr firstForgedItem = Item::CreateItem(itemId, 1); if (!firstForgedItem) { g_logger().error("[Log 3] Player with name {} failed to fuse item with id {}", getName(), itemId); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); @@ -6916,7 +6914,7 @@ void Player::forgeFuseItems(uint16_t itemId, uint8_t tier, bool success, bool re return; } - Item* secondForgedItem = Item::CreateItem(itemId, 1); + std::shared_ptr secondForgedItem = Item::CreateItem(itemId, 1); if (!secondForgedItem) { g_logger().error("[Log 4] Player with name {} failed to fuse item with id {}", getName(), itemId); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); @@ -6963,7 +6961,7 @@ void Player::forgeFuseItems(uint16_t itemId, uint8_t tier, bool success, bool re } break; } - if (!g_game().removeMoney(this, cost, 0, true)) { + if (!g_game().removeMoney(static_self_cast(), cost, 0, true)) { g_logger().error("[{}] Failed to remove {} gold from player with name {}", __FUNCTION__, cost, getName()); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; @@ -7036,7 +7034,7 @@ void Player::forgeFuseItems(uint16_t itemId, uint8_t tier, bool success, bool re } break; } - if (!g_game().removeMoney(this, cost, 0, true)) { + if (!g_game().removeMoney(static_self_cast(), cost, 0, true)) { g_logger().error("[{}] Failed to remove {} gold from player with name {}", __FUNCTION__, cost, getName()); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; @@ -7044,7 +7042,7 @@ void Player::forgeFuseItems(uint16_t itemId, uint8_t tier, bool success, bool re history.cost = cost; } - returnValue = g_game().internalAddItem(this, exaltationContainer, INDEX_WHEREEVER); + returnValue = g_game().internalAddItem(static_self_cast(), exaltationContainer, INDEX_WHEREEVER); if (returnValue != RETURNVALUE_NOERROR) { g_logger().error("Failed to add exaltation chest to player with name {}", fmt::underlying(ITEM_EXALTATION_CHEST), getName()); sendCancelMessage(getReturnMessage(returnValue)); @@ -7107,7 +7105,7 @@ void Player::forgeTransferItemTier(uint16_t donorItemId, uint8_t tier, uint16_t return; } - Item* newDonorItem = Item::CreateItem(donorItemId, 1); + std::shared_ptr newDonorItem = Item::CreateItem(donorItemId, 1); if (!newDonorItem) { g_logger().error("[Log 4] Player with name {} failed to transfer item with id {}", getName(), donorItemId); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); @@ -7121,7 +7119,7 @@ void Player::forgeTransferItemTier(uint16_t donorItemId, uint8_t tier, uint16_t return; } - Item* newReceiveItem = Item::CreateItem(receiveItemId, 1); + std::shared_ptr newReceiveItem = Item::CreateItem(receiveItemId, 1); if (!newReceiveItem) { g_logger().error("[Log 6] Player with name {} failed to fuse item with id {}", getName(), receiveItemId); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); @@ -7166,14 +7164,14 @@ void Player::forgeTransferItemTier(uint16_t donorItemId, uint8_t tier, uint16_t return; } - if (!g_game().removeMoney(this, cost, 0, true)) { + if (!g_game().removeMoney(static_self_cast(), cost, 0, true)) { g_logger().error("[{}] Failed to remove {} gold from player with name {}", __FUNCTION__, cost, getName()); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; } history.cost = cost; - returnValue = g_game().internalAddItem(this, exaltationContainer, INDEX_WHEREEVER); + returnValue = g_game().internalAddItem(static_self_cast(), exaltationContainer, INDEX_WHEREEVER); if (returnValue != RETURNVALUE_NOERROR) { g_logger().error("[Log 10] Failed to add forge item {} from player with name {}", fmt::underlying(ITEM_EXALTATION_CHEST), getName()); sendCancelMessage(getReturnMessage(returnValue)); @@ -7206,8 +7204,8 @@ void Player::forgeResourceConversion(uint8_t action) { } auto itemCount = static_cast(g_configManager().getNumber(FORGE_SLIVER_AMOUNT)); - Item* item = Item::CreateItem(ITEM_FORGE_SLIVER, itemCount); - returnValue = g_game().internalPlayerAddItem(this, item); + std::shared_ptr item = Item::CreateItem(ITEM_FORGE_SLIVER, itemCount); + returnValue = g_game().internalPlayerAddItem(static_self_cast(), item); if (returnValue != RETURNVALUE_NOERROR) { g_logger().error("Failed to add {} slivers to player with name {}", itemCount, getName()); sendCancelMessage(getReturnMessage(returnValue)); @@ -7232,9 +7230,9 @@ void Player::forgeResourceConversion(uint8_t action) { return; } - if (Item* item = Item::CreateItem(ITEM_FORGE_CORE, 1); + if (std::shared_ptr item = Item::CreateItem(ITEM_FORGE_CORE, 1); item) { - returnValue = g_game().internalPlayerAddItem(this, item); + returnValue = g_game().internalPlayerAddItem(static_self_cast(), item); } if (returnValue != RETURNVALUE_NOERROR) { g_logger().error("Failed to add one core to player with name {}", getName()); @@ -7434,26 +7432,26 @@ void Player::closeAllExternalContainers() { return; } - std::vector containerToClose; + std::vector> containerToClose; for (const auto &it : openContainers) { - Container* container = it.second.container; + std::shared_ptr container = it.second.container; if (!container) { continue; } - if (container->getHoldingPlayer() != this) { + if (container->getHoldingPlayer() != getPlayer()) { containerToClose.push_back(container); } } - for (Container* container : containerToClose) { + for (std::shared_ptr container : containerToClose) { autoCloseContainers(container); } } SoundEffect_t Player::getHitSoundEffect() const { // Distance sound effects - const Item* tool = getWeapon(); + std::shared_ptr tool = getWeapon(); if (tool == nullptr) { return SoundEffect_t::SILENCE; } @@ -7495,7 +7493,7 @@ SoundEffect_t Player::getHitSoundEffect() const { } SoundEffect_t Player::getAttackSoundEffect() const { - const Item* tool = getWeapon(); + std::shared_ptr tool = getWeapon(); if (tool == nullptr) { return SoundEffect_t::HUMAN_CLOSE_ATK_FIST; } @@ -7572,7 +7570,7 @@ void Player::setHazardSystemPoints(int32_t count) { } } -void Player::parseAttackRecvHazardSystem(CombatDamage &damage, const Monster* monster) { +void Player::parseAttackRecvHazardSystem(CombatDamage &damage, std::shared_ptr monster) { if (!monster || !monster->getHazard()) { return; } @@ -7631,7 +7629,7 @@ void Player::parseAttackRecvHazardSystem(CombatDamage &damage, const Monster* mo } } -void Player::parseAttackDealtHazardSystem(CombatDamage &damage, const Monster* monster) { +void Player::parseAttackDealtHazardSystem(CombatDamage &damage, std::shared_ptr monster) { if (!g_configManager().getBoolean(TOGGLE_HAZARDSYSTEM)) { return; } @@ -7701,7 +7699,7 @@ void Player::sendLootMessage(const std::string &message) const { } } -Container* Player::getLootPouch() const { +std::shared_ptr Player::getLootPouch() const { // Allow players with CM access or higher have the loot pouch anywhere auto parentItem = getParent() ? getParent()->getItem() : nullptr; if (isPlayerGroup() && parentItem && parentItem->getID() != ITEM_STORE_INBOX) { diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 5f159f0ec37..3137d023824 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -81,7 +81,7 @@ struct ForgeHistory { }; struct OpenContainer { - Container* container; + std::shared_ptr container; uint16_t index; }; @@ -100,11 +100,8 @@ class Player final : public Creature, public Cylinder, public Bankable { Player(const Player &) = delete; Player &operator=(const Player &) = delete; - Player* getPlayer() override { - return this; - } - const Player* getPlayer() const override { - return this; + std::shared_ptr getPlayer() override { + return static_self_cast(); } static std::shared_ptr createPlayerTask(uint32_t delay, std::function f, std::string context); @@ -135,7 +132,7 @@ class Player final : public Creature, public Cylinder, public Bankable { const std::string &getNameDescription() const override { return name; } - std::string getDescription(int32_t lookDistance) const override; + std::string getDescription(int32_t lookDistance) override; CreatureType_t getType() const override { return CREATURETYPE_PLAYER; @@ -260,7 +257,7 @@ class Player final : public Creature, public Cylinder, public Bankable { guildRank = newGuildRank; } - bool isGuildMate(const Player* player) const; + bool isGuildMate(std::shared_ptr player) const; [[nodiscard]] const std::string &getGuildNick() const { return guildNick; @@ -269,7 +266,7 @@ class Player final : public Creature, public Cylinder, public Bankable { guildNick = nick; } - bool isInWar(const Player* player) const; + bool isInWar(std::shared_ptr player) const; bool isInWarList(uint32_t guild_id) const; void setLastWalkthroughAttempt(int64_t walkthroughAttempt) { @@ -279,7 +276,7 @@ class Player final : public Creature, public Cylinder, public Bankable { lastWalkthroughPosition = walkthroughPosition; } - Inbox* getInbox() const { + std::shared_ptr getInbox() const { return inbox; } @@ -386,17 +383,17 @@ class Player final : public Creature, public Cylinder, public Bankable { int32_t getReflectFlat(CombatType_t combat, bool useCharges = false) const override; - PartyShields_t getPartyShield(const Player* player) const; - bool isInviting(const Player* player) const; - bool isPartner(const Player* player) const; - void sendPlayerPartyIcons(Player* player); + PartyShields_t getPartyShield(std::shared_ptr player); + bool isInviting(std::shared_ptr player) const; + bool isPartner(std::shared_ptr player) const; + void sendPlayerPartyIcons(std::shared_ptr player); bool addPartyInvitation(Party* party); void removePartyInvitation(Party* party); void clearPartyInvitations(); void sendUnjustifiedPoints(); - GuildEmblems_t getGuildEmblem(const Player* player) const; + GuildEmblems_t getGuildEmblem(std::shared_ptr player) const; uint64_t getSpentMana() const { return manaSpent; @@ -414,17 +411,17 @@ class Player final : public Creature, public Cylinder, public Bankable { group->flags[static_cast(flag)] = false; } - BedItem* getBedItem() { + std::shared_ptr getBedItem() { return bedItem; } - void setBedItem(BedItem* b) { + void setBedItem(std::shared_ptr b) { bedItem = b; } bool hasImbuingItem() { return imbuingItem != nullptr; } - void setImbuingItem(Item* item); + void setImbuingItem(std::shared_ptr item); void addBlessing(uint8_t index, uint8_t count) { if (blessings[index - 1] == 255) { @@ -458,12 +455,12 @@ class Player final : public Creature, public Cylinder, public Bankable { } uint32_t getIP() const; - void addContainer(uint8_t cid, Container* container); + void addContainer(uint8_t cid, std::shared_ptr container); void closeContainer(uint8_t cid); void setContainerIndex(uint8_t cid, uint16_t index); - Container* getContainerByID(uint8_t cid); - int8_t getContainerID(const Container* container) const; + std::shared_ptr getContainerByID(uint8_t cid); + int8_t getContainerID(std::shared_ptr container) const; uint16_t getContainerIndex(uint8_t cid) const; bool canOpenCorpse(uint32_t ownerId) const; @@ -649,7 +646,7 @@ class Player final : public Creature, public Cylinder, public Bankable { bool hasModalWindowOpen(uint32_t modalWindowId) const; void onModalWindowHandled(uint32_t modalWindowId); - bool isPushable() const override; + bool isPushable() override; uint32_t isMuted() const; void addMessageBuffer(); void removeMessageBuffer(); @@ -722,7 +719,7 @@ class Player final : public Creature, public Cylinder, public Bankable { int32_t getMaxHealth() const override; uint32_t getMaxMana() const override; - Item* getInventoryItem(Slots_t slot) const; + std::shared_ptr getInventoryItem(Slots_t slot) const; bool isItemAbilityEnabled(Slots_t slot) const { return inventoryAbilities[slot]; @@ -741,26 +738,26 @@ class Player final : public Creature, public Cylinder, public Bankable { void addConditionSuppressions(const std::array &addCondition); void removeConditionSuppressions(); - Reward* getReward(const uint64_t rewardId, const bool autoCreate); + std::shared_ptr getReward(const uint64_t rewardId, const bool autoCreate); void removeReward(uint64_t rewardId); void getRewardList(std::vector &rewards) const; - RewardChest* getRewardChest(); + std::shared_ptr getRewardChest(); - std::vector getRewardsFromContainer(const Container* container) const; + std::vector> getRewardsFromContainer(std::shared_ptr container) const; - DepotChest* getDepotChest(uint32_t depotId, bool autoCreate); - DepotLocker* getDepotLocker(uint32_t depotId); - void onReceiveMail() const; - bool isNearDepotBox() const; + std::shared_ptr getDepotChest(uint32_t depotId, bool autoCreate); + std::shared_ptr getDepotLocker(uint32_t depotId); + void onReceiveMail(); + bool isNearDepotBox(); - Container* setLootContainer(ObjectCategory_t category, Container* container, bool loading = false); - Container* getLootContainer(ObjectCategory_t category) const; + std::shared_ptr setLootContainer(ObjectCategory_t category, std::shared_ptr container, bool loading = false); + std::shared_ptr getLootContainer(ObjectCategory_t category) const; - bool canSee(const Position &pos) const override; - bool canSeeCreature(const Creature* creature) const override; + bool canSee(const Position &pos) override; + bool canSeeCreature(std::shared_ptr creature) const override; - bool canWalkthrough(const Creature* creature) const; - bool canWalkthroughEx(const Creature* creature) const; + bool canWalkthrough(std::shared_ptr creature); + bool canWalkthroughEx(std::shared_ptr creature); RaceType_t getRace() const override { return RACE_BLOOD; @@ -776,32 +773,32 @@ class Player final : public Creature, public Cylinder, public Bankable { TradeState_t getTradeState() const { return tradeState; } - Item* getTradeItem() { + std::shared_ptr getTradeItem() { return tradeItem; } // shop functions - void setShopOwner(Npc* owner) { + void setShopOwner(std::shared_ptr owner) { shopOwner = owner; } - Npc* getShopOwner() const { + std::shared_ptr getShopOwner() const { return shopOwner; } // V.I.P. functions - void notifyStatusChange(Player* player, VipStatus_t status, bool message = true); + void notifyStatusChange(std::shared_ptr player, VipStatus_t status, bool message = true); bool removeVIP(uint32_t vipGuid); bool addVIP(uint32_t vipGuid, const std::string &vipName, VipStatus_t status); bool addVIPInternal(uint32_t vipGuid); bool editVIP(uint32_t vipGuid, const std::string &description, uint32_t icon, bool notify); // follow functions - bool setFollowCreature(Creature* creature) override; + bool setFollowCreature(std::shared_ptr creature) override; void goToFollowCreature() override; // follow events - void onFollowCreature(const Creature* creature) override; + void onFollowCreature(std::shared_ptr creature) override; // walk events void onWalk(Direction &dir) override; @@ -809,9 +806,9 @@ class Player final : public Creature, public Cylinder, public Bankable { void onWalkComplete() override; void stopWalk(); - bool openShopWindow(Npc* npc); + bool openShopWindow(std::shared_ptr npc); bool closeShopWindow(bool sendCloseShopWindow = true); - bool updateSaleShopList(const Item* item); + bool updateSaleShopList(std::shared_ptr item); bool hasShopItemForSale(uint16_t itemId, uint8_t subType) const; void setChaseMode(bool mode); @@ -830,16 +827,16 @@ class Player final : public Creature, public Cylinder, public Bankable { faction = factionId; } // combat functions - bool setAttackedCreature(Creature* creature) override; + bool setAttackedCreature(std::shared_ptr creature) override; bool isImmune(CombatType_t type) const override; bool isImmune(ConditionType_t type) const override; bool hasShield() const; bool isAttackable() const override; - static bool lastHitIsPlayer(Creature* lastHitCreature); + static bool lastHitIsPlayer(std::shared_ptr lastHitCreature); // stash functions bool addItemFromStash(uint16_t itemId, uint32_t itemCount); - void stowItem(Item* item, uint32_t count, bool allItems); + void stowItem(std::shared_ptr item, uint32_t count, bool allItems); void changeHealth(int32_t healthChange, bool sendHealthChange = true) override; void changeMana(int32_t manaChange) override; @@ -848,7 +845,7 @@ class Player final : public Creature, public Cylinder, public Bankable { bool isPzLocked() const { return pzLocked; } - BlockType_t blockHit(Creature* attacker, CombatType_t combatType, int32_t &damage, bool checkDefense = false, bool checkArmor = false, bool field = false) override; + BlockType_t blockHit(std::shared_ptr attacker, CombatType_t combatType, int32_t &damage, bool checkDefense = false, bool checkArmor = false, bool field = false) override; void doAttacking(uint32_t interval) override; bool hasExtraSwing() override { return lastAttack > 0 && ((OTSYS_TIME() - lastAttack) >= getAttackSpeed()); @@ -870,14 +867,14 @@ class Player final : public Creature, public Cylinder, public Bankable { return lastAttackBlockType; } - Item* getWeapon(Slots_t slot, bool ignoreAmmo) const; - Item* getWeapon(bool ignoreAmmo = false) const; + std::shared_ptr getWeapon(Slots_t slot, bool ignoreAmmo) const; + std::shared_ptr getWeapon(bool ignoreAmmo = false) const; WeaponType_t getWeaponType() const; - int32_t getWeaponSkill(const Item* item) const; - void getShieldAndWeapon(const Item*&shield, const Item*&weapon) const; + int32_t getWeaponSkill(std::shared_ptr item) const; + void getShieldAndWeapon(std::shared_ptr &shield, std::shared_ptr &weapon) const; - void drainHealth(Creature* attacker, int32_t damage) override; - void drainMana(Creature* attacker, int32_t manaLoss) override; + void drainHealth(std::shared_ptr attacker, int32_t damage) override; + void drainMana(std::shared_ptr attacker, int32_t manaLoss) override; void addManaSpent(uint64_t amount); void addSkillAdvance(skills_t skill, uint64_t count); @@ -890,20 +887,20 @@ class Player final : public Creature, public Cylinder, public Bankable { void addInFightTicks(bool pzlock = false); - uint64_t getGainedExperience(Creature* attacker) const override; + uint64_t getGainedExperience(std::shared_ptr attacker) const override; // combat event functions void onAddCondition(ConditionType_t type) override; void onAddCombatCondition(ConditionType_t type) override; void onEndCondition(ConditionType_t type) override; void onCombatRemoveCondition(Condition* condition) override; - void onAttackedCreature(Creature* target) override; + void onAttackedCreature(std::shared_ptr target) override; void onAttacked() override; - void onAttackedCreatureDrainHealth(Creature* target, int32_t points) override; - void onTargetCreatureGainHealth(Creature* target, int32_t points) override; - bool onKilledCreature(Creature* target, bool lastHit = true) override; - void onGainExperience(uint64_t gainExp, Creature* target) override; - void onGainSharedExperience(uint64_t gainExp, Creature* target); + void onAttackedCreatureDrainHealth(std::shared_ptr target, int32_t points) override; + void onTargetCreatureGainHealth(std::shared_ptr target, int32_t points) override; + bool onKilledCreature(std::shared_ptr target, bool lastHit = true) override; + void onGainExperience(uint64_t gainExp, std::shared_ptr target) override; + void onGainSharedExperience(uint64_t gainExp, std::shared_ptr target); void onAttackedCreatureBlockHit(BlockType_t blockType) override; void onBlockHit() override; void onChangeZone(ZoneType_t zone) override; @@ -914,7 +911,7 @@ class Player final : public Creature, public Cylinder, public Bankable { LightInfo getCreatureLight() const override; Skulls_t getSkull() const override; - Skulls_t getSkullClient(const Creature* creature) const override; + Skulls_t getSkullClient(std::shared_ptr creature) override; int64_t getSkullTicks() const { return skullTicks; } @@ -922,17 +919,17 @@ class Player final : public Creature, public Cylinder, public Bankable { skullTicks = ticks; } - bool hasAttacked(const Player* attacked) const; - void addAttacked(const Player* attacked); - void removeAttacked(const Player* attacked); + bool hasAttacked(std::shared_ptr attacked) const; + void addAttacked(std::shared_ptr attacked); + void removeAttacked(std::shared_ptr attacked); void clearAttacked(); - void addUnjustifiedDead(const Player* attacked); - void sendCreatureEmblem(const Creature* creature) const { + void addUnjustifiedDead(std::shared_ptr attacked); + void sendCreatureEmblem(std::shared_ptr creature) const { if (client) { client->sendCreatureEmblem(creature); } } - void sendCreatureSkull(const Creature* creature) const { + void sendCreatureSkull(std::shared_ptr creature) const { if (client) { client->sendCreatureSkull(creature); } @@ -955,24 +952,24 @@ class Player final : public Creature, public Cylinder, public Bankable { bool canLogout(); - bool hasKilled(const Player* player) const; + bool hasKilled(std::shared_ptr player) const; size_t getMaxVIPEntries() const; size_t getMaxDepotItems() const; // tile // send methods - void sendAddTileItem(const Tile* itemTile, const Position &pos, const Item* item) { + void sendAddTileItem(std::shared_ptr itemTile, const Position &pos, std::shared_ptr item) { if (client) { - int32_t stackpos = itemTile->getStackposOfItem(this, item); + int32_t stackpos = itemTile->getStackposOfItem(static_self_cast(), item); if (stackpos != -1) { client->sendAddTileItem(pos, stackpos, item); } } } - void sendUpdateTileItem(const Tile* updateTile, const Position &pos, const Item* item) { + void sendUpdateTileItem(std::shared_ptr updateTile, const Position &pos, std::shared_ptr item) { if (client) { - int32_t stackpos = updateTile->getStackposOfItem(this, item); + int32_t stackpos = updateTile->getStackposOfItem(static_self_cast(), item); if (stackpos != -1) { client->sendUpdateTileItem(pos, stackpos, item); } @@ -983,7 +980,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendRemoveTileThing(pos, stackpos); } } - void sendUpdateTile(const Tile* updateTile, const Position &pos) { + void sendUpdateTile(std::shared_ptr updateTile, const Position &pos) { if (client) { client->sendUpdateTile(updateTile, pos); } @@ -999,7 +996,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendChannelEvent(channelId, playerName, channelEvent); } } - void sendCreatureAppear(const Creature* creature, const Position &pos, bool isLogin) { + void sendCreatureAppear(std::shared_ptr creature, const Position &pos, bool isLogin) { if (!creature) { return; } @@ -1010,15 +1007,15 @@ class Player final : public Creature, public Cylinder, public Bankable { } if (client) { - client->sendAddCreature(creature, pos, tile->getStackposOfCreature(this, creature), isLogin); + client->sendAddCreature(creature, pos, tile->getStackposOfCreature(static_self_cast(), creature), isLogin); } } - void sendCreatureMove(const Creature* creature, const Position &newPos, int32_t newStackPos, const Position &oldPos, int32_t oldStackPos, bool teleport) { + void sendCreatureMove(std::shared_ptr creature, const Position &newPos, int32_t newStackPos, const Position &oldPos, int32_t oldStackPos, bool teleport) { if (client) { client->sendMoveCreature(creature, newPos, newStackPos, oldPos, oldStackPos, teleport); } } - void sendCreatureTurn(const Creature* creature) { + void sendCreatureTurn(std::shared_ptr creature) { if (!creature) { return; } @@ -1029,38 +1026,38 @@ class Player final : public Creature, public Cylinder, public Bankable { } if (client && canSeeCreature(creature)) { - int32_t stackpos = tile->getStackposOfCreature(this, creature); + int32_t stackpos = tile->getStackposOfCreature(static_self_cast(), creature); if (stackpos != -1) { client->sendCreatureTurn(creature, stackpos); } } } - void sendCreatureSay(const Creature* creature, SpeakClasses type, const std::string &text, const Position* pos = nullptr) { + void sendCreatureSay(std::shared_ptr creature, SpeakClasses type, const std::string &text, const Position* pos = nullptr) { if (client) { client->sendCreatureSay(creature, type, text, pos); } } - void sendCreatureReload(const Creature* creature) { + void sendCreatureReload(std::shared_ptr creature) { if (client) { client->reloadCreature(creature); } } - void sendPrivateMessage(const Player* speaker, SpeakClasses type, const std::string &text) { + void sendPrivateMessage(std::shared_ptr speaker, SpeakClasses type, const std::string &text) { if (client) { client->sendPrivateMessage(speaker, type, text); } } - void sendCreatureSquare(const Creature* creature, SquareColor_t color) { + void sendCreatureSquare(std::shared_ptr creature, SquareColor_t color) { if (client) { client->sendCreatureSquare(creature, color); } } - void sendCreatureChangeOutfit(const Creature* creature, const Outfit_t &outfit) { + void sendCreatureChangeOutfit(std::shared_ptr creature, const Outfit_t &outfit) { if (client) { client->sendCreatureOutfit(creature, outfit); } } - void sendCreatureChangeVisible(const Creature* creature, bool visible) { + void sendCreatureChangeVisible(std::shared_ptr creature, bool visible) { if (!client || !creature) { return; } @@ -1079,7 +1076,7 @@ class Player final : public Creature, public Cylinder, public Bankable { if (!tile) { return; } - int32_t stackpos = tile->getStackposOfCreature(this, creature); + int32_t stackpos = tile->getStackposOfCreature(static_self_cast(), creature); if (stackpos == -1) { return; } @@ -1091,32 +1088,32 @@ class Player final : public Creature, public Cylinder, public Bankable { } } } - void sendCreatureLight(const Creature* creature) { + void sendCreatureLight(std::shared_ptr creature) { if (client) { client->sendCreatureLight(creature); } } - void sendCreatureIcon(const Creature* creature) { + void sendCreatureIcon(std::shared_ptr creature) { if (client && !client->oldProtocol) { client->sendCreatureIcon(creature); } } - void sendUpdateCreature(const Creature* creature) const { + void sendUpdateCreature(std::shared_ptr creature) const { if (client) { client->sendUpdateCreature(creature); } } - void sendCreatureWalkthrough(const Creature* creature, bool walkthrough) { + void sendCreatureWalkthrough(std::shared_ptr creature, bool walkthrough) { if (client) { client->sendCreatureWalkthrough(creature, walkthrough); } } - void sendCreatureShield(const Creature* creature) { + void sendCreatureShield(std::shared_ptr creature) { if (client) { client->sendCreatureShield(creature); } } - void sendCreatureType(const Creature* creature, uint8_t creatureType) { + void sendCreatureType(std::shared_ptr creature, uint8_t creatureType) { if (client) { client->sendCreatureType(creature, creatureType); } @@ -1136,7 +1133,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendUseItemCooldown(time); } } - void reloadCreature(const Creature* creature) { + void reloadCreature(std::shared_ptr creature) { if (client) { client->reloadCreature(creature); } @@ -1145,10 +1142,10 @@ class Player final : public Creature, public Cylinder, public Bankable { // container void closeAllExternalContainers(); - void sendAddContainerItem(const Container* container, const Item* item); - void sendUpdateContainerItem(const Container* container, uint16_t slot, const Item* newItem); - void sendRemoveContainerItem(const Container* container, uint16_t slot); - void sendContainer(uint8_t cid, const Container* container, bool hasParent, uint16_t firstIndex) { + void sendAddContainerItem(std::shared_ptr container, std::shared_ptr item); + void sendUpdateContainerItem(std::shared_ptr container, uint16_t slot, std::shared_ptr newItem); + void sendRemoveContainerItem(std::shared_ptr container, uint16_t slot); + void sendContainer(uint8_t cid, std::shared_ptr container, bool hasParent, uint16_t firstIndex) { if (client) { client->sendContainer(cid, container, hasParent, firstIndex); } @@ -1175,7 +1172,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendCoinBalance(); } } - void sendInventoryItem(Slots_t slot, const Item* item) { + void sendInventoryItem(Slots_t slot, std::shared_ptr item) { if (client) { client->sendInventoryItem(slot, item); } @@ -1211,28 +1208,28 @@ class Player final : public Creature, public Cylinder, public Bankable { SoundEffect_t getHitSoundEffect() const; // event methods - void onUpdateTileItem(const Tile* tile, const Position &pos, const Item* oldItem, const ItemType &oldType, const Item* newItem, const ItemType &newType) override; - void onRemoveTileItem(const Tile* tile, const Position &pos, const ItemType &iType, const Item* item) override; + void onUpdateTileItem(std::shared_ptr tile, const Position &pos, std::shared_ptr oldItem, const ItemType &oldType, std::shared_ptr newItem, const ItemType &newType) override; + void onRemoveTileItem(std::shared_ptr tile, const Position &pos, const ItemType &iType, std::shared_ptr item) override; - void onCreatureAppear(Creature* creature, bool isLogin) override; - void onRemoveCreature(Creature* creature, bool isLogout) override; - void onCreatureMove(Creature* creature, const Tile* newTile, const Position &newPos, const Tile* oldTile, const Position &oldPos, bool teleport) override; + void onCreatureAppear(std::shared_ptr creature, bool isLogin) override; + void onRemoveCreature(std::shared_ptr creature, bool isLogout) override; + void onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport) override; void onAttackedCreatureDisappear(bool isLogout) override; void onFollowCreatureDisappear(bool isLogout) override; // container - void onAddContainerItem(const Item* item); - void onUpdateContainerItem(const Container* container, const Item* oldItem, const Item* newItem); - void onRemoveContainerItem(const Container* container, const Item* item); + void onAddContainerItem(std::shared_ptr item); + void onUpdateContainerItem(std::shared_ptr container, std::shared_ptr oldItem, std::shared_ptr newItem); + void onRemoveContainerItem(std::shared_ptr container, std::shared_ptr item); - void onCloseContainer(const Container* container); - void onSendContainer(const Container* container); - void autoCloseContainers(const Container* container); + void onCloseContainer(std::shared_ptr container); + void onSendContainer(std::shared_ptr container); + void autoCloseContainers(std::shared_ptr container); // inventory - void onUpdateInventoryItem(Item* oldItem, Item* newItem); - void onRemoveInventoryItem(Item* item); + void onUpdateInventoryItem(std::shared_ptr oldItem, std::shared_ptr newItem); + void onRemoveInventoryItem(std::shared_ptr item); void sendCancelMessage(const std::string &msg) const { if (client) { @@ -1250,52 +1247,52 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendCancelWalk(); } } - void sendChangeSpeed(const Creature* creature, uint16_t newSpeed) const { + void sendChangeSpeed(std::shared_ptr creature, uint16_t newSpeed) const { if (client) { client->sendChangeSpeed(creature, newSpeed); } } - void sendCreatureHealth(const Creature* creature) const { + void sendCreatureHealth(std::shared_ptr creature) const { if (client) { client->sendCreatureHealth(creature); } } - void sendPartyCreatureUpdate(const Creature* creature) const { + void sendPartyCreatureUpdate(std::shared_ptr creature) const { if (client) { client->sendPartyCreatureUpdate(creature); } } - void sendPartyCreatureShield(const Creature* creature) const { + void sendPartyCreatureShield(std::shared_ptr creature) const { if (client) { client->sendPartyCreatureShield(creature); } } - void sendPartyCreatureSkull(const Creature* creature) const { + void sendPartyCreatureSkull(std::shared_ptr creature) const { if (client) { client->sendPartyCreatureSkull(creature); } } - void sendPartyCreatureHealth(const Creature* creature, uint8_t healthPercent) const { + void sendPartyCreatureHealth(std::shared_ptr creature, uint8_t healthPercent) const { if (client) { client->sendPartyCreatureHealth(creature, healthPercent); } } - void sendPartyPlayerMana(const Player* player, uint8_t manaPercent) const { + void sendPartyPlayerMana(std::shared_ptr player, uint8_t manaPercent) const { if (client) { client->sendPartyPlayerMana(player, manaPercent); } } - void sendPartyCreatureShowStatus(const Creature* creature, bool showStatus) const { + void sendPartyCreatureShowStatus(std::shared_ptr creature, bool showStatus) const { if (client) { client->sendPartyCreatureShowStatus(creature, showStatus); } } - void sendPartyPlayerVocation(const Player* player) const { + void sendPartyPlayerVocation(std::shared_ptr player) const { if (client) { client->sendPartyPlayerVocation(player); } } - void sendPlayerVocation(const Player* player) const { + void sendPlayerVocation(std::shared_ptr player) const { if (client) { client->sendPlayerVocation(player); } @@ -1374,17 +1371,17 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendReLoginWindow(unfairFightReduction); } } - void sendTextWindow(Item* item, uint16_t maxlen, bool canWrite) const { + void sendTextWindow(std::shared_ptr item, uint16_t maxlen, bool canWrite) const { if (client) { client->sendTextWindow(windowTextId, item, maxlen, canWrite); } } - void sendToChannel(const Creature* creature, SpeakClasses type, const std::string &text, uint16_t channelId) const { + void sendToChannel(std::shared_ptr creature, SpeakClasses type, const std::string &text, uint16_t channelId) const { if (client) { client->sendToChannel(creature, type, text, channelId); } } - void sendShop(Npc* npc) const { + void sendShop(std::shared_ptr npc) const { if (client) { client->sendShop(npc); } @@ -1436,7 +1433,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendMarketCancelOffer(offer); } } - void sendTradeItemRequest(const std::string &traderName, const Item* item, bool ack) const { + void sendTradeItemRequest(const std::string &traderName, std::shared_ptr item, bool ack) const { if (client) { client->sendTradeItemRequest(traderName, item, ack); } @@ -1477,9 +1474,9 @@ class Player final : public Creature, public Cylinder, public Bankable { } } // Imbuements - void onApplyImbuement(Imbuement* imbuement, Item* item, uint8_t slot, bool protectionCharm); - void onClearImbuement(Item* item, uint8_t slot); - void openImbuementWindow(Item* item); + void onApplyImbuement(Imbuement* imbuement, std::shared_ptr item, uint8_t slot, bool protectionCharm); + void onClearImbuement(std::shared_ptr item, uint8_t slot); + void openImbuementWindow(std::shared_ptr item); void sendImbuementResult(const std::string message) { if (client) { client->sendImbuementResult(message); @@ -1490,7 +1487,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->closeImbuementWindow(); } } - void sendPodiumWindow(const Item* podium, const Position &position, uint16_t itemId, uint8_t stackpos) { + void sendPodiumWindow(std::shared_ptr podium, const Position &position, uint16_t itemId, uint8_t stackpos) { if (client) { client->sendPodiumWindow(podium, position, itemId, stackpos); } @@ -1516,7 +1513,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendAddMarker(pos, markType, desc); } } - void sendItemInspection(uint16_t itemId, uint8_t itemCount, const Item* item, bool cyclopedia) { + void sendItemInspection(uint16_t itemId, uint8_t itemCount, std::shared_ptr item, bool cyclopedia) { if (client) { client->sendItemInspection(itemId, itemCount, item, cyclopedia); } @@ -1637,8 +1634,8 @@ class Player final : public Creature, public Cylinder, public Bankable { void onThink(uint32_t interval) override; - void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; - void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; void setNextAction(int64_t time) { if (time > nextAction) { @@ -1674,8 +1671,8 @@ class Player final : public Creature, public Cylinder, public Bankable { uint32_t getNextActionTime() const; uint32_t getNextPotionActionTime() const; - Item* getWriteItem(uint32_t &windowTextId, uint16_t &maxWriteLen); - void setWriteItem(Item* item, uint16_t maxWriteLen = 0); + std::shared_ptr getWriteItem(uint32_t &windowTextId, uint16_t &maxWriteLen); + void setWriteItem(std::shared_ptr item, uint16_t maxWriteLen = 0); House* getEditHouse(uint32_t &windowTextId, uint32_t &listId); void setEditHouse(House* house, uint32_t listId = 0); @@ -1770,7 +1767,7 @@ class Player final : public Creature, public Cylinder, public Bankable { bool isUIExhausted(uint32_t exhaustionTime = 250) const; void updateUIExhausted(); - bool isQuickLootListedItem(const Item* item) const { + bool isQuickLootListedItem(std::shared_ptr item) const { if (!item) { return false; } @@ -1779,7 +1776,7 @@ class Player final : public Creature, public Cylinder, public Bankable { return it != quickLootListItemIds.end(); } - bool updateKillTracker(Container* corpse, const std::string &playerName, const Outfit_t creatureOutfit) const { + bool updateKillTracker(std::shared_ptr corpse, const std::string &playerName, const Outfit_t creatureOutfit) const { if (client) { client->sendKillTrackerUpdate(corpse, playerName, creatureOutfit); return true; @@ -1794,8 +1791,8 @@ class Player final : public Creature, public Cylinder, public Bankable { } } - void sendLootStats(Item* item, uint8_t count) const; - void updateSupplyTracker(const Item* item) const; + void sendLootStats(std::shared_ptr item, uint8_t count); + void updateSupplyTracker(std::shared_ptr item); void updateImpactTracker(CombatType_t type, int32_t amount) const; void updateInputAnalyzer(CombatType_t type, int32_t amount, std::string target) { @@ -2271,9 +2268,9 @@ class Player final : public Creature, public Cylinder, public Bankable { void requestDepotSearchItem(uint16_t itemId, uint8_t tier); void retrieveAllItemsFromDepotSearch(uint16_t itemId, uint8_t tier, bool isDepot); void openContainerFromDepotSearch(const Position &pos); - Item* getItemFromDepotSearch(uint16_t itemId, const Position &pos); + std::shared_ptr getItemFromDepotSearch(uint16_t itemId, const Position &pos); - std::pair, std::map>> requestLockerItems(DepotLocker* depotLocker, bool sendToClient = false, uint8_t tier = 0) const; + std::pair>, std::map>> requestLockerItems(std::shared_ptr depotLocker, bool sendToClient = false, uint8_t tier = 0) const; /** This function returns a pair of an array of items and a 16-bit integer from a DepotLocker instance, a 8-bit byte and a 16-bit integer. @@ -2283,8 +2280,8 @@ class Player final : public Creature, public Cylinder, public Bankable { @return A pair of an array of items and a 16-bit integer, where the array of items is filled with all items from the locker with the specified id and the 16-bit integer is the total items found. */ - std::pair, uint16_t> getLockerItemsAndCountById( - DepotLocker &depotLocker, + std::pair>, uint16_t> getLockerItemsAndCountById( + const std::shared_ptr &depotLocker, uint8_t tier, uint16_t itemId ); @@ -2428,7 +2425,7 @@ class Player final : public Creature, public Cylinder, public Bankable { return bossRemoveTimes; } - void sendMonsterPodiumWindow(const Item* podium, const Position &position, uint16_t itemId, uint8_t stackpos) const { + void sendMonsterPodiumWindow(std::shared_ptr podium, const Position &position, uint16_t itemId, uint8_t stackpos) const { if (client) { client->sendMonsterPodiumWindow(podium, position, itemId, stackpos); } @@ -2440,7 +2437,7 @@ class Player final : public Creature, public Cylinder, public Bankable { } } - void sendInventoryImbuements(const std::map items) const { + void sendInventoryImbuements(const std::map> items) const { if (client) { client->sendInventoryImbuements(items); } @@ -2450,8 +2447,8 @@ class Player final : public Creature, public Cylinder, public Bankable { * Hazard system ******************************************************************************/ // Parser - void parseAttackRecvHazardSystem(CombatDamage &damage, const Monster* monster); - void parseAttackDealtHazardSystem(CombatDamage &damage, const Monster* monster); + void parseAttackRecvHazardSystem(CombatDamage &damage, std::shared_ptr monster); + void parseAttackDealtHazardSystem(CombatDamage &damage, std::shared_ptr monster); // Points increase: void setHazardSystemPoints(int32_t amount); // Points get: @@ -2487,17 +2484,17 @@ class Player final : public Creature, public Cylinder, public Bankable { } // Get specific inventory item from itemid - std::vector getInventoryItemsFromId(uint16_t itemId, bool ignore = true) const; + std::vector> getInventoryItemsFromId(uint16_t itemId, bool ignore = true) const; // This get all player inventory items - std::vector getAllInventoryItems(bool ignoreEquiped = false, bool ignoreItemWithTier = false) const; + std::vector> getAllInventoryItems(bool ignoreEquiped = false, bool ignoreItemWithTier = false) const; /** - * @brief Get the equipped items of the player. + * @brief Get the equipped items of the player-> * @details This function returns a vector containing the items currently equipped by the player * @return A vector of pointers to the equipped items. */ - std::vector getEquippedItems() const; + std::vector> getEquippedItems() const; // Player wheel methods interface std::unique_ptr &wheel(); @@ -2505,7 +2502,7 @@ class Player final : public Creature, public Cylinder, public Bankable { void sendLootMessage(const std::string &message) const; - Container* getLootPouch() const; + std::shared_ptr getLootPouch() const; private: static uint32_t playerFirstID; @@ -2513,13 +2510,13 @@ class Player final : public Creature, public Cylinder, public Bankable { std::forward_list getMuteConditions() const; - void checkTradeState(const Item* item); - bool hasCapacity(const Item* item, uint32_t count) const; + void checkTradeState(std::shared_ptr item); + bool hasCapacity(std::shared_ptr item, uint32_t count) const; - void checkLootContainers(const Item* item); + void checkLootContainers(std::shared_ptr item); - void gainExperience(uint64_t exp, Creature* target); - void addExperience(Creature* target, uint64_t exp, bool sendText = false); + void gainExperience(uint64_t exp, std::shared_ptr target); + void addExperience(std::shared_ptr target, uint64_t exp, bool sendText = false); void removeExperience(uint64_t exp, bool sendText = false); void updateInventoryWeight(); @@ -2535,27 +2532,27 @@ class Player final : public Creature, public Cylinder, public Bankable { void setNextActionPushTask(std::shared_ptr task); void setNextPotionActionTask(std::shared_ptr task); - void death(Creature* lastHitCreature) override; + void death(std::shared_ptr lastHitCreature) override; bool spawn(); void despawn(); - bool dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified) override; - Item* getCorpse(Creature* lastHitCreature, Creature* mostDamageCreature) override; + bool dropCorpse(std::shared_ptr lastHitCreature, std::shared_ptr mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified) override; + std::shared_ptr getCorpse(std::shared_ptr lastHitCreature, std::shared_ptr mostDamageCreature) override; // cylinder implementations - ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; - ReturnValue queryMaxCount(int32_t index, const Thing &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) const override; - ReturnValue queryRemove(const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; - Cylinder* queryDestination(int32_t &index, const Thing &thing, Item** destItem, uint32_t &flags) override; + ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; + ReturnValue queryMaxCount(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) override; + ReturnValue queryRemove(const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; + std::shared_ptr queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &flags) override; - void addThing(Thing*) override { } - void addThing(int32_t index, Thing* thing) override; + void addThing(std::shared_ptr) override { } + void addThing(int32_t index, std::shared_ptr thing) override; - void updateThing(Thing* thing, uint16_t itemId, uint32_t count) override; - void replaceThing(uint32_t index, Thing* thing) override; + void updateThing(std::shared_ptr thing, uint16_t itemId, uint32_t count) override; + void replaceThing(uint32_t index, std::shared_ptr thing) override; - void removeThing(Thing* thing, uint32_t count) override; + void removeThing(std::shared_ptr thing, uint32_t count) override; - int32_t getThingIndex(const Thing* thing) const override; + int32_t getThingIndex(std::shared_ptr thing) const override; size_t getFirstIndex() const override; size_t getLastIndex() const override; uint32_t getItemTypeCount(uint16_t itemId, int32_t subType = -1) const override; @@ -2567,19 +2564,19 @@ class Player final : public Creature, public Cylinder, public Bankable { // Function from player class with correct type sizes (uint16_t) std::map &getAllSaleItemIdAndCount(std::map &countMap) const; void getAllItemTypeCountAndSubtype(std::map &countMap) const; - Item* getForgeItemFromId(uint16_t itemId, uint8_t tier); - Thing* getThing(size_t index) const override; + std::shared_ptr getForgeItemFromId(uint16_t itemId, uint8_t tier); + std::shared_ptr getThing(size_t index) const override; - void internalAddThing(Thing* thing) override; - void internalAddThing(uint32_t index, Thing* thing) override; + void internalAddThing(std::shared_ptr thing) override; + void internalAddThing(uint32_t index, std::shared_ptr thing) override; phmap::flat_hash_set attackedSet; phmap::flat_hash_set VIPList; std::map openContainers; - std::map depotLockerMap; - std::map depotChests; + std::map> depotLockerMap; + std::map> depotChests; std::map moduleDelayMap; std::map storageMap; std::map itemPriceMap; @@ -2590,9 +2587,9 @@ class Player final : public Creature, public Cylinder, public Bankable { { SKILL_CRITICAL_HIT_CHANCE, g_configManager().getNumber(CRITICALCHANCE) } }; - std::map rewardMap; + std::map> rewardMap; - std::map quickLootContainers; + std::map> quickLootContainers; std::vector forgeHistoryVector; std::vector quickLootListItemIds; @@ -2654,24 +2651,24 @@ class Player final : public Creature, public Cylinder, public Bankable { std::vector unjustifiedKills; - BedItem* bedItem = nullptr; + std::shared_ptr bedItem = nullptr; std::shared_ptr guild = nullptr; GuildRank_ptr guildRank; Group* group = nullptr; - Inbox* inbox; - Item* imbuingItem = nullptr; - Item* tradeItem = nullptr; - Item* inventory[CONST_SLOT_LAST + 1] = {}; - Item* writeItem = nullptr; + std::shared_ptr inbox; + std::shared_ptr imbuingItem = nullptr; + std::shared_ptr tradeItem = nullptr; + std::shared_ptr inventory[CONST_SLOT_LAST + 1] = {}; + std::shared_ptr writeItem = nullptr; House* editHouse = nullptr; - Npc* shopOwner = nullptr; + std::shared_ptr shopOwner = nullptr; Party* party = nullptr; - Player* tradePartner = nullptr; + std::shared_ptr tradePartner = nullptr; ProtocolGame_ptr client; std::shared_ptr walkTask; Town* town = nullptr; Vocation* vocation = nullptr; - RewardChest* rewardChest = nullptr; + std::shared_ptr rewardChest = nullptr; uint32_t inventoryWeight = 0; uint32_t capacity = 40000; @@ -2853,7 +2850,7 @@ class Player final : public Creature, public Cylinder, public Bankable { void addConditionSuppression(const std::array &addConditions); uint16_t getLookCorpse() const override; - void getPathSearchParams(const Creature* creature, FindPathParams &fpp) const override; + void getPathSearchParams(std::shared_ptr creature, FindPathParams &fpp) override; void setDead(bool isDead) { dead = isDead; @@ -2890,12 +2887,12 @@ class Player final : public Creature, public Cylinder, public Bankable { bool hasWeaponDistanceEquipped() const; - Item* getQuiverAmmoOfType(const ItemType &it) const; + std::shared_ptr getQuiverAmmoOfType(const ItemType &it) const; std::array getFinalDamageReduction() const; void calculateDamageReductionFromEquipedItems(std::array &combatReductionMap) const; - void calculateDamageReductionFromItem(std::array &combatReductionMap, Item* item) const; - void updateDamageReductionFromItemImbuement(std::array &combatReductionMap, Item* item, uint16_t combatTypeIndex) const; - void updateDamageReductionFromItemAbility(std::array &combatReductionMap, const Item* item, uint16_t combatTypeIndex) const; + void calculateDamageReductionFromItem(std::array &combatReductionMap, std::shared_ptr item) const; + void updateDamageReductionFromItemImbuement(std::array &combatReductionMap, std::shared_ptr item, uint16_t combatTypeIndex) const; + void updateDamageReductionFromItemAbility(std::array &combatReductionMap, std::shared_ptr item, uint16_t combatTypeIndex) const; double_t calculateDamageReduction(double_t currentTotal, int16_t resistance) const; }; diff --git a/src/creatures/players/wheel/player_wheel.cpp b/src/creatures/players/wheel/player_wheel.cpp index 06a25f4d743..bdf64fc63b0 100644 --- a/src/creatures/players/wheel/player_wheel.cpp +++ b/src/creatures/players/wheel/player_wheel.cpp @@ -1074,7 +1074,7 @@ void PlayerWheel::reloadPlayerData() { m_player.sendStats(); m_player.sendBasicData(); sendGiftOfLifeCooldown(); - g_game().reloadCreature(&m_player); + g_game().reloadCreature(m_player.getPlayer()); } void PlayerWheel::registerPlayerBonusData() { @@ -1216,7 +1216,7 @@ void PlayerWheel::registerPlayerBonusData() { if (m_player.getHealth() > m_player.getMaxHealth()) { m_player.health = std::min(m_player.getMaxHealth(), m_player.healthMax); - g_game().addCreatureHealth(&m_player); + g_game().addCreatureHealth(m_player.getPlayer()); } if (m_player.getMana() > m_player.getMaxMana()) { @@ -1374,7 +1374,7 @@ void PlayerWheel::printPlayerWheelMethodsBonusData(const PlayerWheelMethodsBonus } void PlayerWheel::loadDedicationAndConvictionPerks() { - using VocationBonusFunction = std::function; + using VocationBonusFunction = std::function &, uint16_t, uint8_t, PlayerWheelMethodsBonusData &)>; auto &wheelFunctions = g_game().getIOWheel()->getWheelMapFunctions(); auto vocationCipId = getPlayerVocationEnum(); if (vocationCipId < VOCATION_KNIGHT_CIP || vocationCipId > VOCATION_DRUID_CIP) { @@ -1392,7 +1392,7 @@ void PlayerWheel::loadDedicationAndConvictionPerks() { if (internalData == nullptr) { g_logger().warn("[{}] 'internalData' cannot be null on slot type: {}, for player: {}", __FUNCTION__, i, m_player.getName()); } else { - internalData(m_player, points, vocationCipId, m_playerBonusData); + internalData(m_player.getPlayer(), points, vocationCipId, m_playerBonusData); } } } @@ -1612,13 +1612,13 @@ bool PlayerWheel::checkBattleInstinct() { m_player.getPosition().y + offsetY, m_player.getPosition().z ); - const Tile* tile = g_game().map.getTile(playerPositionOffSet); + std::shared_ptr tile = g_game().map.getTile(playerPositionOffSet); if (!tile) { continue; } - const Creature* creature = tile->getTopVisibleCreature(&m_player); - if (!creature || creature == &m_player || (creature->getMaster() && creature->getMaster()->getPlayer() == &m_player)) { + std::shared_ptr creature = tile->getTopVisibleCreature(m_player.getPlayer()); + if (!creature || creature == m_player.getPlayer() || (creature->getMaster() && creature->getMaster()->getPlayer() == m_player.getPlayer())) { continue; } @@ -1660,13 +1660,13 @@ bool PlayerWheel::checkPositionalTatics() { m_player.getPosition().y + offsetY, m_player.getPosition().z ); - const Tile* tile = g_game().map.getTile(playerPositionOffSet); + std::shared_ptr tile = g_game().map.getTile(playerPositionOffSet); if (!tile) { continue; } - const Creature* creature = tile->getTopVisibleCreature(&m_player); - if (!creature || creature == &m_player || !creature->getMonster() || (creature->getMaster() && creature->getMaster()->getPlayer())) { + std::shared_ptr creature = tile->getTopVisibleCreature(m_player.getPlayer()); + if (!creature || creature == m_player.getPlayer() || !creature->getMonster() || (creature->getMaster() && creature->getMaster()->getPlayer())) { continue; } @@ -1707,7 +1707,7 @@ bool PlayerWheel::checkBallisticMastery() { uint16_t newHolyBonus = 2; // 2% uint16_t newPhysicalBonus = 2; // 2% - const Item* item = m_player.getWeapon(); + std::shared_ptr item = m_player.getWeapon(); if (item && item->getAmmoType() == AMMO_BOLT) { if (getMajorStat(WheelMajor_t::CRITICAL_DMG) != newCritical) { setMajorStat(WheelMajor_t::CRITICAL_DMG, newCritical); @@ -1748,7 +1748,7 @@ bool PlayerWheel::checkCombatMastery() { bool updateClient = false; uint8_t stage = getStage(WheelStage_t::COMBAT_MASTERY); - const Item* item = m_player.getWeapon(); + std::shared_ptr item = m_player.getWeapon(); if (item && item->getSlotPosition() & SLOTP_TWO_HAND) { int32_t criticalSkill = 0; if (stage >= 3) { @@ -1793,7 +1793,7 @@ bool PlayerWheel::checkDivineEmpowerment() { bool updateClient = false; setOnThinkTimer(WheelOnThink_t::DIVINE_EMPOWERMENT, OTSYS_TIME() + 2000); - const Tile* tile = m_player.getTile(); + const auto tile = m_player.getTile(); if (tile && tile->getItemTypeCount(ITEM_DIVINE_EMPOWERMENT) > 0) { int32_t damageBonus = 0; uint8_t stage = getStage(WheelStage_t::DIVINE_EMPOWERMENT); @@ -1821,7 +1821,7 @@ void PlayerWheel::checkGiftOfLife() { giftDamage.primary.type = COMBAT_HEALING; m_player.sendTextMessage(MESSAGE_EVENT_ADVANCE, "That was close! Fortunately, your were saved by the Gift of Life."); g_game().addMagicEffect(m_player.getPosition(), CONST_ME_WATER_DROP); - g_game().combatChangeHealth(&m_player, &m_player, giftDamage); + g_game().combatChangeHealth(m_player.getPlayer(), m_player.getPlayer(), giftDamage); // Condition cooldown reduction uint16_t reductionTimer = 60000; reduceAllSpellsCooldownTimer(reductionTimer); @@ -1831,8 +1831,8 @@ void PlayerWheel::checkGiftOfLife() { sendGiftOfLifeCooldown(); } -int32_t PlayerWheel::checkBlessingGroveHealingByTarget(const Creature* target) const { - if (!target || target == &m_player) { +int32_t PlayerWheel::checkBlessingGroveHealingByTarget(std::shared_ptr target) const { + if (!target || target == m_player.getPlayer()) { return 0; } @@ -1860,8 +1860,8 @@ int32_t PlayerWheel::checkBlessingGroveHealingByTarget(const Creature* target) c return healingBonus; } -int32_t PlayerWheel::checkTwinBurstByTarget(const Creature* target) const { - if (!target || target == &m_player) { +int32_t PlayerWheel::checkTwinBurstByTarget(std::shared_ptr target) const { + if (!target || target == m_player.getPlayer()) { return 0; } @@ -1881,8 +1881,8 @@ int32_t PlayerWheel::checkTwinBurstByTarget(const Creature* target) const { return damageBonus; } -int32_t PlayerWheel::checkExecutionersThrow(const Creature* target) const { - if (!target || target == &m_player) { +int32_t PlayerWheel::checkExecutionersThrow(std::shared_ptr target) const { + if (!target || target == m_player.getPlayer()) { return 0; } @@ -1916,7 +1916,7 @@ int32_t PlayerWheel::checkBeamMasteryDamage() const { return damageBoost; } -int32_t PlayerWheel::checkDrainBodyLeech(const Creature* target, skills_t skill) const { +int32_t PlayerWheel::checkDrainBodyLeech(std::shared_ptr target, skills_t skill) const { if (!target || !target->getMonster() || target->getWheelOfDestinyDrainBodyDebuff() == 0) { return 0; } @@ -2036,7 +2036,7 @@ void PlayerWheel::onThink(bool force /* = false*/) { } m_player.sendSkills(); m_player.sendStats(); - g_game().reloadCreature(&m_player); + g_game().reloadCreature(m_player.getPlayer()); } return; } @@ -2074,7 +2074,7 @@ void PlayerWheel::reduceAllSpellsCooldownTimer(int32_t value) { for (Condition* condition : m_player.getConditionsByType(CONDITION_SPELLCOOLDOWN)) { if (condition->getTicks() <= value) { m_player.sendSpellCooldown(condition->getSubId(), 0); - condition->endCondition(&m_player); + condition->endCondition(m_player.getPlayer()); } else { condition->setTicks(condition->getTicks() - value); m_player.sendSpellCooldown(condition->getSubId(), condition->getTicks()); @@ -2612,7 +2612,7 @@ void PlayerWheel::healIfBattleHealingActive() const { CombatDamage damage; damage.primary.value = checkBattleHealingAmount(); damage.primary.type = COMBAT_HEALING; - g_game().combatChangeHealth(&m_player, &m_player, damage); + g_game().combatChangeHealth(m_player.getPlayer(), m_player.getPlayer(), damage); } } @@ -2628,8 +2628,8 @@ void PlayerWheel::adjustDamageBasedOnResistanceAndSkill(int32_t &damage, CombatT float PlayerWheel::calculateMitigation() const { int32_t skill = m_player.getSkillLevel(SKILL_SHIELD); int32_t defenseValue = 0; - const Item* weapon = m_player.inventory[CONST_SLOT_LEFT]; - const Item* shield = m_player.inventory[CONST_SLOT_RIGHT]; + std::shared_ptr weapon = m_player.inventory[CONST_SLOT_LEFT]; + std::shared_ptr shield = m_player.inventory[CONST_SLOT_RIGHT]; float fightFactor = 1.0f; float shieldFactor = 1.0f; diff --git a/src/creatures/players/wheel/player_wheel.hpp b/src/creatures/players/wheel/player_wheel.hpp index bf34418390c..70e55ff28d5 100644 --- a/src/creatures/players/wheel/player_wheel.hpp +++ b/src/creatures/players/wheel/player_wheel.hpp @@ -158,12 +158,13 @@ class PlayerWheel { bool checkBallisticMastery(); bool checkCombatMastery(); bool checkDivineEmpowerment(); - int32_t checkDrainBodyLeech(const Creature* target, skills_t skill) const; + int32_t checkDrainBodyLeech(std::shared_ptr target, skills_t skill) const; int32_t checkBeamMasteryDamage() const; int32_t checkBattleHealingAmount() const; - int32_t checkBlessingGroveHealingByTarget(const Creature* target) const; - int32_t checkTwinBurstByTarget(const Creature* target) const; - int32_t checkExecutionersThrow(const Creature* target) const; + int32_t checkBlessingGroveHealingByTarget(std::shared_ptr target) const; + int32_t checkTwinBurstByTarget(std::shared_ptr target) const; + int32_t checkExecutionersThrow(std::shared_ptr target) const; + int32_t checkDivineGrenade(std::shared_ptr target) const; int32_t checkAvatarSkill(WheelAvatarSkill_t skill) const; int32_t checkFocusMasteryDamage(); int32_t checkElementSensitiveReduction(CombatType_t type) const; diff --git a/src/game/bank/bank.cpp b/src/game/bank/bank.cpp index 3acc788d0df..56be07141e5 100644 --- a/src/game/bank/bank.cpp +++ b/src/game/bank/bank.cpp @@ -22,10 +22,10 @@ Bank::~Bank() { if (bankable == nullptr || bankable->isOnline()) { return; } - Player* player = bankable->getPlayer(); + std::shared_ptr player = bankable->getPlayer(); if (player && !player->isOnline()) { IOLoginData::savePlayer(player); - delete player; + return; } if (bankable->isGuild()) { @@ -100,7 +100,7 @@ bool Bank::transferTo(const std::shared_ptr destination, uint64_t amount) return debit(amount) && destination->credit(amount); } -bool Bank::withdraw(Player* player, uint64_t amount) { +bool Bank::withdraw(std::shared_ptr player, uint64_t amount) { if (!debit(amount)) { return false; } diff --git a/src/game/bank/bank.hpp b/src/game/bank/bank.hpp index d4ae9edf14f..c6db5aaae35 100644 --- a/src/game/bank/bank.hpp +++ b/src/game/bank/bank.hpp @@ -17,7 +17,7 @@ class Bankable { virtual void setBankBalance(uint64_t amount) = 0; [[nodiscard]] virtual uint64_t getBankBalance() const = 0; virtual ~Bankable() = default; - virtual Player* getPlayer() { + virtual std::shared_ptr getPlayer() { return nullptr; } virtual bool isGuild() { @@ -43,7 +43,7 @@ class Bank : public SharedObject { uint64_t balance(); bool hasBalance(uint64_t amount); bool transferTo(const std::shared_ptr destination, uint64_t amount); - bool withdraw(Player* player, uint64_t amount); + bool withdraw(std::shared_ptr player, uint64_t amount); bool deposit(const std::shared_ptr destination); bool deposit(const std::shared_ptr destination, uint64_t amount); diff --git a/src/game/game.cpp b/src/game/game.cpp index 7889c412cec..3eb0d50fd3b 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -49,7 +49,7 @@ #include "kv/kv.hpp" namespace InternalGame { - void sendBlockEffect(BlockType_t blockType, CombatType_t combatType, const Position &targetPos, Creature* source) { + void sendBlockEffect(BlockType_t blockType, CombatType_t combatType, const Position &targetPos, std::shared_ptr source) { if (blockType == BLOCK_DEFENSE) { g_game().addMagicEffect(targetPos, CONST_ME_POFF); } else if (blockType == BLOCK_ARMOR) { @@ -91,7 +91,7 @@ namespace InternalGame { } } - bool playerCanUseItemOnHouseTile(Player* player, Item* item) { + bool playerCanUseItemOnHouseTile(std::shared_ptr player, std::shared_ptr item) { if (!player || !item) { return false; } @@ -101,7 +101,7 @@ namespace InternalGame { return false; } - if (HouseTile* houseTile = dynamic_cast(itemTile)) { + if (std::shared_ptr houseTile = std::dynamic_pointer_cast(itemTile)) { House* house = houseTile->getHouse(); if (!house || !house->isInvited(player)) { return false; @@ -124,7 +124,7 @@ namespace InternalGame { return true; } - bool playerCanUseItemWithOnHouseTile(Player* player, Item* item, const Position &toPos, int toStackPos, int toItemId) { + bool playerCanUseItemWithOnHouseTile(std::shared_ptr player, std::shared_ptr item, const Position &toPos, int toStackPos, int toItemId) { if (!player || !item) { return false; } @@ -135,9 +135,9 @@ namespace InternalGame { } if (g_configManager().getBoolean(ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { - if (HouseTile* houseTile = dynamic_cast(itemTile)) { + if (std::shared_ptr houseTile = std::dynamic_pointer_cast(itemTile)) { House* house = houseTile->getHouse(); - Thing* targetThing = g_game().internalGetThing(player, toPos, toStackPos, toItemId, STACKPOS_FIND_THING); + std::shared_ptr targetThing = g_game().internalGetThing(player, toPos, toStackPos, toItemId, STACKPOS_FIND_THING); auto targetItem = targetThing ? targetThing->getItem() : nullptr; uint16_t targetId = targetItem ? targetItem->getID() : 0; auto invitedCheckUseWith = house && item->getRealParent() && item->getRealParent() != player && (!house->isInvited(player) || house->getHouseAccessLevel(player) == HOUSE_GUEST); @@ -152,7 +152,7 @@ namespace InternalGame { } template - T getCustomAttributeValue(const Item* item, const std::string &attributeName) { + T getCustomAttributeValue(std::shared_ptr item, const std::string &attributeName) { static_assert(std::is_integral::value, "T must be an integral type"); auto attribute = item->getCustomAttribute(attributeName); @@ -245,14 +245,14 @@ void Game::loadBoostedCreature() { if (selectedMonster.raceId == 0) { g_logger().warn("[Game::loadBoostedCreature] - " - "It was not possible to generate a new boosted creature."); + "It was not possible to generate a new boosted creature->"); return; } const auto monsterType = g_monsters().getMonsterType(selectedMonster.name); if (!monsterType) { g_logger().warn("[Game::loadBoostedCreature] - " - "It was not possible to generate a new boosted creature. Monster '" + "It was not possible to generate a new boosted creature-> Monster '" + selectedMonster.name + "' not found."); return; } @@ -499,7 +499,7 @@ void Game::loadMap(const std::string &path, const Position &pos) { map.loadMap(path, false, false, false, false, pos); } -Cylinder* Game::internalGetCylinder(Player* player, const Position &pos) { +std::shared_ptr Game::internalGetCylinder(std::shared_ptr player, const Position &pos) { if (pos.x != 0xFFFF) { return map.getTile(pos); } @@ -514,21 +514,21 @@ Cylinder* Game::internalGetCylinder(Player* player, const Position &pos) { return player; } -Thing* Game::internalGetThing(Player* player, const Position &pos, int32_t index, uint32_t itemId, StackPosType_t type) { +std::shared_ptr Game::internalGetThing(std::shared_ptr player, const Position &pos, int32_t index, uint32_t itemId, StackPosType_t type) { if (pos.x != 0xFFFF) { - Tile* tile = map.getTile(pos); + std::shared_ptr tile = map.getTile(pos); if (!tile) { return nullptr; } - Thing* thing; + std::shared_ptr thing; switch (type) { case STACKPOS_LOOK: { return tile->getTopVisibleThing(player); } case STACKPOS_MOVE: { - Item* item = tile->getTopDownItem(); + std::shared_ptr item = tile->getTopDownItem(); if (item && item->isMoveable()) { thing = item; } else { @@ -595,13 +595,13 @@ Thing* Game::internalGetThing(Player* player, const Position &pos, int32_t index if (pos.y & 0x40) { uint8_t fromCid = pos.y & 0x0F; - Container* parentContainer = player->getContainerByID(fromCid); + std::shared_ptr parentContainer = player->getContainerByID(fromCid); if (!parentContainer) { return nullptr; } if (parentContainer->getID() == ITEM_BROWSEFIELD) { - Tile* tile = parentContainer->getTile(); + std::shared_ptr tile = parentContainer->getTile(); if (tile && tile->hasFlag(TILESTATE_SUPPORTS_HANGABLE)) { if (tile->hasProperty(CONST_PROP_ISVERTICAL)) { if (player->getPosition().x + 1 == tile->getPosition().x) { @@ -653,18 +653,18 @@ Thing* Game::internalGetThing(Player* player, const Position &pos, int32_t index return player->getInventoryItem(slot); } -void Game::internalGetPosition(Item* item, Position &pos, uint8_t &stackpos) { +void Game::internalGetPosition(std::shared_ptr item, Position &pos, uint8_t &stackpos) { pos.x = 0; pos.y = 0; pos.z = 0; stackpos = 0; - Cylinder* topParent = item->getTopParent(); + std::shared_ptr topParent = item->getTopParent(); if (topParent) { - if (Player* player = dynamic_cast(topParent)) { + if (std::shared_ptr player = std::dynamic_pointer_cast(topParent)) { pos.x = 0xFFFF; - Container* container = dynamic_cast(item->getParent()); + std::shared_ptr container = std::dynamic_pointer_cast(item->getParent()); if (container) { pos.y = static_cast(0x40) | static_cast(player->getContainerID(container)); pos.z = container->getThingIndex(item); @@ -673,14 +673,14 @@ void Game::internalGetPosition(Item* item, Position &pos, uint8_t &stackpos) { pos.y = player->getThingIndex(item); stackpos = pos.y; } - } else if (Tile* tile = topParent->getTile()) { + } else if (std::shared_ptr tile = topParent->getTile()) { pos = tile->getPosition(); stackpos = tile->getThingIndex(item); } } } -Creature* Game::getCreatureByID(uint32_t id) { +std::shared_ptr Game::getCreatureByID(uint32_t id) { if (id >= Player::getFirstID() && id <= Player::getLastID()) { return getPlayerByID(id); } else if (id <= Monster::monsterAutoID) { @@ -693,7 +693,7 @@ Creature* Game::getCreatureByID(uint32_t id) { return nullptr; } -Monster* Game::getMonsterByID(uint32_t id) { +std::shared_ptr Game::getMonsterByID(uint32_t id) { if (id == 0) { return nullptr; } @@ -705,7 +705,7 @@ Monster* Game::getMonsterByID(uint32_t id) { return it->second; } -Npc* Game::getNpcByID(uint32_t id) { +std::shared_ptr Game::getNpcByID(uint32_t id) { if (id == 0) { return nullptr; } @@ -717,7 +717,7 @@ Npc* Game::getNpcByID(uint32_t id) { return it->second; } -Player* Game::getPlayerByID(uint32_t id, bool loadTmp /* = false */) { +std::shared_ptr Game::getPlayerByID(uint32_t id, bool loadTmp /* = false */) { auto playerMap = players.find(id); if (playerMap != players.end()) { return playerMap->second; @@ -726,14 +726,14 @@ Player* Game::getPlayerByID(uint32_t id, bool loadTmp /* = false */) { if (!loadTmp) { return nullptr; } - Player* tmpPlayer(nullptr); + std::shared_ptr tmpPlayer(nullptr); if (!IOLoginData::loadPlayerById(tmpPlayer, id)) { return nullptr; } return tmpPlayer; } -Creature* Game::getCreatureByName(const std::string &s) { +std::shared_ptr Game::getCreatureByName(const std::string &s) { if (s.empty()) { return nullptr; } @@ -759,7 +759,7 @@ Creature* Game::getCreatureByName(const std::string &s) { return nullptr; } -Npc* Game::getNpcByName(const std::string &s) { +std::shared_ptr Game::getNpcByName(const std::string &s) { if (s.empty()) { return nullptr; } @@ -773,7 +773,7 @@ Npc* Game::getNpcByName(const std::string &s) { return nullptr; } -Player* Game::getPlayerByName(const std::string &s, bool loadTmp /* = false */) { +std::shared_ptr Game::getPlayerByName(const std::string &s, bool loadTmp /* = false */) { if (s.empty()) { return nullptr; } @@ -783,9 +783,9 @@ Player* Game::getPlayerByName(const std::string &s, bool loadTmp /* = false */) if (!loadTmp) { return nullptr; } - Player* tmpPlayer = new Player(nullptr); + std::shared_ptr tmpPlayer = std::make_shared(nullptr); if (!IOLoginData::loadPlayerByName(tmpPlayer, s)) { - delete tmpPlayer; + return nullptr; } tmpPlayer->setOnline(false); @@ -794,7 +794,7 @@ Player* Game::getPlayerByName(const std::string &s, bool loadTmp /* = false */) return it->second; } -Player* Game::getPlayerByGUID(const uint32_t &guid) { +std::shared_ptr Game::getPlayerByGUID(const uint32_t &guid) { if (guid == 0) { return nullptr; } @@ -806,7 +806,7 @@ Player* Game::getPlayerByGUID(const uint32_t &guid) { return nullptr; } -ReturnValue Game::getPlayerByNameWildcard(const std::string &s, Player*&player) { +ReturnValue Game::getPlayerByNameWildcard(const std::string &s, std::shared_ptr &player) { size_t strlen = s.length(); if (strlen == 0 || strlen > 20) { return RETURNVALUE_PLAYERWITHTHISNAMEISNOTONLINE; @@ -832,7 +832,7 @@ ReturnValue Game::getPlayerByNameWildcard(const std::string &s, Player*&player) return RETURNVALUE_NOERROR; } -Player* Game::getPlayerByAccount(uint32_t acc) { +std::shared_ptr Game::getPlayerByAccount(uint32_t acc) { for (const auto &it : players) { if (it.second->getAccountId() == acc) { return it.second; @@ -841,7 +841,7 @@ Player* Game::getPlayerByAccount(uint32_t acc) { return nullptr; } -bool Game::internalPlaceCreature(Creature* creature, const Position &pos, bool extendedPos /*=false*/, bool forced /*= false*/, bool creatureCheck /*= false*/) { +bool Game::internalPlaceCreature(std::shared_ptr creature, const Position &pos, bool extendedPos /*=false*/, bool forced /*= false*/, bool creatureCheck /*= false*/) { if (creature->getParent() != nullptr) { return false; } @@ -866,7 +866,7 @@ bool Game::internalPlaceCreature(Creature* creature, const Position &pos, bool e return true; } -bool Game::placeCreature(Creature* creature, const Position &pos, bool extendedPos /*=false*/, bool forced /*= false*/) { +bool Game::placeCreature(std::shared_ptr creature, const Position &pos, bool extendedPos /*=false*/, bool forced /*= false*/) { if (!internalPlaceCreature(creature, pos, extendedPos, forced)) { return false; } @@ -874,8 +874,8 @@ bool Game::placeCreature(Creature* creature, const Position &pos, bool extendedP bool hasPlayerSpectators = false; SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true); - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (std::shared_ptr spectator : spectators) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendCreatureAppear(creature, creature->getPosition(), true); hasPlayerSpectators = true; } @@ -891,19 +891,19 @@ bool Game::placeCreature(Creature* creature, const Position &pos, bool extendedP return true; } -bool Game::removeCreature(Creature* creature, bool isLogout /* = true*/) { +bool Game::removeCreature(std::shared_ptr creature, bool isLogout /* = true*/) { if (creature->isRemoved()) { return false; } - Tile* tile = creature->getTile(); + std::shared_ptr tile = creature->getTile(); std::vector oldStackPosVector; SpectatorHashSet spectators; map.getSpectators(spectators, tile->getPosition(), true); - for (Creature* spectator : spectators) { - if (Player* player = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto player = spectator->getPlayer()) { oldStackPosVector.push_back(player->canSeeCreature(creature) ? tile->getStackposOfCreature(player, creature) : -1); } } @@ -914,14 +914,14 @@ bool Game::removeCreature(Creature* creature, bool isLogout /* = true*/) { // send to client size_t i = 0; - for (Creature* spectator : spectators) { - if (Player* player = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto player = spectator->getPlayer()) { player->sendRemoveTileThing(tilePosition, oldStackPosVector[i++]); } } // event method - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->onRemoveCreature(creature, isLogout); } @@ -938,7 +938,7 @@ bool Game::removeCreature(Creature* creature, bool isLogout /* = true*/) { removeCreatureCheck(creature); - for (Creature* summon : creature->summons) { + for (auto summon : creature->summons) { summon->setSkillLoss(false); removeCreature(summon); } @@ -954,7 +954,7 @@ bool Game::removeCreature(Creature* creature, bool isLogout /* = true*/) { } void Game::executeDeath(uint32_t creatureId) { - Creature* creature = getCreatureByID(creatureId); + std::shared_ptr creature = getCreatureByID(creatureId); if (creature && !creature->isRemoved()) { creature->onDeath(); afterCreatureZoneChange(creature, creature->getZones(), {}); @@ -962,7 +962,7 @@ void Game::executeDeath(uint32_t creatureId) { } void Game::playerTeleport(uint32_t playerId, const Position &newPosition) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->hasFlag(PlayerFlags_t::CanMapClickTeleport)) { return; } @@ -973,14 +973,14 @@ void Game::playerTeleport(uint32_t playerId, const Position &newPosition) { } } -void Game::playerInspectItem(Player* player, const Position &pos) { - Thing* thing = internalGetThing(player, pos, 0, 0, STACKPOS_TOPDOWN_ITEM); +void Game::playerInspectItem(std::shared_ptr player, const Position &pos) { + std::shared_ptr thing = internalGetThing(player, pos, 0, 0, STACKPOS_TOPDOWN_ITEM); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -989,7 +989,7 @@ void Game::playerInspectItem(Player* player, const Position &pos) { player->sendItemInspection(item->getID(), static_cast(item->getItemCount()), item, false); } -void Game::playerInspectItem(Player* player, uint16_t itemId, uint8_t itemCount, bool cyclopedia) { +void Game::playerInspectItem(std::shared_ptr player, uint16_t itemId, uint8_t itemCount, bool cyclopedia) { player->sendItemInspection(itemId, itemCount, nullptr, cyclopedia); } @@ -1043,7 +1043,7 @@ FILELOADER_ERRORS Game::loadAppearanceProtobuf(const std::string &file) { } void Game::playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -1070,14 +1070,14 @@ void Game::playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t fromIndex = fromStackPos; } - Thing* thing = internalGetThing(player, fromPos, fromIndex, itemId, STACKPOS_MOVE); + std::shared_ptr thing = internalGetThing(player, fromPos, fromIndex, itemId, STACKPOS_MOVE); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; } - if (Creature* movingCreature = thing->getCreature()) { - Tile* tile = map.getTile(toPos); + if (std::shared_ptr movingCreature = thing->getCreature()) { + std::shared_ptr tile = map.getTile(toPos); if (!tile) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -1094,7 +1094,7 @@ void Game::playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t playerMoveCreature(player, movingCreature, movingCreature->getPosition(), tile); } } else if (thing->getItem()) { - Cylinder* toCylinder = internalGetCylinder(player, toPos); + std::shared_ptr toCylinder = internalGetCylinder(player, toPos); if (!toCylinder) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -1105,17 +1105,17 @@ void Game::playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t } void Game::playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, const Position &movingCreatureOrigPos, const Position &toPos) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Creature* movingCreature = getCreatureByID(movingCreatureId); + std::shared_ptr movingCreature = getCreatureByID(movingCreatureId); if (!movingCreature) { return; } - Tile* toTile = map.getTile(toPos); + std::shared_ptr toTile = map.getTile(toPos); if (!toTile) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -1124,7 +1124,7 @@ void Game::playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, playerMoveCreature(player, movingCreature, movingCreatureOrigPos, toTile); } -void Game::playerMoveCreature(Player* player, Creature* movingCreature, const Position &movingCreatureOrigPos, Tile* toTile) { +void Game::playerMoveCreature(std::shared_ptr player, std::shared_ptr movingCreature, const Position &movingCreatureOrigPos, std::shared_ptr toTile) { if (!player->canDoAction()) { uint32_t delay = 600; std::shared_ptr task = createPlayerTask(delay, std::bind(&Game::playerMoveCreatureByID, this, player->getID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()), "Game::playerMoveCreatureByID"); @@ -1152,7 +1152,7 @@ void Game::playerMoveCreature(Player* player, Creature* movingCreature, const Po } player->pushEvent(false); - const Monster* monster = movingCreature->getMonster(); + std::shared_ptr monster = movingCreature->getMonster(); bool isFamiliar = false; if (monster) { isFamiliar = monster->isFamiliar(); @@ -1180,7 +1180,7 @@ void Game::playerMoveCreature(Player* player, Creature* movingCreature, const Po return; } else { if (CreatureVector* tileCreatures = toTile->getCreatures()) { - for (Creature* tileCreature : *tileCreatures) { + for (auto &tileCreature : *tileCreatures) { if (!tileCreature->isInGhostMode()) { player->sendCancelMessage(RETURNVALUE_NOTENOUGHROOM); return; @@ -1188,7 +1188,7 @@ void Game::playerMoveCreature(Player* player, Creature* movingCreature, const Po } } - Npc* movingNpc = movingCreature->getNpc(); + auto movingNpc = movingCreature->getNpc(); if (movingNpc && movingNpc->canInteract(toPos)) { player->sendCancelMessage(RETURNVALUE_NOTENOUGHROOM); return; @@ -1206,14 +1206,14 @@ void Game::playerMoveCreature(Player* player, Creature* movingCreature, const Po return; } - ReturnValue ret = internalMoveCreature(*movingCreature, *toTile); + ReturnValue ret = internalMoveCreature(movingCreature, toTile); if (ret != RETURNVALUE_NOERROR) { player->sendCancelMessage(ret); } player->setLastPosition(player->getPosition()); } -ReturnValue Game::internalMoveCreature(Creature* creature, Direction direction, uint32_t flags /*= 0*/) { +ReturnValue Game::internalMoveCreature(std::shared_ptr creature, Direction direction, uint32_t flags /*= 0*/) { if (!creature) { return RETURNVALUE_NOTPOSSIBLE; } @@ -1221,14 +1221,14 @@ ReturnValue Game::internalMoveCreature(Creature* creature, Direction direction, creature->setLastPosition(creature->getPosition()); const Position ¤tPos = creature->getPosition(); Position destPos = getNextPosition(direction, currentPos); - Player* player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); bool diagonalMovement = (direction & DIRECTION_DIAGONAL_MASK) != 0; if (player && !diagonalMovement) { // try go up auto tile = creature->getTile(); if (currentPos.z != 8 && tile && tile->hasHeight(3)) { - Tile* tmpTile = map.getTile(currentPos.x, currentPos.y, currentPos.getZ() - 1); + std::shared_ptr tmpTile = map.getTile(currentPos.x, currentPos.y, currentPos.getZ() - 1); if (tmpTile == nullptr || (tmpTile->getGround() == nullptr && !tmpTile->hasFlag(TILESTATE_BLOCKSOLID))) { tmpTile = map.getTile(destPos.x, destPos.y, destPos.getZ() - 1); if (tmpTile && tmpTile->getGround() && !tmpTile->hasFlag(TILESTATE_BLOCKSOLID)) { @@ -1244,7 +1244,7 @@ ReturnValue Game::internalMoveCreature(Creature* creature, Direction direction, // try go down if (currentPos.z != 7 && currentPos.z == destPos.z) { - Tile* tmpTile = map.getTile(destPos.x, destPos.y, destPos.z); + std::shared_ptr tmpTile = map.getTile(destPos.x, destPos.y, destPos.z); if (tmpTile == nullptr || (tmpTile->getGround() == nullptr && !tmpTile->hasFlag(TILESTATE_BLOCKSOLID))) { tmpTile = map.getTile(destPos.x, destPos.y, destPos.z + 1); if (tmpTile && tmpTile->hasHeight(3)) { @@ -1256,51 +1256,51 @@ ReturnValue Game::internalMoveCreature(Creature* creature, Direction direction, } } - Tile* toTile = map.getTile(destPos); + std::shared_ptr toTile = map.getTile(destPos); if (!toTile) { return RETURNVALUE_NOTPOSSIBLE; } - return internalMoveCreature(*creature, *toTile, flags); + return internalMoveCreature(creature, toTile, flags); } -ReturnValue Game::internalMoveCreature(Creature &creature, Tile &toTile, uint32_t flags /*= 0*/) { - if (creature.hasCondition(CONDITION_ROOTED)) { +ReturnValue Game::internalMoveCreature(const std::shared_ptr &creature, const std::shared_ptr &toTile, uint32_t flags /*= 0*/) { + if (creature->hasCondition(CONDITION_ROOTED)) { return RETURNVALUE_NOTPOSSIBLE; } // check if we can move the creature to the destination - ReturnValue ret = toTile.queryAdd(0, creature, 1, flags); + ReturnValue ret = toTile->queryAdd(0, creature, 1, flags); if (ret != RETURNVALUE_NOERROR) { return ret; } - if (creature.hasCondition(CONDITION_ROOTED)) { + if (creature->hasCondition(CONDITION_ROOTED)) { return RETURNVALUE_NOTPOSSIBLE; } - if (creature.hasCondition(CONDITION_FEARED)) { - const MagicField* field = toTile.getFieldItem(); + if (creature->hasCondition(CONDITION_FEARED)) { + std::shared_ptr field = toTile->getFieldItem(); if (field && !field->isBlocking() && field->getDamage() != 0) { return RETURNVALUE_NOTPOSSIBLE; } } map.moveCreature(creature, toTile); - if (creature.getParent() != &toTile) { + if (creature->getParent() != toTile) { return RETURNVALUE_NOERROR; } int32_t index = 0; - Item* toItem = nullptr; - Tile* subCylinder = nullptr; - Tile* toCylinder = &toTile; - Tile* fromCylinder = nullptr; + std::shared_ptr toItem = nullptr; + std::shared_ptr subCylinder = nullptr; + std::shared_ptr toCylinder = toTile; + std::shared_ptr fromCylinder = nullptr; uint32_t n = 0; - while ((subCylinder = toCylinder->queryDestination(index, creature, &toItem, flags)) != toCylinder) { - map.moveCreature(creature, *subCylinder); + while ((subCylinder = toCylinder->queryDestination(index, creature, &toItem, flags)->getTile()) != toCylinder) { + map.moveCreature(creature, subCylinder); - if (creature.getParent() != subCylinder) { + if (creature->getParent() != subCylinder) { // could happen if a script move the creature fromCylinder = nullptr; break; @@ -1322,7 +1322,7 @@ ReturnValue Game::internalMoveCreature(Creature &creature, Tile &toTile, uint32_ if (fromPosition.z != toPosition.z && (fromPosition.x != toPosition.x || fromPosition.y != toPosition.y)) { Direction dir = getDirectionTo(fromPosition, toPosition); if ((dir & DIRECTION_DIAGONAL_MASK) == 0) { - internalCreatureTurn(&creature, dir); + internalCreatureTurn(creature, dir); } } } @@ -1331,14 +1331,14 @@ ReturnValue Game::internalMoveCreature(Creature &creature, Tile &toTile, uint32_ } void Game::playerMoveItemByPlayerID(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } playerMoveItem(player, fromPos, itemId, fromStackPos, toPos, count, nullptr, nullptr); } -void Game::playerMoveItem(Player* player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, Item* item, Cylinder* toCylinder) { +void Game::playerMoveItem(std::shared_ptr player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder) { if (!player->canDoAction()) { uint32_t delay = player->getNextActionTime(); std::shared_ptr task = createPlayerTask(delay, std::bind(&Game::playerMoveItemByPlayerID, this, player->getID(), fromPos, itemId, fromStackPos, toPos, count), "Game::playerMoveItemByPlayerID"); @@ -1366,7 +1366,7 @@ void Game::playerMoveItem(Player* player, const Position &fromPos, uint16_t item fromIndex = fromStackPos; } - Thing* thing = internalGetThing(player, fromPos, fromIndex, itemId, STACKPOS_MOVE); + std::shared_ptr thing = internalGetThing(player, fromPos, fromIndex, itemId, STACKPOS_MOVE); if (!thing || !thing->getItem()) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -1380,7 +1380,7 @@ void Game::playerMoveItem(Player* player, const Position &fromPos, uint16_t item return; } - Cylinder* fromCylinder = nullptr; + std::shared_ptr fromCylinder = nullptr; if (fromPos.x == 0xFFFF && (fromPos.y == 0x20 || fromPos.y == 0x21)) { // '0x20' -> From depot. // '0x21' -> From inbox. @@ -1446,7 +1446,7 @@ void Game::playerMoveItem(Player* player, const Position &fromPos, uint16_t item return; } - const Tile* toCylinderTile = toCylinder->getTile(); + std::shared_ptr toCylinderTile = toCylinder->getTile(); const Position &mapToPos = toCylinderTile->getPosition(); // hangable item specific code @@ -1479,7 +1479,7 @@ void Game::playerMoveItem(Player* player, const Position &fromPos, uint16_t item if (fromPos.x != 0xFFFF && Position::areInRange<1, 1>(mapFromPos, playerPos) && !Position::areInRange<1, 1, 0>(mapFromPos, walkPos)) { // need to pickup the item first - Item* moveItem = nullptr; + std::shared_ptr moveItem = nullptr; ReturnValue ret = internalMoveItem(fromCylinder, player, INDEX_WHEREEVER, item, count, &moveItem); if (ret != RETURNVALUE_NOERROR) { @@ -1532,8 +1532,8 @@ void Game::playerMoveItem(Player* player, const Position &fromPos, uint16_t item } if (item->isWrapable()) { - HouseTile* toHouseTile = dynamic_cast(map.getTile(mapToPos)); - HouseTile* fromHouseTile = dynamic_cast(map.getTile(mapFromPos)); + auto toHouseTile = map.getTile(mapToPos)->dynamic_self_cast(); + auto fromHouseTile = map.getTile(mapFromPos)->dynamic_self_cast(); if (fromHouseTile && (!toHouseTile || toHouseTile->getHouse()->getId() != fromHouseTile->getHouse()->getId())) { player->sendCancelMessage("You can't move this item outside a house."); return; @@ -1554,22 +1554,21 @@ void Game::playerMoveItem(Player* player, const Position &fromPos, uint16_t item g_callbacks().executeCallback(EventCallback_t::playerOnItemMoved, &EventCallback::playerOnItemMoved, player, item, count, fromPos, toPos, fromCylinder, toCylinder); } -bool Game::isTryingToStow(const Position &toPos, Cylinder* toCylinder) const { +bool Game::isTryingToStow(const Position &toPos, std::shared_ptr toCylinder) const { return toCylinder->getContainer() && toCylinder->getItem()->getID() == ITEM_LOCKER && toPos.getZ() == ITEM_SUPPLY_STASH_INDEX; } -ReturnValue Game::checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder, Cylinder* toCylinder, Item* item, Position toPos) { +ReturnValue Game::checkMoveItemToCylinder(std::shared_ptr player, std::shared_ptr fromCylinder, std::shared_ptr toCylinder, std::shared_ptr item, Position toPos) { if (!player || !toCylinder || !item) { return RETURNVALUE_NOTPOSSIBLE; } - if (Container* toCylinderContainer = toCylinder->getContainer()) { + if (std::shared_ptr toCylinderContainer = toCylinder->getContainer()) { auto containerID = toCylinderContainer->getID(); // check the store inbox index if gold pouch forces it as containerID if (containerID == ITEM_STORE_INBOX) { - Item* cylinderItem = toCylinderContainer->getItemByIndex(toPos.getZ()); - + auto cylinderItem = toCylinderContainer->getItemByIndex(toPos.getZ()); if (cylinderItem && cylinderItem->getID() == ITEM_GOLD_POUCH) { containerID = ITEM_GOLD_POUCH; } @@ -1594,7 +1593,7 @@ ReturnValue Game::checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder return RETURNVALUE_NOERROR; } - const Container* topParentContainer = toCylinderContainer->getRootContainer(); + std::shared_ptr topParentContainer = toCylinderContainer->getRootContainer(); const auto parentContainer = topParentContainer->getParent() ? topParentContainer->getParent()->getContainer() : nullptr; auto isStoreInbox = parentContainer && parentContainer->isStoreInbox(); if (!item->isStoreItem() && (containerID == ITEM_STORE_INBOX || isStoreInbox)) { @@ -1603,7 +1602,7 @@ ReturnValue Game::checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder if (item->isStoreItem()) { bool isValidMoveItem = false; - if (HouseTile* fromHouseTile = dynamic_cast(fromCylinder->getTile()); fromHouseTile && fromHouseTile->getHouse()->getOwner() != player->getGUID()) { + if (auto fromHouseTile = fromCylinder->getTile()->dynamic_self_cast(); fromHouseTile && fromHouseTile->getHouse()->getOwner() != player->getGUID()) { return RETURNVALUE_NOTPOSSIBLE; } @@ -1621,14 +1620,14 @@ ReturnValue Game::checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder } if (item->getContainer() && !item->isStoreItem()) { - for (Item* containerItem : item->getContainer()->getItems(true)) { + for (std::shared_ptr containerItem : item->getContainer()->getItems(true)) { if (containerItem->isStoreItem() && ((containerID != ITEM_GOLD_POUCH && containerID != ITEM_DEPOT && containerID != ITEM_STORE_INBOX) || (topParentContainer->getParent() && topParentContainer->getParent()->getContainer() && (!topParentContainer->getParent()->getContainer()->isDepotChest() || topParentContainer->getParent()->getContainer()->getID() != ITEM_STORE_INBOX)))) { return RETURNVALUE_NOTPOSSIBLE; } } } } else if (toCylinder->getTile()) { - HouseTile* toHouseTile = dynamic_cast(toCylinder->getTile()); + std::shared_ptr toHouseTile = std::dynamic_pointer_cast(toCylinder->getTile()); if (fromCylinder->getContainer()) { if (item->isStoreItem()) { if (!toHouseTile || toHouseTile && toHouseTile->getHouse()->getOwner() != player->getGUID()) { @@ -1636,7 +1635,7 @@ ReturnValue Game::checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder } } if (item->getContainer() && !item->isStoreItem()) { - for (Item* containerItem : item->getContainer()->getItems(true)) { + for (std::shared_ptr containerItem : item->getContainer()->getItems(true)) { if (containerItem->isStoreItem()) { return RETURNVALUE_NOTPOSSIBLE; } @@ -1654,7 +1653,7 @@ ReturnValue Game::checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder return RETURNVALUE_NOERROR; } -ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, int32_t index, Item* item, uint32_t count, Item** movedItem, uint32_t flags /*= 0*/, Creature* actor /*=nullptr*/, Item* tradeItem /* = nullptr*/, bool checkTile /* = true*/) { +ReturnValue Game::internalMoveItem(std::shared_ptr fromCylinder, std::shared_ptr toCylinder, int32_t index, std::shared_ptr item, uint32_t count, std::shared_ptr* movedItem, uint32_t flags /*= 0*/, std::shared_ptr actor /*=nullptr*/, std::shared_ptr tradeItem /* = nullptr*/, bool checkTile /* = true*/) { if (fromCylinder == nullptr) { g_logger().error("[{}] fromCylinder is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; @@ -1665,7 +1664,7 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, } if (checkTile) { - if (Tile* fromTile = fromCylinder->getTile()) { + if (std::shared_ptr fromTile = fromCylinder->getTile()) { auto it = browseFields.find(fromTile); if (it != browseFields.end() && it->second == fromCylinder) { fromCylinder = fromTile; @@ -1673,12 +1672,12 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, } } - Item* toItem = nullptr; + std::shared_ptr toItem = nullptr; - Cylinder* subCylinder; + std::shared_ptr subCylinder; int floorN = 0; - while ((subCylinder = toCylinder->queryDestination(index, *item, &toItem, flags)) != toCylinder) { + while ((subCylinder = toCylinder->queryDestination(index, item, &toItem, flags)) != toCylinder) { toCylinder = subCylinder; flags = 0; @@ -1700,20 +1699,20 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, } // check if we can add this item - ReturnValue ret = toCylinder->queryAdd(index, *item, count, flags, actor); + ReturnValue ret = toCylinder->queryAdd(index, item, count, flags, actor); if (ret == RETURNVALUE_NEEDEXCHANGE) { // check if we can add it to source cylinder - ret = fromCylinder->queryAdd(fromCylinder->getThingIndex(item), *toItem, toItem->getItemCount(), 0); + ret = fromCylinder->queryAdd(fromCylinder->getThingIndex(item), toItem, toItem->getItemCount(), 0); if (ret == RETURNVALUE_NOERROR) { // check how much we can move uint32_t maxExchangeQueryCount = 0; - ReturnValue retExchangeMaxCount = fromCylinder->queryMaxCount(INDEX_WHEREEVER, *toItem, toItem->getItemCount(), maxExchangeQueryCount, 0); + ReturnValue retExchangeMaxCount = fromCylinder->queryMaxCount(INDEX_WHEREEVER, toItem, toItem->getItemCount(), maxExchangeQueryCount, 0); if (retExchangeMaxCount != RETURNVALUE_NOERROR && maxExchangeQueryCount == 0) { return retExchangeMaxCount; } - if (toCylinder->queryRemove(*toItem, toItem->getItemCount(), flags, actor) == RETURNVALUE_NOERROR) { + if (toCylinder->queryRemove(toItem, toItem->getItemCount(), flags, actor) == RETURNVALUE_NOERROR) { int32_t oldToItemIndex = toCylinder->getThingIndex(toItem); toCylinder->removeThing(toItem, toItem->getItemCount()); fromCylinder->addThing(toItem); @@ -1727,7 +1726,7 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, fromCylinder->postAddNotification(toItem, toCylinder, newToItemIndex); } - ret = toCylinder->queryAdd(index, *item, count, flags); + ret = toCylinder->queryAdd(index, item, count, flags); toItem = nullptr; } } @@ -1739,7 +1738,7 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, // check how much we can move uint32_t maxQueryCount = 0; - ReturnValue retMaxCount = toCylinder->queryMaxCount(index, *item, count, maxQueryCount, flags); + ReturnValue retMaxCount = toCylinder->queryMaxCount(index, item, count, maxQueryCount, flags); if (retMaxCount != RETURNVALUE_NOERROR && maxQueryCount == 0) { return retMaxCount; } @@ -1751,9 +1750,9 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, m = maxQueryCount; } - Item* moveItem = item; + std::shared_ptr moveItem = item; // check if we can remove this item - ret = fromCylinder->queryRemove(*item, m, flags, actor); + ret = fromCylinder->queryRemove(item, m, flags, actor); if (ret != RETURNVALUE_NOERROR) { return ret; } @@ -1763,7 +1762,7 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, return RETURNVALUE_NOTENOUGHROOM; } - Cylinder* tmpCylinder = toCylinder->getParent(); + std::shared_ptr tmpCylinder = toCylinder->getParent(); while (tmpCylinder) { if (tmpCylinder->getItem() == tradeItem) { return RETURNVALUE_NOTENOUGHROOM; @@ -1775,7 +1774,7 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, // remove the item int32_t itemIndex = fromCylinder->getThingIndex(item); - Item* updateItem = nullptr; + std::shared_ptr updateItem = nullptr; fromCylinder->removeThing(item, m); // update item(s) @@ -1837,7 +1836,7 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, } } - Item* quiver = toCylinder->getItem(); + std::shared_ptr quiver = toCylinder->getItem(); if (quiver && quiver->isQuiver() && quiver->getHoldingPlayer() && quiver->getHoldingPlayer()->getThing(CONST_SLOT_RIGHT) == quiver) { @@ -1880,7 +1879,7 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, return ret; } - if (Player* player = actor->getPlayer()) { + if (std::shared_ptr player = actor->getPlayer()) { // Refresh depot search window if necessary if (player->isDepotSearchOpenOnItem(item->getID()) && ((fromCylinder->getItem() && fromCylinder->getItem()->isInsideDepot(true)) || (toCylinder->getItem() && toCylinder->getItem()->isInsideDepot(true)))) { player->requestDepotSearchItem(item->getID(), item->getTier()); @@ -1901,12 +1900,12 @@ ReturnValue Game::internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, return ret; } -ReturnValue Game::internalAddItem(Cylinder* toCylinder, Item* item, int32_t index /*= INDEX_WHEREEVER*/, uint32_t flags /* = 0*/, bool test /* = false*/) { +ReturnValue Game::internalAddItem(std::shared_ptr toCylinder, std::shared_ptr item, int32_t index /*= INDEX_WHEREEVER*/, uint32_t flags /* = 0*/, bool test /* = false*/) { uint32_t remainderCount = 0; return internalAddItem(toCylinder, item, index, flags, test, remainderCount); } -ReturnValue Game::internalAddItem(Cylinder* toCylinder, Item* item, int32_t index, uint32_t flags, bool test, uint32_t &remainderCount) { +ReturnValue Game::internalAddItem(std::shared_ptr toCylinder, std::shared_ptr item, int32_t index, uint32_t flags, bool test, uint32_t &remainderCount) { if (toCylinder == nullptr) { g_logger().error("[{}] fromCylinder is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; @@ -1918,12 +1917,12 @@ ReturnValue Game::internalAddItem(Cylinder* toCylinder, Item* item, int32_t inde auto addedItem = toCylinder->getItem(); - Cylinder* destCylinder = toCylinder; - Item* toItem = nullptr; - toCylinder = toCylinder->queryDestination(index, *item, &toItem, flags); + std::shared_ptr destCylinder = toCylinder; + std::shared_ptr toItem = nullptr; + toCylinder = toCylinder->queryDestination(index, item, &toItem, flags); // check if we can add this item - ReturnValue ret = toCylinder->queryAdd(index, *item, item->getItemCount(), flags); + ReturnValue ret = toCylinder->queryAdd(index, item, item->getItemCount(), flags); if (ret != RETURNVALUE_NOERROR) { return ret; } @@ -1933,7 +1932,7 @@ ReturnValue Game::internalAddItem(Cylinder* toCylinder, Item* item, int32_t inde since the queryDestination can return a cylinder that might only hold a part of the full amount. */ uint32_t maxQueryCount = 0; - ret = destCylinder->queryMaxCount(INDEX_WHEREEVER, *item, item->getItemCount(), maxQueryCount, flags); + ret = destCylinder->queryMaxCount(INDEX_WHEREEVER, item, item->getItemCount(), maxQueryCount, flags); if (ret != RETURNVALUE_NOERROR && addedItem && addedItem->getID() != ITEM_REWARD_CONTAINER) { return ret; @@ -1952,7 +1951,7 @@ ReturnValue Game::internalAddItem(Cylinder* toCylinder, Item* item, int32_t inde int32_t count = m - n; if (count > 0) { if (item->getItemCount() != count) { - Item* remainderItem = item->clone(); + std::shared_ptr remainderItem = item->clone(); remainderItem->setItemCount(count); if (internalAddItem(destCylinder, remainderItem, INDEX_WHEREEVER, flags, false) != RETURNVALUE_NOERROR) { ReleaseItem(remainderItem); @@ -1994,17 +1993,17 @@ ReturnValue Game::internalAddItem(Cylinder* toCylinder, Item* item, int32_t inde return RETURNVALUE_NOERROR; } -ReturnValue Game::internalRemoveItem(Item* item, int32_t count /*= -1*/, bool test /*= false*/, uint32_t flags /*= 0*/, bool force /*= false*/) { +ReturnValue Game::internalRemoveItem(std::shared_ptr item, int32_t count /*= -1*/, bool test /*= false*/, uint32_t flags /*= 0*/, bool force /*= false*/) { if (item == nullptr) { g_logger().debug("{} - Item is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; } - Cylinder* cylinder = item->getParent(); + std::shared_ptr cylinder = item->getParent(); if (cylinder == nullptr) { g_logger().debug("{} - Cylinder is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; } - Tile* fromTile = cylinder->getTile(); + std::shared_ptr fromTile = cylinder->getTile(); if (fromTile) { auto it = browseFields.find(fromTile); if (it != browseFields.end() && it->second == cylinder) { @@ -2014,7 +2013,7 @@ ReturnValue Game::internalRemoveItem(Item* item, int32_t count /*= -1*/, bool te if (count == -1) { count = item->getItemCount(); } - ReturnValue ret = cylinder->queryRemove(*item, count, flags | FLAG_IGNORENOTMOVEABLE); + ReturnValue ret = cylinder->queryRemove(item, count, flags | FLAG_IGNORENOTMOVEABLE); if (!force && ret != RETURNVALUE_NOERROR) { g_logger().debug("{} - Failed to execute query remove", __FUNCTION__); return ret; @@ -2045,7 +2044,7 @@ ReturnValue Game::internalRemoveItem(Item* item, int32_t count /*= -1*/, bool te cylinder->postRemoveNotification(item, nullptr, index); } - Item* quiver = cylinder->getItem(); + std::shared_ptr quiver = cylinder->getItem(); if (quiver && quiver->isQuiver() && quiver->getHoldingPlayer() && quiver->getHoldingPlayer()->getThing(CONST_SLOT_RIGHT) == quiver) { @@ -2055,11 +2054,11 @@ ReturnValue Game::internalRemoveItem(Item* item, int32_t count /*= -1*/, bool te return RETURNVALUE_NOERROR; } -ReturnValue Game::internalPlayerAddItem(Player* player, Item* item, bool dropOnMap /*= true*/, Slots_t slot /*= CONST_SLOT_WHEREEVER*/) { +ReturnValue Game::internalPlayerAddItem(std::shared_ptr player, std::shared_ptr item, bool dropOnMap /*= true*/, Slots_t slot /*= CONST_SLOT_WHEREEVER*/) { uint32_t remainderCount = 0; ReturnValue ret = internalAddItem(player, item, static_cast(slot), 0, false, remainderCount); if (remainderCount != 0) { - Item* remainderItem = Item::CreateItem(item->getID(), remainderCount); + std::shared_ptr remainderItem = Item::CreateItem(item->getID(), remainderCount); ReturnValue remaindRet = internalAddItem(player->getTile(), remainderItem, INDEX_WHEREEVER, FLAG_NOLIMIT); if (remaindRet != RETURNVALUE_NOERROR) { ReleaseItem(remainderItem); @@ -2078,20 +2077,20 @@ ReturnValue Game::internalPlayerAddItem(Player* player, Item* item, bool dropOnM return ret; } -Item* Game::findItemOfType(const Cylinder* cylinder, uint16_t itemId, bool depthSearch /*= true*/, int32_t subType /*= -1*/) const { +std::shared_ptr Game::findItemOfType(std::shared_ptr cylinder, uint16_t itemId, bool depthSearch /*= true*/, int32_t subType /*= -1*/) const { if (cylinder == nullptr) { g_logger().error("[{}] Cylinder is nullptr", __FUNCTION__); return nullptr; } - std::vector containers; + std::vector> containers; for (size_t i = cylinder->getFirstIndex(), j = cylinder->getLastIndex(); i < j; ++i) { - Thing* thing = cylinder->getThing(i); + std::shared_ptr thing = cylinder->getThing(i); if (!thing) { continue; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item) { continue; } @@ -2101,7 +2100,7 @@ Item* Game::findItemOfType(const Cylinder* cylinder, uint16_t itemId, bool depth } if (depthSearch) { - Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container) { containers.push_back(container); } @@ -2110,13 +2109,13 @@ Item* Game::findItemOfType(const Cylinder* cylinder, uint16_t itemId, bool depth size_t i = 0; while (i < containers.size()) { - Container* container = containers[i++]; - for (Item* item : container->getItemList()) { + std::shared_ptr container = containers[i++]; + for (std::shared_ptr item : container->getItemList()) { if (item->getID() == itemId && (subType == -1 || subType == item->getSubType())) { return item; } - Container* subContainer = item->getContainer(); + std::shared_ptr subContainer = item->getContainer(); if (subContainer) { containers.push_back(subContainer); } @@ -2125,7 +2124,7 @@ Item* Game::findItemOfType(const Cylinder* cylinder, uint16_t itemId, bool depth return nullptr; } -bool Game::removeMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/, bool useBalance /*= false*/) { +bool Game::removeMoney(std::shared_ptr cylinder, uint64_t money, uint32_t flags /*= 0*/, bool useBalance /*= false*/) { if (cylinder == nullptr) { g_logger().error("[{}] cylinder is nullptr", __FUNCTION__); return false; @@ -2133,19 +2132,19 @@ bool Game::removeMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0* if (money == 0) { return true; } - std::vector containers; - std::multimap moneyMap; + std::vector> containers; + std::multimap> moneyMap; uint64_t moneyCount = 0; for (size_t i = cylinder->getFirstIndex(), j = cylinder->getLastIndex(); i < j; ++i) { - Thing* thing = cylinder->getThing(i); + std::shared_ptr thing = cylinder->getThing(i); if (!thing) { continue; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item) { continue; } - Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container) { containers.push_back(container); } else { @@ -2158,9 +2157,9 @@ bool Game::removeMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0* } size_t i = 0; while (i < containers.size()) { - Container* container = containers[i++]; - for (Item* item : container->getItemList()) { - Container* tmpContainer = item->getContainer(); + std::shared_ptr container = containers[i++]; + for (std::shared_ptr item : container->getItemList()) { + std::shared_ptr tmpContainer = item->getContainer(); if (tmpContainer) { containers.push_back(tmpContainer); } else { @@ -2173,7 +2172,7 @@ bool Game::removeMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0* } } - Player* player = useBalance ? dynamic_cast(cylinder) : nullptr; + std::shared_ptr player = useBalance ? std::dynamic_pointer_cast(cylinder) : nullptr; uint64_t balance = 0; if (useBalance && player) { balance = player->getBankBalance(); @@ -2184,7 +2183,7 @@ bool Game::removeMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0* } for (const auto &moneyEntry : moneyMap) { - Item* item = moneyEntry.second; + std::shared_ptr item = moneyEntry.second; if (moneyEntry.first < money) { internalRemoveItem(item); money -= moneyEntry.first; @@ -2207,7 +2206,7 @@ bool Game::removeMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0* return true; } -void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/) { +void Game::addMoney(std::shared_ptr cylinder, uint64_t money, uint32_t flags /*= 0*/) { if (cylinder == nullptr) { g_logger().error("[{}] cylinder is nullptr", __FUNCTION__); return; @@ -2221,7 +2220,7 @@ void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/) while (crystalCoins > 0) { const uint16_t count = std::min(100, crystalCoins); - Item* remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, count); + std::shared_ptr remaindItem = Item::CreateItem(ITEM_CRYSTAL_COIN, count); ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags); if (ret != RETURNVALUE_NOERROR) { @@ -2233,7 +2232,7 @@ void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/) uint16_t platinumCoins = money / 100; if (platinumCoins != 0) { - Item* remaindItem = Item::CreateItem(ITEM_PLATINUM_COIN, platinumCoins); + std::shared_ptr remaindItem = Item::CreateItem(ITEM_PLATINUM_COIN, platinumCoins); ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags); if (ret != RETURNVALUE_NOERROR) { @@ -2244,7 +2243,7 @@ void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/) } if (money != 0) { - Item* remaindItem = Item::CreateItem(ITEM_GOLD_COIN, money); + std::shared_ptr remaindItem = Item::CreateItem(ITEM_GOLD_COIN, money); ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags); if (ret != RETURNVALUE_NOERROR) { @@ -2253,17 +2252,17 @@ void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/) } } -Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/) { +std::shared_ptr Game::transformItem(std::shared_ptr item, uint16_t newId, int32_t newCount /*= -1*/) { if (item->getID() == newId && (newCount == -1 || (newCount == item->getSubType() && newCount != 0))) { // chargeless item placed on map = infinite return item; } - Cylinder* cylinder = item->getParent(); + std::shared_ptr cylinder = item->getParent(); if (cylinder == nullptr) { return nullptr; } - Tile* fromTile = cylinder->getTile(); + std::shared_ptr fromTile = cylinder->getTile(); if (fromTile) { auto it = browseFields.find(fromTile); if (it != browseFields.end() && it->second == cylinder) { @@ -2298,7 +2297,7 @@ Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/) } cylinder->addThing(item); - Cylinder* newParent = item->getParent(); + std::shared_ptr newParent = item->getParent(); if (newParent == nullptr) { item->stopDecaying(); ReleaseItem(item); @@ -2327,7 +2326,7 @@ Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/) internalRemoveItem(item); return nullptr; } else if (newItemId != newId) { - // Replacing the the old item with the new while maintaining the old position + // Replacing the the old item with the std::make_shared< while> maintaining the old position auto newItem = item->transform(newItemId); if (newItem == nullptr) { g_logger().error("[{}] new item with id {} is nullptr, (ERROR CODE: 01)", __FUNCTION__, newItemId); @@ -2359,7 +2358,7 @@ Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/) cylinder->updateThing(item, itemId, count); cylinder->postAddNotification(item, cylinder, itemIndex); - Item* quiver = cylinder->getItem(); + std::shared_ptr quiver = cylinder->getItem(); if (quiver && quiver->isQuiver() && quiver->getHoldingPlayer() && quiver->getHoldingPlayer()->getThing(CONST_SLOT_RIGHT) == quiver) { @@ -2371,7 +2370,7 @@ Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/) } } - Item* quiver = cylinder->getItem(); + std::shared_ptr quiver = cylinder->getItem(); if (quiver && quiver->isQuiver() && quiver->getHoldingPlayer() && quiver->getHoldingPlayer()->getThing(CONST_SLOT_RIGHT) == quiver) { @@ -2388,7 +2387,7 @@ Item* Game::transformItem(Item* item, uint16_t newId, int32_t newCount /*= -1*/) return newItem; } -ReturnValue Game::internalTeleport(Thing* thing, const Position &newPos, bool pushMove /* = true*/, uint32_t flags /*= 0*/) { +ReturnValue Game::internalTeleport(std::shared_ptr thing, const Position &newPos, bool pushMove /* = true*/, uint32_t flags /*= 0*/) { if (thing == nullptr) { g_logger().error("[{}] thing is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; @@ -2400,38 +2399,38 @@ ReturnValue Game::internalTeleport(Thing* thing, const Position &newPos, bool pu return RETURNVALUE_NOTPOSSIBLE; } - Tile* toTile = map.getTile(newPos); + std::shared_ptr toTile = map.getTile(newPos); if (!toTile) { return RETURNVALUE_NOTPOSSIBLE; } - if (Creature* creature = thing->getCreature()) { - ReturnValue ret = toTile->queryAdd(0, *creature, 1, FLAG_NOLIMIT); + if (std::shared_ptr creature = thing->getCreature()) { + ReturnValue ret = toTile->queryAdd(0, creature, 1, FLAG_NOLIMIT); if (ret != RETURNVALUE_NOERROR) { return ret; } - map.moveCreature(*creature, *toTile, !pushMove); + map.moveCreature(creature, toTile, !pushMove); return RETURNVALUE_NOERROR; - } else if (Item* item = thing->getItem()) { + } else if (std::shared_ptr item = thing->getItem()) { return internalMoveItem(item->getParent(), toTile, INDEX_WHEREEVER, item, item->getItemCount(), nullptr, flags); } return RETURNVALUE_NOTPOSSIBLE; } -void Game::internalQuickLootCorpse(Player* player, Container* corpse) { +void Game::internalQuickLootCorpse(std::shared_ptr player, std::shared_ptr corpse) { if (!player || !corpse) { return; } - std::vector itemList; + std::vector> itemList; bool ignoreListItems = (player->quickLootFilter == QUICKLOOTFILTER_SKIPPEDLOOT); bool missedAnyGold = false; bool missedAnyItem = false; for (ContainerIterator it = corpse->iterator(); it.hasNext(); it.advance()) { - Item* item = *it; + std::shared_ptr item = *it; bool listed = player->isQuickLootListedItem(item); if ((listed && ignoreListItems) || (!listed && !ignoreListItems)) { if (item->getWorth() != 0) { @@ -2450,7 +2449,7 @@ void Game::internalQuickLootCorpse(Player* player, Container* corpse) { uint32_t totalLootedGold = 0; uint32_t totalLootedItems = 0; - for (Item* item : itemList) { + for (std::shared_ptr item : itemList) { uint32_t worth = item->getWorth(); uint16_t baseCount = item->getItemCount(); ObjectCategory_t category = getObjectCategory(item); @@ -2562,11 +2561,11 @@ void Game::internalQuickLootCorpse(Player* player, Container* corpse) { player->lastQuickLootNotification = OTSYS_TIME(); } -Container* Game::findLootContainer(Player* player, bool &fallbackConsumed, ObjectCategory_t category) { - Container* lootContainer = player->getLootContainer(category); +std::shared_ptr Game::findLootContainer(std::shared_ptr player, bool &fallbackConsumed, ObjectCategory_t category) { + auto lootContainer = player->getLootContainer(category); if (!lootContainer && player->quickLootFallbackToMainContainer && !fallbackConsumed) { - Item* fallbackItem = player->getInventoryItem(CONST_SLOT_BACKPACK); - Container* mainBackpack = fallbackItem ? fallbackItem->getContainer() : nullptr; + auto fallbackItem = player->getInventoryItem(CONST_SLOT_BACKPACK); + auto mainBackpack = fallbackItem ? fallbackItem->getContainer() : nullptr; if (mainBackpack) { player->setLootContainer(OBJECTCATEGORY_DEFAULT, mainBackpack); @@ -2579,10 +2578,10 @@ Container* Game::findLootContainer(Player* player, bool &fallbackConsumed, Objec return lootContainer; } -Container* Game::findNextAvailableContainer(ContainerIterator &containerIterator, Container*&lootContainer, Container*&lastSubContainer) { +std::shared_ptr Game::findNextAvailableContainer(ContainerIterator &containerIterator, std::shared_ptr &lootContainer, std::shared_ptr &lastSubContainer) { while (containerIterator.hasNext()) { - Item* cur = *containerIterator; - Container* subContainer = cur ? cur->getContainer() : nullptr; + std::shared_ptr cur = *containerIterator; + std::shared_ptr subContainer = cur ? cur->getContainer() : nullptr; containerIterator.advance(); if (subContainer) { @@ -2594,7 +2593,7 @@ Container* Game::findNextAvailableContainer(ContainerIterator &containerIterator // Fix last empty sub-container if (lastSubContainer && !lastSubContainer->empty()) { - Item* cur = lastSubContainer->getItemByIndex(lastSubContainer->size() - 1); + auto cur = lastSubContainer->getItemByIndex(lastSubContainer->size() - 1); lootContainer = cur ? cur->getContainer() : nullptr; lastSubContainer = nullptr; return lootContainer; @@ -2603,12 +2602,12 @@ Container* Game::findNextAvailableContainer(ContainerIterator &containerIterator return nullptr; } -bool Game::handleFallbackLogic(const Player* player, Container*&lootContainer, ContainerIterator &containerIterator, const bool &fallbackConsumed) { +bool Game::handleFallbackLogic(std::shared_ptr player, std::shared_ptr &lootContainer, ContainerIterator &containerIterator, const bool &fallbackConsumed) { if (fallbackConsumed || !player->quickLootFallbackToMainContainer) { return false; } - Item* fallbackItem = player->getInventoryItem(CONST_SLOT_BACKPACK); + std::shared_ptr fallbackItem = player->getInventoryItem(CONST_SLOT_BACKPACK); if (!fallbackItem || !fallbackItem->getContainer()) { return false; } @@ -2619,8 +2618,8 @@ bool Game::handleFallbackLogic(const Player* player, Container*&lootContainer, C return true; } -ReturnValue Game::processMoveOrAddItemToLootContainer(Item* item, Container* lootContainer, uint32_t &remainderCount, Player* player) { - Item* moveItem = nullptr; +ReturnValue Game::processMoveOrAddItemToLootContainer(std::shared_ptr item, std::shared_ptr lootContainer, uint32_t &remainderCount, std::shared_ptr player) { + std::shared_ptr moveItem = nullptr; ReturnValue ret; if (item->getParent()) { ret = internalMoveItem(item->getParent(), lootContainer, INDEX_WHEREEVER, item, item->getItemCount(), &moveItem, 0, player, nullptr, false); @@ -2633,8 +2632,8 @@ ReturnValue Game::processMoveOrAddItemToLootContainer(Item* item, Container* loo return ret; } -ReturnValue Game::processLootItems(Player* player, Container* lootContainer, Item* item, bool &fallbackConsumed) { - Container* lastSubContainer = nullptr; +ReturnValue Game::processLootItems(std::shared_ptr player, std::shared_ptr lootContainer, std::shared_ptr item, bool &fallbackConsumed) { + std::shared_ptr lastSubContainer = nullptr; uint32_t remainderCount = item->getItemCount(); ContainerIterator containerIterator = lootContainer->iterator(); @@ -2645,7 +2644,7 @@ ReturnValue Game::processLootItems(Player* player, Container* lootContainer, Ite return ret; } - const Container* nextContainer = findNextAvailableContainer(containerIterator, lootContainer, lastSubContainer); + std::shared_ptr nextContainer = findNextAvailableContainer(containerIterator, lootContainer, lastSubContainer); if (!nextContainer && !handleFallbackLogic(player, lootContainer, containerIterator, fallbackConsumed)) { break; } @@ -2655,7 +2654,7 @@ ReturnValue Game::processLootItems(Player* player, Container* lootContainer, Ite return ret; } -ReturnValue Game::internalCollectLootItems(Player* player, Item* item, ObjectCategory_t category /* = OBJECTCATEGORY_DEFAULT*/) { +ReturnValue Game::internalCollectLootItems(std::shared_ptr player, std::shared_ptr item, ObjectCategory_t category /* = OBJECTCATEGORY_DEFAULT*/) { if (!player || !item) { return RETURNVALUE_NOTPOSSIBLE; } @@ -2684,7 +2683,7 @@ ReturnValue Game::internalCollectLootItems(Player* player, Item* item, ObjectCat } bool fallbackConsumed = false; - Container* lootContainer = findLootContainer(player, fallbackConsumed, category); + std::shared_ptr lootContainer = findLootContainer(player, fallbackConsumed, category); if (!lootContainer) { return RETURNVALUE_NOTPOSSIBLE; } @@ -2692,9 +2691,9 @@ ReturnValue Game::internalCollectLootItems(Player* player, Item* item, ObjectCat return processLootItems(player, lootContainer, item, fallbackConsumed); } -ReturnValue Game::collectRewardChestItems(Player* player, uint32_t maxMoveItems /* = 0*/) { +ReturnValue Game::collectRewardChestItems(std::shared_ptr player, uint32_t maxMoveItems /* = 0*/) { // Check if have item on player reward chest - RewardChest* rewardChest = player->getRewardChest(); + std::shared_ptr rewardChest = player->getRewardChest(); if (rewardChest->empty()) { g_logger().debug("Reward chest is empty"); return RETURNVALUE_REWARDCHESTISEMPTY; @@ -2735,7 +2734,7 @@ ReturnValue Game::collectRewardChestItems(Player* player, uint32_t maxMoveItems return RETURNVALUE_NOERROR; } -ObjectCategory_t Game::getObjectCategory(const Item* item) { +ObjectCategory_t Game::getObjectCategory(std::shared_ptr item) { ObjectCategory_t category = OBJECTCATEGORY_DEFAULT; if (!item) { return OBJECTCATEGORY_NONE; @@ -2829,7 +2828,7 @@ uint64_t Game::getItemMarketPrice(const std::map &itemMap, b return total; } -Item* searchForItem(const Container* container, uint16_t itemId, bool hasTier /* = false*/, uint8_t tier /* = 0*/) { +std::shared_ptr searchForItem(std::shared_ptr container, uint16_t itemId, bool hasTier /* = false*/, uint8_t tier /* = 0*/) { for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { if ((*it)->getID() == itemId && (!hasTier || (*it)->getTier() == tier)) { return *it; @@ -2868,7 +2867,7 @@ Slots_t getSlotType(const ItemType &it) { // Implementation of player invoked events void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = false*/, uint8_t tier /* = 0*/) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -2881,12 +2880,12 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = return; } - Item* item = player->getInventoryItem(CONST_SLOT_BACKPACK); + std::shared_ptr item = player->getInventoryItem(CONST_SLOT_BACKPACK); if (!item) { return; } - const Container* backpack = item->getContainer(); + std::shared_ptr backpack = item->getContainer(); if (!backpack) { return; } @@ -2894,13 +2893,13 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = const ItemType &it = Item::items[itemId]; Slots_t slot = getSlotType(it); - Item* slotItem = player->getInventoryItem(slot); - Item* equipItem = searchForItem(backpack, it.id, hasTier, tier); + auto slotItem = player->getInventoryItem(slot); + auto equipItem = searchForItem(backpack, it.id, hasTier, tier); if (slotItem && slotItem->getID() == it.id && (!it.stackable || slotItem->getItemCount() == slotItem->getStackSize() || !equipItem)) { internalMoveItem(slotItem->getParent(), player, CONST_SLOT_WHEREEVER, slotItem, slotItem->getItemCount(), nullptr); } else if (equipItem) { if (it.weaponType == WEAPON_AMMO) { - Item* quiver = player->getInventoryItem(CONST_SLOT_RIGHT); + auto quiver = player->getInventoryItem(CONST_SLOT_RIGHT); if (quiver && quiver->isQuiver()) { internalMoveItem(equipItem->getParent(), quiver->getContainer(), 0, equipItem, equipItem->getItemCount(), nullptr); return; @@ -2912,7 +2911,7 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = } void Game::playerMove(uint32_t playerId, Direction direction) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -2925,7 +2924,7 @@ void Game::playerMove(uint32_t playerId, Direction direction) { } void Game::forcePlayerMove(uint32_t playerId, Direction direction) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -2937,7 +2936,7 @@ void Game::forcePlayerMove(uint32_t playerId, Direction direction) { player->startAutoWalk(std::forward_list { direction }, true); } -bool Game::playerBroadcastMessage(Player* player, const std::string &text) const { +bool Game::playerBroadcastMessage(std::shared_ptr player, const std::string &text) const { if (!player->hasFlag(PlayerFlags_t::CanBroadcast)) { return false; } @@ -2952,13 +2951,13 @@ bool Game::playerBroadcastMessage(Player* player, const std::string &text) const } void Game::playerCreatePrivateChannel(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->isPremium()) { return; } - ChatChannel* channel = g_chat().createChannel(*player, CHANNEL_PRIVATE); - if (!channel || !channel->addUser(*player)) { + ChatChannel* channel = g_chat().createChannel(player, CHANNEL_PRIVATE); + if (!channel || !channel->addUser(player)) { return; } @@ -2966,17 +2965,17 @@ void Game::playerCreatePrivateChannel(uint32_t playerId) { } void Game::playerChannelInvite(uint32_t playerId, const std::string &name) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - PrivateChatChannel* channel = g_chat().getPrivateChannel(*player); + PrivateChatChannel* channel = g_chat().getPrivateChannel(player); if (!channel) { return; } - Player* invitePlayer = getPlayerByName(name); + std::shared_ptr invitePlayer = getPlayerByName(name); if (!invitePlayer) { return; } @@ -2985,21 +2984,21 @@ void Game::playerChannelInvite(uint32_t playerId, const std::string &name) { return; } - channel->invitePlayer(*player, *invitePlayer); + channel->invitePlayer(player, invitePlayer); } void Game::playerChannelExclude(uint32_t playerId, const std::string &name) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - PrivateChatChannel* channel = g_chat().getPrivateChannel(*player); + PrivateChatChannel* channel = g_chat().getPrivateChannel(player); if (!channel) { return; } - Player* excludePlayer = getPlayerByName(name); + std::shared_ptr excludePlayer = getPlayerByName(name); if (!excludePlayer) { return; } @@ -3008,11 +3007,11 @@ void Game::playerChannelExclude(uint32_t playerId, const std::string &name) { return; } - channel->excludePlayer(*player, *excludePlayer); + channel->excludePlayer(player, excludePlayer); } void Game::playerRequestChannels(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3021,12 +3020,12 @@ void Game::playerRequestChannels(uint32_t playerId) { } void Game::playerOpenChannel(uint32_t playerId, uint16_t channelId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - const ChatChannel* channel = g_chat().addUserToChannel(*player, channelId); + const ChatChannel* channel = g_chat().addUserToChannel(player, channelId); if (!channel) { return; } @@ -3043,16 +3042,16 @@ void Game::playerOpenChannel(uint32_t playerId, uint16_t channelId) { } void Game::playerCloseChannel(uint32_t playerId, uint16_t channelId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - g_chat().removeUserFromChannel(*player, channelId); + g_chat().removeUserFromChannel(player, channelId); } void Game::playerOpenPrivateChannel(uint32_t playerId, std::string &receiver) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3071,22 +3070,22 @@ void Game::playerOpenPrivateChannel(uint32_t playerId, std::string &receiver) { } void Game::playerCloseNpcChannel(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } SpectatorHashSet spectators; map.getSpectators(spectators, player->getPosition()); - for (Creature* spectator : spectators) { - if (Npc* npc = spectator->getNpc()) { + for (std::shared_ptr spectator : spectators) { + if (auto npc = spectator->getNpc()) { npc->onPlayerCloseChannel(player); } } } void Game::playerReceivePing(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3095,7 +3094,7 @@ void Game::playerReceivePing(uint32_t playerId) { } void Game::playerReceivePingBack(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3104,7 +3103,7 @@ void Game::playerReceivePingBack(uint32_t playerId) { } void Game::playerAutoWalk(uint32_t playerId, const std::forward_list &listDir) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3115,7 +3114,7 @@ void Game::playerAutoWalk(uint32_t playerId, const std::forward_list } void Game::forcePlayerAutoWalk(uint32_t playerId, const std::forward_list &listDir) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3132,7 +3131,7 @@ void Game::forcePlayerAutoWalk(uint32_t playerId, const std::forward_list player = getPlayerByID(playerId); if (!player) { return; } @@ -3141,7 +3140,7 @@ void Game::playerStopAutoWalk(uint32_t playerId) { } void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t fromStackPos, uint16_t fromItemId, const Position &toPos, uint8_t toStackPos, uint16_t toItemId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3151,13 +3150,13 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f return; } - Thing* thing = internalGetThing(player, fromPos, fromStackPos, fromItemId, STACKPOS_FIND_THING); + std::shared_ptr thing = internalGetThing(player, fromPos, fromStackPos, fromItemId, STACKPOS_FIND_THING); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item || !item->isMultiUse() || item->getID() != fromItemId) { player->sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT); return; @@ -3191,7 +3190,7 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f uint8_t itemStackPos = fromStackPos; if (fromPos.x != 0xFFFF && toPos.x != 0xFFFF && Position::areInRange<1, 1, 0>(fromPos, player->getPosition()) && !Position::areInRange<1, 1, 0>(fromPos, toPos)) { - Item* moveItem = nullptr; + std::shared_ptr moveItem = nullptr; ret = internalMoveItem(item->getParent(), player, INDEX_WHEREEVER, item, item->getItemCount(), &moveItem); if (ret != RETURNVALUE_NOERROR) { @@ -3255,7 +3254,7 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f if (item->isInsideDepot(true)) { mustReloadDepotSearch = true; } else { - if (Thing* targetThing = internalGetThing(player, toPos, toStackPos, toItemId, STACKPOS_FIND_THING); + if (auto targetThing = internalGetThing(player, toPos, toStackPos, toItemId, STACKPOS_FIND_THING); targetThing && targetThing->getItem() && targetThing->getItem()->isInsideDepot(true)) { mustReloadDepotSearch = true; } @@ -3270,7 +3269,7 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f } void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPos, uint8_t index, uint16_t itemId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3280,13 +3279,13 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo return; } - Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_FIND_THING); + std::shared_ptr thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_FIND_THING); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item || item->isMultiUse() || item->getID() != itemId) { player->sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT); return; @@ -3364,12 +3363,12 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo } void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uint8_t fromStackPos, uint32_t creatureId, uint16_t itemId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Creature* creature = getCreatureByID(creatureId); + std::shared_ptr creature = getCreatureByID(creatureId); if (!creature) { return; } @@ -3386,20 +3385,20 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin } } - Thing* thing = internalGetThing(player, fromPos, fromStackPos, itemId, STACKPOS_FIND_THING); + std::shared_ptr thing = internalGetThing(player, fromPos, fromStackPos, itemId, STACKPOS_FIND_THING); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item || !item->isMultiUse() || item->getID() != itemId) { player->sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT); return; } if (g_configManager().getBoolean(ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { - if (HouseTile* houseTile = dynamic_cast(item->getTile())) { + if (std::shared_ptr houseTile = std::dynamic_pointer_cast(item->getTile())) { House* house = houseTile->getHouse(); if (house && item->getRealParent() && item->getRealParent() != player && (!house->isInvited(player) || house->getHouseAccessLevel(player) == HOUSE_GUEST)) { player->sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT); @@ -3431,7 +3430,7 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin uint8_t itemStackPos = fromStackPos; if (fromPos.x != 0xFFFF && Position::areInRange<1, 1, 0>(fromPos, player->getPosition()) && !Position::areInRange<1, 1, 0>(fromPos, toPos)) { - Item* moveItem = nullptr; + std::shared_ptr moveItem = nullptr; ret = internalMoveItem(item->getParent(), player, INDEX_WHEREEVER, item, item->getItemCount(), &moveItem); if (ret != RETURNVALUE_NOERROR) { player->sendCancelMessage(ret); @@ -3493,7 +3492,7 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin } void Game::playerCloseContainer(uint32_t playerId, uint8_t cid) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3503,19 +3502,19 @@ void Game::playerCloseContainer(uint32_t playerId, uint8_t cid) { } void Game::playerMoveUpContainer(uint32_t playerId, uint8_t cid) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Container* container = player->getContainerByID(cid); + std::shared_ptr container = player->getContainerByID(cid); if (!container) { return; } - Container* parentContainer = dynamic_cast(container->getRealParent()); + std::shared_ptr parentContainer = std::dynamic_pointer_cast(container->getRealParent()); if (!parentContainer) { - Tile* tile = container->getTile(); + std::shared_ptr tile = container->getTile(); if (!tile) { return; } @@ -3530,7 +3529,7 @@ void Game::playerMoveUpContainer(uint32_t playerId, uint8_t cid) { auto it = browseFields.find(tile); if (it == browseFields.end()) { - parentContainer = new Container(tile); + parentContainer = std::make_shared(tile); parentContainer->incrementReferenceCounter(); browseFields[tile] = parentContainer; g_scheduler().addEvent(30000, std::bind(&Game::decreaseBrowseFieldRef, this, tile->getPosition()), "Game::decreaseBrowseFieldRef"); @@ -3552,12 +3551,12 @@ void Game::playerMoveUpContainer(uint32_t playerId, uint8_t cid) { } void Game::playerUpdateContainer(uint32_t playerId, uint8_t cid) { - Player* player = getPlayerByGUID(playerId); + std::shared_ptr player = getPlayerByGUID(playerId); if (!player) { return; } - Container* container = player->getContainerByID(cid); + std::shared_ptr container = player->getContainerByID(cid); if (!container) { return; } @@ -3566,17 +3565,17 @@ void Game::playerUpdateContainer(uint32_t playerId, uint8_t cid) { } void Game::playerRotateItem(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM); + std::shared_ptr thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM); if (!thing) { return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item || item->getID() != itemId || !item->isRotatable() || item->hasAttribute(ItemAttribute_t::UNIQUEID)) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -3606,17 +3605,17 @@ void Game::playerRotateItem(uint32_t playerId, const Position &pos, uint8_t stac } void Game::playerConfigureShowOffSocket(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || pos.x == 0xFFFF) { return; } - Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM); + std::shared_ptr thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM); if (!thing) { return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item || item->getID() != itemId || !item->isPodium() || item->hasAttribute(ItemAttribute_t::UNIQUEID)) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -3648,17 +3647,17 @@ void Game::playerConfigureShowOffSocket(uint32_t playerId, const Position &pos, } void Game::playerSetShowOffSocket(uint32_t playerId, Outfit_t &outfit, const Position &pos, uint8_t stackPos, const uint16_t itemId, uint8_t podiumVisible, uint8_t direction) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || pos.x == 0xFFFF) { return; } - Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM); + std::shared_ptr thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM); if (!thing) { return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item || item->getID() != itemId || !item->isPodium() || item->hasAttribute(ItemAttribute_t::UNIQUEID)) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -3763,15 +3762,15 @@ void Game::playerSetShowOffSocket(uint32_t playerId, Outfit_t &outfit, const Pos g_game().map.getSpectators(spectators, pos, true); // Send to client - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendUpdateTileItem(tile, pos, item); } } } void Game::playerWrapableItem(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3782,14 +3781,14 @@ void Game::playerWrapableItem(uint32_t playerId, const Position &pos, uint8_t st return; } - Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_FIND_THING); + std::shared_ptr thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_FIND_THING); if (!thing) { return; } - Item* item = thing->getItem(); - Tile* tile = map.getTile(item->getPosition()); - HouseTile* houseTile = dynamic_cast(tile); + std::shared_ptr item = thing->getItem(); + std::shared_ptr tile = map.getTile(item->getPosition()); + std::shared_ptr houseTile = std::dynamic_pointer_cast(tile); if (!tile->hasFlag(TILESTATE_PROTECTIONZONE) || !houseTile) { player->sendCancelMessage("You may construct this only inside a house."); return; @@ -3817,7 +3816,7 @@ void Game::playerWrapableItem(uint32_t playerId, const Position &pos, uint8_t st return; } - const Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container && container->getItemHoldingCount() > 0) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -3853,7 +3852,7 @@ void Game::playerWrapableItem(uint32_t playerId, const Position &pos, uint8_t st addMagicEffect(pos, CONST_ME_POFF); } -Item* Game::wrapItem(Item* item, House* house) { +std::shared_ptr Game::wrapItem(std::shared_ptr item, House* house) { uint16_t hiddenCharges = 0; uint16_t amount = item->getItemCount(); if (isCaskItem(item->getID())) { @@ -3864,7 +3863,7 @@ Item* Game::wrapItem(Item* item, House* house) { house->removeBed(item->getBed()); } uint16_t oldItemID = item->getID(); - Item* newItem = transformItem(item, ITEM_DECORATION_KIT); + std::shared_ptr newItem = transformItem(item, ITEM_DECORATION_KIT); newItem->setCustomAttribute("unWrapId", static_cast(oldItemID)); item->setAttribute(ItemAttribute_t::DESCRIPTION, "Unwrap it in your own house to create a <" + item->getName() + ">."); if (hiddenCharges > 0) { @@ -3877,7 +3876,7 @@ Item* Game::wrapItem(Item* item, House* house) { return newItem; } -void Game::unwrapItem(Item* item, uint16_t unWrapId, House* house, Player* player) { +void Game::unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* house, std::shared_ptr player) { auto hiddenCharges = item->getAttribute(DATE); const ItemType &newiType = Item::items.getItemType(unWrapId); if (player != nullptr && house != nullptr && newiType.isBed() && house->getMaxBeds() > -1 && house->getBedCount() >= house->getMaxBeds()) { @@ -3888,7 +3887,7 @@ void Game::unwrapItem(Item* item, uint16_t unWrapId, House* house, Player* playe if (!amount) { amount = 1; } - Item* newItem = transformItem(item, unWrapId, amount); + std::shared_ptr newItem = transformItem(item, unWrapId, amount); if (house && newiType.isBed()) { house->addBed(newItem->getBed()); } @@ -3903,7 +3902,7 @@ void Game::unwrapItem(Item* item, uint16_t unWrapId, House* house, Player* playe } void Game::playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std::string &text) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3911,7 +3910,7 @@ void Game::playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std:: uint16_t maxTextLength = 0; uint32_t internalWindowTextId = 0; - Item* writeItem = player->getWriteItem(internalWindowTextId, maxTextLength); + std::shared_ptr writeItem = player->getWriteItem(internalWindowTextId, maxTextLength); if (text.length() > maxTextLength || windowTextId != internalWindowTextId) { return; } @@ -3921,9 +3920,9 @@ void Game::playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std:: return; } - Cylinder* topParent = writeItem->getTopParent(); + std::shared_ptr topParent = writeItem->getTopParent(); - Player* owner = dynamic_cast(topParent); + std::shared_ptr owner = std::dynamic_pointer_cast(topParent); if (owner && owner != player) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -3962,7 +3961,7 @@ void Game::playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std:: } void Game::playerBrowseField(uint32_t playerId, const Position &pos) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3985,7 +3984,7 @@ void Game::playerBrowseField(uint32_t playerId, const Position &pos) { return; } - Tile* tile = map.getTile(pos); + std::shared_ptr tile = map.getTile(pos); if (!tile) { return; } @@ -3998,11 +3997,11 @@ void Game::playerBrowseField(uint32_t playerId, const Position &pos) { return; } - Container* container; + std::shared_ptr container; auto it = browseFields.find(tile); if (it == browseFields.end()) { - container = new Container(tile); + container = std::make_shared(tile); container->incrementReferenceCounter(); browseFields[tile] = container; g_scheduler().addEvent(30000, std::bind(&Game::decreaseBrowseFieldRef, this, tile->getPosition()), "Game::decreaseBrowseFieldRef"); @@ -4011,7 +4010,7 @@ void Game::playerBrowseField(uint32_t playerId, const Position &pos) { } uint8_t dummyContainerId = 0xF - ((pos.x % 3) * 3 + (pos.y % 3)); - Container* openContainer = player->getContainerByID(dummyContainerId); + std::shared_ptr openContainer = player->getContainerByID(dummyContainerId); if (openContainer) { player->onCloseContainer(openContainer); player->closeContainer(dummyContainerId); @@ -4022,7 +4021,7 @@ void Game::playerBrowseField(uint32_t playerId, const Position &pos) { } void Game::playerStowItem(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackpos, uint8_t count, bool allItems) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4032,12 +4031,12 @@ void Game::playerStowItem(uint32_t playerId, const Position &pos, uint16_t itemI return; } - Thing* thing = internalGetThing(player, pos, stackpos, itemId, STACKPOS_TOPDOWN_ITEM); + std::shared_ptr thing = internalGetThing(player, pos, stackpos, itemId, STACKPOS_TOPDOWN_ITEM); if (!thing) { return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item || item->getID() != itemId || item->getItemCount() < count || item->isStoreItem()) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -4058,7 +4057,7 @@ void Game::playerStowItem(uint32_t playerId, const Position &pos, uint16_t itemI } void Game::playerStashWithdraw(uint32_t playerId, uint16_t itemId, uint32_t count, uint8_t) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4073,7 +4072,7 @@ void Game::playerStashWithdraw(uint32_t playerId, uint16_t itemId, uint32_t coun } uint16_t freeSlots = player->getFreeBackpackSlots(); - Container* stashContainer = player->getLootContainer(OBJECTCATEGORY_STASHRETRIEVE); + auto stashContainer = player->getLootContainer(OBJECTCATEGORY_STASHRETRIEVE); if (stashContainer && !(player->quickLootFallbackToMainContainer)) { freeSlots = stashContainer->getFreeSlots(); } @@ -4131,12 +4130,12 @@ void Game::playerStashWithdraw(uint32_t playerId, uint16_t itemId, uint32_t coun } void Game::playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_t index, uint8_t containerCategory) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Container* container = player->getContainerByID(containerId); + std::shared_ptr container = player->getContainerByID(containerId); if (!container || !container->hasPagination()) { return; } @@ -4156,7 +4155,7 @@ void Game::playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_ } void Game::playerUpdateHouseWindow(uint32_t playerId, uint8_t listId, uint32_t windowTextId, const std::string &text) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4173,12 +4172,12 @@ void Game::playerUpdateHouseWindow(uint32_t playerId, uint8_t listId, uint32_t w } void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t stackPos, uint32_t tradePlayerId, uint16_t itemId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Player* tradePartner = getPlayerByID(tradePlayerId); + std::shared_ptr tradePartner = getPlayerByID(tradePlayerId); if (!tradePartner || tradePartner == player) { player->sendTextMessage(MESSAGE_FAILURE, "Sorry, not possible."); return; @@ -4196,20 +4195,20 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st return; } - Thing* tradeThing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM); + std::shared_ptr tradeThing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM); if (!tradeThing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; } - Item* tradeItem = tradeThing->getItem(); + std::shared_ptr tradeItem = tradeThing->getItem(); if (tradeItem->getID() != itemId || !tradeItem->isPickupable() || tradeItem->hasAttribute(ItemAttribute_t::UNIQUEID)) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; } if (g_configManager().getBoolean(ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { - if (HouseTile* houseTile = dynamic_cast(tradeItem->getTile())) { + if (std::shared_ptr houseTile = std::dynamic_pointer_cast(tradeItem->getTile())) { House* house = houseTile->getHouse(); if (house && tradeItem->getRealParent() != player && (!house->isInvited(player) || house->getHouseAccessLevel(player) == HOUSE_GUEST)) { player->sendCancelMessage(RETURNVALUE_NOTMOVEABLE); @@ -4238,10 +4237,10 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st return; } - Container* tradeItemContainer = tradeItem->getContainer(); + std::shared_ptr tradeItemContainer = tradeItem->getContainer(); if (tradeItemContainer) { for (const auto &it : tradeItems) { - Item* item = it.first; + std::shared_ptr item = it.first; if (tradeItem == item) { player->sendTextMessage(MESSAGE_TRADE, "This item is already being traded."); return; @@ -4252,7 +4251,7 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st return; } - Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container && container->isHoldingItem(tradeItem)) { player->sendTextMessage(MESSAGE_TRADE, "This item is already being traded."); return; @@ -4260,13 +4259,13 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st } } else { for (const auto &it : tradeItems) { - Item* item = it.first; + std::shared_ptr item = it.first; if (tradeItem == item) { player->sendTextMessage(MESSAGE_TRADE, "This item is already being traded."); return; } - Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container && container->isHoldingItem(tradeItem)) { player->sendTextMessage(MESSAGE_TRADE, "This item is already being traded."); return; @@ -4274,7 +4273,7 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st } } - Container* tradeContainer = tradeItem->getContainer(); + auto tradeContainer = tradeItem->getContainer(); if (tradeContainer && tradeContainer->getItemHoldingCount() + 1 > 100) { player->sendTextMessage(MESSAGE_TRADE, "You can not trade more than 100 items."); return; @@ -4286,7 +4285,7 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st } if (tradeItemContainer) { - for (Item* containerItem : tradeItemContainer->getItems(true)) { + for (std::shared_ptr containerItem : tradeItemContainer->getItems(true)) { if (containerItem->isStoreItem()) { player->sendTextMessage(MESSAGE_TRADE, "This item cannot be trade."); return; @@ -4305,7 +4304,7 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st internalStartTrade(player, tradePartner, tradeItem); } -bool Game::internalStartTrade(Player* player, Player* tradePartner, Item* tradeItem) { +bool Game::internalStartTrade(std::shared_ptr player, std::shared_ptr tradePartner, std::shared_ptr tradeItem) { if (player->tradeState != TRADE_NONE && !(player->tradeState == TRADE_ACKNOWLEDGE && player->tradePartner == tradePartner)) { player->sendCancelMessage(RETURNVALUE_YOUAREALREADYTRADING); return false; @@ -4329,7 +4328,7 @@ bool Game::internalStartTrade(Player* player, Player* tradePartner, Item* tradeI tradePartner->tradeState = TRADE_ACKNOWLEDGE; tradePartner->tradePartner = player; } else { - Item* counterOfferItem = tradePartner->tradeItem; + std::shared_ptr counterOfferItem = tradePartner->tradeItem; player->sendTradeItemRequest(tradePartner->getName(), counterOfferItem, false); tradePartner->sendTradeItemRequest(player->getName(), tradeItem, false); } @@ -4338,7 +4337,7 @@ bool Game::internalStartTrade(Player* player, Player* tradePartner, Item* tradeI } void Game::playerAcceptTrade(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4347,7 +4346,7 @@ void Game::playerAcceptTrade(uint32_t playerId) { return; } - Player* tradePartner = player->tradePartner; + std::shared_ptr tradePartner = player->tradePartner; if (!tradePartner) { return; } @@ -4360,8 +4359,8 @@ void Game::playerAcceptTrade(uint32_t playerId) { player->setTradeState(TRADE_ACCEPT); if (tradePartner->getTradeState() == TRADE_ACCEPT) { - Item* tradeItem1 = player->tradeItem; - Item* tradeItem2 = tradePartner->tradeItem; + std::shared_ptr tradeItem1 = player->tradeItem; + std::shared_ptr tradeItem2 = tradePartner->tradeItem; if (!g_events().eventPlayerOnTradeAccept(player, tradePartner, tradeItem1, tradeItem2)) { internalCloseTrade(player); return; @@ -4395,8 +4394,8 @@ void Game::playerAcceptTrade(uint32_t playerId) { ret1 = internalRemoveItem(tradeItem1, tradeItem1->getItemCount(), true); ret2 = internalRemoveItem(tradeItem2, tradeItem2->getItemCount(), true); if (ret1 == RETURNVALUE_NOERROR && ret2 == RETURNVALUE_NOERROR) { - Cylinder* cylinder1 = tradeItem1->getParent(); - Cylinder* cylinder2 = tradeItem2->getParent(); + std::shared_ptr cylinder1 = tradeItem1->getParent(); + std::shared_ptr cylinder2 = tradeItem2->getParent(); uint32_t count1 = tradeItem1->getItemCount(); uint32_t count2 = tradeItem2->getItemCount(); @@ -4441,7 +4440,7 @@ void Game::playerAcceptTrade(uint32_t playerId) { } } -std::string Game::getTradeErrorDescription(ReturnValue ret, Item* item) { +std::string Game::getTradeErrorDescription(ReturnValue ret, std::shared_ptr item) { if (item) { if (ret == RETURNVALUE_NOTENOUGHCAPACITY) { std::ostringstream ss; @@ -4473,17 +4472,17 @@ std::string Game::getTradeErrorDescription(ReturnValue ret, Item* item) { } void Game::playerLookInTrade(uint32_t playerId, bool lookAtCounterOffer, uint8_t index) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Player* tradePartner = player->tradePartner; + std::shared_ptr tradePartner = player->tradePartner; if (!tradePartner) { return; } - Item* tradeItem; + std::shared_ptr tradeItem; if (lookAtCounterOffer) { tradeItem = tradePartner->getTradeItem(); } else { @@ -4507,17 +4506,17 @@ void Game::playerLookInTrade(uint32_t playerId, bool lookAtCounterOffer, uint8_t return; } - Container* tradeContainer = tradeItem->getContainer(); + std::shared_ptr tradeContainer = tradeItem->getContainer(); if (!tradeContainer) { return; } - std::vector containers { tradeContainer }; + std::vector> containers { tradeContainer }; size_t i = 0; while (i < containers.size()) { - const Container* container = containers[i++]; - for (Item* item : container->getItemList()) { - Container* tmpContainer = item->getContainer(); + std::shared_ptr container = containers[i++]; + for (std::shared_ptr item : container->getItemList()) { + std::shared_ptr tmpContainer = item->getContainer(); if (tmpContainer) { containers.push_back(tmpContainer); } @@ -4532,7 +4531,7 @@ void Game::playerLookInTrade(uint32_t playerId, bool lookAtCounterOffer, uint8_t } void Game::playerCloseTrade(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4540,8 +4539,8 @@ void Game::playerCloseTrade(uint32_t playerId) { internalCloseTrade(player); } -void Game::internalCloseTrade(Player* player) { - Player* tradePartner = player->tradePartner; +void Game::internalCloseTrade(std::shared_ptr player) { + std::shared_ptr tradePartner = player->tradePartner; if ((tradePartner && tradePartner->getTradeState() == TRADE_TRANSFER) || player->getTradeState() == TRADE_TRANSFER) { return; } @@ -4588,12 +4587,12 @@ void Game::playerBuyItem(uint32_t playerId, uint16_t itemId, uint8_t count, uint return; } - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Npc* merchant = player->getShopOwner(); + std::shared_ptr merchant = player->getShopOwner(); if (!merchant) { return; } @@ -4626,12 +4625,12 @@ void Game::playerSellItem(uint32_t playerId, uint16_t itemId, uint8_t count, uin return; } - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Npc* merchant = player->getShopOwner(); + std::shared_ptr merchant = player->getShopOwner(); if (!merchant) { return; } @@ -4656,7 +4655,7 @@ void Game::playerSellItem(uint32_t playerId, uint16_t itemId, uint8_t count, uin } void Game::playerCloseShop(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4665,12 +4664,12 @@ void Game::playerCloseShop(uint32_t playerId) { } void Game::playerLookInShop(uint32_t playerId, uint16_t itemId, uint8_t count) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Npc* merchant = player->getShopOwner(); + std::shared_ptr merchant = player->getShopOwner(); if (!merchant) { return; } @@ -4695,12 +4694,12 @@ void Game::playerLookInShop(uint32_t playerId, uint16_t itemId, uint8_t count) { } void Game::playerLookAt(uint32_t playerId, uint16_t itemId, const Position &pos, uint8_t stackPos) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_LOOK); + std::shared_ptr thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_LOOK); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -4730,12 +4729,12 @@ void Game::playerLookAt(uint32_t playerId, uint16_t itemId, const Position &pos, } void Game::playerLookInBattleList(uint32_t playerId, uint32_t creatureId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Creature* creature = getCreatureByID(creatureId); + std::shared_ptr creature = getCreatureByID(creatureId); if (!creature) { return; } @@ -4764,8 +4763,8 @@ void Game::playerLookInBattleList(uint32_t playerId, uint32_t creatureId) { g_callbacks().executeCallback(EventCallback_t::playerOnLookInBattleList, &EventCallback::playerOnLookInBattleList, player, creature, lookDistance); } -void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, Item* defaultItem, bool lootAllCorpses, bool autoLoot) { - Player* player = getPlayerByID(playerId); +void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, std::shared_ptr defaultItem, bool lootAllCorpses, bool autoLoot) { + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4801,9 +4800,9 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item player->setNextActionTask(nullptr); } - Item* item = nullptr; + std::shared_ptr item = nullptr; if (!defaultItem) { - Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_FIND_THING); + std::shared_ptr thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_FIND_THING); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -4819,7 +4818,7 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item return; } - Container* corpse = nullptr; + std::shared_ptr corpse = nullptr; if (pos.x == 0xffff) { corpse = item->getParent()->getContainer(); if (corpse && corpse->getID() == ITEM_BROWSEFIELD) { @@ -4895,9 +4894,9 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item } } -void Game::playerLootAllCorpses(Player* player, const Position &pos, bool lootAllCorpses) { +void Game::playerLootAllCorpses(std::shared_ptr player, const Position &pos, bool lootAllCorpses) { if (lootAllCorpses) { - Tile* tile = g_game().map.getTile(pos.x, pos.y, pos.z); + std::shared_ptr tile = g_game().map.getTile(pos.x, pos.y, pos.z); if (!tile) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -4905,12 +4904,12 @@ void Game::playerLootAllCorpses(Player* player, const Position &pos, bool lootAl const TileItemVector* itemVector = tile->getItemList(); uint16_t corpses = 0; - for (Item* tileItem : *itemVector) { + for (auto &tileItem : *itemVector) { if (!tileItem) { continue; } - Container* tileCorpse = tileItem->getContainer(); + std::shared_ptr tileCorpse = tileItem->getContainer(); if (!tileCorpse || !tileCorpse->isCorpse() || tileCorpse->hasAttribute(ItemAttribute_t::UNIQUEID) || tileCorpse->hasAttribute(ItemAttribute_t::ACTIONID)) { continue; } @@ -4945,18 +4944,18 @@ void Game::playerLootAllCorpses(Player* player, const Position &pos, bool lootAl } void Game::playerSetLootContainer(uint32_t playerId, ObjectCategory_t category, const Position &pos, uint16_t itemId, uint8_t stackPos) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || pos.x != 0xffff) { return; } - Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_USEITEM); + std::shared_ptr thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_USEITEM); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; } - Container* container = thing->getContainer(); + std::shared_ptr container = thing->getContainer(); if (!container || (container->getID() == ITEM_GOLD_POUCH && category != OBJECTCATEGORY_GOLD && !g_configManager().getBoolean(TOGGLE_GOLD_POUCH_ALLOW_ANYTHING))) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -4967,10 +4966,10 @@ void Game::playerSetLootContainer(uint32_t playerId, ObjectCategory_t category, return; } - Container* previousContainer = player->setLootContainer(category, container); + std::shared_ptr previousContainer = player->setLootContainer(category, container); player->sendLootContainers(); - Cylinder* parent = container->getParent(); + std::shared_ptr parent = container->getParent(); if (parent) { parent->updateThing(container, container->getID(), container->getItemCount()); } @@ -4984,16 +4983,16 @@ void Game::playerSetLootContainer(uint32_t playerId, ObjectCategory_t category, } void Game::playerClearLootContainer(uint32_t playerId, ObjectCategory_t category) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Container* previousContainer = player->setLootContainer(category, nullptr); + std::shared_ptr previousContainer = player->setLootContainer(category, nullptr); player->sendLootContainers(); if (previousContainer != nullptr) { - Cylinder* parent = previousContainer->getParent(); + std::shared_ptr parent = previousContainer->getParent(); if (parent) { parent->updateThing(previousContainer, previousContainer->getID(), previousContainer->getItemCount()); } @@ -5001,12 +5000,12 @@ void Game::playerClearLootContainer(uint32_t playerId, ObjectCategory_t category } void Game::playerOpenLootContainer(uint32_t playerId, ObjectCategory_t category) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Container* container = player->getLootContainer(category); + std::shared_ptr container = player->getLootContainer(category); if (!container) { return; } @@ -5015,7 +5014,7 @@ void Game::playerOpenLootContainer(uint32_t playerId, ObjectCategory_t category) } void Game::playerSetQuickLootFallback(uint32_t playerId, bool fallback) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5024,7 +5023,7 @@ void Game::playerSetQuickLootFallback(uint32_t playerId, bool fallback) { } void Game::playerQuickLootBlackWhitelist(uint32_t playerId, QuickLootFilter_t filter, const std::vector itemIds) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5037,7 +5036,7 @@ void Game::playerQuickLootBlackWhitelist(uint32_t playerId, QuickLootFilter_t fi * Depot search system ******************************************************************************/ void Game::playerRequestDepotItems(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->isDepotSearchAvailable()) { return; } @@ -5052,7 +5051,7 @@ void Game::playerRequestDepotItems(uint32_t playerId) { } void Game::playerRequestCloseDepotSearch(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->isDepotSearchOpen()) { return; } @@ -5062,7 +5061,7 @@ void Game::playerRequestCloseDepotSearch(uint32_t playerId) { } void Game::playerRequestDepotSearchItem(uint32_t playerId, uint16_t itemId, uint8_t tier) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->isDepotSearchOpen()) { return; } @@ -5077,7 +5076,7 @@ void Game::playerRequestDepotSearchItem(uint32_t playerId, uint16_t itemId, uint } void Game::playerRequestDepotSearchRetrieve(uint32_t playerId, uint16_t itemId, uint8_t tier, uint8_t type) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->isDepotSearchOpenOnItem(itemId)) { return; } @@ -5092,7 +5091,7 @@ void Game::playerRequestDepotSearchRetrieve(uint32_t playerId, uint16_t itemId, } void Game::playerRequestOpenContainerFromDepotSearch(uint32_t playerId, const Position &pos) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->isDepotSearchOpen()) { return; } @@ -5107,7 +5106,7 @@ void Game::playerRequestOpenContainerFromDepotSearch(uint32_t playerId, const Po } void Game::playerCancelAttackAndFollow(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5118,7 +5117,7 @@ void Game::playerCancelAttackAndFollow(uint32_t playerId) { } void Game::playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5129,7 +5128,7 @@ void Game::playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId) { return; } - Creature* attackCreature = getCreatureByID(creatureId); + std::shared_ptr attackCreature = getCreatureByID(creatureId); if (!attackCreature) { player->setAttackedCreature(nullptr); player->sendCancelTarget(); @@ -5149,7 +5148,7 @@ void Game::playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId) { } void Game::playerFollowCreature(uint32_t playerId, uint32_t creatureId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5160,7 +5159,7 @@ void Game::playerFollowCreature(uint32_t playerId, uint32_t creatureId) { } void Game::playerSetFightModes(uint32_t playerId, FightMode_t fightMode, bool chaseMode, bool secureMode) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5175,12 +5174,12 @@ void Game::playerRequestAddVip(uint32_t playerId, const std::string &name) { return; } - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Player* vipPlayer = getPlayerByName(name); + std::shared_ptr vipPlayer = getPlayerByName(name); if (!vipPlayer) { uint32_t guid; bool specialVip; @@ -5191,14 +5190,14 @@ void Game::playerRequestAddVip(uint32_t playerId, const std::string &name) { } if (specialVip && !player->hasFlag(PlayerFlags_t::SpecialVIP)) { - player->sendTextMessage(MESSAGE_FAILURE, "You can not add this player."); + player->sendTextMessage(MESSAGE_FAILURE, "You can not add this player->"); return; } player->addVIP(guid, formattedName, VIPSTATUS_OFFLINE); } else { if (vipPlayer->hasFlag(PlayerFlags_t::SpecialVIP) && !player->hasFlag(PlayerFlags_t::SpecialVIP)) { - player->sendTextMessage(MESSAGE_FAILURE, "You can not add this player."); + player->sendTextMessage(MESSAGE_FAILURE, "You can not add this player->"); return; } @@ -5211,7 +5210,7 @@ void Game::playerRequestAddVip(uint32_t playerId, const std::string &name) { } void Game::playerRequestRemoveVip(uint32_t playerId, uint32_t guid) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5220,7 +5219,7 @@ void Game::playerRequestRemoveVip(uint32_t playerId, uint32_t guid) { } void Game::playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::string &description, uint32_t icon, bool notify) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5229,7 +5228,7 @@ void Game::playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::str } void Game::playerApplyImbuement(uint32_t playerId, uint16_t imbuementid, uint8_t slot, bool protectionCharm) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5243,7 +5242,7 @@ void Game::playerApplyImbuement(uint32_t playerId, uint16_t imbuementid, uint8_t return; } - Item* item = player->imbuingItem; + std::shared_ptr item = player->imbuingItem; if (!item) { return; } @@ -5258,7 +5257,7 @@ void Game::playerApplyImbuement(uint32_t playerId, uint16_t imbuementid, uint8_t } void Game::playerClearImbuement(uint32_t playerid, uint8_t slot) { - Player* player = getPlayerByID(playerid); + std::shared_ptr player = getPlayerByID(playerid); if (!player) { return; } @@ -5267,7 +5266,7 @@ void Game::playerClearImbuement(uint32_t playerid, uint8_t slot) { return; } - Item* item = player->imbuingItem; + std::shared_ptr item = player->imbuingItem; if (!item) { return; } @@ -5276,7 +5275,7 @@ void Game::playerClearImbuement(uint32_t playerid, uint8_t slot) { } void Game::playerCloseImbuementWindow(uint32_t playerid) { - Player* player = getPlayerByID(playerid); + std::shared_ptr player = getPlayerByID(playerid); if (!player) { return; } @@ -5286,7 +5285,7 @@ void Game::playerCloseImbuementWindow(uint32_t playerid) { } void Game::playerTurn(uint32_t playerId, Direction dir) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5308,7 +5307,7 @@ void Game::playerRequestOutfit(uint32_t playerId) { return; } - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5317,7 +5316,7 @@ void Game::playerRequestOutfit(uint32_t playerId) { } void Game::playerToggleMount(uint32_t playerId, bool mount) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5330,7 +5329,7 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, uint8_t isMoun return; } - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5357,7 +5356,7 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, uint8_t isMoun return; } - const Tile* playerTile = player->getTile(); + std::shared_ptr playerTile = player->getTile(); if (!playerTile) { return; } @@ -5392,7 +5391,7 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, uint8_t isMoun } void Game::playerShowQuestLog(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5402,7 +5401,7 @@ void Game::playerShowQuestLog(uint32_t playerId) { } void Game::playerShowQuestLine(uint32_t playerId, uint16_t questId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5412,7 +5411,7 @@ void Game::playerShowQuestLine(uint32_t playerId, uint16_t questId) { } void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, const std::string &receiver, const std::string &text) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5460,7 +5459,7 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, c case TALKTYPE_CHANNEL_O: case TALKTYPE_CHANNEL_Y: case TALKTYPE_CHANNEL_R1: - g_chat().talkToChannel(*player, type, text, channelId); + g_chat().talkToChannel(player, type, text, channelId); break; case TALKTYPE_PRIVATE_PN: @@ -5476,7 +5475,7 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, c } } -bool Game::playerSaySpell(Player* player, SpeakClasses type, const std::string &text) { +bool Game::playerSaySpell(std::shared_ptr player, SpeakClasses type, const std::string &text) { if (player->walkExhausted()) { return true; } @@ -5505,13 +5504,13 @@ bool Game::playerSaySpell(Player* player, SpeakClasses type, const std::string & return false; } -void Game::playerWhisper(Player* player, const std::string &text) { +void Game::playerWhisper(std::shared_ptr player, const std::string &text) { SpectatorHashSet spectators; map.getSpectators(spectators, player->getPosition(), false, false, MAP_MAX_CLIENT_VIEW_PORT_X, MAP_MAX_CLIENT_VIEW_PORT_X, MAP_MAX_CLIENT_VIEW_PORT_Y, MAP_MAX_CLIENT_VIEW_PORT_Y); // send to client - for (Creature* spectator : spectators) { - if (Player* spectatorPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto spectatorPlayer = spectator->getPlayer()) { if (!Position::areInRange<1, 1>(player->getPosition(), spectatorPlayer->getPosition())) { spectatorPlayer->sendCreatureSay(player, TALKTYPE_WHISPER, "pspsps"); } else { @@ -5521,12 +5520,12 @@ void Game::playerWhisper(Player* player, const std::string &text) { } // event method - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->onCreatureSay(player, TALKTYPE_WHISPER, text); } } -bool Game::playerYell(Player* player, const std::string &text) { +bool Game::playerYell(std::shared_ptr player, const std::string &text) { if (player->getLevel() == 1) { player->sendTextMessage(MESSAGE_FAILURE, "You may not yell as long as you are on level 1."); return false; @@ -5546,8 +5545,8 @@ bool Game::playerYell(Player* player, const std::string &text) { return true; } -bool Game::playerSpeakTo(Player* player, SpeakClasses type, const std::string &receiver, const std::string &text) { - Player* toPlayer = getPlayerByName(receiver); +bool Game::playerSpeakTo(std::shared_ptr player, SpeakClasses type, const std::string &receiver, const std::string &text) { + std::shared_ptr toPlayer = getPlayerByName(receiver); if (!toPlayer) { player->sendTextMessage(MESSAGE_FAILURE, "A player with this name is not online."); return false; @@ -5572,7 +5571,7 @@ bool Game::playerSpeakTo(Player* player, SpeakClasses type, const std::string &r return true; } -void Game::playerSpeakToNpc(Player* player, const std::string &text) { +void Game::playerSpeakToNpc(std::shared_ptr player, const std::string &text) { if (player == nullptr) { g_logger().error("[Game::playerSpeakToNpc] - Player is nullptr"); return; @@ -5586,7 +5585,7 @@ void Game::playerSpeakToNpc(Player* player, const std::string &text) { SpectatorHashSet spectators; map.getSpectators(spectators, player->getPosition()); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { if (spectator->getNpc()) { spectator->onCreatureSay(player, TALKTYPE_PRIVATE_PN, text); } @@ -5608,12 +5607,12 @@ bool Game::isSightClear(const Position &fromPos, const Position &toPos, bool flo return map.isSightClear(fromPos, toPos, floorCheck); } -bool Game::internalCreatureTurn(Creature* creature, Direction dir) { +bool Game::internalCreatureTurn(std::shared_ptr creature, Direction dir) { if (creature->getDirection() == dir) { return false; } - if (Player* player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->cancelPush(); } creature->setDirection(dir); @@ -5621,8 +5620,8 @@ bool Game::internalCreatureTurn(Creature* creature, Direction dir) { // Send to client SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); - for (Creature* spectator : spectators) { - Player* tmpPlayer = spectator->getPlayer(); + for (auto spectator : spectators) { + auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; } @@ -5631,7 +5630,7 @@ bool Game::internalCreatureTurn(Creature* creature, Direction dir) { return true; } -bool Game::internalCreatureSay(Creature* creature, SpeakClasses type, const std::string &text, bool ghostMode, SpectatorHashSet* spectatorsPtr /* = nullptr*/, const Position* pos /* = nullptr*/) { +bool Game::internalCreatureSay(std::shared_ptr creature, SpeakClasses type, const std::string &text, bool ghostMode, SpectatorHashSet* spectatorsPtr /* = nullptr*/, const Position* pos /* = nullptr*/) { if (text.empty()) { return false; } @@ -5657,8 +5656,8 @@ bool Game::internalCreatureSay(Creature* creature, SpeakClasses type, const std: } // send to client - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto tmpPlayer = spectator->getPlayer()) { if (!ghostMode || tmpPlayer->canSeeCreature(creature)) { tmpPlayer->sendCreatureSay(creature, type, text, pos); } @@ -5666,7 +5665,7 @@ bool Game::internalCreatureSay(Creature* creature, SpeakClasses type, const std: } // event method - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->onCreatureSay(creature, type, text); if (creature != spectator) { g_events().eventCreatureOnHear(spectator, creature, text, type); @@ -5677,7 +5676,7 @@ bool Game::internalCreatureSay(Creature* creature, SpeakClasses type, const std: } void Game::checkCreatureWalk(uint32_t creatureId) { - Creature* creature = getCreatureByID(creatureId); + std::shared_ptr creature = getCreatureByID(creatureId); if (creature && creature->getHealth() > 0) { creature->onCreatureWalk(); cleanup(); @@ -5685,20 +5684,20 @@ void Game::checkCreatureWalk(uint32_t creatureId) { } void Game::updateCreatureWalk(uint32_t creatureId) { - Creature* creature = getCreatureByID(creatureId); + std::shared_ptr creature = getCreatureByID(creatureId); if (creature && creature->getHealth() > 0) { creature->goToFollowCreature(); } } void Game::checkCreatureAttack(uint32_t creatureId) { - Creature* creature = getCreatureByID(creatureId); + std::shared_ptr creature = getCreatureByID(creatureId); if (creature && creature->getHealth() > 0) { creature->onAttacking(0); } } -void Game::addCreatureCheck(Creature* creature) { +void Game::addCreatureCheck(std::shared_ptr creature) { creature->creatureCheck = true; if (creature->inCheckCreaturesVector) { @@ -5711,7 +5710,7 @@ void Game::addCreatureCheck(Creature* creature) { creature->incrementReferenceCounter(); } -void Game::removeCreatureCheck(Creature* creature) { +void Game::removeCreatureCheck(std::shared_ptr creature) { if (creature->inCheckCreaturesVector) { creature->creatureCheck = false; } @@ -5723,7 +5722,7 @@ void Game::checkCreatures(size_t index) { auto &checkCreatureList = checkCreatureLists[index]; size_t it = 0, end = checkCreatureList.size(); while (it < end) { - Creature* creature = checkCreatureList[it]; + std::shared_ptr creature = checkCreatureList[it]; if (creature && creature->creatureCheck) { if (creature->getHealth() > 0) { creature->onThink(EVENT_CREATURE_THINK_INTERVAL); @@ -5745,7 +5744,7 @@ void Game::checkCreatures(size_t index) { cleanup(); } -void Game::changeSpeed(Creature* creature, int32_t varSpeedDelta) { +void Game::changeSpeed(std::shared_ptr creature, int32_t varSpeedDelta) { int32_t varSpeed = creature->getSpeed() - creature->getBaseSpeed(); varSpeed += varSpeedDelta; @@ -5754,48 +5753,48 @@ void Game::changeSpeed(Creature* creature, int32_t varSpeedDelta) { // send to clients SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), false, true); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->getPlayer()->sendChangeSpeed(creature, creature->getStepSpeed()); } } -void Game::setCreatureSpeed(Creature* creature, int32_t speed) { +void Game::setCreatureSpeed(std::shared_ptr creature, int32_t speed) { creature->setBaseSpeed(static_cast(speed)); // send creature speed to client SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), false, true); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->getPlayer()->sendChangeSpeed(creature, creature->getStepSpeed()); } } -void Game::changePlayerSpeed(Player &player, int32_t varSpeedDelta) { - int32_t varSpeed = player.getSpeed() - player.getBaseSpeed(); +void Game::changePlayerSpeed(const std::shared_ptr &player, int32_t varSpeedDelta) { + int32_t varSpeed = player->getSpeed() - player->getBaseSpeed(); varSpeed += varSpeedDelta; - player.setSpeed(varSpeed); + player->setSpeed(varSpeed); // Send new player speed to the spectators SpectatorHashSet spectators; - map.getSpectators(spectators, player.getPosition(), false, true); - for (Creature* creatureSpectator : spectators) { + map.getSpectators(spectators, player->getPosition(), false, true); + for (std::shared_ptr creatureSpectator : spectators) { if (creatureSpectator == nullptr) { g_logger().error("[Game::changePlayerSpeed] - Creature spectator is nullptr"); continue; } - const Player* playerSpectator = creatureSpectator->getPlayer(); + std::shared_ptr playerSpectator = creatureSpectator->getPlayer(); if (playerSpectator == nullptr) { g_logger().error("[Game::changePlayerSpeed] - Player spectator is nullptr"); continue; } - playerSpectator->sendChangeSpeed(&player, player.getStepSpeed()); + playerSpectator->sendChangeSpeed(player, player->getStepSpeed()); } } -void Game::internalCreatureChangeOutfit(Creature* creature, const Outfit_t &outfit) { +void Game::internalCreatureChangeOutfit(std::shared_ptr creature, const Outfit_t &outfit) { if (!g_events().eventCreatureOnChangeOutfit(creature, outfit)) { return; } @@ -5813,39 +5812,39 @@ void Game::internalCreatureChangeOutfit(Creature* creature, const Outfit_t &outf // send to clients SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->getPlayer()->sendCreatureChangeOutfit(creature, outfit); } } -void Game::internalCreatureChangeVisible(Creature* creature, bool visible) { +void Game::internalCreatureChangeVisible(std::shared_ptr creature, bool visible) { // send to clients SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->getPlayer()->sendCreatureChangeVisible(creature, visible); } } -void Game::changeLight(const Creature* creature) { +void Game::changeLight(std::shared_ptr creature) { // send to clients SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->getPlayer()->sendCreatureLight(creature); } } -void Game::updateCreatureIcon(const Creature* creature) { +void Game::updateCreatureIcon(std::shared_ptr creature) { // send to clients SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->getPlayer()->sendCreatureIcon(creature); } } -void Game::reloadCreature(const Creature* creature) { +void Game::reloadCreature(std::shared_ptr creature) { if (!creature) { g_logger().error("[{}] Creature is nullptr", __FUNCTION__); return; @@ -5853,8 +5852,8 @@ void Game::reloadCreature(const Creature* creature) { SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), false, true); - for (Creature* spectator : spectators) { - Player* tmpPlayer = spectator->getPlayer(); + for (auto spectator : spectators) { + auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; } @@ -5862,15 +5861,15 @@ void Game::reloadCreature(const Creature* creature) { } } -void Game::sendSingleSoundEffect(const Position &pos, SoundEffect_t soundId, Creature* actor /* = nullptr*/) { +void Game::sendSingleSoundEffect(const Position &pos, SoundEffect_t soundId, std::shared_ptr actor /* = nullptr*/) { if (soundId == SoundEffect_t::SILENCE) { return; } SpectatorHashSet spectators; map.getSpectators(spectators, pos, false, true); - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto tmpPlayer = spectator->getPlayer()) { SourceEffect_t source = SourceEffect_t::CREATURES; if (!actor || actor->getNpc()) { source = SourceEffect_t::GLOBAL; @@ -5885,7 +5884,7 @@ void Game::sendSingleSoundEffect(const Position &pos, SoundEffect_t soundId, Cre } } -void Game::sendDoubleSoundEffect(const Position &pos, SoundEffect_t mainSoundEffect, SoundEffect_t secondarySoundEffect, Creature* actor /* = nullptr*/) { +void Game::sendDoubleSoundEffect(const Position &pos, SoundEffect_t mainSoundEffect, SoundEffect_t secondarySoundEffect, std::shared_ptr actor /* = nullptr*/) { if (secondarySoundEffect == SoundEffect_t::SILENCE) { sendSingleSoundEffect(pos, mainSoundEffect, actor); return; @@ -5893,8 +5892,8 @@ void Game::sendDoubleSoundEffect(const Position &pos, SoundEffect_t mainSoundEff SpectatorHashSet spectators; map.getSpectators(spectators, pos, false, true); - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto tmpPlayer = spectator->getPlayer()) { SourceEffect_t source = SourceEffect_t::CREATURES; if (!actor || actor->getNpc()) { source = SourceEffect_t::GLOBAL; @@ -5909,7 +5908,7 @@ void Game::sendDoubleSoundEffect(const Position &pos, SoundEffect_t mainSoundEff } } -bool Game::combatBlockHit(CombatDamage &damage, Creature* attacker, Creature* target, bool checkDefense, bool checkArmor, bool field) { +bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr attacker, std::shared_ptr target, bool checkDefense, bool checkArmor, bool field) { if (damage.primary.type == COMBAT_NONE && damage.secondary.type == COMBAT_NONE) { return true; } @@ -5923,7 +5922,7 @@ bool Game::combatBlockHit(CombatDamage &damage, Creature* attacker, Creature* ta } // Skill dodge (ruse) - if (const Player* targetPlayer = target->getPlayer()) { + if (std::shared_ptr targetPlayer = target->getPlayer()) { if (auto playerArmor = targetPlayer->getInventoryItem(CONST_SLOT_ARMOR); playerArmor != nullptr && playerArmor->getTier()) { double_t chance = playerArmor->getDodgeChance(); @@ -5948,7 +5947,7 @@ bool Game::combatBlockHit(CombatDamage &damage, Creature* attacker, Creature* ta CombatParams damageReflectedParams; BlockType_t primaryBlockType, secondaryBlockType; - Player* targetPlayer = target->getPlayer(); + std::shared_ptr targetPlayer = target->getPlayer(); if (damage.primary.type != COMBAT_NONE) { // Damage reflection primary @@ -6094,10 +6093,10 @@ bool Game::combatBlockHit(CombatDamage &damage, Creature* attacker, Creature* ta return (primaryBlockType != BLOCK_NONE) && (secondaryBlockType != BLOCK_NONE); } -void Game::combatGetTypeInfo(CombatType_t combatType, Creature* target, TextColor_t &color, uint16_t &effect) { +void Game::combatGetTypeInfo(CombatType_t combatType, std::shared_ptr target, TextColor_t &color, uint16_t &effect) { switch (combatType) { case COMBAT_PHYSICALDAMAGE: { - Item* splash = nullptr; + std::shared_ptr splash = nullptr; switch (target->getRace()) { case RACE_VENOM: color = TEXTCOLOR_LIGHTGREEN; @@ -6107,7 +6106,7 @@ void Game::combatGetTypeInfo(CombatType_t combatType, Creature* target, TextColo case RACE_BLOOD: color = TEXTCOLOR_RED; effect = CONST_ME_DRAWBLOOD; - if (const Tile* tile = target->getTile()) { + if (std::shared_ptr tile = target->getTile()) { if (!tile->hasFlag(TILESTATE_PROTECTIONZONE)) { splash = Item::CreateItem(ITEM_SMALLSPLASH, FLUID_BLOOD); } @@ -6205,7 +6204,7 @@ void Game::combatGetTypeInfo(CombatType_t combatType, Creature* target, TextColo } // Hazard combat helpers -void Game::handleHazardSystemAttack(CombatDamage &damage, Player* player, const Monster* monster, bool isPlayerAttacker) { +void Game::handleHazardSystemAttack(CombatDamage &damage, std::shared_ptr player, std::shared_ptr monster, bool isPlayerAttacker) { if (damage.primary.value != 0 && monster->getHazard()) { if (isPlayerAttacker) { player->parseAttackDealtHazardSystem(damage, monster); @@ -6215,9 +6214,9 @@ void Game::handleHazardSystemAttack(CombatDamage &damage, Player* player, const } } -void Game::notifySpectators(const SpectatorHashSet &spectators, const Position &targetPos, Player* attackerPlayer, Monster* targetMonster) { +void Game::notifySpectators(const SpectatorHashSet &spectators, const Position &targetPos, std::shared_ptr attackerPlayer, std::shared_ptr targetMonster) { if (!spectators.empty()) { - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { if (!spectator) { continue; } @@ -6244,7 +6243,7 @@ void Game::notifySpectators(const SpectatorHashSet &spectators, const Position & } // Wheel of destiny combat helpers -void Game::applyWheelOfDestinyHealing(CombatDamage &damage, Player* attackerPlayer, const Creature* target) { +void Game::applyWheelOfDestinyHealing(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr target) { damage.primary.value += (damage.primary.value * damage.healingMultiplier) / 100.; if (attackerPlayer) { @@ -6267,7 +6266,7 @@ void Game::applyWheelOfDestinyHealing(CombatDamage &damage, Player* attackerPlay } } -void Game::applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, const Player* attackerPlayer, const Creature* target) const { +void Game::applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr target) const { // If damage is 0, it means the target is immune to the damage type, or that we missed. if (damage.primary.value == 0 && damage.secondary.value == 0) { return; @@ -6300,11 +6299,11 @@ void Game::applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, const Player } } -int32_t Game::applyHealthChange(CombatDamage &damage, const Creature* target) const { +int32_t Game::applyHealthChange(CombatDamage &damage, std::shared_ptr target) const { int32_t targetHealth = target->getHealth(); // Wheel of destiny (Gift of Life) - if (const Player* targetPlayer = target->getPlayer()) { + if (std::shared_ptr targetPlayer = target->getPlayer()) { if (targetPlayer->wheel()->getInstant("Gift of Life") && targetPlayer->wheel()->getGiftOfCooldown() == 0 && (damage.primary.value + damage.secondary.value) >= targetHealth) { int32_t overkillMultiplier = (damage.primary.value + damage.secondary.value) - targetHealth; overkillMultiplier = (overkillMultiplier * 100) / targetPlayer->getMaxHealth(); @@ -6325,7 +6324,7 @@ int32_t Game::applyHealthChange(CombatDamage &damage, const Creature* target) co return targetHealth; } -bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage &damage, bool isEvent /*= false*/) { +bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_ptr target, CombatDamage &damage, bool isEvent /*= false*/) { using namespace std; const Position &targetPos = target->getPosition(); if (damage.primary.value > 0) { @@ -6333,14 +6332,14 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage return false; } - Player* attackerPlayer; + std::shared_ptr attackerPlayer; if (attacker) { attackerPlayer = attacker->getPlayer(); } else { attackerPlayer = nullptr; } - Player* targetPlayer = target->getPlayer(); + auto targetPlayer = target->getPlayer(); if (attackerPlayer && targetPlayer && attackerPlayer->getSkull() == SKULL_BLACK && attackerPlayer->getSkullClient(targetPlayer) == SKULL_NONE) { return false; } @@ -6387,8 +6386,8 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage SpectatorHashSet spectators; map.getSpectators(spectators, targetPos, false, true); - for (Creature* spectator : spectators) { - Player* tmpPlayer = spectator->getPlayer(); + for (auto spectator : spectators) { + auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; @@ -6441,14 +6440,14 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage return true; } - Player* attackerPlayer; + std::shared_ptr attackerPlayer; if (attacker) { attackerPlayer = attacker->getPlayer(); } else { attackerPlayer = nullptr; } - Player* targetPlayer = target->getPlayer(); + auto targetPlayer = target->getPlayer(); if (attackerPlayer && targetPlayer && attackerPlayer->getSkull() == SKULL_BLACK && attackerPlayer->getSkullClient(targetPlayer) == SKULL_NONE) { return false; } @@ -6459,14 +6458,14 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage damage.primary.value = std::abs(damage.primary.value); damage.secondary.value = std::abs(damage.secondary.value); - Monster* targetMonster; + std::shared_ptr targetMonster; if (target && target->getMonster()) { targetMonster = target->getMonster(); } else { targetMonster = nullptr; } - const Monster* attackerMonster; + std::shared_ptr attackerMonster; if (attacker && attacker->getMonster()) { attackerMonster = attacker->getMonster(); } else { @@ -6480,9 +6479,9 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage int32_t distanceY = Position::getDistanceY(targetPos, attackerPos); int32_t damageX = attackerPlayer->getPerfectShotDamage(distanceX, true); int32_t damageY = attackerPlayer->getPerfectShotDamage(distanceY, true); - Item* item = attackerPlayer->getWeapon(); + std::shared_ptr item = attackerPlayer->getWeapon(); if (item && item->getWeaponType() == WEAPON_DISTANCE) { - Item* quiver = attackerPlayer->getInventoryItem(CONST_SLOT_RIGHT); + std::shared_ptr quiver = attackerPlayer->getInventoryItem(CONST_SLOT_RIGHT); if (quiver && quiver->getWeaponType()) { if (quiver->getPerfectShotRange() == distanceX) { damageX -= quiver->getPerfectShotDamage(); @@ -6604,12 +6603,12 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage message.primary.value = manaDamage; message.primary.color = TEXTCOLOR_BLUE; - for (Creature* spectator : spectators) { + for (std::shared_ptr spectator : spectators) { if (!spectator) { continue; } - Player* tmpPlayer = spectator->getPlayer(); + std::shared_ptr tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; } @@ -6746,7 +6745,7 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage return true; } -void Game::updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, const Player* player) const { +void Game::updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, std::shared_ptr player) const { if (!player) { return; } @@ -6762,8 +6761,8 @@ void Game::updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, const Playe } void Game::sendDamageMessageAndEffects( - const Creature* attacker, Creature* target, const CombatDamage &damage, - const Position &targetPos, Player* attackerPlayer, Player* targetPlayer, + std::shared_ptr attacker, std::shared_ptr target, const CombatDamage &damage, + const Position &targetPos, std::shared_ptr attackerPlayer, std::shared_ptr targetPlayer, TextMessage &message, const SpectatorHashSet &spectators, int32_t realDamage ) { message.primary.value = damage.primary.value; @@ -6781,8 +6780,8 @@ bool Game::shouldSendMessage(const TextMessage &message) const { } void Game::sendMessages( - const Creature* attacker, const Creature* target, const CombatDamage &damage, - const Position &targetPos, Player* attackerPlayer, Player* targetPlayer, + std::shared_ptr attacker, std::shared_ptr target, const CombatDamage &damage, + const Position &targetPos, std::shared_ptr attackerPlayer, std::shared_ptr targetPlayer, TextMessage &message, const SpectatorHashSet &spectators, int32_t realDamage ) const { if (attackerPlayer) { @@ -6811,8 +6810,8 @@ void Game::sendMessages( std::string spectatorMessage; - for (Creature* spectator : spectators) { - Player* tmpPlayer = spectator->getPlayer(); + for (std::shared_ptr spectator : spectators) { + std::shared_ptr tmpPlayer = spectator->getPlayer(); if (tmpPlayer->getPosition().z != targetPos.z) { continue; } @@ -6829,8 +6828,8 @@ void Game::sendMessages( } void Game::buildMessageAsSpectator( - const Creature* attacker, const Creature* target, const CombatDamage &damage, - const Player* targetPlayer, TextMessage &message, std::stringstream &ss, + std::shared_ptr attacker, std::shared_ptr target, const CombatDamage &damage, + std::shared_ptr targetPlayer, TextMessage &message, std::stringstream &ss, const std::string &damageString, std::string &spectatorMessage ) const { if (spectatorMessage.empty()) { @@ -6860,8 +6859,8 @@ void Game::buildMessageAsSpectator( } void Game::buildMessageAsTarget( - const Creature* attacker, const CombatDamage &damage, const Player* attackerPlayer, - const Player* targetPlayer, TextMessage &message, std::stringstream &ss, + std::shared_ptr attacker, const CombatDamage &damage, std::shared_ptr attackerPlayer, + std::shared_ptr targetPlayer, TextMessage &message, std::stringstream &ss, const std::string &damageString ) const { ss.str({}); @@ -6881,7 +6880,7 @@ void Game::buildMessageAsTarget( } void Game::buildMessageAsAttacker( - const Creature* target, const CombatDamage &damage, TextMessage &message, + std::shared_ptr target, const CombatDamage &damage, TextMessage &message, std::stringstream &ss, const std::string &damageString ) const { ss.str({}); @@ -6897,7 +6896,7 @@ void Game::buildMessageAsAttacker( } void Game::sendEffects( - Creature* target, const CombatDamage &damage, const Position &targetPos, TextMessage &message, + std::shared_ptr target, const CombatDamage &damage, const Position &targetPos, TextMessage &message, const SpectatorHashSet &spectators ) { uint16_t hitEffect; @@ -6917,7 +6916,7 @@ void Game::sendEffects( } void Game::applyCharmRune( - const Monster* targetMonster, Player* attackerPlayer, Creature* target, const int32_t &realDamage + std::shared_ptr targetMonster, std::shared_ptr attackerPlayer, std::shared_ptr target, const int32_t &realDamage ) const { if (!targetMonster || !attackerPlayer) { return; @@ -6935,7 +6934,7 @@ void Game::applyCharmRune( // Mana leech void Game::applyManaLeech( - Player* attackerPlayer, const Monster* targetMonster, Creature* target, const CombatDamage &damage, const int32_t &realDamage + std::shared_ptr attackerPlayer, std::shared_ptr targetMonster, std::shared_ptr target, const CombatDamage &damage, const int32_t &realDamage ) const { // Wheel of destiny bonus - mana leech chance and amount auto wheelLeechChance = attackerPlayer->wheel()->checkDrainBodyLeech(target, SKILL_MANA_LEECH_CHANCE); @@ -6968,7 +6967,7 @@ void Game::applyManaLeech( // Life leech void Game::applyLifeLeech( - Player* attackerPlayer, const Monster* targetMonster, Creature* target, const CombatDamage &damage, const int32_t &realDamage + std::shared_ptr attackerPlayer, std::shared_ptr targetMonster, std::shared_ptr target, const CombatDamage &damage, const int32_t &realDamage ) const { // Wheel of destiny bonus - life leech chance and amount auto wheelLeechChance = attackerPlayer->wheel()->checkDrainBodyLeech(target, SKILL_LIFE_LEECH_CHANCE); @@ -7002,18 +7001,18 @@ int32_t Game::calculateLeechAmount(const int32_t &realDamage, const uint16_t &sk return std::clamp(static_cast(std::lround(intermediateResult)), 0, realDamage); } -bool Game::combatChangeMana(Creature* attacker, Creature* target, CombatDamage &damage) { +bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr target, CombatDamage &damage) { const Position &targetPos = target->getPosition(); auto manaChange = damage.primary.value + damage.secondary.value; if (manaChange > 0) { - Player* attackerPlayer; + std::shared_ptr attackerPlayer; if (attacker) { attackerPlayer = attacker->getPlayer(); } else { attackerPlayer = nullptr; } - Player* targetPlayer = target->getPlayer(); + auto targetPlayer = target->getPlayer(); if (attackerPlayer && targetPlayer && attackerPlayer->getSkull() == SKULL_BLACK && attackerPlayer->getSkullClient(targetPlayer) == SKULL_NONE) { return false; } @@ -7058,8 +7057,8 @@ bool Game::combatChangeMana(Creature* attacker, Creature* target, CombatDamage & SpectatorHashSet spectators; map.getSpectators(spectators, targetPos, false, true); - for (Creature* spectator : spectators) { - Player* tmpPlayer = spectator->getPlayer(); + for (auto spectator : spectators) { + auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; @@ -7092,14 +7091,14 @@ bool Game::combatChangeMana(Creature* attacker, Creature* target, CombatDamage & return false; } - Player* attackerPlayer; + std::shared_ptr attackerPlayer; if (attacker) { attackerPlayer = attacker->getPlayer(); } else { attackerPlayer = nullptr; } - Player* targetPlayer = target->getPlayer(); + auto targetPlayer = target->getPlayer(); if (attackerPlayer && targetPlayer && attackerPlayer->getSkull() == SKULL_BLACK && attackerPlayer->getSkullClient(targetPlayer) == SKULL_NONE) { return false; } @@ -7158,8 +7157,8 @@ bool Game::combatChangeMana(Creature* attacker, Creature* target, CombatDamage & SpectatorHashSet spectators; map.getSpectators(spectators, targetPos, false, true); - for (Creature* spectator : spectators) { - Player* tmpPlayer = spectator->getPlayer(); + for (auto spectator : spectators) { + auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; @@ -7207,40 +7206,40 @@ bool Game::combatChangeMana(Creature* attacker, Creature* target, CombatDamage & return true; } -void Game::addCreatureHealth(const Creature* target) { +void Game::addCreatureHealth(std::shared_ptr target) { SpectatorHashSet spectators; map.getSpectators(spectators, target->getPosition(), true, true); addCreatureHealth(spectators, target); } -void Game::addCreatureHealth(const SpectatorHashSet &spectators, const Creature* target) { +void Game::addCreatureHealth(const SpectatorHashSet &spectators, std::shared_ptr target) { uint8_t healthPercent = std::ceil((static_cast(target->getHealth()) / std::max(target->getMaxHealth(), 1)) * 100); - if (const Player* targetPlayer = target->getPlayer()) { + if (std::shared_ptr targetPlayer = target->getPlayer()) { if (Party* party = targetPlayer->getParty()) { party->updatePlayerHealth(targetPlayer, target, healthPercent); } - } else if (const Creature* master = target->getMaster()) { - if (const Player* masterPlayer = master->getPlayer()) { + } else if (std::shared_ptr master = target->getMaster()) { + if (std::shared_ptr masterPlayer = master->getPlayer()) { if (Party* party = masterPlayer->getParty()) { party->updatePlayerHealth(masterPlayer, target, healthPercent); } } } - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (std::shared_ptr spectator : spectators) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendCreatureHealth(target); } } } -void Game::addPlayerMana(const Player* target) { +void Game::addPlayerMana(std::shared_ptr target) { if (Party* party = target->getParty()) { uint8_t manaPercent = std::ceil((static_cast(target->getMana()) / std::max(target->getMaxMana(), 1)) * 100); party->updatePlayerMana(target, manaPercent); } } -void Game::addPlayerVocation(const Player* target) { +void Game::addPlayerVocation(std::shared_ptr target) { if (Party* party = target->getParty()) { party->updatePlayerVocation(target); } @@ -7248,8 +7247,8 @@ void Game::addPlayerVocation(const Player* target) { SpectatorHashSet spectators; map.getSpectators(spectators, target->getPosition(), true, true); - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendPlayerVocation(target); } } @@ -7262,8 +7261,8 @@ void Game::addMagicEffect(const Position &pos, uint16_t effect) { } void Game::addMagicEffect(const SpectatorHashSet &spectators, const Position &pos, uint16_t effect) { - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendMagicEffect(pos, effect); } } @@ -7276,8 +7275,8 @@ void Game::removeMagicEffect(const Position &pos, uint16_t effect) { } void Game::removeMagicEffect(const SpectatorHashSet &spectators, const Position &pos, uint16_t effect) { - for (Creature* spectator : spectators) { - if (const Player* tmpPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (const auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->removeMagicEffect(pos, effect); } } @@ -7291,8 +7290,8 @@ void Game::addDistanceEffect(const Position &fromPos, const Position &toPos, uin } void Game::addDistanceEffect(const SpectatorHashSet &spectators, const Position &fromPos, const Position &toPos, uint16_t effect) { - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendDistanceShoot(fromPos, toPos, effect); } } @@ -7424,11 +7423,11 @@ void Game::cleanup() { ToReleaseItems.clear(); } -void Game::ReleaseCreature(Creature* creature) { +void Game::ReleaseCreature(std::shared_ptr creature) { ToReleaseCreatures.push_back(creature); } -void Game::ReleaseItem(Item* item) { +void Game::ReleaseItem(std::shared_ptr item) { if (!item) { return; } @@ -7452,45 +7451,45 @@ void Game::broadcastMessage(const std::string &text, MessageClasses type) const } } -void Game::updateCreatureWalkthrough(const Creature* creature) { +void Game::updateCreatureWalkthrough(std::shared_ptr creature) { // send to clients SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); - for (Creature* spectator : spectators) { - Player* tmpPlayer = spectator->getPlayer(); + for (auto spectator : spectators) { + auto tmpPlayer = spectator->getPlayer(); tmpPlayer->sendCreatureWalkthrough(creature, tmpPlayer->canWalkthroughEx(creature)); } } -void Game::updateCreatureSkull(const Creature* creature) { +void Game::updateCreatureSkull(std::shared_ptr creature) { if (getWorldType() != WORLD_TYPE_PVP) { return; } SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->getPlayer()->sendCreatureSkull(creature); } } -void Game::updatePlayerShield(Player* player) { +void Game::updatePlayerShield(std::shared_ptr player) { SpectatorHashSet spectators; map.getSpectators(spectators, player->getPosition(), true, true); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->getPlayer()->sendCreatureShield(player); } } -void Game::updateCreatureType(Creature* creature) { +void Game::updateCreatureType(std::shared_ptr creature) { if (!creature) { return; } - const Player* masterPlayer = nullptr; + std::shared_ptr masterPlayer = nullptr; CreatureType_t creatureType = creature->getType(); if (creatureType == CREATURETYPE_MONSTER) { - const Creature* master = creature->getMaster(); + std::shared_ptr master = creature->getMaster(); if (master) { masterPlayer = master->getPlayer(); if (masterPlayer) { @@ -7506,8 +7505,8 @@ void Game::updateCreatureType(Creature* creature) { SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); if (creatureType == CREATURETYPE_SUMMON_OTHERS) { - for (Creature* spectator : spectators) { - Player* player = spectator->getPlayer(); + for (auto spectator : spectators) { + auto player = spectator->getPlayer(); if (!player) { continue; } @@ -7519,8 +7518,8 @@ void Game::updateCreatureType(Creature* creature) { } } } else { - for (Creature* spectator : spectators) { - if (Player* player = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto player = spectator->getPlayer()) { player->sendCreatureType(creature, creatureType); } } @@ -7598,12 +7597,12 @@ void Game::playerInviteToParty(uint32_t playerId, uint32_t invitedId) { return; } - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Player* invitedPlayer = getPlayerByID(invitedId); + std::shared_ptr invitedPlayer = getPlayerByID(invitedId); if (!invitedPlayer || invitedPlayer->isInviting(player)) { return; } @@ -7622,10 +7621,10 @@ void Game::playerInviteToParty(uint32_t playerId, uint32_t invitedId) { return; } - party->invitePlayer(*invitedPlayer); + party->invitePlayer(invitedPlayer); } -void Game::updatePlayerHelpers(Player* player) { +void Game::updatePlayerHelpers(std::shared_ptr player) { if (!player) { return; } @@ -7634,7 +7633,7 @@ void Game::updatePlayerHelpers(Player* player) { SpectatorHashSet spectators; map.getSpectators(spectators, player->getPosition(), true, true); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { if (!spectator || !spectator->getPlayer()) { continue; } @@ -7644,12 +7643,12 @@ void Game::updatePlayerHelpers(Player* player) { } void Game::playerJoinParty(uint32_t playerId, uint32_t leaderId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Player* leader = getPlayerByID(leaderId); + std::shared_ptr leader = getPlayerByID(leaderId); if (!leader || !leader->isInviting(player)) { return; } @@ -7664,11 +7663,11 @@ void Game::playerJoinParty(uint32_t playerId, uint32_t leaderId) { return; } - party->joinParty(*player); + party->joinParty(player); } void Game::playerRevokePartyInvitation(uint32_t playerId, uint32_t invitedId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -7678,16 +7677,16 @@ void Game::playerRevokePartyInvitation(uint32_t playerId, uint32_t invitedId) { return; } - Player* invitedPlayer = getPlayerByID(invitedId); + std::shared_ptr invitedPlayer = getPlayerByID(invitedId); if (!invitedPlayer || !player->isInviting(invitedPlayer)) { return; } - party->revokeInvitation(*invitedPlayer); + party->revokeInvitation(invitedPlayer); } void Game::playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -7697,7 +7696,7 @@ void Game::playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId) { return; } - Player* newLeader = getPlayerByID(newLeaderId); + std::shared_ptr newLeader = getPlayerByID(newLeaderId); if (!newLeader || !player->isPartner(newLeader)) { return; } @@ -7706,7 +7705,7 @@ void Game::playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId) { } void Game::playerLeaveParty(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -7720,13 +7719,13 @@ void Game::playerLeaveParty(uint32_t playerId) { } void Game::playerEnableSharedPartyExperience(uint32_t playerId, bool sharedExpActive) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Party* party = player->getParty(); - Tile* playerTile = player->getTile(); + auto party = player->getParty(); + auto playerTile = player->getTile(); if (!party || (player->hasCondition(CONDITION_INFIGHT) && playerTile && !playerTile->hasFlag(TILESTATE_PROTECTIONZONE))) { return; } @@ -7735,7 +7734,7 @@ void Game::playerEnableSharedPartyExperience(uint32_t playerId, bool sharedExpAc } void Game::sendGuildMotd(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -7747,7 +7746,7 @@ void Game::sendGuildMotd(uint32_t playerId) { } void Game::kickPlayer(uint32_t playerId, bool displayEffect) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -7755,7 +7754,7 @@ void Game::kickPlayer(uint32_t playerId, bool displayEffect) { player->removePlayer(displayEffect); } -void Game::playerCyclopediaCharacterInfo(Player* player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page) { +void Game::playerCyclopediaCharacterInfo(std::shared_ptr player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page) { uint32_t playerGUID = player->getGUID(); if (characterID != playerGUID) { // For now allow viewing only our character since we don't have tournaments supported @@ -7780,7 +7779,7 @@ void Game::playerCyclopediaCharacterInfo(Player* player, uint32_t characterID, C uint32_t playerID = player->getID(); std::function callback = [playerID, page, entriesPerPage](DBResult_ptr result, bool) { - Player* player = g_game().getPlayerByID(playerID); + std::shared_ptr player = g_game().getPlayerByID(playerID); if (!player) { return; } @@ -7845,7 +7844,7 @@ void Game::playerCyclopediaCharacterInfo(Player* player, uint32_t characterID, C uint32_t playerID = player->getID(); std::function callback = [playerID, page, entriesPerPage](DBResult_ptr result, bool) { - Player* player = g_game().getPlayerByID(playerID); + std::shared_ptr player = g_game().getPlayerByID(playerID); if (!player) { return; } @@ -7915,7 +7914,7 @@ void Game::playerCyclopediaCharacterInfo(Player* player, uint32_t characterID, C } } -void Game::playerHighscores(Player* player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &, uint16_t page, uint8_t entriesPerPage) { +void Game::playerHighscores(std::shared_ptr player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &, uint16_t page, uint8_t entriesPerPage) { if (player->hasAsyncOngoingTask(PlayerAsyncTask_Highscore)) { return; } @@ -7999,7 +7998,7 @@ void Game::playerHighscores(Player* player, HighscoreType_t type, uint8_t catego uint32_t playerID = player->getID(); std::function callback = [playerID, category, vocation, entriesPerPage](DBResult_ptr result, bool) { - Player* player = g_game().getPlayerByID(playerID); + std::shared_ptr player = g_game().getPlayerByID(playerID); if (!player) { return; } @@ -8034,7 +8033,7 @@ void Game::playerHighscores(Player* player, HighscoreType_t type, uint8_t catego } void Game::playerReportRuleViolationReport(uint32_t playerId, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8044,7 +8043,7 @@ void Game::playerReportRuleViolationReport(uint32_t playerId, const std::string } void Game::playerReportBug(uint32_t playerId, const std::string &message, const Position &position, uint8_t category) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8054,7 +8053,7 @@ void Game::playerReportBug(uint32_t playerId, const std::string &message, const } void Game::playerDebugAssert(uint32_t playerId, const std::string &assertLine, const std::string &date, const std::string &description, const std::string &comment) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8069,7 +8068,7 @@ void Game::playerDebugAssert(uint32_t playerId, const std::string &assertLine, c } void Game::playerPreyAction(uint32_t playerId, uint8_t slot, uint8_t action, uint8_t option, int8_t index, uint16_t raceId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8078,7 +8077,7 @@ void Game::playerPreyAction(uint32_t playerId, uint8_t slot, uint8_t action, uin } void Game::playerTaskHuntingAction(uint32_t playerId, uint8_t slot, uint8_t action, bool upgrade, uint16_t raceId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8087,12 +8086,12 @@ void Game::playerTaskHuntingAction(uint32_t playerId, uint8_t slot, uint8_t acti } void Game::playerNpcGreet(uint32_t playerId, uint32_t npcId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Npc* npc = getNpcByID(npcId); + std::shared_ptr npc = getNpcByID(npcId); if (!npc) { return; } @@ -8111,7 +8110,7 @@ void Game::playerNpcGreet(uint32_t playerId, uint32_t npcId) { } void Game::playerLeaveMarket(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8120,7 +8119,7 @@ void Game::playerLeaveMarket(uint32_t playerId) { } void Game::playerBrowseMarket(uint32_t playerId, uint16_t itemId, uint8_t tier) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8145,7 +8144,7 @@ void Game::playerBrowseMarket(uint32_t playerId, uint16_t itemId, uint8_t tier) } void Game::playerBrowseMarketOwnOffers(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8160,7 +8159,7 @@ void Game::playerBrowseMarketOwnOffers(uint32_t playerId) { } void Game::playerBrowseMarketOwnHistory(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8175,28 +8174,28 @@ void Game::playerBrowseMarketOwnHistory(uint32_t playerId) { } namespace { - bool removeOfferItems(Player &player, DepotLocker &depotLocker, const ItemType &itemType, uint16_t amount, uint8_t tier, std::ostringstream &offerStatus) { + bool removeOfferItems(const std::shared_ptr &player, const std::shared_ptr &depotLocker, const ItemType &itemType, uint16_t amount, uint8_t tier, std::ostringstream &offerStatus) { uint16_t removeAmount = amount; if ( // Init-statement - auto stashItemCount = player.getStashItemCount(itemType.wareId); + auto stashItemCount = player->getStashItemCount(itemType.wareId); // Condition stashItemCount > 0 ) { - if (removeAmount > stashItemCount && player.withdrawItem(itemType.wareId, stashItemCount)) { + if (removeAmount > stashItemCount && player->withdrawItem(itemType.wareId, stashItemCount)) { removeAmount -= stashItemCount; - } else if (player.withdrawItem(itemType.wareId, removeAmount)) { + } else if (player->withdrawItem(itemType.wareId, removeAmount)) { removeAmount = 0; } else { - offerStatus << "Failed to remove stash items from player " << player.getName(); + offerStatus << "Failed to remove stash items from player " << player->getName(); return false; } } - auto [itemVector, totalCount] = player.getLockerItemsAndCountById(depotLocker, tier, itemType.id); + auto [itemVector, totalCount] = player->getLockerItemsAndCountById(depotLocker, tier, itemType.id); if (removeAmount > 0) { if (totalCount == 0 || itemVector.size() == 0) { - offerStatus << "Player " << player.getName() << " not have item for create offer"; + offerStatus << "Player " << player->getName() << " not have item for create offer"; return false; } @@ -8215,7 +8214,7 @@ namespace { // Condition ret != RETURNVALUE_NOERROR ) { - offerStatus << "Failed to remove items from player " << player.getName() << " error: " << getReturnMessage(ret); + offerStatus << "Failed to remove items from player " << player->getName() << " error: " << getReturnMessage(ret); return false; } @@ -8229,7 +8228,7 @@ namespace { } auto ret = g_game().internalRemoveItem(item); if (ret != RETURNVALUE_NOERROR) { - offerStatus << "Failed to remove items from player " << player.getName() << " error: " << getReturnMessage(ret); + offerStatus << "Failed to remove items from player " << player->getName() << " error: " << getReturnMessage(ret); return false; } else { removeAmount -= 1; @@ -8238,7 +8237,7 @@ namespace { } } if (removeAmount > 0) { - g_logger().error("Player {} tried to sell an item {} without this item", itemType.id, player.getName()); + g_logger().error("Player {} tried to sell an item {} without this item", itemType.id, player->getName()); offerStatus << "The item you tried to market is not correct. Check the item again."; return false; } @@ -8246,7 +8245,7 @@ namespace { } } // namespace -bool checkCanInitCreateMarketOffer(const Player* player, uint8_t type, const ItemType &it, uint16_t amount, uint64_t price, std::ostringstream &offerStatus) { +bool checkCanInitCreateMarketOffer(std::shared_ptr player, uint8_t type, const ItemType &it, uint16_t amount, uint64_t price, std::ostringstream &offerStatus) { if (!player) { offerStatus << "Failed to load player"; return false; @@ -8312,7 +8311,7 @@ void Game::playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t ite // Initialize variables // Before creating the offer we will compare it with the RETURN VALUE ERROR std::ostringstream offerStatus; - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); const ItemType &it = Item::items[itemId]; // Make sure everything is ok before the create market offer starts @@ -8331,7 +8330,7 @@ void Game::playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t ite return; } - DepotLocker* depotLocker = player->getDepotLocker(player->getLastDepotId()); + std::shared_ptr depotLocker = player->getDepotLocker(player->getLastDepotId()); if (depotLocker == nullptr) { offerStatus << "Depot locker is nullptr for player " << player->getName(); return; @@ -8348,7 +8347,7 @@ void Game::playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t ite // Do not register a transaction for coins creating an offer player->getAccount()->removeCoins(account::CoinType::TRANSFERABLE, static_cast(amount), ""); } else { - if (!removeOfferItems(*player, *depotLocker, it, amount, tier, offerStatus)) { + if (!removeOfferItems(player, depotLocker, it, amount, tier, offerStatus)) { g_logger().error("[{}] failed to remove item with id {}, from player {}, errorcode: {}", __FUNCTION__, it.id, player->getName(), offerStatus.str()); return; } @@ -8404,7 +8403,7 @@ void Game::playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t ite } void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->getAccount()) { return; } @@ -8440,9 +8439,9 @@ void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 uint16_t tmpAmount = offer.amount; while (tmpAmount > 0) { int32_t stackCount = std::min(it.stackSize, tmpAmount); - Item* item = Item::CreateItem(it.id, stackCount); + std::shared_ptr item = Item::CreateItem(it.id, stackCount); if (internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { - delete item; + break; } @@ -8461,9 +8460,9 @@ void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 } for (uint16_t i = 0; i < offer.amount; ++i) { - Item* item = Item::CreateItem(it.id, subType); + std::shared_ptr item = Item::CreateItem(it.id, subType); if (internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { - delete item; + break; } @@ -8488,7 +8487,7 @@ void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter, uint16_t amount) { std::ostringstream offerStatus; - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->getAccount()) { offerStatus << "Failed to load player"; return; @@ -8526,17 +8525,17 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 // The player has an offer to by something and someone is going to sell to item type // so the market action is 'buy' as who created the offer is buying. if (offer.type == MARKETACTION_BUY) { - DepotLocker* depotLocker = player->getDepotLocker(player->getLastDepotId()); + std::shared_ptr depotLocker = player->getDepotLocker(player->getLastDepotId()); if (depotLocker == nullptr) { offerStatus << "Depot locker is nullptr"; return; } - Player* buyerPlayer = getPlayerByGUID(offer.playerId); + std::shared_ptr buyerPlayer = getPlayerByGUID(offer.playerId); if (!buyerPlayer) { - buyerPlayer = new Player(nullptr); + buyerPlayer = std::make_shared(nullptr); if (!IOLoginData::loadPlayerById(buyerPlayer, offer.playerId)) { - delete buyerPlayer; + offerStatus << "Failed to load buyer player " << player->getName(); return; } @@ -8571,7 +8570,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 "Sold on Market" ); } else { - if (!removeOfferItems(*player, *depotLocker, it, amount, offer.tier, offerStatus)) { + if (!removeOfferItems(player, depotLocker, it, amount, offer.tier, offerStatus)) { g_logger().error("[{}] failed to remove item with id {}, from player {}, errorcode: {}", __FUNCTION__, it.id, player->getName(), offerStatus.str()); return; } @@ -8598,10 +8597,10 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 uint16_t tmpAmount = amount; while (tmpAmount > 0) { uint16_t stackCount = std::min(it.stackSize, tmpAmount); - Item* item = Item::CreateItem(it.id, stackCount); + std::shared_ptr item = Item::CreateItem(it.id, stackCount); if (internalAddItem(buyerPlayer->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { offerStatus << "Failed to add player inbox stackable item for buy offer for player " << player->getName(); - delete item; + break; } @@ -8620,10 +8619,10 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 } for (uint16_t i = 0; i < amount; ++i) { - Item* item = Item::CreateItem(it.id, subType); + std::shared_ptr item = Item::CreateItem(it.id, subType); if (internalAddItem(buyerPlayer->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { offerStatus << "Failed to add player inbox item for buy offer for player " << player->getName(); - delete item; + break; } @@ -8635,15 +8634,14 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 if (buyerPlayer->isOffline()) { IOLoginData::savePlayer(buyerPlayer); - delete buyerPlayer; } } else if (offer.type == MARKETACTION_SELL) { - Player* sellerPlayer = getPlayerByGUID(offer.playerId); + std::shared_ptr sellerPlayer = getPlayerByGUID(offer.playerId); if (!sellerPlayer) { - sellerPlayer = new Player(nullptr); + sellerPlayer = std::make_shared(nullptr); if (!IOLoginData::loadPlayerById(sellerPlayer, offer.playerId)) { offerStatus << "Failed to load seller player"; - delete sellerPlayer; + return; } } @@ -8673,7 +8671,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 uint16_t tmpAmount = amount; while (tmpAmount > 0) { uint16_t stackCount = std::min(it.stackSize, tmpAmount); - Item* item = Item::CreateItem(it.id, stackCount); + std::shared_ptr item = Item::CreateItem(it.id, stackCount); if ( // Init-statement auto ret = internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT); @@ -8682,7 +8680,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 ) { g_logger().error("{} - Create offer internal add item error code: {}", __FUNCTION__, getReturnMessage(ret)); offerStatus << "Failed to add inbox stackable item for sell offer for player " << player->getName(); - delete item; + break; } @@ -8701,7 +8699,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 } for (uint16_t i = 0; i < amount; ++i) { - Item* item = Item::CreateItem(it.id, subType); + std::shared_ptr item = Item::CreateItem(it.id, subType); if ( // Init-statement auto ret = internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT); @@ -8709,7 +8707,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 ret != RETURNVALUE_NOERROR ) { offerStatus << "Failed to add inbox item for sell offer for player " << player->getName(); - delete item; + break; } @@ -8730,7 +8728,6 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 if (sellerPlayer->isOffline()) { IOLoginData::savePlayer(sellerPlayer); - delete sellerPlayer; } } @@ -8765,7 +8762,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 } void Game::parsePlayerExtendedOpcode(uint32_t playerId, uint8_t opcode, const std::string &buffer) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8776,7 +8773,7 @@ void Game::parsePlayerExtendedOpcode(uint32_t playerId, uint8_t opcode, const st } void Game::forceRemoveCondition(uint32_t creatureId, ConditionType_t conditionType, ConditionId_t conditionId) { - Creature* creature = getCreatureByID(creatureId); + std::shared_ptr creature = getCreatureByID(creatureId); if (!creature) { return; } @@ -8784,7 +8781,7 @@ void Game::forceRemoveCondition(uint32_t creatureId, ConditionType_t conditionTy creature->removeCondition(conditionType, conditionId, true); } -void Game::sendOfflineTrainingDialog(Player* player) { +void Game::sendOfflineTrainingDialog(std::shared_ptr player) { if (!player) { return; } @@ -8795,7 +8792,7 @@ void Game::sendOfflineTrainingDialog(Player* player) { } void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, uint8_t button, uint8_t choice) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8810,7 +8807,7 @@ void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, ui if (modalWindowId == std::numeric_limits::max()) { if (button == 1) { if (choice == SKILL_SWORD || choice == SKILL_AXE || choice == SKILL_CLUB || choice == SKILL_DISTANCE || choice == SKILL_MAGLEVEL) { - BedItem* bedItem = player->getBedItem(); + auto bedItem = player->getBedItem(); if (bedItem && bedItem->sleep(player)) { player->setOfflineTrainingSkill(static_cast(choice)); return; @@ -8829,7 +8826,7 @@ void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, ui } void Game::playerForgeFuseItems(uint32_t playerId, uint16_t itemId, uint8_t tier, bool usedCore, bool reduceTierLoss) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8854,7 +8851,7 @@ void Game::playerForgeFuseItems(uint32_t playerId, uint16_t itemId, uint8_t tier } void Game::playerForgeTransferItemTier(uint32_t playerId, uint16_t donorItemId, uint8_t tier, uint16_t receiveItemId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8863,7 +8860,7 @@ void Game::playerForgeTransferItemTier(uint32_t playerId, uint16_t donorItemId, } void Game::playerForgeResourceConversion(uint32_t playerId, uint8_t action) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8878,7 +8875,7 @@ void Game::playerForgeResourceConversion(uint32_t playerId, uint8_t action) { } void Game::playerBrowseForgeHistory(uint32_t playerId, uint8_t page) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8893,7 +8890,7 @@ void Game::playerBrowseForgeHistory(uint32_t playerId, uint8_t page) { } void Game::playerBosstiarySlot(uint32_t playerId, uint8_t slotId, uint32_t selectedBossId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8919,17 +8916,17 @@ void Game::playerBosstiarySlot(uint32_t playerId, uint8_t slotId, uint32_t selec } void Game::playerSetMonsterPodium(uint32_t playerId, uint32_t monsterRaceId, const Position &pos, uint8_t stackPos, const uint16_t itemId, uint8_t direction, const std::pair &podiumAndMonsterVisible) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || pos.x == 0xFFFF) { return; } - Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM); + std::shared_ptr thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM); if (!thing) { return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item || item->getID() != itemId || !item->isPodium() || item->hasAttribute(ItemAttribute_t::UNIQUEID)) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -9014,25 +9011,25 @@ void Game::playerSetMonsterPodium(uint32_t playerId, uint32_t monsterRaceId, con g_game().map.getSpectators(spectators, pos, true); // Send to client - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendUpdateTileItem(tile, pos, item); } } } void Game::playerRotatePodium(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM); + std::shared_ptr thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM); if (!thing) { return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item || item->getID() != itemId || item->hasAttribute(ItemAttribute_t::UNIQUEID)) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -9107,7 +9104,7 @@ void Game::playerRotatePodium(uint32_t playerId, const Position &pos, uint8_t st } void Game::playerRequestInventoryImbuements(uint32_t playerId, bool isTrackerOpen) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || player->isRemoved()) { return; } @@ -9117,7 +9114,7 @@ void Game::playerRequestInventoryImbuements(uint32_t playerId, bool isTrackerOpe return; } - std::map itemsWithImbueSlotMap; + std::map> itemsWithImbueSlotMap; for (uint8_t inventorySlot = CONST_SLOT_FIRST; inventorySlot <= CONST_SLOT_LAST; ++inventorySlot) { auto item = player->getInventoryItem(static_cast(inventorySlot)); if (!item) { @@ -9139,7 +9136,7 @@ void Game::playerRequestInventoryImbuements(uint32_t playerId, bool isTrackerOpe } void Game::playerOpenWheel(uint32_t playerId, uint32_t ownerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -9159,7 +9156,7 @@ void Game::playerOpenWheel(uint32_t playerId, uint32_t ownerId) { } void Game::playerSaveWheel(uint32_t playerId, NetworkMessage &msg) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -9177,7 +9174,7 @@ void Game::playerSaveWheel(uint32_t playerId, NetworkMessage &msg) { ********************/ void Game::updatePlayerSaleItems(uint32_t playerId) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -9187,33 +9184,33 @@ void Game::updatePlayerSaleItems(uint32_t playerId) { player->setScheduledSaleUpdate(false); } -void Game::addPlayer(Player* player) { +void Game::addPlayer(std::shared_ptr player) { const std::string &lowercase_name = asLowerCaseString(player->getName()); mappedPlayerNames[lowercase_name] = player; wildcardTree.insert(lowercase_name); players[player->getID()] = player; } -void Game::removePlayer(Player* player) { +void Game::removePlayer(std::shared_ptr player) { const std::string &lowercase_name = asLowerCaseString(player->getName()); mappedPlayerNames.erase(lowercase_name); wildcardTree.remove(lowercase_name); players.erase(player->getID()); } -void Game::addNpc(Npc* npc) { +void Game::addNpc(std::shared_ptr npc) { npcs[npc->getID()] = npc; } -void Game::removeNpc(Npc* npc) { +void Game::removeNpc(std::shared_ptr npc) { npcs.erase(npc->getID()); } -void Game::addMonster(Monster* monster) { +void Game::addMonster(std::shared_ptr monster) { monsters[monster->getID()] = monster; } -void Game::removeMonster(Monster* monster) { +void Game::removeMonster(std::shared_ptr monster) { monsters.erase(monster->getID()); } @@ -9256,7 +9253,7 @@ void Game::removeGuild(uint32_t guildId) { } void Game::decreaseBrowseFieldRef(const Position &pos) { - Tile* tile = map.getTile(pos.x, pos.y, pos.z); + std::shared_ptr tile = map.getTile(pos.x, pos.y, pos.z); if (!tile) { return; } @@ -9267,9 +9264,9 @@ void Game::decreaseBrowseFieldRef(const Position &pos) { } } -void Game::internalRemoveItems(const std::vector itemVector, uint32_t amount, bool stackable) { +void Game::internalRemoveItems(const std::vector> itemVector, uint32_t amount, bool stackable) { if (stackable) { - for (Item* item : itemVector) { + for (std::shared_ptr item : itemVector) { if (item->getItemCount() > amount) { internalRemoveItem(item, amount); break; @@ -9279,13 +9276,13 @@ void Game::internalRemoveItems(const std::vector itemVector, uint32_t amo } } } else { - for (Item* item : itemVector) { + for (std::shared_ptr item : itemVector) { internalRemoveItem(item); } } } -BedItem* Game::getBedBySleeper(uint32_t guid) const { +std::shared_ptr Game::getBedBySleeper(uint32_t guid) const { auto it = bedSleepersMap.find(guid); if (it == bedSleepersMap.end()) { return nullptr; @@ -9293,7 +9290,7 @@ BedItem* Game::getBedBySleeper(uint32_t guid) const { return it->second; } -void Game::setBedSleeper(BedItem* bed, uint32_t guid) { +void Game::setBedSleeper(std::shared_ptr bed, uint32_t guid) { bedSleepersMap[guid] = bed; } @@ -9304,7 +9301,7 @@ void Game::removeBedSleeper(uint32_t guid) { } } -Item* Game::getUniqueItem(uint16_t uniqueId) { +std::shared_ptr Game::getUniqueItem(uint16_t uniqueId) { auto it = uniqueItems.find(uniqueId); if (it == uniqueItems.end()) { return nullptr; @@ -9312,7 +9309,7 @@ Item* Game::getUniqueItem(uint16_t uniqueId) { return it->second; } -bool Game::addUniqueItem(uint16_t uniqueId, Item* item) { +bool Game::addUniqueItem(uint16_t uniqueId, std::shared_ptr item) { auto result = uniqueItems.emplace(uniqueId, item); if (!result.second) { g_logger().warn("Duplicate unique id: {}", uniqueId); @@ -9349,17 +9346,17 @@ bool Game::hasDistanceEffect(uint16_t effectId) { void Game::createLuaItemsOnMap() { for (const auto [position, itemId] : mapLuaItemsStored) { - Item* item = Item::CreateItem(itemId, 1); + std::shared_ptr item = Item::CreateItem(itemId, 1); if (!item) { g_logger().warn("[Game::createLuaItemsOnMap] - Cannot create item with id {}", itemId); continue; } if (position.x != 0) { - Tile* tile = g_game().map.getTile(position); + std::shared_ptr tile = g_game().map.getTile(position); if (!tile) { g_logger().warn("[Game::createLuaItemsOnMap] - Tile is wrong or not found position: {}", position.toString()); - delete item; + continue; } @@ -9374,15 +9371,15 @@ void Game::createLuaItemsOnMap() { } } -void Game::sendUpdateCreature(const Creature* creature) { +void Game::sendUpdateCreature(std::shared_ptr creature) { if (!creature) { return; } SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true); - for (Creature* spectator : spectators) { - if (const Player* tmpPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (const auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendUpdateCreature(creature); } } @@ -9401,7 +9398,7 @@ uint32_t Game::makeInfluencedMonster() { auto maxTries = forgeableMonsters.size(); uint16_t tries = 0; - Monster* monster = nullptr; + std::shared_ptr monster = nullptr; while (true) { if (tries == maxTries) { return 0; @@ -9478,7 +9475,7 @@ uint32_t Game::makeFiendishMonster(uint32_t forgeableMonsterId /* = 0*/, bool cr auto maxTries = forgeableMonsters.size(); uint16_t tries = 0; - Monster* monster = nullptr; + std::shared_ptr monster = nullptr; while (true) { if (tries == maxTries) { return 0; @@ -9553,7 +9550,7 @@ uint32_t Game::makeFiendishMonster(uint32_t forgeableMonsterId /* = 0*/, bool cr } void Game::updateFiendishMonsterStatus(uint32_t monsterId, const std::string &monsterName) { - Monster* monster = getMonsterByID(monsterId); + std::shared_ptr monster = getMonsterByID(monsterId); if (!monster) { g_logger().warn("[{}] Failed to update monster with id {} and name {}, monster not found", __FUNCTION__, monsterId, monsterName); return; @@ -9678,7 +9675,7 @@ void Game::checkForgeEventId(uint32_t monsterId) { } } -bool Game::addInfluencedMonster(Monster* monster) { +bool Game::addInfluencedMonster(std::shared_ptr monster) { if (monster && monster->canBeForgeMonster()) { if (auto maxInfluencedMonsters = static_cast(g_configManager().getNumber(FORGE_INFLUENCED_CREATURES_LIMIT)); // If condition @@ -9694,8 +9691,8 @@ bool Game::addInfluencedMonster(Monster* monster) { return false; } -bool Game::addItemStoreInbox(const Player* player, uint32_t itemId) { - Item* decoKit = Item::CreateItem(ITEM_DECORATION_KIT, 1); +bool Game::addItemStoreInbox(std::shared_ptr player, uint32_t itemId) { + std::shared_ptr decoKit = Item::CreateItem(ITEM_DECORATION_KIT, 1); if (!decoKit) { return false; } @@ -9704,17 +9701,17 @@ bool Game::addItemStoreInbox(const Player* player, uint32_t itemId) { decoKit->setAttribute(ItemAttribute_t::DESCRIPTION, description); decoKit->setCustomAttribute("unWrapId", static_cast(itemId)); - Thing* thing = player->getThing(CONST_SLOT_STORE_INBOX); + std::shared_ptr thing = player->getThing(CONST_SLOT_STORE_INBOX); if (!thing) { return false; } - Item* inboxItem = thing->getItem(); + std::shared_ptr inboxItem = thing->getItem(); if (!inboxItem) { return false; } - Container* inboxContainer = inboxItem->getContainer(); + std::shared_ptr inboxContainer = inboxItem->getContainer(); if (!inboxContainer) { return false; } @@ -9726,7 +9723,7 @@ bool Game::addItemStoreInbox(const Player* player, uint32_t itemId) { return true; } -void Game::addPlayerUniqueLogin(Player* player) { +void Game::addPlayerUniqueLogin(std::shared_ptr player) { if (!player) { g_logger().error("Attempted to add null player to unique player names list"); return; @@ -9736,7 +9733,7 @@ void Game::addPlayerUniqueLogin(Player* player) { m_uniqueLoginPlayerNames[lowercase_name] = player; } -Player* Game::getPlayerUniqueLogin(const std::string &playerName) const { +std::shared_ptr Game::getPlayerUniqueLogin(const std::string &playerName) const { if (playerName.empty()) { g_logger().error("Attempted to get player with empty name string"); return nullptr; @@ -9756,7 +9753,7 @@ void Game::removePlayerUniqueLogin(const std::string &playerName) { m_uniqueLoginPlayerNames.erase(lowercase_name); } -void Game::removePlayerUniqueLogin(Player* player) { +void Game::removePlayerUniqueLogin(std::shared_ptr player) { if (!player) { g_logger().error("Attempted to remove null player from unique player names list."); return; @@ -9767,7 +9764,7 @@ void Game::removePlayerUniqueLogin(Player* player) { } void Game::playerCheckActivity(const std::string &playerName, int interval) { - Player* player = getPlayerUniqueLogin(playerName); + std::shared_ptr player = getPlayerUniqueLogin(playerName); if (!player) { return; } @@ -9800,12 +9797,12 @@ void Game::playerCheckActivity(const std::string &playerName, int interval) { } void Game::playerRewardChestCollect(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, uint32_t maxMoveItems /* = 0*/) { - Player* player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_FIND_THING); + std::shared_ptr thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_FIND_THING); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -9823,7 +9820,7 @@ void Game::playerRewardChestCollect(uint32_t playerId, const Position &pos, uint } // Updates the parent of the reward chest and reward containers to avoid memory usage after cleaning - RewardChest* playerRewardChest = player->getRewardChest(); + auto playerRewardChest = player->getRewardChest(); if (playerRewardChest->empty()) { player->sendCancelMessage(RETURNVALUE_REWARDCHESTISEMPTY); return; @@ -9842,7 +9839,7 @@ void Game::playerRewardChestCollect(uint32_t playerId, const Position &pos, uint } } -bool Game::tryRetrieveStashItems(Player* player, Item* item) { +bool Game::tryRetrieveStashItems(std::shared_ptr player, std::shared_ptr item) { return internalCollectLootItems(player, item, OBJECTCATEGORY_STASHRETRIEVE) == RETURNVALUE_NOERROR; } @@ -9865,7 +9862,7 @@ phmap::parallel_flat_hash_set setDifference(const phmap::parallel_flat_hash_s return setResult; } -ReturnValue Game::beforeCreatureZoneChange(Creature* creature, const phmap::parallel_flat_hash_set> &fromZones, const phmap::parallel_flat_hash_set> &toZones, bool force /* = false*/) const { +ReturnValue Game::beforeCreatureZoneChange(std::shared_ptr creature, const phmap::parallel_flat_hash_set> &fromZones, const phmap::parallel_flat_hash_set> &toZones, bool force /* = false*/) const { if (!creature) { return RETURNVALUE_NOTPOSSIBLE; } @@ -9895,7 +9892,7 @@ ReturnValue Game::beforeCreatureZoneChange(Creature* creature, const phmap::para return RETURNVALUE_NOERROR; } -void Game::afterCreatureZoneChange(Creature* creature, const phmap::parallel_flat_hash_set> &fromZones, const phmap::parallel_flat_hash_set> &toZones) const { +void Game::afterCreatureZoneChange(std::shared_ptr creature, const phmap::parallel_flat_hash_set> &fromZones, const phmap::parallel_flat_hash_set> &toZones) const { if (!creature) { return; } diff --git a/src/game/game.hpp b/src/game/game.hpp index 047a7f47484..dd9bbbf2500 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -98,41 +98,41 @@ class Game { teamFinderMap.erase(leaderGuid); } - Cylinder* internalGetCylinder(Player* player, const Position &pos); - Thing* internalGetThing(Player* player, const Position &pos, int32_t index, uint32_t itemId, StackPosType_t type); - static void internalGetPosition(Item* item, Position &pos, uint8_t &stackpos); + std::shared_ptr internalGetCylinder(std::shared_ptr player, const Position &pos); + std::shared_ptr internalGetThing(std::shared_ptr player, const Position &pos, int32_t index, uint32_t itemId, StackPosType_t type); + static void internalGetPosition(std::shared_ptr item, Position &pos, uint8_t &stackpos); - static std::string getTradeErrorDescription(ReturnValue ret, Item* item); + static std::string getTradeErrorDescription(ReturnValue ret, std::shared_ptr item); - Creature* getCreatureByID(uint32_t id); + std::shared_ptr getCreatureByID(uint32_t id); - Monster* getMonsterByID(uint32_t id); + std::shared_ptr getMonsterByID(uint32_t id); - Npc* getNpcByID(uint32_t id); + std::shared_ptr getNpcByID(uint32_t id); - Creature* getCreatureByName(const std::string &s); + std::shared_ptr getCreatureByName(const std::string &s); - Npc* getNpcByName(const std::string &s); + std::shared_ptr getNpcByName(const std::string &s); - Player* getPlayerByID(uint32_t id, bool allowOffline = false); + std::shared_ptr getPlayerByID(uint32_t id, bool allowOffline = false); - Player* getPlayerByName(const std::string &s, bool allowOffline = false); + std::shared_ptr getPlayerByName(const std::string &s, bool allowOffline = false); - Player* getPlayerByGUID(const uint32_t &guid); + std::shared_ptr getPlayerByGUID(const uint32_t &guid); - ReturnValue getPlayerByNameWildcard(const std::string &s, Player*&player); + ReturnValue getPlayerByNameWildcard(const std::string &s, std::shared_ptr &player); - Player* getPlayerByAccount(uint32_t acc); + std::shared_ptr getPlayerByAccount(uint32_t acc); - bool internalPlaceCreature(Creature* creature, const Position &pos, bool extendedPos = false, bool forced = false, bool creatureCheck = false); + bool internalPlaceCreature(std::shared_ptr creature, const Position &pos, bool extendedPos = false, bool forced = false, bool creatureCheck = false); - bool placeCreature(Creature* creature, const Position &pos, bool extendedPos = false, bool force = false); + bool placeCreature(std::shared_ptr creature, const Position &pos, bool extendedPos = false, bool force = false); - bool removeCreature(Creature* creature, bool isLogout = true); + bool removeCreature(std::shared_ptr creature, bool isLogout = true); void executeDeath(uint32_t creatureId); - void addCreatureCheck(Creature* creature); - static void removeCreatureCheck(Creature* creature); + void addCreatureCheck(std::shared_ptr creature); + static void removeCreatureCheck(std::shared_ptr creature); size_t getPlayersOnline() const { return players.size(); @@ -173,43 +173,43 @@ class Game { bool gameIsDay(); - ReturnValue internalMoveCreature(Creature* creature, Direction direction, uint32_t flags = 0); - ReturnValue internalMoveCreature(Creature &creature, Tile &toTile, uint32_t flags = 0); + ReturnValue internalMoveCreature(std::shared_ptr creature, Direction direction, uint32_t flags = 0); + ReturnValue internalMoveCreature(const std::shared_ptr &creature, const std::shared_ptr &toTile, uint32_t flags = 0); - ReturnValue checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder, Cylinder* toCylinder, Item* item, Position toPos); - ReturnValue internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, int32_t index, Item* item, uint32_t count, Item** movedItem, uint32_t flags = 0, Creature* actor = nullptr, Item* tradeItem = nullptr, bool checkTile = true); + ReturnValue checkMoveItemToCylinder(std::shared_ptr player, std::shared_ptr fromCylinder, std::shared_ptr toCylinder, std::shared_ptr item, Position toPos); + ReturnValue internalMoveItem(std::shared_ptr fromCylinder, std::shared_ptr toCylinder, int32_t index, std::shared_ptr item, uint32_t count, std::shared_ptr* movedItem, uint32_t flags = 0, std::shared_ptr actor = nullptr, std::shared_ptr tradeItem = nullptr, bool checkTile = true); - ReturnValue internalAddItem(Cylinder* toCylinder, Item* item, int32_t index = INDEX_WHEREEVER, uint32_t flags = 0, bool test = false); - ReturnValue internalAddItem(Cylinder* toCylinder, Item* item, int32_t index, uint32_t flags, bool test, uint32_t &remainderCount); - ReturnValue internalRemoveItem(Item* item, int32_t count = -1, bool test = false, uint32_t flags = 0, bool force = false); + ReturnValue internalAddItem(std::shared_ptr toCylinder, std::shared_ptr item, int32_t index = INDEX_WHEREEVER, uint32_t flags = 0, bool test = false); + ReturnValue internalAddItem(std::shared_ptr toCylinder, std::shared_ptr item, int32_t index, uint32_t flags, bool test, uint32_t &remainderCount); + ReturnValue internalRemoveItem(std::shared_ptr item, int32_t count = -1, bool test = false, uint32_t flags = 0, bool force = false); - ReturnValue internalPlayerAddItem(Player* player, Item* item, bool dropOnMap = true, Slots_t slot = CONST_SLOT_WHEREEVER); + ReturnValue internalPlayerAddItem(std::shared_ptr player, std::shared_ptr item, bool dropOnMap = true, Slots_t slot = CONST_SLOT_WHEREEVER); - Item* findItemOfType(const Cylinder* cylinder, uint16_t itemId, bool depthSearch = true, int32_t subType = -1) const; + std::shared_ptr findItemOfType(std::shared_ptr cylinder, uint16_t itemId, bool depthSearch = true, int32_t subType = -1) const; void createLuaItemsOnMap(); - bool removeMoney(Cylinder* cylinder, uint64_t money, uint32_t flags = 0, bool useBank = false); + bool removeMoney(std::shared_ptr cylinder, uint64_t money, uint32_t flags = 0, bool useBank = false); - void addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags = 0); + void addMoney(std::shared_ptr cylinder, uint64_t money, uint32_t flags = 0); - Item* transformItem(Item* item, uint16_t newId, int32_t newCount = -1); + std::shared_ptr transformItem(std::shared_ptr item, uint16_t newId, int32_t newCount = -1); - ReturnValue internalTeleport(Thing* thing, const Position &newPos, bool pushMove = true, uint32_t flags = 0); + ReturnValue internalTeleport(std::shared_ptr thing, const Position &newPos, bool pushMove = true, uint32_t flags = 0); - bool internalCreatureTurn(Creature* creature, Direction dir); + bool internalCreatureTurn(std::shared_ptr creature, Direction dir); - bool internalCreatureSay(Creature* creature, SpeakClasses type, const std::string &text, bool ghostMode, SpectatorHashSet* spectatorsPtr = nullptr, const Position* pos = nullptr); + bool internalCreatureSay(std::shared_ptr creature, SpeakClasses type, const std::string &text, bool ghostMode, SpectatorHashSet* spectatorsPtr = nullptr, const Position* pos = nullptr); - ObjectCategory_t getObjectCategory(const Item* item); + ObjectCategory_t getObjectCategory(const std::shared_ptr item); uint64_t getItemMarketPrice(const std::map &itemMap, bool buyPrice) const; void loadPlayersRecord(); void checkPlayersRecord(); - void sendSingleSoundEffect(const Position &pos, SoundEffect_t soundId, Creature* actor = nullptr); - void sendDoubleSoundEffect(const Position &pos, SoundEffect_t mainSoundEffect, SoundEffect_t secondarySoundEffect, Creature* actor = nullptr); + void sendSingleSoundEffect(const Position &pos, SoundEffect_t soundId, std::shared_ptr actor = nullptr); + void sendDoubleSoundEffect(const Position &pos, SoundEffect_t mainSoundEffect, SoundEffect_t secondarySoundEffect, std::shared_ptr actor = nullptr); void sendGuildMotd(uint32_t playerId); void kickPlayer(uint32_t playerId, bool displayEffect); @@ -241,30 +241,30 @@ class Game { void playerRequestInventoryImbuements(uint32_t playerId, bool isTrackerOpen); - bool addItemStoreInbox(const Player* player, uint32_t itemId); + bool addItemStoreInbox(std::shared_ptr player, uint32_t itemId); void playerRewardChestCollect(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, uint32_t maxMoveItems = 0); void playerReportRuleViolationReport(uint32_t playerId, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation); - void playerCyclopediaCharacterInfo(Player* player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page); + void playerCyclopediaCharacterInfo(std::shared_ptr player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page); - void playerHighscores(Player* player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &worldName, uint16_t page, uint8_t entriesPerPage); + void playerHighscores(std::shared_ptr player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &worldName, uint16_t page, uint8_t entriesPerPage); void updatePlayerSaleItems(uint32_t playerId); - bool internalStartTrade(Player* player, Player* partner, Item* tradeItem); - void internalCloseTrade(Player* player); - bool playerBroadcastMessage(Player* player, const std::string &text) const; + bool internalStartTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr tradeItem); + void internalCloseTrade(std::shared_ptr player); + bool playerBroadcastMessage(std::shared_ptr player, const std::string &text) const; void broadcastMessage(const std::string &text, MessageClasses type) const; // Implementation of player invoked events void playerTeleport(uint32_t playerId, const Position &pos); void playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count); void playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, const Position &movingCreatureOrigPos, const Position &toPos); - void playerMoveCreature(Player* playerId, Creature* movingCreature, const Position &movingCreatureOrigPos, Tile* toTile); + void playerMoveCreature(std::shared_ptr playerId, std::shared_ptr movingCreature, const Position &movingCreatureOrigPos, std::shared_ptr toTile); void playerMoveItemByPlayerID(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count); - void playerMoveItem(Player* player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, Item* item, Cylinder* toCylinder); + void playerMoveItem(std::shared_ptr player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder); void playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier = false, uint8_t tier = 0); void playerMove(uint32_t playerId, Direction direction); void forcePlayerMove(uint32_t playerId, Direction direction); @@ -311,8 +311,8 @@ class Game { void playerSetFightModes(uint32_t playerId, FightMode_t fightMode, bool chaseMode, bool secureMode); void playerLookAt(uint32_t playerId, uint16_t itemId, const Position &pos, uint8_t stackPos); void playerLookInBattleList(uint32_t playerId, uint32_t creatureId); - void playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, Item* defaultItem = nullptr, bool lootAllCorpses = false, bool autoLoot = false); - void playerLootAllCorpses(Player* player, const Position &pos, bool lootAllCorpses); + void playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, std::shared_ptr defaultItem = nullptr, bool lootAllCorpses = false, bool autoLoot = false); + void playerLootAllCorpses(std::shared_ptr player, const Position &pos, bool lootAllCorpses); void playerSetLootContainer(uint32_t playerId, ObjectCategory_t category, const Position &pos, uint16_t itemId, uint8_t stackPos); void playerClearLootContainer(uint32_t playerId, ObjectCategory_t category); ; @@ -325,7 +325,7 @@ class Game { void playerRequestDepotSearchItem(uint32_t playerId, uint16_t itemId, uint8_t tier); void playerRequestDepotSearchRetrieve(uint32_t playerId, uint16_t itemId, uint8_t tier, uint8_t type); void playerRequestOpenContainerFromDepotSearch(uint32_t playerId, const Position &pos); - void playerMoveThingFromDepotSearch(Player* player, uint16_t itemId, uint8_t tier, uint8_t count, const Position &fromPos, const Position &toPos, bool allItems = false); + void playerMoveThingFromDepotSearch(std::shared_ptr player, uint16_t itemId, uint8_t tier, uint8_t count, const Position &fromPos, const Position &toPos, bool allItems = false); void playerRequestAddVip(uint32_t playerId, const std::string &name); void playerRequestRemoveVip(uint32_t playerId, uint32_t guid); @@ -359,13 +359,13 @@ class Game { void playerOpenWheel(uint32_t playerId, uint32_t ownerId); void playerSaveWheel(uint32_t playerId, NetworkMessage &msg); - void updatePlayerHelpers(Player* player); + void updatePlayerHelpers(std::shared_ptr player); void cleanup(); void shutdown(); void dieSafely(std::string errorMsg); - void ReleaseCreature(Creature* creature); - void ReleaseItem(Item* item); + void ReleaseCreature(std::shared_ptr creature); + void ReleaseItem(std::shared_ptr item); void addBestiaryList(uint16_t raceid, std::string name); const std::map &getBestiaryList() const { return BestiaryList; @@ -383,18 +383,18 @@ class Game { bool canThrowObjectTo(const Position &fromPos, const Position &toPos, bool checkLineOfSight = true, int32_t rangex = MAP_MAX_CLIENT_VIEW_PORT_X, int32_t rangey = MAP_MAX_CLIENT_VIEW_PORT_Y); bool isSightClear(const Position &fromPos, const Position &toPos, bool sameFloor); - void changeSpeed(Creature* creature, int32_t varSpeedDelta); - void setCreatureSpeed(Creature* creature, int32_t speed); // setCreatureSpeed - void changePlayerSpeed(Player &player, int32_t varSpeedDelta); - void internalCreatureChangeOutfit(Creature* creature, const Outfit_t &oufit); - void internalCreatureChangeVisible(Creature* creature, bool visible); - void changeLight(const Creature* creature); - void updateCreatureIcon(const Creature* creature); - void reloadCreature(const Creature* creature); - void updateCreatureSkull(const Creature* player); - void updatePlayerShield(Player* player); - void updateCreatureType(Creature* creature); - void updateCreatureWalkthrough(const Creature* creature); + void changeSpeed(std::shared_ptr creature, int32_t varSpeedDelta); + void setCreatureSpeed(std::shared_ptr creature, int32_t speed); // setCreatureSpeed + void changePlayerSpeed(const std::shared_ptr &player, int32_t varSpeedDelta); + void internalCreatureChangeOutfit(std::shared_ptr creature, const Outfit_t &oufit); + void internalCreatureChangeVisible(std::shared_ptr creature, bool visible); + void changeLight(const std::shared_ptr creature); + void updateCreatureIcon(const std::shared_ptr creature); + void reloadCreature(const std::shared_ptr creature); + void updateCreatureSkull(std::shared_ptr player); + void updatePlayerShield(std::shared_ptr player); + void updateCreatureType(std::shared_ptr creature); + void updateCreatureWalkthrough(const std::shared_ptr creature); GameState_t getGameState() const; void setGameState(GameState_t newState); @@ -407,37 +407,37 @@ class Game { void checkCreatures(size_t index); void checkLight(); - bool combatBlockHit(CombatDamage &damage, Creature* attacker, Creature* target, bool checkDefense, bool checkArmor, bool field); + bool combatBlockHit(CombatDamage &damage, std::shared_ptr attacker, std::shared_ptr target, bool checkDefense, bool checkArmor, bool field); - void combatGetTypeInfo(CombatType_t combatType, Creature* target, TextColor_t &color, uint16_t &effect); + void combatGetTypeInfo(CombatType_t combatType, std::shared_ptr target, TextColor_t &color, uint16_t &effect); // Hazard combat helpers - void handleHazardSystemAttack(CombatDamage &damage, Player* player, const Monster* monster, bool isPlayerAttacker); - void notifySpectators(const SpectatorHashSet &spectators, const Position &targetPos, Player* attackerPlayer, Monster* targetMonster); + void handleHazardSystemAttack(CombatDamage &damage, std::shared_ptr player, const std::shared_ptr monster, bool isPlayerAttacker); + void notifySpectators(const SpectatorHashSet &spectators, const Position &targetPos, std::shared_ptr attackerPlayer, std::shared_ptr targetMonster); // Wheel of destiny combat helpers - void applyWheelOfDestinyHealing(CombatDamage &damage, Player* attackerPlayer, const Creature* target); - void applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, const Player* attackerPlayer, const Creature* target) const; - int32_t applyHealthChange(CombatDamage &damage, const Creature* target) const; + void applyWheelOfDestinyHealing(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr target); + void applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr target) const; + int32_t applyHealthChange(CombatDamage &damage, std::shared_ptr target) const; - bool combatChangeHealth(Creature* attacker, Creature* target, CombatDamage &damage, bool isEvent = false); - void applyCharmRune(const Monster* targetMonster, Player* attackerPlayer, Creature* target, const int32_t &realDamage) const; + bool combatChangeHealth(std::shared_ptr attacker, std::shared_ptr target, CombatDamage &damage, bool isEvent = false); + void applyCharmRune(std::shared_ptr targetMonster, std::shared_ptr attackerPlayer, std::shared_ptr target, const int32_t &realDamage) const; void applyManaLeech( - Player* attackerPlayer, const Monster* targetMonster, - Creature* target, const CombatDamage &damage, const int32_t &realDamage + std::shared_ptr attackerPlayer, std::shared_ptr targetMonster, + std::shared_ptr target, const CombatDamage &damage, const int32_t &realDamage ) const; void applyLifeLeech( - Player* attackerPlayer, const Monster* targetMonster, - Creature* target, const CombatDamage &damage, const int32_t &realDamage + std::shared_ptr attackerPlayer, std::shared_ptr targetMonster, + std::shared_ptr target, const CombatDamage &damage, const int32_t &realDamage ) const; int32_t calculateLeechAmount(const int32_t &realDamage, const uint16_t &skillAmount, int targetsAffected) const; - bool combatChangeMana(Creature* attacker, Creature* target, CombatDamage &damage); + bool combatChangeMana(std::shared_ptr attacker, std::shared_ptr target, CombatDamage &damage); // Animation help functions - void addCreatureHealth(const Creature* target); - static void addCreatureHealth(const SpectatorHashSet &spectators, const Creature* target); - void addPlayerMana(const Player* target); - void addPlayerVocation(const Player* target); + void addCreatureHealth(const std::shared_ptr target); + static void addCreatureHealth(const SpectatorHashSet &spectators, const std::shared_ptr target); + void addPlayerMana(const std::shared_ptr target); + void addPlayerVocation(const std::shared_ptr target); void addMagicEffect(const Position &pos, uint16_t effect); static void addMagicEffect(const SpectatorHashSet &spectators, const Position &pos, uint16_t effect); void removeMagicEffect(const Position &pos, uint16_t effect); @@ -463,18 +463,18 @@ class Game { motdNum++; } - void sendOfflineTrainingDialog(Player* player); + void sendOfflineTrainingDialog(std::shared_ptr player); const std::map> &getItemsPrice() const { return itemsPriceMap; } - const phmap::flat_hash_map &getPlayers() const { + const phmap::flat_hash_map> &getPlayers() const { return players; } - const std::map &getMonsters() const { + const std::map> &getMonsters() const { return monsters; } - const std::map &getNpcs() const { + const std::map> &getNpcs() const { return npcs; } @@ -482,14 +482,14 @@ class Game { return itemsClassifications; } - void addPlayer(Player* player); - void removePlayer(Player* player); + void addPlayer(std::shared_ptr player); + void removePlayer(std::shared_ptr player); - void addNpc(Npc* npc); - void removeNpc(Npc* npc); + void addNpc(std::shared_ptr npc); + void removeNpc(std::shared_ptr npc); - void addMonster(Monster* npc); - void removeMonster(Monster* npc); + void addMonster(std::shared_ptr npc); + void removeMonster(std::shared_ptr npc); std::shared_ptr getGuild(uint32_t id, bool allowOffline = false) const; std::shared_ptr getGuildByName(const std::string &name, bool allowOffline = false) const; @@ -497,16 +497,16 @@ class Game { void removeGuild(uint32_t guildId); void decreaseBrowseFieldRef(const Position &pos); - phmap::flat_hash_map browseFields; + phmap::flat_hash_map, std::shared_ptr> browseFields; - void internalRemoveItems(const std::vector itemVector, uint32_t amount, bool stackable); + void internalRemoveItems(const std::vector> itemVector, uint32_t amount, bool stackable); - BedItem* getBedBySleeper(uint32_t guid) const; - void setBedSleeper(BedItem* bed, uint32_t guid); + std::shared_ptr getBedBySleeper(uint32_t guid) const; + void setBedSleeper(std::shared_ptr bed, uint32_t guid); void removeBedSleeper(uint32_t guid); - Item* getUniqueItem(uint16_t uniqueId); - bool addUniqueItem(uint16_t uniqueId, Item* item); + std::shared_ptr getUniqueItem(uint16_t uniqueId); + bool addUniqueItem(uint16_t uniqueId, std::shared_ptr item); void removeUniqueItem(uint16_t uniqueId); bool hasEffect(uint16_t effectId); @@ -518,21 +518,21 @@ class Game { Raids raids; Canary::protobuf::appearances::Appearances appearances; - phmap::flat_hash_set getTilesToClean() const { + phmap::flat_hash_set> getTilesToClean() const { return tilesToClean; } - void addTileToClean(Tile* tile) { + void addTileToClean(std::shared_ptr tile) { tilesToClean.emplace(tile); } - void removeTileToClean(Tile* tile) { + void removeTileToClean(std::shared_ptr tile) { tilesToClean.erase(tile); } void clearTilesToClean() { tilesToClean.clear(); } - void playerInspectItem(Player* player, const Position &pos); - void playerInspectItem(Player* player, uint16_t itemId, uint8_t itemCount, bool cyclopedia); + void playerInspectItem(std::shared_ptr player, const Position &pos); + void playerInspectItem(std::shared_ptr player, uint16_t itemId, uint8_t itemCount, bool cyclopedia); void addCharmRune(const std::shared_ptr charm) { CharmList.push_back(charm); @@ -579,9 +579,9 @@ class Game { uint32_t makeFiendishMonster(uint32_t forgeableMonsterId = 0, bool createForgeableMonsters = false); uint32_t makeInfluencedMonster(); - bool addInfluencedMonster(Monster* monster); - void sendUpdateCreature(const Creature* creature); - Item* wrapItem(Item* item, House* house); + bool addInfluencedMonster(std::shared_ptr monster); + void sendUpdateCreature(std::shared_ptr creature); + std::shared_ptr wrapItem(std::shared_ptr item, House* house); /** * @brief Adds a player to the unique login map. @@ -590,7 +590,7 @@ class Game { * * @param player A pointer to the Player object to add. */ - void addPlayerUniqueLogin(Player* player); + void addPlayerUniqueLogin(std::shared_ptr player); /** * @brief Gets a player from the unique login map using their name. @@ -601,7 +601,7 @@ class Game { * @param playerName The name of the player to search for. * @return A pointer to the Player object if found, null otherwise. */ - Player* getPlayerUniqueLogin(const std::string &playerName) const; + std::shared_ptr getPlayerUniqueLogin(const std::string &playerName) const; /** * @brief Removes a player from the unique login map using their name. @@ -619,7 +619,7 @@ class Game { * * @param player A pointer to the Player object to remove. */ - void removePlayerUniqueLogin(Player* player); + void removePlayerUniqueLogin(std::shared_ptr player); void playerCheckActivity(const std::string &playerName, int interval); /** @@ -632,10 +632,10 @@ class Game { * @param item Pointer to the item to be checked. * @return True if stash items can be retrieved, false otherwise. */ - bool tryRetrieveStashItems(Player* player, Item* item); + bool tryRetrieveStashItems(std::shared_ptr player, std::shared_ptr item); - ReturnValue beforeCreatureZoneChange(Creature* creature, const phmap::parallel_flat_hash_set> &fromZones, const phmap::parallel_flat_hash_set> &toZones, bool force = false) const; - void afterCreatureZoneChange(Creature* creature, const phmap::parallel_flat_hash_set> &fromZones, const phmap::parallel_flat_hash_set> &toZones) const; + ReturnValue beforeCreatureZoneChange(std::shared_ptr creature, const phmap::parallel_flat_hash_set> &fromZones, const phmap::parallel_flat_hash_set> &toZones, bool force = false) const; + void afterCreatureZoneChange(std::shared_ptr creature, const phmap::parallel_flat_hash_set> &fromZones, const phmap::parallel_flat_hash_set> &toZones) const; std::unique_ptr &getIOWheel(); const std::unique_ptr &getIOWheel() const; @@ -645,11 +645,11 @@ class Game { std::set fiendishMonsters; std::set influencedMonsters; void checkImbuements(); - bool playerSaySpell(Player* player, SpeakClasses type, const std::string &text); - void playerWhisper(Player* player, const std::string &text); - bool playerYell(Player* player, const std::string &text); - bool playerSpeakTo(Player* player, SpeakClasses type, const std::string &receiver, const std::string &text); - void playerSpeakToNpc(Player* player, const std::string &text); + bool playerSaySpell(std::shared_ptr player, SpeakClasses type, const std::string &text); + void playerWhisper(std::shared_ptr player, const std::string &text); + bool playerYell(std::shared_ptr player, const std::string &text); + bool playerSpeakTo(std::shared_ptr player, SpeakClasses type, const std::string &receiver, const std::string &text); + void playerSpeakToNpc(std::shared_ptr player, const std::string &text); std::shared_ptr createPlayerTask(uint32_t delay, std::function f, std::string context) const; /** @@ -657,7 +657,7 @@ class Game { * \param player Player pointer * \param corpse Container pointer to be looted */ - void internalQuickLootCorpse(Player* player, Container* corpse); + void internalQuickLootCorpse(std::shared_ptr player, std::shared_ptr corpse); /** * @brief Finds the container for loot based on the given parameters. @@ -671,7 +671,7 @@ class Game { * * @return Pointer to the loot container or nullptr if not found. */ - Container* findLootContainer(Player* player, bool &fallbackConsumed, ObjectCategory_t category); + std::shared_ptr findLootContainer(std::shared_ptr player, bool &fallbackConsumed, ObjectCategory_t category); /** * @brief Finds the next available sub-container within a container. @@ -681,7 +681,7 @@ class Game { * @param lootContainer Reference to the loot container being used. * @return Pointer to the next available container or nullptr if not found. */ - Container* findNextAvailableContainer(ContainerIterator &containerIterator, Container*&lastSubContainer, Container*&lootContainer); + std::shared_ptr findNextAvailableContainer(ContainerIterator &containerIterator, std::shared_ptr &lastSubContainer, std::shared_ptr &lootContainer); /** * @brief Handles the fallback logic for loot containers. @@ -692,7 +692,7 @@ class Game { * @param fallbackConsumed Reference to a boolean flag indicating whether a fallback has been consumed. * @return True if fallback logic was handled, false otherwise. */ - bool handleFallbackLogic(const Player* player, Container*&lootContainer, ContainerIterator &containerIterator, const bool &fallbackConsumed); + bool handleFallbackLogic(std::shared_ptr player, std::shared_ptr &lootContainer, ContainerIterator &containerIterator, const bool &fallbackConsumed); /** * @brief Processes the movement or addition of an item to a loot container. @@ -703,7 +703,7 @@ class Game { * @param player Pointer to the player object. * @return Return value indicating success or error. */ - ReturnValue processMoveOrAddItemToLootContainer(Item* item, Container* lootContainer, uint32_t &remainderCount, Player* player); + ReturnValue processMoveOrAddItemToLootContainer(std::shared_ptr item, std::shared_ptr lootContainer, uint32_t &remainderCount, std::shared_ptr player); /** * @brief Processes loot items and places them into the appropriate containers. @@ -714,7 +714,7 @@ class Game { * @param fallbackConsumed Reference to a boolean flag indicating whether a fallback has been consumed. * @return Return value indicating success or error. */ - ReturnValue processLootItems(Player* player, Container* lootContainer, Item* item, bool &fallbackConsumed); + ReturnValue processLootItems(std::shared_ptr player, std::shared_ptr lootContainer, std::shared_ptr item, bool &fallbackConsumed); /** * @brief Internally collects loot items from a given item and places them into the loot container. @@ -724,7 +724,7 @@ class Game { * @param category Category of the item (default is OBJECTCATEGORY_DEFAULT). * @return Return value indicating success or error. */ - ReturnValue internalCollectLootItems(Player* player, Item* item, ObjectCategory_t category = OBJECTCATEGORY_DEFAULT); + ReturnValue internalCollectLootItems(std::shared_ptr player, std::shared_ptr item, ObjectCategory_t category = OBJECTCATEGORY_DEFAULT); /** * @brief Collects items from the reward chest. @@ -733,13 +733,13 @@ class Game { * @param maxMoveItems Maximum number of items to move (default is 0, which means no limit). * @return Return value indicating success or error. */ - ReturnValue collectRewardChestItems(Player* player, uint32_t maxMoveItems = 0); + ReturnValue collectRewardChestItems(std::shared_ptr player, uint32_t maxMoveItems = 0); - phmap::flat_hash_map m_uniqueLoginPlayerNames; - phmap::flat_hash_map players; - phmap::flat_hash_map mappedPlayerNames; + phmap::flat_hash_map> m_uniqueLoginPlayerNames; + phmap::flat_hash_map> players; + phmap::flat_hash_map> mappedPlayerNames; phmap::flat_hash_map> guilds; - phmap::flat_hash_map uniqueItems; + phmap::flat_hash_map> uniqueItems; std::map stages; /* Items stored from the lua scripts positions @@ -752,9 +752,9 @@ class Game { std::string boostedCreature = ""; std::vector> CharmList; - std::vector ToReleaseCreatures; - std::vector checkCreatureLists[EVENT_CREATURECOUNT]; - std::vector ToReleaseItems; + std::vector> ToReleaseCreatures; + std::vector> checkCreatureLists[EVENT_CREATURECOUNT]; + std::vector> ToReleaseItems; std::vector registeredMagicEffects; std::vector registeredDistanceEffects; @@ -765,18 +765,18 @@ class Game { WildcardTreeNode wildcardTree { false }; - std::map npcs; - std::map monsters; + std::map> npcs; + std::map> monsters; std::vector forgeableMonsters; std::map teamFinderMap; // [leaderGUID] = TeamFinder* // list of items that are in trading state, mapped to the player - std::map tradeItems; + std::map, uint32_t> tradeItems; - std::map bedSleepersMap; + std::map> bedSleepersMap; - phmap::flat_hash_set tilesToClean; + phmap::flat_hash_set> tilesToClean; ModalWindow offlineTrainingWindow { std::numeric_limits::max(), "Choose a Skill", "Please choose a skill:" }; @@ -813,47 +813,47 @@ class Game { std::vector itemsClassifications; - bool isTryingToStow(const Position &toPos, Cylinder* toCylinder) const; + bool isTryingToStow(const Position &toPos, std::shared_ptr toCylinder) const; void sendDamageMessageAndEffects( - const Creature* attacker, Creature* target, const CombatDamage &damage, const Position &targetPos, - Player* attackerPlayer, Player* targetPlayer, TextMessage &message, + std::shared_ptr attacker, std::shared_ptr target, const CombatDamage &damage, const Position &targetPos, + std::shared_ptr attackerPlayer, std::shared_ptr targetPlayer, TextMessage &message, const SpectatorHashSet &spectators, int32_t realDamage ); - void updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, const Player* player) const; + void updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, std::shared_ptr player) const; void sendEffects( - Creature* target, const CombatDamage &damage, const Position &targetPos, + std::shared_ptr target, const CombatDamage &damage, const Position &targetPos, TextMessage &message, const SpectatorHashSet &spectators ); void sendMessages( - const Creature* attacker, const Creature* target, const CombatDamage &damage, - const Position &targetPos, Player* attackerPlayer, Player* targetPlayer, + std::shared_ptr attacker, std::shared_ptr target, const CombatDamage &damage, + const Position &targetPos, std::shared_ptr attackerPlayer, std::shared_ptr targetPlayer, TextMessage &message, const SpectatorHashSet &spectators, int32_t realDamage ) const; bool shouldSendMessage(const TextMessage &message) const; void buildMessageAsAttacker( - const Creature* target, const CombatDamage &damage, TextMessage &message, + std::shared_ptr target, const CombatDamage &damage, TextMessage &message, std::stringstream &ss, const std::string &damageString ) const; void buildMessageAsTarget( - const Creature* attacker, const CombatDamage &damage, const Player* attackerPlayer, - const Player* targetPlayer, TextMessage &message, std::stringstream &ss, + std::shared_ptr attacker, const CombatDamage &damage, std::shared_ptr attackerPlayer, + std::shared_ptr targetPlayer, TextMessage &message, std::stringstream &ss, const std::string &damageString ) const; void buildMessageAsSpectator( - const Creature* attacker, const Creature* target, const CombatDamage &damage, - const Player* targetPlayer, TextMessage &message, std::stringstream &ss, + std::shared_ptr attacker, std::shared_ptr target, const CombatDamage &damage, + std::shared_ptr targetPlayer, TextMessage &message, std::stringstream &ss, const std::string &damageString, std::string &spectatorMessage ) const; - void unwrapItem(Item* item, uint16_t unWrapId, House* house, Player* player); + void unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* house, std::shared_ptr player); // Variable members (m_) std::unique_ptr m_IOWheel; diff --git a/src/game/movement/teleport.cpp b/src/game/movement/teleport.cpp index 31bd42d11cf..5fdb984e168 100644 --- a/src/game/movement/teleport.cpp +++ b/src/game/movement/teleport.cpp @@ -31,28 +31,28 @@ void Teleport::serializeAttr(PropWriteStream &propWriteStream) const { propWriteStream.write(destPos.z); } -ReturnValue Teleport::queryAdd(int32_t, const Thing &, uint32_t, uint32_t, Creature*) const { +ReturnValue Teleport::queryAdd(int32_t, const std::shared_ptr &, uint32_t, uint32_t, std::shared_ptr) { return RETURNVALUE_NOTPOSSIBLE; } -ReturnValue Teleport::queryMaxCount(int32_t, const Thing &, uint32_t, uint32_t &, uint32_t) const { +ReturnValue Teleport::queryMaxCount(int32_t, const std::shared_ptr &, uint32_t, uint32_t &, uint32_t) { return RETURNVALUE_NOTPOSSIBLE; } -ReturnValue Teleport::queryRemove(const Thing &, uint32_t, uint32_t, Creature* /*= nullptr */) const { +ReturnValue Teleport::queryRemove(const std::shared_ptr &, uint32_t, uint32_t, std::shared_ptr /*= nullptr */) { return RETURNVALUE_NOERROR; } -Cylinder* Teleport::queryDestination(int32_t &, const Thing &, Item**, uint32_t &) { - return this; +std::shared_ptr Teleport::queryDestination(int32_t &, const std::shared_ptr &, std::shared_ptr*, uint32_t &) { + return getTeleport(); } -bool Teleport::checkInfinityLoop(Tile* destTile) { +bool Teleport::checkInfinityLoop(std::shared_ptr destTile) { if (!destTile) { return false; } - if (Teleport* teleport = destTile->getTeleportItem()) { + if (std::shared_ptr teleport = destTile->getTeleportItem()) { const Position &nextDestPos = teleport->getDestPos(); if (getPosition() == nextDestPos) { return true; @@ -62,16 +62,16 @@ bool Teleport::checkInfinityLoop(Tile* destTile) { return false; } -void Teleport::addThing(Thing* thing) { +void Teleport::addThing(std::shared_ptr thing) { return addThing(0, thing); } -void Teleport::addThing(int32_t, Thing* thing) { +void Teleport::addThing(int32_t, std::shared_ptr thing) { if (!thing) { return; } - Tile* destTile = g_game().map.getTile(destPos); + std::shared_ptr destTile = g_game().map.getTile(destPos); if (!destTile) { return; } @@ -87,15 +87,15 @@ void Teleport::addThing(int32_t, Thing* thing) { const MagicEffectClasses effect = Item::items[id].magicEffect; - if (Creature* creature = thing->getCreature()) { + if (std::shared_ptr creature = thing->getCreature()) { Position origPos = creature->getPosition(); g_game().internalCreatureTurn(creature, origPos.x > destPos.x ? DIRECTION_WEST : DIRECTION_EAST); - g_game().map.moveCreature(*creature, *destTile); + g_game().map.moveCreature(creature, destTile); if (effect != CONST_ME_NONE) { g_game().addMagicEffect(origPos, effect); g_game().addMagicEffect(destTile->getPosition(), effect); } - } else if (Item* item = thing->getItem()) { + } else if (std::shared_ptr item = thing->getItem()) { if (effect != CONST_ME_NONE) { g_game().addMagicEffect(destTile->getPosition(), effect); g_game().addMagicEffect(item->getPosition(), effect); @@ -104,22 +104,22 @@ void Teleport::addThing(int32_t, Thing* thing) { } } -void Teleport::updateThing(Thing*, uint16_t, uint32_t) { +void Teleport::updateThing(std::shared_ptr, uint16_t, uint32_t) { // } -void Teleport::replaceThing(uint32_t, Thing*) { +void Teleport::replaceThing(uint32_t, std::shared_ptr) { // } -void Teleport::removeThing(Thing*, uint32_t) { +void Teleport::removeThing(std::shared_ptr, uint32_t) { // } -void Teleport::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t) { +void Teleport::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { getParent()->postAddNotification(thing, oldParent, index, LINK_PARENT); } -void Teleport::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t) { +void Teleport::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { getParent()->postRemoveNotification(thing, newParent, index, LINK_PARENT); } diff --git a/src/game/movement/teleport.hpp b/src/game/movement/teleport.hpp index 1000b9daf3a..ed2d752ad08 100644 --- a/src/game/movement/teleport.hpp +++ b/src/game/movement/teleport.hpp @@ -16,11 +16,8 @@ class Teleport final : public Item, public Cylinder { explicit Teleport(uint16_t type) : Item(type) {}; - Teleport* getTeleport() override { - return this; - } - const Teleport* getTeleport() const override { - return this; + std::shared_ptr getTeleport() override { + return static_self_cast(); } // serialization @@ -34,24 +31,24 @@ class Teleport final : public Item, public Cylinder { destPos = std::move(pos); } - bool checkInfinityLoop(Tile* destTile); + bool checkInfinityLoop(std::shared_ptr destTile); // cylinder implementations - ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; - ReturnValue queryMaxCount(int32_t index, const Thing &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) const override; - ReturnValue queryRemove(const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; - Cylinder* queryDestination(int32_t &index, const Thing &thing, Item** destItem, uint32_t &flags) override; + ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; + ReturnValue queryMaxCount(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) override; + ReturnValue queryRemove(const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; + std::shared_ptr queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &flags) override; - void addThing(Thing* thing) override; - void addThing(int32_t index, Thing* thing) override; + void addThing(std::shared_ptr thing) override; + void addThing(int32_t index, std::shared_ptr thing) override; - void updateThing(Thing* thing, uint16_t itemId, uint32_t count) override; - void replaceThing(uint32_t index, Thing* thing) override; + void updateThing(std::shared_ptr thing, uint16_t itemId, uint32_t count) override; + void replaceThing(uint32_t index, std::shared_ptr thing) override; - void removeThing(Thing* thing, uint32_t count) override; + void removeThing(std::shared_ptr thing, uint32_t count) override; - void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; - void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; private: Position destPos; diff --git a/src/game/scheduling/dispatcher.cpp b/src/game/scheduling/dispatcher.cpp index 9f37393e36a..9423c8799c3 100644 --- a/src/game/scheduling/dispatcher.cpp +++ b/src/game/scheduling/dispatcher.cpp @@ -21,12 +21,12 @@ Dispatcher &Dispatcher::getInstance() { return inject(); } -void Dispatcher::addTask(std::function f, std::string context) { - addTask(std::make_shared(std::move(f), std::move(context))); +void Dispatcher::addTask(std::function f, const std::string &context) { + addTask(std::make_shared(std::move(f), context)); } -void Dispatcher::addTask(std::function f, std::string context, uint32_t expiresAfterMs) { - addTask(std::make_shared(std::move(f), std::move(context)), expiresAfterMs); +void Dispatcher::addTask(std::function f, const std::string &context, uint32_t expiresAfterMs) { + addTask(std::make_shared(std::move(f), context), expiresAfterMs); } void Dispatcher::addTask(const std::shared_ptr task) { diff --git a/src/game/scheduling/dispatcher.hpp b/src/game/scheduling/dispatcher.hpp index 2beda8b3401..7590773bd79 100644 --- a/src/game/scheduling/dispatcher.hpp +++ b/src/game/scheduling/dispatcher.hpp @@ -30,8 +30,8 @@ class Dispatcher { static Dispatcher &getInstance(); - void addTask(std::function f, std::string context); - void addTask(std::function f, std::string context, uint32_t expiresAfterMs); + void addTask(std::function f, const std::string &context); + void addTask(std::function f, const std::string &context, uint32_t expiresAfterMs); void addTask(const std::shared_ptr task); void addTask(const std::shared_ptr task, uint32_t expiresAfterMs); diff --git a/src/game/zones/zone.cpp b/src/game/zones/zone.cpp index 56fc3a1afb2..2df32e215ca 100644 --- a/src/game/zones/zone.cpp +++ b/src/game/zones/zone.cpp @@ -35,7 +35,7 @@ std::shared_ptr Zone::addZone(const std::string &name) { void Zone::addArea(Area area) { for (const Position &pos : area) { positions.insert(pos); - Tile* tile = g_game().map.getTile(pos); + std::shared_ptr tile = g_game().map.getTile(pos); if (tile) { for (auto item : *tile->getItemList()) { itemAdded(item); @@ -50,7 +50,7 @@ void Zone::addArea(Area area) { void Zone::subtractArea(Area area) { for (const Position &pos : area) { positions.erase(pos); - Tile* tile = g_game().map.getTile(pos); + std::shared_ptr tile = g_game().map.getTile(pos); if (tile) { for (auto item : *tile->getItemList()) { itemRemoved(item); @@ -66,7 +66,7 @@ bool Zone::isPositionInZone(const Position &pos) const { return positions.contains(pos); } -Position Zone::getRemoveDestination(Creature* creature /* = nullptr */) const { +Position Zone::getRemoveDestination(std::shared_ptr creature /* = nullptr */) const { if (!creature || !creature->getPlayer()) { return Position(); } @@ -87,11 +87,11 @@ const phmap::parallel_flat_hash_set &Zone::getPositions() const { return positions; } -const phmap::parallel_flat_hash_set &Zone::getTiles() const { - static phmap::parallel_flat_hash_set tiles; +const phmap::parallel_flat_hash_set> &Zone::getTiles() const { + static phmap::parallel_flat_hash_set> tiles; tiles.clear(); for (const auto &position : positions) { - Tile* tile = g_game().map.getTile(position); + std::shared_ptr tile = g_game().map.getTile(position); if (tile) { tiles.insert(tile); } @@ -99,8 +99,8 @@ const phmap::parallel_flat_hash_set &Zone::getTiles() const { return tiles; } -const phmap::parallel_flat_hash_set &Zone::getCreatures() const { - static phmap::parallel_flat_hash_set creatures; +const phmap::parallel_flat_hash_set> &Zone::getCreatures() const { + static phmap::parallel_flat_hash_set> creatures; creatures.clear(); for (const auto creatureId : creaturesCache) { auto creature = g_game().getCreatureByID(creatureId); @@ -111,8 +111,8 @@ const phmap::parallel_flat_hash_set &Zone::getCreatures() const { return creatures; } -const phmap::parallel_flat_hash_set &Zone::getPlayers() const { - static phmap::parallel_flat_hash_set players; +const phmap::parallel_flat_hash_set> &Zone::getPlayers() const { + static phmap::parallel_flat_hash_set> players; players.clear(); for (const auto playerId : playersCache) { auto player = g_game().getPlayerByID(playerId); @@ -123,8 +123,8 @@ const phmap::parallel_flat_hash_set &Zone::getPlayers() const { return players; } -const phmap::parallel_flat_hash_set &Zone::getMonsters() const { - static phmap::parallel_flat_hash_set monsters; +const phmap::parallel_flat_hash_set> &Zone::getMonsters() const { + static phmap::parallel_flat_hash_set> monsters; monsters.clear(); for (const auto monsterId : monstersCache) { auto monster = g_game().getMonsterByID(monsterId); @@ -135,8 +135,8 @@ const phmap::parallel_flat_hash_set &Zone::getMonsters() const { return monsters; } -const phmap::parallel_flat_hash_set &Zone::getNpcs() const { - static phmap::parallel_flat_hash_set npcs; +const phmap::parallel_flat_hash_set> &Zone::getNpcs() const { + static phmap::parallel_flat_hash_set> npcs; npcs.clear(); for (const auto npcId : npcsCache) { auto npc = g_game().getNpcByID(npcId); @@ -147,7 +147,7 @@ const phmap::parallel_flat_hash_set &Zone::getNpcs() const { return npcs; } -const phmap::parallel_flat_hash_set &Zone::getItems() const { +const phmap::parallel_flat_hash_set> &Zone::getItems() const { return itemsCache; } @@ -194,7 +194,7 @@ const phmap::parallel_flat_hash_set> &Zone::getZones() { return zonesSet; } -void Zone::creatureAdded(Creature* creature) { +void Zone::creatureAdded(std::shared_ptr creature) { if (!creature) { return; } @@ -227,7 +227,7 @@ void Zone::creatureAdded(Creature* creature) { } } -void Zone::creatureRemoved(Creature* creature) { +void Zone::creatureRemoved(std::shared_ptr creature) { if (!creature) { return; } @@ -243,7 +243,7 @@ void Zone::creatureRemoved(Creature* creature) { } } -void Zone::thingAdded(Thing* thing) { +void Zone::thingAdded(std::shared_ptr thing) { if (!thing) { return; } @@ -255,14 +255,14 @@ void Zone::thingAdded(Thing* thing) { } } -void Zone::itemAdded(Item* item) { +void Zone::itemAdded(std::shared_ptr item) { if (!item) { return; } itemsCache.insert(item); } -void Zone::itemRemoved(Item* item) { +void Zone::itemRemoved(std::shared_ptr item) { if (!item) { return; } diff --git a/src/game/zones/zone.hpp b/src/game/zones/zone.hpp index 27626d469ec..46c8edb08a0 100644 --- a/src/game/zones/zone.hpp +++ b/src/game/zones/zone.hpp @@ -93,24 +93,24 @@ class Zone { void addArea(Area area); void subtractArea(Area area); bool isPositionInZone(const Position &position) const; - Position getRemoveDestination(Creature* creature = nullptr) const; + Position getRemoveDestination(std::shared_ptr creature = nullptr) const; void setRemoveDestination(const Position &position) { removeDestination = position; } const phmap::parallel_flat_hash_set &getPositions() const; - const phmap::parallel_flat_hash_set &getTiles() const; - const phmap::parallel_flat_hash_set &getCreatures() const; - const phmap::parallel_flat_hash_set &getPlayers() const; - const phmap::parallel_flat_hash_set &getMonsters() const; - const phmap::parallel_flat_hash_set &getNpcs() const; - const phmap::parallel_flat_hash_set &getItems() const; - - void creatureAdded(Creature* creature); - void creatureRemoved(Creature* creature); - void thingAdded(Thing* thing); - void itemAdded(Item* item); - void itemRemoved(Item* item); + const phmap::parallel_flat_hash_set> &getTiles() const; + const phmap::parallel_flat_hash_set> &getCreatures() const; + const phmap::parallel_flat_hash_set> &getPlayers() const; + const phmap::parallel_flat_hash_set> &getMonsters() const; + const phmap::parallel_flat_hash_set> &getNpcs() const; + const phmap::parallel_flat_hash_set> &getItems() const; + + void creatureAdded(std::shared_ptr creature); + void creatureRemoved(std::shared_ptr creature); + void thingAdded(std::shared_ptr thing); + void itemAdded(std::shared_ptr item); + void itemRemoved(std::shared_ptr item); void removePlayers() const; void removeMonsters() const; @@ -127,7 +127,7 @@ class Zone { std::string name; phmap::parallel_flat_hash_set positions; - phmap::parallel_flat_hash_set itemsCache; + phmap::parallel_flat_hash_set> itemsCache; phmap::parallel_flat_hash_set creaturesCache; phmap::parallel_flat_hash_set monstersCache; phmap::parallel_flat_hash_set npcsCache; diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index f8e6e785563..b89c7257c63 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -13,7 +13,7 @@ #include "io/functions/iologindata_load_player.hpp" #include "game/game.hpp" -void IOLoginDataLoad::loadItems(ItemsMap &itemsMap, DBResult_ptr result, Player &player) { +void IOLoginDataLoad::loadItems(ItemsMap &itemsMap, DBResult_ptr result, const std::shared_ptr &player) { try { do { uint32_t sid = result->getNumber("sid"); @@ -26,18 +26,18 @@ void IOLoginDataLoad::loadItems(ItemsMap &itemsMap, DBResult_ptr result, Player propStream.init(attr, attrSize); try { - Item* item = Item::CreateItem(type, count); + std::shared_ptr item = Item::CreateItem(type, count); if (item) { if (!item->unserializeAttr(propStream)) { - g_logger().warn("[{}] - Failed to deserialize item attributes {}, from player {}, from account id {}", __FUNCTION__, item->getID(), player.getName(), player.getAccountId()); - savePlayer(&player); + g_logger().warn("[{}] - Failed to deserialize item attributes {}, from player {}, from account id {}", __FUNCTION__, item->getID(), player->getName(), player->getAccountId()); + savePlayer(player); g_logger().info("[{}] - Deleting wrong item: {}", __FUNCTION__, item->getID()); - delete item; + continue; } itemsMap[sid] = std::make_pair(item, pid); } else { - g_logger().warn("[{}] - Failed to create item of type {} for player {}, from account id {}", __FUNCTION__, type, player.getName(), player.getAccountId()); + g_logger().warn("[{}] - Failed to create item of type {} for player {}, from account id {}", __FUNCTION__, type, player->getName(), player->getAccountId()); } } catch (const std::exception &e) { g_logger().warn("[{}] - Exception during the creation or deserialization of the item: {}", __FUNCTION__, e.what()); @@ -49,7 +49,7 @@ void IOLoginDataLoad::loadItems(ItemsMap &itemsMap, DBResult_ptr result, Player } } -bool IOLoginDataLoad::preLoadPlayer(Player* player, const std::string &name) { +bool IOLoginDataLoad::preLoadPlayer(std::shared_ptr player, const std::string &name) { Database &db = Database::getInstance(); std::ostringstream query; @@ -103,7 +103,7 @@ bool IOLoginDataLoad::preLoadPlayer(Player* player, const std::string &name) { return true; } -bool IOLoginDataLoad::loadPlayerFirst(Player* player, DBResult_ptr result) { +bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return false; @@ -183,7 +183,7 @@ bool IOLoginDataLoad::loadPlayerFirst(Player* player, DBResult_ptr result) { return true; } -void IOLoginDataLoad::loadPlayerExperience(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerExperience(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -206,7 +206,7 @@ void IOLoginDataLoad::loadPlayerExperience(Player* player, DBResult_ptr result) } } -void IOLoginDataLoad::loadPlayerBlessings(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerBlessings(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -219,7 +219,7 @@ void IOLoginDataLoad::loadPlayerBlessings(Player* player, DBResult_ptr result) { } } -void IOLoginDataLoad::loadPlayerConditions(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerConditions(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -239,7 +239,7 @@ void IOLoginDataLoad::loadPlayerConditions(Player* player, DBResult_ptr result) } } -void IOLoginDataLoad::loadPlayerDefaultOutfit(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerDefaultOutfit(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -270,7 +270,7 @@ void IOLoginDataLoad::loadPlayerDefaultOutfit(Player* player, DBResult_ptr resul player->currentOutfit = player->defaultOutfit; } -void IOLoginDataLoad::loadPlayerSkullSystem(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerSkullSystem(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -292,7 +292,7 @@ void IOLoginDataLoad::loadPlayerSkullSystem(Player* player, DBResult_ptr result) } } -void IOLoginDataLoad::loadPlayerSkill(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerSkill(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -314,7 +314,7 @@ void IOLoginDataLoad::loadPlayerSkill(Player* player, DBResult_ptr result) { } } -void IOLoginDataLoad::loadPlayerKills(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerKills(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -333,7 +333,7 @@ void IOLoginDataLoad::loadPlayerKills(Player* player, DBResult_ptr result) { } } -void IOLoginDataLoad::loadPlayerGuild(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerGuild(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -383,7 +383,7 @@ void IOLoginDataLoad::loadPlayerGuild(Player* player, DBResult_ptr result) { } } -void IOLoginDataLoad::loadPlayerStashItems(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerStashItems(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -399,7 +399,7 @@ void IOLoginDataLoad::loadPlayerStashItems(Player* player, DBResult_ptr result) } } -void IOLoginDataLoad::loadPlayerBestiaryCharms(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerBestiaryCharms(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -452,7 +452,7 @@ void IOLoginDataLoad::loadPlayerBestiaryCharms(Player* player, DBResult_ptr resu } } -void IOLoginDataLoad::loadPlayerInstantSpellList(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerInstantSpellList(std::shared_ptr player, DBResult_ptr result) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -468,7 +468,7 @@ void IOLoginDataLoad::loadPlayerInstantSpellList(Player* player, DBResult_ptr re } } -void IOLoginDataLoad::loadPlayerInventoryItems(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerInventoryItems(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -480,15 +480,15 @@ void IOLoginDataLoad::loadPlayerInventoryItems(Player* player, DBResult_ptr resu query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_items` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC"; ItemsMap inventoryItems; - std::vector> openContainersList; + std::vector>> openContainersList; try { if ((result = db.storeQuery(query.str()))) { - loadItems(inventoryItems, result, *player); + loadItems(inventoryItems, result, player); for (ItemsMap::const_reverse_iterator it = inventoryItems.rbegin(), end = inventoryItems.rend(); it != end; ++it) { - const std::pair &pair = it->second; - Item* item = pair.first; + const std::pair, int32_t> &pair = it->second; + std::shared_ptr item = pair.first; if (!item) { continue; } @@ -504,14 +504,14 @@ void IOLoginDataLoad::loadPlayerInventoryItems(Player* player, DBResult_ptr resu continue; } - Container* container = it2->second.first->getContainer(); + std::shared_ptr container = it2->second.first->getContainer(); if (container) { container->internalAddThing(item); item->startDecaying(); } } - Container* itemContainer = item->getContainer(); + std::shared_ptr itemContainer = item->getContainer(); if (itemContainer) { if (!oldProtocol) { auto cid = item->getAttribute(ItemAttribute_t::OPENCONTAINER); @@ -532,7 +532,7 @@ void IOLoginDataLoad::loadPlayerInventoryItems(Player* player, DBResult_ptr resu } if (!oldProtocol) { - std::ranges::sort(openContainersList.begin(), openContainersList.end(), [](const std::pair &left, const std::pair &right) { + std::ranges::sort(openContainersList.begin(), openContainersList.end(), [](const std::pair> &left, const std::pair> &right) { return left.first < right.first; }); @@ -546,7 +546,7 @@ void IOLoginDataLoad::loadPlayerInventoryItems(Player* player, DBResult_ptr resu } } -void IOLoginDataLoad::loadPlayerStoreInbox(Player* player) { +void IOLoginDataLoad::loadPlayerStoreInbox(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -557,7 +557,7 @@ void IOLoginDataLoad::loadPlayerStoreInbox(Player* player) { } } -void IOLoginDataLoad::loadRewardItems(Player* player) { +void IOLoginDataLoad::loadRewardItems(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -569,13 +569,13 @@ void IOLoginDataLoad::loadRewardItems(Player* player) { query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_rewards` WHERE `player_id` = " << player->getGUID() << " ORDER BY `pid`, `sid` ASC"; if (auto result = Database::getInstance().storeQuery(query.str())) { - loadItems(rewardItems, result, *player); + loadItems(rewardItems, result, player); bindRewardBag(player, rewardItems); insertItemsIntoRewardBag(rewardItems); } } -void IOLoginDataLoad::loadPlayerDepotItems(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerDepotItems(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -587,14 +587,14 @@ void IOLoginDataLoad::loadPlayerDepotItems(Player* player, DBResult_ptr result) query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_depotitems` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC"; if ((result = db.storeQuery(query.str()))) { - loadItems(depotItems, result, *player); + loadItems(depotItems, result, player); for (ItemsMap::const_reverse_iterator it = depotItems.rbegin(), end = depotItems.rend(); it != end; ++it) { - const std::pair &pair = it->second; - Item* item = pair.first; + const std::pair, int32_t> &pair = it->second; + std::shared_ptr item = pair.first; int32_t pid = pair.second; if (pid >= 0 && pid < 100) { - DepotChest* depotChest = player->getDepotChest(pid, true); + std::shared_ptr depotChest = player->getDepotChest(pid, true); if (depotChest) { depotChest->internalAddThing(item); item->startDecaying(); @@ -605,7 +605,7 @@ void IOLoginDataLoad::loadPlayerDepotItems(Player* player, DBResult_ptr result) continue; } - Container* container = it2->second.first->getContainer(); + std::shared_ptr container = it2->second.first->getContainer(); if (container) { container->internalAddThing(item); item->startDecaying(); @@ -615,7 +615,7 @@ void IOLoginDataLoad::loadPlayerDepotItems(Player* player, DBResult_ptr result) } } -void IOLoginDataLoad::loadPlayerInboxItems(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerInboxItems(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -627,11 +627,11 @@ void IOLoginDataLoad::loadPlayerInboxItems(Player* player, DBResult_ptr result) if ((result = db.storeQuery(query.str()))) { ItemsMap inboxItems; - loadItems(inboxItems, result, *player); + loadItems(inboxItems, result, player); for (ItemsMap::const_reverse_iterator it = inboxItems.rbegin(), end = inboxItems.rend(); it != end; ++it) { - const std::pair &pair = it->second; - Item* item = pair.first; + const std::pair, int32_t> &pair = it->second; + std::shared_ptr item = pair.first; int32_t pid = pair.second; if (pid >= 0 && pid < 100) { player->getInbox()->internalAddThing(item); @@ -642,7 +642,7 @@ void IOLoginDataLoad::loadPlayerInboxItems(Player* player, DBResult_ptr result) continue; } - Container* container = it2->second.first->getContainer(); + std::shared_ptr container = it2->second.first->getContainer(); if (container) { container->internalAddThing(item); item->startDecaying(); @@ -652,7 +652,7 @@ void IOLoginDataLoad::loadPlayerInboxItems(Player* player, DBResult_ptr result) } } -void IOLoginDataLoad::loadPlayerStorageMap(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerStorageMap(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -668,7 +668,7 @@ void IOLoginDataLoad::loadPlayerStorageMap(Player* player, DBResult_ptr result) } } -void IOLoginDataLoad::loadPlayerVip(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerVip(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -684,7 +684,7 @@ void IOLoginDataLoad::loadPlayerVip(Player* player, DBResult_ptr result) { } } -void IOLoginDataLoad::loadPlayerPreyClass(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerPreyClass(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -731,7 +731,7 @@ void IOLoginDataLoad::loadPlayerPreyClass(Player* player, DBResult_ptr result) { } } -void IOLoginDataLoad::loadPlayerTaskHuntingClass(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerTaskHuntingClass(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -781,7 +781,7 @@ void IOLoginDataLoad::loadPlayerTaskHuntingClass(Player* player, DBResult_ptr re } } -void IOLoginDataLoad::loadPlayerForgeHistory(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerForgeHistory(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -802,7 +802,7 @@ void IOLoginDataLoad::loadPlayerForgeHistory(Player* player, DBResult_ptr result } } -void IOLoginDataLoad::loadPlayerBosstiary(Player* player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerBosstiary(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -834,7 +834,7 @@ void IOLoginDataLoad::loadPlayerBosstiary(Player* player, DBResult_ptr result) { } } -void IOLoginDataLoad::bindRewardBag(Player* player, ItemsMap &rewardItemsMap) { +void IOLoginDataLoad::bindRewardBag(std::shared_ptr player, ItemsMap &rewardItemsMap) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -845,7 +845,7 @@ void IOLoginDataLoad::bindRewardBag(Player* player, ItemsMap &rewardItemsMap) { if (pid == 0) { auto reward = player->getReward(item->getAttribute(ItemAttribute_t::DATE), true); if (reward) { - itemPair = std::pair(reward->getItem(), player->getRewardChest()->getID()); + itemPair = std::pair, int32_t>(reward->getItem(), player->getRewardChest()->getID()); } } else { break; @@ -855,8 +855,8 @@ void IOLoginDataLoad::bindRewardBag(Player* player, ItemsMap &rewardItemsMap) { void IOLoginDataLoad::insertItemsIntoRewardBag(const ItemsMap &rewardItemsMap) { for (const auto &it : std::views::reverse(rewardItemsMap)) { - const std::pair &pair = it.second; - Item* item = pair.first; + const std::pair, int32_t> &pair = it.second; + std::shared_ptr item = pair.first; int32_t pid = pair.second; if (pid == 0) { break; @@ -867,14 +867,14 @@ void IOLoginDataLoad::insertItemsIntoRewardBag(const ItemsMap &rewardItemsMap) { continue; } - Container* container = it2->second.first->getContainer(); + std::shared_ptr container = it2->second.first->getContainer(); if (container) { container->internalAddThing(item); } } } -void IOLoginDataLoad::loadPlayerInitializeSystem(Player* player) { +void IOLoginDataLoad::loadPlayerInitializeSystem(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -888,7 +888,7 @@ void IOLoginDataLoad::loadPlayerInitializeSystem(Player* player) { player->initializeTaskHunting(); } -void IOLoginDataLoad::loadPlayerUpdateSystem(Player* player) { +void IOLoginDataLoad::loadPlayerUpdateSystem(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; diff --git a/src/io/functions/iologindata_load_player.hpp b/src/io/functions/iologindata_load_player.hpp index b1c9fe7c18d..e8b0b4094de 100644 --- a/src/io/functions/iologindata_load_player.hpp +++ b/src/io/functions/iologindata_load_player.hpp @@ -13,38 +13,38 @@ class IOLoginDataLoad : public IOLoginData { public: - static bool loadPlayerFirst(Player* player, DBResult_ptr result); - static bool preLoadPlayer(Player* player, const std::string &name); - static void loadPlayerExperience(Player* player, DBResult_ptr result); - static void loadPlayerBlessings(Player* player, DBResult_ptr result); - static void loadPlayerConditions(Player* player, DBResult_ptr result); - static void loadPlayerDefaultOutfit(Player* player, DBResult_ptr result); - static void loadPlayerSkullSystem(Player* player, DBResult_ptr result); - static void loadPlayerSkill(Player* player, DBResult_ptr result); - static void loadPlayerKills(Player* player, DBResult_ptr result); - static void loadPlayerGuild(Player* player, DBResult_ptr result); - static void loadPlayerStashItems(Player* player, DBResult_ptr result); - static void loadPlayerBestiaryCharms(Player* player, DBResult_ptr result); - static void loadPlayerInstantSpellList(Player* player, DBResult_ptr result); - static void loadPlayerInventoryItems(Player* player, DBResult_ptr result); - static void loadPlayerStoreInbox(Player* player); - static void loadPlayerDepotItems(Player* player, DBResult_ptr result); - static void loadRewardItems(Player* player); - static void loadPlayerInboxItems(Player* player, DBResult_ptr result); - static void loadPlayerStorageMap(Player* player, DBResult_ptr result); - static void loadPlayerVip(Player* player, DBResult_ptr result); - static void loadPlayerPreyClass(Player* player, DBResult_ptr result); - static void loadPlayerTaskHuntingClass(Player* player, DBResult_ptr result); - static void loadPlayerForgeHistory(Player* player, DBResult_ptr result); - static void loadPlayerBosstiary(Player* player, DBResult_ptr result); - static void loadPlayerInitializeSystem(Player* player); - static void loadPlayerUpdateSystem(Player* player); + static bool loadPlayerFirst(std::shared_ptr player, DBResult_ptr result); + static bool preLoadPlayer(std::shared_ptr player, const std::string &name); + static void loadPlayerExperience(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerBlessings(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerConditions(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerDefaultOutfit(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerSkullSystem(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerSkill(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerKills(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerGuild(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerStashItems(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerBestiaryCharms(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerInstantSpellList(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerInventoryItems(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerStoreInbox(std::shared_ptr player); + static void loadPlayerDepotItems(std::shared_ptr player, DBResult_ptr result); + static void loadRewardItems(std::shared_ptr player); + static void loadPlayerInboxItems(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerStorageMap(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerVip(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerPreyClass(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerTaskHuntingClass(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerForgeHistory(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerBosstiary(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerInitializeSystem(std::shared_ptr player); + static void loadPlayerUpdateSystem(std::shared_ptr player); private: - using ItemsMap = std::map>; + using ItemsMap = std::map, uint32_t>>; - static void bindRewardBag(Player* player, ItemsMap &rewardItemsMap); + static void bindRewardBag(std::shared_ptr player, ItemsMap &rewardItemsMap); static void insertItemsIntoRewardBag(const ItemsMap &rewardItemsMap); - static void loadItems(ItemsMap &itemsMap, DBResult_ptr result, Player &player); + static void loadItems(ItemsMap &itemsMap, DBResult_ptr result, const std::shared_ptr &player); }; diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index 130fa9e8850..877c2483786 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -12,7 +12,7 @@ #include "io/functions/iologindata_save_player.hpp" #include "game/game.hpp" -bool IOLoginDataSave::saveItems(const Player* player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &propWriteStream) { +bool IOLoginDataSave::saveItems(std::shared_ptr player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &propWriteStream) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -22,7 +22,7 @@ bool IOLoginDataSave::saveItems(const Player* player, const ItemBlockList &itemL std::ostringstream ss; // Initialize variables - using ContainerBlock = std::pair; + using ContainerBlock = std::pair, int32_t>; std::list queue; int32_t runningId = 100; @@ -30,11 +30,11 @@ bool IOLoginDataSave::saveItems(const Player* player, const ItemBlockList &itemL const auto &openContainers = player->getOpenContainers(); for (const auto &it : itemList) { int32_t pid = it.first; - Item* item = it.second; + std::shared_ptr item = it.second; ++runningId; // Update container attributes if necessary - if (Container* container = item->getContainer()) { + if (std::shared_ptr container = item->getContainer()) { if (!container) { continue; // Check for null container } @@ -82,7 +82,7 @@ bool IOLoginDataSave::saveItems(const Player* player, const ItemBlockList &itemL // Loop through containers in queue while (!queue.empty()) { const ContainerBlock &cb = queue.front(); - Container* container = cb.first; + std::shared_ptr container = cb.first; int32_t parentId = cb.second; queue.pop_front(); @@ -91,7 +91,7 @@ bool IOLoginDataSave::saveItems(const Player* player, const ItemBlockList &itemL } // Loop through items in container - for (Item* item : container->getItemList()) { + for (std::shared_ptr item : container->getItemList()) { if (!item) { continue; // Check for null item } @@ -99,7 +99,7 @@ bool IOLoginDataSave::saveItems(const Player* player, const ItemBlockList &itemL ++runningId; // Update sub-container attributes if necessary - Container* subContainer = item->getContainer(); + std::shared_ptr subContainer = item->getContainer(); if (subContainer) { queue.emplace_back(subContainer, runningId); if (subContainer->getAttribute(ItemAttribute_t::OPENCONTAINER) > 0) { @@ -148,7 +148,7 @@ bool IOLoginDataSave::saveItems(const Player* player, const ItemBlockList &itemL return true; } -bool IOLoginDataSave::savePlayerFirst(Player* player) { +bool IOLoginDataSave::savePlayerFirst(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -313,7 +313,7 @@ bool IOLoginDataSave::savePlayerFirst(Player* player) { return true; } -bool IOLoginDataSave::savePlayerStash(const Player* player) { +bool IOLoginDataSave::savePlayerStash(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -339,7 +339,7 @@ bool IOLoginDataSave::savePlayerStash(const Player* player) { return true; } -bool IOLoginDataSave::savePlayerSpells(const Player* player) { +bool IOLoginDataSave::savePlayerSpells(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -368,7 +368,7 @@ bool IOLoginDataSave::savePlayerSpells(const Player* player) { return true; } -bool IOLoginDataSave::savePlayerKills(const Player* player) { +bool IOLoginDataSave::savePlayerKills(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -397,7 +397,7 @@ bool IOLoginDataSave::savePlayerKills(const Player* player) { return true; } -bool IOLoginDataSave::savePlayerBestiarySystem(const Player* player) { +bool IOLoginDataSave::savePlayerBestiarySystem(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -447,7 +447,7 @@ bool IOLoginDataSave::savePlayerBestiarySystem(const Player* player) { return true; } -bool IOLoginDataSave::savePlayerItem(const Player* player) { +bool IOLoginDataSave::savePlayerItem(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -466,7 +466,7 @@ bool IOLoginDataSave::savePlayerItem(const Player* player) { ItemBlockList itemList; for (int32_t slotId = CONST_SLOT_FIRST; slotId <= CONST_SLOT_LAST; ++slotId) { - Item* item = player->inventory[slotId]; + std::shared_ptr item = player->inventory[slotId]; if (item) { itemList.emplace_back(slotId, item); } @@ -479,7 +479,7 @@ bool IOLoginDataSave::savePlayerItem(const Player* player) { return true; } -bool IOLoginDataSave::savePlayerDepotItems(const Player* player) { +bool IOLoginDataSave::savePlayerDepotItems(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -501,7 +501,7 @@ bool IOLoginDataSave::savePlayerDepotItems(const Player* player) { DBInsert depotQuery("INSERT INTO `player_depotitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES "); for (const auto &[pid, depotChest] : player->depotChests) { - for (Item* item : depotChest->getItemList()) { + for (std::shared_ptr item : depotChest->getItemList()) { depotList.emplace_back(pid, item); } } @@ -514,7 +514,7 @@ bool IOLoginDataSave::savePlayerDepotItems(const Player* player) { return true; } -bool IOLoginDataSave::saveRewardItems(Player* player) { +bool IOLoginDataSave::saveRewardItems(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -548,7 +548,7 @@ bool IOLoginDataSave::saveRewardItems(Player* player) { return true; } -bool IOLoginDataSave::savePlayerInbox(const Player* player) { +bool IOLoginDataSave::savePlayerInbox(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -566,7 +566,7 @@ bool IOLoginDataSave::savePlayerInbox(const Player* player) { query.str(""); DBInsert inboxQuery("INSERT INTO `player_inboxitems` (`player_id`, `pid`, `sid`, `itemtype`, `count`, `attributes`) VALUES "); - for (Item* item : player->getInbox()->getItemList()) { + for (std::shared_ptr item : player->getInbox()->getItemList()) { inboxList.emplace_back(0, item); } @@ -576,7 +576,7 @@ bool IOLoginDataSave::savePlayerInbox(const Player* player) { return true; } -bool IOLoginDataSave::savePlayerPreyClass(Player* player) { +bool IOLoginDataSave::savePlayerPreyClass(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -631,7 +631,7 @@ bool IOLoginDataSave::savePlayerPreyClass(Player* player) { return true; } -bool IOLoginDataSave::savePlayerTaskHuntingClass(Player* player) { +bool IOLoginDataSave::savePlayerTaskHuntingClass(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -684,7 +684,7 @@ bool IOLoginDataSave::savePlayerTaskHuntingClass(Player* player) { return true; } -bool IOLoginDataSave::savePlayerForgeHistory(Player* player) { +bool IOLoginDataSave::savePlayerForgeHistory(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -718,7 +718,7 @@ bool IOLoginDataSave::savePlayerForgeHistory(Player* player) { return true; } -bool IOLoginDataSave::savePlayerBosstiary(const Player* player) { +bool IOLoginDataSave::savePlayerBosstiary(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -762,7 +762,7 @@ bool IOLoginDataSave::savePlayerBosstiary(const Player* player) { return true; } -bool IOLoginDataSave::savePlayerStorage(Player* player) { +bool IOLoginDataSave::savePlayerStorage(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; diff --git a/src/io/functions/iologindata_save_player.hpp b/src/io/functions/iologindata_save_player.hpp index 8b35dd7f592..1c3cf89cb9c 100644 --- a/src/io/functions/iologindata_save_player.hpp +++ b/src/io/functions/iologindata_save_player.hpp @@ -13,26 +13,26 @@ class IOLoginDataSave : public IOLoginData { public: - static bool savePlayerFirst(Player* player); - static bool savePlayerStash(const Player* player); - static bool savePlayerSpells(const Player* player); - static bool savePlayerKills(const Player* player); - static bool savePlayerBestiarySystem(const Player* player); - static bool savePlayerItem(const Player* player); - static bool savePlayerDepotItems(const Player* player); - static bool saveRewardItems(Player* player); - static bool savePlayerInbox(const Player* player); - static bool savePlayerPreyClass(Player* player); - static bool savePlayerTaskHuntingClass(Player* player); - static bool savePlayerForgeHistory(Player* player); - static bool savePlayerBosstiary(const Player* player); - static bool savePlayerStorage(Player* palyer); + static bool savePlayerFirst(std::shared_ptr player); + static bool savePlayerStash(std::shared_ptr player); + static bool savePlayerSpells(std::shared_ptr player); + static bool savePlayerKills(std::shared_ptr player); + static bool savePlayerBestiarySystem(std::shared_ptr player); + static bool savePlayerItem(std::shared_ptr player); + static bool savePlayerDepotItems(std::shared_ptr player); + static bool saveRewardItems(std::shared_ptr player); + static bool savePlayerInbox(std::shared_ptr player); + static bool savePlayerPreyClass(std::shared_ptr player); + static bool savePlayerTaskHuntingClass(std::shared_ptr player); + static bool savePlayerForgeHistory(std::shared_ptr player); + static bool savePlayerBosstiary(std::shared_ptr player); + static bool savePlayerStorage(std::shared_ptr palyer); protected: - using ItemBlockList = std::list>; - using ItemDepotList = std::list>; - using ItemRewardList = std::list>; - using ItemInboxList = std::list>; + using ItemBlockList = std::list>>; + using ItemDepotList = std::list>>; + using ItemRewardList = std::list>>; + using ItemInboxList = std::list>>; - static bool saveItems(const Player* player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &stream); + static bool saveItems(std::shared_ptr player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &stream); }; diff --git a/src/io/io_bosstiary.cpp b/src/io/io_bosstiary.cpp index afe6c647245..cda3336af9c 100644 --- a/src/io/io_bosstiary.cpp +++ b/src/io/io_bosstiary.cpp @@ -164,7 +164,7 @@ std::shared_ptr IOBosstiary::getMonsterTypeByBossRaceId(uint16_t ra return nullptr; } -void IOBosstiary::addBosstiaryKill(Player* player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) const { +void IOBosstiary::addBosstiaryKill(std::shared_ptr player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) const { if (!player || !mtype) { return; } @@ -231,7 +231,7 @@ uint32_t IOBosstiary::calculateBossPoints(uint16_t lootBonus) const { return static_cast((2.5 * lootBonus * lootBonus) - (477.5 * lootBonus) + 24000); } -phmap::parallel_flat_hash_set IOBosstiary::getBosstiaryFinished(const Player* player, uint8_t level /* = 1*/) const { +phmap::parallel_flat_hash_set IOBosstiary::getBosstiaryFinished(std::shared_ptr player, uint8_t level /* = 1*/) const { phmap::parallel_flat_hash_set unlockedMonsters; if (!player) { return unlockedMonsters; @@ -265,7 +265,7 @@ phmap::parallel_flat_hash_set IOBosstiary::getBosstiaryFinished(const return unlockedMonsters; } -uint8_t IOBosstiary::getBossCurrentLevel(const Player* player, uint16_t bossId) const { +uint8_t IOBosstiary::getBossCurrentLevel(std::shared_ptr player, uint16_t bossId) const { if (bossId == 0 || !player) { return 0; } @@ -300,7 +300,7 @@ uint32_t IOBosstiary::calculteRemoveBoss(uint8_t removeTimes) const { return 300000 * removeTimes - 500000; } -std::vector IOBosstiary::getBosstiaryCooldownRaceId(const Player* player) const { +std::vector IOBosstiary::getBosstiaryCooldownRaceId(std::shared_ptr player) const { std::vector bossesCooldownRaceId; if (!player) { return bossesCooldownRaceId; diff --git a/src/io/io_bosstiary.hpp b/src/io/io_bosstiary.hpp index 912ee1fab55..bbb1367e8b8 100644 --- a/src/io/io_bosstiary.hpp +++ b/src/io/io_bosstiary.hpp @@ -60,13 +60,13 @@ class IOBosstiary { uint16_t getBoostedBossId() const; std::shared_ptr getMonsterTypeByBossRaceId(uint16_t raceId) const; - void addBosstiaryKill(Player* player, const std::shared_ptr mtype, uint32_t amount = 1) const; + void addBosstiaryKill(std::shared_ptr player, const std::shared_ptr mtype, uint32_t amount = 1) const; uint16_t calculateLootBonus(uint32_t bossPoints) const; uint32_t calculateBossPoints(uint16_t lootBonus) const; - phmap::parallel_flat_hash_set getBosstiaryFinished(const Player* player, uint8_t level = 1) const; - uint8_t getBossCurrentLevel(const Player* player, uint16_t bossId) const; + phmap::parallel_flat_hash_set getBosstiaryFinished(std::shared_ptr player, uint8_t level = 1) const; + uint8_t getBossCurrentLevel(std::shared_ptr player, uint16_t bossId) const; uint32_t calculteRemoveBoss(uint8_t removeTimes) const; - std::vector getBosstiaryCooldownRaceId(const Player* player) const; + std::vector getBosstiaryCooldownRaceId(std::shared_ptr player) const; const std::vector &getBossRaceKillStages(BosstiaryRarity_t race) const; private: diff --git a/src/io/io_wheel.cpp b/src/io/io_wheel.cpp index 976284baede..fba20d54674 100644 --- a/src/io/io_wheel.cpp +++ b/src/io/io_wheel.cpp @@ -170,7 +170,7 @@ const std::vector &IOWheel::getFocusSpells() const { return InternalPlayerWheel::m_focusSpells; } -using VocationBonusFunction = std::function; +using VocationBonusFunction = std::function &, uint16_t, uint8_t, PlayerWheelMethodsBonusData &)>; using VocationBonusMap = std::map; const VocationBonusMap &IOWheel::getWheelMapFunctions() const { return m_vocationBonusMap; @@ -306,8 +306,8 @@ void IOWheel::initializeSorcererSpells() { m_wheelBonusData.spells.sorcerer[4].grade[2].decrease.secondaryGroupCooldown = 4; } -bool IOWheel::isMaxPointAddedToSlot(Player &player, uint16_t points, WheelSlots_t slotType) const { - return points == player.wheel()->getPointsBySlotType(slotType) && points == player.wheel()->getMaxPointsPerSlot(slotType); +bool IOWheel::isMaxPointAddedToSlot(const std::shared_ptr &player, uint16_t points, WheelSlots_t slotType) const { + return points == player->wheel()->getPointsBySlotType(slotType) && points == player->wheel()->getMaxPointsPerSlot(slotType); } bool IOWheel::isKnight(uint8_t vocationId) const { @@ -326,13 +326,13 @@ bool IOWheel::isDruid(uint8_t vocationId) const { return vocationId == Vocation_t::VOCATION_DRUID_CIP; } -void IOWheel::addSpell(Player &player, PlayerWheelMethodsBonusData &bonusData, WheelSlots_t slotType, uint16_t points, const std::string &spellName) const { +void IOWheel::addSpell(const std::shared_ptr &player, PlayerWheelMethodsBonusData &bonusData, WheelSlots_t slotType, uint16_t points, const std::string &spellName) const { if (isMaxPointAddedToSlot(player, points, slotType)) { bonusData.spells.push_back(spellName); } } -void IOWheel::increaseResistance(Player &player, PlayerWheelMethodsBonusData &bonusData, WheelSlots_t slotType, uint16_t points, CombatType_t combat, int16_t value) const { +void IOWheel::increaseResistance(const std::shared_ptr &player, PlayerWheelMethodsBonusData &bonusData, WheelSlots_t slotType, uint16_t points, CombatType_t combat, int16_t value) const { if (isMaxPointAddedToSlot(player, points, slotType)) { bonusData.resistance[combatTypeToIndex(combat)] += value; } @@ -384,7 +384,7 @@ void IOWheel::initializeWheelMapFunctions() { } // SLOT_GREEN_200 = 1 -void IOWheel::slotGreen200(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotGreen200(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { auto pointsInSlot = isMaxPointAddedToSlot(player, points, WheelSlots_t::SLOT_GREEN_200); if (isKnight(vocationCipId)) { bonusData.stats.health += 3 * points; @@ -410,13 +410,13 @@ void IOWheel::slotGreen200(Player &player, uint16_t points, uint8_t vocationCipI } // SLOT_GREEN_TOP_150 = 2 -void IOWheel::slotGreenTop150(Player &player, uint16_t points, uint8_t, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotGreenTop150(const std::shared_ptr &player, uint16_t points, uint8_t, PlayerWheelMethodsBonusData &bonusData) const { bonusData.mitigation += 0.03 * points; increaseResistance(player, bonusData, WheelSlots_t::SLOT_GREEN_TOP_150, points, COMBAT_ICEDAMAGE, 200); } // SLOT_GREEN_TOP_100 = 3 -void IOWheel::slotGreenTop100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotGreenTop100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.health += 3 * points; } else if (isPaladin(vocationCipId)) { @@ -430,7 +430,7 @@ void IOWheel::slotGreenTop100(Player &player, uint16_t points, uint8_t vocationC } // SLOT_RED_TOP_100 = 4 -void IOWheel::slotRedTop100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotRedTop100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { auto pointsInSlot = isMaxPointAddedToSlot(player, points, WheelSlots_t::SLOT_RED_TOP_100); if (isKnight(vocationCipId)) { bonusData.stats.mana += 1 * points; @@ -451,7 +451,7 @@ void IOWheel::slotRedTop100(Player &player, uint16_t points, uint8_t vocationCip } // SLOT_RED_TOP_150 = 5 -void IOWheel::slotRedTop150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotRedTop150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.health += 3 * points; } else if (isPaladin(vocationCipId)) { @@ -466,7 +466,7 @@ void IOWheel::slotRedTop150(Player &player, uint16_t points, uint8_t vocationCip } // SLOT_RED_200 = 6 -void IOWheel::slotRed200(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotRed200(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { addSpell(player, bonusData, WheelSlots_t::SLOT_RED_200, points, "Front Sweep"); bonusData.stats.health += 3 * points; @@ -489,7 +489,7 @@ void IOWheel::slotRed200(Player &player, uint16_t points, uint8_t vocationCipId, } // SLOT_GREEN_BOTTOM_150 = 7 -void IOWheel::slotGreenBottom150(Player &player, uint16_t points, uint8_t, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotGreenBottom150(const std::shared_ptr &player, uint16_t points, uint8_t, PlayerWheelMethodsBonusData &bonusData) const { bonusData.mitigation += 0.03 * points; // 0,03% if (isMaxPointAddedToSlot(player, points, WheelSlots_t::SLOT_GREEN_BOTTOM_150)) { bonusData.leech.manaLeech += 0.25; // 0,25% @@ -497,7 +497,7 @@ void IOWheel::slotGreenBottom150(Player &player, uint16_t points, uint8_t, Playe } // SLOT_GREEN_MIDDLE_100 = 8 -void IOWheel::slotGreenMiddle100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotGreenMiddle100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { addSpell(player, bonusData, WheelSlots_t::SLOT_GREEN_MIDDLE_100, points, "Groundshaker"); bonusData.stats.health += 3 * points; @@ -515,7 +515,7 @@ void IOWheel::slotGreenMiddle100(Player &player, uint16_t points, uint8_t vocati } // SLOT_GREEN_TOP_75 = 9 -void IOWheel::slotGreenTop75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotGreenTop75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.mana += 1 * points; } else if (isPaladin(vocationCipId)) { @@ -529,7 +529,7 @@ void IOWheel::slotGreenTop75(Player &player, uint16_t points, uint8_t vocationCi } // SLOT_RED_TOP_75 = 10 -void IOWheel::slotRedTop75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotRedTop75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.capacity += 5 * points; } else if (isPaladin(vocationCipId)) { @@ -542,7 +542,7 @@ void IOWheel::slotRedTop75(Player &player, uint16_t points, uint8_t vocationCipI } // SLOT_RED_MIDDLE_100 = 11 -void IOWheel::slotRedMiddle100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotRedMiddle100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { addSpell(player, bonusData, WheelSlots_t::SLOT_RED_MIDDLE_100, points, "Chivalrous Challenge"); bonusData.stats.mana += 1 * points; @@ -560,7 +560,7 @@ void IOWheel::slotRedMiddle100(Player &player, uint16_t points, uint8_t vocation } // SLOT_RED_BOTTOM_150 = 12 -void IOWheel::slotRedBottom150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotRedBottom150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.health += 3 * points; } else if (isPaladin(vocationCipId)) { @@ -574,7 +574,7 @@ void IOWheel::slotRedBottom150(Player &player, uint16_t points, uint8_t vocation } // SLOT_GREEN_BOTTOM_100 = 13 -void IOWheel::slotGreenBottom100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotGreenBottom100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { addSpell(player, bonusData, WheelSlots_t::SLOT_GREEN_BOTTOM_100, points, "Intense Wound Cleansing"); bonusData.stats.health += 3 * points; @@ -592,7 +592,7 @@ void IOWheel::slotGreenBottom100(Player &player, uint16_t points, uint8_t vocati } // SLOT_GREEN_BOTTOM_75 = 14 -void IOWheel::slotGreenBottom75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotGreenBottom75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { auto pointsInSlot = isMaxPointAddedToSlot(player, points, WheelSlots_t::SLOT_GREEN_BOTTOM_75); if (isKnight(vocationCipId)) { bonusData.stats.mana += 1 * points; @@ -613,7 +613,7 @@ void IOWheel::slotGreenBottom75(Player &player, uint16_t points, uint8_t vocatio } // SLOT_GREEN_50 = 15 -void IOWheel::slotGreen50(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotGreen50(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.capacity += 5 * points; } else if (isPaladin(vocationCipId)) { @@ -626,7 +626,7 @@ void IOWheel::slotGreen50(Player &player, uint16_t points, uint8_t vocationCipId } // SLOT_RED_50 = 16 -void IOWheel::slotRed50(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotRed50(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { bonusData.mitigation += 0.03 * points; // 0,03% if (isKnight(vocationCipId)) { addSpell(player, bonusData, WheelSlots_t::SLOT_RED_50, points, "Fierce Berserk"); @@ -640,7 +640,7 @@ void IOWheel::slotRed50(Player &player, uint16_t points, uint8_t vocationCipId, } // SLOT_RED_BOTTOM_75 = 17 -void IOWheel::slotRedBottom75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotRedBottom75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.capacity += 5 * points; } else if (isPaladin(vocationCipId)) { @@ -654,7 +654,7 @@ void IOWheel::slotRedBottom75(Player &player, uint16_t points, uint8_t vocationC } // SLOT_RED_BOTTOM_100 = 18 -void IOWheel::slotRedBottom100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotRedBottom100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.mana += 1 * points; } else if (isPaladin(vocationCipId)) { @@ -667,13 +667,13 @@ void IOWheel::slotRedBottom100(Player &player, uint16_t points, uint8_t vocation } // SLOT_BLUE_TOP_100 = 19 -void IOWheel::slotBlueTop100(Player &player, uint16_t points, uint8_t, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotBlueTop100(const std::shared_ptr &player, uint16_t points, uint8_t, PlayerWheelMethodsBonusData &bonusData) const { bonusData.mitigation += 0.03 * points; // 0,03% increaseResistance(player, bonusData, WheelSlots_t::SLOT_BLUE_TOP_100, points, COMBAT_ENERGYDAMAGE, 200); } // SLOT_BLUE_TOP_75 = 20 -void IOWheel::slotBlueTop75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotBlueTop75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.health += 3 * points; } else if (isPaladin(vocationCipId)) { @@ -687,7 +687,7 @@ void IOWheel::slotBlueTop75(Player &player, uint16_t points, uint8_t vocationCip } // SLOT_BLUE_50 = 21 -void IOWheel::slotBlue50(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotBlue50(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { addSpell(player, bonusData, WheelSlots_t::SLOT_BLUE_50, points, "Front Sweep"); bonusData.stats.mana += 1 * points; @@ -707,7 +707,7 @@ void IOWheel::slotBlue50(Player &player, uint16_t points, uint8_t vocationCipId, } // SLOT_PURPLE_50 = 22 -void IOWheel::slotPurple50(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotPurple50(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.health += 3 * points; } else if (isPaladin(vocationCipId)) { @@ -720,7 +720,7 @@ void IOWheel::slotPurple50(Player &player, uint16_t points, uint8_t vocationCipI } // SLOT_PURPLE_TOP_75 = 23 -void IOWheel::slotPurpleTop75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotPurpleTop75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { bonusData.mitigation += 0.03 * points; // 0,03% auto pointsInSlot = isMaxPointAddedToSlot(player, points, WheelSlots_t::SLOT_PURPLE_TOP_75); if (isKnight(vocationCipId)) { @@ -739,7 +739,7 @@ void IOWheel::slotPurpleTop75(Player &player, uint16_t points, uint8_t vocationC } // SLOT_PURPLE_TOP_100 = 24 -void IOWheel::slotPurpleTop100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotPurpleTop100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { addSpell(player, bonusData, WheelSlots_t::SLOT_PURPLE_TOP_100, points, "Groundshaker"); bonusData.stats.capacity += 5 * points; @@ -757,7 +757,7 @@ void IOWheel::slotPurpleTop100(Player &player, uint16_t points, uint8_t vocation } // SLOT_BLUE_TOP_150 = 25 -void IOWheel::slotBlueTop150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotBlueTop150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.capacity += 5 * points; } else if (isPaladin(vocationCipId)) { @@ -772,7 +772,7 @@ void IOWheel::slotBlueTop150(Player &player, uint16_t points, uint8_t vocationCi } // SLOT_BLUE_MIDDLE_100 = 26 -void IOWheel::slotBlueMiddle100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotBlueMiddle100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { bonusData.mitigation += 0.03 * points; // 0,03% if (isKnight(vocationCipId)) { addSpell(player, bonusData, WheelSlots_t::SLOT_BLUE_MIDDLE_100, points, "Chivalrous Challenge"); @@ -788,7 +788,7 @@ void IOWheel::slotBlueMiddle100(Player &player, uint16_t points, uint8_t vocatio } // SLOT_BLUE_BOTTOM_75 = 27 -void IOWheel::slotBlueBottom75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotBlueBottom75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.health += 3 * points; } else if (isPaladin(vocationCipId)) { @@ -801,14 +801,14 @@ void IOWheel::slotBlueBottom75(Player &player, uint16_t points, uint8_t vocation } // SLOT_PURPLE_BOTTOM_75 = 28 -void IOWheel::slotPurpleBottom75(Player &player, uint16_t points, uint8_t, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotPurpleBottom75(const std::shared_ptr &player, uint16_t points, uint8_t, PlayerWheelMethodsBonusData &bonusData) const { bonusData.mitigation += 0.03 * points; // 0,03% increaseResistance(player, bonusData, WheelSlots_t::SLOT_PURPLE_BOTTOM_75, points, COMBAT_HOLYDAMAGE, 100); increaseResistance(player, bonusData, WheelSlots_t::SLOT_PURPLE_BOTTOM_75, points, COMBAT_DEATHDAMAGE, 100); } // SLOT_PURPLE_MIDDLE_100 = 29 -void IOWheel::slotPurpleMiddle100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotPurpleMiddle100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { addSpell(player, bonusData, WheelSlots_t::SLOT_PURPLE_MIDDLE_100, points, "Intense Wound Cleansing"); bonusData.stats.capacity += 5 * points; @@ -826,7 +826,7 @@ void IOWheel::slotPurpleMiddle100(Player &player, uint16_t points, uint8_t vocat } // SLOT_PURPLE_TOP_150 = 30 -void IOWheel::slotPurpleTop150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotPurpleTop150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.mana += 1 * points; } else if (isPaladin(vocationCipId)) { @@ -840,7 +840,7 @@ void IOWheel::slotPurpleTop150(Player &player, uint16_t points, uint8_t vocation } // SLOT_BLUE_200 = 31 -void IOWheel::slotBlue200(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotBlue200(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { addSpell(player, bonusData, WheelSlots_t::SLOT_BLUE_200, points, "Fierce Berserk"); bonusData.stats.health += 3 * points; @@ -861,7 +861,7 @@ void IOWheel::slotBlue200(Player &player, uint16_t points, uint8_t vocationCipId } // SLOT_BLUE_BOTTOM_150 = 32 -void IOWheel::slotBlueBottom150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotBlueBottom150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.capacity += 5 * points; } else if (isPaladin(vocationCipId)) { @@ -875,7 +875,7 @@ void IOWheel::slotBlueBottom150(Player &player, uint16_t points, uint8_t vocatio } // SLOT_BLUE_BOTTOM_100 = 33 -void IOWheel::slotBlueBottom100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotBlueBottom100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { bonusData.mitigation += 0.03 * points; // 0,03% bool onSlot = isMaxPointAddedToSlot(player, points, WheelSlots_t::SLOT_BLUE_BOTTOM_100); if (isKnight(vocationCipId) && onSlot) { @@ -888,7 +888,7 @@ void IOWheel::slotBlueBottom100(Player &player, uint16_t points, uint8_t vocatio } // SLOT_PURPLE_BOTTOM_100 = 34 -void IOWheel::slotPurpleBottom100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotPurpleBottom100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.capacity += 5 * points; } else if (isPaladin(vocationCipId)) { @@ -902,7 +902,7 @@ void IOWheel::slotPurpleBottom100(Player &player, uint16_t points, uint8_t vocat } // SLOT_PURPLE_BOTTOM_150 = 35 -void IOWheel::slotPurpleBottom150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotPurpleBottom150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { if (isKnight(vocationCipId)) { bonusData.stats.mana += 1 * points; } else if (isPaladin(vocationCipId)) { @@ -915,7 +915,7 @@ void IOWheel::slotPurpleBottom150(Player &player, uint16_t points, uint8_t vocat } // SLOT_PURPLE_200 = 36 -void IOWheel::slotPurple200(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { +void IOWheel::slotPurple200(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const { bool isPointsAtSlot = isMaxPointAddedToSlot(player, points, WheelSlots_t::SLOT_PURPLE_200); if (isKnight(vocationCipId)) { bonusData.stats.health += 3 * points; diff --git a/src/io/io_wheel.hpp b/src/io/io_wheel.hpp index 08017e0714d..f1b95f20073 100644 --- a/src/io/io_wheel.hpp +++ b/src/io/io_wheel.hpp @@ -155,7 +155,7 @@ class IOWheel : public IOWheelBonusData { */ const std::vector &getFocusSpells() const; - using VocationBonusFunction = std::function; + using VocationBonusFunction = std::function &, uint16_t, uint8_t, PlayerWheelMethodsBonusData &)>; using VocationBonusMap = std::map; /** * @brief Retrieves the mapping of wheel slots to vocation bonus functions. @@ -258,7 +258,7 @@ class IOWheel : public IOWheelBonusData { * @param slotType The slot type to be checked. * @return true if the number of points is equal to the player's points in the specified slot type, false otherwise. */ - bool isMaxPointAddedToSlot(Player &player, uint16_t points, WheelSlots_t slotType) const; + bool isMaxPointAddedToSlot(const std::shared_ptr &player, uint16_t points, WheelSlots_t slotType) const; /** * @brief Checks if the vocation ID corresponds to a knight. @@ -296,7 +296,7 @@ class IOWheel : public IOWheelBonusData { * @param points The number of points required to add the spell. * @param spellName The name of the spell to add. */ - void addSpell(Player &player, PlayerWheelMethodsBonusData &bonusData, WheelSlots_t slotType, uint16_t points, const std::string &spellName) const; + void addSpell(const std::shared_ptr &player, PlayerWheelMethodsBonusData &bonusData, WheelSlots_t slotType, uint16_t points, const std::string &spellName) const; /** * @brief Increases the resistance value of the specified combat type for the player's bonus data if the number of points is equal to the player's points in the specified slot type. @@ -307,7 +307,7 @@ class IOWheel : public IOWheelBonusData { * @param combat The combat type to increase the resistance for. * @param value The value to increase the resistance by. */ - void increaseResistance(Player &player, PlayerWheelMethodsBonusData &bonusData, WheelSlots_t slotType, uint16_t points, CombatType_t combat, int16_t value) const; + void increaseResistance(const std::shared_ptr &player, PlayerWheelMethodsBonusData &bonusData, WheelSlots_t slotType, uint16_t points, CombatType_t combat, int16_t value) const; /** * @brief Initialize the wheel map functions. @@ -327,51 +327,51 @@ class IOWheel : public IOWheelBonusData { * @details It's important to note that although the functions have similar objectives, they are tailored to each specific vocation, allowing for proper customization for each one. Furthermore, these functions are designed to prevent code redundancy, promoting a modular structure that is easy to maintain. * @note Note: Due to the large number of similar functions in this module, we have chosen not to document each function individually to avoid excessive documentation work. However, the information provided in this general description should provide a sufficient overview of the purpose and operation of these functions. */ - void slotGreen200(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotGreenTop150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotGreenTop100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotGreen200(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotGreenTop150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotGreenTop100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotRedTop100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotRedTop150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotRed200(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotRedTop100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotRedTop150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotRed200(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotGreenBottom150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotGreenMiddle100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotGreenTop75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotGreenBottom150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotGreenMiddle100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotGreenTop75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotRedTop75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotRedMiddle100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotRedBottom150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotRedTop75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotRedMiddle100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotRedBottom150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotGreenBottom100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotGreenBottom75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotGreen50(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotGreenBottom100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotGreenBottom75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotGreen50(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotRed50(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotRedBottom75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotRedBottom100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotRed50(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotRedBottom75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotRedBottom100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotBlueTop100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotBlueTop75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotBlue50(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotBlueTop100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotBlueTop75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotBlue50(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotPurple50(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotPurpleTop75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotPurpleTop100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotPurple50(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotPurpleTop75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotPurpleTop100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotBlueTop150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotBlueMiddle100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotBlueBottom75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotBlueTop150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotBlueMiddle100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotBlueBottom75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotPurpleBottom75(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotPurpleMiddle100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotPurpleTop150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotPurpleBottom75(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotPurpleMiddle100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotPurpleTop150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotBlue200(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotBlueBottom150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotBlueBottom100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotBlue200(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotBlueBottom150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotBlueBottom100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotPurpleBottom100(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotPurpleBottom150(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; - void slotPurple200(Player &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotPurpleBottom100(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotPurpleBottom150(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; + void slotPurple200(const std::shared_ptr &player, uint16_t points, uint8_t vocationCipId, PlayerWheelMethodsBonusData &bonusData) const; }; diff --git a/src/io/iobestiary.cpp b/src/io/iobestiary.cpp index acfeb561ae6..7e5d1c9ad55 100644 --- a/src/io/iobestiary.cpp +++ b/src/io/iobestiary.cpp @@ -17,7 +17,7 @@ SoftSingleton IOBestiary::instanceTracker("IOBestiary"); -bool IOBestiary::parseCharmCombat(const std::shared_ptr charm, Player* player, Creature* target, int32_t realDamage, bool dueToPotion, bool checkArmor) { +bool IOBestiary::parseCharmCombat(const std::shared_ptr charm, std::shared_ptr player, std::shared_ptr target, int32_t realDamage, bool dueToPotion, bool checkArmor) { if (!charm || !player || !target) { return false; } @@ -146,7 +146,7 @@ uint8_t IOBestiary::getKillStatus(const std::shared_ptr mtype, uint return 4; } -void IOBestiary::resetCharmRuneCreature(Player* player, const std::shared_ptr charm) { +void IOBestiary::resetCharmRuneCreature(std::shared_ptr player, const std::shared_ptr charm) { if (!player || !charm) { return; } @@ -156,7 +156,7 @@ void IOBestiary::resetCharmRuneCreature(Player* player, const std::shared_ptrparseRacebyCharm(charm->id, true, 0); } -void IOBestiary::setCharmRuneCreature(Player* player, const std::shared_ptr charm, uint16_t raceid) { +void IOBestiary::setCharmRuneCreature(std::shared_ptr player, const std::shared_ptr charm, uint16_t raceid) { if (!player || !charm) { return; } @@ -166,7 +166,7 @@ void IOBestiary::setCharmRuneCreature(Player* player, const std::shared_ptrsetUsedRunesBit(Toggle); } -std::list IOBestiary::getCharmUsedRuneBitAll(Player* player) { +std::list IOBestiary::getCharmUsedRuneBitAll(std::shared_ptr player) { int32_t input = player->getUsedRunesBit(); ; int8_t i = 0; @@ -182,7 +182,7 @@ std::list IOBestiary::getCharmUsedRuneBitAll(Player* player) { return rtn; } -uint16_t IOBestiary::getBestiaryRaceUnlocked(Player* player, BestiaryType_t race) const { +uint16_t IOBestiary::getBestiaryRaceUnlocked(std::shared_ptr player, BestiaryType_t race) const { if (!player) { return 0; } @@ -199,7 +199,7 @@ uint16_t IOBestiary::getBestiaryRaceUnlocked(Player* player, BestiaryType_t race return count; } -void IOBestiary::addCharmPoints(Player* player, uint16_t amount, bool negative /*= false*/) { +void IOBestiary::addCharmPoints(std::shared_ptr player, uint16_t amount, bool negative /*= false*/) { if (!player) { return; } @@ -213,7 +213,7 @@ void IOBestiary::addCharmPoints(Player* player, uint16_t amount, bool negative / player->setCharmPoints(myCharms); } -void IOBestiary::addBestiaryKill(Player* player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) { +void IOBestiary::addBestiaryKill(std::shared_ptr player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) { uint16_t raceid = mtype->info.raceid; if (raceid == 0 || !player || !mtype) { return; @@ -241,7 +241,7 @@ void IOBestiary::addBestiaryKill(Player* player, const std::shared_ptrrefreshCyclopediaMonsterTracker(); } -charmRune_t IOBestiary::getCharmFromTarget(Player* player, const std::shared_ptr mtype) { +charmRune_t IOBestiary::getCharmFromTarget(std::shared_ptr player, const std::shared_ptr mtype) { if (!player || !mtype) { return CHARM_NONE; } @@ -283,7 +283,7 @@ int32_t IOBestiary::bitToggle(int32_t input, const std::shared_ptr charm, } } -void IOBestiary::sendBuyCharmRune(Player* player, charmRune_t runeID, uint8_t action, uint16_t raceid) { +void IOBestiary::sendBuyCharmRune(std::shared_ptr player, charmRune_t runeID, uint8_t action, uint16_t raceid) { const auto charm = getBestiaryCharm(runeID); if (!player || !charm) { return; @@ -384,7 +384,7 @@ std::map IOBestiary::getMonsterElements(const std::shared_ptr< return defaultMap; } -std::map IOBestiary::getBestiaryKillCountByMonsterIDs(Player* player, std::map mtype_list) const { +std::map IOBestiary::getBestiaryKillCountByMonsterIDs(std::shared_ptr player, std::map mtype_list) const { std::map raceMonsters = {}; for (const auto &it : mtype_list) { uint16_t raceid = it.first; @@ -396,7 +396,7 @@ std::map IOBestiary::getBestiaryKillCountByMonsterIDs(Player return raceMonsters; } -phmap::parallel_flat_hash_set IOBestiary::getBestiaryFinished(Player* player) const { +phmap::parallel_flat_hash_set IOBestiary::getBestiaryFinished(std::shared_ptr player) const { phmap::parallel_flat_hash_set finishedMonsters; auto bestiaryMap = g_game().getBestiaryList(); diff --git a/src/io/iobestiary.hpp b/src/io/iobestiary.hpp index e072e9ae8e4..26f802dcb5b 100644 --- a/src/io/iobestiary.hpp +++ b/src/io/iobestiary.hpp @@ -55,28 +55,28 @@ class IOBestiary { } std::shared_ptr getBestiaryCharm(charmRune_t activeCharm, bool force = false) const; - void addBestiaryKill(Player* player, const std::shared_ptr mtype, uint32_t amount = 1); - bool parseCharmCombat(const std::shared_ptr charm, Player* player, Creature* target, int32_t realDamage, bool dueToPotion = false, bool checkArmor = false); - void addCharmPoints(Player* player, uint16_t amount, bool negative = false); - void sendBuyCharmRune(Player* player, charmRune_t runeID, uint8_t action, uint16_t raceid); - void setCharmRuneCreature(Player* player, const std::shared_ptr charm, uint16_t raceid); - void resetCharmRuneCreature(Player* player, const std::shared_ptr charm); + void addBestiaryKill(std::shared_ptr player, const std::shared_ptr mtype, uint32_t amount = 1); + bool parseCharmCombat(const std::shared_ptr charm, std::shared_ptr player, std::shared_ptr target, int32_t realDamage, bool dueToPotion = false, bool checkArmor = false); + void addCharmPoints(std::shared_ptr player, uint16_t amount, bool negative = false); + void sendBuyCharmRune(std::shared_ptr player, charmRune_t runeID, uint8_t action, uint16_t raceid); + void setCharmRuneCreature(std::shared_ptr player, const std::shared_ptr charm, uint16_t raceid); + void resetCharmRuneCreature(std::shared_ptr player, const std::shared_ptr charm); int8_t calculateDifficult(uint32_t chance) const; uint8_t getKillStatus(const std::shared_ptr mtype, uint32_t killAmount) const; - uint16_t getBestiaryRaceUnlocked(Player* player, BestiaryType_t race) const; + uint16_t getBestiaryRaceUnlocked(std::shared_ptr player, BestiaryType_t race) const; int32_t bitToggle(int32_t input, const std::shared_ptr charm, bool on) const; bool hasCharmUnlockedRuneBit(const std::shared_ptr charm, int32_t input) const; - std::list getCharmUsedRuneBitAll(Player* player); - phmap::parallel_flat_hash_set getBestiaryFinished(Player* player) const; + std::list getCharmUsedRuneBitAll(std::shared_ptr player); + phmap::parallel_flat_hash_set getBestiaryFinished(std::shared_ptr player) const; - charmRune_t getCharmFromTarget(Player* player, const std::shared_ptr mtype); + charmRune_t getCharmFromTarget(std::shared_ptr player, const std::shared_ptr mtype); - std::map getBestiaryKillCountByMonsterIDs(Player* player, std::map mtype_list) const; + std::map getBestiaryKillCountByMonsterIDs(std::shared_ptr player, std::map mtype_list) const; std::map getMonsterElements(const std::shared_ptr mtype) const; std::map findRaceByName(const std::string &race, bool Onlystring = true, BestiaryType_t raceNumber = BESTY_RACE_NONE) const; diff --git a/src/io/iologindata.cpp b/src/io/iologindata.cpp index 3314cd5cf56..db32e581ec2 100644 --- a/src/io/iologindata.cpp +++ b/src/io/iologindata.cpp @@ -85,21 +85,21 @@ void IOLoginData::updateOnlineStatus(uint32_t guid, bool login) { } // The boolean "disable" will desactivate the loading of information that is not relevant to the preload, for example, forge, bosstiary, etc. None of this we need to access if the player is offline -bool IOLoginData::loadPlayerById(Player* player, uint32_t id, bool disable /* = true*/) { +bool IOLoginData::loadPlayerById(std::shared_ptr player, uint32_t id, bool disable /* = true*/) { Database &db = Database::getInstance(); std::ostringstream query; query << "SELECT * FROM `players` WHERE `id` = " << id; return loadPlayer(player, db.storeQuery(query.str()), disable); } -bool IOLoginData::loadPlayerByName(Player* player, const std::string &name, bool disable /* = true*/) { +bool IOLoginData::loadPlayerByName(std::shared_ptr player, const std::string &name, bool disable /* = true*/) { Database &db = Database::getInstance(); std::ostringstream query; query << "SELECT * FROM `players` WHERE `name` = " << db.escapeString(name); return loadPlayer(player, db.storeQuery(query.str()), disable); } -bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result, bool disable /* = false*/) { +bool IOLoginData::loadPlayer(std::shared_ptr player, DBResult_ptr result, bool disable /* = false*/) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Resultnullptr: {}", __FUNCTION__); return false; @@ -185,7 +185,7 @@ bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result, bool disable / } } -bool IOLoginData::savePlayer(Player* player) { +bool IOLoginData::savePlayer(std::shared_ptr player) { bool success = DBTransaction::executeWithinTransaction([player]() { return savePlayerGuard(player); }); @@ -197,7 +197,7 @@ bool IOLoginData::savePlayer(Player* player) { return success; } -bool IOLoginData::savePlayerGuard(Player* player) { +bool IOLoginData::savePlayerGuard(std::shared_ptr player) { if (!player) { throw DatabaseException("Player nullptr in function: " + std::string(__FUNCTION__)); } diff --git a/src/io/iologindata.hpp b/src/io/iologindata.hpp index baae9a57b9e..724967d2877 100644 --- a/src/io/iologindata.hpp +++ b/src/io/iologindata.hpp @@ -13,17 +13,17 @@ #include "creatures/players/player.hpp" #include "database/database.hpp" -using ItemBlockList = std::list>; +using ItemBlockList = std::list>>; class IOLoginData { public: static bool gameWorldAuthentication(const std::string &accountDescriptor, const std::string &sessionOrPassword, std::string &characterName, uint32_t &accountId, bool oldProcotol); static account::AccountType getAccountType(uint32_t accountId); static void updateOnlineStatus(uint32_t guid, bool login); - static bool loadPlayerById(Player* player, uint32_t id, bool disable = true); - static bool loadPlayerByName(Player* player, const std::string &name, bool disable = true); - static bool loadPlayer(Player* player, DBResult_ptr result, bool disable = true); - static bool savePlayer(Player* player); + static bool loadPlayerById(std::shared_ptr player, uint32_t id, bool disable = true); + static bool loadPlayerByName(std::shared_ptr player, const std::string &name, bool disable = true); + static bool loadPlayer(std::shared_ptr player, DBResult_ptr result, bool disable = true); + static bool savePlayer(std::shared_ptr player); static uint32_t getGuidByName(const std::string &name); static bool getGuidByNameEx(uint32_t &guid, bool &specialVip, std::string &name); static std::string getNameByGuid(uint32_t guid); @@ -37,5 +37,5 @@ class IOLoginData { static void removeVIPEntry(uint32_t accountId, uint32_t guid); private: - static bool savePlayerGuard(Player* player); + static bool savePlayerGuard(std::shared_ptr player); }; diff --git a/src/io/iomapserialize.cpp b/src/io/iomapserialize.cpp index 8c9d8dc3125..ca382c9215d 100644 --- a/src/io/iomapserialize.cpp +++ b/src/io/iomapserialize.cpp @@ -34,7 +34,7 @@ void IOMapSerialize::loadHouseItems(Map* map) { continue; } - Tile* tile = map->getTile(x, y, z); + std::shared_ptr tile = map->getTile(x, y, z); if (!tile) { continue; } @@ -77,7 +77,7 @@ bool IOMapSerialize::SaveHouseItemsGuard() { PropWriteStream stream; for (const auto &[key, house] : g_game().map.houses.getHouses()) { // save house items - for (HouseTile* tile : house->getTiles()) { + for (std::shared_ptr tile : house->getTiles()) { saveTile(stream, tile); size_t attributesSize; @@ -100,7 +100,7 @@ bool IOMapSerialize::SaveHouseItemsGuard() { return true; } -bool IOMapSerialize::loadContainer(PropStream &propStream, Container* container) { +bool IOMapSerialize::loadContainer(PropStream &propStream, std::shared_ptr container) { while (container->serializationCount > 0) { if (!loadItem(propStream, container)) { g_logger().warn("Deserialization error for container item: {}", container->getID()); @@ -119,13 +119,13 @@ bool IOMapSerialize::loadContainer(PropStream &propStream, Container* container) uint32_t NEW_BEDS_START_ID = 30000; -bool IOMapSerialize::loadItem(PropStream &propStream, Cylinder* parent, bool isHouseItem /*= false*/) { +bool IOMapSerialize::loadItem(PropStream &propStream, std::shared_ptr parent, bool isHouseItem /*= false*/) { uint16_t id; if (!propStream.read(id)) { return false; } - Tile* tile = nullptr; + std::shared_ptr tile = nullptr; if (parent->getParent() == nullptr) { tile = parent->getTile(); } @@ -136,12 +136,12 @@ bool IOMapSerialize::loadItem(PropStream &propStream, Cylinder* parent, bool isH } if (iType.moveable || !tile || iType.isCarpet() || iType.isBed()) { // create a new item - Item* item = Item::CreateItem(id); + std::shared_ptr item = Item::CreateItem(id); if (item) { if (item->unserializeAttr(propStream)) { - Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container && !loadContainer(propStream, container)) { - delete item; + return false; } @@ -149,15 +149,15 @@ bool IOMapSerialize::loadItem(PropStream &propStream, Cylinder* parent, bool isH item->startDecaying(); } else { g_logger().warn("Deserialization error in {}", id); - delete item; + return false; } } } else { // Stationary items like doors/beds/blackboards/bookcases - Item* item = nullptr; + std::shared_ptr item = nullptr; if (const TileItemVector* items = tile->getItemList()) { - for (Item* findItem : *items) { + for (auto &findItem : *items) { if (findItem->getID() == id) { item = findItem; break; @@ -176,7 +176,7 @@ bool IOMapSerialize::loadItem(PropStream &propStream, Cylinder* parent, bool isH if (item) { if (item->unserializeAttr(propStream)) { - Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container && !loadContainer(propStream, container)) { return false; } @@ -187,15 +187,15 @@ bool IOMapSerialize::loadItem(PropStream &propStream, Cylinder* parent, bool isH } } else { // The map changed since the last save, just read the attributes - std::unique_ptr dummy(Item::CreateItem(id)); + auto dummy = Item::CreateItem(id); if (dummy) { dummy->unserializeAttr(propStream); - Container* container = dummy->getContainer(); + std::shared_ptr container = dummy->getContainer(); if (container) { if (!loadContainer(propStream, container)) { return false; } - } else if (BedItem* bedItem = dynamic_cast(dummy.get())) { + } else if (std::shared_ptr bedItem = std::dynamic_pointer_cast(dummy)) { uint32_t sleeperGUID = bedItem->getSleeper(); if (sleeperGUID != 0) { g_game().removeBedSleeper(sleeperGUID); @@ -207,8 +207,8 @@ bool IOMapSerialize::loadItem(PropStream &propStream, Cylinder* parent, bool isH return true; } -void IOMapSerialize::saveItem(PropWriteStream &stream, const Item* item) { - const Container* container = item->getContainer(); +void IOMapSerialize::saveItem(PropWriteStream &stream, std::shared_ptr item) { + std::shared_ptr container = item->getContainer(); // Write ID & props stream.write(item->getID()); @@ -226,15 +226,15 @@ void IOMapSerialize::saveItem(PropWriteStream &stream, const Item* item) { stream.write(0x00); // attr end } -void IOMapSerialize::saveTile(PropWriteStream &stream, const Tile* tile) { +void IOMapSerialize::saveTile(PropWriteStream &stream, std::shared_ptr tile) { const TileItemVector* tileItems = tile->getItemList(); if (!tileItems) { return; } - std::forward_list items; + std::forward_list> items; uint16_t count = 0; - for (Item* item : *tileItems) { + for (auto &item : *tileItems) { if (!item->isSavedToHouses()) { continue; } @@ -250,7 +250,7 @@ void IOMapSerialize::saveTile(PropWriteStream &stream, const Tile* tile) { stream.write(tilePosition.z); stream.write(count); - for (const Item* item : items) { + for (std::shared_ptr item : items) { saveItem(stream, item); } } @@ -342,7 +342,7 @@ bool IOMapSerialize::SaveHouseInfoGuard() { listText.clear(); } - for (Door* door : house->getDoors()) { + for (std::shared_ptr door : house->getDoors()) { if (door->getAccessList(listText) && !listText.empty()) { query << house->getId() << ',' << door->getDoorId() << ',' << db.escapeString(listText); if (!stmt.addRow(query)) { diff --git a/src/io/iomapserialize.hpp b/src/io/iomapserialize.hpp index 1fe13af92c2..017dd970529 100644 --- a/src/io/iomapserialize.hpp +++ b/src/io/iomapserialize.hpp @@ -21,9 +21,9 @@ class IOMapSerialize { private: static bool SaveHouseInfoGuard(); static bool SaveHouseItemsGuard(); - static void saveItem(PropWriteStream &stream, const Item* item); - static void saveTile(PropWriteStream &stream, const Tile* tile); + static void saveItem(PropWriteStream &stream, std::shared_ptr item); + static void saveTile(PropWriteStream &stream, std::shared_ptr tile); - static bool loadContainer(PropStream &propStream, Container* container); - static bool loadItem(PropStream &propStream, Cylinder* parent, bool isHouseItem = false); + static bool loadContainer(PropStream &propStream, std::shared_ptr container); + static bool loadItem(PropStream &propStream, std::shared_ptr parent, bool isHouseItem = false); }; diff --git a/src/io/iomarket.cpp b/src/io/iomarket.cpp index cf07aa04f45..8feb7f38dc8 100644 --- a/src/io/iomarket.cpp +++ b/src/io/iomarket.cpp @@ -131,11 +131,11 @@ void IOMarket::processExpiredOffers(DBResult_ptr result, bool) { continue; } - Player* player = g_game().getPlayerByGUID(playerId); + std::shared_ptr player = g_game().getPlayerByGUID(playerId); if (!player) { - player = new Player(nullptr); + player = std::make_shared(nullptr); if (!IOLoginData::loadPlayerById(player, playerId)) { - delete player; + continue; } } @@ -144,10 +144,10 @@ void IOMarket::processExpiredOffers(DBResult_ptr result, bool) { uint16_t tmpAmount = amount; while (tmpAmount > 0) { uint16_t stackCount = std::min(100, tmpAmount); - Item* item = Item::CreateItem(itemType.id, stackCount); + std::shared_ptr item = Item::CreateItem(itemType.id, stackCount); if (g_game().internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { g_logger().error("[{}] Ocurred an error to add item with id {} to player {}", __FUNCTION__, itemType.id, player->getName()); - delete item; + break; } @@ -166,9 +166,9 @@ void IOMarket::processExpiredOffers(DBResult_ptr result, bool) { } for (uint16_t i = 0; i < amount; ++i) { - Item* item = Item::CreateItem(itemType.id, subType); + std::shared_ptr item = Item::CreateItem(itemType.id, subType); if (g_game().internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { - delete item; + break; } @@ -180,12 +180,11 @@ void IOMarket::processExpiredOffers(DBResult_ptr result, bool) { if (player->isOffline()) { IOLoginData::savePlayer(player); - delete player; } } else { uint64_t totalPrice = result->getNumber("price") * amount; - Player* player = g_game().getPlayerByGUID(playerId); + std::shared_ptr player = g_game().getPlayerByGUID(playerId); if (player) { player->setBankBalance(player->getBankBalance() + totalPrice); } else { diff --git a/src/io/ioprey.cpp b/src/io/ioprey.cpp index 23aa3d794ee..449383a1b87 100644 --- a/src/io/ioprey.cpp +++ b/src/io/ioprey.cpp @@ -246,7 +246,7 @@ void TaskHuntingSlot::reloadReward() { } // Prey/Task hunting global class -void IOPrey::CheckPlayerPreys(Player* player, uint8_t amount) const { +void IOPrey::CheckPlayerPreys(std::shared_ptr player, uint8_t amount) const { if (!player) { return; } @@ -289,7 +289,7 @@ void IOPrey::CheckPlayerPreys(Player* player, uint8_t amount) const { } } -void IOPrey::ParsePreyAction(Player* player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const { +void IOPrey::ParsePreyAction(std::shared_ptr player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const { PreySlot* slot = player->getPreySlotById(slotId); if (!slot || slot->state == PreyDataState_Locked) { player->sendMessageDialog("To unlock this prey slot first you must buy it on store."); @@ -389,7 +389,7 @@ void IOPrey::ParsePreyAction(Player* player, PreySlot_t slotId, PreyAction_t act player->reloadPreySlot(slotId); } -void IOPrey::ParseTaskHuntingAction(Player* player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const { +void IOPrey::ParseTaskHuntingAction(std::shared_ptr player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const { TaskHuntingSlot* slot = player->getTaskHuntingSlotById(slotId); if (!slot || slot->state == PreyTaskDataState_Locked) { player->sendMessageDialog("To unlock this task hunting slot first you must buy it on store."); diff --git a/src/io/ioprey.hpp b/src/io/ioprey.hpp index 00597156260..5885615d225 100644 --- a/src/io/ioprey.hpp +++ b/src/io/ioprey.hpp @@ -217,10 +217,10 @@ class IOPrey { return inject(); } - void CheckPlayerPreys(Player* player, uint8_t amount) const; - void ParsePreyAction(Player* player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const; + void CheckPlayerPreys(std::shared_ptr player, uint8_t amount) const; + void ParsePreyAction(std::shared_ptr player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const; - void ParseTaskHuntingAction(Player* player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const; + void ParseTaskHuntingAction(std::shared_ptr player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const; void InitializeTaskHuntOptions(); TaskHuntingOption* GetTaskRewardOption(const TaskHuntingSlot* slot) const; diff --git a/src/items/bed.cpp b/src/items/bed.cpp index f166320a220..2f029cb1eea 100644 --- a/src/items/bed.cpp +++ b/src/items/bed.cpp @@ -31,7 +31,7 @@ Attr_ReadValue BedItem::readAttr(AttrTypes_t attr, PropStream &propStream) { std::string name = IOLoginData::getNameByGuid(guid); if (!name.empty()) { setAttribute(ItemAttribute_t::DESCRIPTION, name + " is sleeping there."); - g_game().setBedSleeper(this, guid); + g_game().setBedSleeper(static_self_cast(), guid); sleeperGUID = guid; } } @@ -67,18 +67,18 @@ void BedItem::serializeAttr(PropWriteStream &propWriteStream) const { } } -BedItem* BedItem::getNextBedItem() const { +std::shared_ptr BedItem::getNextBedItem() { Direction dir = Item::items[id].bedPartnerDir; Position targetPos = getNextPosition(dir, getPosition()); - const Tile* tile = g_game().map.getTile(targetPos); + std::shared_ptr tile = g_game().map.getTile(targetPos); if (tile == nullptr) { return nullptr; } return tile->getBedItem(); } -bool BedItem::canUse(Player* player) { +bool BedItem::canUse(std::shared_ptr player) { if ((player == nullptr) || (house == nullptr) || !player->isPremium()) { return false; } @@ -99,18 +99,18 @@ bool BedItem::canUse(Player* player) { return true; } - Player sleeper(nullptr); - if (!IOLoginData::loadPlayerById(&sleeper, sleeperGUID)) { + auto sleeper = std::make_shared(nullptr); + if (!IOLoginData::loadPlayerById(sleeper, sleeperGUID)) { return false; } - if (house->getHouseAccessLevel(&sleeper) > house->getHouseAccessLevel(player)) { + if (house->getHouseAccessLevel(sleeper) > house->getHouseAccessLevel(player)) { return false; } return true; } -bool BedItem::trySleep(Player* player) { +bool BedItem::trySleep(std::shared_ptr player) { if (!house || player->isRemoved()) { return false; } @@ -126,7 +126,7 @@ bool BedItem::trySleep(Player* player) { return true; } -bool BedItem::sleep(Player* player) { +bool BedItem::sleep(std::shared_ptr player) { if (house == nullptr) { return false; } @@ -135,7 +135,7 @@ bool BedItem::sleep(Player* player) { return false; } - BedItem* nextBedItem = getNextBedItem(); + std::shared_ptr nextBedItem = getNextBedItem(); internalSetSleeper(player); @@ -144,10 +144,10 @@ bool BedItem::sleep(Player* player) { } // update the bedSleepersMap - g_game().setBedSleeper(this, player->getGUID()); + g_game().setBedSleeper(static_self_cast(), player->getGUID()); // make the player walk onto the bed - g_game().map.moveCreature(*player, *getTile()); + g_game().map.moveCreature(player, getTile()); // display 'Zzzz'/sleep effect g_game().addMagicEffect(player->getPosition(), CONST_ME_SLEEP); @@ -165,7 +165,7 @@ bool BedItem::sleep(Player* player) { return true; } -void BedItem::wakeUp(Player* player) { +void BedItem::wakeUp(std::shared_ptr player) { if (house == nullptr) { return; } @@ -175,10 +175,10 @@ void BedItem::wakeUp(Player* player) { if (sleeperGUID != 0) { if (player == nullptr) { - Player regenPlayer(nullptr); - if (IOLoginData::loadPlayerById(®enPlayer, sleeperGUID)) { - regeneratePlayer(®enPlayer); - IOLoginData::savePlayer(®enPlayer); + auto regenPlayer = std::make_shared(nullptr); + if (IOLoginData::loadPlayerById(regenPlayer, sleeperGUID)) { + regeneratePlayer(regenPlayer); + IOLoginData::savePlayer(regenPlayer); } } else { regeneratePlayer(player); @@ -189,7 +189,7 @@ void BedItem::wakeUp(Player* player) { // update the bedSleepersMap g_game().removeBedSleeper(sleeperGUID); - BedItem* nextBedItem = getNextBedItem(); + std::shared_ptr nextBedItem = getNextBedItem(); // unset sleep info internalRemoveSleeper(); @@ -206,7 +206,7 @@ void BedItem::wakeUp(Player* player) { } } -void BedItem::regeneratePlayer(Player* player) const { +void BedItem::regeneratePlayer(std::shared_ptr player) const { const uint32_t sleptTime = time(nullptr) - sleepStart; Condition* condition = player->getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT); @@ -232,24 +232,24 @@ void BedItem::regeneratePlayer(Player* player) const { player->changeSoul(soulRegen); } -void BedItem::updateAppearance(const Player* player) { +void BedItem::updateAppearance(std::shared_ptr player) { const ItemType &it = Item::items[id]; if (it.type == ITEM_TYPE_BED) { if ((player != nullptr) && it.transformToOnUse[player->getSex()] != 0) { const ItemType &newType = Item::items[it.transformToOnUse[player->getSex()]]; if (newType.type == ITEM_TYPE_BED) { - g_game().transformItem(this, it.transformToOnUse[player->getSex()]); + g_game().transformItem(static_self_cast(), it.transformToOnUse[player->getSex()]); } } else if (it.transformToFree != 0) { const ItemType &newType = Item::items[it.transformToFree]; if (newType.type == ITEM_TYPE_BED) { - g_game().transformItem(this, it.transformToFree); + g_game().transformItem(static_self_cast(), it.transformToFree); } } } } -void BedItem::internalSetSleeper(const Player* player) { +void BedItem::internalSetSleeper(std::shared_ptr player) { std::string desc_str = player->getName() + " is sleeping there."; sleeperGUID = player->getGUID(); diff --git a/src/items/bed.hpp b/src/items/bed.hpp index 95b39e3b9dc..bdacbd88204 100644 --- a/src/items/bed.hpp +++ b/src/items/bed.hpp @@ -18,11 +18,8 @@ class BedItem final : public Item { public: explicit BedItem(uint16_t id); - BedItem* getBed() override { - return this; - } - const BedItem* getBed() const override { - return this; + std::shared_ptr getBed() override { + return static_self_cast(); } Attr_ReadValue readAttr(AttrTypes_t attr, PropStream &propStream) override; @@ -40,20 +37,20 @@ class BedItem final : public Item { house = h; } - bool canUse(Player* player); + bool canUse(std::shared_ptr player); - bool trySleep(Player* player); - bool sleep(Player* player); - void wakeUp(Player* player); + bool trySleep(std::shared_ptr player); + bool sleep(std::shared_ptr player); + void wakeUp(std::shared_ptr player); - BedItem* getNextBedItem() const; + std::shared_ptr getNextBedItem(); friend class MapCache; private: - void updateAppearance(const Player* player); - void regeneratePlayer(Player* player) const; - void internalSetSleeper(const Player* player); + void updateAppearance(std::shared_ptr player); + void regeneratePlayer(std::shared_ptr player) const; + void internalSetSleeper(std::shared_ptr player); void internalRemoveSleeper(); House* house = nullptr; diff --git a/src/items/containers/container.cpp b/src/items/containers/container.cpp index fbe9486c3bb..8dcf094d944 100644 --- a/src/items/containers/container.cpp +++ b/src/items/containers/container.cpp @@ -30,14 +30,14 @@ Container::Container(uint16_t initType, uint16_t initSize, bool initUnlocked /*= unlocked(initUnlocked), pagination(initPagination) { } -Container::Container(Tile* tile) : +Container::Container(std::shared_ptr tile) : Container(ITEM_BROWSEFIELD, 30, false, true) { TileItemVector* itemVector = tile->getItemList(); if (itemVector) { - for (Item* item : *itemVector) { + for (auto &item : *itemVector) { if (((item->getContainer() || item->hasProperty(CONST_PROP_MOVEABLE)) || (item->isWrapable() && !item->hasProperty(CONST_PROP_MOVEABLE) && !item->hasProperty(CONST_PROP_BLOCKPATH))) && !item->hasAttribute(ItemAttribute_t::UNIQUEID)) { itemlist.push_front(item); - item->setParent(this); + item->setParent(getContainer()); } } } @@ -49,37 +49,37 @@ Container::~Container() { if (getID() == ITEM_BROWSEFIELD) { g_game().browseFields.erase(getTile()); - for (Item* item : itemlist) { + for (std::shared_ptr item : itemlist) { item->setParent(parent); } } else { - for (Item* item : itemlist) { + for (std::shared_ptr item : itemlist) { item->setParent(nullptr); item->decrementReferenceCounter(); } } } -Item* Container::clone() const { - Container* clone = static_cast(Item::clone()); - for (Item* item : itemlist) { +std::shared_ptr Container::clone() const { + std::shared_ptr clone = std::static_pointer_cast(Item::clone()); + for (std::shared_ptr item : itemlist) { clone->addItem(item->clone()); } clone->totalWeight = totalWeight; return clone; } -Container* Container::getParentContainer() { - Thing* thing = getParent(); +std::shared_ptr Container::getParentContainer() { + std::shared_ptr thing = getParent(); if (!thing) { return nullptr; } return thing->getContainer(); } -Container* Container::getTopParentContainer() const { - Thing* thing = getParent(); - Thing* prevThing = const_cast(this); +std::shared_ptr Container::getTopParentContainer() { + std::shared_ptr thing = getParent(); + std::shared_ptr prevThing = getContainer(); if (!thing) { return prevThing->getContainer(); } @@ -96,17 +96,17 @@ Container* Container::getTopParentContainer() const { return thing->getContainer(); } -Container* Container::getRootContainer() const { +std::shared_ptr Container::getRootContainer() { return getTopParentContainer(); } bool Container::hasParent() const { - return getID() != ITEM_BROWSEFIELD && dynamic_cast(getParent()) == nullptr; + return getID() != ITEM_BROWSEFIELD && std::dynamic_pointer_cast(getParent()) == nullptr; } -void Container::addItem(Item* item) { +void Container::addItem(std::shared_ptr item) { itemlist.push_back(item); - item->setParent(this); + item->setParent(getContainer()); } StashContainerList Container::getStowableItems() const { @@ -115,11 +115,11 @@ StashContainerList Container::getStowableItems() const { if (item->getContainer() != NULL) { auto subContainer = item->getContainer()->getStowableItems(); for (auto subContItem : subContainer) { - Item* containerItem = subContItem.first; - toReturnList.push_back(std::pair(containerItem, static_cast(containerItem->getItemCount()))); + std::shared_ptr containerItem = subContItem.first; + toReturnList.push_back(std::pair, uint32_t>(containerItem, static_cast(containerItem->getItemCount()))); } } else if (item->isItemStorable()) { - toReturnList.push_back(std::pair(item, static_cast(item->getItemCount()))); + toReturnList.push_back(std::pair, uint32_t>(item, static_cast(item->getItemCount()))); } } @@ -159,7 +159,7 @@ bool Container::unserializeItemNode(OTB::Loader &loader, const OTB::Node &node, return false; } - Item* item = Item::CreateItem(id, itemPosition); + std::shared_ptr item = Item::CreateItem(id, itemPosition); if (!item) { continue; } @@ -188,7 +188,7 @@ bool Container::countsToLootAnalyzerBalance() { void Container::updateItemWeight(int32_t diff) { totalWeight += diff; - Container* parentContainer = this; // credits: SaiyansKing + std::shared_ptr parentContainer = getContainer(); while ((parentContainer = parentContainer->getParentContainer()) != nullptr) { parentContainer->totalWeight += diff; } @@ -198,17 +198,17 @@ uint32_t Container::getWeight() const { return Item::getWeight() + totalWeight; } -std::string Container::getContentDescription(bool oldProtocol) const { +std::string Container::getContentDescription(bool oldProtocol) { std::ostringstream os; return getContentDescription(os, oldProtocol).str(); } -std::ostringstream &Container::getContentDescription(std::ostringstream &os, bool oldProtocol) const { +std::ostringstream &Container::getContentDescription(std::ostringstream &os, bool oldProtocol) { bool firstitem = true; for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { - Item* item = *it; + std::shared_ptr item = *it; - Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container && !container->empty()) { continue; } @@ -245,11 +245,11 @@ bool Container::isStoreInboxFiltered() const { return false; } -std::deque Container::getStoreInboxFilteredItems() const { +std::deque> Container::getStoreInboxFilteredItems() const { const auto enumName = getAttribute(ItemAttribute_t::STORE_INBOX_CATEGORY); ItemDeque storeInboxFilteredList; if (isStoreInboxFiltered()) { - for (Item* item : getItemList()) { + for (std::shared_ptr item : getItemList()) { auto itemId = item->getID(); auto attribute = item->getCustomAttribute("unWrapId"); uint16_t unWrapId = attribute ? static_cast(attribute->getInteger()) : 0; @@ -291,7 +291,7 @@ phmap::flat_hash_set Container::getStoreInboxValidCategorie return validCategories; } -Item* Container::getFilteredItemByIndex(size_t index) const { +std::shared_ptr Container::getFilteredItemByIndex(size_t index) const { const auto &filteredItems = getStoreInboxFilteredItems(); if (index >= filteredItems.size()) { return nullptr; @@ -307,7 +307,7 @@ Item* Container::getFilteredItemByIndex(size_t index) const { return *it; } -Item* Container::getItemByIndex(size_t index) const { +std::shared_ptr Container::getItemByIndex(size_t index) const { if (index >= size()) { return nullptr; } @@ -315,7 +315,7 @@ Item* Container::getItemByIndex(size_t index) const { return itemlist[index]; } -uint32_t Container::getItemHoldingCount() const { +uint32_t Container::getItemHoldingCount() { uint32_t counter = 0; for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { ++counter; @@ -323,7 +323,7 @@ uint32_t Container::getItemHoldingCount() const { return counter; } -uint32_t Container::getContainerHoldingCount() const { +uint32_t Container::getContainerHoldingCount() { uint32_t counter = 0; for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { if ((*it)->getContainer()) { @@ -333,7 +333,7 @@ uint32_t Container::getContainerHoldingCount() const { return counter; } -bool Container::isHoldingItem(const Item* item) const { +bool Container::isHoldingItem(std::shared_ptr item) { for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { if (*it == item) { return true; @@ -342,9 +342,9 @@ bool Container::isHoldingItem(const Item* item) const { return false; } -bool Container::isHoldingItemWithId(const uint16_t id) const { +bool Container::isHoldingItemWithId(const uint16_t id) { for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { - const Item* item = *it; + std::shared_ptr item = *it; if (item->getID() == id) { return true; } @@ -352,52 +352,52 @@ bool Container::isHoldingItemWithId(const uint16_t id) const { return false; } -void Container::onAddContainerItem(Item* item) { +void Container::onAddContainerItem(std::shared_ptr item) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, getPosition(), false, true, 2, 2, 2, 2); // send to client - for (Creature* spectator : spectators) { - spectator->getPlayer()->sendAddContainerItem(this, item); + for (std::shared_ptr spectator : spectators) { + spectator->getPlayer()->sendAddContainerItem(getContainer(), item); } // event methods - for (Creature* spectator : spectators) { + for (std::shared_ptr spectator : spectators) { spectator->getPlayer()->onAddContainerItem(item); } } -void Container::onUpdateContainerItem(uint32_t index, Item* oldItem, Item* newItem) { +void Container::onUpdateContainerItem(uint32_t index, std::shared_ptr oldItem, std::shared_ptr newItem) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, getPosition(), false, true, 2, 2, 2, 2); // send to client - for (Creature* spectator : spectators) { - spectator->getPlayer()->sendUpdateContainerItem(this, index, newItem); + for (std::shared_ptr spectator : spectators) { + spectator->getPlayer()->sendUpdateContainerItem(getContainer(), index, newItem); } // event methods - for (Creature* spectator : spectators) { - spectator->getPlayer()->onUpdateContainerItem(this, oldItem, newItem); + for (std::shared_ptr spectator : spectators) { + spectator->getPlayer()->onUpdateContainerItem(getContainer(), oldItem, newItem); } } -void Container::onRemoveContainerItem(uint32_t index, Item* item) { +void Container::onRemoveContainerItem(uint32_t index, std::shared_ptr item) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, getPosition(), false, true, 2, 2, 2, 2); // send change to client - for (Creature* spectator : spectators) { - spectator->getPlayer()->sendRemoveContainerItem(this, index); + for (std::shared_ptr spectator : spectators) { + spectator->getPlayer()->sendRemoveContainerItem(getContainer(), index); } // event methods - for (Creature* spectator : spectators) { - spectator->getPlayer()->onRemoveContainerItem(this, item); + for (std::shared_ptr spectator : spectators) { + spectator->getPlayer()->onRemoveContainerItem(getContainer(), item); } } -ReturnValue Container::queryAdd(int32_t addIndex, const Thing &addThing, uint32_t addCount, uint32_t flags, Creature* actor /* = nullptr*/) const { +ReturnValue Container::queryAdd(int32_t addIndex, const std::shared_ptr &addThing, uint32_t addCount, uint32_t flags, std::shared_ptr actor /* = nullptr*/) { bool childIsOwner = hasBitSet(FLAG_CHILDISOWNER, flags); if (childIsOwner) { // a child container is querying, since we are the top container (not carried by a player) @@ -409,7 +409,7 @@ ReturnValue Container::queryAdd(int32_t addIndex, const Thing &addThing, uint32_ return RETURNVALUE_NOTPOSSIBLE; } - const Item* item = addThing.getItem(); + std::shared_ptr item = addThing->getItem(); if (item == nullptr) { return RETURNVALUE_NOTPOSSIBLE; } @@ -418,21 +418,21 @@ ReturnValue Container::queryAdd(int32_t addIndex, const Thing &addThing, uint32_ return RETURNVALUE_CANNOTPICKUP; } - if (item == this) { + if (item == getItem()) { return RETURNVALUE_THISISIMPOSSIBLE; } - const Cylinder* cylinder = getParent(); + std::shared_ptr cylinder = getParent(); auto noLimit = hasBitSet(FLAG_NOLIMIT, flags); while (cylinder) { - if (cylinder == &addThing) { + if (cylinder == addThing) { return RETURNVALUE_THISISIMPOSSIBLE; } - const Container* container = cylinder->getContainer(); + std::shared_ptr container = cylinder->getContainer(); if (!noLimit && container && container->isInbox()) { return RETURNVALUE_CONTAINERNOTENOUGHROOM; } - const Cylinder* parent = cylinder->getParent(); + std::shared_ptr parent = cylinder->getParent(); if (cylinder == parent) { g_logger().error("Container::queryAdd: parent == cylinder. Preventing infinite loop."); return RETURNVALUE_NOTPOSSIBLE; @@ -444,8 +444,8 @@ ReturnValue Container::queryAdd(int32_t addIndex, const Thing &addThing, uint32_ return RETURNVALUE_CONTAINERNOTENOUGHROOM; } - if (const Container* topParentContainer = getTopParentContainer()) { - if (const Container* addContainer = item->getContainer()) { + if (std::shared_ptr topParentContainer = getTopParentContainer()) { + if (std::shared_ptr addContainer = item->getContainer()) { uint32_t addContainerCount = addContainer->getContainerHoldingCount() + 1; uint32_t maxContainer = static_cast(g_configManager().getNumber(MAX_CONTAINER)); if (addContainerCount + topParentContainer->getContainerHoldingCount() > maxContainer) { @@ -467,16 +467,16 @@ ReturnValue Container::queryAdd(int32_t addIndex, const Thing &addThing, uint32_ return RETURNVALUE_ONLYAMMOINQUIVER; } - const Cylinder* topParent = getTopParent(); - if (topParent != this) { - return topParent->queryAdd(INDEX_WHEREEVER, *item, addCount, flags | FLAG_CHILDISOWNER, actor); + std::shared_ptr topParent = getTopParent(); + if (topParent != getContainer()) { + return topParent->queryAdd(INDEX_WHEREEVER, item, addCount, flags | FLAG_CHILDISOWNER, actor); } else { return RETURNVALUE_NOERROR; } } -ReturnValue Container::queryMaxCount(int32_t index, const Thing &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) const { - const Item* item = thing.getItem(); +ReturnValue Container::queryMaxCount(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) { + std::shared_ptr item = thing->getItem(); if (item == nullptr) { maxQueryCount = 0; return RETURNVALUE_NOTPOSSIBLE; @@ -495,16 +495,16 @@ ReturnValue Container::queryMaxCount(int32_t index, const Thing &thing, uint32_t if (index == INDEX_WHEREEVER) { // Iterate through every item and check how much free stackable slots there is. uint32_t slotIndex = 0; - for (Item* containerItem : itemlist) { + for (std::shared_ptr containerItem : itemlist) { if (containerItem != item && containerItem->equals(item) && containerItem->getItemCount() < containerItem->getStackSize()) { uint32_t remainder = (containerItem->getStackSize() - containerItem->getItemCount()); - if (queryAdd(slotIndex++, *item, remainder, flags) == RETURNVALUE_NOERROR) { + if (queryAdd(slotIndex++, item, remainder, flags) == RETURNVALUE_NOERROR) { n += remainder; } } } } else { - const Item* destItem = getItemByIndex(index); + std::shared_ptr destItem = getItemByIndex(index); if (item->equals(destItem) && destItem->getItemCount() < destItem->getStackSize()) { n = destItem->getStackSize() - destItem->getItemCount(); } @@ -524,14 +524,14 @@ ReturnValue Container::queryMaxCount(int32_t index, const Thing &thing, uint32_t return RETURNVALUE_NOERROR; } -ReturnValue Container::queryRemove(const Thing &thing, uint32_t count, uint32_t flags, Creature* actor /*= nullptr */) const { - int32_t index = getThingIndex(&thing); +ReturnValue Container::queryRemove(const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor /*= nullptr */) { + int32_t index = getThingIndex(thing); if (index == -1) { g_logger().debug("{} - Failed to get thing index", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; } - const Item* item = thing.getItem(); + std::shared_ptr item = thing->getItem(); if (item == nullptr) { g_logger().debug("{} - Item is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; @@ -546,28 +546,28 @@ ReturnValue Container::queryRemove(const Thing &thing, uint32_t count, uint32_t g_logger().debug("{} - Item is not moveable", __FUNCTION__); return RETURNVALUE_NOTMOVEABLE; } - const HouseTile* houseTile = dynamic_cast(getTopParent()); + std::shared_ptr houseTile = std::dynamic_pointer_cast(getTopParent()); if (houseTile) { return houseTile->queryRemove(thing, count, flags, actor); } return RETURNVALUE_NOERROR; } -Cylinder* Container::queryDestination(int32_t &index, const Thing &thing, Item** destItem, uint32_t &flags) { +std::shared_ptr Container::queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &flags) { if (!unlocked) { *destItem = nullptr; - return this; + return getContainer(); } if (index == 254 /*move up*/) { index = INDEX_WHEREEVER; *destItem = nullptr; - Container* parentContainer = dynamic_cast(getParent()); + std::shared_ptr parentContainer = std::dynamic_pointer_cast(getParent()); if (parentContainer) { return parentContainer; } - return this; + return getContainer(); } if (index == 255 /*add wherever*/) { @@ -585,18 +585,18 @@ Cylinder* Container::queryDestination(int32_t &index, const Thing &thing, Item** *destItem = nullptr; } - const Item* item = thing.getItem(); + std::shared_ptr item = thing->getItem(); if (!item) { - return this; + return getContainer(); } if (index != INDEX_WHEREEVER) { - Item* itemFromIndex = getItemByIndex(index); + std::shared_ptr itemFromIndex = getItemByIndex(index); if (itemFromIndex) { *destItem = itemFromIndex; } - Cylinder* subCylinder = dynamic_cast(*destItem); + std::shared_ptr subCylinder = std::dynamic_pointer_cast(*destItem); if (subCylinder) { index = INDEX_WHEREEVER; *destItem = nullptr; @@ -605,30 +605,30 @@ Cylinder* Container::queryDestination(int32_t &index, const Thing &thing, Item** } bool autoStack = !hasBitSet(FLAG_IGNOREAUTOSTACK, flags); - if (autoStack && item->isStackable() && item->getParent() != this) { + if (autoStack && item->isStackable() && item->getParent() != getContainer()) { if (*destItem && (*destItem)->equals(item) && (*destItem)->getItemCount() < (*destItem)->getStackSize()) { - return this; + return getContainer(); } // try find a suitable item to stack with uint32_t n = 0; - for (Item* listItem : itemlist) { + for (std::shared_ptr listItem : itemlist) { if (listItem != item && listItem->equals(item) && listItem->getItemCount() < listItem->getStackSize()) { *destItem = listItem; index = n; - return this; + return getContainer(); } ++n; } } - return this; + return getContainer(); } -void Container::addThing(Thing* thing) { +void Container::addThing(std::shared_ptr thing) { return addThing(0, thing); } -void Container::addThing(int32_t index, Thing* thing) { +void Container::addThing(int32_t index, std::shared_ptr thing) { if (!thing) { return /*RETURNVALUE_NOTPOSSIBLE*/; } @@ -637,12 +637,12 @@ void Container::addThing(int32_t index, Thing* thing) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item == nullptr) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - item->setParent(this); + item->setParent(getContainer()); itemlist.push_front(item); updateItemWeight(item->getWeight()); @@ -652,7 +652,7 @@ void Container::addThing(int32_t index, Thing* thing) { } } -void Container::addItemBack(Item* item) { +void Container::addItemBack(std::shared_ptr item) { addItem(item); updateItemWeight(item->getWeight()); @@ -662,13 +662,13 @@ void Container::addItemBack(Item* item) { } } -void Container::updateThing(Thing* thing, uint16_t itemId, uint32_t count) { +void Container::updateThing(std::shared_ptr thing, uint16_t itemId, uint32_t count) { int32_t index = getThingIndex(thing); if (index == -1) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item == nullptr) { return /*RETURNVALUE_NOTPOSSIBLE*/; } @@ -684,19 +684,19 @@ void Container::updateThing(Thing* thing, uint16_t itemId, uint32_t count) { } } -void Container::replaceThing(uint32_t index, Thing* thing) { - Item* item = thing->getItem(); +void Container::replaceThing(uint32_t index, std::shared_ptr thing) { + std::shared_ptr item = thing->getItem(); if (!item) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - Item* replacedItem = getItemByIndex(index); + std::shared_ptr replacedItem = getItemByIndex(index); if (!replacedItem) { return /*RETURNVALUE_NOTPOSSIBLE*/; } itemlist[index] = item; - item->setParent(this); + item->setParent(getContainer()); updateItemWeight(-static_cast(replacedItem->getWeight()) + item->getWeight()); // send change to client @@ -707,8 +707,8 @@ void Container::replaceThing(uint32_t index, Thing* thing) { replacedItem->setParent(nullptr); } -void Container::removeThing(Thing* thing, uint32_t count) { - Item* item = thing->getItem(); +void Container::removeThing(std::shared_ptr thing, uint32_t count) { + std::shared_ptr item = thing->getItem(); if (item == nullptr) { return /*RETURNVALUE_NOTPOSSIBLE*/; } @@ -741,9 +741,9 @@ void Container::removeThing(Thing* thing, uint32_t count) { } } -int32_t Container::getThingIndex(const Thing* thing) const { +int32_t Container::getThingIndex(std::shared_ptr thing) const { int32_t index = 0; - for (Item* item : itemlist) { + for (std::shared_ptr item : itemlist) { if (item == thing) { return index; } @@ -762,7 +762,7 @@ size_t Container::getLastIndex() const { uint32_t Container::getItemTypeCount(uint16_t itemId, int32_t subType /* = -1*/) const { uint32_t count = 0; - for (Item* item : itemlist) { + for (std::shared_ptr item : itemlist) { if (item->getID() == itemId) { count += countByType(item, subType); } @@ -771,35 +771,35 @@ uint32_t Container::getItemTypeCount(uint16_t itemId, int32_t subType /* = -1*/) } std::map &Container::getAllItemTypeCount(std::map &countMap) const { - for (Item* item : itemlist) { + for (std::shared_ptr item : itemlist) { countMap[item->getID()] += item->getItemCount(); } return countMap; } -Thing* Container::getThing(size_t index) const { +std::shared_ptr Container::getThing(size_t index) const { return getItemByIndex(index); } -ItemVector Container::getItems(bool recursive /*= false*/) const { +ItemVector Container::getItems(bool recursive /*= false*/) { ItemVector containerItems; if (recursive) { for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { containerItems.push_back(*it); } } else { - for (Item* item : itemlist) { + for (std::shared_ptr item : itemlist) { containerItems.push_back(item); } } return containerItems; } -void Container::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t) { - Cylinder* topParent = getTopParent(); +void Container::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { + std::shared_ptr topParent = getTopParent(); if (topParent->getCreature()) { topParent->postAddNotification(thing, oldParent, index, LINK_TOPPARENT); - } else if (topParent == this) { + } else if (topParent == getContainer()) { // let the tile class notify surrounding players if (topParent->getParent()) { topParent->getParent()->postAddNotification(thing, oldParent, index, LINK_NEAR); @@ -809,11 +809,11 @@ void Container::postAddNotification(Thing* thing, const Cylinder* oldParent, int } } -void Container::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t) { - Cylinder* topParent = getTopParent(); +void Container::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { + std::shared_ptr topParent = getTopParent(); if (topParent->getCreature()) { topParent->postRemoveNotification(thing, newParent, index, LINK_TOPPARENT); - } else if (topParent == this) { + } else if (topParent == getContainer()) { // let the tile class notify surrounding players if (topParent->getParent()) { topParent->getParent()->postRemoveNotification(thing, newParent, index, LINK_NEAR); @@ -823,44 +823,44 @@ void Container::postRemoveNotification(Thing* thing, const Cylinder* newParent, } } -void Container::internalAddThing(Thing* thing) { +void Container::internalAddThing(std::shared_ptr thing) { internalAddThing(0, thing); } -void Container::internalAddThing(uint32_t, Thing* thing) { +void Container::internalAddThing(uint32_t, std::shared_ptr thing) { if (!thing) { return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item == nullptr) { return; } - item->setParent(this); + item->setParent(getContainer()); itemlist.push_front(item); updateItemWeight(item->getWeight()); } void Container::startDecaying() { - g_decay().startDecay(this); + g_decay().startDecay(getContainer()); for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { g_decay().startDecay(*it); } } void Container::stopDecaying() { - g_decay().stopDecay(this); + g_decay().stopDecay(getContainer()); for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { g_decay().stopDecay(*it); } } -uint16_t Container::getFreeSlots() const { +uint16_t Container::getFreeSlots() { uint16_t counter = std::max(0, capacity() - size()); - for (Item* item : itemlist) { - if (Container* container = item->getContainer()) { + for (std::shared_ptr item : itemlist) { + if (std::shared_ptr container = item->getContainer()) { counter += std::max(0, container->getFreeSlots()); } } @@ -868,16 +868,16 @@ uint16_t Container::getFreeSlots() const { return counter; } -ContainerIterator Container::iterator() const { +ContainerIterator Container::iterator() { ContainerIterator cit; if (!itemlist.empty()) { - cit.over.push_back(this); + cit.over.push_back(getContainer()); cit.cur = itemlist.begin(); } return cit; } -void Container::removeItem(Thing* thing, bool sendUpdateToClient /* = false*/) { +void Container::removeItem(std::shared_ptr thing, bool sendUpdateToClient /* = false*/) { if (thing == nullptr) { return; } @@ -899,13 +899,13 @@ void Container::removeItem(Thing* thing, bool sendUpdateToClient /* = false*/) { } } -Item* ContainerIterator::operator*() { +std::shared_ptr ContainerIterator::operator*() { return *cur; } void ContainerIterator::advance() { - if (Item* i = *cur) { - if (Container* c = i->getContainer()) { + if (std::shared_ptr i = *cur) { + if (std::shared_ptr c = i->getContainer()) { if (!c->empty()) { over.push_back(c); } diff --git a/src/items/containers/container.hpp b/src/items/containers/container.hpp index b58929b3628..3d50dff6c62 100644 --- a/src/items/containers/container.hpp +++ b/src/items/containers/container.hpp @@ -26,10 +26,10 @@ class ContainerIterator { } void advance(); - Item* operator*(); + std::shared_ptr operator*(); private: - std::list over; + std::list> over; ItemDeque::const_iterator cur; friend class Container; @@ -39,42 +39,30 @@ class Container : public Item, public Cylinder { public: explicit Container(uint16_t type); Container(uint16_t type, uint16_t size, bool unlocked = true, bool pagination = false); - explicit Container(Tile* type); + explicit Container(std::shared_ptr type); ~Container(); // non-copyable Container(const Container &) = delete; Container &operator=(const Container &) = delete; - Item* clone() const override final; + std::shared_ptr clone() const override final; - Container* getContainer() override final { - return this; - } - const Container* getContainer() const override final { - return this; + std::shared_ptr getContainer() override final { + return static_self_cast(); } - Container* getRootContainer() const; + std::shared_ptr getRootContainer(); - virtual DepotLocker* getDepotLocker() { - return nullptr; - } - virtual const DepotLocker* getDepotLocker() const { + virtual std::shared_ptr getDepotLocker() { return nullptr; } - virtual RewardChest* getRewardChest() { - return nullptr; - } - virtual const RewardChest* getRewardChest() const { + virtual std::shared_ptr getRewardChest() { return nullptr; } - virtual Reward* getReward() { - return nullptr; - } - virtual const Reward* getReward() const { + virtual std::shared_ptr getReward() { return nullptr; } virtual bool isInbox() const { @@ -86,7 +74,7 @@ class Container : public Item, public Cylinder { Attr_ReadValue readAttr(AttrTypes_t attr, PropStream &propStream) override; bool unserializeItemNode(OTB::Loader &loader, const OTB::Node &node, PropStream &propStream, Position &itemPosition) override; - std::string getContentDescription(bool oldProtocol) const; + std::string getContentDescription(bool oldProtocol); size_t size() const { return itemlist.size(); @@ -98,7 +86,7 @@ class Container : public Item, public Cylinder { return maxSize; } - ContainerIterator iterator() const; + ContainerIterator iterator(); const ItemDeque &getItemList() const { return itemlist; @@ -113,20 +101,20 @@ class Container : public Item, public Cylinder { bool countsToLootAnalyzerBalance(); bool hasParent() const; - void addItem(Item* item); + void addItem(std::shared_ptr item); StashContainerList getStowableItems() const; bool isStoreInbox() const; bool isStoreInboxFiltered() const; - std::deque getStoreInboxFilteredItems() const; + std::deque> getStoreInboxFilteredItems() const; phmap::flat_hash_set getStoreInboxValidCategories() const; - Item* getFilteredItemByIndex(size_t index) const; - Item* getItemByIndex(size_t index) const; - bool isHoldingItem(const Item* item) const; - bool isHoldingItemWithId(const uint16_t id) const; - - uint32_t getItemHoldingCount() const; - uint32_t getContainerHoldingCount() const; - uint16_t getFreeSlots() const; + std::shared_ptr getFilteredItemByIndex(size_t index) const; + std::shared_ptr getItemByIndex(size_t index) const; + bool isHoldingItem(std::shared_ptr item); + bool isHoldingItemWithId(const uint16_t id); + + uint32_t getItemHoldingCount(); + uint32_t getContainerHoldingCount(); + uint16_t getFreeSlots(); uint32_t getWeight() const override final; bool isUnlocked() const { @@ -137,41 +125,41 @@ class Container : public Item, public Cylinder { } // cylinder implementations - virtual ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; - ReturnValue queryMaxCount(int32_t index, const Thing &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) const override final; - ReturnValue queryRemove(const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override final; - Cylinder* queryDestination(int32_t &index, const Thing &thing, Item** destItem, uint32_t &flags) override final; + virtual ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; + ReturnValue queryMaxCount(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) override final; + ReturnValue queryRemove(const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override final; + std::shared_ptr queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &flags) override final; - void addThing(Thing* thing) override final; - void addThing(int32_t index, Thing* thing) override final; - void addItemBack(Item* item); + void addThing(std::shared_ptr thing) override final; + void addThing(int32_t index, std::shared_ptr thing) override final; + void addItemBack(std::shared_ptr item); - void updateThing(Thing* thing, uint16_t itemId, uint32_t count) override final; - void replaceThing(uint32_t index, Thing* thing) override final; + void updateThing(std::shared_ptr thing, uint16_t itemId, uint32_t count) override final; + void replaceThing(uint32_t index, std::shared_ptr thing) override final; - void removeThing(Thing* thing, uint32_t count) override final; + void removeThing(std::shared_ptr thing, uint32_t count) override final; - int32_t getThingIndex(const Thing* thing) const override final; + int32_t getThingIndex(std::shared_ptr thing) const override final; size_t getFirstIndex() const override final; size_t getLastIndex() const override final; uint32_t getItemTypeCount(uint16_t itemId, int32_t subType = -1) const override final; std::map &getAllItemTypeCount(std::map &countMap) const override final; - Thing* getThing(size_t index) const override final; + std::shared_ptr getThing(size_t index) const override final; - ItemVector getItems(bool recursive = false) const; + ItemVector getItems(bool recursive = false); - void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; - void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; - void internalAddThing(Thing* thing) override final; - void internalAddThing(uint32_t index, Thing* thing) override final; + void internalAddThing(std::shared_ptr thing) override final; + void internalAddThing(uint32_t index, std::shared_ptr thing) override final; void startDecaying() override; void stopDecaying() override; - virtual void removeItem(Thing* thing, bool sendUpdateToClient = false); + virtual void removeItem(std::shared_ptr thing, bool sendUpdateToClient = false); protected: - std::ostringstream &getContentDescription(std::ostringstream &os, bool oldProtocol) const; + std::ostringstream &getContentDescription(std::ostringstream &os, bool oldProtocol); uint32_t m_maxItems; uint32_t maxSize; @@ -185,12 +173,12 @@ class Container : public Item, public Cylinder { friend class MapCache; private: - void onAddContainerItem(Item* item); - void onUpdateContainerItem(uint32_t index, Item* oldItem, Item* newItem); - void onRemoveContainerItem(uint32_t index, Item* item); + void onAddContainerItem(std::shared_ptr item); + void onUpdateContainerItem(uint32_t index, std::shared_ptr oldItem, std::shared_ptr newItem); + void onRemoveContainerItem(uint32_t index, std::shared_ptr item); - Container* getParentContainer(); - Container* getTopParentContainer() const; + std::shared_ptr getParentContainer(); + std::shared_ptr getTopParentContainer(); void updateItemWeight(int32_t diff); friend class ContainerIterator; diff --git a/src/items/containers/depot/depotchest.cpp b/src/items/containers/depot/depotchest.cpp index 2e116d90ff6..b3edfbd82ac 100644 --- a/src/items/containers/depot/depotchest.cpp +++ b/src/items/containers/depot/depotchest.cpp @@ -19,8 +19,8 @@ DepotChest::DepotChest(uint16_t type) : pagination = true; } -ReturnValue DepotChest::queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor /* = nullptr*/) const { - const Item* item = thing.getItem(); +ReturnValue DepotChest::queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor /* = nullptr*/) { + std::shared_ptr item = thing->getItem(); if (item == nullptr) { return RETURNVALUE_NOTPOSSIBLE; } @@ -33,15 +33,15 @@ ReturnValue DepotChest::queryAdd(int32_t index, const Thing &thing, uint32_t cou addCount = 1; } - if (item->getTopParent() != this) { - if (const Container* container = item->getContainer()) { + if (item->getTopParent().get() != this) { + if (std::shared_ptr container = item->getContainer()) { addCount = container->getItemHoldingCount() + 1; } else { addCount = 1; } } - if (Cylinder* localParent = getRealParent()) { + if (std::shared_ptr localParent = getRealParent()) { if (localParent->getContainer()->getItemHoldingCount() + addCount > maxDepotItems) { return RETURNVALUE_DEPOTISFULL; } @@ -53,21 +53,21 @@ ReturnValue DepotChest::queryAdd(int32_t index, const Thing &thing, uint32_t cou return Container::queryAdd(index, thing, count, flags, actor); } -void DepotChest::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t) { - Cylinder* localParent = getParent(); +void DepotChest::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { + std::shared_ptr localParent = getParent(); if (localParent != nullptr) { localParent->postAddNotification(thing, oldParent, index, LINK_PARENT); } } -void DepotChest::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t) { - Cylinder* localParent = getParent(); +void DepotChest::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { + std::shared_ptr localParent = getParent(); if (localParent != nullptr) { localParent->postRemoveNotification(thing, newParent, index, LINK_PARENT); } } -Cylinder* DepotChest::getParent() const { +std::shared_ptr DepotChest::getParent() const { if (parent && parent->getParent()) { return parent->getParent()->getParent(); } diff --git a/src/items/containers/depot/depotchest.hpp b/src/items/containers/depot/depotchest.hpp index 001e63d2e60..8cded7616fb 100644 --- a/src/items/containers/depot/depotchest.hpp +++ b/src/items/containers/depot/depotchest.hpp @@ -21,10 +21,10 @@ class DepotChest final : public Container { } // cylinder implementations - ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; + ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; - void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; - void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; bool isDepotChest() const override { return true; @@ -38,8 +38,8 @@ class DepotChest final : public Container { return false; } - Cylinder* getParent() const override; - Cylinder* getRealParent() const override { + std::shared_ptr getParent() const override; + std::shared_ptr getRealParent() const override { return parent; } diff --git a/src/items/containers/depot/depotlocker.cpp b/src/items/containers/depot/depotlocker.cpp index e0954284599..cfa40b8e833 100644 --- a/src/items/containers/depot/depotlocker.cpp +++ b/src/items/containers/depot/depotlocker.cpp @@ -24,23 +24,23 @@ Attr_ReadValue DepotLocker::readAttr(AttrTypes_t attr, PropStream &propStream) { return Item::readAttr(attr, propStream); } -ReturnValue DepotLocker::queryAdd(int32_t, const Thing &, uint32_t, uint32_t, Creature*) const { +ReturnValue DepotLocker::queryAdd(int32_t, const std::shared_ptr &, uint32_t, uint32_t, std::shared_ptr) { return RETURNVALUE_NOTENOUGHROOM; } -void DepotLocker::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t) { +void DepotLocker::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { if (parent != nullptr) { parent->postAddNotification(thing, oldParent, index, LINK_PARENT); } } -void DepotLocker::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t) { +void DepotLocker::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { if (parent != nullptr) { parent->postRemoveNotification(thing, newParent, index, LINK_PARENT); } } -void DepotLocker::removeInbox(Inbox* inbox) { +void DepotLocker::removeInbox(std::shared_ptr inbox) { auto cit = std::find(itemlist.begin(), itemlist.end(), inbox); if (cit == itemlist.end()) { return; diff --git a/src/items/containers/depot/depotlocker.hpp b/src/items/containers/depot/depotlocker.hpp index 4cf9b127be3..aac143ccf0a 100644 --- a/src/items/containers/depot/depotlocker.hpp +++ b/src/items/containers/depot/depotlocker.hpp @@ -16,14 +16,11 @@ class DepotLocker final : public Container { public: explicit DepotLocker(uint16_t type, uint16_t size); - DepotLocker* getDepotLocker() override { - return this; - } - const DepotLocker* getDepotLocker() const override { - return this; + std::shared_ptr getDepotLocker() override { + return static_self_cast(); } - void removeInbox(Inbox* inbox); + void removeInbox(std::shared_ptr inbox); // serialization Attr_ReadValue readAttr(AttrTypes_t attr, PropStream &propStream) override; @@ -36,10 +33,10 @@ class DepotLocker final : public Container { } // cylinder implementations - ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; + ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; - void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; - void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; bool canRemove() const override { return false; diff --git a/src/items/containers/inbox/inbox.cpp b/src/items/containers/inbox/inbox.cpp index 126b4ea35b2..d18ee024362 100644 --- a/src/items/containers/inbox/inbox.cpp +++ b/src/items/containers/inbox/inbox.cpp @@ -17,19 +17,19 @@ Inbox::Inbox(uint16_t type) : maxInboxItems = std::numeric_limits::max(); } -ReturnValue Inbox::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t flags, Creature*) const { +ReturnValue Inbox::queryAdd(int32_t, const std::shared_ptr &thing, uint32_t, uint32_t flags, std::shared_ptr) { int32_t addCount = 0; if (!hasBitSet(FLAG_NOLIMIT, flags)) { return RETURNVALUE_CONTAINERNOTENOUGHROOM; } - const Item* item = thing.getItem(); + std::shared_ptr item = thing->getItem(); if (!item) { return RETURNVALUE_NOTPOSSIBLE; } - if (item == this) { + if (item.get() == this) { return RETURNVALUE_THISISIMPOSSIBLE; } @@ -37,8 +37,8 @@ ReturnValue Inbox::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t flag return RETURNVALUE_CANNOTPICKUP; } - if (item->getTopParent() != this) { // MY - if (const Container* container = item->getContainer()) { + if (item->getTopParent().get() != this) { // MY + if (std::shared_ptr container = item->getContainer()) { addCount = container->getItemHoldingCount() + 1; } else { addCount = 1; @@ -52,21 +52,21 @@ ReturnValue Inbox::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t flag return RETURNVALUE_NOERROR; } -void Inbox::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t) { - Cylinder* localParent = getParent(); +void Inbox::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { + std::shared_ptr localParent = getParent(); if (localParent != nullptr) { localParent->postAddNotification(thing, oldParent, index, LINK_PARENT); } } -void Inbox::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t) { - Cylinder* localParent = getParent(); +void Inbox::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { + std::shared_ptr localParent = getParent(); if (localParent != nullptr) { localParent->postRemoveNotification(thing, newParent, index, LINK_PARENT); } } -Cylinder* Inbox::getParent() const { +std::shared_ptr Inbox::getParent() const { if (parent) { return parent->getParent(); } diff --git a/src/items/containers/inbox/inbox.hpp b/src/items/containers/inbox/inbox.hpp index b58f03d6768..be7d74885fc 100644 --- a/src/items/containers/inbox/inbox.hpp +++ b/src/items/containers/inbox/inbox.hpp @@ -20,10 +20,10 @@ class Inbox final : public Container { } // cylinder implementations - ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; + ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; - void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; - void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; bool isInbox() const override { return true; @@ -37,8 +37,8 @@ class Inbox final : public Container { return false; } - Cylinder* getParent() const override; - Cylinder* getRealParent() const override { + std::shared_ptr getParent() const override; + std::shared_ptr getRealParent() const override { return parent; } diff --git a/src/items/containers/mailbox/mailbox.cpp b/src/items/containers/mailbox/mailbox.cpp index af3b79eae13..bfc732939e0 100644 --- a/src/items/containers/mailbox/mailbox.cpp +++ b/src/items/containers/mailbox/mailbox.cpp @@ -13,63 +13,63 @@ #include "game/game.hpp" #include "io/iologindata.hpp" -ReturnValue Mailbox::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t, Creature*) const { - const Item* item = thing.getItem(); +ReturnValue Mailbox::queryAdd(int32_t, const std::shared_ptr &thing, uint32_t, uint32_t, std::shared_ptr) { + std::shared_ptr item = thing->getItem(); if (item && Mailbox::canSend(item)) { return RETURNVALUE_NOERROR; } return RETURNVALUE_NOTPOSSIBLE; } -ReturnValue Mailbox::queryMaxCount(int32_t, const Thing &, uint32_t count, uint32_t &maxQueryCount, uint32_t) const { +ReturnValue Mailbox::queryMaxCount(int32_t, const std::shared_ptr &, uint32_t count, uint32_t &maxQueryCount, uint32_t) { maxQueryCount = std::max(1, count); return RETURNVALUE_NOERROR; } -ReturnValue Mailbox::queryRemove(const Thing &, uint32_t, uint32_t, Creature* /*= nullptr */) const { +ReturnValue Mailbox::queryRemove(const std::shared_ptr &, uint32_t, uint32_t, std::shared_ptr /*= nullptr */) { return RETURNVALUE_NOTPOSSIBLE; } -Cylinder* Mailbox::queryDestination(int32_t &, const Thing &, Item**, uint32_t &) { - return this; +std::shared_ptr Mailbox::queryDestination(int32_t &, const std::shared_ptr &, std::shared_ptr*, uint32_t &) { + return getMailbox(); } -void Mailbox::addThing(Thing* thing) { +void Mailbox::addThing(std::shared_ptr thing) { return addThing(0, thing); } -void Mailbox::addThing(int32_t, Thing* thing) { +void Mailbox::addThing(int32_t, std::shared_ptr thing) { if (!thing) { return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item && Mailbox::canSend(item)) { sendItem(item); } } -void Mailbox::updateThing(Thing*, uint16_t, uint32_t) { +void Mailbox::updateThing(std::shared_ptr, uint16_t, uint32_t) { // } -void Mailbox::replaceThing(uint32_t, Thing*) { +void Mailbox::replaceThing(uint32_t, std::shared_ptr) { // } -void Mailbox::removeThing(Thing*, uint32_t) { +void Mailbox::removeThing(std::shared_ptr, uint32_t) { // } -void Mailbox::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t) { +void Mailbox::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { getParent()->postAddNotification(thing, oldParent, index, LINK_PARENT); } -void Mailbox::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t) { +void Mailbox::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { getParent()->postRemoveNotification(thing, newParent, index, LINK_PARENT); } -bool Mailbox::sendItem(Item* item) const { +bool Mailbox::sendItem(std::shared_ptr item) const { std::string receiver; if (!getReceiver(item, receiver)) { return false; @@ -83,14 +83,14 @@ bool Mailbox::sendItem(Item* item) const { if (item && item->getContainer() && item->getTile()) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, item->getTile()->getPosition(), false, true); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { if (spectator && spectator->getPlayer()) { spectator->getPlayer()->autoCloseContainers(item->getContainer()); } } } - Player* player = g_game().getPlayerByName(receiver, true); + std::shared_ptr player = g_game().getPlayerByName(receiver, true); std::string writer; time_t date = time(0); std::string text; @@ -101,7 +101,7 @@ bool Mailbox::sendItem(Item* item) const { } if (player && item) { if (g_game().internalMoveItem(item->getParent(), player->getInbox(), INDEX_WHEREEVER, item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) { - Item* newItem = g_game().transformItem(item, item->getID() + 1); + auto newItem = g_game().transformItem(item, item->getID() + 1); if (newItem && newItem->getID() == ITEM_LETTER_STAMPED && writer != "") { newItem->setAttribute(ItemAttribute_t::WRITER, writer); newItem->setAttribute(ItemAttribute_t::DATE, date); @@ -111,7 +111,6 @@ bool Mailbox::sendItem(Item* item) const { player->onReceiveMail(); } else { IOLoginData::savePlayer(player); - delete player; } return true; } @@ -119,10 +118,10 @@ bool Mailbox::sendItem(Item* item) const { return false; } -bool Mailbox::getReceiver(Item* item, std::string &name) const { - const Container* container = item->getContainer(); +bool Mailbox::getReceiver(std::shared_ptr item, std::string &name) const { + std::shared_ptr container = item->getContainer(); if (container) { - for (Item* containerItem : container->getItemList()) { + for (std::shared_ptr containerItem : container->getItemList()) { if (containerItem->getID() == ITEM_LABEL && getReceiver(containerItem, name)) { return true; } @@ -140,6 +139,6 @@ bool Mailbox::getReceiver(Item* item, std::string &name) const { return true; } -bool Mailbox::canSend(const Item* item) { +bool Mailbox::canSend(std::shared_ptr item) { return item->getID() == ITEM_PARCEL || item->getID() == ITEM_LETTER; } diff --git a/src/items/containers/mailbox/mailbox.hpp b/src/items/containers/mailbox/mailbox.hpp index bf22096d0d4..3d57c72b5ef 100644 --- a/src/items/containers/mailbox/mailbox.hpp +++ b/src/items/containers/mailbox/mailbox.hpp @@ -17,33 +17,30 @@ class Mailbox final : public Item, public Cylinder { explicit Mailbox(uint16_t itemId) : Item(itemId) { } - Mailbox* getMailbox() override { - return this; - } - const Mailbox* getMailbox() const override { - return this; + std::shared_ptr getMailbox() override { + return static_self_cast(); } // cylinder implementations - ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; - ReturnValue queryMaxCount(int32_t index, const Thing &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) const override; - ReturnValue queryRemove(const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; - Cylinder* queryDestination(int32_t &index, const Thing &thing, Item** destItem, uint32_t &flags) override; + ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; + ReturnValue queryMaxCount(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) override; + ReturnValue queryRemove(const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; + std::shared_ptr queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &flags) override; - void addThing(Thing* thing) override; - void addThing(int32_t index, Thing* thing) override; + void addThing(std::shared_ptr thing) override; + void addThing(int32_t index, std::shared_ptr thing) override; - void updateThing(Thing* thing, uint16_t itemId, uint32_t count) override; - void replaceThing(uint32_t index, Thing* thing) override; + void updateThing(std::shared_ptr thing, uint16_t itemId, uint32_t count) override; + void replaceThing(uint32_t index, std::shared_ptr thing) override; - void removeThing(Thing* thing, uint32_t count) override; + void removeThing(std::shared_ptr thing, uint32_t count) override; - void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; - void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; private: - bool getReceiver(Item* item, std::string &name) const; - bool sendItem(Item* item) const; + bool getReceiver(std::shared_ptr item, std::string &name) const; + bool sendItem(std::shared_ptr item) const; - static bool canSend(const Item* item); + static bool canSend(std::shared_ptr item); }; diff --git a/src/items/containers/rewards/reward.cpp b/src/items/containers/rewards/reward.cpp index 7dac4a71969..2170400bcc5 100644 --- a/src/items/containers/rewards/reward.cpp +++ b/src/items/containers/rewards/reward.cpp @@ -18,17 +18,17 @@ Reward::Reward() : pagination = true; } -ReturnValue Reward::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t, Creature* actor /* = nullptr*/) const { +ReturnValue Reward::queryAdd(int32_t, const std::shared_ptr &thing, uint32_t, uint32_t, std::shared_ptr actor /* = nullptr*/) { if (actor) { return RETURNVALUE_NOTPOSSIBLE; } - const Item* item = thing.getItem(); + std::shared_ptr item = thing->getItem(); if (!item) { return RETURNVALUE_NOTPOSSIBLE; } - if (item == this) { + if (item.get() == this) { return RETURNVALUE_THISISIMPOSSIBLE; } @@ -39,20 +39,20 @@ ReturnValue Reward::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t, Cr return RETURNVALUE_NOERROR; } -void Reward::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t) { - Cylinder* localParent = getParent(); +void Reward::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { + std::shared_ptr localParent = getParent(); if (localParent != nullptr) { localParent->postAddNotification(thing, oldParent, index, LINK_PARENT); } } -void Reward::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t) { - Cylinder* localParent = getParent(); +void Reward::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { + std::shared_ptr localParent = getParent(); if (localParent != nullptr) { localParent->postRemoveNotification(thing, newParent, index, LINK_PARENT); } } -Cylinder* Reward::getParent() const { +std::shared_ptr Reward::getParent() const { return parent; } diff --git a/src/items/containers/rewards/reward.hpp b/src/items/containers/rewards/reward.hpp index 8bc6ae2740b..d231f8a0a80 100644 --- a/src/items/containers/rewards/reward.hpp +++ b/src/items/containers/rewards/reward.hpp @@ -15,26 +15,23 @@ class Reward : public Container { public: explicit Reward(); - Reward* getReward() final { - return this; - } - const Reward* getReward() const final { - return this; + std::shared_ptr getReward() final { + return static_self_cast(); } // cylinder implementations - ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const final; + ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) final; - void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) final; - void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link = LINK_OWNER) final; + void postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) final; + void postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link = LINK_OWNER) final; // overrides bool canRemove() const final { return true; } - Cylinder* getParent() const final; - Cylinder* getRealParent() const final { + std::shared_ptr getParent() const final; + std::shared_ptr getRealParent() const final { return parent; } }; diff --git a/src/items/containers/rewards/rewardchest.cpp b/src/items/containers/rewards/rewardchest.cpp index 0ed966d7810..2b02421cdfd 100644 --- a/src/items/containers/rewards/rewardchest.cpp +++ b/src/items/containers/rewards/rewardchest.cpp @@ -18,7 +18,7 @@ RewardChest::RewardChest(uint16_t type) : pagination = true; } -ReturnValue RewardChest::queryAdd(int32_t, const Thing &, uint32_t, uint32_t, Creature* actor /* = nullptr*/) const { +ReturnValue RewardChest::queryAdd(int32_t, const std::shared_ptr &, uint32_t, uint32_t, std::shared_ptr actor /* = nullptr*/) { if (actor) { return RETURNVALUE_NOTPOSSIBLE; } @@ -26,20 +26,20 @@ ReturnValue RewardChest::queryAdd(int32_t, const Thing &, uint32_t, uint32_t, Cr return RETURNVALUE_NOERROR; } -void RewardChest::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t) { +void RewardChest::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { if (parent != nullptr) { parent->postAddNotification(thing, oldParent, index, LINK_PARENT); } } -void RewardChest::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t) { +void RewardChest::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { if (parent != nullptr) { parent->postRemoveNotification(thing, newParent, index, LINK_PARENT); } } // Second argument is disabled by default because not need to send to client in the RewardChest -void RewardChest::removeItem(Thing* thing, bool /* sendToClient = false*/) { +void RewardChest::removeItem(std::shared_ptr thing, bool /* sendToClient = false*/) { if (thing == nullptr) { return; } diff --git a/src/items/containers/rewards/rewardchest.hpp b/src/items/containers/rewards/rewardchest.hpp index 6f09d85795b..295eafc06df 100644 --- a/src/items/containers/rewards/rewardchest.hpp +++ b/src/items/containers/rewards/rewardchest.hpp @@ -15,22 +15,19 @@ class RewardChest final : public Container { public: explicit RewardChest(uint16_t type); - RewardChest* getRewardChest() final { - return this; - } - const RewardChest* getRewardChest() const final { - return this; + std::shared_ptr getRewardChest() final { + return static_self_cast(); } // cylinder implementations - ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const final; + ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) final; - void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) final; - void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link = LINK_OWNER) final; + void postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) final; + void postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link = LINK_OWNER) final; bool canRemove() const final { return false; } - void removeItem(Thing* thing, bool sendToClient = false) override; + void removeItem(std::shared_ptr thing, bool sendToClient = false) override; }; diff --git a/src/items/cylinder.cpp b/src/items/cylinder.cpp index e88bc1a0c5b..c328b1fbd8d 100644 --- a/src/items/cylinder.cpp +++ b/src/items/cylinder.cpp @@ -11,9 +11,9 @@ #include "items/cylinder.hpp" -VirtualCylinder* VirtualCylinder::virtualCylinder = new VirtualCylinder; +std::shared_ptr VirtualCylinder::virtualCylinder = std::make_shared(); -int32_t Cylinder::getThingIndex(const Thing*) const { +int32_t Cylinder::getThingIndex(std::shared_ptr) const { return -1; } @@ -33,15 +33,15 @@ std::map &Cylinder::getAllItemTypeCount(std::map Cylinder::getThing(size_t) const { return nullptr; } -void Cylinder::internalAddThing(Thing*) { +void Cylinder::internalAddThing(std::shared_ptr) { // } -void Cylinder::internalAddThing(uint32_t, Thing*) { +void Cylinder::internalAddThing(uint32_t, std::shared_ptr) { // } diff --git a/src/items/cylinder.hpp b/src/items/cylinder.hpp index f0d1b14231a..424060b3b2e 100644 --- a/src/items/cylinder.hpp +++ b/src/items/cylinder.hpp @@ -30,7 +30,7 @@ class Cylinder : virtual public Thing { * \param actor the creature trying to add the thing * \returns ReturnValue holds the return value */ - virtual ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const = 0; + virtual ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) = 0; /** * Query the cylinder how much it can accept @@ -42,7 +42,7 @@ class Cylinder : virtual public Thing { * \param flags optional flags to modify the default behaviour * \returns ReturnValue holds the return value */ - virtual ReturnValue queryMaxCount(int32_t index, const Thing &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) const = 0; + virtual ReturnValue queryMaxCount(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) = 0; /** * Query if the cylinder can remove an object @@ -51,7 +51,7 @@ class Cylinder : virtual public Thing { * \param flags optional flags to modify the default behaviour * \returns ReturnValue holds the return value */ - virtual ReturnValue queryRemove(const Thing &thing, uint32_t count, uint32_t flags, Creature* = nullptr) const = 0; + virtual ReturnValue queryRemove(const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr = nullptr) = 0; /** * Query the destination cylinder @@ -63,20 +63,20 @@ class Cylinder : virtual public Thing { * this method can modify the flags * \returns Cylinder returns the destination cylinder */ - virtual Cylinder* queryDestination(int32_t &index, const Thing &thing, Item** destItem, uint32_t &flags) = 0; + virtual std::shared_ptr queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &flags) = 0; /** * Add the object to the cylinder * \param thing is the object to add */ - virtual void addThing(Thing* thing) = 0; + virtual void addThing(std::shared_ptr thing) = 0; /** * Add the object to the cylinder * \param index points to the destination index (inventory slot/container position) * \param thing is the object to add */ - virtual void addThing(int32_t index, Thing* thing) = 0; + virtual void addThing(int32_t index, std::shared_ptr thing) = 0; /** * Update the item count or type for an object @@ -84,21 +84,21 @@ class Cylinder : virtual public Thing { * \param itemId is the new item id * \param count is the new count value */ - virtual void updateThing(Thing* thing, uint16_t itemId, uint32_t count) = 0; + virtual void updateThing(std::shared_ptr thing, uint16_t itemId, uint32_t count) = 0; /** * Replace an object with a new * \param index is the position to change (inventory slot/container position) * \param thing is the object to update */ - virtual void replaceThing(uint32_t index, Thing* thing) = 0; + virtual void replaceThing(uint32_t index, std::shared_ptr thing) = 0; /** * Remove an object * \param thing is the object to delete * \param count is the new count value */ - virtual void removeThing(Thing* thing, uint32_t count) = 0; + virtual void removeThing(std::shared_ptr thing, uint32_t count) = 0; /** * Is sent after an operation (move/add) to update internal values @@ -106,7 +106,7 @@ class Cylinder : virtual public Thing { * \param index is the objects new index value * \param link holds the relation the object has to the cylinder */ - virtual void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) = 0; + virtual void postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) = 0; /** * Is sent after an operation (move/remove) to update internal values @@ -114,14 +114,14 @@ class Cylinder : virtual public Thing { * \param index is the previous index of the removed object * \param link holds the relation the object has to the cylinder */ - virtual void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link = LINK_OWNER) = 0; + virtual void postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link = LINK_OWNER) = 0; /** * Gets the index of an object * \param thing the object to get the index value from * \returns the index of the object, returns -1 if not found */ - virtual int32_t getThingIndex(const Thing* thing) const; + virtual int32_t getThingIndex(std::shared_ptr thing) const; /** * Returns the first index @@ -139,7 +139,7 @@ class Cylinder : virtual public Thing { * Gets the object based on index * \returns the object, returns nullptr if not found */ - virtual Thing* getThing(size_t index) const; + virtual std::shared_ptr getThing(size_t index) const; /** * Get the amount of items of a certain type @@ -160,51 +160,51 @@ class Cylinder : virtual public Thing { * Adds an object to the cylinder without sending to the client(s) * \param thing is the object to add */ - virtual void internalAddThing(Thing* thing); + virtual void internalAddThing(std::shared_ptr thing); /** * Adds an object to the cylinder without sending to the client(s) * \param thing is the object to add * \param index points to the destination index (inventory slot/container position) */ - virtual void internalAddThing(uint32_t index, Thing* thing); + virtual void internalAddThing(uint32_t index, std::shared_ptr thing); virtual void startDecaying(); }; class VirtualCylinder final : public Cylinder { public: - static VirtualCylinder* virtualCylinder; + static std::shared_ptr virtualCylinder; - virtual ReturnValue queryAdd(int32_t, const Thing &, uint32_t, uint32_t, Creature* = nullptr) const override { + virtual ReturnValue queryAdd(int32_t, const std::shared_ptr &, uint32_t, uint32_t, std::shared_ptr = nullptr) override { return RETURNVALUE_NOTPOSSIBLE; } - virtual ReturnValue queryMaxCount(int32_t, const Thing &, uint32_t, uint32_t &, uint32_t) const override { + virtual ReturnValue queryMaxCount(int32_t, const std::shared_ptr &, uint32_t, uint32_t &, uint32_t) override { return RETURNVALUE_NOTPOSSIBLE; } - virtual ReturnValue queryRemove(const Thing &, uint32_t, uint32_t, Creature* = nullptr) const override { + virtual ReturnValue queryRemove(const std::shared_ptr &, uint32_t, uint32_t, std::shared_ptr = nullptr) override { return RETURNVALUE_NOTPOSSIBLE; } - virtual Cylinder* queryDestination(int32_t &, const Thing &, Item**, uint32_t &) override { + virtual std::shared_ptr queryDestination(int32_t &, const std::shared_ptr &, std::shared_ptr*, uint32_t &) override { return nullptr; } - virtual void addThing(Thing*) override { } - virtual void addThing(int32_t, Thing*) override { } - virtual void updateThing(Thing*, uint16_t, uint32_t) override { } - virtual void replaceThing(uint32_t, Thing*) override { } - virtual void removeThing(Thing*, uint32_t) override { } + virtual void addThing(std::shared_ptr) override { } + virtual void addThing(int32_t, std::shared_ptr) override { } + virtual void updateThing(std::shared_ptr, uint16_t, uint32_t) override { } + virtual void replaceThing(uint32_t, std::shared_ptr) override { } + virtual void removeThing(std::shared_ptr, uint32_t) override { } - virtual void postAddNotification(Thing*, const Cylinder*, int32_t, CylinderLink_t = LINK_OWNER) override { } - virtual void postRemoveNotification(Thing*, const Cylinder*, int32_t, CylinderLink_t = LINK_OWNER) override { } + virtual void postAddNotification(std::shared_ptr, std::shared_ptr, int32_t, CylinderLink_t = LINK_OWNER) override { } + virtual void postRemoveNotification(std::shared_ptr, std::shared_ptr, int32_t, CylinderLink_t = LINK_OWNER) override { } - bool isPushable() const override { + bool isPushable() override { return false; } int32_t getThrowRange() const override { return 1; } - std::string getDescription(int32_t) const override { + std::string getDescription(int32_t) override { return {}; } bool isRemoved() const override { diff --git a/src/items/decay/decay.cpp b/src/items/decay/decay.cpp index e08854c111a..ef655b74933 100644 --- a/src/items/decay/decay.cpp +++ b/src/items/decay/decay.cpp @@ -13,7 +13,7 @@ #include "game/game.hpp" #include "game/scheduling/scheduler.hpp" -void Decay::startDecay(Item* item) { +void Decay::startDecay(std::shared_ptr item) { if (!item) { return; } @@ -56,13 +56,13 @@ void Decay::startDecay(Item* item) { } } -void Decay::stopDecay(Item* item) { +void Decay::stopDecay(std::shared_ptr item) { if (item->hasAttribute(ItemAttribute_t::DECAYSTATE)) { auto timestamp = item->getAttribute(ItemAttribute_t::DURATION_TIMESTAMP); if (item->hasAttribute(ItemAttribute_t::DURATION_TIMESTAMP)) { auto it = decayMap.find(timestamp); if (it != decayMap.end()) { - std::vector &decayItems = it->second; + std::vector> &decayItems = it->second; size_t i = 0, end = decayItems.size(); if (end == 1) { @@ -104,7 +104,7 @@ void Decay::stopDecay(Item* item) { void Decay::checkDecay() { int64_t timestamp = OTSYS_TIME(); - std::vector tempItems; + std::vector> tempItems; tempItems.reserve(32); // Small preallocation auto it = decayMap.begin(), end = decayMap.end(); @@ -114,12 +114,12 @@ void Decay::checkDecay() { } // Iterating here is unsafe so let's copy our items into temporary vector - std::vector &decayItems = it->second; + std::vector> &decayItems = it->second; tempItems.insert(tempItems.end(), decayItems.begin(), decayItems.end()); it = decayMap.erase(it); } - for (Item* item : tempItems) { + for (std::shared_ptr item : tempItems) { if (!item->canDecay()) { item->setDuration(item->getDuration()); item->setDecaying(DECAYING_FALSE); @@ -136,10 +136,10 @@ void Decay::checkDecay() { } } -void Decay::internalDecayItem(Item* item) { +void Decay::internalDecayItem(std::shared_ptr item) { const ItemType &it = Item::items[item->getID()]; if (it.decayTo != 0) { - Player* player = item->getHoldingPlayer(); + std::shared_ptr player = item->getHoldingPlayer(); if (player) { bool needUpdateSkills = false; for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { diff --git a/src/items/decay/decay.hpp b/src/items/decay/decay.hpp index 9c3a39a6116..f5eb60d1542 100644 --- a/src/items/decay/decay.hpp +++ b/src/items/decay/decay.hpp @@ -22,15 +22,15 @@ class Decay { return inject(); } - void startDecay(Item* item); - void stopDecay(Item* item); + void startDecay(std::shared_ptr item); + void stopDecay(std::shared_ptr item); private: void checkDecay(); - void internalDecayItem(Item* item); + void internalDecayItem(std::shared_ptr item); uint32_t eventId { 0 }; - std::map> decayMap; + std::map>> decayMap; }; constexpr auto g_decay = Decay::getInstance; diff --git a/src/items/functions/item/item_parse.cpp b/src/items/functions/item/item_parse.cpp index 2172326f097..b1d70a0396f 100644 --- a/src/items/functions/item/item_parse.cpp +++ b/src/items/functions/item/item_parse.cpp @@ -705,7 +705,6 @@ void ItemParse::parseField(const std::string &tmpStrValue, pugi::xml_node attrib if (combatType != COMBAT_NONE) { if (conditionDamage) { - delete conditionDamage; } conditionDamage = new ConditionDamage(conditionId, conditionType); diff --git a/src/items/item.cpp b/src/items/item.cpp index c30794edc76..e75115520d9 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -28,8 +28,8 @@ Items Item::items; -Item* Item::CreateItem(const uint16_t type, uint16_t count /*= 0*/, Position* itemPosition /*= nullptr*/) { - Item* newItem = nullptr; +std::shared_ptr Item::CreateItem(const uint16_t type, uint16_t count /*= 0*/, Position* itemPosition /*= nullptr*/) { + std::shared_ptr newItem = nullptr; const ItemType &it = Item::items[type]; if (it.stackable && count == 0) { @@ -38,29 +38,29 @@ Item* Item::CreateItem(const uint16_t type, uint16_t count /*= 0*/, Position* it if (it.id != 0) { if (it.isDepot()) { - newItem = new DepotLocker(type, 4); + newItem = std::make_shared(type, 4); } else if (it.isRewardChest()) { - newItem = new RewardChest(type); + newItem = std::make_shared(type); } else if (it.isContainer()) { - newItem = new Container(type); + newItem = std::make_shared(type); } else if (it.isTeleport()) { - newItem = new Teleport(type); + newItem = std::make_shared(type); } else if (it.isMagicField()) { - newItem = new MagicField(type); + newItem = std::make_shared(type); } else if (it.isDoor()) { - newItem = new Door(type); + newItem = std::make_shared(type); } else if (it.isTrashHolder()) { - newItem = new TrashHolder(type); + newItem = std::make_shared(type); } else if (it.isMailbox()) { - newItem = new Mailbox(type); + newItem = std::make_shared(type); } else if (it.isBed()) { - newItem = new BedItem(type); + newItem = std::make_shared(type); } else { auto itemMap = ItemTransformationMap.find(static_cast(it.id)); if (itemMap != ItemTransformationMap.end()) { - newItem = new Item(itemMap->second, count); + newItem = std::make_shared(itemMap->second, count); } else { - newItem = new Item(type, count); + newItem = std::make_shared(type, count); } } @@ -89,7 +89,7 @@ void Item::setImbuement(uint8_t slot, uint16_t imbuementId, uint32_t duration) { } void Item::addImbuement(uint8_t slot, uint16_t imbuementId, uint32_t duration) { - Player* player = getHoldingPlayer(); + std::shared_ptr player = getHoldingPlayer(); if (!player) { return; } @@ -129,7 +129,7 @@ bool Item::hasImbuementCategoryId(uint16_t categoryId) const { return false; } -Container* Item::CreateItemAsContainer(const uint16_t type, uint16_t size) { +std::shared_ptr Item::CreateItemAsContainer(const uint16_t type, uint16_t size) { if (const ItemType &it = Item::items[type]; it.id == 0 || it.stackable @@ -142,12 +142,12 @@ Container* Item::CreateItemAsContainer(const uint16_t type, uint16_t size) { return nullptr; } - Container* newItem = new Container(type, size); + std::shared_ptr newItem = std::make_shared(type, size); newItem->incrementReferenceCounter(); return newItem; } -Item* Item::CreateItem(uint16_t itemId, Position &itemPosition) { +std::shared_ptr Item::CreateItem(uint16_t itemId, Position &itemPosition) { switch (itemId) { case ITEM_FIREFIELD_PVP_FULL: itemId = ITEM_FIREFIELD_PERSISTENT_FULL; @@ -207,15 +207,15 @@ Item::Item(const uint16_t itemId, uint16_t itemCount /*= 0*/) : setDefaultDuration(); } -Item::Item(const Item &i) : - Thing(), id(i.id), count(i.count), loadedFromMap(i.loadedFromMap) { - if (i.attributePtr) { - attributePtr.reset(new ItemAttribute(*i.attributePtr)); +Item::Item(const std::shared_ptr &i) : + Thing(), id(i->id), count(i->count), loadedFromMap(i->loadedFromMap) { + if (i->attributePtr) { + attributePtr.reset(new ItemAttribute(*i->attributePtr)); } } -Item* Item::clone() const { - Item* item = Item::CreateItem(id, count); +std::shared_ptr Item::clone() const { + std::shared_ptr item = Item::CreateItem(id, count); if (item == nullptr) { g_logger().error("[{}] item is nullptr", __FUNCTION__); return nullptr; @@ -228,7 +228,7 @@ Item* Item::clone() const { return item; } -bool Item::equals(const Item* compareItem) const { +bool Item::equals(std::shared_ptr compareItem) const { if (!compareItem) { return false; } @@ -276,7 +276,7 @@ void Item::setDefaultSubtype() { } void Item::onRemoved() { - ScriptEnvironment::removeTempItem(this); + ScriptEnvironment::removeTempItem(static_self_cast()); if (hasAttribute(ItemAttribute_t::UNIQUEID)) { g_game().removeUniqueItem(getAttribute(ItemAttribute_t::UNIQUEID)); @@ -308,9 +308,9 @@ void Item::setID(uint16_t newid) { } } -Cylinder* Item::getTopParent() { - Cylinder* aux = getParent(); - Cylinder* prevaux = dynamic_cast(this); +std::shared_ptr Item::getTopParent() { + std::shared_ptr aux = getParent(); + std::shared_ptr prevaux = std::dynamic_pointer_cast(shared_from_this()); if (!aux) { return prevaux; } @@ -326,40 +326,13 @@ Cylinder* Item::getTopParent() { return aux; } -const Cylinder* Item::getTopParent() const { - const Cylinder* aux = getParent(); - const Cylinder* prevaux = dynamic_cast(this); - if (!aux) { - return prevaux; - } - - while (aux && aux->getParent() != nullptr) { - prevaux = aux; - aux = aux->getParent(); - } - - if (prevaux) { - return prevaux; - } - return aux; -} - -Tile* Item::getTile() { - Cylinder* cylinder = getTopParent(); - // get root cylinder - if (cylinder && cylinder->getParent()) { - cylinder = cylinder->getParent(); - } - return dynamic_cast(cylinder); -} - -const Tile* Item::getTile() const { - const Cylinder* cylinder = getTopParent(); +std::shared_ptr Item::getTile() { + std::shared_ptr cylinder = getTopParent(); // get root cylinder if (cylinder && cylinder->getParent()) { cylinder = cylinder->getParent(); } - return dynamic_cast(cylinder); + return std::dynamic_pointer_cast(cylinder); } uint16_t Item::getSubType() const { @@ -374,8 +347,8 @@ uint16_t Item::getSubType() const { return static_cast(count); } -Player* Item::getHoldingPlayer() const { - Cylinder* p = getParent(); +std::shared_ptr Item::getHoldingPlayer() const { + std::shared_ptr p = getParent(); while (p) { if (p->getCreature()) { return p->getCreature()->getPlayer(); @@ -1037,7 +1010,7 @@ uint32_t Item::getWeight() const { } std::vector> -Item::getDescriptions(const ItemType &it, const Item* item /*= nullptr*/) { +Item::getDescriptions(const ItemType &it, std::shared_ptr item /*= nullptr*/) { std::ostringstream ss; std::vector> descriptions; bool isTradeable = true; @@ -1826,7 +1799,7 @@ Item::getDescriptions(const ItemType &it, const Item* item /*= nullptr*/) { return descriptions; } -std::string Item::parseImbuementDescription(const Item* item) { +std::string Item::parseImbuementDescription(std::shared_ptr item) { std::ostringstream s; if (item && item->getImbuementSlot() >= 1) { s << std::endl @@ -1858,17 +1831,17 @@ std::string Item::parseImbuementDescription(const Item* item) { return s.str(); } -bool Item::isSavedToHouses() const { +bool Item::isSavedToHouses() { const auto &it = items[id]; return it.moveable || it.isWrappable() || it.isCarpet() || getDoor() || (getContainer() && !getContainer()->empty()) || it.canWriteText || getBed() || it.m_transformOnUse; } -SoundEffect_t Item::getMovementSound(Cylinder* toCylinder) const { +SoundEffect_t Item::getMovementSound(std::shared_ptr toCylinder) const { if (!toCylinder) { return SoundEffect_t::ITEM_MOVE_DEFAULT; } - if (const Container* toContainer = toCylinder->getContainer(); + if (std::shared_ptr toContainer = toCylinder->getContainer(); toContainer && toContainer->getHoldingPlayer()) { return SoundEffect_t::ITEM_MOVE_BACKPACK; } @@ -1925,7 +1898,7 @@ SoundEffect_t Item::getMovementSound(Cylinder* toCylinder) const { return SoundEffect_t::ITEM_MOVE_DEFAULT; } -std::string Item::parseClassificationDescription(const Item* item) { +std::string Item::parseClassificationDescription(std::shared_ptr item) { std::ostringstream string; if (item && item->getClassification() >= 1) { string << std::endl @@ -1956,7 +1929,7 @@ std::string Item::parseShowDurationSpeed(int32_t speed, bool &begin) { return description.str(); } -std::string Item::parseShowDuration(const Item* item) { +std::string Item::parseShowDuration(std::shared_ptr item) { if (!item) { return {}; } @@ -1999,7 +1972,7 @@ std::string Item::parseShowDuration(const Item* item) { return description.str(); } -std::string Item::parseShowAttributesDescription(const Item* item, const uint16_t itemId) { +std::string Item::parseShowAttributesDescription(std::shared_ptr item, const uint16_t itemId) { std::ostringstream itemDescription; const ItemType &itemType = Item::items[itemId]; if (itemType.armor != 0 || (item && item->getArmor() != 0) || itemType.showAttributes) { @@ -2225,7 +2198,7 @@ std::string Item::parseShowAttributesDescription(const Item* item, const uint16_ return itemDescription.str(); } -std::string Item::getDescription(const ItemType &it, int32_t lookDistance, const Item* item /*= nullptr*/, int32_t subType /*= -1*/, bool addArticle /*= true*/) { +std::string Item::getDescription(const ItemType &it, int32_t lookDistance, std::shared_ptr item /*= nullptr*/, int32_t subType /*= -1*/, bool addArticle /*= true*/) { std::string text = ""; std::ostringstream s; @@ -2967,12 +2940,12 @@ std::string Item::getDescription(const ItemType &it, int32_t lookDistance, const return s.str(); } -std::string Item::getDescription(int32_t lookDistance) const { +std::string Item::getDescription(int32_t lookDistance) { const ItemType &it = items[id]; - return getDescription(it, lookDistance, this); + return getDescription(it, lookDistance, getItem()); } -std::string Item::getNameDescription(const ItemType &it, const Item* item /*= nullptr*/, int32_t subType /*= -1*/, bool addArticle /*= true*/) { +std::string Item::getNameDescription(const ItemType &it, std::shared_ptr item /*= nullptr*/, int32_t subType /*= -1*/, bool addArticle /*= true*/) { if (item) { subType = item->getSubType(); } @@ -3003,9 +2976,9 @@ std::string Item::getNameDescription(const ItemType &it, const Item* item /*= nu return s.str(); } -std::string Item::getNameDescription() const { +std::string Item::getNameDescription() { const ItemType &it = items[id]; - return getNameDescription(it, this); + return getNameDescription(it, getItem()); } std::string Item::getWeightDescription(const ItemType &it, uint32_t weight, uint32_t count /*= 1*/) { @@ -3048,7 +3021,7 @@ void Item::addUniqueId(uint16_t uniqueId) { return; } - if (g_game().addUniqueItem(uniqueId, this)) { + if (g_game().addUniqueItem(uniqueId, static_self_cast())) { setAttribute(ItemAttribute_t::UNIQUEID, uniqueId); } } @@ -3108,21 +3081,21 @@ LightInfo Item::getLightInfo() const { } void Item::startDecaying() { - g_decay().startDecay(this); + g_decay().startDecay(static_self_cast()); } void Item::stopDecaying() { - g_decay().stopDecay(this); + g_decay().stopDecay(static_self_cast()); } -Item* Item::transform(uint16_t itemId, uint16_t itemCount /*= -1*/) { - Cylinder* cylinder = getParent(); +std::shared_ptr Item::transform(uint16_t itemId, uint16_t itemCount /*= -1*/) { + std::shared_ptr cylinder = getParent(); if (cylinder == nullptr) { g_logger().info("[{}] failed to transform item {}, cylinder is nullptr", __FUNCTION__, getID()); return nullptr; } - Tile* fromTile = cylinder->getTile(); + std::shared_ptr fromTile = cylinder->getTile(); if (fromTile) { auto it = g_game().browseFields.find(fromTile); if (it != g_game().browseFields.end() && it->second == cylinder) { @@ -3130,14 +3103,14 @@ Item* Item::transform(uint16_t itemId, uint16_t itemCount /*= -1*/) { } } - Item* newItem; + std::shared_ptr newItem; if (itemCount == -1) { newItem = Item::CreateItem(itemId, 1); } else { newItem = Item::CreateItem(itemId, itemCount); } - int32_t itemIndex = cylinder->getThingIndex(this); + int32_t itemIndex = cylinder->getThingIndex(static_self_cast()); auto duration = getDuration(); if (duration > 0) { newItem->setDuration(duration); @@ -3147,9 +3120,9 @@ Item* Item::transform(uint16_t itemId, uint16_t itemCount /*= -1*/) { cylinder->postAddNotification(newItem, cylinder, itemIndex); setParent(nullptr); - cylinder->postRemoveNotification(this, cylinder, itemIndex); + cylinder->postRemoveNotification(static_self_cast(), cylinder, itemIndex); stopDecaying(); - g_game().ReleaseItem(this); + g_game().ReleaseItem(static_self_cast()); newItem->startDecaying(); return newItem; } @@ -3181,16 +3154,16 @@ bool Item::hasMarketAttributes() const { } bool Item::isInsideDepot(bool includeInbox /* = false*/) const { - if (const Container* thisContainer = getContainer(); thisContainer && (thisContainer->getDepotLocker() || thisContainer->isDepotChest() || (includeInbox && thisContainer->isInbox()))) { + if (std::shared_ptr thisContainer = getContainer(); thisContainer && (thisContainer->getDepotLocker() || thisContainer->isDepotChest() || (includeInbox && thisContainer->isInbox()))) { return true; } - const Cylinder* cylinder = getParent(); + std::shared_ptr cylinder = getParent(); if (!cylinder) { return false; } - const Container* container = cylinder->getContainer(); + std::shared_ptr container = cylinder->getContainer(); if (!container) { return false; } @@ -3208,6 +3181,6 @@ bool Item::isInsideDepot(bool includeInbox /* = false*/) const { void Item::updateTileFlags() { if (auto tile = getTile()) { - tile->updateTileFlags(this); + tile->updateTileFlags(static_self_cast()); } } diff --git a/src/items/item.hpp b/src/items/item.hpp index 9c7ab4af7d1..8cfef48b54e 100644 --- a/src/items/item.hpp +++ b/src/items/item.hpp @@ -212,72 +212,51 @@ class ItemProperties { friend class Item; }; -class Item : virtual public Thing, public ItemProperties { +class Item : virtual public Thing, public ItemProperties, public SharedObject { public: // Factory member to create item of right type based on type - static Item* CreateItem(const uint16_t type, uint16_t count = 0, Position* itemPosition = nullptr); - static Container* CreateItemAsContainer(const uint16_t type, uint16_t size); - static Item* CreateItem(uint16_t itemId, Position &itemPosition); + static std::shared_ptr CreateItem(const uint16_t type, uint16_t count = 0, Position* itemPosition = nullptr); + static std::shared_ptr CreateItemAsContainer(const uint16_t type, uint16_t size); + static std::shared_ptr CreateItem(uint16_t itemId, Position &itemPosition); static Items items; // Constructor for items Item(const uint16_t type, uint16_t count = 0); - Item(const Item &i); - virtual Item* clone() const; + Item(const std::shared_ptr &i); + virtual std::shared_ptr clone() const; virtual ~Item() = default; // non-assignable Item &operator=(const Item &) = delete; - bool equals(const Item* compareItem) const; + bool equals(std::shared_ptr compareItem) const; - Item* getItem() override final { - return this; + std::shared_ptr getItem() override final { + return static_self_cast(); } - const Item* getItem() const override final { - return this; - } - virtual Teleport* getTeleport() { - return nullptr; - } - virtual const Teleport* getTeleport() const { - return nullptr; - } - virtual TrashHolder* getTrashHolder() { - return nullptr; - } - virtual const TrashHolder* getTrashHolder() const { - return nullptr; - } - virtual Mailbox* getMailbox() { - return nullptr; - } - virtual const Mailbox* getMailbox() const { - return nullptr; - } - virtual Door* getDoor() { + virtual std::shared_ptr getTeleport() { return nullptr; } - virtual const Door* getDoor() const { + virtual std::shared_ptr getTrashHolder() { return nullptr; } - virtual MagicField* getMagicField() { + virtual std::shared_ptr getMailbox() { return nullptr; } - virtual const MagicField* getMagicField() const { + virtual std::shared_ptr getDoor() { return nullptr; } - virtual BedItem* getBed() { + virtual std::shared_ptr getMagicField() { return nullptr; } - virtual const BedItem* getBed() const { + virtual std::shared_ptr getBed() { return nullptr; } - bool isSavedToHouses() const; + bool isSavedToHouses(); - SoundEffect_t getMovementSound(Cylinder* toCylinder) const; + SoundEffect_t getMovementSound(std::shared_ptr toCylinder) const; void setIsLootTrackeable(bool value) { isLootTrackeable = value; @@ -287,19 +266,19 @@ class Item : virtual public Thing, public ItemProperties { return isLootTrackeable; } - static std::string parseImbuementDescription(const Item* item); + static std::string parseImbuementDescription(std::shared_ptr item); static std::string parseShowDurationSpeed(int32_t speed, bool &begin); - static std::string parseShowDuration(const Item* item); - static std::string parseShowAttributesDescription(const Item* item, const uint16_t itemId); - static std::string parseClassificationDescription(const Item* item); + static std::string parseShowDuration(std::shared_ptr item); + static std::string parseShowAttributesDescription(std::shared_ptr item, const uint16_t itemId); + static std::string parseClassificationDescription(std::shared_ptr item); - static std::vector> getDescriptions(const ItemType &it, const Item* item = nullptr); - static std::string getDescription(const ItemType &it, int32_t lookDistance, const Item* item = nullptr, int32_t subType = -1, bool addArticle = true); - static std::string getNameDescription(const ItemType &it, const Item* item = nullptr, int32_t subType = -1, bool addArticle = true); + static std::vector> getDescriptions(const ItemType &it, std::shared_ptr item = nullptr); + static std::string getDescription(const ItemType &it, int32_t lookDistance, std::shared_ptr item = nullptr, int32_t subType = -1, bool addArticle = true); + static std::string getNameDescription(const ItemType &it, std::shared_ptr item = nullptr, int32_t subType = -1, bool addArticle = true); static std::string getWeightDescription(const ItemType &it, uint32_t weight, uint32_t count = 1); - std::string getDescription(int32_t lookDistance) const override final; - std::string getNameDescription() const; + std::string getDescription(int32_t lookDistance) override final; + std::string getNameDescription(); std::string getWeightDescription() const; // serialization @@ -309,7 +288,7 @@ class Item : virtual public Thing, public ItemProperties { virtual void serializeAttr(PropWriteStream &propWriteStream) const; - bool isPushable() const override final { + bool isPushable() override final { return isMoveable(); } int32_t getThrowRange() const override final { @@ -322,7 +301,7 @@ class Item : virtual public Thing, public ItemProperties { void setID(uint16_t newid); // Returns the player that is holding this item in his inventory - Player* getHoldingPlayer() const; + std::shared_ptr getHoldingPlayer() const; WeaponType_t getWeaponType() const { return items[id].weaponType; @@ -534,7 +513,7 @@ class Item : virtual public Thing, public ItemProperties { count = n; } - static uint32_t countByType(const Item* item, int32_t subType) { + static uint32_t countByType(std::shared_ptr item, int32_t subType) { if (subType == -1 || subType == item->getSubType()) { return item->getItemCount(); } @@ -567,12 +546,12 @@ class Item : virtual public Thing, public ItemProperties { return true; } virtual void onRemoved(); - virtual void onTradeEvent(TradeEvents_t, Player*) { } + virtual void onTradeEvent(TradeEvents_t, std::shared_ptr) { } virtual void startDecaying(); virtual void stopDecaying(); - Item* transform(uint16_t itemId, uint16_t itemCount = -1); + std::shared_ptr transform(uint16_t itemId, uint16_t itemCount = -1); bool isLoadedFromMap() const { return loadedFromMap; @@ -589,20 +568,17 @@ class Item : virtual public Thing, public ItemProperties { } void decrementReferenceCounter() { if (--referenceCounter == 0) { - delete this; } } - Cylinder* getParent() const override { + std::shared_ptr getParent() const override { return parent; } - void setParent(Cylinder* cylinder) override { + void setParent(std::shared_ptr cylinder) override { parent = cylinder; } - Cylinder* getTopParent(); - const Cylinder* getTopParent() const; - Tile* getTile() override; - const Tile* getTile() const override; + std::shared_ptr getTopParent(); + std::shared_ptr getTile() override; bool isRemoved() const override { return !parent || parent->isRemoved(); } @@ -705,7 +681,7 @@ class Item : virtual public Thing, public ItemProperties { void checkDecayMapItemOnMove(); protected: - Cylinder* parent = nullptr; + std::shared_ptr parent = nullptr; uint32_t referenceCounter = 0; @@ -725,6 +701,6 @@ class Item : virtual public Thing, public ItemProperties { friend class MapCache; }; -using ItemList = std::list; -using ItemDeque = std::deque; -using StashContainerList = std::vector>; +using ItemList = std::list>; +using ItemDeque = std::deque>; +using StashContainerList = std::vector, uint32_t>>; diff --git a/src/items/thing.cpp b/src/items/thing.cpp index f06989f51a7..0665f15a6e5 100644 --- a/src/items/thing.cpp +++ b/src/items/thing.cpp @@ -12,18 +12,10 @@ #include "items/thing.hpp" #include "items/tile.hpp" -const Position &Thing::getPosition() const { - const Tile* tile = getTile(); +const Position &Thing::getPosition() { + std::shared_ptr tile = getTile(); if (!tile) { - return Tile::nullptr_tile.getPosition(); + return Tile::nullptr_tile->getPosition(); } return tile->getPosition(); } - -Tile* Thing::getTile() { - return dynamic_cast(this); -} - -const Tile* Thing::getTile() const { - return dynamic_cast(this); -} diff --git a/src/items/thing.hpp b/src/items/thing.hpp index 990755e54d8..956c01468f3 100644 --- a/src/items/thing.hpp +++ b/src/items/thing.hpp @@ -26,42 +26,43 @@ class Thing { Thing(const Thing &) = delete; Thing &operator=(const Thing &) = delete; - virtual std::string getDescription(int32_t lookDistance) const = 0; + virtual std::string getDescription(int32_t lookDistance) = 0; - virtual Cylinder* getParent() const { + virtual std::shared_ptr getParent() const { return nullptr; } - virtual Cylinder* getRealParent() const { + virtual std::shared_ptr getRealParent() const { return getParent(); } - virtual void setParent(Cylinder*) { + virtual void setParent(std::shared_ptr) { // } - virtual Tile* getTile(); - virtual const Tile* getTile() const; + virtual std::shared_ptr getTile() { + return nullptr; + } - virtual const Position &getPosition() const; + virtual const Position &getPosition(); virtual int32_t getThrowRange() const = 0; - virtual bool isPushable() const = 0; + virtual bool isPushable() = 0; - virtual Container* getContainer() { + virtual std::shared_ptr getContainer() { return nullptr; } - virtual const Container* getContainer() const { + virtual std::shared_ptr getContainer() const { return nullptr; } - virtual Item* getItem() { + virtual std::shared_ptr getItem() { return nullptr; } - virtual const Item* getItem() const { + virtual std::shared_ptr getItem() const { return nullptr; } - virtual Creature* getCreature() { + virtual std::shared_ptr getCreature() { return nullptr; } - virtual const Creature* getCreature() const { + virtual std::shared_ptr getCreature() const { return nullptr; } diff --git a/src/items/tile.cpp b/src/items/tile.cpp index a7bc6115889..92740203daf 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -22,8 +22,8 @@ #include "map/house/housetile.hpp" #include "io/iomap.hpp" -StaticTile real_nullptr_tile(0xFFFF, 0xFFFF, 0xFF); -Tile &Tile::nullptr_tile = real_nullptr_tile; +auto real_nullptr_tile = std::make_shared(0xFFFF, 0xFFFF, 0xFF); +const std::shared_ptr &Tile::nullptr_tile = real_nullptr_tile; bool Tile::hasProperty(ItemProperty prop) const { if (ground && ground->hasProperty(prop)) { @@ -31,7 +31,7 @@ bool Tile::hasProperty(ItemProperty prop) const { } if (const TileItemVector* items = getItemList()) { - for (const Item* item : *items) { + for (std::shared_ptr item : *items) { if (item->hasProperty(prop)) { return true; } @@ -40,7 +40,7 @@ bool Tile::hasProperty(ItemProperty prop) const { return false; } -bool Tile::hasProperty(const Item* exclude, ItemProperty prop) const { +bool Tile::hasProperty(std::shared_ptr exclude, ItemProperty prop) const { assert(exclude); if (ground && exclude != ground && ground->hasProperty(prop)) { @@ -48,7 +48,7 @@ bool Tile::hasProperty(const Item* exclude, ItemProperty prop) const { } if (const TileItemVector* items = getItemList()) { - for (const Item* item : *items) { + for (std::shared_ptr item : *items) { if (item != exclude && item->hasProperty(prop)) { return true; } @@ -72,7 +72,7 @@ bool Tile::hasHeight(uint32_t n) const { } if (const TileItemVector* items = getItemList()) { - for (const Item* item : *items) { + for (std::shared_ptr item : *items) { if (item->hasProperty(CONST_PROP_HASHEIGHT)) { ++height; } @@ -113,11 +113,11 @@ uint32_t Tile::getDownItemCount() const { return 0; } -std::string Tile::getDescription(int32_t) const { +std::string Tile::getDescription(int32_t) { return "You dont know why, but you cant see anything!"; } -Teleport* Tile::getTeleportItem() const { +std::shared_ptr Tile::getTeleportItem() const { if (!hasFlag(TILESTATE_TELEPORT)) { return nullptr; } @@ -132,7 +132,7 @@ Teleport* Tile::getTeleportItem() const { return nullptr; } -MagicField* Tile::getFieldItem() const { +std::shared_ptr Tile::getFieldItem() const { if (!hasFlag(TILESTATE_MAGICFIELD)) { return nullptr; } @@ -151,7 +151,7 @@ MagicField* Tile::getFieldItem() const { return nullptr; } -TrashHolder* Tile::getTrashHolder() const { +std::shared_ptr Tile::getTrashHolder() const { if (!hasFlag(TILESTATE_TRASHHOLDER)) { return nullptr; } @@ -170,7 +170,7 @@ TrashHolder* Tile::getTrashHolder() const { return nullptr; } -Mailbox* Tile::getMailbox() const { +std::shared_ptr Tile::getMailbox() const { if (!hasFlag(TILESTATE_MAILBOX)) { return nullptr; } @@ -189,7 +189,7 @@ Mailbox* Tile::getMailbox() const { return nullptr; } -BedItem* Tile::getBedItem() const { +std::shared_ptr Tile::getBedItem() const { if (!hasFlag(TILESTATE_BED)) { return nullptr; } @@ -208,7 +208,7 @@ BedItem* Tile::getBedItem() const { return nullptr; } -Creature* Tile::getTopCreature() const { +std::shared_ptr Tile::getTopCreature() const { if (const CreatureVector* creatures = getCreatures()) { if (!creatures->empty()) { return *creatures->begin(); @@ -217,7 +217,7 @@ Creature* Tile::getTopCreature() const { return nullptr; } -const Creature* Tile::getBottomCreature() const { +std::shared_ptr Tile::getBottomCreature() const { if (const CreatureVector* creatures = getCreatures()) { if (!creatures->empty()) { return *creatures->rbegin(); @@ -226,23 +226,23 @@ const Creature* Tile::getBottomCreature() const { return nullptr; } -Creature* Tile::getTopVisibleCreature(const Creature* creature) const { +std::shared_ptr Tile::getTopVisibleCreature(std::shared_ptr creature) const { if (const CreatureVector* creatures = getCreatures()) { if (creature) { - const Player* player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player && player->isAccessPlayer()) { return getTopCreature(); } - for (Creature* tileCreature : *creatures) { + for (auto &tileCreature : *creatures) { if (creature->canSeeCreature(tileCreature)) { return tileCreature; } } } else { - for (Creature* tileCreature : *creatures) { + for (auto &tileCreature : *creatures) { if (!tileCreature->isInvisible()) { - const Player* player = tileCreature->getPlayer(); + std::shared_ptr player = tileCreature->getPlayer(); if (!player || !player->isInGhostMode()) { return tileCreature; } @@ -253,10 +253,10 @@ Creature* Tile::getTopVisibleCreature(const Creature* creature) const { return nullptr; } -const Creature* Tile::getBottomVisibleCreature(const Creature* creature) const { +std::shared_ptr Tile::getBottomVisibleCreature(std::shared_ptr creature) const { if (const CreatureVector* creatures = getCreatures()) { if (creature) { - const Player* player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player && player->isAccessPlayer()) { return getBottomCreature(); } @@ -269,7 +269,7 @@ const Creature* Tile::getBottomVisibleCreature(const Creature* creature) const { } else { for (auto it = creatures->rbegin(), end = creatures->rend(); it != end; ++it) { if (!(*it)->isInvisible()) { - const Player* player = (*it)->getPlayer(); + std::shared_ptr player = (*it)->getPlayer(); if (!player || !player->isInGhostMode()) { return *it; } @@ -280,21 +280,21 @@ const Creature* Tile::getBottomVisibleCreature(const Creature* creature) const { return nullptr; } -Item* Tile::getTopDownItem() const { +std::shared_ptr Tile::getTopDownItem() const { if (const TileItemVector* items = getItemList()) { return items->getTopDownItem(); } return nullptr; } -Item* Tile::getTopTopItem() const { +std::shared_ptr Tile::getTopTopItem() const { if (const TileItemVector* items = getItemList()) { return items->getTopTopItem(); } return nullptr; } -Item* Tile::getItemByTopOrder(int32_t topOrder) { +std::shared_ptr Tile::getItemByTopOrder(int32_t topOrder) { // topOrder: // 1: borders // 2: ladders, signs, splashes @@ -310,8 +310,8 @@ Item* Tile::getItemByTopOrder(int32_t topOrder) { return nullptr; } -Thing* Tile::getTopVisibleThing(const Creature* creature) { - Thing* thing = getTopVisibleCreature(creature); +std::shared_ptr Tile::getTopVisibleThing(std::shared_ptr creature) { + std::shared_ptr thing = getTopVisibleCreature(creature); if (thing) { return thing; } @@ -336,12 +336,12 @@ Thing* Tile::getTopVisibleThing(const Creature* creature) { return ground; } -void Tile::onAddTileItem(Item* item) { +void Tile::onAddTileItem(std::shared_ptr item) { if ((item->hasProperty(CONST_PROP_MOVEABLE) || item->getContainer()) || (item->isWrapable() && !item->hasProperty(CONST_PROP_MOVEABLE) && !item->hasProperty(CONST_PROP_BLOCKPATH))) { - auto it = g_game().browseFields.find(this); + auto it = g_game().browseFields.find(static_self_cast()); if (it != g_game().browseFields.end()) { it->second->addItemBack(item); - item->setParent(this); + item->setParent(static_self_cast()); } } @@ -353,21 +353,21 @@ void Tile::onAddTileItem(Item* item) { g_game().map.getSpectators(spectators, cylinderMapPos, true); // send to client - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { - tmpPlayer->sendAddTileItem(this, cylinderMapPos, item); + for (std::shared_ptr spectator : spectators) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { + tmpPlayer->sendAddTileItem(static_self_cast(), cylinderMapPos, item); } } // event methods - for (Creature* spectator : spectators) { - spectator->onAddTileItem(this, cylinderMapPos); + for (std::shared_ptr spectator : spectators) { + spectator->onAddTileItem(static_self_cast(), cylinderMapPos); } if ((!hasFlag(TILESTATE_PROTECTIONZONE) || g_configManager().getBoolean(CLEAN_PROTECTION_ZONES)) && item->isCleanable()) { if (!this->getHouse()) { - g_game().addTileToClean(this); + g_game().addTileToClean(static_self_cast()); } } @@ -407,20 +407,20 @@ void Tile::onAddTileItem(Item* item) { } } -void Tile::onUpdateTileItem(Item* oldItem, const ItemType &oldType, Item* newItem, const ItemType &newType) { +void Tile::onUpdateTileItem(std::shared_ptr oldItem, const ItemType &oldType, std::shared_ptr newItem, const ItemType &newType) { if ((newItem->hasProperty(CONST_PROP_MOVEABLE) || newItem->getContainer()) || (newItem->isWrapable() && newItem->hasProperty(CONST_PROP_MOVEABLE) && !oldItem->hasProperty(CONST_PROP_BLOCKPATH))) { - auto it = g_game().browseFields.find(this); + auto it = g_game().browseFields.find(static_self_cast()); if (it != g_game().browseFields.end()) { int32_t index = it->second->getThingIndex(oldItem); if (index != -1) { it->second->replaceThing(index, newItem); - newItem->setParent(this); + newItem->setParent(static_self_cast()); } } } else if ((oldItem->hasProperty(CONST_PROP_MOVEABLE) || oldItem->getContainer()) || (oldItem->isWrapable() && !oldItem->hasProperty(CONST_PROP_MOVEABLE) && !oldItem->hasProperty(CONST_PROP_BLOCKPATH))) { - auto it = g_game().browseFields.find(this); + auto it = g_game().browseFields.find(static_self_cast()); if (it != g_game().browseFields.end()) { - Cylinder* oldParent = oldItem->getParent(); + std::shared_ptr oldParent = oldItem->getParent(); it->second->removeThing(oldItem, oldItem->getItemCount()); oldItem->setParent(oldParent); } @@ -432,21 +432,21 @@ void Tile::onUpdateTileItem(Item* oldItem, const ItemType &oldType, Item* newIte g_game().map.getSpectators(spectators, cylinderMapPos, true); // send to client - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { - tmpPlayer->sendUpdateTileItem(this, cylinderMapPos, newItem); + for (std::shared_ptr spectator : spectators) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { + tmpPlayer->sendUpdateTileItem(static_self_cast(), cylinderMapPos, newItem); } } // event methods - for (Creature* spectator : spectators) { - spectator->onUpdateTileItem(this, cylinderMapPos, oldItem, oldType, newItem, newType); + for (std::shared_ptr spectator : spectators) { + spectator->onUpdateTileItem(static_self_cast(), cylinderMapPos, oldItem, oldType, newItem, newType); } } -void Tile::onRemoveTileItem(const SpectatorHashSet &spectators, const std::vector &oldStackPosVector, Item* item) { +void Tile::onRemoveTileItem(const SpectatorHashSet &spectators, const std::vector &oldStackPosVector, std::shared_ptr item) { if ((item->hasProperty(CONST_PROP_MOVEABLE) || item->getContainer()) || (item->isWrapable() && !item->hasProperty(CONST_PROP_MOVEABLE) && !item->hasProperty(CONST_PROP_BLOCKPATH))) { - auto it = g_game().browseFields.find(this); + auto it = g_game().browseFields.find(static_self_cast()); if (it != g_game().browseFields.end()) { it->second->removeThing(item, item->getItemCount()); } @@ -462,21 +462,21 @@ void Tile::onRemoveTileItem(const SpectatorHashSet &spectators, const std::vecto // send to client size_t i = 0; - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (std::shared_ptr spectator : spectators) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendRemoveTileThing(cylinderMapPos, oldStackPosVector[i++]); } } // event methods - for (Creature* spectator : spectators) { - spectator->onRemoveTileItem(this, cylinderMapPos, iType, item); + for (std::shared_ptr spectator : spectators) { + spectator->onRemoveTileItem(static_self_cast(), cylinderMapPos, iType, item); } if (!hasFlag(TILESTATE_PROTECTIONZONE) || g_configManager().getBoolean(CLEAN_PROTECTION_ZONES)) { auto items = getItemList(); if (!items || items->empty()) { - g_game().removeTileToClean(this); + g_game().removeTileToClean(static_self_cast()); return; } @@ -489,7 +489,7 @@ void Tile::onRemoveTileItem(const SpectatorHashSet &spectators, const std::vecto } if (!ret) { - g_game().removeTileToClean(this); + g_game().removeTileToClean(static_self_cast()); } } @@ -528,17 +528,17 @@ void Tile::onUpdateTile(const SpectatorHashSet &spectators) { const Position &cylinderMapPos = getPosition(); // send to clients - for (Creature* spectator : spectators) { - spectator->getPlayer()->sendUpdateTile(this, cylinderMapPos); + for (std::shared_ptr spectator : spectators) { + spectator->getPlayer()->sendUpdateTile(getTile(), cylinderMapPos); } } -ReturnValue Tile::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t tileFlags, Creature*) const { +ReturnValue Tile::queryAdd(int32_t, const std::shared_ptr &thing, uint32_t, uint32_t tileFlags, std::shared_ptr) { if (hasBitSet(FLAG_NOLIMIT, tileFlags)) { return RETURNVALUE_NOERROR; } - if (const Creature* creature = thing.getCreature()) { + if (auto creature = thing->getCreature()) { if (creature->getNpc()) { ReturnValue returnValue = checkNpcCanWalkIntoTile(); @@ -555,7 +555,7 @@ ReturnValue Tile::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t tileF return RETURNVALUE_NOTPOSSIBLE; } - if (const Monster* monster = creature->getMonster()) { + if (std::shared_ptr monster = creature->getMonster()) { if (hasFlag(TILESTATE_PROTECTIONZONE | TILESTATE_FLOORCHANGE | TILESTATE_TELEPORT) && (!monster->isFamiliar() || (monster->isFamiliar() && monster->getMaster() && monster->getMaster()->getAttackedCreature()))) { return RETURNVALUE_NOTPOSSIBLE; } @@ -569,19 +569,19 @@ ReturnValue Tile::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t tileF const CreatureVector* creatures = getCreatures(); if (monster->canPushCreatures() && !monster->isSummon()) { if (creatures) { - for (Creature* tileCreature : *creatures) { + for (auto &tileCreature : *creatures) { if (tileCreature->getPlayer() && tileCreature->getPlayer()->isInGhostMode()) { continue; } - const Monster* creatureMonster = tileCreature->getMonster(); + std::shared_ptr creatureMonster = tileCreature->getMonster(); if (!creatureMonster || !tileCreature->isPushable() || (creatureMonster->isSummon() && creatureMonster->getMaster()->getPlayer())) { return RETURNVALUE_NOTPOSSIBLE; } } } } else if (creatures && !creatures->empty()) { - for (const Creature* tileCreature : *creatures) { + for (std::shared_ptr tileCreature : *creatures) { if (!tileCreature->isInGhostMode()) { return RETURNVALUE_NOTENOUGHROOM; } @@ -624,9 +624,9 @@ ReturnValue Tile::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t tileF } const CreatureVector* creatures = getCreatures(); - if (const Player* player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { if (creatures && !creatures->empty() && !hasBitSet(FLAG_IGNOREBLOCKCREATURE, tileFlags) && !player->isAccessPlayer()) { - for (const Creature* tileCreature : *creatures) { + for (std::shared_ptr tileCreature : *creatures) { if (!player->canWalkthrough(tileCreature)) { return RETURNVALUE_NOTPOSSIBLE; } @@ -642,7 +642,7 @@ ReturnValue Tile::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t tileF return RETURNVALUE_NOTPOSSIBLE; } - const Tile* playerTile = player->getTile(); + const auto playerTile = player->getTile(); if (playerTile && player->isPzLocked()) { if (!playerTile->hasFlag(TILESTATE_PVPZONE)) { // player is trying to enter a pvp zone while being pz-locked @@ -660,7 +660,7 @@ ReturnValue Tile::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t tileF } } } else if (creatures && !creatures->empty() && !hasBitSet(FLAG_IGNOREBLOCKCREATURE, tileFlags)) { - for (const Creature* tileCreature : *creatures) { + for (std::shared_ptr tileCreature : *creatures) { if (!tileCreature->isInGhostMode()) { return RETURNVALUE_NOTENOUGHROOM; } @@ -673,7 +673,7 @@ ReturnValue Tile::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t tileF // NO PVP magic wall or wild growth field check if (creature && creature->getPlayer()) { if (const auto fieldList = getItemList()) { - for (Item* findfield : *fieldList) { + for (auto &findfield : *fieldList) { if (findfield && (findfield->getID() == ITEM_WILDGROWTH_SAFE || findfield->getID() == ITEM_MAGICWALL_SAFE)) { if (!creature->isInGhostMode()) { g_game().internalRemoveItem(findfield, 1); @@ -695,7 +695,7 @@ ReturnValue Tile::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t tileF } if (const auto items = getItemList()) { - for (const Item* item : *items) { + for (std::shared_ptr item : *items) { const ItemType &iiType = Item::items[item->getID()]; if (iiType.blockSolid && (!iiType.moveable || item->hasAttribute(ItemAttribute_t::UNIQUEID))) { return RETURNVALUE_NOTPOSSIBLE; @@ -703,7 +703,7 @@ ReturnValue Tile::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t tileF } } } - } else if (const Item* item = thing.getItem()) { + } else if (auto item = thing->getItem()) { const TileItemVector* items = getItemList(); if (items && items->size() >= 0x3E8) { return RETURNVALUE_NOTPOSSIBLE; @@ -716,7 +716,7 @@ ReturnValue Tile::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t tileF const CreatureVector* creatures = getCreatures(); if (creatures && !creatures->empty() && item->isBlocking() && !hasBitSet(FLAG_IGNOREBLOCKCREATURE, tileFlags)) { - for (const Creature* tileCreature : *creatures) { + for (std::shared_ptr tileCreature : *creatures) { if (!tileCreature->isInGhostMode()) { return RETURNVALUE_NOTENOUGHROOM; } @@ -725,7 +725,7 @@ ReturnValue Tile::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t tileF if (itemIsHangable && hasFlag(TILESTATE_SUPPORTS_HANGABLE)) { if (items) { - for (const Item* tileItem : *items) { + for (std::shared_ptr tileItem : *items) { if (tileItem->isHangable()) { return RETURNVALUE_NEEDEXCHANGE; } @@ -748,7 +748,7 @@ ReturnValue Tile::queryAdd(int32_t, const Thing &thing, uint32_t, uint32_t tileF } if (items) { - for (const Item* tileItem : *items) { + for (std::shared_ptr tileItem : *items) { const ItemType &iiType = Item::items[tileItem->getID()]; if (!iiType.blockSolid) { continue; @@ -784,18 +784,18 @@ bool Tile::hasHarmfulField() const { return hasFlag(TILESTATE_MAGICFIELD) && getFieldItem() && !getFieldItem()->isBlocking() && getFieldItem()->getDamage() > 0; } -ReturnValue Tile::queryMaxCount(int32_t, const Thing &, uint32_t count, uint32_t &maxQueryCount, uint32_t) const { +ReturnValue Tile::queryMaxCount(int32_t, const std::shared_ptr &, uint32_t count, uint32_t &maxQueryCount, uint32_t) { maxQueryCount = std::max(1, count); return RETURNVALUE_NOERROR; } -ReturnValue Tile::queryRemove(const Thing &thing, uint32_t count, uint32_t tileFlags, Creature* /*= nullptr */) const { - int32_t index = getThingIndex(&thing); +ReturnValue Tile::queryRemove(const std::shared_ptr &thing, uint32_t count, uint32_t tileFlags, std::shared_ptr /*= nullptr */) { + int32_t index = getThingIndex(thing); if (index == -1) { return RETURNVALUE_NOTPOSSIBLE; } - const Item* item = thing.getItem(); + std::shared_ptr item = thing->getItem(); if (item == nullptr) { return RETURNVALUE_NOTPOSSIBLE; } @@ -811,8 +811,8 @@ ReturnValue Tile::queryRemove(const Thing &thing, uint32_t count, uint32_t tileF return RETURNVALUE_NOERROR; } -Tile* Tile::queryDestination(int32_t &, const Thing &, Item** destItem, uint32_t &tileFlags) { - Tile* destTile = nullptr; +std::shared_ptr Tile::queryDestination(int32_t &, const std::shared_ptr &, std::shared_ptr* destItem, uint32_t &tileFlags) { + std::shared_ptr destTile = nullptr; *destItem = nullptr; if (hasFlag(TILESTATE_FLOORCHANGE_DOWN)) { @@ -820,17 +820,17 @@ Tile* Tile::queryDestination(int32_t &, const Thing &, Item** destItem, uint32_t uint16_t dy = tilePos.y; uint8_t dz = tilePos.z + 1; - const Tile* southDownTile = g_game().map.getTile(dx, dy - 1, dz); + std::shared_ptr southDownTile = g_game().map.getTile(dx, dy - 1, dz); if (southDownTile && southDownTile->hasFlag(TILESTATE_FLOORCHANGE_SOUTH_ALT)) { dy -= 2; destTile = g_game().map.getTile(dx, dy, dz); } else { - const Tile* eastDownTile = g_game().map.getTile(dx - 1, dy, dz); + std::shared_ptr eastDownTile = g_game().map.getTile(dx - 1, dy, dz); if (eastDownTile && eastDownTile->hasFlag(TILESTATE_FLOORCHANGE_EAST_ALT)) { dx -= 2; destTile = g_game().map.getTile(dx, dy, dz); } else { - const Tile* downTile = g_game().map.getTile(dx, dy, dz); + std::shared_ptr downTile = g_game().map.getTile(dx, dy, dz); if (downTile) { if (downTile->hasFlag(TILESTATE_FLOORCHANGE_NORTH)) { ++dy; @@ -893,13 +893,13 @@ Tile* Tile::queryDestination(int32_t &, const Thing &, Item** destItem, uint32_t } if (destTile == nullptr) { - destTile = this; + destTile = static_self_cast(); } else { tileFlags |= FLAG_NOLIMIT; // Will ignore that there is blocking items/creatures } if (destTile) { - Thing* destThing = destTile->getTopDownItem(); + std::shared_ptr destThing = destTile->getTopDownItem(); if (destThing) { *destItem = destThing->getItem(); } @@ -907,7 +907,7 @@ Tile* Tile::queryDestination(int32_t &, const Thing &, Item** destItem, uint32_t return destTile; } -std::vector Tile::getSurroundingTiles() const { +std::vector> Tile::getSurroundingTiles() { const auto &position = getPosition(); return { g_game().map.getTile(position.x - 1, position.y, position.z), @@ -921,23 +921,23 @@ std::vector Tile::getSurroundingTiles() const { }; } -void Tile::addThing(Thing* thing) { +void Tile::addThing(std::shared_ptr thing) { addThing(0, thing); } -void Tile::addThing(int32_t, Thing* thing) { +void Tile::addThing(int32_t, std::shared_ptr thing) { if (!thing) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - Creature* creature = thing->getCreature(); + std::shared_ptr creature = thing->getCreature(); if (creature) { g_game().map.clearSpectatorCache(); - creature->setParent(this); + creature->setParent(static_self_cast()); CreatureVector* creatures = makeCreatures(); creatures->insert(creatures->begin(), creature); } else { - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item == nullptr) { return /*RETURNVALUE_NOTPOSSIBLE*/; } @@ -947,7 +947,7 @@ void Tile::addThing(int32_t, Thing* thing) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - item->setParent(this); + item->setParent(static_self_cast()); const ItemType &itemType = Item::items[item->getID()]; if (itemType.isGroundTile()) { @@ -957,7 +957,7 @@ void Tile::addThing(int32_t, Thing* thing) { } else { const ItemType &oldType = Item::items[ground->getID()]; - Item* oldGround = ground; + std::shared_ptr oldGround = ground; ground->setParent(nullptr); g_game().ReleaseItem(ground); ground = item; @@ -970,7 +970,7 @@ void Tile::addThing(int32_t, Thing* thing) { if (itemType.isSplash() && items) { // remove old splash if exists for (ItemVector::const_iterator it = items->getBeginTopItem(), end = items->getEndTopItem(); it != end; ++it) { - Item* oldSplash = *it; + std::shared_ptr oldSplash = *it; if (!Item::items[oldSplash->getID()].isSplash()) { continue; } @@ -1008,7 +1008,7 @@ void Tile::addThing(int32_t, Thing* thing) { // remove old field item if exists if (items) { for (ItemVector::const_iterator it = items->getBeginDownItem(), end = items->getEndDownItem(); it != end; ++it) { - MagicField* oldField = (*it)->getMagicField(); + std::shared_ptr oldField = (*it)->getMagicField(); if (oldField) { if (oldField->isReplaceable()) { removeThing(oldField, 1); @@ -1036,13 +1036,13 @@ void Tile::addThing(int32_t, Thing* thing) { } } -void Tile::updateThing(Thing* thing, uint16_t itemId, uint32_t count) { +void Tile::updateThing(std::shared_ptr thing, uint16_t itemId, uint32_t count) { int32_t index = getThingIndex(thing); if (index == -1) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item == nullptr) { return /*RETURNVALUE_NOTPOSSIBLE*/; } @@ -1056,15 +1056,15 @@ void Tile::updateThing(Thing* thing, uint16_t itemId, uint32_t count) { onUpdateTileItem(item, oldType, item, newType); } -void Tile::replaceThing(uint32_t index, Thing* thing) { +void Tile::replaceThing(uint32_t index, std::shared_ptr thing) { int32_t pos = index; - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item == nullptr) { return /*RETURNVALUE_NOTPOSSIBLE*/; } - Item* oldItem = nullptr; + std::shared_ptr oldItem = nullptr; bool isInserted = false; if (ground) { @@ -1114,7 +1114,7 @@ void Tile::replaceThing(uint32_t index, Thing* thing) { } if (isInserted) { - item->setParent(this); + item->setParent(static_self_cast()); resetTileFlags(oldItem); setTileFlags(item); @@ -1127,8 +1127,8 @@ void Tile::replaceThing(uint32_t index, Thing* thing) { } } -void Tile::removeThing(Thing* thing, uint32_t count) { - Creature* creature = thing->getCreature(); +void Tile::removeThing(std::shared_ptr thing, uint32_t count) { + std::shared_ptr creature = thing->getCreature(); if (creature) { CreatureVector* creatures = getCreatures(); if (creatures) { @@ -1141,7 +1141,7 @@ void Tile::removeThing(Thing* thing, uint32_t count) { return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item) { return; } @@ -1176,8 +1176,8 @@ void Tile::removeThing(Thing* thing, uint32_t count) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, getPosition(), true); - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (std::shared_ptr spectator : spectators) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { oldStackPosVector.push_back(getStackposOfItem(tmpPlayer, item)); } } @@ -1201,8 +1201,8 @@ void Tile::removeThing(Thing* thing, uint32_t count) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, getPosition(), true); - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (std::shared_ptr spectator : spectators) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { oldStackPosVector.push_back(getStackposOfItem(tmpPlayer, item)); } } @@ -1215,12 +1215,12 @@ void Tile::removeThing(Thing* thing, uint32_t count) { } } -void Tile::removeCreature(Creature* creature) { +void Tile::removeCreature(std::shared_ptr creature) { g_game().map.getQTNode(tilePos.x, tilePos.y)->removeCreature(creature); removeThing(creature, 0); } -int32_t Tile::getThingIndex(const Thing* thing) const { +int32_t Tile::getThingIndex(std::shared_ptr thing) const { int32_t n = -1; if (ground) { if (ground == thing) { @@ -1231,7 +1231,7 @@ int32_t Tile::getThingIndex(const Thing* thing) const { const TileItemVector* items = getItemList(); if (items) { - const Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item && item->isAlwaysOnTop()) { for (auto it = items->getBeginTopItem(), end = items->getEndTopItem(); it != end; ++it) { ++n; @@ -1246,7 +1246,7 @@ int32_t Tile::getThingIndex(const Thing* thing) const { if (const CreatureVector* creatures = getCreatures()) { if (thing->getCreature()) { - for (Creature* creature : *creatures) { + for (auto &creature : *creatures) { ++n; if (creature == thing) { return n; @@ -1258,7 +1258,7 @@ int32_t Tile::getThingIndex(const Thing* thing) const { } if (items) { - const Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item && !item->isAlwaysOnTop()) { for (auto it = items->getBeginDownItem(), end = items->getEndDownItem(); it != end; ++it) { ++n; @@ -1271,7 +1271,7 @@ int32_t Tile::getThingIndex(const Thing* thing) const { return -1; } -int32_t Tile::getClientIndexOfCreature(const Player* player, const Creature* creature) const { +int32_t Tile::getClientIndexOfCreature(std::shared_ptr player, std::shared_ptr creature) const { int32_t n; if (ground) { n = 1; @@ -1296,7 +1296,7 @@ int32_t Tile::getClientIndexOfCreature(const Player* player, const Creature* cre return -1; } -int32_t Tile::getStackposOfCreature(const Player* player, const Creature* creature) const { +int32_t Tile::getStackposOfCreature(std::shared_ptr player, std::shared_ptr creature) const { int32_t n; if (ground) { n = 1; @@ -1326,7 +1326,7 @@ int32_t Tile::getStackposOfCreature(const Player* player, const Creature* creatu return -1; } -int32_t Tile::getStackposOfItem(const Player* player, const Item* item) const { +int32_t Tile::getStackposOfItem(std::shared_ptr player, std::shared_ptr item) const { int32_t n = 0; if (ground) { if (ground == item) { @@ -1354,7 +1354,7 @@ int32_t Tile::getStackposOfItem(const Player* player, const Item* item) const { } if (const CreatureVector* creatures = getCreatures()) { - for (const Creature* creature : *creatures) { + for (std::shared_ptr creature : *creatures) { if (player->canSeeCreature(creature)) { if (++n >= 10) { return -1; @@ -1391,7 +1391,7 @@ uint32_t Tile::getItemTypeCount(uint16_t itemId, int32_t subType /*= -1*/) const const TileItemVector* items = getItemList(); if (items) { - for (const Item* item : *items) { + for (std::shared_ptr item : *items) { if (item->getID() == itemId) { count += Item::countByType(item, subType); } @@ -1400,7 +1400,7 @@ uint32_t Tile::getItemTypeCount(uint16_t itemId, int32_t subType /*= -1*/) const return count; } -Thing* Tile::getThing(size_t index) const { +std::shared_ptr Tile::getThing(size_t index) const { if (ground) { if (index == 0) { return ground; @@ -1431,16 +1431,16 @@ Thing* Tile::getThing(size_t index) const { return nullptr; } -void Tile::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link /*= LINK_OWNER*/) { +void Tile::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link /*= LINK_OWNER*/) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, getPosition(), true, true); - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->getPlayer()->postAddNotification(thing, oldParent, index, LINK_NEAR); } // add a reference to this item, it may be deleted after being added (mailbox for example) - Creature* creature = thing->getCreature(); - Item* item; + std::shared_ptr creature = thing->getCreature(); + std::shared_ptr item; if (creature) { creature->incrementReferenceCounter(); item = nullptr; @@ -1453,17 +1453,17 @@ void Tile::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t if (link == LINK_OWNER) { if (hasFlag(TILESTATE_TELEPORT)) { - Teleport* teleport = getTeleportItem(); + std::shared_ptr teleport = getTeleportItem(); if (teleport) { teleport->addThing(thing); } } else if (hasFlag(TILESTATE_TRASHHOLDER)) { - TrashHolder* trashholder = getTrashHolder(); + std::shared_ptr trashholder = getTrashHolder(); if (trashholder) { trashholder->addThing(thing); } } else if (hasFlag(TILESTATE_MAILBOX)) { - Mailbox* mailbox = getMailbox(); + std::shared_ptr mailbox = getMailbox(); if (mailbox) { mailbox->addThing(thing); } @@ -1471,9 +1471,9 @@ void Tile::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t // calling movement scripts if (creature) { - g_moveEvents().onCreatureMove(*creature, *this, MOVE_EVENT_STEP_IN); + g_moveEvents().onCreatureMove(creature, static_self_cast(), MOVE_EVENT_STEP_IN); } else if (item) { - g_moveEvents().onItemMove(*item, *this, true); + g_moveEvents().onItemMove(item, static_self_cast(), true); } } @@ -1485,7 +1485,7 @@ void Tile::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t } } -void Tile::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t) { +void Tile::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, getPosition(), true, true); @@ -1493,35 +1493,35 @@ void Tile::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32 onUpdateTile(spectators); } - for (Creature* spectator : spectators) { + for (auto spectator : spectators) { spectator->getPlayer()->postRemoveNotification(thing, newParent, index, LINK_NEAR); } // calling movement scripts - Creature* creature = thing->getCreature(); + std::shared_ptr creature = thing->getCreature(); if (creature) { - g_moveEvents().onCreatureMove(*creature, *this, MOVE_EVENT_STEP_OUT); + g_moveEvents().onCreatureMove(creature, static_self_cast(), MOVE_EVENT_STEP_OUT); } else { - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item) { - g_moveEvents().onItemMove(*item, *this, false); + g_moveEvents().onItemMove(item, static_self_cast(), false); } } } -void Tile::internalAddThing(Thing* thing) { +void Tile::internalAddThing(std::shared_ptr thing) { internalAddThing(0, thing); if (!thing || !thing->getParent()) { return; } if (auto house = thing->getTile()->getHouse()) { - if (Item* item = thing->getItem()) { - if (item->getParent() != this) { + if (std::shared_ptr item = thing->getItem()) { + if (item->getParent().get() != this) { return; } - Door* door = item->getDoor(); + std::shared_ptr door = item->getDoor(); if (door && door->getDoorId() != 0) { house->addDoor(door); } @@ -1529,7 +1529,7 @@ void Tile::internalAddThing(Thing* thing) { } } -void Tile::internalAddThing(uint32_t, Thing* thing) { +void Tile::internalAddThing(uint32_t, std::shared_ptr thing) { if (!thing) { return; } @@ -1537,15 +1537,15 @@ void Tile::internalAddThing(uint32_t, Thing* thing) { zone->thingAdded(thing); } - thing->setParent(this); + thing->setParent(static_self_cast()); - Creature* creature = thing->getCreature(); + std::shared_ptr creature = thing->getCreature(); if (creature) { g_game().map.clearSpectatorCache(); CreatureVector* creatures = makeCreatures(); creatures->insert(creatures->begin(), creature); } else { - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item == nullptr) { return; } @@ -1586,12 +1586,12 @@ void Tile::internalAddThing(uint32_t, Thing* thing) { } } -void Tile::updateTileFlags(const Item* item) { +void Tile::updateTileFlags(std::shared_ptr item) { resetTileFlags(item); setTileFlags(item); } -void Tile::setTileFlags(const Item* item) { +void Tile::setTileFlags(std::shared_ptr item) { if (!hasFlag(TILESTATE_FLOORCHANGE)) { const ItemType &it = Item::items[item->getID()]; if (it.floorChange != 0) { @@ -1639,7 +1639,7 @@ void Tile::setTileFlags(const Item* item) { setFlag(TILESTATE_BED); } - const Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container && container->getDepotLocker()) { setFlag(TILESTATE_DEPOT); } @@ -1649,7 +1649,7 @@ void Tile::setTileFlags(const Item* item) { } } -void Tile::resetTileFlags(const Item* item) { +void Tile::resetTileFlags(std::shared_ptr item) { const ItemType &it = Item::items[item->getID()]; if (it.floorChange != 0) { resetFlag(TILESTATE_FLOORCHANGE); @@ -1699,7 +1699,7 @@ void Tile::resetTileFlags(const Item* item) { resetFlag(TILESTATE_BED); } - const Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container && container->getDepotLocker()) { resetFlag(TILESTATE_DEPOT); } @@ -1713,27 +1713,27 @@ bool Tile::isMoveableBlocking() const { return !ground || hasFlag(TILESTATE_BLOCKSOLID); } -Item* Tile::getUseItem(int32_t index) const { +std::shared_ptr Tile::getUseItem(int32_t index) const { const TileItemVector* items = getItemList(); if (!items || items->size() == 0) { return ground; } - if (Thing* thing = getThing(index)) { + if (std::shared_ptr thing = getThing(index)) { return thing->getItem(); } return nullptr; } -Item* Tile::getDoorItem() const { +std::shared_ptr Tile::getDoorItem() const { const TileItemVector* items = getItemList(); if (!items || items->size() == 0) { return ground; } if (items) { - for (Item* item : *items) { + for (auto &item : *items) { const ItemType &it = Item::items[item->getID()]; if (it.isDoor()) { return item; diff --git a/src/items/tile.hpp b/src/items/tile.hpp index 3569675f332..bbc24441087 100644 --- a/src/items/tile.hpp +++ b/src/items/tile.hpp @@ -23,9 +23,9 @@ class BedItem; class House; class Zone; -using CreatureVector = std::vector; -using ItemVector = std::vector; -using SpectatorHashSet = phmap::flat_hash_set; +using CreatureVector = std::vector>; +using ItemVector = std::vector>; +using SpectatorHashSet = phmap::flat_hash_set>; class TileItemVector : private ItemVector { public: @@ -77,13 +77,13 @@ class TileItemVector : private ItemVector { uint32_t getDownItemCount() const { return downItemCount; } - inline Item* getTopTopItem() const { + inline std::shared_ptr getTopTopItem() const { if (getTopItemCount() == 0) { return nullptr; } return *(getEndTopItem() - 1); } - inline Item* getTopDownItem() const { + inline std::shared_ptr getTopDownItem() const { if (downItemCount == 0) { return nullptr; } @@ -100,13 +100,13 @@ class TileItemVector : private ItemVector { uint32_t downItemCount = 0; }; -class Tile : public Cylinder { +class Tile : public Cylinder, public SharedObject { public: - static Tile &nullptr_tile; + static const std::shared_ptr &nullptr_tile; Tile(uint16_t x, uint16_t y, uint8_t z) : tilePos(x, y, z) { } virtual ~Tile() { - delete ground; + }; // non-copyable @@ -127,25 +127,28 @@ class Tile : public Cylinder { int32_t getThrowRange() const override final { return 0; } - bool isPushable() const override final { + bool isPushable() override final { return false; } - MagicField* getFieldItem() const; - Teleport* getTeleportItem() const; - TrashHolder* getTrashHolder() const; - Mailbox* getMailbox() const; - BedItem* getBedItem() const; + std::shared_ptr getTile() override final { + return static_self_cast(); + } + std::shared_ptr getFieldItem() const; + std::shared_ptr getTeleportItem() const; + std::shared_ptr getTrashHolder() const; + std::shared_ptr getMailbox() const; + std::shared_ptr getBedItem() const; - Creature* getTopCreature() const; - const Creature* getBottomCreature() const; - Creature* getTopVisibleCreature(const Creature* creature) const; - const Creature* getBottomVisibleCreature(const Creature* creature) const; - Item* getTopTopItem() const; - Item* getTopDownItem() const; + std::shared_ptr getTopCreature() const; + std::shared_ptr getBottomCreature() const; + std::shared_ptr getTopVisibleCreature(std::shared_ptr creature) const; + std::shared_ptr getBottomVisibleCreature(std::shared_ptr creature) const; + std::shared_ptr getTopTopItem() const; + std::shared_ptr getTopDownItem() const; bool isMoveableBlocking() const; - Thing* getTopVisibleThing(const Creature* creature); - Item* getItemByTopOrder(int32_t topOrder); + std::shared_ptr getTopVisibleThing(std::shared_ptr creature); + std::shared_ptr getItemByTopOrder(int32_t topOrder); size_t getThingCount() const { size_t thingCount = getCreatureCount() + getItemCount(); @@ -161,7 +164,7 @@ class Tile : public Cylinder { uint32_t getDownItemCount() const; bool hasProperty(ItemProperty prop) const; - bool hasProperty(const Item* exclude, ItemProperty prop) const; + bool hasProperty(std::shared_ptr exclude, ItemProperty prop) const; bool hasFlag(uint32_t flag) const { return hasBitSet(flag, this->flags); @@ -191,44 +194,44 @@ class Tile : public Cylinder { bool hasHeight(uint32_t n) const; - std::string getDescription(int32_t lookDistance) const override final; + std::string getDescription(int32_t lookDistance) override final; - int32_t getClientIndexOfCreature(const Player* player, const Creature* creature) const; - int32_t getStackposOfCreature(const Player* player, const Creature* creature) const; - int32_t getStackposOfItem(const Player* player, const Item* item) const; + int32_t getClientIndexOfCreature(std::shared_ptr player, std::shared_ptr creature) const; + int32_t getStackposOfCreature(std::shared_ptr player, std::shared_ptr creature) const; + int32_t getStackposOfItem(std::shared_ptr player, std::shared_ptr item) const; // cylinder implementations - ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; - ReturnValue queryMaxCount(int32_t index, const Thing &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) const override final; - ReturnValue queryRemove(const Thing &thing, uint32_t count, uint32_t tileFlags, Creature* actor = nullptr) const override; - Tile* queryDestination(int32_t &index, const Thing &thing, Item** destItem, uint32_t &flags) override; + ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; + ReturnValue queryMaxCount(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) override final; + ReturnValue queryRemove(const std::shared_ptr &thing, uint32_t count, uint32_t tileFlags, std::shared_ptr actor = nullptr) override; + std::shared_ptr queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &flags) override; - std::vector getSurroundingTiles() const; + std::vector> getSurroundingTiles(); - void addThing(Thing* thing) override final; - void addThing(int32_t index, Thing* thing) override; + void addThing(std::shared_ptr thing) override final; + void addThing(int32_t index, std::shared_ptr thing) override; - void updateTileFlags(const Item* item); - void updateThing(Thing* thing, uint16_t itemId, uint32_t count) override final; - void replaceThing(uint32_t index, Thing* thing) override final; + void updateTileFlags(std::shared_ptr item); + void updateThing(std::shared_ptr thing, uint16_t itemId, uint32_t count) override final; + void replaceThing(uint32_t index, std::shared_ptr thing) override final; - void removeThing(Thing* thing, uint32_t count) override final; + void removeThing(std::shared_ptr thing, uint32_t count) override final; - void removeCreature(Creature* creature); + void removeCreature(std::shared_ptr creature); - int32_t getThingIndex(const Thing* thing) const override final; + int32_t getThingIndex(std::shared_ptr thing) const override final; size_t getFirstIndex() const override final; size_t getLastIndex() const override final; uint32_t getItemTypeCount(uint16_t itemId, int32_t subType = -1) const override final; - Thing* getThing(size_t index) const override final; + std::shared_ptr getThing(size_t index) const override final; - void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override final; - void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override final; + void postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override final; + void postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override final; - void internalAddThing(Thing* thing) override; - void virtual internalAddThing(uint32_t index, Thing* thing) override; + void internalAddThing(std::shared_ptr thing) override; + void virtual internalAddThing(uint32_t index, std::shared_ptr thing) override; - const Position &getPosition() const override final { + const Position &getPosition() override final { return tilePos; } @@ -236,29 +239,29 @@ class Tile : public Cylinder { return false; } - Item* getUseItem(int32_t index) const; - Item* getDoorItem() const; + std::shared_ptr getUseItem(int32_t index) const; + std::shared_ptr getDoorItem() const; - Item* getGround() const { + std::shared_ptr getGround() const { return ground; } - void setGround(Item* item) { + void setGround(std::shared_ptr item) { ground = item; } private: - void onAddTileItem(Item* item); - void onUpdateTileItem(Item* oldItem, const ItemType &oldType, Item* newItem, const ItemType &newType); - void onRemoveTileItem(const SpectatorHashSet &spectators, const std::vector &oldStackPosVector, Item* item); + void onAddTileItem(std::shared_ptr item); + void onUpdateTileItem(std::shared_ptr oldItem, const ItemType &oldType, std::shared_ptr newItem, const ItemType &newType); + void onRemoveTileItem(const SpectatorHashSet &spectators, const std::vector &oldStackPosVector, std::shared_ptr item); void onUpdateTile(const SpectatorHashSet &spectators); - void setTileFlags(const Item* item); - void resetTileFlags(const Item* item); + void setTileFlags(std::shared_ptr item); + void resetTileFlags(std::shared_ptr item); bool hasHarmfulField() const; ReturnValue checkNpcCanWalkIntoTile() const; protected: - Item* ground = nullptr; + std::shared_ptr ground = nullptr; Position tilePos; uint32_t flags = 0; std::shared_ptr zone; @@ -275,7 +278,7 @@ class DynamicTile : public Tile { DynamicTile(uint16_t x, uint16_t y, uint8_t z) : Tile(x, y, z) { } ~DynamicTile() { - for (Item* item : items) { + for (std::shared_ptr item : items) { item->decrementReferenceCounter(); } } @@ -316,7 +319,7 @@ class StaticTile final : public Tile { Tile(x, y, z) { } ~StaticTile() { if (items) { - for (Item* item : *items) { + for (auto &item : *items) { item->decrementReferenceCounter(); } } diff --git a/src/items/trashholder.cpp b/src/items/trashholder.cpp index 353efabdcff..024bb31fcd0 100644 --- a/src/items/trashholder.cpp +++ b/src/items/trashholder.cpp @@ -12,44 +12,44 @@ #include "items/trashholder.hpp" #include "game/game.hpp" -ReturnValue TrashHolder::queryAdd(int32_t, const Thing &, uint32_t, uint32_t, Creature*) const { +ReturnValue TrashHolder::queryAdd(int32_t, const std::shared_ptr &, uint32_t, uint32_t, std::shared_ptr) { return RETURNVALUE_NOERROR; } -ReturnValue TrashHolder::queryMaxCount(int32_t, const Thing &, uint32_t queryCount, uint32_t &maxQueryCount, uint32_t) const { +ReturnValue TrashHolder::queryMaxCount(int32_t, const std::shared_ptr &, uint32_t queryCount, uint32_t &maxQueryCount, uint32_t) { maxQueryCount = std::max(1, queryCount); return RETURNVALUE_NOERROR; } -ReturnValue TrashHolder::queryRemove(const Thing &, uint32_t, uint32_t, Creature* /*= nullptr*/) const { +ReturnValue TrashHolder::queryRemove(const std::shared_ptr &, uint32_t, uint32_t, std::shared_ptr /*= nullptr*/) { return RETURNVALUE_NOTPOSSIBLE; } -Cylinder* TrashHolder::queryDestination(int32_t &, const Thing &, Item**, uint32_t &) { - return this; +std::shared_ptr TrashHolder::queryDestination(int32_t &, const std::shared_ptr &, std::shared_ptr*, uint32_t &) { + return static_self_cast(); } -void TrashHolder::addThing(Thing* thing) { +void TrashHolder::addThing(std::shared_ptr thing) { return addThing(0, thing); } -void TrashHolder::addThing(int32_t, Thing* thing) { +void TrashHolder::addThing(int32_t, std::shared_ptr thing) { if (!thing) { return; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (!item) { return; } - if (item == this || !item->hasProperty(CONST_PROP_MOVEABLE)) { + if (item.get() == this || !item->hasProperty(CONST_PROP_MOVEABLE)) { return; } const ItemType &it = Item::items[id]; if (item->isHangable() && it.isGroundTile()) { - Tile* tile = dynamic_cast(getParent()); + std::shared_ptr tile = std::dynamic_pointer_cast(getParent()); if (tile && tile->hasFlag(TILESTATE_SUPPORTS_HANGABLE)) { return; } @@ -65,22 +65,22 @@ void TrashHolder::addThing(int32_t, Thing* thing) { } } -void TrashHolder::updateThing(Thing*, uint16_t, uint32_t) { +void TrashHolder::updateThing(std::shared_ptr, uint16_t, uint32_t) { // } -void TrashHolder::replaceThing(uint32_t, Thing*) { +void TrashHolder::replaceThing(uint32_t, std::shared_ptr) { // } -void TrashHolder::removeThing(Thing*, uint32_t) { +void TrashHolder::removeThing(std::shared_ptr, uint32_t) { // } -void TrashHolder::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t) { +void TrashHolder::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { getParent()->postAddNotification(thing, oldParent, index, LINK_PARENT); } -void TrashHolder::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t) { +void TrashHolder::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { getParent()->postRemoveNotification(thing, newParent, index, LINK_PARENT); } diff --git a/src/items/trashholder.hpp b/src/items/trashholder.hpp index cdc4659499f..5043e897d1e 100644 --- a/src/items/trashholder.hpp +++ b/src/items/trashholder.hpp @@ -17,27 +17,24 @@ class TrashHolder final : public Item, public Cylinder { explicit TrashHolder(uint16_t itemId) : Item(itemId) { } - TrashHolder* getTrashHolder() override { - return this; - } - const TrashHolder* getTrashHolder() const override { - return this; + std::shared_ptr getTrashHolder() override { + return static_self_cast(); } // cylinder implementations - ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; - ReturnValue queryMaxCount(int32_t index, const Thing &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) const override; - ReturnValue queryRemove(const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; - Cylinder* queryDestination(int32_t &index, const Thing &thing, Item** destItem, uint32_t &flags) override; + ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; + ReturnValue queryMaxCount(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t &maxQueryCount, uint32_t flags) override; + ReturnValue queryRemove(const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; + std::shared_ptr queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &flags) override; - void addThing(Thing* thing) override; - void addThing(int32_t index, Thing* thing) override; + void addThing(std::shared_ptr thing) override; + void addThing(int32_t index, std::shared_ptr thing) override; - void updateThing(Thing* thing, uint16_t itemId, uint32_t count) override; - void replaceThing(uint32_t index, Thing* thing) override; + void updateThing(std::shared_ptr thing, uint16_t itemId, uint32_t count) override; + void replaceThing(uint32_t index, std::shared_ptr thing) override; - void removeThing(Thing* thing, uint32_t count) override; + void removeThing(std::shared_ptr thing, uint32_t count) override; - void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; - void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; + void postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t link = LINK_OWNER) override; }; diff --git a/src/items/weapons/weapons.cpp b/src/items/weapons/weapons.cpp index aae19c09f74..995b71518c0 100644 --- a/src/items/weapons/weapons.cpp +++ b/src/items/weapons/weapons.cpp @@ -17,7 +17,7 @@ Weapons::Weapons() = default; Weapons::~Weapons() = default; -const Weapon* Weapons::getWeapon(const Item* item) const { +const Weapon* Weapons::getWeapon(std::shared_ptr item) const { if (!item) { return nullptr; } @@ -57,7 +57,7 @@ void Weapon::configureWeapon(const ItemType &it) { id = it.id; } -int32_t Weapon::playerWeaponCheck(Player* player, Creature* target, uint8_t shootRange) const { +int32_t Weapon::playerWeaponCheck(std::shared_ptr player, std::shared_ptr target, uint8_t shootRange) const { const Position &playerPos = player->getPosition(); const Position &targetPos = target->getPosition(); if (playerPos.z != targetPos.z) { @@ -107,7 +107,7 @@ int32_t Weapon::playerWeaponCheck(Player* player, Creature* target, uint8_t shoo return 100; } -bool Weapon::useWeapon(Player* player, Item* item, Creature* target) const { +bool Weapon::useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const { int32_t damageModifier = playerWeaponCheck(player, target, item->getShootRange()); if (damageModifier == 0) { return false; @@ -117,7 +117,7 @@ bool Weapon::useWeapon(Player* player, Item* item, Creature* target) const { return true; } -CombatDamage Weapon::getCombatDamage(CombatDamage combat, Player* player, Item* item, int32_t damageModifier) const { +CombatDamage Weapon::getCombatDamage(CombatDamage combat, std::shared_ptr player, std::shared_ptr item, int32_t damageModifier) const { // Local variables uint32_t level = player->getLevel(); int16_t elementalAttack = getElementDamageValue(); @@ -140,7 +140,7 @@ CombatDamage Weapon::getCombatDamage(CombatDamage combat, Player* player, Item* return combat; } -bool Weapon::useFist(Player* player, Creature* target) { +bool Weapon::useFist(std::shared_ptr player, std::shared_ptr target) { if (!Position::areInRange<1, 1>(player->getPosition(), target->getPosition())) { return false; } @@ -170,7 +170,7 @@ bool Weapon::useFist(Player* player, Creature* target) { return true; } -void Weapon::internalUseWeapon(Player* player, Item* item, Creature* target, int32_t damageModifier, int32_t cleavePercent) const { +void Weapon::internalUseWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target, int32_t damageModifier, int32_t cleavePercent) const { if (player) { if (params.soundCastEffect == SoundEffect_t::SILENCE) { g_game().sendDoubleSoundEffect(player->getPosition(), player->getHitSoundEffect(), player->getAttackSoundEffect(), player); @@ -225,7 +225,7 @@ void Weapon::internalUseWeapon(Player* player, Item* item, Creature* target, int onUsedWeapon(player, item, target->getTile()); } -void Weapon::internalUseWeapon(Player* player, Item* item, Tile* tile) const { +void Weapon::internalUseWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr tile) const { if (isLoadedCallback()) { LuaVariant var; var.type = VARIANT_TARGETPOSITION; @@ -239,7 +239,7 @@ void Weapon::internalUseWeapon(Player* player, Item* item, Tile* tile) const { onUsedWeapon(player, item, tile); } -void Weapon::onUsedWeapon(Player* player, Item* item, Tile* destTile) const { +void Weapon::onUsedWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr destTile) const { if (!player->hasFlag(PlayerFlags_t::NotGainSkill)) { skills_t skillType; uint32_t skillPoint; @@ -293,7 +293,7 @@ void Weapon::onUsedWeapon(Player* player, Item* item, Tile* destTile) const { } } -uint32_t Weapon::getManaCost(const Player* player) const { +uint32_t Weapon::getManaCost(std::shared_ptr player) const { if (mana != 0) { return mana; } @@ -305,7 +305,7 @@ uint32_t Weapon::getManaCost(const Player* player) const { return (player->getMaxMana() * manaPercent) / 100; } -int32_t Weapon::getHealthCost(const Player* player) const { +int32_t Weapon::getHealthCost(std::shared_ptr player) const { if (health != 0) { return health; } @@ -317,7 +317,7 @@ int32_t Weapon::getHealthCost(const Player* player) const { return (player->getMaxHealth() * healthPercent) / 100; } -bool Weapon::executeUseWeapon(Player* player, const LuaVariant &var) const { +bool Weapon::executeUseWeapon(std::shared_ptr player, const LuaVariant &var) const { // onUseWeapon(player, var) if (!getScriptInterface()->reserveScriptEnv()) { std::string playerName = player ? player->getName() : "Player nullptr"; @@ -340,7 +340,7 @@ bool Weapon::executeUseWeapon(Player* player, const LuaVariant &var) const { return getScriptInterface()->callFunction(2); } -void Weapon::decrementItemCount(Item* item) { +void Weapon::decrementItemCount(std::shared_ptr item) { uint16_t count = item->getItemCount(); if (count > 1) { g_game().transformItem(item, item->getID(), count - 1); @@ -370,7 +370,7 @@ void WeaponMelee::configureWeapon(const ItemType &it) { Weapon::configureWeapon(it); } -bool WeaponMelee::useWeapon(Player* player, Item* item, Creature* target) const { +bool WeaponMelee::useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const { int32_t damageModifier = playerWeaponCheck(player, target, item->getShootRange()); if (damageModifier == 0) { return false; @@ -402,12 +402,12 @@ bool WeaponMelee::useWeapon(Player* player, Item* item, Creature* target) const secondCleaveTargetPos.y++; } } - Tile* firstTile = g_game().map.getTile(firstCleaveTargetPos.x, firstCleaveTargetPos.y, firstCleaveTargetPos.z); - Tile* secondTile = g_game().map.getTile(secondCleaveTargetPos.x, secondCleaveTargetPos.y, secondCleaveTargetPos.z); + std::shared_ptr firstTile = g_game().map.getTile(firstCleaveTargetPos.x, firstCleaveTargetPos.y, firstCleaveTargetPos.z); + std::shared_ptr secondTile = g_game().map.getTile(secondCleaveTargetPos.x, secondCleaveTargetPos.y, secondCleaveTargetPos.z); if (firstTile) { if (CreatureVector* tileCreatures = firstTile->getCreatures()) { - for (Creature* tileCreature : *tileCreatures) { + for (auto &tileCreature : *tileCreatures) { if (tileCreature->getMonster() || (tileCreature->getPlayer() && !player->hasSecureMode())) { internalUseWeapon(player, item, tileCreature, damageModifier, cleavePercent); } @@ -416,7 +416,7 @@ bool WeaponMelee::useWeapon(Player* player, Item* item, Creature* target) const } if (secondTile) { if (CreatureVector* tileCreatures = secondTile->getCreatures()) { - for (Creature* tileCreature : *tileCreatures) { + for (auto &tileCreature : *tileCreatures) { if (tileCreature->getMonster() || (tileCreature->getPlayer() && !player->hasSecureMode())) { internalUseWeapon(player, item, tileCreature, damageModifier, cleavePercent); } @@ -430,7 +430,7 @@ bool WeaponMelee::useWeapon(Player* player, Item* item, Creature* target) const return true; } -bool WeaponMelee::getSkillType(const Player* player, const Item* item, skills_t &skill, uint32_t &skillpoint) const { +bool WeaponMelee::getSkillType(std::shared_ptr player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const { if (player->getAddAttackSkill() && player->getLastAttackBlockType() != BLOCK_IMMUNITY) { skillpoint = 1; } else { @@ -460,7 +460,7 @@ bool WeaponMelee::getSkillType(const Player* player, const Item* item, skills_t return false; } -int32_t WeaponMelee::getElementDamage(const Player* player, const Creature*, const Item* item) const { +int32_t WeaponMelee::getElementDamage(std::shared_ptr player, std::shared_ptr, std::shared_ptr item) const { if (elementType == COMBAT_NONE) { return 0; } @@ -479,7 +479,7 @@ int16_t WeaponMelee::getElementDamageValue() const { return elementDamage; } -int32_t WeaponMelee::getWeaponDamage(const Player* player, const Creature*, const Item* item, bool maxDamage /*= false*/) const { +int32_t WeaponMelee::getWeaponDamage(std::shared_ptr player, std::shared_ptr, std::shared_ptr item, bool maxDamage /*= false*/) const { using namespace std; int32_t attackSkill = player->getWeaponSkill(item); int32_t attackValue = std::max(0, item->getAttack()); @@ -519,11 +519,11 @@ void WeaponDistance::configureWeapon(const ItemType &it) { Weapon::configureWeapon(it); } -bool WeaponDistance::useWeapon(Player* player, Item* item, Creature* target) const { +bool WeaponDistance::useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const { int32_t damageModifier; const ItemType &it = Item::items[id]; if (it.weaponType == WEAPON_AMMO) { - Item* mainWeaponItem = player->getWeapon(true); + std::shared_ptr mainWeaponItem = player->getWeapon(true); const Weapon* mainWeapon = g_weapons().getWeapon(mainWeaponItem); if (mainWeapon) { damageModifier = mainWeapon->playerWeaponCheck(player, target, mainWeaponItem->getShootRange()); @@ -547,7 +547,7 @@ bool WeaponDistance::useWeapon(Player* player, Item* item, Creature* target) con int32_t damageY = player->getPerfectShotDamage(distanceY); if (it.weaponType == WEAPON_DISTANCE) { - Item* quiver = player->getInventoryItem(CONST_SLOT_RIGHT); + std::shared_ptr quiver = player->getInventoryItem(CONST_SLOT_RIGHT); if (quiver && quiver->getWeaponType()) { if (quiver->getPerfectShotRange() == distanceX) { damageX -= quiver->getPerfectShotDamage(); @@ -660,7 +660,7 @@ bool WeaponDistance::useWeapon(Player* player, Item* item, Creature* target) con } if (!perfectShot && item->getWeaponType() == WEAPON_AMMO) { - Item* bow = player->getWeapon(true); + std::shared_ptr bow = player->getWeapon(true); if (bow && bow->getHitChance() != 0) { chance += bow->getHitChance(); } @@ -670,7 +670,7 @@ bool WeaponDistance::useWeapon(Player* player, Item* item, Creature* target) con Weapon::internalUseWeapon(player, item, target, damageModifier); } else { // miss target - Tile* destTile = target->getTile(); + std::shared_ptr destTile = target->getTile(); if (!Position::areInRange<1, 1, 0>(player->getPosition(), target->getPosition())) { static std::vector> destList { @@ -682,7 +682,7 @@ bool WeaponDistance::useWeapon(Player* player, Item* item, Creature* target) con for (const auto &dir : destList) { // Blocking tiles or tiles without ground ain't valid targets for spears - Tile* tmpTile = g_game().map.getTile(static_cast(destPos.x + dir.first), static_cast(destPos.y + dir.second), destPos.z); + auto tmpTile = g_game().map.getTile(static_cast(destPos.x + dir.first), static_cast(destPos.y + dir.second), destPos.z); if (tmpTile && !tmpTile->hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) && tmpTile->getGround() != nullptr) { destTile = tmpTile; break; @@ -695,14 +695,14 @@ bool WeaponDistance::useWeapon(Player* player, Item* item, Creature* target) con return true; } -int32_t WeaponDistance::getElementDamage(const Player* player, const Creature* target, const Item* item) const { +int32_t WeaponDistance::getElementDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const { if (elementType == COMBAT_NONE) { return 0; } int32_t attackValue = elementDamage; if (item->getWeaponType() == WEAPON_AMMO) { - Item* weapon = player->getWeapon(true); + std::shared_ptr weapon = player->getWeapon(true); if (weapon) { attackValue += item->getAttack(); attackValue += weapon->getAttack(); @@ -730,12 +730,12 @@ int16_t WeaponDistance::getElementDamageValue() const { return elementDamage; } -int32_t WeaponDistance::getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage /*= false*/) const { +int32_t WeaponDistance::getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage /*= false*/) const { int32_t attackValue = item->getAttack(); bool hasElement = false; if (item->getWeaponType() == WEAPON_AMMO) { - Item* weapon = player->getWeapon(true); + std::shared_ptr weapon = player->getWeapon(true); if (weapon) { const ItemType &it = Item::items[item->getID()]; if (it.abilities && it.abilities->elementDamage != 0) { @@ -772,7 +772,7 @@ int32_t WeaponDistance::getWeaponDamage(const Player* player, const Creature* ta return -normal_random(minValue, (maxValue * static_cast(player->getVocation()->distDamageMultiplier))); } -bool WeaponDistance::getSkillType(const Player* player, const Item*, skills_t &skill, uint32_t &skillpoint) const { +bool WeaponDistance::getSkillType(std::shared_ptr player, std::shared_ptr, skills_t &skill, uint32_t &skillpoint) const { skill = SKILL_DISTANCE; if (player->getAddAttackSkill()) { @@ -805,7 +805,7 @@ void WeaponWand::configureWeapon(const ItemType &it) { Weapon::configureWeapon(it); } -int32_t WeaponWand::getWeaponDamage(const Player*, const Creature*, const Item*, bool maxDamage /*= false*/) const { +int32_t WeaponWand::getWeaponDamage(std::shared_ptr, std::shared_ptr, std::shared_ptr, bool maxDamage /*= false*/) const { if (maxDamage) { return -maxChange; } diff --git a/src/items/weapons/weapons.hpp b/src/items/weapons/weapons.hpp index 7dd9ba27b55..90785983e17 100644 --- a/src/items/weapons/weapons.hpp +++ b/src/items/weapons/weapons.hpp @@ -36,7 +36,7 @@ class Weapons final : public Scripts { return inject(); } - const Weapon* getWeapon(const Item* item) const; + const Weapon* getWeapon(std::shared_ptr item) const; static int32_t getMaxMeleeDamage(int32_t attackSkill, int32_t attackValue); static int32_t getMaxWeaponDamage(uint32_t level, int32_t attackSkill, int32_t attackValue, float attackFactor, bool isMelee); @@ -59,15 +59,15 @@ class Weapon : public Script { return false; } - int32_t playerWeaponCheck(Player* player, Creature* target, uint8_t shootRange) const; - static bool useFist(Player* player, Creature* target); - virtual bool useWeapon(Player* player, Item* item, Creature* target) const; + int32_t playerWeaponCheck(std::shared_ptr player, std::shared_ptr target, uint8_t shootRange) const; + static bool useFist(std::shared_ptr player, std::shared_ptr target); + virtual bool useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const; - virtual int32_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const = 0; - virtual int32_t getElementDamage(const Player* player, const Creature* target, const Item* item) const = 0; + virtual int32_t getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const = 0; + virtual int32_t getElementDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const = 0; virtual CombatType_t getElementType() const = 0; virtual int16_t getElementDamageValue() const = 0; - virtual CombatDamage getCombatDamage(CombatDamage combat, Player* player, Item* item, int32_t damageModifier) const; + virtual CombatDamage getCombatDamage(CombatDamage combat, std::shared_ptr player, std::shared_ptr item, int32_t damageModifier) const; uint16_t getID() const { return id; } @@ -174,17 +174,17 @@ class Weapon : public Script { } protected: - void internalUseWeapon(Player* player, Item* item, Creature* target, int32_t damageModifier, int32_t cleavePercent = 0) const; - void internalUseWeapon(Player* player, Item* item, Tile* tile) const; + void internalUseWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target, int32_t damageModifier, int32_t cleavePercent = 0) const; + void internalUseWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr tile) const; private: - virtual bool getSkillType(const Player*, const Item*, skills_t &, uint32_t &) const { + virtual bool getSkillType(std::shared_ptr, std::shared_ptr, skills_t &, uint32_t &) const { return false; } - uint32_t getManaCost(const Player* player) const; - int32_t getHealthCost(const Player* player) const; - bool executeUseWeapon(Player* player, const LuaVariant &var) const; + uint32_t getManaCost(std::shared_ptr player) const; + int32_t getHealthCost(std::shared_ptr player) const; + bool executeUseWeapon(std::shared_ptr player, const LuaVariant &var) const; uint16_t id = 0; @@ -202,9 +202,9 @@ class Weapon : public Script { bool wieldUnproperly = false; std::string vocationString = ""; - void onUsedWeapon(Player* player, Item* item, Tile* destTile) const; + void onUsedWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr destTile) const; - static void decrementItemCount(Item* item); + static void decrementItemCount(std::shared_ptr item); WeaponAction_t action = WEAPONACTION_NONE; CombatParams params; @@ -228,17 +228,17 @@ class WeaponMelee final : public Weapon { void configureWeapon(const ItemType &it) override; - bool useWeapon(Player* player, Item* item, Creature* target) const override; + bool useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const override; - int32_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const override; - int32_t getElementDamage(const Player* player, const Creature* target, const Item* item) const override; + int32_t getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; + int32_t getElementDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const override; CombatType_t getElementType() const override { return elementType; } virtual int16_t getElementDamageValue() const override; private: - bool getSkillType(const Player* player, const Item* item, skills_t &skill, uint32_t &skillpoint) const override; + bool getSkillType(std::shared_ptr player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const override; uint16_t elementDamage = 0; CombatType_t elementType = COMBAT_NONE; }; @@ -256,17 +256,17 @@ class WeaponDistance final : public Weapon { return true; } - bool useWeapon(Player* player, Item* item, Creature* target) const override; + bool useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const override; - int32_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const override; - int32_t getElementDamage(const Player* player, const Creature* target, const Item* item) const override; + int32_t getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; + int32_t getElementDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const override; CombatType_t getElementType() const override { return elementType; } virtual int16_t getElementDamageValue() const override; private: - bool getSkillType(const Player* player, const Item* item, skills_t &skill, uint32_t &skillpoint) const override; + bool getSkillType(std::shared_ptr player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const override; CombatType_t elementType = COMBAT_NONE; uint16_t elementDamage = 0; @@ -282,8 +282,8 @@ class WeaponWand final : public Weapon { void configureWeapon(const ItemType &it) override; - int32_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const override; - int32_t getElementDamage(const Player*, const Creature*, const Item*) const override { + int32_t getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; + int32_t getElementDamage(std::shared_ptr, std::shared_ptr, std::shared_ptr) const override { return 0; } CombatType_t getElementType() const override { @@ -299,7 +299,7 @@ class WeaponWand final : public Weapon { } private: - bool getSkillType(const Player*, const Item*, skills_t &, uint32_t &) const override { + bool getSkillType(std::shared_ptr, std::shared_ptr, skills_t &, uint32_t &) const override { return false; } diff --git a/src/lua/callbacks/creaturecallback.cpp b/src/lua/callbacks/creaturecallback.cpp index 577d26e7aa4..5a099f434be 100644 --- a/src/lua/callbacks/creaturecallback.cpp +++ b/src/lua/callbacks/creaturecallback.cpp @@ -34,12 +34,12 @@ bool CreatureCallback::startScriptInterface(int32_t scriptId) { return true; } -void CreatureCallback::pushSpecificCreature(Creature* creature) { - if (Npc* npc = creature->getNpc()) { +void CreatureCallback::pushSpecificCreature(std::shared_ptr creature) { + if (std::shared_ptr npc = creature->getNpc()) { LuaScriptInterface::pushUserdata(L, npc); - } else if (Monster* monster = creature->getMonster()) { + } else if (std::shared_ptr monster = creature->getMonster()) { LuaScriptInterface::pushUserdata(L, monster); - } else if (Player* player = creature->getPlayer()) { + } else if (std::shared_ptr player = creature->getPlayer()) { LuaScriptInterface::pushUserdata(L, player); } else { return; @@ -49,7 +49,7 @@ void CreatureCallback::pushSpecificCreature(Creature* creature) { LuaScriptInterface::setMetatable(L, -1, getCreatureClass(creature)); } -std::string CreatureCallback::getCreatureClass(Creature* creature) { +std::string CreatureCallback::getCreatureClass(std::shared_ptr creature) { if (creature->getNpc()) { return "Npc"; } diff --git a/src/lua/callbacks/creaturecallback.hpp b/src/lua/callbacks/creaturecallback.hpp index fccc921b472..16d91d0c966 100644 --- a/src/lua/callbacks/creaturecallback.hpp +++ b/src/lua/callbacks/creaturecallback.hpp @@ -16,19 +16,19 @@ class Creature; class CreatureCallback { public: - CreatureCallback(LuaScriptInterface* scriptInterface, Creature* targetCreature) : + CreatureCallback(LuaScriptInterface* scriptInterface, std::shared_ptr targetCreature) : scriptInterface(scriptInterface), targetCreature(targetCreature) {}; ~CreatureCallback() { } bool startScriptInterface(int32_t scriptId); - void pushSpecificCreature(Creature* creature); + void pushSpecificCreature(std::shared_ptr creature); bool persistLuaState() { return params > 0 && scriptInterface->callFunction(params); } - void pushCreature(Creature* creature) { + void pushCreature(std::shared_ptr creature) { params++; LuaScriptInterface::pushUserdata(L, creature); LuaScriptInterface::setCreatureMetatable(L, -1, creature); @@ -55,11 +55,11 @@ class CreatureCallback { } protected: - static std::string getCreatureClass(Creature* creature); + static std::string getCreatureClass(std::shared_ptr creature); private: LuaScriptInterface* scriptInterface; - Creature* targetCreature; + std::shared_ptr targetCreature; uint32_t params = 0; lua_State* L = nullptr; }; diff --git a/src/lua/callbacks/event_callback.cpp b/src/lua/callbacks/event_callback.cpp index 4ad8358d005..e9ac54f15e6 100644 --- a/src/lua/callbacks/event_callback.cpp +++ b/src/lua/callbacks/event_callback.cpp @@ -49,7 +49,7 @@ void EventCallback::setType(EventCallback_t type) { // Lua functions // Creature -bool EventCallback::creatureOnChangeOutfit(Creature* creature, const Outfit_t &outfit) const { +bool EventCallback::creatureOnChangeOutfit(std::shared_ptr creature, const Outfit_t &outfit) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::creatureOnChangeOutfit - Creature {}] " "Call stack overflow. Too many lua script calls being nested.", @@ -71,7 +71,7 @@ bool EventCallback::creatureOnChangeOutfit(Creature* creature, const Outfit_t &o return getScriptInterface()->callFunction(2); } -ReturnValue EventCallback::creatureOnAreaCombat(Creature* creature, Tile* tile, bool aggressive) const { +ReturnValue EventCallback::creatureOnAreaCombat(std::shared_ptr creature, std::shared_ptr tile, bool aggressive) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::creatureOnAreaCombat - " "Creature {} on tile position {}] " @@ -111,7 +111,7 @@ ReturnValue EventCallback::creatureOnAreaCombat(Creature* creature, Tile* tile, return returnValue; } -ReturnValue EventCallback::creatureOnTargetCombat(Creature* creature, Creature* target) const { +ReturnValue EventCallback::creatureOnTargetCombat(std::shared_ptr creature, std::shared_ptr target) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::creatureOnTargetCombat - " "Creature {} target {}] " @@ -149,7 +149,7 @@ ReturnValue EventCallback::creatureOnTargetCombat(Creature* creature, Creature* return returnValue; } -void EventCallback::creatureOnHear(Creature* creature, Creature* speaker, const std::string &words, SpeakClasses type) const { +void EventCallback::creatureOnHear(std::shared_ptr creature, std::shared_ptr speaker, const std::string &words, SpeakClasses type) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::creatureOnHear - " "Creature {} speaker {}] " @@ -176,7 +176,7 @@ void EventCallback::creatureOnHear(Creature* creature, Creature* speaker, const getScriptInterface()->callVoidFunction(4); } -void EventCallback::creatureOnDrainHealth(Creature* creature, Creature* attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) const { +void EventCallback::creatureOnDrainHealth(std::shared_ptr creature, std::shared_ptr attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::creatureOnDrainHealth - " "Creature {} attacker {}] " @@ -228,7 +228,7 @@ void EventCallback::creatureOnDrainHealth(Creature* creature, Creature* attacker } // Party -bool EventCallback::partyOnJoin(Party* party, Player* player) const { +bool EventCallback::partyOnJoin(Party* party, std::shared_ptr player) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::partyOnJoin - " "Player {}] " @@ -252,7 +252,7 @@ bool EventCallback::partyOnJoin(Party* party, Player* player) const { return getScriptInterface()->callFunction(2); } -bool EventCallback::partyOnLeave(Party* party, Player* player) const { +bool EventCallback::partyOnLeave(Party* party, std::shared_ptr player) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::partyOnLeave - " "Player {}] " @@ -324,7 +324,7 @@ void EventCallback::partyOnShareExperience(Party* party, uint64_t &exp) const { } // Player -bool EventCallback::playerOnBrowseField(Player* player, const Position &position) const { +bool EventCallback::playerOnBrowseField(std::shared_ptr player, const Position &position) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnBrowseField - " "Player {}] " @@ -347,7 +347,7 @@ bool EventCallback::playerOnBrowseField(Player* player, const Position &position return getScriptInterface()->callFunction(2); } -void EventCallback::playerOnLook(Player* player, const Position &position, Thing* thing, uint8_t stackpos, int32_t lookDistance) const { +void EventCallback::playerOnLook(std::shared_ptr player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLook - " "Player {}] " @@ -365,10 +365,10 @@ void EventCallback::playerOnLook(Player* player, const Position &position, Thing LuaScriptInterface::pushUserdata(L, player); LuaScriptInterface::setMetatable(L, -1, "Player"); - if (Creature* creature = thing->getCreature()) { + if (std::shared_ptr creature = thing->getCreature()) { LuaScriptInterface::pushUserdata(L, creature); LuaScriptInterface::setCreatureMetatable(L, -1, creature); - } else if (Item* item = thing->getItem()) { + } else if (std::shared_ptr item = thing->getItem()) { LuaScriptInterface::pushUserdata(L, item); LuaScriptInterface::setItemMetatable(L, -1, item); } else { @@ -381,7 +381,7 @@ void EventCallback::playerOnLook(Player* player, const Position &position, Thing getScriptInterface()->callVoidFunction(4); } -void EventCallback::playerOnLookInBattleList(Player* player, Creature* creature, int32_t lookDistance) const { +void EventCallback::playerOnLookInBattleList(std::shared_ptr player, std::shared_ptr creature, int32_t lookDistance) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLookInBattleList - " "Player {}] " @@ -407,7 +407,7 @@ void EventCallback::playerOnLookInBattleList(Player* player, Creature* creature, getScriptInterface()->callVoidFunction(3); } -void EventCallback::playerOnLookInTrade(Player* player, Player* partner, Item* item, int32_t lookDistance) const { +void EventCallback::playerOnLookInTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr item, int32_t lookDistance) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLookInTrade - " "Player {}] " @@ -436,7 +436,7 @@ void EventCallback::playerOnLookInTrade(Player* player, Player* partner, Item* i getScriptInterface()->callVoidFunction(4); } -bool EventCallback::playerOnLookInShop(Player* player, const ItemType* itemType, uint8_t count) const { +bool EventCallback::playerOnLookInShop(std::shared_ptr player, const ItemType* itemType, uint8_t count) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLookInShop - " "Player {} itemType {}] " @@ -462,7 +462,7 @@ bool EventCallback::playerOnLookInShop(Player* player, const ItemType* itemType, return getScriptInterface()->callFunction(3); } -void EventCallback::playerOnRemoveCount(Player* player, Item* item) const { +void EventCallback::playerOnRemoveCount(std::shared_ptr player, std::shared_ptr item) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnMove - " "Player {} item {}] " @@ -486,7 +486,7 @@ void EventCallback::playerOnRemoveCount(Player* player, Item* item) const { getScriptInterface()->callFunction(2); } -bool EventCallback::playerOnMoveItem(Player* player, Item* item, uint16_t count, const Position &fromPos, const Position &toPos, Cylinder* fromCylinder, Cylinder* toCylinder) const { +bool EventCallback::playerOnMoveItem(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPos, const Position &toPos, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const { if (!getScriptInterface()) { g_logger().error("script interface nullptr"); return false; @@ -521,7 +521,7 @@ bool EventCallback::playerOnMoveItem(Player* player, Item* item, uint16_t count, return getScriptInterface()->callFunction(7); } -void EventCallback::playerOnItemMoved(Player* player, Item* item, uint16_t count, const Position &fromPosition, const Position &toPosition, Cylinder* fromCylinder, Cylinder* toCylinder) const { +void EventCallback::playerOnItemMoved(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnItemMoved - " "Player {} item {}] " @@ -552,7 +552,7 @@ void EventCallback::playerOnItemMoved(Player* player, Item* item, uint16_t count getScriptInterface()->callVoidFunction(7); } -void EventCallback::playerOnChangeZone(Player* player, ZoneType_t zone) const { +void EventCallback::playerOnChangeZone(std::shared_ptr player, ZoneType_t zone) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnChangeZone - " "Player {}] " @@ -574,7 +574,7 @@ void EventCallback::playerOnChangeZone(Player* player, ZoneType_t zone) const { getScriptInterface()->callVoidFunction(2); } -bool EventCallback::playerOnMoveCreature(Player* player, Creature* creature, const Position &fromPosition, const Position &toPosition) const { +bool EventCallback::playerOnMoveCreature(std::shared_ptr player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnMoveCreature - " "Player {} creature {}] " @@ -601,7 +601,7 @@ bool EventCallback::playerOnMoveCreature(Player* player, Creature* creature, con return getScriptInterface()->callFunction(4); } -void EventCallback::playerOnReportRuleViolation(Player* player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const { +void EventCallback::playerOnReportRuleViolation(std::shared_ptr player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnReportRuleViolation - " "Player {}] " @@ -630,7 +630,7 @@ void EventCallback::playerOnReportRuleViolation(Player* player, const std::strin getScriptInterface()->callVoidFunction(6); } -void EventCallback::playerOnReportBug(Player* player, const std::string &message, const Position &position, uint8_t category) const { +void EventCallback::playerOnReportBug(std::shared_ptr player, const std::string &message, const Position &position, uint8_t category) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnReportBug - " "Player {}] " @@ -655,7 +655,7 @@ void EventCallback::playerOnReportBug(Player* player, const std::string &message getScriptInterface()->callFunction(4); } -bool EventCallback::playerOnTurn(Player* player, Direction direction) const { +bool EventCallback::playerOnTurn(std::shared_ptr player, Direction direction) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnTurn - " "Player {}] " @@ -678,7 +678,7 @@ bool EventCallback::playerOnTurn(Player* player, Direction direction) const { return getScriptInterface()->callFunction(2); } -bool EventCallback::playerOnTradeRequest(Player* player, Player* target, Item* item) const { +bool EventCallback::playerOnTradeRequest(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnTradeRequest - " "Player {} target {}] " @@ -705,7 +705,7 @@ bool EventCallback::playerOnTradeRequest(Player* player, Player* target, Item* i return getScriptInterface()->callFunction(3); } -bool EventCallback::playerOnTradeAccept(Player* player, Player* target, Item* item, Item* targetItem) const { +bool EventCallback::playerOnTradeAccept(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, std::shared_ptr targetItem) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnTradeAccept - " "Player {} target {}] " @@ -735,7 +735,7 @@ bool EventCallback::playerOnTradeAccept(Player* player, Player* target, Item* it return getScriptInterface()->callFunction(4); } -void EventCallback::playerOnGainExperience(Player* player, Creature* target, uint64_t &exp, uint64_t rawExp) const { +void EventCallback::playerOnGainExperience(std::shared_ptr player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnGainExperience - " "Player {} target {}] " @@ -773,7 +773,7 @@ void EventCallback::playerOnGainExperience(Player* player, Creature* target, uin getScriptInterface()->resetScriptEnv(); } -void EventCallback::playerOnLoseExperience(Player* player, uint64_t &exp) const { +void EventCallback::playerOnLoseExperience(std::shared_ptr player, uint64_t &exp) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLoseExperience - " "Player {}] " @@ -803,7 +803,7 @@ void EventCallback::playerOnLoseExperience(Player* player, uint64_t &exp) const getScriptInterface()->resetScriptEnv(); } -void EventCallback::playerOnGainSkillTries(Player* player, skills_t skill, uint64_t &tries) const { +void EventCallback::playerOnGainSkillTries(std::shared_ptr player, skills_t skill, uint64_t &tries) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnGainSkillTries - " "Player {} skill {}] " @@ -834,7 +834,7 @@ void EventCallback::playerOnGainSkillTries(Player* player, skills_t skill, uint6 getScriptInterface()->resetScriptEnv(); } -void EventCallback::playerOnCombat(Player* player, Creature* target, Item* item, CombatDamage &damage) const { +void EventCallback::playerOnCombat(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnCombat - " "Player {} target {}] " @@ -896,7 +896,7 @@ void EventCallback::playerOnCombat(Player* player, Creature* target, Item* item, getScriptInterface()->resetScriptEnv(); } -void EventCallback::playerOnRequestQuestLog(Player* player) const { +void EventCallback::playerOnRequestQuestLog(std::shared_ptr player) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnRequestQuestLog - " "Player {}] " @@ -917,7 +917,7 @@ void EventCallback::playerOnRequestQuestLog(Player* player) const { getScriptInterface()->callVoidFunction(1); } -void EventCallback::playerOnRequestQuestLine(Player* player, uint16_t questId) const { +void EventCallback::playerOnRequestQuestLine(std::shared_ptr player, uint16_t questId) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnRequestQuestLine - " "Player {} questId {}] " @@ -940,7 +940,7 @@ void EventCallback::playerOnRequestQuestLine(Player* player, uint16_t questId) c getScriptInterface()->callVoidFunction(2); } -void EventCallback::playerOnInventoryUpdate(Player* player, Item* item, Slots_t slot, bool equip) const { +void EventCallback::playerOnInventoryUpdate(std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool equip) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[{}] Call stack overflow", __FUNCTION__); return; @@ -964,7 +964,7 @@ void EventCallback::playerOnInventoryUpdate(Player* player, Item* item, Slots_t getScriptInterface()->callVoidFunction(4); } -bool EventCallback::playerOnRotateItem(Player* player, Item* item, const Position &position) const { +bool EventCallback::playerOnRotateItem(std::shared_ptr player, std::shared_ptr item, const Position &position) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[{}] Call stack overflow", __FUNCTION__); return false; @@ -987,7 +987,7 @@ bool EventCallback::playerOnRotateItem(Player* player, Item* item, const Positio return getScriptInterface()->callFunction(3); } -void EventCallback::playerOnStorageUpdate(Player* player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const { +void EventCallback::playerOnStorageUpdate(std::shared_ptr player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::eventOnStorageUpdate - " "Player {} key {}] " @@ -1014,7 +1014,7 @@ void EventCallback::playerOnStorageUpdate(Player* player, const uint32_t key, co } // Monster -void EventCallback::monsterOnDropLoot(Monster* monster, Container* corpse) const { +void EventCallback::monsterOnDropLoot(std::shared_ptr monster, std::shared_ptr corpse) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::monsterOnDropLoot - " "Monster corpse {}] " @@ -1038,7 +1038,7 @@ void EventCallback::monsterOnDropLoot(Monster* monster, Container* corpse) const return getScriptInterface()->callVoidFunction(2); } -void EventCallback::monsterPostDropLoot(Monster* monster, Container* corpse) const { +void EventCallback::monsterPostDropLoot(std::shared_ptr monster, std::shared_ptr corpse) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::monsterPostDropLoot - " "Monster corpse {}] " @@ -1062,7 +1062,7 @@ void EventCallback::monsterPostDropLoot(Monster* monster, Container* corpse) con return getScriptInterface()->callVoidFunction(2); } -void EventCallback::monsterOnSpawn(Monster* monster, const Position &position) const { +void EventCallback::monsterOnSpawn(std::shared_ptr monster, const Position &position) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("{} - " "Position {}" @@ -1091,7 +1091,7 @@ void EventCallback::monsterOnSpawn(Monster* monster, const Position &position) c } // Npc -void EventCallback::npcOnSpawn(Npc* npc, const Position &position) const { +void EventCallback::npcOnSpawn(std::shared_ptr npc, const Position &position) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("{} - " "Position {}" @@ -1119,7 +1119,7 @@ void EventCallback::npcOnSpawn(Npc* npc, const Position &position) const { getScriptInterface()->resetScriptEnv(); } -bool EventCallback::zoneBeforeCreatureEnter(std::shared_ptr zone, Creature* creature) const { +bool EventCallback::zoneBeforeCreatureEnter(std::shared_ptr zone, std::shared_ptr creature) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::zoneBeforeCreatureEnter - " "Zone {} Creature {}] " @@ -1143,7 +1143,7 @@ bool EventCallback::zoneBeforeCreatureEnter(std::shared_ptr zone, Creature return getScriptInterface()->callFunction(2); } -bool EventCallback::zoneBeforeCreatureLeave(std::shared_ptr zone, Creature* creature) const { +bool EventCallback::zoneBeforeCreatureLeave(std::shared_ptr zone, std::shared_ptr creature) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::zoneBeforeCreatureLeave - " "Zone {} Creature {}] " @@ -1167,7 +1167,7 @@ bool EventCallback::zoneBeforeCreatureLeave(std::shared_ptr zone, Creature return getScriptInterface()->callFunction(2); } -void EventCallback::zoneAfterCreatureEnter(std::shared_ptr zone, Creature* creature) const { +void EventCallback::zoneAfterCreatureEnter(std::shared_ptr zone, std::shared_ptr creature) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::zoneAfterCreatureEnter - " "Zone {} Creature {}] " @@ -1191,7 +1191,7 @@ void EventCallback::zoneAfterCreatureEnter(std::shared_ptr zone, Creature* getScriptInterface()->callVoidFunction(2); } -void EventCallback::zoneAfterCreatureLeave(std::shared_ptr zone, Creature* creature) const { +void EventCallback::zoneAfterCreatureLeave(std::shared_ptr zone, std::shared_ptr creature) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::zoneAfterCreatureLeave - " "Zone {} Creature {}] " diff --git a/src/lua/callbacks/event_callback.hpp b/src/lua/callbacks/event_callback.hpp index f1dea466fe6..e5712a06d71 100644 --- a/src/lua/callbacks/event_callback.hpp +++ b/src/lua/callbacks/event_callback.hpp @@ -79,57 +79,57 @@ class EventCallback : public Script { */ // Creature - bool creatureOnChangeOutfit(Creature* creature, const Outfit_t &outfit) const; - ReturnValue creatureOnAreaCombat(Creature* creature, Tile* tile, bool aggressive) const; - ReturnValue creatureOnTargetCombat(Creature* creature, Creature* target) const; - void creatureOnHear(Creature* creature, Creature* speaker, const std::string &words, SpeakClasses type) const; - void creatureOnDrainHealth(Creature* creature, Creature* attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) const; + bool creatureOnChangeOutfit(std::shared_ptr creature, const Outfit_t &outfit) const; + ReturnValue creatureOnAreaCombat(std::shared_ptr creature, std::shared_ptr tile, bool aggressive) const; + ReturnValue creatureOnTargetCombat(std::shared_ptr creature, std::shared_ptr target) const; + void creatureOnHear(std::shared_ptr creature, std::shared_ptr speaker, const std::string &words, SpeakClasses type) const; + void creatureOnDrainHealth(std::shared_ptr creature, std::shared_ptr attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) const; // Party - bool partyOnJoin(Party* party, Player* player) const; - bool partyOnLeave(Party* party, Player* player) const; + bool partyOnJoin(Party* party, std::shared_ptr player) const; + bool partyOnLeave(Party* party, std::shared_ptr player) const; bool partyOnDisband(Party* party) const; void partyOnShareExperience(Party* party, uint64_t &exp) const; // Player - bool playerOnBrowseField(Player* player, const Position &position) const; - void playerOnLook(Player* player, const Position &position, Thing* thing, uint8_t stackpos, int32_t lookDistance) const; - void playerOnLookInBattleList(Player* player, Creature* creature, int32_t lookDistance) const; - void playerOnLookInTrade(Player* player, Player* partner, Item* item, int32_t lookDistance) const; - bool playerOnLookInShop(Player* player, const ItemType* itemType, uint8_t count) const; - bool playerOnMoveItem(Player* player, Item* item, uint16_t count, const Position &fromPosition, const Position &toPosition, Cylinder* fromCylinder, Cylinder* toCylinder) const; - void playerOnItemMoved(Player* player, Item* item, uint16_t count, const Position &fromPosition, const Position &toPosition, Cylinder* fromCylinder, Cylinder* toCylinder) const; - void playerOnChangeZone(Player* player, ZoneType_t zone) const; - bool playerOnMoveCreature(Player* player, Creature* creature, const Position &fromPosition, const Position &toPosition) const; - void playerOnReportRuleViolation(Player* player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const; - void playerOnReportBug(Player* player, const std::string &message, const Position &position, uint8_t category) const; - bool playerOnTurn(Player* player, Direction direction) const; - bool playerOnTradeRequest(Player* player, Player* target, Item* item) const; - bool playerOnTradeAccept(Player* player, Player* target, Item* item, Item* targetItem) const; - void playerOnGainExperience(Player* player, Creature* target, uint64_t &exp, uint64_t rawExp) const; - void playerOnLoseExperience(Player* player, uint64_t &exp) const; - void playerOnGainSkillTries(Player* player, skills_t skill, uint64_t &tries) const; - void playerOnRemoveCount(Player* player, Item* item) const; - void playerOnRequestQuestLog(Player* player) const; - void playerOnRequestQuestLine(Player* player, uint16_t questId) const; - void playerOnStorageUpdate(Player* player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const; - void playerOnCombat(Player* player, Creature* target, Item* item, CombatDamage &damage) const; - void playerOnInventoryUpdate(Player* player, Item* item, Slots_t slot, bool equip) const; - bool playerOnRotateItem(Player* player, Item* item, const Position &position) const; + bool playerOnBrowseField(std::shared_ptr player, const Position &position) const; + void playerOnLook(std::shared_ptr player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) const; + void playerOnLookInBattleList(std::shared_ptr player, std::shared_ptr creature, int32_t lookDistance) const; + void playerOnLookInTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr item, int32_t lookDistance) const; + bool playerOnLookInShop(std::shared_ptr player, const ItemType* itemType, uint8_t count) const; + bool playerOnMoveItem(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; + void playerOnItemMoved(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; + void playerOnChangeZone(std::shared_ptr player, ZoneType_t zone) const; + bool playerOnMoveCreature(std::shared_ptr player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) const; + void playerOnReportRuleViolation(std::shared_ptr player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const; + void playerOnReportBug(std::shared_ptr player, const std::string &message, const Position &position, uint8_t category) const; + bool playerOnTurn(std::shared_ptr player, Direction direction) const; + bool playerOnTradeRequest(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const; + bool playerOnTradeAccept(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, std::shared_ptr targetItem) const; + void playerOnGainExperience(std::shared_ptr player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) const; + void playerOnLoseExperience(std::shared_ptr player, uint64_t &exp) const; + void playerOnGainSkillTries(std::shared_ptr player, skills_t skill, uint64_t &tries) const; + void playerOnRemoveCount(std::shared_ptr player, std::shared_ptr item) const; + void playerOnRequestQuestLog(std::shared_ptr player) const; + void playerOnRequestQuestLine(std::shared_ptr player, uint16_t questId) const; + void playerOnStorageUpdate(std::shared_ptr player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const; + void playerOnCombat(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) const; + void playerOnInventoryUpdate(std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool equip) const; + bool playerOnRotateItem(std::shared_ptr player, std::shared_ptr item, const Position &position) const; // Monster - void monsterOnDropLoot(Monster* monster, Container* corpse) const; - void monsterPostDropLoot(Monster* monster, Container* corpse) const; - void monsterOnSpawn(Monster* monster, const Position &position) const; + void monsterOnDropLoot(std::shared_ptr monster, std::shared_ptr corpse) const; + void monsterPostDropLoot(std::shared_ptr monster, std::shared_ptr corpse) const; + void monsterOnSpawn(std::shared_ptr monster, const Position &position) const; // Npc - void npcOnSpawn(Npc* npc, const Position &position) const; + void npcOnSpawn(std::shared_ptr npc, const Position &position) const; // Zone - bool zoneBeforeCreatureEnter(std::shared_ptr zone, Creature* creature) const; - bool zoneBeforeCreatureLeave(std::shared_ptr zone, Creature* creature) const; - void zoneAfterCreatureEnter(std::shared_ptr zone, Creature* creature) const; - void zoneAfterCreatureLeave(std::shared_ptr zone, Creature* creature) const; + bool zoneBeforeCreatureEnter(std::shared_ptr zone, std::shared_ptr creature) const; + bool zoneBeforeCreatureLeave(std::shared_ptr zone, std::shared_ptr creature) const; + void zoneAfterCreatureEnter(std::shared_ptr zone, std::shared_ptr creature) const; + void zoneAfterCreatureLeave(std::shared_ptr zone, std::shared_ptr creature) const; /** * @note here end the lua binder functions } diff --git a/src/lua/creature/actions.cpp b/src/lua/creature/actions.cpp index 34fa1cba896..6a79d697eb7 100644 --- a/src/lua/creature/actions.cpp +++ b/src/lua/creature/actions.cpp @@ -166,7 +166,7 @@ bool Actions::registerLuaEvent(const std::shared_ptr action) { return false; } -ReturnValue Actions::canUse(const Player* player, const Position &pos) { +ReturnValue Actions::canUse(std::shared_ptr player, const Position &pos) { if (pos.x != 0xFFFF) { const Position &playerPos = player->getPosition(); if (playerPos.z != pos.z) { @@ -180,7 +180,7 @@ ReturnValue Actions::canUse(const Player* player, const Position &pos) { return RETURNVALUE_NOERROR; } -ReturnValue Actions::canUse(const Player* player, const Position &pos, const Item* item) { +ReturnValue Actions::canUse(std::shared_ptr player, const Position &pos, std::shared_ptr item) { const std::shared_ptr action = getAction(item); if (action != nullptr) { return action->canExecuteAction(player, pos); @@ -188,7 +188,7 @@ ReturnValue Actions::canUse(const Player* player, const Position &pos, const Ite return RETURNVALUE_NOERROR; } -ReturnValue Actions::canUseFar(const Creature* creature, const Position &toPos, bool checkLineOfSight, bool checkFloor) { +ReturnValue Actions::canUseFar(std::shared_ptr creature, const Position &toPos, bool checkLineOfSight, bool checkFloor) { if (toPos.x == 0xFFFF) { return RETURNVALUE_NOERROR; } @@ -209,7 +209,7 @@ ReturnValue Actions::canUseFar(const Creature* creature, const Position &toPos, return RETURNVALUE_NOERROR; } -std::shared_ptr Actions::getAction(const Item* item) { +std::shared_ptr Actions::getAction(std::shared_ptr item) { if (item->hasAttribute(ItemAttribute_t::UNIQUEID)) { auto it = uniqueItemMap.find(item->getAttribute(ItemAttribute_t::UNIQUEID)); if (it != uniqueItemMap.end()) { @@ -231,9 +231,9 @@ std::shared_ptr Actions::getAction(const Item* item) { if (auto iteratePositions = actionPositionMap.find(item->getPosition()); iteratePositions != actionPositionMap.end()) { - if (const Tile* tile = item->getTile(); + if (std::shared_ptr tile = item->getTile(); tile) { - if (const Player* player = item->getHoldingPlayer(); + if (std::shared_ptr player = item->getHoldingPlayer(); player && item->getTopParent() == player) { g_logger().debug("[Actions::getAction] - The position only is valid for use item in the map, player name {}", player->getName()); return nullptr; @@ -247,8 +247,8 @@ std::shared_ptr Actions::getAction(const Item* item) { return g_spells().getRuneSpell(item->getID()); } -ReturnValue Actions::internalUseItem(Player* player, const Position &pos, uint8_t index, Item* item, bool isHotkey) { - if (Door* door = item->getDoor()) { +ReturnValue Actions::internalUseItem(std::shared_ptr player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { + if (std::shared_ptr door = item->getDoor()) { if (!door->canUse(player)) { return RETURNVALUE_CANNOTUSETHISOBJECT; } @@ -282,7 +282,7 @@ ReturnValue Actions::internalUseItem(Player* player, const Position &pos, uint8_ } } - if (BedItem* bed = item->getBed()) { + if (std::shared_ptr bed = item->getBed()) { if (!bed->canUse(player)) { return RETURNVALUE_CANNOTUSETHISOBJECT; } @@ -295,12 +295,12 @@ ReturnValue Actions::internalUseItem(Player* player, const Position &pos, uint8_ return RETURNVALUE_NOERROR; } - if (Container* container = item->getContainer()) { - Container* openContainer; + if (std::shared_ptr container = item->getContainer()) { + std::shared_ptr openContainer; // depot container - if (DepotLocker* depot = container->getDepotLocker()) { - DepotLocker* myDepotLocker = player->getDepotLocker(depot->getDepotId()); + if (std::shared_ptr depot = container->getDepotLocker()) { + std::shared_ptr myDepotLocker = player->getDepotLocker(depot->getDepotId()); myDepotLocker->setParent(depot->getParent()->getTile()); openContainer = myDepotLocker; player->setLastDepotId(depot->getDepotId()); @@ -310,7 +310,7 @@ ReturnValue Actions::internalUseItem(Player* player, const Position &pos, uint8_ // reward chest if (container->getRewardChest() != nullptr && container->getParent()) { - RewardChest* playerRewardChest = player->getRewardChest(); + std::shared_ptr playerRewardChest = player->getRewardChest(); if (playerRewardChest->empty()) { return RETURNVALUE_REWARDCHESTISEMPTY; } @@ -383,7 +383,7 @@ ReturnValue Actions::internalUseItem(Player* player, const Position &pos, uint8_ return RETURNVALUE_CANNOTUSETHISOBJECT; } -bool Actions::useItem(Player* player, const Position &pos, uint8_t index, Item* item, bool isHotkey) { +bool Actions::useItem(std::shared_ptr player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { const ItemType &it = Item::items[item->getID()]; if (it.isRune() || it.type == ITEM_TYPE_POTION) { if (player->walkExhausted()) { @@ -415,7 +415,7 @@ bool Actions::useItem(Player* player, const Position &pos, uint8_t index, Item* return true; } -bool Actions::useItemEx(Player* player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature /* = nullptr*/) { +bool Actions::useItemEx(std::shared_ptr player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature /* = nullptr*/) { const ItemType &it = Item::items[item->getID()]; if (it.isRune() || it.type == ITEM_TYPE_POTION) { if (player->walkExhausted()) { @@ -467,7 +467,7 @@ bool Actions::useItemEx(Player* player, const Position &fromPos, const Position return true; } -void Actions::showUseHotkeyMessage(Player* player, const Item* item, uint32_t count) { +void Actions::showUseHotkeyMessage(std::shared_ptr player, std::shared_ptr item, uint32_t count) { std::ostringstream ss; const ItemType &it = Item::items[item->getID()]; @@ -491,7 +491,7 @@ void Actions::showUseHotkeyMessage(Player* player, const Item* item, uint32_t co Action::Action(LuaScriptInterface* interface) : Script(interface) { } -ReturnValue Action::canExecuteAction(const Player* player, const Position &toPos) { +ReturnValue Action::canExecuteAction(std::shared_ptr player, const Position &toPos) { if (!allowFarUse) { return g_actions().canUse(player, toPos); } @@ -499,14 +499,14 @@ ReturnValue Action::canExecuteAction(const Player* player, const Position &toPos return g_actions().canUseFar(player, toPos, checkLineOfSight, checkFloor); } -Thing* Action::getTarget(Player* player, Creature* targetCreature, const Position &toPosition, uint8_t toStackPos) const { +std::shared_ptr Action::getTarget(std::shared_ptr player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const { if (targetCreature != nullptr) { return targetCreature; } return g_game().internalGetThing(player, toPosition, toStackPos, 0, STACKPOS_USETARGET); } -bool Action::executeUse(Player* player, Item* item, const Position &fromPosition, Thing* target, const Position &toPosition, bool isHotkey) { +bool Action::executeUse(std::shared_ptr player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey) { // onUse(player, item, fromPosition, target, toPosition, isHotkey) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[Action::executeUse - Player {}, on item {}] " diff --git a/src/lua/creature/actions.hpp b/src/lua/creature/actions.hpp index b93dee55aae..c0fb1a27790 100644 --- a/src/lua/creature/actions.hpp +++ b/src/lua/creature/actions.hpp @@ -21,7 +21,7 @@ class Action : public Script { explicit Action(LuaScriptInterface* interface); // Scripting - virtual bool executeUse(Player* player, Item* item, const Position &fromPosition, Thing* target, const Position &toPosition, bool isHotkey); + virtual bool executeUse(std::shared_ptr player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey); bool getAllowFarUse() const { return allowFarUse; @@ -96,13 +96,13 @@ class Action : public Script { positions.emplace_back(pos); } - virtual ReturnValue canExecuteAction(const Player* player, const Position &toPos); + virtual ReturnValue canExecuteAction(std::shared_ptr player, const Position &toPos); virtual bool hasOwnErrorHandler() { return false; } - virtual Thing* getTarget(Player* player, Creature* targetCreature, const Position &toPosition, uint8_t toStackPos) const; + virtual std::shared_ptr getTarget(std::shared_ptr player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const; private: std::string getScriptTypeName() const override { @@ -110,8 +110,8 @@ class Action : public Script { } std::function player, std::shared_ptr item, + const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey )> useFunction = nullptr; @@ -143,12 +143,12 @@ class Actions final : public Scripts { return inject(); } - bool useItem(Player* player, const Position &pos, uint8_t index, Item* item, bool isHotkey); - bool useItemEx(Player* player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature = nullptr); + bool useItem(std::shared_ptr player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); + bool useItemEx(std::shared_ptr player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature = nullptr); - ReturnValue canUse(const Player* player, const Position &pos); - ReturnValue canUse(const Player* player, const Position &pos, const Item* item); - ReturnValue canUseFar(const Creature* creature, const Position &toPos, bool checkLineOfSight, bool checkFloor); + ReturnValue canUse(std::shared_ptr player, const Position &pos); + ReturnValue canUse(std::shared_ptr player, const Position &pos, std::shared_ptr item); + ReturnValue canUseFar(std::shared_ptr creature, const Position &toPos, bool checkLineOfSight, bool checkFloor); bool registerLuaItemEvent(const std::shared_ptr action); bool registerLuaUniqueEvent(const std::shared_ptr action); @@ -211,8 +211,8 @@ class Actions final : public Scripts { actionItemMap.try_emplace(actionId, action); } - ReturnValue internalUseItem(Player* player, const Position &pos, uint8_t index, Item* item, bool isHotkey); - static void showUseHotkeyMessage(Player* player, const Item* item, uint32_t count); + ReturnValue internalUseItem(std::shared_ptr player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); + static void showUseHotkeyMessage(std::shared_ptr player, std::shared_ptr item, uint32_t count); using ActionUseMap = std::map>; ActionUseMap useItemMap; @@ -220,7 +220,7 @@ class Actions final : public Scripts { ActionUseMap actionItemMap; std::map> actionPositionMap; - std::shared_ptr getAction(const Item* item); + std::shared_ptr getAction(std::shared_ptr item); }; constexpr auto g_actions = Actions::getInstance; diff --git a/src/lua/creature/creatureevent.cpp b/src/lua/creature/creatureevent.cpp index 1480b5782a4..b1984be2fd6 100644 --- a/src/lua/creature/creatureevent.cpp +++ b/src/lua/creature/creatureevent.cpp @@ -55,7 +55,7 @@ std::shared_ptr CreatureEvents::getEventByName(const std::string return nullptr; } -bool CreatureEvents::playerLogin(Player* player) const { +bool CreatureEvents::playerLogin(std::shared_ptr player) const { // fire global event if is registered for (const auto &it : creatureEvents) { if (it.second->getEventType() == CREATURE_EVENT_LOGIN) { @@ -67,7 +67,7 @@ bool CreatureEvents::playerLogin(Player* player) const { return true; } -bool CreatureEvents::playerLogout(Player* player) const { +bool CreatureEvents::playerLogout(std::shared_ptr player) const { // fire global event if is registered for (const auto &it : creatureEvents) { if (it.second->getEventType() == CREATURE_EVENT_LOGOUT) { @@ -80,7 +80,7 @@ bool CreatureEvents::playerLogout(Player* player) const { } bool CreatureEvents::playerAdvance( - Player* player, + std::shared_ptr player, skills_t skill, uint32_t oldLevel, uint32_t newLevel @@ -171,7 +171,7 @@ void CreatureEvent::clearEvent() { loaded = false; } -bool CreatureEvent::executeOnLogin(Player* player) const { +bool CreatureEvent::executeOnLogin(std::shared_ptr player) const { // onLogin(player) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeOnLogin - Player {} event {}]" @@ -191,7 +191,7 @@ bool CreatureEvent::executeOnLogin(Player* player) const { return getScriptInterface()->callFunction(1); } -bool CreatureEvent::executeOnLogout(Player* player) const { +bool CreatureEvent::executeOnLogout(std::shared_ptr player) const { // onLogout(player) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeOnLogout - Player {} event {}] " @@ -211,7 +211,7 @@ bool CreatureEvent::executeOnLogout(Player* player) const { return getScriptInterface()->callFunction(1); } -bool CreatureEvent::executeOnThink(Creature* creature, uint32_t interval) const { +bool CreatureEvent::executeOnThink(std::shared_ptr creature, uint32_t interval) const { // onThink(creature, interval) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeOnThink - Creature {} event {}] " @@ -233,7 +233,7 @@ bool CreatureEvent::executeOnThink(Creature* creature, uint32_t interval) const return getScriptInterface()->callFunction(2); } -bool CreatureEvent::executeOnPrepareDeath(Creature* creature, Creature* killer) const { +bool CreatureEvent::executeOnPrepareDeath(std::shared_ptr creature, std::shared_ptr killer) const { // onPrepareDeath(creature, killer) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeOnPrepareDeath - Creature {} killer {}" @@ -262,7 +262,7 @@ bool CreatureEvent::executeOnPrepareDeath(Creature* creature, Creature* killer) return getScriptInterface()->callFunction(2); } -bool CreatureEvent::executeOnDeath(Creature* creature, Item* corpse, Creature* killer, Creature* mostDamageKiller, bool lastHitUnjustified, bool mostDamageUnjustified) const { +bool CreatureEvent::executeOnDeath(std::shared_ptr creature, std::shared_ptr corpse, std::shared_ptr killer, std::shared_ptr mostDamageKiller, bool lastHitUnjustified, bool mostDamageUnjustified) const { // onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeOnDeath - Creature {} killer {} event {}] " @@ -302,7 +302,7 @@ bool CreatureEvent::executeOnDeath(Creature* creature, Item* corpse, Creature* k return getScriptInterface()->callFunction(6); } -bool CreatureEvent::executeAdvance(Player* player, skills_t skill, uint32_t oldLevel, uint32_t newLevel) const { +bool CreatureEvent::executeAdvance(std::shared_ptr player, skills_t skill, uint32_t oldLevel, uint32_t newLevel) const { // onAdvance(player, skill, oldLevel, newLevel) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeAdvance - Player {} event {}] " @@ -326,7 +326,7 @@ bool CreatureEvent::executeAdvance(Player* player, skills_t skill, uint32_t oldL return getScriptInterface()->callFunction(4); } -void CreatureEvent::executeOnKill(Creature* creature, Creature* target, bool lastHit) const { +void CreatureEvent::executeOnKill(std::shared_ptr creature, std::shared_ptr target, bool lastHit) const { // onKill(creature, target, lastHit) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeOnKill - Creature {} target {} event {}] " @@ -349,7 +349,7 @@ void CreatureEvent::executeOnKill(Creature* creature, Creature* target, bool las getScriptInterface()->callVoidFunction(3); } -void CreatureEvent::executeModalWindow(Player* player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const { +void CreatureEvent::executeModalWindow(std::shared_ptr player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const { // onModalWindow(player, modalWindowId, buttonId, choiceId) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeModalWindow - " @@ -375,7 +375,7 @@ void CreatureEvent::executeModalWindow(Player* player, uint32_t modalWindowId, u getScriptInterface()->callVoidFunction(4); } -bool CreatureEvent::executeTextEdit(Player* player, Item* item, const std::string &text) const { +bool CreatureEvent::executeTextEdit(std::shared_ptr player, std::shared_ptr item, const std::string &text) const { // onTextEdit(player, item, text) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeTextEdit - Player {} event {}] " @@ -399,7 +399,7 @@ bool CreatureEvent::executeTextEdit(Player* player, Item* item, const std::strin return getScriptInterface()->callFunction(3); } -void CreatureEvent::executeHealthChange(Creature* creature, Creature* attacker, CombatDamage &damage) const { +void CreatureEvent::executeHealthChange(std::shared_ptr creature, std::shared_ptr attacker, CombatDamage &damage) const { // onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeHealthChange - " @@ -444,7 +444,7 @@ void CreatureEvent::executeHealthChange(Creature* creature, Creature* attacker, getScriptInterface()->resetScriptEnv(); } -void CreatureEvent::executeManaChange(Creature* creature, Creature* attacker, CombatDamage &damage) const { +void CreatureEvent::executeManaChange(std::shared_ptr creature, std::shared_ptr attacker, CombatDamage &damage) const { // onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeManaChange - " @@ -484,7 +484,7 @@ void CreatureEvent::executeManaChange(Creature* creature, Creature* attacker, Co getScriptInterface()->resetScriptEnv(); } -void CreatureEvent::executeExtendedOpcode(Player* player, uint8_t opcode, const std::string &buffer) const { +void CreatureEvent::executeExtendedOpcode(std::shared_ptr player, uint8_t opcode, const std::string &buffer) const { // onExtendedOpcode(player, opcode, buffer) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeExtendedOpcode - " diff --git a/src/lua/creature/creatureevent.hpp b/src/lua/creature/creatureevent.hpp index 06dbb729347..24052aa84a2 100644 --- a/src/lua/creature/creatureevent.hpp +++ b/src/lua/creature/creatureevent.hpp @@ -43,18 +43,18 @@ class CreatureEvent final : public Script { void copyEvent(const std::shared_ptr creatureEvent); // scripting - bool executeOnLogin(Player* player) const; - bool executeOnLogout(Player* player) const; - bool executeOnThink(Creature* creature, uint32_t interval) const; - bool executeOnPrepareDeath(Creature* creature, Creature* killer) const; - bool executeOnDeath(Creature* creature, Item* corpse, Creature* killer, Creature* mostDamageKiller, bool lastHitUnjustified, bool mostDamageUnjustified) const; - void executeOnKill(Creature* creature, Creature* target, bool lastHit) const; - bool executeAdvance(Player* player, skills_t, uint32_t, uint32_t) const; - void executeModalWindow(Player* player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const; - bool executeTextEdit(Player* player, Item* item, const std::string &text) const; - void executeHealthChange(Creature* creature, Creature* attacker, CombatDamage &damage) const; - void executeManaChange(Creature* creature, Creature* attacker, CombatDamage &damage) const; - void executeExtendedOpcode(Player* player, uint8_t opcode, const std::string &buffer) const; + bool executeOnLogin(std::shared_ptr player) const; + bool executeOnLogout(std::shared_ptr player) const; + bool executeOnThink(std::shared_ptr creature, uint32_t interval) const; + bool executeOnPrepareDeath(std::shared_ptr creature, std::shared_ptr killer) const; + bool executeOnDeath(std::shared_ptr creature, std::shared_ptr corpse, std::shared_ptr killer, std::shared_ptr mostDamageKiller, bool lastHitUnjustified, bool mostDamageUnjustified) const; + void executeOnKill(std::shared_ptr creature, std::shared_ptr target, bool lastHit) const; + bool executeAdvance(std::shared_ptr player, skills_t, uint32_t, uint32_t) const; + void executeModalWindow(std::shared_ptr player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const; + bool executeTextEdit(std::shared_ptr player, std::shared_ptr item, const std::string &text) const; + void executeHealthChange(std::shared_ptr creature, std::shared_ptr attacker, CombatDamage &damage) const; + void executeManaChange(std::shared_ptr creature, std::shared_ptr attacker, CombatDamage &damage) const; + void executeExtendedOpcode(std::shared_ptr player, uint8_t opcode, const std::string &buffer) const; // private: @@ -78,9 +78,9 @@ class CreatureEvents final : public Scripts { } // global events - bool playerLogin(Player* player) const; - bool playerLogout(Player* player) const; - bool playerAdvance(Player* player, skills_t, uint32_t, uint32_t) const; + bool playerLogin(std::shared_ptr player) const; + bool playerLogout(std::shared_ptr player) const; + bool playerAdvance(std::shared_ptr player, skills_t, uint32_t, uint32_t) const; std::shared_ptr getEventByName(const std::string &name, bool forceLoaded = true); diff --git a/src/lua/creature/events.cpp b/src/lua/creature/events.cpp index 1625e50fd81..65f9270a58a 100644 --- a/src/lua/creature/events.cpp +++ b/src/lua/creature/events.cpp @@ -150,7 +150,7 @@ bool Events::loadFromXml() { } // Monster -void Events::eventMonsterOnSpawn(Monster* monster, const Position &position) { +void Events::eventMonsterOnSpawn(std::shared_ptr monster, const Position &position) { // Monster:onSpawn(position) or Monster.onSpawn(self, position) if (info.monsterOnSpawn == -1) { return; @@ -184,7 +184,7 @@ void Events::eventMonsterOnSpawn(Monster* monster, const Position &position) { } // Npc -void Events::eventNpcOnSpawn(Npc* npc, const Position &position) { +void Events::eventNpcOnSpawn(std::shared_ptr npc, const Position &position) { // Npc:onSpawn(position) or Npc.onSpawn(self, position) if (info.npcOnSpawn == -1) { return; @@ -218,7 +218,7 @@ void Events::eventNpcOnSpawn(Npc* npc, const Position &position) { } // Creature -bool Events::eventCreatureOnChangeOutfit(Creature* creature, const Outfit_t &outfit) { +bool Events::eventCreatureOnChangeOutfit(std::shared_ptr creature, const Outfit_t &outfit) { // Creature:onChangeOutfit(outfit) or Creature.onChangeOutfit(self, outfit) if (info.creatureOnChangeOutfit == -1) { return true; @@ -245,7 +245,7 @@ bool Events::eventCreatureOnChangeOutfit(Creature* creature, const Outfit_t &out return scriptInterface.callFunction(2); } -ReturnValue Events::eventCreatureOnAreaCombat(Creature* creature, Tile* tile, bool aggressive) { +ReturnValue Events::eventCreatureOnAreaCombat(std::shared_ptr creature, std::shared_ptr tile, bool aggressive) { // Creature:onAreaCombat(tile, aggressive) or Creature.onAreaCombat(self, tile, aggressive) if (info.creatureOnAreaCombat == -1) { return RETURNVALUE_NOERROR; @@ -290,7 +290,7 @@ ReturnValue Events::eventCreatureOnAreaCombat(Creature* creature, Tile* tile, bo return returnValue; } -ReturnValue Events::eventCreatureOnTargetCombat(Creature* creature, Creature* target) { +ReturnValue Events::eventCreatureOnTargetCombat(std::shared_ptr creature, std::shared_ptr target) { // Creature:onTargetCombat(target) or Creature.onTargetCombat(self, target) if (info.creatureOnTargetCombat == -1) { return RETURNVALUE_NOERROR; @@ -333,7 +333,7 @@ ReturnValue Events::eventCreatureOnTargetCombat(Creature* creature, Creature* ta return returnValue; } -void Events::eventCreatureOnHear(Creature* creature, Creature* speaker, const std::string &words, SpeakClasses type) { +void Events::eventCreatureOnHear(std::shared_ptr creature, std::shared_ptr speaker, const std::string &words, SpeakClasses type) { // Creature:onHear(speaker, words, type) if (info.creatureOnHear == -1) { return; @@ -365,7 +365,7 @@ void Events::eventCreatureOnHear(Creature* creature, Creature* speaker, const st scriptInterface.callVoidFunction(4); } -void Events::eventCreatureOnDrainHealth(Creature* creature, Creature* attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) { +void Events::eventCreatureOnDrainHealth(std::shared_ptr creature, std::shared_ptr attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) { if (info.creatureOnDrainHealth == -1) { return; } @@ -421,7 +421,7 @@ void Events::eventCreatureOnDrainHealth(Creature* creature, Creature* attacker, } // Party -bool Events::eventPartyOnJoin(Party* party, Player* player) { +bool Events::eventPartyOnJoin(Party* party, std::shared_ptr player) { // Party:onJoin(player) or Party.onJoin(self, player) if (info.partyOnJoin == -1) { return true; @@ -450,7 +450,7 @@ bool Events::eventPartyOnJoin(Party* party, Player* player) { return scriptInterface.callFunction(2); } -bool Events::eventPartyOnLeave(Party* party, Player* player) { +bool Events::eventPartyOnLeave(Party* party, std::shared_ptr player) { // Party:onLeave(player) or Party.onLeave(self, player) if (info.partyOnLeave == -1) { return true; @@ -537,7 +537,7 @@ void Events::eventPartyOnShareExperience(Party* party, uint64_t &exp) { } // Player -bool Events::eventPlayerOnBrowseField(Player* player, const Position &position) { +bool Events::eventPlayerOnBrowseField(std::shared_ptr player, const Position &position) { // Player:onBrowseField(position) or Player.onBrowseField(self, position) if (info.playerOnBrowseField == -1) { return true; @@ -565,7 +565,7 @@ bool Events::eventPlayerOnBrowseField(Player* player, const Position &position) return scriptInterface.callFunction(2); } -void Events::eventPlayerOnLook(Player* player, const Position &position, Thing* thing, uint8_t stackpos, int32_t lookDistance) { +void Events::eventPlayerOnLook(std::shared_ptr player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) { // Player:onLook(thing, position, distance) or Player.onLook(self, thing, position, distance) if (info.playerOnLook == -1) { return; @@ -588,10 +588,10 @@ void Events::eventPlayerOnLook(Player* player, const Position &position, Thing* LuaScriptInterface::pushUserdata(L, player); LuaScriptInterface::setMetatable(L, -1, "Player"); - if (Creature* creature = thing->getCreature()) { + if (std::shared_ptr creature = thing->getCreature()) { LuaScriptInterface::pushUserdata(L, creature); LuaScriptInterface::setCreatureMetatable(L, -1, creature); - } else if (Item* item = thing->getItem()) { + } else if (std::shared_ptr item = thing->getItem()) { LuaScriptInterface::pushUserdata(L, item); LuaScriptInterface::setItemMetatable(L, -1, item); } else { @@ -604,7 +604,7 @@ void Events::eventPlayerOnLook(Player* player, const Position &position, Thing* scriptInterface.callVoidFunction(4); } -void Events::eventPlayerOnLookInBattleList(Player* player, Creature* creature, int32_t lookDistance) { +void Events::eventPlayerOnLookInBattleList(std::shared_ptr player, std::shared_ptr creature, int32_t lookDistance) { // Player:onLookInBattleList(creature, position, distance) or Player.onLookInBattleList(self, creature, position, distance) if (info.playerOnLookInBattleList == -1) { return; @@ -635,7 +635,7 @@ void Events::eventPlayerOnLookInBattleList(Player* player, Creature* creature, i scriptInterface.callVoidFunction(3); } -void Events::eventPlayerOnLookInTrade(Player* player, Player* partner, Item* item, int32_t lookDistance) { +void Events::eventPlayerOnLookInTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr item, int32_t lookDistance) { // Player:onLookInTrade(partner, item, distance) or Player.onLookInTrade(self, partner, item, distance) if (info.playerOnLookInTrade == -1) { return; @@ -669,7 +669,7 @@ void Events::eventPlayerOnLookInTrade(Player* player, Player* partner, Item* ite scriptInterface.callVoidFunction(4); } -bool Events::eventPlayerOnLookInShop(Player* player, const ItemType* itemType, uint8_t count) { +bool Events::eventPlayerOnLookInShop(std::shared_ptr player, const ItemType* itemType, uint8_t count) { // Player:onLookInShop(itemType, count) or Player.onLookInShop(self, itemType, count) if (info.playerOnLookInShop == -1) { return true; @@ -700,7 +700,7 @@ bool Events::eventPlayerOnLookInShop(Player* player, const ItemType* itemType, u return scriptInterface.callFunction(3); } -bool Events::eventPlayerOnRemoveCount(Player* player, Item* item) { +bool Events::eventPlayerOnRemoveCount(std::shared_ptr player, std::shared_ptr item) { // Player:onMove() if (info.playerOnRemoveCount == -1) { return true; @@ -729,7 +729,7 @@ bool Events::eventPlayerOnRemoveCount(Player* player, Item* item) { return scriptInterface.callFunction(2); } -bool Events::eventPlayerOnMoveItem(Player* player, Item* item, uint16_t count, const Position &fromPosition, const Position &toPosition, Cylinder* fromCylinder, Cylinder* toCylinder) { +bool Events::eventPlayerOnMoveItem(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { // Player:onMoveItem(item, count, fromPosition, toPosition) or Player.onMoveItem(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder) if (info.playerOnMoveItem == -1) { return true; @@ -765,7 +765,7 @@ bool Events::eventPlayerOnMoveItem(Player* player, Item* item, uint16_t count, c return scriptInterface.callFunction(7); } -void Events::eventPlayerOnItemMoved(Player* player, Item* item, uint16_t count, const Position &fromPosition, const Position &toPosition, Cylinder* fromCylinder, Cylinder* toCylinder) { +void Events::eventPlayerOnItemMoved(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { // Player:onItemMoved(item, count, fromPosition, toPosition) or Player.onItemMoved(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder) if (info.playerOnItemMoved == -1) { return; @@ -801,7 +801,7 @@ void Events::eventPlayerOnItemMoved(Player* player, Item* item, uint16_t count, scriptInterface.callVoidFunction(7); } -void Events::eventPlayerOnChangeZone(Player* player, ZoneType_t zone) { +void Events::eventPlayerOnChangeZone(std::shared_ptr player, ZoneType_t zone) { // Player:onChangeZone(zone) if (info.playerOnChangeZone == -1) { return; @@ -828,7 +828,7 @@ void Events::eventPlayerOnChangeZone(Player* player, ZoneType_t zone) { scriptInterface.callVoidFunction(2); } -bool Events::eventPlayerOnMoveCreature(Player* player, Creature* creature, const Position &fromPosition, const Position &toPosition) { +bool Events::eventPlayerOnMoveCreature(std::shared_ptr player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) { // Player:onMoveCreature(creature, fromPosition, toPosition) or Player.onMoveCreature(self, creature, fromPosition, toPosition) if (info.playerOnMoveCreature == -1) { return true; @@ -860,7 +860,7 @@ bool Events::eventPlayerOnMoveCreature(Player* player, Creature* creature, const return scriptInterface.callFunction(4); } -void Events::eventPlayerOnReportRuleViolation(Player* player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) { +void Events::eventPlayerOnReportRuleViolation(std::shared_ptr player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) { // Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation) if (info.playerOnReportRuleViolation == -1) { return; @@ -894,7 +894,7 @@ void Events::eventPlayerOnReportRuleViolation(Player* player, const std::string scriptInterface.callVoidFunction(6); } -bool Events::eventPlayerOnReportBug(Player* player, const std::string &message, const Position &position, uint8_t category) { +bool Events::eventPlayerOnReportBug(std::shared_ptr player, const std::string &message, const Position &position, uint8_t category) { // Player:onReportBug(message, position, category) if (info.playerOnReportBug == -1) { return true; @@ -924,7 +924,7 @@ bool Events::eventPlayerOnReportBug(Player* player, const std::string &message, return scriptInterface.callFunction(4); } -bool Events::eventPlayerOnTurn(Player* player, Direction direction) { +bool Events::eventPlayerOnTurn(std::shared_ptr player, Direction direction) { // Player:onTurn(direction) or Player.onTurn(self, direction) if (info.playerOnTurn == -1) { return true; @@ -952,7 +952,7 @@ bool Events::eventPlayerOnTurn(Player* player, Direction direction) { return scriptInterface.callFunction(2); } -bool Events::eventPlayerOnTradeRequest(Player* player, Player* target, Item* item) { +bool Events::eventPlayerOnTradeRequest(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) { // Player:onTradeRequest(target, item) if (info.playerOnTradeRequest == -1) { return true; @@ -984,7 +984,7 @@ bool Events::eventPlayerOnTradeRequest(Player* player, Player* target, Item* ite return scriptInterface.callFunction(3); } -bool Events::eventPlayerOnTradeAccept(Player* player, Player* target, Item* item, Item* targetItem) { +bool Events::eventPlayerOnTradeAccept(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, std::shared_ptr targetItem) { // Player:onTradeAccept(target, item, targetItem) if (info.playerOnTradeAccept == -1) { return true; @@ -1019,7 +1019,7 @@ bool Events::eventPlayerOnTradeAccept(Player* player, Player* target, Item* item return scriptInterface.callFunction(4); } -void Events::eventPlayerOnGainExperience(Player* player, Creature* target, uint64_t &exp, uint64_t rawExp) { +void Events::eventPlayerOnGainExperience(std::shared_ptr player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) { // Player:onGainExperience(target, exp, rawExp) // rawExp gives the original exp which is not multiplied if (info.playerOnGainExperience == -1) { @@ -1063,7 +1063,7 @@ void Events::eventPlayerOnGainExperience(Player* player, Creature* target, uint6 scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnLoseExperience(Player* player, uint64_t &exp) { +void Events::eventPlayerOnLoseExperience(std::shared_ptr player, uint64_t &exp) { // Player:onLoseExperience(exp) if (info.playerOnLoseExperience == -1) { return; @@ -1098,7 +1098,7 @@ void Events::eventPlayerOnLoseExperience(Player* player, uint64_t &exp) { scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnGainSkillTries(Player* player, skills_t skill, uint64_t &tries) { +void Events::eventPlayerOnGainSkillTries(std::shared_ptr player, skills_t skill, uint64_t &tries) { // Player:onGainSkillTries(skill, tries) if (info.playerOnGainSkillTries == -1) { return; @@ -1134,7 +1134,7 @@ void Events::eventPlayerOnGainSkillTries(Player* player, skills_t skill, uint64_ scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnCombat(Player* player, Creature* target, Item* item, CombatDamage &damage) { +void Events::eventPlayerOnCombat(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) { // Player:onCombat(target, item, primaryDamage, primaryType, secondaryDamage, secondaryType) if (info.playerOnCombat == -1) { return; @@ -1191,7 +1191,7 @@ void Events::eventPlayerOnCombat(Player* player, Creature* target, Item* item, C scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnRequestQuestLog(Player* player) { +void Events::eventPlayerOnRequestQuestLog(std::shared_ptr player) { // Player:onRequestQuestLog() if (info.playerOnRequestQuestLog == -1) { return; @@ -1217,7 +1217,7 @@ void Events::eventPlayerOnRequestQuestLog(Player* player) { scriptInterface.callVoidFunction(1); } -void Events::eventPlayerOnRequestQuestLine(Player* player, uint16_t questId) { +void Events::eventPlayerOnRequestQuestLine(std::shared_ptr player, uint16_t questId) { // Player::onRequestQuestLine() if (info.playerOnRequestQuestLine == -1) { return; @@ -1245,7 +1245,7 @@ void Events::eventPlayerOnRequestQuestLine(Player* player, uint16_t questId) { scriptInterface.callVoidFunction(2); } -void Events::eventPlayerOnInventoryUpdate(Player* player, Item* item, Slots_t slot, bool equip) { +void Events::eventPlayerOnInventoryUpdate(std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool equip) { // Player:onInventoryUpdate(item, slot, equip) if (info.playerOnInventoryUpdate == -1) { return; @@ -1274,7 +1274,7 @@ void Events::eventPlayerOnInventoryUpdate(Player* player, Item* item, Slots_t sl scriptInterface.callVoidFunction(4); } -void Events::eventOnStorageUpdate(Player* player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) { +void Events::eventOnStorageUpdate(std::shared_ptr player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) { // Player::onStorageUpdate(key, value, oldValue, currentTime) if (info.playerOnStorageUpdate == -1) { return; @@ -1306,7 +1306,7 @@ void Events::eventOnStorageUpdate(Player* player, const uint32_t key, const int3 } // Monster -void Events::eventMonsterOnDropLoot(Monster* monster, Container* corpse) { +void Events::eventMonsterOnDropLoot(std::shared_ptr monster, std::shared_ptr corpse) { // Monster:onDropLoot(corpse) if (info.monsterOnDropLoot == -1) { return; diff --git a/src/lua/creature/events.hpp b/src/lua/creature/events.hpp index ef09e438dee..172144a6f9a 100644 --- a/src/lua/creature/events.hpp +++ b/src/lua/creature/events.hpp @@ -81,49 +81,49 @@ class Events { } // Creature - bool eventCreatureOnChangeOutfit(Creature* creature, const Outfit_t &outfit); - ReturnValue eventCreatureOnAreaCombat(Creature* creature, Tile* tile, bool aggressive); - ReturnValue eventCreatureOnTargetCombat(Creature* creature, Creature* target); - void eventCreatureOnHear(Creature* creature, Creature* speaker, const std::string &words, SpeakClasses type); - void eventCreatureOnDrainHealth(Creature* creature, Creature* attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary); + bool eventCreatureOnChangeOutfit(std::shared_ptr creature, const Outfit_t &outfit); + ReturnValue eventCreatureOnAreaCombat(std::shared_ptr creature, std::shared_ptr tile, bool aggressive); + ReturnValue eventCreatureOnTargetCombat(std::shared_ptr creature, std::shared_ptr target); + void eventCreatureOnHear(std::shared_ptr creature, std::shared_ptr speaker, const std::string &words, SpeakClasses type); + void eventCreatureOnDrainHealth(std::shared_ptr creature, std::shared_ptr attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary); // Party - bool eventPartyOnJoin(Party* party, Player* player); - bool eventPartyOnLeave(Party* party, Player* player); + bool eventPartyOnJoin(Party* party, std::shared_ptr player); + bool eventPartyOnLeave(Party* party, std::shared_ptr player); bool eventPartyOnDisband(Party* party); void eventPartyOnShareExperience(Party* party, uint64_t &exp); // Player - bool eventPlayerOnBrowseField(Player* player, const Position &position); - void eventPlayerOnLook(Player* player, const Position &position, Thing* thing, uint8_t stackpos, int32_t lookDistance); - void eventPlayerOnLookInBattleList(Player* player, Creature* creature, int32_t lookDistance); - void eventPlayerOnLookInTrade(Player* player, Player* partner, Item* item, int32_t lookDistance); - bool eventPlayerOnLookInShop(Player* player, const ItemType* itemType, uint8_t count); - bool eventPlayerOnMoveItem(Player* player, Item* item, uint16_t count, const Position &fromPosition, const Position &toPosition, Cylinder* fromCylinder, Cylinder* toCylinder); - void eventPlayerOnItemMoved(Player* player, Item* item, uint16_t count, const Position &fromPosition, const Position &toPosition, Cylinder* fromCylinder, Cylinder* toCylinder); - void eventPlayerOnChangeZone(Player* player, ZoneType_t zone); - bool eventPlayerOnMoveCreature(Player* player, Creature* creature, const Position &fromPosition, const Position &toPosition); - void eventPlayerOnReportRuleViolation(Player* player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation); - bool eventPlayerOnReportBug(Player* player, const std::string &message, const Position &position, uint8_t category); - bool eventPlayerOnTurn(Player* player, Direction direction); - bool eventPlayerOnTradeRequest(Player* player, Player* target, Item* item); - bool eventPlayerOnTradeAccept(Player* player, Player* target, Item* item, Item* targetItem); - void eventPlayerOnGainExperience(Player* player, Creature* target, uint64_t &exp, uint64_t rawExp); - void eventPlayerOnLoseExperience(Player* player, uint64_t &exp); - void eventPlayerOnGainSkillTries(Player* player, skills_t skill, uint64_t &tries); - bool eventPlayerOnRemoveCount(Player* player, Item* item); - void eventPlayerOnRequestQuestLog(Player* player); - void eventPlayerOnRequestQuestLine(Player* player, uint16_t questId); - void eventOnStorageUpdate(Player* player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime); - void eventPlayerOnCombat(Player* player, Creature* target, Item* item, CombatDamage &damage); - void eventPlayerOnInventoryUpdate(Player* player, Item* item, Slots_t slot, bool equip); + bool eventPlayerOnBrowseField(std::shared_ptr player, const Position &position); + void eventPlayerOnLook(std::shared_ptr player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance); + void eventPlayerOnLookInBattleList(std::shared_ptr player, std::shared_ptr creature, int32_t lookDistance); + void eventPlayerOnLookInTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr item, int32_t lookDistance); + bool eventPlayerOnLookInShop(std::shared_ptr player, const ItemType* itemType, uint8_t count); + bool eventPlayerOnMoveItem(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); + void eventPlayerOnItemMoved(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); + void eventPlayerOnChangeZone(std::shared_ptr player, ZoneType_t zone); + bool eventPlayerOnMoveCreature(std::shared_ptr player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition); + void eventPlayerOnReportRuleViolation(std::shared_ptr player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation); + bool eventPlayerOnReportBug(std::shared_ptr player, const std::string &message, const Position &position, uint8_t category); + bool eventPlayerOnTurn(std::shared_ptr player, Direction direction); + bool eventPlayerOnTradeRequest(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item); + bool eventPlayerOnTradeAccept(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, std::shared_ptr targetItem); + void eventPlayerOnGainExperience(std::shared_ptr player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp); + void eventPlayerOnLoseExperience(std::shared_ptr player, uint64_t &exp); + void eventPlayerOnGainSkillTries(std::shared_ptr player, skills_t skill, uint64_t &tries); + bool eventPlayerOnRemoveCount(std::shared_ptr player, std::shared_ptr item); + void eventPlayerOnRequestQuestLog(std::shared_ptr player); + void eventPlayerOnRequestQuestLine(std::shared_ptr player, uint16_t questId); + void eventOnStorageUpdate(std::shared_ptr player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime); + void eventPlayerOnCombat(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage); + void eventPlayerOnInventoryUpdate(std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool equip); // Monster - void eventMonsterOnDropLoot(Monster* monster, Container* corpse); - void eventMonsterOnSpawn(Monster* monster, const Position &position); + void eventMonsterOnDropLoot(std::shared_ptr monster, std::shared_ptr corpse); + void eventMonsterOnSpawn(std::shared_ptr monster, const Position &position); // Monster - void eventNpcOnSpawn(Npc* npc, const Position &position); + void eventNpcOnSpawn(std::shared_ptr npc, const Position &position); private: LuaScriptInterface scriptInterface; diff --git a/src/lua/creature/movement.cpp b/src/lua/creature/movement.cpp index 92945118978..29ba10f8cce 100644 --- a/src/lua/creature/movement.cpp +++ b/src/lua/creature/movement.cpp @@ -147,7 +147,7 @@ bool MoveEvents::registerEvent(const std::shared_ptr moveEvent, int32 } } -std::shared_ptr MoveEvents::getEvent(Item &item, MoveEvent_t eventType, Slots_t slot) { +std::shared_ptr MoveEvents::getEvent(const std::shared_ptr &item, MoveEvent_t eventType, Slots_t slot) { uint32_t slotp; switch (slot) { case CONST_SLOT_HEAD: @@ -185,8 +185,8 @@ std::shared_ptr MoveEvents::getEvent(Item &item, MoveEvent_t eventTyp break; } - if (item.hasAttribute(ItemAttribute_t::ACTIONID)) { - std::map::iterator it = actionIdMap.find(item.getAttribute(ItemAttribute_t::ACTIONID)); + if (item->hasAttribute(ItemAttribute_t::ACTIONID)) { + std::map::iterator it = actionIdMap.find(item->getAttribute(ItemAttribute_t::ACTIONID)); if (it != actionIdMap.end()) { std::list> moveEventList = it->second.moveEvent[eventType]; for (const auto &moveEvent : moveEventList) { @@ -197,7 +197,7 @@ std::shared_ptr MoveEvents::getEvent(Item &item, MoveEvent_t eventTyp } } - auto it = itemIdMap.find(item.getID()); + auto it = itemIdMap.find(item->getID()); if (it != itemIdMap.end()) { std::list> &moveEventList = it->second.moveEvent[eventType]; for (const auto &moveEvent : moveEventList) { @@ -209,10 +209,10 @@ std::shared_ptr MoveEvents::getEvent(Item &item, MoveEvent_t eventTyp return nullptr; } -std::shared_ptr MoveEvents::getEvent(Item &item, MoveEvent_t eventType) { +std::shared_ptr MoveEvents::getEvent(const std::shared_ptr &item, MoveEvent_t eventType) { std::map::iterator it; - if (item.hasAttribute(ItemAttribute_t::UNIQUEID)) { - it = uniqueIdMap.find(item.getAttribute(ItemAttribute_t::UNIQUEID)); + if (item->hasAttribute(ItemAttribute_t::UNIQUEID)) { + it = uniqueIdMap.find(item->getAttribute(ItemAttribute_t::UNIQUEID)); if (it != uniqueIdMap.end()) { std::list> &moveEventList = it->second.moveEvent[eventType]; if (!moveEventList.empty()) { @@ -221,8 +221,8 @@ std::shared_ptr MoveEvents::getEvent(Item &item, MoveEvent_t eventTyp } } - if (item.hasAttribute(ItemAttribute_t::ACTIONID)) { - it = actionIdMap.find(item.getAttribute(ItemAttribute_t::ACTIONID)); + if (item->hasAttribute(ItemAttribute_t::ACTIONID)) { + it = actionIdMap.find(item->getAttribute(ItemAttribute_t::ACTIONID)); if (it != actionIdMap.end()) { std::list> &moveEventList = it->second.moveEvent[eventType]; if (!moveEventList.empty()) { @@ -231,7 +231,7 @@ std::shared_ptr MoveEvents::getEvent(Item &item, MoveEvent_t eventTyp } } - it = itemIdMap.find(item.getID()); + it = itemIdMap.find(item->getID()); if (it != itemIdMap.end()) { std::list> &moveEventList = it->second.moveEvent[eventType]; if (!moveEventList.empty()) { @@ -265,8 +265,8 @@ bool MoveEvents::registerEvent(const std::shared_ptr moveEvent, const } } -std::shared_ptr MoveEvents::getEvent(Tile &tile, MoveEvent_t eventType) { - if (auto it = positionsMap.find(tile.getPosition()); +std::shared_ptr MoveEvents::getEvent(const std::shared_ptr &tile, MoveEvent_t eventType) { + if (auto it = positionsMap.find(tile->getPosition()); it != positionsMap.end()) { std::list> &moveEventList = it->second.moveEvent[eventType]; if (!moveEventList.empty()) { @@ -276,8 +276,8 @@ std::shared_ptr MoveEvents::getEvent(Tile &tile, MoveEvent_t eventTyp return nullptr; } -uint32_t MoveEvents::onCreatureMove(Creature &creature, Tile &tile, MoveEvent_t eventType) { - const Position &pos = tile.getPosition(); +uint32_t MoveEvents::onCreatureMove(const std::shared_ptr &creature, const std::shared_ptr &tile, MoveEvent_t eventType) { + const Position &pos = tile->getPosition(); uint32_t ret = 1; @@ -286,18 +286,18 @@ uint32_t MoveEvents::onCreatureMove(Creature &creature, Tile &tile, MoveEvent_t ret &= moveEvent->fireStepEvent(creature, nullptr, pos); } - for (size_t i = tile.getFirstIndex(), j = tile.getLastIndex(); i < j; ++i) { - Thing* thing = tile.getThing(i); + for (size_t i = tile->getFirstIndex(), j = tile->getLastIndex(); i < j; ++i) { + std::shared_ptr thing = tile->getThing(i); if (!thing) { continue; } - Item* tileItem = thing->getItem(); + std::shared_ptr tileItem = thing->getItem(); if (!tileItem) { continue; } - moveEvent = getEvent(*tileItem, eventType); + moveEvent = getEvent(tileItem, eventType); if (moveEvent) { auto step = moveEvent->fireStepEvent(creature, tileItem, pos); // If there is any problem in the function, we will kill the loop @@ -310,27 +310,27 @@ uint32_t MoveEvents::onCreatureMove(Creature &creature, Tile &tile, MoveEvent_t return ret; } -uint32_t MoveEvents::onPlayerEquip(Player &player, Item &item, Slots_t slot, bool isCheck) { +uint32_t MoveEvents::onPlayerEquip(const std::shared_ptr &player, const std::shared_ptr &item, Slots_t slot, bool isCheck) { const auto &moveEvent = getEvent(item, MOVE_EVENT_EQUIP, slot); if (!moveEvent) { return 1; } - g_events().eventPlayerOnInventoryUpdate(&player, &item, slot, true); - g_callbacks().executeCallback(EventCallback_t::playerOnInventoryUpdate, &EventCallback::playerOnInventoryUpdate, &player, &item, slot, true); + g_events().eventPlayerOnInventoryUpdate(player, item, slot, true); + g_callbacks().executeCallback(EventCallback_t::playerOnInventoryUpdate, &EventCallback::playerOnInventoryUpdate, player, item, slot, true); return moveEvent->fireEquip(player, item, slot, isCheck); } -uint32_t MoveEvents::onPlayerDeEquip(Player &player, Item &item, Slots_t slot) { +uint32_t MoveEvents::onPlayerDeEquip(const std::shared_ptr &player, const std::shared_ptr &item, Slots_t slot) { const auto &moveEvent = getEvent(item, MOVE_EVENT_DEEQUIP, slot); if (!moveEvent) { return 1; } - g_events().eventPlayerOnInventoryUpdate(&player, &item, slot, false); - g_callbacks().executeCallback(EventCallback_t::playerOnInventoryUpdate, &EventCallback::playerOnInventoryUpdate, &player, &item, slot, false); + g_events().eventPlayerOnInventoryUpdate(player, item, slot, false); + g_callbacks().executeCallback(EventCallback_t::playerOnInventoryUpdate, &EventCallback::playerOnInventoryUpdate, player, item, slot, false); return moveEvent->fireEquip(player, item, slot, false); } -uint32_t MoveEvents::onItemMove(Item &item, Tile &tile, bool isAdd) { +uint32_t MoveEvents::onItemMove(const std::shared_ptr &item, const std::shared_ptr &tile, bool isAdd) { MoveEvent_t eventType1, eventType2; if (isAdd) { eventType1 = MOVE_EVENT_ADD_ITEM; @@ -344,29 +344,29 @@ uint32_t MoveEvents::onItemMove(Item &item, Tile &tile, bool isAdd) { auto moveEvent = getEvent(tile, eventType1); if (moveEvent) { // No tile item - ret &= moveEvent->fireAddRemItem(item, tile.getPosition()); + ret &= moveEvent->fireAddRemItem(item, tile->getPosition()); } moveEvent = getEvent(item, eventType1); if (moveEvent) { // No tile item - ret &= moveEvent->fireAddRemItem(item, tile.getPosition()); + ret &= moveEvent->fireAddRemItem(item, tile->getPosition()); } - for (size_t i = tile.getFirstIndex(), j = tile.getLastIndex(); i < j; ++i) { - Thing* thing = tile.getThing(i); + for (size_t i = tile->getFirstIndex(), j = tile->getLastIndex(); i < j; ++i) { + std::shared_ptr thing = tile->getThing(i); if (!thing) { continue; } - Item* tileItem = thing->getItem(); + std::shared_ptr tileItem = thing->getItem(); if (!tileItem) { continue; } - moveEvent = getEvent(*tileItem, eventType2); + moveEvent = getEvent(tileItem, eventType2); if (moveEvent) { - auto moveItem = moveEvent->fireAddRemItem(item, *tileItem, tile.getPosition()); + auto moveItem = moveEvent->fireAddRemItem(item, tileItem, tile->getPosition()); // If there is any problem in the function, we will kill the loop if (moveItem == 0) { break; @@ -409,7 +409,7 @@ std::string MoveEvent::getScriptTypeName() const { } } -uint32_t MoveEvent::StepInField(Creature* creature, Item* item, const Position &) { +uint32_t MoveEvent::StepInField(std::shared_ptr creature, std::shared_ptr item, const Position &) { if (creature == nullptr) { g_logger().error("[MoveEvent::StepInField] - Creature is nullptr"); return 0; @@ -420,27 +420,27 @@ uint32_t MoveEvent::StepInField(Creature* creature, Item* item, const Position & return 0; } - MagicField* field = item->getMagicField(); + std::shared_ptr field = item->getMagicField(); if (field) { - field->onStepInField(*creature); + field->onStepInField(creature); return 1; } return LUA_ERROR_ITEM_NOT_FOUND; } -uint32_t MoveEvent::StepOutField(Creature*, Item*, const Position &) { +uint32_t MoveEvent::StepOutField(std::shared_ptr, std::shared_ptr, const Position &) { return 1; } -uint32_t MoveEvent::AddItemField(Item* item, Item*, const Position &) { +uint32_t MoveEvent::AddItemField(std::shared_ptr item, std::shared_ptr, const Position &) { if (item == nullptr) { g_logger().error("[MoveEvent::AddItemField] - Item is nullptr"); return 0; } - if (MagicField* field = item->getMagicField()) { - Tile* tile = item->getTile(); + if (std::shared_ptr field = item->getMagicField()) { + std::shared_ptr tile = item->getTile(); if (tile == nullptr) { g_logger().debug("[MoveEvent::AddItemField] - Tile is nullptr"); return 0; @@ -450,24 +450,24 @@ uint32_t MoveEvent::AddItemField(Item* item, Item*, const Position &) { g_logger().debug("[MoveEvent::AddItemField] - Creatures is nullptr"); return 0; } - for (Creature* creature : *creatures) { + for (auto &creature : *creatures) { if (field == nullptr) { g_logger().debug("[MoveEvent::AddItemField] - MagicField is nullptr"); return 0; } - field->onStepInField(*creature); + field->onStepInField(creature); } return 1; } return LUA_ERROR_ITEM_NOT_FOUND; } -uint32_t MoveEvent::RemoveItemField(Item*, Item*, const Position &) { +uint32_t MoveEvent::RemoveItemField(std::shared_ptr, std::shared_ptr, const Position &) { return 1; } -uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, Player* player, Item* item, Slots_t slot, bool isCheck) { +uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool isCheck) { if (player == nullptr) { g_logger().error("[MoveEvent::EquipItem] - Player is nullptr"); return 0; @@ -530,7 +530,7 @@ uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, Player } if (it.abilities->speed != 0) { - g_game().changePlayerSpeed(*player, it.abilities->speed); + g_game().changePlayerSpeed(player, it.abilities->speed); } player->addConditionSuppressions(it.abilities->conditionSuppressions); @@ -581,7 +581,7 @@ uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, Player return 1; } -uint32_t MoveEvent::DeEquipItem(const std::shared_ptr MoveEvent, Player* player, Item* item, Slots_t slot, bool) { +uint32_t MoveEvent::DeEquipItem(const std::shared_ptr MoveEvent, std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool) { if (player == nullptr) { g_logger().error("[MoveEvent::EquipItem] - Player is nullptr"); return 0; @@ -623,7 +623,7 @@ uint32_t MoveEvent::DeEquipItem(const std::shared_ptr MoveEvent, Play } if (it.abilities->speed != 0) { - g_game().changePlayerSpeed(*player, -it.abilities->speed); + g_game().changePlayerSpeed(player, -it.abilities->speed); } player->removeConditionSuppressions(); @@ -664,22 +664,22 @@ void MoveEvent::setEventType(MoveEvent_t type) { eventType = type; } -uint32_t MoveEvent::fireStepEvent(Creature &creature, Item* item, const Position &pos) const { +uint32_t MoveEvent::fireStepEvent(const std::shared_ptr &creature, std::shared_ptr item, const Position &pos) const { if (isLoadedCallback()) { return executeStep(creature, item, pos); } else { - return stepFunction(&creature, item, pos); + return stepFunction(creature, item, pos); } } -bool MoveEvent::executeStep(Creature &creature, Item* item, const Position &pos) const { +bool MoveEvent::executeStep(const std::shared_ptr &creature, std::shared_ptr item, const Position &pos) const { // onStepIn(creature, item, pos, fromPosition) // onStepOut(creature, item, pos, fromPosition) // Check if the new position is the same as the old one // If it is, log a warning and either teleport the player to their temple position if item type is an teleport - auto fromPosition = creature.getLastPosition(); - if (auto player = creature.getPlayer(); item && fromPosition == pos && getEventType() == MOVE_EVENT_STEP_IN) { + auto fromPosition = creature->getLastPosition(); + if (auto player = creature->getPlayer(); item && fromPosition == pos && getEventType() == MOVE_EVENT_STEP_IN) { if (const ItemType &itemType = Item::items[item->getID()]; player && itemType.isTeleport()) { g_logger().warn("[{}] cannot teleport player: {}, to the same position: {} of fromPosition: {}", __FUNCTION__, player->getName(), pos.toString(), fromPosition.toString()); g_game().internalTeleport(player, player->getTemplePosition()); @@ -694,11 +694,11 @@ bool MoveEvent::executeStep(Creature &creature, Item* item, const Position &pos) if (item != nullptr) { g_logger().error("[MoveEvent::executeStep - Creature {} item {}, position {}] " "Call stack overflow. Too many lua script calls being nested.", - creature.getName(), item->getName(), pos.toString()); + creature->getName(), item->getName(), pos.toString()); } else { g_logger().error("[MoveEvent::executeStep - Creature {}, position {}] " "Call stack overflow. Too many lua script calls being nested.", - creature.getName(), pos.toString()); + creature->getName(), pos.toString()); } return false; } @@ -709,8 +709,8 @@ bool MoveEvent::executeStep(Creature &creature, Item* item, const Position &pos) lua_State* L = getScriptInterface()->getLuaState(); getScriptInterface()->pushFunction(getScriptId()); - LuaScriptInterface::pushUserdata(L, &creature); - LuaScriptInterface::setCreatureMetatable(L, -1, &creature); + LuaScriptInterface::pushUserdata(L, creature); + LuaScriptInterface::setCreatureMetatable(L, -1, creature); LuaScriptInterface::pushThing(L, item); LuaScriptInterface::pushPosition(L, pos); LuaScriptInterface::pushPosition(L, fromPosition); @@ -718,26 +718,26 @@ bool MoveEvent::executeStep(Creature &creature, Item* item, const Position &pos) return getScriptInterface()->callFunction(4); } -uint32_t MoveEvent::fireEquip(Player &player, Item &item, Slots_t toSlot, bool isCheck) { +uint32_t MoveEvent::fireEquip(const std::shared_ptr &player, const std::shared_ptr &item, Slots_t toSlot, bool isCheck) { if (isLoadedCallback()) { - if (!equipFunction || equipFunction(static_self_cast(), &player, &item, toSlot, isCheck) == 1) { + if (!equipFunction || equipFunction(static_self_cast(), player, item, toSlot, isCheck) == 1) { if (executeEquip(player, item, toSlot, isCheck)) { return 1; } } return 0; } else { - return equipFunction(static_self_cast(), &player, &item, toSlot, isCheck); + return equipFunction(static_self_cast(), player, item, toSlot, isCheck); } } -bool MoveEvent::executeEquip(Player &player, Item &item, Slots_t onSlot, bool isCheck) const { +bool MoveEvent::executeEquip(const std::shared_ptr &player, const std::shared_ptr &item, Slots_t onSlot, bool isCheck) const { // onEquip(player, item, slot, isCheck) // onDeEquip(player, item, slot, isCheck) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[MoveEvent::executeEquip - Player {} item {}] " "Call stack overflow. Too many lua script calls being nested.", - player.getName(), item.getName()); + player->getName(), item->getName()); return false; } @@ -747,31 +747,31 @@ bool MoveEvent::executeEquip(Player &player, Item &item, Slots_t onSlot, bool is lua_State* L = getScriptInterface()->getLuaState(); getScriptInterface()->pushFunction(getScriptId()); - LuaScriptInterface::pushUserdata(L, &player); + LuaScriptInterface::pushUserdata(L, player); LuaScriptInterface::setMetatable(L, -1, "Player"); - LuaScriptInterface::pushThing(L, &item); + LuaScriptInterface::pushThing(L, item); lua_pushnumber(L, onSlot); LuaScriptInterface::pushBoolean(L, isCheck); return getScriptInterface()->callFunction(4); } -uint32_t MoveEvent::fireAddRemItem(Item &item, Item &fromTile, const Position &pos) const { +uint32_t MoveEvent::fireAddRemItem(const std::shared_ptr &item, const std::shared_ptr &fromTile, const Position &pos) const { if (isLoadedCallback()) { return executeAddRemItem(item, fromTile, pos); } else { - return moveFunction(&item, &fromTile, pos); + return moveFunction(item, fromTile, pos); } } -bool MoveEvent::executeAddRemItem(Item &item, Item &fromTile, const Position &pos) const { +bool MoveEvent::executeAddRemItem(const std::shared_ptr &item, const std::shared_ptr &fromTile, const Position &pos) const { // onAddItem(moveitem, tileitem, pos) // onRemoveItem(moveitem, tileitem, pos) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[MoveEvent::executeAddRemItem - " "Item {} item on tile x: {} y: {} z: {}] " "Call stack overflow. Too many lua script calls being nested.", - item.getName(), pos.getX(), pos.getY(), pos.getZ()); + item->getName(), pos.getX(), pos.getY(), pos.getZ()); return false; } @@ -781,29 +781,29 @@ bool MoveEvent::executeAddRemItem(Item &item, Item &fromTile, const Position &po lua_State* L = getScriptInterface()->getLuaState(); getScriptInterface()->pushFunction(getScriptId()); - LuaScriptInterface::pushThing(L, &item); - LuaScriptInterface::pushThing(L, &fromTile); + LuaScriptInterface::pushThing(L, item); + LuaScriptInterface::pushThing(L, fromTile); LuaScriptInterface::pushPosition(L, pos); return getScriptInterface()->callFunction(3); } -uint32_t MoveEvent::fireAddRemItem(Item &item, const Position &pos) const { +uint32_t MoveEvent::fireAddRemItem(const std::shared_ptr &item, const Position &pos) const { if (isLoadedCallback()) { return executeAddRemItem(item, pos); } else { - return moveFunction(&item, nullptr, pos); + return moveFunction(item, nullptr, pos); } } -bool MoveEvent::executeAddRemItem(Item &item, const Position &pos) const { +bool MoveEvent::executeAddRemItem(const std::shared_ptr &item, const Position &pos) const { // onaddItem(moveitem, pos) // onRemoveItem(moveitem, pos) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[MoveEvent::executeAddRemItem - " "Item {} item on tile x: {} y: {} z: {}] " "Call stack overflow. Too many lua script calls being nested.", - item.getName(), pos.getX(), pos.getY(), pos.getZ()); + item->getName(), pos.getX(), pos.getY(), pos.getZ()); return false; } @@ -813,7 +813,7 @@ bool MoveEvent::executeAddRemItem(Item &item, const Position &pos) const { lua_State* L = getScriptInterface()->getLuaState(); getScriptInterface()->pushFunction(getScriptId()); - LuaScriptInterface::pushThing(L, &item); + LuaScriptInterface::pushThing(L, item); LuaScriptInterface::pushPosition(L, pos); return getScriptInterface()->callFunction(2); diff --git a/src/lua/creature/movement.hpp b/src/lua/creature/movement.hpp index a4b613c4ac7..d410cf2a03f 100644 --- a/src/lua/creature/movement.hpp +++ b/src/lua/creature/movement.hpp @@ -36,10 +36,10 @@ class MoveEvents final : public Scripts { return inject(); } - uint32_t onCreatureMove(Creature &creature, Tile &tile, MoveEvent_t eventType); - uint32_t onPlayerEquip(Player &player, Item &item, Slots_t slot, bool isCheck); - uint32_t onPlayerDeEquip(Player &player, Item &item, Slots_t slot); - uint32_t onItemMove(Item &item, Tile &tile, bool isAdd); + uint32_t onCreatureMove(const std::shared_ptr &creature, const std::shared_ptr &tile, MoveEvent_t eventType); + uint32_t onPlayerEquip(const std::shared_ptr &player, const std::shared_ptr &item, Slots_t slot, bool isCheck); + uint32_t onPlayerDeEquip(const std::shared_ptr &player, const std::shared_ptr &item, Slots_t slot); + uint32_t onItemMove(const std::shared_ptr &item, const std::shared_ptr &tile, bool isAdd); std::map getPositionsMap() const { return positionsMap; @@ -105,7 +105,7 @@ class MoveEvents final : public Scripts { actionIdMap.try_emplace(actionId, moveEventList); } - std::shared_ptr getEvent(Item &item, MoveEvent_t eventType); + std::shared_ptr getEvent(const std::shared_ptr &item, MoveEvent_t eventType); bool registerLuaItemEvent(const std::shared_ptr moveEvent); bool registerLuaActionEvent(const std::shared_ptr moveEvent); @@ -120,9 +120,9 @@ class MoveEvents final : public Scripts { bool registerEvent(const std::shared_ptr moveEvent, int32_t id, std::map &moveListMap) const; bool registerEvent(const std::shared_ptr moveEvent, const Position &position, std::map &moveListMap) const; - std::shared_ptr getEvent(Tile &tile, MoveEvent_t eventType); + std::shared_ptr getEvent(const std::shared_ptr &tile, MoveEvent_t eventType); - std::shared_ptr getEvent(Item &item, MoveEvent_t eventType, Slots_t slot); + std::shared_ptr getEvent(const std::shared_ptr &item, MoveEvent_t eventType, Slots_t slot); std::map uniqueIdMap; std::map actionIdMap; @@ -139,21 +139,21 @@ class MoveEvent final : public Script, public SharedObject { MoveEvent_t getEventType() const; void setEventType(MoveEvent_t type); - uint32_t fireStepEvent(Creature &creature, Item* item, const Position &pos) const; - uint32_t fireAddRemItem(Item &item, Item &tileItem, const Position &pos) const; - uint32_t fireAddRemItem(Item &item, const Position &pos) const; - uint32_t fireEquip(Player &player, Item &item, Slots_t slot, bool isCheck); + uint32_t fireStepEvent(const std::shared_ptr &creature, std::shared_ptr item, const Position &pos) const; + uint32_t fireAddRemItem(const std::shared_ptr &item, const std::shared_ptr &tileItem, const Position &pos) const; + uint32_t fireAddRemItem(const std::shared_ptr &item, const Position &pos) const; + uint32_t fireEquip(const std::shared_ptr &player, const std::shared_ptr &item, Slots_t slot, bool isCheck); uint32_t getSlot() const { return slot; } // Scripting to lua interface - bool executeStep(Creature &creature, Item* item, const Position &pos) const; - bool executeEquip(Player &player, Item &item, Slots_t slot, bool isCheck) const; - bool executeAddRemItem(Item &item, Item &tileItem, const Position &pos) const; + bool executeStep(const std::shared_ptr &creature, std::shared_ptr item, const Position &pos) const; + bool executeEquip(const std::shared_ptr &player, const std::shared_ptr &item, Slots_t slot, bool isCheck) const; + bool executeAddRemItem(const std::shared_ptr &item, const std::shared_ptr &tileItem, const Position &pos) const; // No have tile item - bool executeAddRemItem(Item &item, const Position &pos) const; + bool executeAddRemItem(const std::shared_ptr &item, const Position &pos) const; // // onEquip information @@ -242,14 +242,14 @@ class MoveEvent final : public Script, public SharedObject { wieldInfo |= info; } - static uint32_t StepInField(Creature* creature, Item* item, const Position &pos); - static uint32_t StepOutField(Creature* creature, Item* item, const Position &pos); + static uint32_t StepInField(std::shared_ptr creature, std::shared_ptr item, const Position &pos); + static uint32_t StepOutField(std::shared_ptr creature, std::shared_ptr item, const Position &pos); - static uint32_t AddItemField(Item* item, Item* tileItem, const Position &pos); - static uint32_t RemoveItemField(Item* item, Item* tileItem, const Position &pos); + static uint32_t AddItemField(std::shared_ptr item, std::shared_ptr tileItem, const Position &pos); + static uint32_t RemoveItemField(std::shared_ptr item, std::shared_ptr tileItem, const Position &pos); - static uint32_t EquipItem(const std::shared_ptr moveEvent, Player* player, Item* item, Slots_t slot, bool boolean); - static uint32_t DeEquipItem(const std::shared_ptr moveEvent, Player* player, Item* item, Slots_t slot, bool boolean); + static uint32_t EquipItem(const std::shared_ptr moveEvent, std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool boolean); + static uint32_t DeEquipItem(const std::shared_ptr moveEvent, std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool boolean); private: std::string getScriptTypeName() const override; @@ -259,23 +259,23 @@ class MoveEvent final : public Script, public SharedObject { MoveEvent_t eventType = MOVE_EVENT_NONE; /// Step function std::function creature, + std::shared_ptr item, const Position &pos )> stepFunction; // Move function std::function item, + std::shared_ptr tileItem, const Position &pos )> moveFunction; // equipFunction std::function moveEvent, - Player* player, - Item* item, + std::shared_ptr player, + std::shared_ptr item, Slots_t slot, bool boolean )> diff --git a/src/lua/creature/raids.cpp b/src/lua/creature/raids.cpp index 27fec5d2792..1e0ec6b0bde 100644 --- a/src/lua/creature/raids.cpp +++ b/src/lua/creature/raids.cpp @@ -365,14 +365,14 @@ bool SingleSpawnEvent::configureRaidEvent(const pugi::xml_node &eventNode) { } bool SingleSpawnEvent::executeEvent() { - Monster* monster = Monster::createMonster(monsterName); + std::shared_ptr monster = Monster::createMonster(monsterName); if (!monster) { g_logger().error("{} - Cant create monster {}", __FUNCTION__, monsterName); return false; } if (!g_game().placeCreature(monster, position, false, true)) { - delete monster; + g_logger().error("{} - Cant create monster {}", __FUNCTION__, monsterName); return false; } @@ -529,7 +529,7 @@ bool AreaSpawnEvent::executeEvent() { for (const MonsterSpawn &spawn : spawnMonsterList) { uint32_t amount = uniform_random(spawn.minAmount, spawn.maxAmount); for (uint32_t i = 0; i < amount; ++i) { - Monster* monster = Monster::createMonster(spawn.name); + std::shared_ptr monster = Monster::createMonster(spawn.name); if (!monster) { g_logger().error("{} - Can't create monster {}", __FUNCTION__, spawn.name); return false; @@ -537,7 +537,7 @@ bool AreaSpawnEvent::executeEvent() { bool success = false; for (int32_t tries = 0; tries < MAXIMUM_TRIES_PER_MONSTER; tries++) { - const Tile* tile = g_game().map.getTile(static_cast(uniform_random(fromPos.x, toPos.x)), static_cast(uniform_random(fromPos.y, toPos.y)), static_cast(uniform_random(fromPos.z, toPos.z))); + std::shared_ptr tile = g_game().map.getTile(static_cast(uniform_random(fromPos.x, toPos.x)), static_cast(uniform_random(fromPos.y, toPos.y)), static_cast(uniform_random(fromPos.z, toPos.z))); if (tile && !tile->isMoveableBlocking() && !tile->hasFlag(TILESTATE_PROTECTIONZONE) && tile->getTopCreature() == nullptr && g_game().placeCreature(monster, tile->getPosition(), false, true)) { success = true; monster->setForgeMonster(false); @@ -546,7 +546,6 @@ bool AreaSpawnEvent::executeEvent() { } if (!success) { - delete monster; } } } diff --git a/src/lua/creature/talkaction.cpp b/src/lua/creature/talkaction.cpp index 13e40746477..4386f6f9b15 100644 --- a/src/lua/creature/talkaction.cpp +++ b/src/lua/creature/talkaction.cpp @@ -25,7 +25,7 @@ bool TalkActions::registerLuaEvent(const TalkAction_ptr &talkAction) { return inserted; } -bool TalkActions::checkWord(Player* player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const { +bool TalkActions::checkWord(std::shared_ptr player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const { auto spacePos = std::ranges::find_if(words.begin(), words.end(), ::isspace); std::string firstWord = words.substr(0, spacePos - words.begin()); @@ -61,7 +61,7 @@ bool TalkActions::checkWord(Player* player, SpeakClasses type, const std::string return talkActionPtr->executeSay(player, words, param, type); } -TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(Player* player, SpeakClasses type, const std::string &words) const { +TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(std::shared_ptr player, SpeakClasses type, const std::string &words) const { for (const auto &[talkactionWords, talkActionPtr] : talkActions) { if (talkactionWords.find(',') != std::string::npos) { auto wordsList = split(talkactionWords); @@ -79,7 +79,7 @@ TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(Player* player, Spea return TALKACTION_CONTINUE; } -bool TalkAction::executeSay(Player* player, const std::string &words, const std::string ¶m, SpeakClasses type) const { +bool TalkAction::executeSay(std::shared_ptr player, const std::string &words, const std::string ¶m, SpeakClasses type) const { // onSay(player, words, param, type) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[TalkAction::executeSay - Player {} words {}] " diff --git a/src/lua/creature/talkaction.hpp b/src/lua/creature/talkaction.hpp index f5e42ff7c91..bc078a72d75 100644 --- a/src/lua/creature/talkaction.hpp +++ b/src/lua/creature/talkaction.hpp @@ -44,7 +44,7 @@ class TalkAction : public Script { } // scripting - bool executeSay(Player* player, const std::string &words, const std::string ¶m, SpeakClasses type) const; + bool executeSay(std::shared_ptr player, const std::string &words, const std::string ¶m, SpeakClasses type) const; // void setGroupType(account::GroupType newGroupType) { @@ -78,8 +78,8 @@ class TalkActions final : public Scripts { return inject(); } - bool checkWord(Player* player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const; - TalkActionResult_t checkPlayerCanSayTalkAction(Player* player, SpeakClasses type, const std::string &words) const; + bool checkWord(std::shared_ptr player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const; + TalkActionResult_t checkPlayerCanSayTalkAction(std::shared_ptr player, SpeakClasses type, const std::string &words) const; bool registerLuaEvent(const TalkAction_ptr &talkAction); void clear(); diff --git a/src/lua/functions/core/game/bank_functions.cpp b/src/lua/functions/core/game/bank_functions.cpp index 2997de4d4cc..e9451a5a637 100644 --- a/src/lua/functions/core/game/bank_functions.cpp +++ b/src/lua/functions/core/game/bank_functions.cpp @@ -98,9 +98,7 @@ int BankFunctions::luaBankWithdraw(lua_State* L) { return 1; } - // TODO: When Player is also shared_ptr, we won't need to verride the deleter - const auto bankablePlayer = std::shared_ptr(player, [](Bankable*) {}); - const auto bank = std::make_shared(bankablePlayer); + const auto bank = std::make_shared(player); pushBoolean(L, bank->withdraw(player, amount)); return 1; } @@ -119,9 +117,7 @@ int BankFunctions::luaBankDeposit(lua_State* L) { if (!player) { return 1; } - // TODO: When Player is also shared_ptr, we won't need to verride the deleter - const auto bankablePlayer = std::shared_ptr(player, [](Bankable*) {}); - const auto bank = std::make_shared(bankablePlayer); + const auto bank = std::make_shared(player); uint64_t amount = 0; if (lua_isnumber(L, 2)) { @@ -154,11 +150,9 @@ std::shared_ptr BankFunctions::getBank(lua_State* L, int32_t arg, bool isG } return std::make_shared(guild); } - Player* player = getPlayer(L, arg, true); + std::shared_ptr player = getPlayer(L, arg, true); if (!player) { return nullptr; } - // TODO: When Player is also shared_ptr, we won't need to verride the deleter - const auto bankablePlayer = std::shared_ptr(player, [](Bankable*) {}); - return std::make_shared(bankablePlayer); + return std::make_shared(player); } diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index 6f872c6907e..1a23358aaf7 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -75,7 +75,7 @@ int GameFunctions::luaGameGetSpectators(lua_State* L) { lua_createtable(L, spectators.size(), 0); int index = 0; - for (Creature* creature : spectators) { + for (std::shared_ptr creature : spectators) { pushUserdata(L, creature); setCreatureMetatable(L, -1, creature); lua_rawseti(L, -2, ++index); @@ -301,7 +301,7 @@ int GameFunctions::luaGameCreateItem(lua_State* L) { subType -= stackCount; } - Item* item = Item::CreateItem(itemId, stackCount); + std::shared_ptr item = Item::CreateItem(itemId, stackCount); if (!item) { if (!hasTable) { lua_pushnil(L); @@ -310,9 +310,9 @@ int GameFunctions::luaGameCreateItem(lua_State* L) { } if (position.x != 0) { - Tile* tile = g_game().map.getTile(position); + std::shared_ptr tile = g_game().map.getTile(position); if (!tile) { - delete item; + if (!hasTable) { lua_pushnil(L); } @@ -321,7 +321,7 @@ int GameFunctions::luaGameCreateItem(lua_State* L) { ReturnValue ret = g_game().internalAddItem(tile, item, INDEX_WHEREEVER, FLAG_NOLIMIT); if (ret != RETURNVALUE_NOERROR) { - delete item; + if (!hasTable) { lua_pushnil(L); } @@ -360,7 +360,7 @@ int GameFunctions::luaGameCreateContainer(lua_State* L) { } } - Container* container = Item::CreateItemAsContainer(id, size); + std::shared_ptr container = Item::CreateItemAsContainer(id, size); if (!container) { lua_pushnil(L); return 1; @@ -368,9 +368,9 @@ int GameFunctions::luaGameCreateContainer(lua_State* L) { if (lua_gettop(L) >= 3) { const Position &position = getPosition(L, 3); - Tile* tile = g_game().map.getTile(position); + std::shared_ptr tile = g_game().map.getTile(position); if (!tile) { - delete container; + lua_pushnil(L); return 1; } @@ -388,7 +388,7 @@ int GameFunctions::luaGameCreateContainer(lua_State* L) { int GameFunctions::luaGameCreateMonster(lua_State* L) { // Game.createMonster(monsterName, position[, extended = false[, force = false[, master = nil]]]) - Monster* monster = Monster::createMonster(getString(L, 1)); + std::shared_ptr monster = Monster::createMonster(getString(L, 1)); if (!monster) { lua_pushnil(L); return 1; @@ -396,7 +396,7 @@ int GameFunctions::luaGameCreateMonster(lua_State* L) { bool isSummon = false; if (lua_gettop(L) >= 5) { - Creature* master = getCreature(L, 5); + std::shared_ptr master = getCreature(L, 5); if (master) { monster->setMaster(master, true); isSummon = true; @@ -413,8 +413,8 @@ int GameFunctions::luaGameCreateMonster(lua_State* L) { if (mtype && mtype->info.raceid > 0 && mtype->info.bosstiaryRace == BosstiaryRarity_t::RARITY_ARCHFOE) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, monster->getPosition(), true); - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (std::shared_ptr spectator : spectators) { + if (auto tmpPlayer = spectator->getPlayer()) { auto bossesOnTracker = g_ioBosstiary().getBosstiaryCooldownRaceId(tmpPlayer); // If not have boss to update, then kill loop for economize resources if (bossesOnTracker.size() == 0) { @@ -432,7 +432,6 @@ int GameFunctions::luaGameCreateMonster(lua_State* L) { if (isSummon) { monster->setMaster(nullptr); } else { - delete monster; } lua_pushnil(L); } @@ -441,7 +440,7 @@ int GameFunctions::luaGameCreateMonster(lua_State* L) { int GameFunctions::luaGameGenerateNpc(lua_State* L) { // Game.generateNpc(npcName) - Npc* npc = Npc::createNpc(getString(L, 1)); + std::shared_ptr npc = Npc::createNpc(getString(L, 1)); if (!npc) { lua_pushnil(L); return 1; @@ -454,7 +453,7 @@ int GameFunctions::luaGameGenerateNpc(lua_State* L) { int GameFunctions::luaGameCreateNpc(lua_State* L) { // Game.createNpc(npcName, position[, extended = false[, force = false]]) - Npc* npc = Npc::createNpc(getString(L, 1)); + std::shared_ptr npc = Npc::createNpc(getString(L, 1)); if (!npc) { lua_pushnil(L); return 1; @@ -467,7 +466,7 @@ int GameFunctions::luaGameCreateNpc(lua_State* L) { pushUserdata(L, npc); setMetatable(L, -1, "Npc"); } else { - delete npc; + lua_pushnil(L); } return 1; @@ -598,9 +597,8 @@ int GameFunctions::luaGameHasDistanceEffect(lua_State* L) { int GameFunctions::luaGameGetOfflinePlayer(lua_State* L) { uint32_t playerId = getNumber(L, 1); - Player* offlinePlayer = new Player(nullptr); + auto offlinePlayer = std::make_shared(nullptr); if (!IOLoginData::loadPlayerById(offlinePlayer, playerId)) { - delete offlinePlayer; lua_pushnil(L); } else { pushUserdata(L, offlinePlayer); @@ -613,11 +611,10 @@ int GameFunctions::luaGameGetOfflinePlayer(lua_State* L) { int GameFunctions::luaGameGetNormalizedPlayerName(lua_State* L) { // Game.getNormalizedPlayerName(name) auto name = getString(L, 1); - Player* player = g_game().getPlayerByName(name, true); + std::shared_ptr player = g_game().getPlayerByName(name, true); if (player) { pushString(L, player->getName()); if (!player->isOnline()) { - delete player; } } else { lua_pushnil(L); @@ -639,7 +636,7 @@ int GameFunctions::luaGameGetNormalizedGuildName(lua_State* L) { int GameFunctions::luaGameAddInfluencedMonster(lua_State* L) { // Game.addInfluencedMonster(monster) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/core/game/global_functions.cpp b/src/lua/functions/core/game/global_functions.cpp index 4a4a4dee66a..a0f283188ae 100644 --- a/src/lua/functions/core/game/global_functions.cpp +++ b/src/lua/functions/core/game/global_functions.cpp @@ -22,7 +22,7 @@ class Creature; int GlobalFunctions::luaDoPlayerAddItem(lua_State* L) { // doPlayerAddItem(cid, itemid, count/subtype, canDropOnMap) // doPlayerAddItem(cid, itemid, count, canDropOnMap, subtype) - Player* player = getPlayer(L, 1); + std::shared_ptr player = getPlayer(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -58,7 +58,7 @@ int GlobalFunctions::luaDoPlayerAddItem(lua_State* L) { stackCount = it.stackSize; } - Item* newItem = Item::CreateItem(itemId, stackCount); + std::shared_ptr newItem = Item::CreateItem(itemId, stackCount); if (!newItem) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); pushBoolean(L, false); @@ -71,7 +71,7 @@ int GlobalFunctions::luaDoPlayerAddItem(lua_State* L) { ReturnValue ret = g_game().internalPlayerAddItem(player, newItem, canDropOnMap); if (ret != RETURNVALUE_NOERROR) { - delete newItem; + pushBoolean(L, false); return 1; } @@ -95,7 +95,7 @@ int GlobalFunctions::luaDoPlayerAddItem(lua_State* L) { int GlobalFunctions::luaDoSetCreatureLight(lua_State* L) { // doSetCreatureLight(cid, lightLevel, lightColor, time) - Creature* creature = getCreature(L, 1); + std::shared_ptr creature = getCreature(L, 1); if (!creature) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -119,7 +119,7 @@ int GlobalFunctions::luaIsValidUID(lua_State* L) { int GlobalFunctions::luaIsDepot(lua_State* L) { // isDepot(uid) - Container* container = getScriptEnv()->getContainerByUID(getNumber(L, -1)); + std::shared_ptr container = getScriptEnv()->getContainerByUID(getNumber(L, -1)); pushBoolean(L, container && container->getDepotLocker()); return 1; } @@ -127,7 +127,7 @@ int GlobalFunctions::luaIsDepot(lua_State* L) { int GlobalFunctions::luaIsMoveable(lua_State* L) { // isMoveable(uid) // isMovable(uid) - Thing* thing = getScriptEnv()->getThingByUID(getNumber(L, -1)); + std::shared_ptr thing = getScriptEnv()->getThingByUID(getNumber(L, -1)); pushBoolean(L, thing && thing->isPushable()); return 1; } @@ -137,7 +137,7 @@ int GlobalFunctions::luaDoAddContainerItem(lua_State* L) { uint32_t uid = getNumber(L, 1); ScriptEnvironment* env = getScriptEnv(); - Container* container = env->getContainerByUID(uid); + std::shared_ptr container = env->getContainerByUID(uid); if (!container) { reportErrorFunc(getErrorDesc(LUA_ERROR_CONTAINER_NOT_FOUND)); pushBoolean(L, false); @@ -163,7 +163,7 @@ int GlobalFunctions::luaDoAddContainerItem(lua_State* L) { while (itemCount > 0) { int32_t stackCount = std::min(it.stackSize, subType); - Item* newItem = Item::CreateItem(itemId, stackCount); + std::shared_ptr newItem = Item::CreateItem(itemId, stackCount); if (!newItem) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); pushBoolean(L, false); @@ -176,7 +176,7 @@ int GlobalFunctions::luaDoAddContainerItem(lua_State* L) { ReturnValue ret = g_game().internalAddItem(container, newItem); if (ret != RETURNVALUE_NOERROR) { - delete newItem; + pushBoolean(L, false); return 1; } @@ -200,14 +200,14 @@ int GlobalFunctions::luaGetDepotId(lua_State* L) { // getDepotId(uid) uint32_t uid = getNumber(L, -1); - Container* container = getScriptEnv()->getContainerByUID(uid); + std::shared_ptr container = getScriptEnv()->getContainerByUID(uid); if (!container) { reportErrorFunc(getErrorDesc(LUA_ERROR_CONTAINER_NOT_FOUND)); pushBoolean(L, false); return 1; } - DepotLocker* depotLocker = container->getDepotLocker(); + std::shared_ptr depotLocker = container->getDepotLocker(); if (!depotLocker) { reportErrorFunc("Depot not found"); pushBoolean(L, false); @@ -279,7 +279,7 @@ int GlobalFunctions::luaCreateCombatArea(lua_State* L) { int GlobalFunctions::luaDoAreaCombatHealth(lua_State* L) { // doAreaCombatHealth(cid, type, pos, area, min, max, effect[, origin = ORIGIN_SPELL]) - Creature* creature = getCreature(L, 1); + std::shared_ptr creature = getCreature(L, 1); if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -319,14 +319,14 @@ int GlobalFunctions::luaDoAreaCombatHealth(lua_State* L) { int GlobalFunctions::luaDoTargetCombatHealth(lua_State* L) { // doTargetCombatHealth(cid, target, type, min, max, effect[, origin = ORIGIN_SPELL]) - Creature* creature = getCreature(L, 1); + std::shared_ptr creature = getCreature(L, 1); if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); return 1; } - Creature* target = getCreature(L, 2); + std::shared_ptr target = getCreature(L, 2); if (!target) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -364,7 +364,7 @@ int GlobalFunctions::luaDoTargetCombatHealth(lua_State* L) { int GlobalFunctions::luaDoAreaCombatMana(lua_State* L) { // doAreaCombatMana(cid, pos, area, min, max, effect[, origin = ORIGIN_SPELL]) - Creature* creature = getCreature(L, 1); + std::shared_ptr creature = getCreature(L, 1); if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -402,14 +402,14 @@ int GlobalFunctions::luaDoAreaCombatMana(lua_State* L) { int GlobalFunctions::luaDoTargetCombatMana(lua_State* L) { // doTargetCombatMana(cid, target, min, max, effect[, origin = ORIGIN_SPELL) - Creature* creature = getCreature(L, 1); + std::shared_ptr creature = getCreature(L, 1); if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); return 1; } - Creature* target = getCreature(L, 2); + std::shared_ptr target = getCreature(L, 2); if (!target) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -442,7 +442,7 @@ int GlobalFunctions::luaDoTargetCombatMana(lua_State* L) { int GlobalFunctions::luaDoAreaCombatCondition(lua_State* L) { // doAreaCombatCondition(cid, pos, area, condition, effect) - Creature* creature = getCreature(L, 1); + std::shared_ptr creature = getCreature(L, 1); if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -473,14 +473,14 @@ int GlobalFunctions::luaDoAreaCombatCondition(lua_State* L) { int GlobalFunctions::luaDoTargetCombatCondition(lua_State* L) { // doTargetCombatCondition(cid, target, condition, effect) - Creature* creature = getCreature(L, 1); + std::shared_ptr creature = getCreature(L, 1); if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); return 1; } - Creature* target = getCreature(L, 2); + std::shared_ptr target = getCreature(L, 2); if (!target) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -504,7 +504,7 @@ int GlobalFunctions::luaDoTargetCombatCondition(lua_State* L) { int GlobalFunctions::luaDoAreaCombatDispel(lua_State* L) { // doAreaCombatDispel(cid, pos, area, type, effect) - Creature* creature = getCreature(L, 1); + std::shared_ptr creature = getCreature(L, 1); if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -529,14 +529,14 @@ int GlobalFunctions::luaDoAreaCombatDispel(lua_State* L) { int GlobalFunctions::luaDoTargetCombatDispel(lua_State* L) { // doTargetCombatDispel(cid, target, type, effect) - Creature* creature = getCreature(L, 1); + std::shared_ptr creature = getCreature(L, 1); if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); return 1; } - Creature* target = getCreature(L, 2); + std::shared_ptr target = getCreature(L, 2); if (!target) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -553,14 +553,14 @@ int GlobalFunctions::luaDoTargetCombatDispel(lua_State* L) { int GlobalFunctions::luaDoChallengeCreature(lua_State* L) { // doChallengeCreature(cid, target, targetChangeCooldown) - Creature* creature = getCreature(L, 1); + std::shared_ptr creature = getCreature(L, 1); if (!creature) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); return 1; } - Creature* target = getCreature(L, 2); + std::shared_ptr target = getCreature(L, 2); if (!target) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -742,14 +742,14 @@ int GlobalFunctions::luaDebugPrint(lua_State* L) { int GlobalFunctions::luaIsInWar(lua_State* L) { // isInWar(cid, target) - Player* player = getPlayer(L, 1); + std::shared_ptr player = getPlayer(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); return 1; } - Player* targetPlayer = getPlayer(L, 2); + std::shared_ptr targetPlayer = getPlayer(L, 2); if (!targetPlayer) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/core/game/modal_window_functions.cpp b/src/lua/functions/core/game/modal_window_functions.cpp index 125e5148773..a56db5a6b65 100644 --- a/src/lua/functions/core/game/modal_window_functions.cpp +++ b/src/lua/functions/core/game/modal_window_functions.cpp @@ -213,7 +213,7 @@ int ModalWindowFunctions::luaModalWindowSetPriority(lua_State* L) { int ModalWindowFunctions::luaModalWindowSendToPlayer(lua_State* L) { // modalWindow:sendToPlayer(player) - Player* player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); if (!player) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/core/network/network_message_functions.cpp b/src/lua/functions/core/network/network_message_functions.cpp index 6ca01e6af2d..d989df46095 100644 --- a/src/lua/functions/core/network/network_message_functions.cpp +++ b/src/lua/functions/core/network/network_message_functions.cpp @@ -240,14 +240,14 @@ int NetworkMessageFunctions::luaNetworkMessageAddDouble(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddItem(lua_State* L) { // networkMessage:addItem(item, player) - Item* item = getUserdata(L, 2); + std::shared_ptr item = getUserdataShared(L, 2); if (!item) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); lua_pushnil(L); return 1; } - Player* player = getUserdata(L, 3); + std::shared_ptr player = getUserdataShared(L, 3); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -297,7 +297,7 @@ int NetworkMessageFunctions::luaNetworkMessageSendToPlayer(lua_State* L) { return 1; } - Player* player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); if (player) { player->sendNetworkMessage(*message); pushBoolean(L, true); diff --git a/src/lua/functions/creatures/combat/combat_functions.cpp b/src/lua/functions/creatures/combat/combat_functions.cpp index 50488ac0a6a..889afefb2b8 100644 --- a/src/lua/functions/creatures/combat/combat_functions.cpp +++ b/src/lua/functions/creatures/combat/combat_functions.cpp @@ -150,7 +150,7 @@ int CombatFunctions::luaCombatExecute(lua_State* L) { } } - Creature* creature = getCreature(L, 2); + std::shared_ptr creature = getCreature(L, 2); const LuaVariant &variant = getVariant(L, 3); combat->setInstantSpellName(variant.instantName); @@ -158,7 +158,7 @@ int CombatFunctions::luaCombatExecute(lua_State* L) { bool result = true; switch (variant.type) { case VARIANT_NUMBER: { - Creature* target = g_game().getCreatureByID(variant.number); + std::shared_ptr target = g_game().getCreatureByID(variant.number); if (!target) { pushBoolean(L, false); return 1; @@ -188,7 +188,7 @@ int CombatFunctions::luaCombatExecute(lua_State* L) { } case VARIANT_STRING: { - Player* target = g_game().getPlayerByName(variant.text); + std::shared_ptr target = g_game().getPlayerByName(variant.text); if (!target) { pushBoolean(L, false); return 1; diff --git a/src/lua/functions/creatures/combat/variant_functions.cpp b/src/lua/functions/creatures/combat/variant_functions.cpp index 28d9143157e..4741e69ed0f 100644 --- a/src/lua/functions/creatures/combat/variant_functions.cpp +++ b/src/lua/functions/creatures/combat/variant_functions.cpp @@ -16,7 +16,7 @@ int VariantFunctions::luaVariantCreate(lua_State* L) { // Variant(number or string or position or thing) LuaVariant variant; if (isUserdata(L, 2)) { - if (Thing* thing = getThing(L, 2)) { + if (std::shared_ptr thing = getThing(L, 2)) { variant.type = VARIANT_TARGETPOSITION; variant.pos = thing->getPosition(); } diff --git a/src/lua/functions/creatures/creature_functions.cpp b/src/lua/functions/creatures/creature_functions.cpp index d1ec3d19dab..aaa02677db7 100644 --- a/src/lua/functions/creatures/creature_functions.cpp +++ b/src/lua/functions/creatures/creature_functions.cpp @@ -15,7 +15,7 @@ int CreatureFunctions::luaCreatureCreate(lua_State* L) { // Creature(id or name or userdata) - Creature* creature; + std::shared_ptr creature; if (isNumber(L, 2)) { creature = g_game().getCreatureByID(getNumber(L, 2)); } else if (isString(L, 2)) { @@ -26,7 +26,7 @@ int CreatureFunctions::luaCreatureCreate(lua_State* L) { lua_pushnil(L); return 1; } - creature = getUserdata(L, 2); + creature = getUserdataShared(L, 2); } else { creature = nullptr; } @@ -42,7 +42,7 @@ int CreatureFunctions::luaCreatureCreate(lua_State* L) { int CreatureFunctions::luaCreatureGetEvents(lua_State* L) { // creature:getEvents(type) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -62,7 +62,7 @@ int CreatureFunctions::luaCreatureGetEvents(lua_State* L) { int CreatureFunctions::luaCreatureRegisterEvent(lua_State* L) { // creature:registerEvent(name) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { const std::string &name = getString(L, 2); pushBoolean(L, creature->registerCreatureEvent(name)); @@ -75,7 +75,7 @@ int CreatureFunctions::luaCreatureRegisterEvent(lua_State* L) { int CreatureFunctions::luaCreatureUnregisterEvent(lua_State* L) { // creature:unregisterEvent(name) const std::string &name = getString(L, 2); - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { pushBoolean(L, creature->unregisterCreatureEvent(name)); } else { @@ -86,7 +86,7 @@ int CreatureFunctions::luaCreatureUnregisterEvent(lua_State* L) { int CreatureFunctions::luaCreatureIsRemoved(lua_State* L) { // creature:isRemoved() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { pushBoolean(L, creature->isRemoved()); } else { @@ -97,13 +97,13 @@ int CreatureFunctions::luaCreatureIsRemoved(lua_State* L) { int CreatureFunctions::luaCreatureIsCreature(lua_State* L) { // creature:isCreature() - pushBoolean(L, getUserdata(L, 1) != nullptr); + pushBoolean(L, getUserdataShared(L, 1) != nullptr); return 1; } int CreatureFunctions::luaCreatureIsInGhostMode(lua_State* L) { // creature:isInGhostMode() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { pushBoolean(L, creature->isInGhostMode()); } else { @@ -114,7 +114,7 @@ int CreatureFunctions::luaCreatureIsInGhostMode(lua_State* L) { int CreatureFunctions::luaCreatureIsHealthHidden(lua_State* L) { // creature:isHealthHidden() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { pushBoolean(L, creature->isHealthHidden()); } else { @@ -125,7 +125,7 @@ int CreatureFunctions::luaCreatureIsHealthHidden(lua_State* L) { int CreatureFunctions::luaCreatureCanSee(lua_State* L) { // creature:canSee(position) - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { const Position &position = getPosition(L, 2); pushBoolean(L, creature->canSee(position)); @@ -137,9 +137,9 @@ int CreatureFunctions::luaCreatureCanSee(lua_State* L) { int CreatureFunctions::luaCreatureCanSeeCreature(lua_State* L) { // creature:canSeeCreature(creature) - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { - const Creature* otherCreature = getCreature(L, 2); + std::shared_ptr otherCreature = getCreature(L, 2); pushBoolean(L, creature->canSeeCreature(otherCreature)); } else { lua_pushnil(L); @@ -149,13 +149,13 @@ int CreatureFunctions::luaCreatureCanSeeCreature(lua_State* L) { int CreatureFunctions::luaCreatureGetParent(lua_State* L) { // creature:getParent() - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - Cylinder* parent = creature->getParent(); + std::shared_ptr parent = creature->getParent(); if (!parent) { lua_pushnil(L); return 1; @@ -167,7 +167,7 @@ int CreatureFunctions::luaCreatureGetParent(lua_State* L) { int CreatureFunctions::luaCreatureGetId(lua_State* L) { // creature:getId() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getID()); } else { @@ -178,7 +178,7 @@ int CreatureFunctions::luaCreatureGetId(lua_State* L) { int CreatureFunctions::luaCreatureGetName(lua_State* L) { // creature:getName() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { pushString(L, creature->getName()); } else { @@ -189,7 +189,7 @@ int CreatureFunctions::luaCreatureGetName(lua_State* L) { int CreatureFunctions::luaCreatureGetTypeName(lua_State* L) { // creature:getTypeName() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { pushString(L, creature->getTypeName()); } else { @@ -200,13 +200,13 @@ int CreatureFunctions::luaCreatureGetTypeName(lua_State* L) { int CreatureFunctions::luaCreatureGetTarget(lua_State* L) { // creature:getTarget() - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - Creature* target = creature->getAttackedCreature(); + std::shared_ptr target = creature->getAttackedCreature(); if (target) { pushUserdata(L, target); setCreatureMetatable(L, -1, target); @@ -218,9 +218,9 @@ int CreatureFunctions::luaCreatureGetTarget(lua_State* L) { int CreatureFunctions::luaCreatureSetTarget(lua_State* L) { // creature:setTarget(target) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { - Creature* target = getCreature(L, 2); + std::shared_ptr target = getCreature(L, 2); pushBoolean(L, creature->setAttackedCreature(target)); } else { lua_pushnil(L); @@ -230,13 +230,13 @@ int CreatureFunctions::luaCreatureSetTarget(lua_State* L) { int CreatureFunctions::luaCreatureGetFollowCreature(lua_State* L) { // creature:getFollowCreature() - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - Creature* followCreature = creature->getFollowCreature(); + std::shared_ptr followCreature = creature->getFollowCreature(); if (followCreature) { pushUserdata(L, followCreature); setCreatureMetatable(L, -1, followCreature); @@ -248,9 +248,9 @@ int CreatureFunctions::luaCreatureGetFollowCreature(lua_State* L) { int CreatureFunctions::luaCreatureSetFollowCreature(lua_State* L) { // creature:setFollowCreature(followedCreature) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { - Creature* followCreature = getCreature(L, 2); + std::shared_ptr followCreature = getCreature(L, 2); pushBoolean(L, creature->setFollowCreature(followCreature)); } else { lua_pushnil(L); @@ -260,13 +260,13 @@ int CreatureFunctions::luaCreatureSetFollowCreature(lua_State* L) { int CreatureFunctions::luaCreatureGetMaster(lua_State* L) { // creature:getMaster() - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - Creature* master = creature->getMaster(); + std::shared_ptr master = creature->getMaster(); if (!master) { lua_pushnil(L); return 1; @@ -279,7 +279,7 @@ int CreatureFunctions::luaCreatureGetMaster(lua_State* L) { int CreatureFunctions::luaCreatureReload(lua_State* L) { // creature:reload() - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -292,7 +292,7 @@ int CreatureFunctions::luaCreatureReload(lua_State* L) { int CreatureFunctions::luaCreatureSetMaster(lua_State* L) { // creature:setMaster(master) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -306,7 +306,7 @@ int CreatureFunctions::luaCreatureSetMaster(lua_State* L) { int CreatureFunctions::luaCreatureGetLight(lua_State* L) { // creature:getLight() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -320,7 +320,7 @@ int CreatureFunctions::luaCreatureGetLight(lua_State* L) { int CreatureFunctions::luaCreatureSetLight(lua_State* L) { // creature:setLight(color, level) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -337,7 +337,7 @@ int CreatureFunctions::luaCreatureSetLight(lua_State* L) { int CreatureFunctions::luaCreatureGetSpeed(lua_State* L) { // creature:getSpeed() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getSpeed()); } else { @@ -348,7 +348,7 @@ int CreatureFunctions::luaCreatureGetSpeed(lua_State* L) { int CreatureFunctions::luaCreatureSetSpeed(lua_State* L) { // creature:setSpeed(speed) - Creature* creature = getCreature(L, 1); + std::shared_ptr creature = getCreature(L, 1); if (!creature) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -363,7 +363,7 @@ int CreatureFunctions::luaCreatureSetSpeed(lua_State* L) { int CreatureFunctions::luaCreatureGetBaseSpeed(lua_State* L) { // creature:getBaseSpeed() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getBaseSpeed()); } else { @@ -374,7 +374,7 @@ int CreatureFunctions::luaCreatureGetBaseSpeed(lua_State* L) { int CreatureFunctions::luaCreatureChangeSpeed(lua_State* L) { // creature:changeSpeed(delta) - Creature* creature = getCreature(L, 1); + std::shared_ptr creature = getCreature(L, 1); if (!creature) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -389,7 +389,7 @@ int CreatureFunctions::luaCreatureChangeSpeed(lua_State* L) { int CreatureFunctions::luaCreatureSetDropLoot(lua_State* L) { // creature:setDropLoot(doDrop) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { creature->setDropLoot(getBoolean(L, 2)); pushBoolean(L, true); @@ -401,7 +401,7 @@ int CreatureFunctions::luaCreatureSetDropLoot(lua_State* L) { int CreatureFunctions::luaCreatureSetSkillLoss(lua_State* L) { // creature:setSkillLoss(skillLoss) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { creature->setSkillLoss(getBoolean(L, 2)); pushBoolean(L, true); @@ -413,7 +413,7 @@ int CreatureFunctions::luaCreatureSetSkillLoss(lua_State* L) { int CreatureFunctions::luaCreatureGetPosition(lua_State* L) { // creature:getPosition() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { pushPosition(L, creature->getPosition()); } else { @@ -424,13 +424,13 @@ int CreatureFunctions::luaCreatureGetPosition(lua_State* L) { int CreatureFunctions::luaCreatureGetTile(lua_State* L) { // creature:getTile() - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - Tile* tile = creature->getTile(); + std::shared_ptr tile = creature->getTile(); if (tile) { pushUserdata(L, tile); setMetatable(L, -1, "Tile"); @@ -442,7 +442,7 @@ int CreatureFunctions::luaCreatureGetTile(lua_State* L) { int CreatureFunctions::luaCreatureGetDirection(lua_State* L) { // creature:getDirection() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getDirection()); } else { @@ -453,7 +453,7 @@ int CreatureFunctions::luaCreatureGetDirection(lua_State* L) { int CreatureFunctions::luaCreatureSetDirection(lua_State* L) { // creature:setDirection(direction) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { pushBoolean(L, g_game().internalCreatureTurn(creature, getNumber(L, 2))); } else { @@ -464,7 +464,7 @@ int CreatureFunctions::luaCreatureSetDirection(lua_State* L) { int CreatureFunctions::luaCreatureGetHealth(lua_State* L) { // creature:getHealth() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getHealth()); } else { @@ -475,7 +475,7 @@ int CreatureFunctions::luaCreatureGetHealth(lua_State* L) { int CreatureFunctions::luaCreatureSetHealth(lua_State* L) { // creature:setHealth(health) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -484,7 +484,7 @@ int CreatureFunctions::luaCreatureSetHealth(lua_State* L) { creature->health = std::min(getNumber(L, 2), creature->healthMax); g_game().addCreatureHealth(creature); - Player* player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->sendStats(); } @@ -494,7 +494,7 @@ int CreatureFunctions::luaCreatureSetHealth(lua_State* L) { int CreatureFunctions::luaCreatureAddHealth(lua_State* L) { // creature:addHealth(healthChange, combatType) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -515,7 +515,7 @@ int CreatureFunctions::luaCreatureAddHealth(lua_State* L) { int CreatureFunctions::luaCreatureGetMaxHealth(lua_State* L) { // creature:getMaxHealth() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getMaxHealth()); } else { @@ -526,7 +526,7 @@ int CreatureFunctions::luaCreatureGetMaxHealth(lua_State* L) { int CreatureFunctions::luaCreatureSetMaxHealth(lua_State* L) { // creature:setMaxHealth(maxHealth) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -536,7 +536,7 @@ int CreatureFunctions::luaCreatureSetMaxHealth(lua_State* L) { creature->health = std::min(creature->health, creature->healthMax); g_game().addCreatureHealth(creature); - Player* player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->sendStats(); } @@ -546,7 +546,7 @@ int CreatureFunctions::luaCreatureSetMaxHealth(lua_State* L) { int CreatureFunctions::luaCreatureSetHiddenHealth(lua_State* L) { // creature:setHiddenHealth(hide) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { creature->setHiddenHealth(getBoolean(L, 2)); g_game().addCreatureHealth(creature); @@ -559,7 +559,7 @@ int CreatureFunctions::luaCreatureSetHiddenHealth(lua_State* L) { int CreatureFunctions::luaCreatureIsMoveLocked(lua_State* L) { // creature:isMoveLocked() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { pushBoolean(L, creature->isMoveLocked()); } else { @@ -570,7 +570,7 @@ int CreatureFunctions::luaCreatureIsMoveLocked(lua_State* L) { int CreatureFunctions::luaCreatureSetMoveLocked(lua_State* L) { // creature:setMoveLocked(moveLocked) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { creature->setMoveLocked(getBoolean(L, 2)); pushBoolean(L, true); @@ -582,7 +582,7 @@ int CreatureFunctions::luaCreatureSetMoveLocked(lua_State* L) { int CreatureFunctions::luaCreatureGetSkull(lua_State* L) { // creature:getSkull() - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getSkull()); } else { @@ -593,7 +593,7 @@ int CreatureFunctions::luaCreatureGetSkull(lua_State* L) { int CreatureFunctions::luaCreatureSetSkull(lua_State* L) { // creature:setSkull(skull) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { creature->setSkull(getNumber(L, 2)); pushBoolean(L, true); @@ -605,7 +605,7 @@ int CreatureFunctions::luaCreatureSetSkull(lua_State* L) { int CreatureFunctions::luaCreatureGetOutfit(lua_State* L) { // creature:getOutfit() - const Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { pushOutfit(L, creature->getCurrentOutfit()); } else { @@ -616,7 +616,7 @@ int CreatureFunctions::luaCreatureGetOutfit(lua_State* L) { int CreatureFunctions::luaCreatureSetOutfit(lua_State* L) { // creature:setOutfit(outfit) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { Outfit_t outfit = getOutfit(L, 2); if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && outfit.lookType != 0 && !g_game().isLookTypeRegistered(outfit.lookType)) { @@ -635,7 +635,7 @@ int CreatureFunctions::luaCreatureSetOutfit(lua_State* L) { int CreatureFunctions::luaCreatureGetCondition(lua_State* L) { // creature:getCondition(conditionType[, conditionId = CONDITIONID_COMBAT[, subId = 0]]) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -657,7 +657,7 @@ int CreatureFunctions::luaCreatureGetCondition(lua_State* L) { int CreatureFunctions::luaCreatureAddCondition(lua_State* L) { // creature:addCondition(condition) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); Condition* condition = getUserdata(L, 2); if (creature && condition) { pushBoolean(L, creature->addCondition(condition->clone())); @@ -669,7 +669,7 @@ int CreatureFunctions::luaCreatureAddCondition(lua_State* L) { int CreatureFunctions::luaCreatureRemoveCondition(lua_State* L) { // creature:removeCondition(conditionType[, conditionId = CONDITIONID_COMBAT[, subId = 0[, force = false]]]) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -691,7 +691,7 @@ int CreatureFunctions::luaCreatureRemoveCondition(lua_State* L) { int CreatureFunctions::luaCreatureHasCondition(lua_State* L) { // creature:hasCondition(conditionType[, subId = 0]) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -705,7 +705,7 @@ int CreatureFunctions::luaCreatureHasCondition(lua_State* L) { int CreatureFunctions::luaCreatureIsImmune(lua_State* L) { // creature:isImmune(condition or conditionType) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -723,20 +723,20 @@ int CreatureFunctions::luaCreatureIsImmune(lua_State* L) { int CreatureFunctions::luaCreatureRemove(lua_State* L) { // creature:remove([forced = true]) - Creature** creaturePtr = getRawUserdata(L, 1); + std::shared_ptr* creaturePtr = getRawUserDataShared(L, 1); if (!creaturePtr) { lua_pushnil(L); return 1; } - Creature* creature = *creaturePtr; + std::shared_ptr creature = *creaturePtr; if (!creature) { lua_pushnil(L); return 1; } bool forced = getBoolean(L, 2, true); - if (Player* player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { if (forced) { player->removePlayer(true); } else { @@ -756,7 +756,7 @@ int CreatureFunctions::luaCreatureTeleportTo(lua_State* L) { bool pushMovement = getBoolean(L, 3, false); const Position &position = getPosition(L, 2); - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -802,7 +802,7 @@ int CreatureFunctions::luaCreatureSay(lua_State* L) { } } - Creature* target = nullptr; + std::shared_ptr target = nullptr; if (parameters >= 5) { target = getCreature(L, 5); } @@ -811,7 +811,7 @@ int CreatureFunctions::luaCreatureSay(lua_State* L) { SpeakClasses type = getNumber(L, 3, TALKTYPE_MONSTER_SAY); const std::string &text = getString(L, 2); - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -832,7 +832,7 @@ int CreatureFunctions::luaCreatureSay(lua_State* L) { int CreatureFunctions::luaCreatureGetDamageMap(lua_State* L) { // creature:getDamageMap() - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -850,7 +850,7 @@ int CreatureFunctions::luaCreatureGetDamageMap(lua_State* L) { int CreatureFunctions::luaCreatureGetSummons(lua_State* L) { // creature:getSummons() - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -859,7 +859,7 @@ int CreatureFunctions::luaCreatureGetSummons(lua_State* L) { lua_createtable(L, creature->getSummonCount(), 0); int index = 0; - for (Creature* summon : creature->getSummons()) { + for (std::shared_ptr summon : creature->getSummons()) { pushUserdata(L, summon); setCreatureMetatable(L, -1, summon); lua_rawseti(L, -2, ++index); @@ -869,7 +869,7 @@ int CreatureFunctions::luaCreatureGetSummons(lua_State* L) { int CreatureFunctions::luaCreatureHasBeenSummoned(lua_State* L) { // creature:hasBeenSummoned() - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { pushBoolean(L, creature->hasBeenSummoned()); } else { @@ -882,7 +882,7 @@ int CreatureFunctions::luaCreatureHasBeenSummoned(lua_State* L) { int CreatureFunctions::luaCreatureGetDescription(lua_State* L) { // creature:getDescription(distance) int32_t distance = getNumber(L, 2); - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { pushString(L, creature->getDescription(distance)); } else { @@ -893,7 +893,7 @@ int CreatureFunctions::luaCreatureGetDescription(lua_State* L) { int CreatureFunctions::luaCreatureGetPathTo(lua_State* L) { // creature:getPathTo(pos[, minTargetDist = 0[, maxTargetDist = 1[, fullPathSearch = true[, clearSight = true[, maxSearchDist = 0]]]]]) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -926,7 +926,7 @@ int CreatureFunctions::luaCreatureGetPathTo(lua_State* L) { int CreatureFunctions::luaCreatureMove(lua_State* L) { // creature:move(direction) // creature:move(tile[, flags = 0]) - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -940,19 +940,19 @@ int CreatureFunctions::luaCreatureMove(lua_State* L) { } lua_pushnumber(L, g_game().internalMoveCreature(creature, direction, FLAG_NOLIMIT)); } else { - Tile* tile = getUserdata(L, 2); + std::shared_ptr tile = getUserdataShared(L, 2); if (!tile) { lua_pushnil(L); return 1; } - lua_pushnumber(L, g_game().internalMoveCreature(*creature, *tile, getNumber(L, 3))); + lua_pushnumber(L, g_game().internalMoveCreature(creature, tile, getNumber(L, 3))); } return 1; } int CreatureFunctions::luaCreatureGetZoneType(lua_State* L) { // creature:getZoneType() - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getZoneType()); } else { @@ -963,7 +963,7 @@ int CreatureFunctions::luaCreatureGetZoneType(lua_State* L) { int CreatureFunctions::luaCreatureGetZones(lua_State* L) { // creature:getZones() - Creature* creature = getUserdata(L, 1); + std::shared_ptr creature = getUserdataShared(L, 1); if (creature == nullptr) { lua_pushnil(L); return 1; @@ -983,7 +983,7 @@ int CreatureFunctions::luaCreatureGetZones(lua_State* L) { int CreatureFunctions::luaCreatureSetIcon(lua_State* L) { // creature:setIcon(key, category, icon[, number]) - auto creature = getUserdata(L, 1); + auto creature = getUserdataShared(L, 1); if (!creature) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -1008,7 +1008,7 @@ int CreatureFunctions::luaCreatureSetIcon(lua_State* L) { int CreatureFunctions::luaCreatureGetIcons(lua_State* L) { // creature:getIcons() - const auto creature = getUserdata(L, 1); + const auto creature = getUserdataShared(L, 1); if (!creature) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -1029,7 +1029,7 @@ int CreatureFunctions::luaCreatureGetIcons(lua_State* L) { int CreatureFunctions::luaCreatureGetIcon(lua_State* L) { // creature:getIcon(key) - const auto creature = getUserdata(L, 1); + const auto creature = getUserdataShared(L, 1); if (!creature) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -1050,7 +1050,7 @@ int CreatureFunctions::luaCreatureGetIcon(lua_State* L) { int CreatureFunctions::luaCreatureRemoveIcon(lua_State* L) { // creature:removeIcon(key) - auto creature = getUserdata(L, 1); + auto creature = getUserdataShared(L, 1); if (!creature) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -1064,7 +1064,7 @@ int CreatureFunctions::luaCreatureRemoveIcon(lua_State* L) { int CreatureFunctions::luaCreatureClearIcons(lua_State* L) { // creature:clearIcons() - auto creature = getUserdata(L, 1); + auto creature = getUserdataShared(L, 1); if (!creature) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/creatures/monster/monster_functions.cpp b/src/lua/functions/creatures/monster/monster_functions.cpp index bca5a2e421e..14c400fa5ff 100644 --- a/src/lua/functions/creatures/monster/monster_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_functions.cpp @@ -17,7 +17,7 @@ int MonsterFunctions::luaMonsterCreate(lua_State* L) { // Monster(id or userdata) - Monster* monster; + std::shared_ptr monster; if (isNumber(L, 2)) { monster = g_game().getMonsterByID(getNumber(L, 2)); } else if (isUserdata(L, 2)) { @@ -25,7 +25,7 @@ int MonsterFunctions::luaMonsterCreate(lua_State* L) { lua_pushnil(L); return 1; } - monster = getUserdata(L, 2); + monster = getUserdataShared(L, 2); } else { monster = nullptr; } @@ -41,13 +41,13 @@ int MonsterFunctions::luaMonsterCreate(lua_State* L) { int MonsterFunctions::luaMonsterIsMonster(lua_State* L) { // monster:isMonster() - pushBoolean(L, getUserdata(L, 1) != nullptr); + pushBoolean(L, getUserdataShared(L, 1) != nullptr); return 1; } int MonsterFunctions::luaMonsterGetType(lua_State* L) { // monster:getType() - const Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { pushUserdata(L, monster->mType); setMetatable(L, -1, "MonsterType"); @@ -59,7 +59,7 @@ int MonsterFunctions::luaMonsterGetType(lua_State* L) { int MonsterFunctions::luaMonsterSetType(lua_State* L) { // monster:setType(name or raceid) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { std::shared_ptr mType = nullptr; if (isNumber(L, 2)) { @@ -94,8 +94,8 @@ int MonsterFunctions::luaMonsterSetType(lua_State* L) { // Reload creature on spectators SpectatorHashSet spectators; g_game().map.getSpectators(spectators, monster->getPosition(), true); - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendCreatureReload(monster); } } @@ -108,7 +108,7 @@ int MonsterFunctions::luaMonsterSetType(lua_State* L) { int MonsterFunctions::luaMonsterGetSpawnPosition(lua_State* L) { // monster:getSpawnPosition() - const Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { pushPosition(L, monster->getMasterPos()); } else { @@ -119,7 +119,7 @@ int MonsterFunctions::luaMonsterGetSpawnPosition(lua_State* L) { int MonsterFunctions::luaMonsterIsInSpawnRange(lua_State* L) { // monster:isInSpawnRange([position]) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { pushBoolean(L, monster->isInSpawnRange(lua_gettop(L) >= 2 ? getPosition(L, 2) : monster->getPosition())); } else { @@ -130,7 +130,7 @@ int MonsterFunctions::luaMonsterIsInSpawnRange(lua_State* L) { int MonsterFunctions::luaMonsterIsIdle(lua_State* L) { // monster:isIdle() - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { pushBoolean(L, monster->getIdleStatus()); } else { @@ -141,7 +141,7 @@ int MonsterFunctions::luaMonsterIsIdle(lua_State* L) { int MonsterFunctions::luaMonsterSetIdle(lua_State* L) { // monster:setIdle(idle) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); return 1; @@ -154,9 +154,9 @@ int MonsterFunctions::luaMonsterSetIdle(lua_State* L) { int MonsterFunctions::luaMonsterIsTarget(lua_State* L) { // monster:isTarget(creature) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { - const Creature* creature = getCreature(L, 2); + std::shared_ptr creature = getCreature(L, 2); pushBoolean(L, monster->isTarget(creature)); } else { lua_pushnil(L); @@ -166,9 +166,9 @@ int MonsterFunctions::luaMonsterIsTarget(lua_State* L) { int MonsterFunctions::luaMonsterIsOpponent(lua_State* L) { // monster:isOpponent(creature) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { - const Creature* creature = getCreature(L, 2); + std::shared_ptr creature = getCreature(L, 2); pushBoolean(L, monster->isOpponent(creature)); } else { lua_pushnil(L); @@ -178,9 +178,9 @@ int MonsterFunctions::luaMonsterIsOpponent(lua_State* L) { int MonsterFunctions::luaMonsterIsFriend(lua_State* L) { // monster:isFriend(creature) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { - const Creature* creature = getCreature(L, 2); + std::shared_ptr creature = getCreature(L, 2); pushBoolean(L, monster->isFriend(creature)); } else { lua_pushnil(L); @@ -190,9 +190,9 @@ int MonsterFunctions::luaMonsterIsFriend(lua_State* L) { int MonsterFunctions::luaMonsterAddFriend(lua_State* L) { // monster:addFriend(creature) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { - Creature* creature = getCreature(L, 2); + std::shared_ptr creature = getCreature(L, 2); monster->addFriend(creature); pushBoolean(L, true); } else { @@ -203,9 +203,9 @@ int MonsterFunctions::luaMonsterAddFriend(lua_State* L) { int MonsterFunctions::luaMonsterRemoveFriend(lua_State* L) { // monster:removeFriend(creature) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { - Creature* creature = getCreature(L, 2); + std::shared_ptr creature = getCreature(L, 2); monster->removeFriend(creature); pushBoolean(L, true); } else { @@ -216,7 +216,7 @@ int MonsterFunctions::luaMonsterRemoveFriend(lua_State* L) { int MonsterFunctions::luaMonsterGetFriendList(lua_State* L) { // monster:getFriendList() - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); return 1; @@ -226,7 +226,7 @@ int MonsterFunctions::luaMonsterGetFriendList(lua_State* L) { lua_createtable(L, friendList.size(), 0); int index = 0; - for (Creature* creature : friendList) { + for (std::shared_ptr creature : friendList) { pushUserdata(L, creature); setCreatureMetatable(L, -1, creature); lua_rawseti(L, -2, ++index); @@ -236,7 +236,7 @@ int MonsterFunctions::luaMonsterGetFriendList(lua_State* L) { int MonsterFunctions::luaMonsterGetFriendCount(lua_State* L) { // monster:getFriendCount() - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { lua_pushnumber(L, monster->getFriendList().size()); } else { @@ -247,13 +247,13 @@ int MonsterFunctions::luaMonsterGetFriendCount(lua_State* L) { int MonsterFunctions::luaMonsterAddTarget(lua_State* L) { // monster:addTarget(creature[, pushFront = false]) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); return 1; } - Creature* creature = getCreature(L, 2); + std::shared_ptr creature = getCreature(L, 2); bool pushFront = getBoolean(L, 3, false); monster->addTarget(creature, pushFront); pushBoolean(L, true); @@ -262,7 +262,7 @@ int MonsterFunctions::luaMonsterAddTarget(lua_State* L) { int MonsterFunctions::luaMonsterRemoveTarget(lua_State* L) { // monster:removeTarget(creature) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); return 1; @@ -275,7 +275,7 @@ int MonsterFunctions::luaMonsterRemoveTarget(lua_State* L) { int MonsterFunctions::luaMonsterGetTargetList(lua_State* L) { // monster:getTargetList() - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); return 1; @@ -285,7 +285,7 @@ int MonsterFunctions::luaMonsterGetTargetList(lua_State* L) { lua_createtable(L, targetList.size(), 0); int index = 0; - for (Creature* creature : targetList) { + for (std::shared_ptr creature : targetList) { pushUserdata(L, creature); setCreatureMetatable(L, -1, creature); lua_rawseti(L, -2, ++index); @@ -295,7 +295,7 @@ int MonsterFunctions::luaMonsterGetTargetList(lua_State* L) { int MonsterFunctions::luaMonsterGetTargetCount(lua_State* L) { // monster:getTargetCount() - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { lua_pushnumber(L, monster->getTargetList().size()); } else { @@ -306,7 +306,7 @@ int MonsterFunctions::luaMonsterGetTargetCount(lua_State* L) { int MonsterFunctions::luaMonsterChangeTargetDistance(lua_State* L) { // monster:changeTargetDistance(distance[, duration = 12000]) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { int32_t distance = getNumber(L, 2, 1); uint32_t duration = getNumber(L, 3, 12000); @@ -319,7 +319,7 @@ int MonsterFunctions::luaMonsterChangeTargetDistance(lua_State* L) { int MonsterFunctions::luaMonsterIsChallenged(lua_State* L) { // monster:isChallenged() - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { pushBoolean(L, monster->isChallenged()); } else { @@ -330,9 +330,9 @@ int MonsterFunctions::luaMonsterIsChallenged(lua_State* L) { int MonsterFunctions::luaMonsterSelectTarget(lua_State* L) { // monster:selectTarget(creature) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { - Creature* creature = getCreature(L, 2); + std::shared_ptr creature = getCreature(L, 2); pushBoolean(L, monster->selectTarget(creature)); } else { lua_pushnil(L); @@ -342,7 +342,7 @@ int MonsterFunctions::luaMonsterSelectTarget(lua_State* L) { int MonsterFunctions::luaMonsterSearchTarget(lua_State* L) { // monster:searchTarget([searchType = TARGETSEARCH_DEFAULT]) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (monster) { TargetSearchType_t searchType = getNumber(L, 2, TARGETSEARCH_DEFAULT); pushBoolean(L, monster->searchTarget(searchType)); @@ -354,7 +354,7 @@ int MonsterFunctions::luaMonsterSearchTarget(lua_State* L) { int MonsterFunctions::luaMonsterSetSpawnPosition(lua_State* L) { // monster:setSpawnPosition() - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); return 1; @@ -374,7 +374,7 @@ int MonsterFunctions::luaMonsterSetSpawnPosition(lua_State* L) { int MonsterFunctions::luaMonsterGetRespawnType(lua_State* L) { // monster:getRespawnType() - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); @@ -390,7 +390,7 @@ int MonsterFunctions::luaMonsterGetRespawnType(lua_State* L) { int MonsterFunctions::luaMonsterGetTimeToChangeFiendish(lua_State* L) { // monster:getTimeToChangeFiendish() - const Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); pushBoolean(L, false); @@ -404,7 +404,7 @@ int MonsterFunctions::luaMonsterGetTimeToChangeFiendish(lua_State* L) { int MonsterFunctions::luaMonsterSetTimeToChangeFiendish(lua_State* L) { // monster:setTimeToChangeFiendish(endTime) time_t endTime = getNumber(L, 2, 1); - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); pushBoolean(L, false); @@ -417,7 +417,7 @@ int MonsterFunctions::luaMonsterSetTimeToChangeFiendish(lua_State* L) { int MonsterFunctions::luaMonsterGetMonsterForgeClassification(lua_State* L) { // monster:getMonsterForgeClassification() - const Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); pushBoolean(L, false); @@ -432,7 +432,7 @@ int MonsterFunctions::luaMonsterGetMonsterForgeClassification(lua_State* L) { int MonsterFunctions::luaMonsterSetMonsterForgeClassification(lua_State* L) { // monster:setMonsterForgeClassification(classication) ForgeClassifications_t classification = getNumber(L, 2); - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); pushBoolean(L, false); @@ -445,7 +445,7 @@ int MonsterFunctions::luaMonsterSetMonsterForgeClassification(lua_State* L) { int MonsterFunctions::luaMonsterGetForgeStack(lua_State* L) { // monster:getForgeStack() - const Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); pushBoolean(L, false); @@ -459,7 +459,7 @@ int MonsterFunctions::luaMonsterGetForgeStack(lua_State* L) { int MonsterFunctions::luaMonsterSetForgeStack(lua_State* L) { // monster:setForgeStack(stack) uint16_t stack = getNumber(L, 2, 0); - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); pushBoolean(L, false); @@ -478,7 +478,7 @@ int MonsterFunctions::luaMonsterSetForgeStack(lua_State* L) { int MonsterFunctions::luaMonsterConfigureForgeSystem(lua_State* L) { // monster:configureForgeSystem() - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); pushBoolean(L, false); @@ -491,7 +491,7 @@ int MonsterFunctions::luaMonsterConfigureForgeSystem(lua_State* L) { int MonsterFunctions::luaMonsterClearFiendishStatus(lua_State* L) { // monster:clearFiendishStatus() - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); pushBoolean(L, false); @@ -504,7 +504,7 @@ int MonsterFunctions::luaMonsterClearFiendishStatus(lua_State* L) { int MonsterFunctions::luaMonsterIsForgeable(lua_State* L) { // monster:isForgeable() - const Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); if (!monster) { reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); pushBoolean(L, false); @@ -517,7 +517,7 @@ int MonsterFunctions::luaMonsterIsForgeable(lua_State* L) { int MonsterFunctions::luaMonsterGetName(lua_State* L) { // monster:getName() - const auto monster = getUserdata(L, 1); + const auto monster = getUserdataShared(L, 1); if (!monster) { reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); pushBoolean(L, false); @@ -530,7 +530,7 @@ int MonsterFunctions::luaMonsterGetName(lua_State* L) { int MonsterFunctions::luaMonsterHazard(lua_State* L) { // get: monster:hazard() ; set: monster:hazard(hazard) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); bool hazard = getBoolean(L, 2, false); if (monster) { if (lua_gettop(L) == 1) { @@ -547,7 +547,7 @@ int MonsterFunctions::luaMonsterHazard(lua_State* L) { int MonsterFunctions::luaMonsterHazardCrit(lua_State* L) { // get: monster:hazardCrit() ; set: monster:hazardCrit(hazardCrit) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); bool hazardCrit = getBoolean(L, 2, false); if (monster) { if (lua_gettop(L) == 1) { @@ -564,7 +564,7 @@ int MonsterFunctions::luaMonsterHazardCrit(lua_State* L) { int MonsterFunctions::luaMonsterHazardDodge(lua_State* L) { // get: monster:hazardDodge() ; set: monster:hazardDodge(hazardDodge) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); bool hazardDodge = getBoolean(L, 2, false); if (monster) { if (lua_gettop(L) == 1) { @@ -581,7 +581,7 @@ int MonsterFunctions::luaMonsterHazardDodge(lua_State* L) { int MonsterFunctions::luaMonsterHazardDamageBoost(lua_State* L) { // get: monster:hazardDamageBoost() ; set: monster:hazardDamageBoost(hazardDamageBoost) - Monster* monster = getUserdata(L, 1); + std::shared_ptr monster = getUserdataShared(L, 1); bool hazardDamageBoost = getBoolean(L, 2, false); if (monster) { if (lua_gettop(L) == 1) { diff --git a/src/lua/functions/creatures/npc/npc_functions.cpp b/src/lua/functions/creatures/npc/npc_functions.cpp index dd6563f65a4..56d8411d909 100644 --- a/src/lua/functions/creatures/npc/npc_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_functions.cpp @@ -16,7 +16,7 @@ int NpcFunctions::luaNpcCreate(lua_State* L) { // Npc([id or name or userdata]) - Npc* npc; + std::shared_ptr npc; if (lua_gettop(L) >= 2) { if (isNumber(L, 2)) { npc = g_game().getNpcByID(getNumber(L, 2)); @@ -27,12 +27,12 @@ int NpcFunctions::luaNpcCreate(lua_State* L) { lua_pushnil(L); return 1; } - npc = getUserdata(L, 2); + npc = getUserdataShared(L, 2); } else { npc = nullptr; } } else { - npc = getUserdata(L, 1); + npc = getUserdataShared(L, 1); } if (npc) { @@ -46,13 +46,13 @@ int NpcFunctions::luaNpcCreate(lua_State* L) { int NpcFunctions::luaNpcIsNpc(lua_State* L) { // npc:isNpc() - pushBoolean(L, getUserdata(L, 1) != nullptr); + pushBoolean(L, getUserdataShared(L, 1) != nullptr); return 1; } int NpcFunctions::luaNpcSetMasterPos(lua_State* L) { // npc:setMasterPos(pos) - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); pushBoolean(L, false); @@ -67,7 +67,7 @@ int NpcFunctions::luaNpcSetMasterPos(lua_State* L) { int NpcFunctions::luaNpcGetCurrency(lua_State* L) { // npc:getCurrency() - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); @@ -79,7 +79,7 @@ int NpcFunctions::luaNpcGetCurrency(lua_State* L) { int NpcFunctions::luaNpcSetCurrency(lua_State* L) { // npc:getCurrency() - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); pushBoolean(L, false); @@ -92,7 +92,7 @@ int NpcFunctions::luaNpcSetCurrency(lua_State* L) { int NpcFunctions::luaNpcGetSpeechBubble(lua_State* L) { // npc:getSpeechBubble() - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); @@ -104,7 +104,7 @@ int NpcFunctions::luaNpcGetSpeechBubble(lua_State* L) { int NpcFunctions::luaNpcSetSpeechBubble(lua_State* L) { // npc:setSpeechBubble(speechBubble) - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); @@ -116,7 +116,7 @@ int NpcFunctions::luaNpcSetSpeechBubble(lua_State* L) { int NpcFunctions::luaNpcGetName(lua_State* L) { // npc:getName() - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); @@ -129,7 +129,7 @@ int NpcFunctions::luaNpcGetName(lua_State* L) { int NpcFunctions::luaNpcSetName(lua_State* L) { // npc:setName(name) - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); const std::string &name = getString(L, 2); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); @@ -142,7 +142,7 @@ int NpcFunctions::luaNpcSetName(lua_State* L) { int NpcFunctions::luaNpcPlace(lua_State* L) { // npc:place(position[, extended = false[, force = true]]) - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); @@ -175,7 +175,7 @@ int NpcFunctions::luaNpcSay(lua_State* L) { } } - Creature* target = nullptr; + std::shared_ptr target = nullptr; if (parameters >= 5) { target = getCreature(L, 5); } @@ -184,7 +184,7 @@ int NpcFunctions::luaNpcSay(lua_State* L) { SpeakClasses type = getNumber(L, 3, TALKTYPE_PRIVATE_NP); const std::string &text = getString(L, 2); - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { lua_pushnil(L); return 1; @@ -209,8 +209,8 @@ int NpcFunctions::luaNpcSay(lua_State* L) { */ int NpcFunctions::luaNpcTurnToCreature(lua_State* L) { // npc:turnToCreature(creature, true) - Npc* npc = getUserdata(L, 1); - Creature* creature = getCreature(L, 2); + std::shared_ptr npc = getUserdataShared(L, 1); + std::shared_ptr creature = getCreature(L, 2); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); @@ -235,8 +235,8 @@ int NpcFunctions::luaNpcTurnToCreature(lua_State* L) { int NpcFunctions::luaNpcSetPlayerInteraction(lua_State* L) { // npc:setPlayerInteraction(creature, topic = 0) - Npc* npc = getUserdata(L, 1); - Creature* creature = getCreature(L, 2); + std::shared_ptr npc = getUserdataShared(L, 1); + std::shared_ptr creature = getCreature(L, 2); uint16_t topicId = getNumber(L, 3, 0); if (!npc) { @@ -258,8 +258,8 @@ int NpcFunctions::luaNpcSetPlayerInteraction(lua_State* L) { int NpcFunctions::luaNpcRemovePlayerInteraction(lua_State* L) { // npc:removePlayerInteraction() - Npc* npc = getUserdata(L, 1); - Creature* creature = getCreature(L, 2); + std::shared_ptr npc = getUserdataShared(L, 1); + std::shared_ptr creature = getCreature(L, 2); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); @@ -280,8 +280,8 @@ int NpcFunctions::luaNpcRemovePlayerInteraction(lua_State* L) { int NpcFunctions::luaNpcIsInteractingWithPlayer(lua_State* L) { // npc:isInteractingWithPlayer(creature) - Npc* npc = getUserdata(L, 1); - Creature* creature = getCreature(L, 2); + std::shared_ptr npc = getUserdataShared(L, 1); + std::shared_ptr creature = getCreature(L, 2); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); @@ -301,8 +301,8 @@ int NpcFunctions::luaNpcIsInteractingWithPlayer(lua_State* L) { int NpcFunctions::luaNpcIsPlayerInteractingOnTopic(lua_State* L) { // npc:isPlayerInteractingOnTopic(creature, topicId = 0) - Npc* npc = getUserdata(L, 1); - Creature* creature = getCreature(L, 2); + std::shared_ptr npc = getUserdataShared(L, 1); + std::shared_ptr creature = getCreature(L, 2); uint32_t topicId = getNumber(L, 3, 0); if (!npc) { @@ -323,7 +323,7 @@ int NpcFunctions::luaNpcIsPlayerInteractingOnTopic(lua_State* L) { int NpcFunctions::luaNpcIsInTalkRange(lua_State* L) { // npc:isInTalkRange(position[, range = 4]) - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); const Position &position = getPosition(L, 2); uint32_t range = getNumber(L, 3, 4); @@ -339,14 +339,14 @@ int NpcFunctions::luaNpcIsInTalkRange(lua_State* L) { int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { // npc:openShopWindow(player) - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); pushBoolean(L, false); return 1; } - Player* player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -359,14 +359,14 @@ int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { int NpcFunctions::luaNpcCloseShopWindow(lua_State* L) { // npc:closeShopWindow(player) - Player* player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); return 1; } - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -383,7 +383,7 @@ int NpcFunctions::luaNpcCloseShopWindow(lua_State* L) { int NpcFunctions::luaNpcIsMerchant(lua_State* L) { // npc:isMerchant() - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); pushBoolean(L, false); @@ -403,7 +403,7 @@ int NpcFunctions::luaNpcIsMerchant(lua_State* L) { int NpcFunctions::luaNpcGetShopItem(lua_State* L) { // npc:getShopItem(itemId) - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); pushBoolean(L, false); @@ -427,7 +427,7 @@ int NpcFunctions::luaNpcGetShopItem(lua_State* L) { int NpcFunctions::luaNpcMove(lua_State* L) { // npc:move(direction) - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (npc) { g_game().internalMoveCreature(npc, getNumber(L, 2)); } @@ -436,7 +436,7 @@ int NpcFunctions::luaNpcMove(lua_State* L) { int NpcFunctions::luaNpcTurn(lua_State* L) { // npc:turn(direction) - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (npc) { g_game().internalCreatureTurn(npc, getNumber(L, 2)); } @@ -445,7 +445,7 @@ int NpcFunctions::luaNpcTurn(lua_State* L) { int NpcFunctions::luaNpcFollow(lua_State* L) { // npc:follow(player) - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { pushBoolean(L, false); return 1; @@ -457,7 +457,7 @@ int NpcFunctions::luaNpcFollow(lua_State* L) { int NpcFunctions::luaNpcGetId(lua_State* L) { // npc:getId() - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); @@ -470,14 +470,14 @@ int NpcFunctions::luaNpcGetId(lua_State* L) { int NpcFunctions::luaNpcSellItem(lua_State* L) { // npc:sellItem(player, itemid, amount, subtype, actionid, ignoreCap, inBackpacks) - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); pushBoolean(L, false); return 1; } - Player* player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -499,7 +499,7 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { uint32_t shoppingBagPrice = 20; double shoppingBagSlots = 20; - if (const Tile* tile = ignoreCap ? player->getTile() : nullptr; tile) { + if (std::shared_ptr tile = ignoreCap ? player->getTile() : nullptr; tile) { double slotsNedeed = 0; if (it.stackable) { slotsNedeed = inBackpacks ? std::ceil(std::ceil(amount / it.stackSize) / shoppingBagSlots) : std::ceil(amount / it.stackSize); @@ -529,20 +529,20 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { auto remainingAmount = static_cast(amount); if (inBackpacks) { while (remainingAmount > 0) { - Item* container = Item::CreateItem(ITEM_SHOPPING_BAG); + std::shared_ptr container = Item::CreateItem(ITEM_SHOPPING_BAG); if (!container) { break; } if (g_game().internalPlayerAddItem(player, container, ignoreCap, CONST_SLOT_WHEREEVER) != RETURNVALUE_NOERROR) { - delete container; + break; } backpacksPurchased++; uint8_t internalAmount = (remainingAmount > internalCount) ? internalCount : static_cast(remainingAmount); const ItemType &iType = Item::items[itemId]; - Item* item; + std::shared_ptr item; if (iType.isWrappable()) { item = Item::CreateItem(ITEM_DECORATION_KIT, subType); item->setAttribute(ItemAttribute_t::DESCRIPTION, "Unwrap this item in your own house to create a <" + iType.name + ">."); @@ -556,7 +556,7 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { while (remainingAmount > 0) { if (g_game().internalAddItem(container->getContainer(), item, INDEX_WHEREEVER, 0) != RETURNVALUE_NOERROR) { - delete item; + break; } @@ -575,7 +575,7 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { } else { uint8_t internalAmount = (remainingAmount > internalCount) ? internalCount : static_cast(remainingAmount); const ItemType &iType = Item::items[itemId]; - Item* item; + std::shared_ptr item; if (iType.isWrappable()) { item = Item::CreateItem(ITEM_DECORATION_KIT, subType); item->setAttribute(ItemAttribute_t::DESCRIPTION, "Unwrap this item in your own house to create a <" + iType.name + ">."); @@ -589,7 +589,7 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { while (remainingAmount > 0) { if (g_game().internalPlayerAddItem(player, item, ignoreCap, CONST_SLOT_WHEREEVER) != RETURNVALUE_NOERROR) { - delete item; + break; } @@ -669,14 +669,14 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { int NpcFunctions::luaNpcGetDistanceTo(lua_State* L) { // npc:getDistanceTo(uid) - Npc* npc = getUserdata(L, 1); + std::shared_ptr npc = getUserdataShared(L, 1); if (!npc) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); pushBoolean(L, false); return 1; } - Thing* thing = getScriptEnv()->getThingByUID(getNumber(L, -1)); + std::shared_ptr thing = getScriptEnv()->getThingByUID(getNumber(L, -1)); pushBoolean(L, thing && thing->isPushable()); if (!thing) { reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND)); diff --git a/src/lua/functions/creatures/player/guild_functions.cpp b/src/lua/functions/creatures/player/guild_functions.cpp index ff9e54cf8d3..7dd23f45844 100644 --- a/src/lua/functions/creatures/player/guild_functions.cpp +++ b/src/lua/functions/creatures/player/guild_functions.cpp @@ -58,7 +58,7 @@ int GuildFunctions::luaGuildGetMembersOnline(lua_State* L) { lua_createtable(L, members.size(), 0); int index = 0; - for (Player* player : members) { + for (std::shared_ptr player : members) { pushUserdata(L, player); setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); diff --git a/src/lua/functions/creatures/player/party_functions.cpp b/src/lua/functions/creatures/player/party_functions.cpp index 25feb5abb65..e51d231ebf8 100644 --- a/src/lua/functions/creatures/player/party_functions.cpp +++ b/src/lua/functions/creatures/player/party_functions.cpp @@ -16,7 +16,7 @@ int32_t PartyFunctions::luaPartyCreate(lua_State* L) { // Party(userdata) - Player* player = getUserdata(L, 2); + std::shared_ptr player = getUserdataShared(L, 2); if (!player) { lua_pushnil(L); return 1; @@ -57,7 +57,7 @@ int PartyFunctions::luaPartyGetLeader(lua_State* L) { return 1; } - Player* leader = party->getLeader(); + std::shared_ptr leader = party->getLeader(); if (leader) { pushUserdata(L, leader); setMetatable(L, -1, "Player"); @@ -69,7 +69,7 @@ int PartyFunctions::luaPartyGetLeader(lua_State* L) { int PartyFunctions::luaPartySetLeader(lua_State* L) { // party:setLeader(player) - Player* player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { pushBoolean(L, party->passPartyLeadership(player)); @@ -89,7 +89,7 @@ int PartyFunctions::luaPartyGetMembers(lua_State* L) { int index = 0; lua_createtable(L, party->getMemberCount(), 0); - for (Player* player : party->getMembers()) { + for (std::shared_ptr player : party->getMembers()) { pushUserdata(L, player); setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); @@ -115,7 +115,7 @@ int PartyFunctions::luaPartyGetInvitees(lua_State* L) { lua_createtable(L, party->getInvitationCount(), 0); int index = 0; - for (Player* player : party->getInvitees()) { + for (std::shared_ptr player : party->getInvitees()) { pushUserdata(L, player); setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); @@ -139,10 +139,10 @@ int PartyFunctions::luaPartyGetInviteeCount(lua_State* L) { int PartyFunctions::luaPartyAddInvite(lua_State* L) { // party:addInvite(player) - Player* player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { - pushBoolean(L, party->invitePlayer(*player)); + pushBoolean(L, party->invitePlayer(player)); } else { lua_pushnil(L); } @@ -151,10 +151,10 @@ int PartyFunctions::luaPartyAddInvite(lua_State* L) { int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { // party:removeInvite(player) - Player* player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { - pushBoolean(L, party->removeInvite(*player)); + pushBoolean(L, party->removeInvite(player)); } else { lua_pushnil(L); } @@ -163,10 +163,10 @@ int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { int PartyFunctions::luaPartyAddMember(lua_State* L) { // party:addMember(player) - Player* player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { - pushBoolean(L, party->joinParty(*player)); + pushBoolean(L, party->joinParty(player)); } else { lua_pushnil(L); } @@ -175,7 +175,7 @@ int PartyFunctions::luaPartyAddMember(lua_State* L) { int PartyFunctions::luaPartyRemoveMember(lua_State* L) { // party:removeMember(player) - Player* player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { pushBoolean(L, party->leaveParty(player)); diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 4b72347b231..afb991f816d 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -22,7 +22,7 @@ int PlayerFunctions::luaPlayerSendInventory(lua_State* L) { // player:sendInventory() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -36,13 +36,13 @@ int PlayerFunctions::luaPlayerSendInventory(lua_State* L) { int PlayerFunctions::luaPlayerSendLootStats(lua_State* L) { // player:sendLootStats(item, count) - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - Item* item = getUserdata(L, 2); + std::shared_ptr item = getUserdataShared(L, 2); if (!item) { lua_pushnil(L); return 1; @@ -62,13 +62,13 @@ int PlayerFunctions::luaPlayerSendLootStats(lua_State* L) { int PlayerFunctions::luaPlayerUpdateSupplyTracker(lua_State* L) { // player:updateSupplyTracker(item) - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - Item* item = getUserdata(L, 2); + std::shared_ptr item = getUserdataShared(L, 2); if (!item) { lua_pushnil(L); return 1; @@ -82,19 +82,19 @@ int PlayerFunctions::luaPlayerUpdateSupplyTracker(lua_State* L) { int PlayerFunctions::luaPlayerUpdateKillTracker(lua_State* L) { // player:updateKillTracker(creature, corpse) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - Creature* monster = getUserdata(L, 2); + std::shared_ptr monster = getUserdataShared(L, 2); if (!monster) { lua_pushnil(L); return 1; } - Container* corpse = getUserdata(L, 3); + std::shared_ptr corpse = getUserdataShared(L, 3); if (!corpse) { lua_pushnil(L); return 1; @@ -109,7 +109,7 @@ int PlayerFunctions::luaPlayerUpdateKillTracker(lua_State* L) { // Player int PlayerFunctions::luaPlayerCreate(lua_State* L) { // Player(id or guid or name or userdata) - Player* player; + std::shared_ptr player; if (isNumber(L, 2)) { uint32_t id = getNumber(L, 2); if (id >= Player::getFirstID() && id <= Player::getLastID()) { @@ -129,7 +129,7 @@ int PlayerFunctions::luaPlayerCreate(lua_State* L) { lua_pushnil(L); return 1; } - player = getUserdata(L, 2); + player = getUserdataShared(L, 2); } else { player = nullptr; } @@ -145,7 +145,7 @@ int PlayerFunctions::luaPlayerCreate(lua_State* L) { int PlayerFunctions::luaPlayerResetCharmsMonsters(lua_State* L) { // player:resetCharmsBestiary() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setCharmPoints(0); player->setCharmExpansion(false); @@ -163,7 +163,7 @@ int PlayerFunctions::luaPlayerResetCharmsMonsters(lua_State* L) { int PlayerFunctions::luaPlayerUnlockAllCharmRunes(lua_State* L) { // player:unlockAllCharmRunes() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { for (int8_t i = CHARM_WOUND; i <= CHARM_LAST; i++) { const auto charm = g_iobestiary().getBestiaryCharm(static_cast(i)); @@ -181,7 +181,7 @@ int PlayerFunctions::luaPlayerUnlockAllCharmRunes(lua_State* L) { int PlayerFunctions::luaPlayeraddCharmPoints(lua_State* L) { // player:addCharmPoints() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { int16_t charms = getNumber(L, 2); if (charms >= 0) { @@ -199,13 +199,13 @@ int PlayerFunctions::luaPlayeraddCharmPoints(lua_State* L) { int PlayerFunctions::luaPlayerIsPlayer(lua_State* L) { // player:isPlayer() - pushBoolean(L, getUserdata(L, 1) != nullptr); + pushBoolean(L, getUserdataShared(L, 1) != nullptr); return 1; } int PlayerFunctions::luaPlayerGetGuid(lua_State* L) { // player:getGuid() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getGUID()); } else { @@ -216,7 +216,7 @@ int PlayerFunctions::luaPlayerGetGuid(lua_State* L) { int PlayerFunctions::luaPlayerGetIp(lua_State* L) { // player:getIp() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getIP()); } else { @@ -227,7 +227,7 @@ int PlayerFunctions::luaPlayerGetIp(lua_State* L) { int PlayerFunctions::luaPlayerGetAccountId(lua_State* L) { // player:getAccountId() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || player->getAccountId() == 0) { lua_pushnil(L); return 1; @@ -240,7 +240,7 @@ int PlayerFunctions::luaPlayerGetAccountId(lua_State* L) { int PlayerFunctions::luaPlayerGetLastLoginSaved(lua_State* L) { // player:getLastLoginSaved() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getLastLoginSaved()); } else { @@ -251,7 +251,7 @@ int PlayerFunctions::luaPlayerGetLastLoginSaved(lua_State* L) { int PlayerFunctions::luaPlayerGetLastLogout(lua_State* L) { // player:getLastLogout() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getLastLogout()); } else { @@ -262,7 +262,7 @@ int PlayerFunctions::luaPlayerGetLastLogout(lua_State* L) { int PlayerFunctions::luaPlayerGetAccountType(lua_State* L) { // player:getAccountType() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getAccountType()); } else { @@ -273,7 +273,7 @@ int PlayerFunctions::luaPlayerGetAccountType(lua_State* L) { int PlayerFunctions::luaPlayerSetAccountType(lua_State* L) { // player:setAccountType(accountType) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { lua_pushnil(L); return 1; @@ -295,7 +295,7 @@ int PlayerFunctions::luaPlayerSetAccountType(lua_State* L) { int PlayerFunctions::luaPlayerAddBestiaryKill(lua_State* L) { // player:addBestiaryKill(name[, amount = 1]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { const auto mtype = g_monsters().getMonsterType(getString(L, 2)); if (mtype) { @@ -312,7 +312,7 @@ int PlayerFunctions::luaPlayerAddBestiaryKill(lua_State* L) { int PlayerFunctions::luaPlayerIsMonsterBestiaryUnlocked(lua_State* L) { // player:isMonsterBestiaryUnlocked(raceId) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -340,7 +340,7 @@ int PlayerFunctions::luaPlayerIsMonsterBestiaryUnlocked(lua_State* L) { int PlayerFunctions::luaPlayergetCharmMonsterType(lua_State* L) { // player:getCharmMonsterType(charmRune_t) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { charmRune_t charmid = getNumber(L, 2); uint16_t raceid = player->parseRacebyCharm(charmid, false, 0); @@ -363,7 +363,7 @@ int PlayerFunctions::luaPlayergetCharmMonsterType(lua_State* L) { int PlayerFunctions::luaPlayerRemovePreyStamina(lua_State* L) { // player:removePreyStamina(amount) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { g_ioprey().CheckPlayerPreys(player, getNumber(L, 2, 1)); pushBoolean(L, true); @@ -375,7 +375,7 @@ int PlayerFunctions::luaPlayerRemovePreyStamina(lua_State* L) { int PlayerFunctions::luaPlayerAddPreyCards(lua_State* L) { // player:addPreyCards(amount) - if (Player* player = getUserdata(L, 1)) { + if (std::shared_ptr player = getUserdataShared(L, 1)) { player->addPreyCards(getNumber(L, 2, 0)); pushBoolean(L, true); } else { @@ -386,7 +386,7 @@ int PlayerFunctions::luaPlayerAddPreyCards(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyCards(lua_State* L) { // player:getPreyCards() - if (const Player* player = getUserdata(L, 1)) { + if (std::shared_ptr player = getUserdataShared(L, 1)) { lua_pushnumber(L, static_cast(player->getPreyCards())); } else { lua_pushnil(L); @@ -396,7 +396,7 @@ int PlayerFunctions::luaPlayerGetPreyCards(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyExperiencePercentage(lua_State* L) { // player:getPreyExperiencePercentage(raceId) - if (const Player* player = getUserdata(L, 1)) { + if (std::shared_ptr player = getUserdataShared(L, 1)) { if (const PreySlot* slot = player->getPreyWithMonster(getNumber(L, 2, 0)); slot && slot->isOccupied() && slot->bonus == PreyBonus_Experience && slot->bonusTimeLeft > 0) { lua_pushnumber(L, static_cast(100 + slot->bonusPercentage)); @@ -411,7 +411,7 @@ int PlayerFunctions::luaPlayerGetPreyExperiencePercentage(lua_State* L) { int PlayerFunctions::luaPlayerRemoveTaskHuntingPoints(lua_State* L) { // player:removeTaskHuntingPoints(amount) - if (Player* player = getUserdata(L, 1)) { + if (std::shared_ptr player = getUserdataShared(L, 1)) { pushBoolean(L, player->useTaskHuntingPoints(getNumber(L, 2, 0))); } else { lua_pushnil(L); @@ -421,7 +421,7 @@ int PlayerFunctions::luaPlayerRemoveTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetTaskHuntingPoints(lua_State* L) { // player:getTaskHuntingPoints() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -434,7 +434,7 @@ int PlayerFunctions::luaPlayerGetTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerAddTaskHuntingPoints(lua_State* L) { // player:addTaskHuntingPoints(amount) - if (Player* player = getUserdata(L, 1)) { + if (std::shared_ptr player = getUserdataShared(L, 1)) { auto points = getNumber(L, 2); player->addTaskHuntingPoints(getNumber(L, 2)); lua_pushnumber(L, static_cast(points)); @@ -446,7 +446,7 @@ int PlayerFunctions::luaPlayerAddTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyLootPercentage(lua_State* L) { // player:getPreyLootPercentage(raceid) - if (const Player* player = getUserdata(L, 1)) { + if (std::shared_ptr player = getUserdataShared(L, 1)) { if (const PreySlot* slot = player->getPreyWithMonster(getNumber(L, 2, 0)); slot && slot->isOccupied() && slot->bonus == PreyBonus_Loot) { lua_pushnumber(L, slot->bonusPercentage); @@ -461,7 +461,7 @@ int PlayerFunctions::luaPlayerGetPreyLootPercentage(lua_State* L) { int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { // get: player:preyThirdSlot() set: player:preyThirdSlot(bool) - if (Player* player = getUserdata(L, 1); + if (std::shared_ptr player = getUserdataShared(L, 1); PreySlot* slot = player->getPreySlotById(PreySlot_Three)) { if (lua_gettop(L) == 1) { pushBoolean(L, slot->state != PreyDataState_Locked); @@ -485,7 +485,7 @@ int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { int PlayerFunctions::luaPlayerTaskThirdSlot(lua_State* L) { // get: player:taskHuntingThirdSlot() set: player:taskHuntingThirdSlot(bool) - if (Player* player = getUserdata(L, 1); + if (std::shared_ptr player = getUserdataShared(L, 1); TaskHuntingSlot* slot = player->getTaskHuntingSlotById(PreySlot_Three)) { if (lua_gettop(L) == 1) { pushBoolean(L, slot->state != PreyTaskDataState_Locked); @@ -510,7 +510,7 @@ int PlayerFunctions::luaPlayerTaskThirdSlot(lua_State* L) { int PlayerFunctions::luaPlayercharmExpansion(lua_State* L) { // get: player:charmExpansion() set: player:charmExpansion(bool) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { if (lua_gettop(L) == 1) { pushBoolean(L, player->hasCharmExpansion()); @@ -526,7 +526,7 @@ int PlayerFunctions::luaPlayercharmExpansion(lua_State* L) { int PlayerFunctions::luaPlayerGetCapacity(lua_State* L) { // player:getCapacity() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getCapacity()); } else { @@ -537,7 +537,7 @@ int PlayerFunctions::luaPlayerGetCapacity(lua_State* L) { int PlayerFunctions::luaPlayerSetCapacity(lua_State* L) { // player:setCapacity(capacity) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->capacity = getNumber(L, 2); player->sendStats(); @@ -550,7 +550,7 @@ int PlayerFunctions::luaPlayerSetCapacity(lua_State* L) { int PlayerFunctions::luaPlayerSetTraining(lua_State* L) { // player:setTraining(value) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { bool value = getBoolean(L, 2, false); player->setTraining(value); @@ -563,7 +563,7 @@ int PlayerFunctions::luaPlayerSetTraining(lua_State* L) { int PlayerFunctions::luaPlayerGetIsTraining(lua_State* L) { // player:isTraining() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { pushBoolean(L, false); reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); @@ -576,7 +576,7 @@ int PlayerFunctions::luaPlayerGetIsTraining(lua_State* L) { int PlayerFunctions::luaPlayerGetFreeCapacity(lua_State* L) { // player:getFreeCapacity() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getFreeCapacity()); } else { @@ -587,7 +587,7 @@ int PlayerFunctions::luaPlayerGetFreeCapacity(lua_State* L) { int PlayerFunctions::luaPlayerGetKills(lua_State* L) { // player:getKills() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -611,7 +611,7 @@ int PlayerFunctions::luaPlayerGetKills(lua_State* L) { int PlayerFunctions::luaPlayerSetKills(lua_State* L) { // player:setKills(kills) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -639,7 +639,7 @@ int PlayerFunctions::luaPlayerSetKills(lua_State* L) { int PlayerFunctions::luaPlayerGetReward(lua_State* L) { // player:getReward(rewardId[, autoCreate = false]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -658,7 +658,7 @@ int PlayerFunctions::luaPlayerGetReward(lua_State* L) { int PlayerFunctions::luaPlayerRemoveReward(lua_State* L) { // player:removeReward(rewardId) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -672,7 +672,7 @@ int PlayerFunctions::luaPlayerRemoveReward(lua_State* L) { int PlayerFunctions::luaPlayerGetRewardList(lua_State* L) { // player:getRewardList() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -692,7 +692,7 @@ int PlayerFunctions::luaPlayerGetRewardList(lua_State* L) { int PlayerFunctions::luaPlayerSetDailyReward(lua_State* L) { // player:setDailyReward(value) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setDailyReward(getNumber(L, 2)); pushBoolean(L, true); @@ -704,14 +704,14 @@ int PlayerFunctions::luaPlayerSetDailyReward(lua_State* L) { int PlayerFunctions::luaPlayerGetDepotLocker(lua_State* L) { // player:getDepotLocker(depotId) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } uint32_t depotId = getNumber(L, 2); - DepotLocker* depotLocker = player->getDepotLocker(depotId); + std::shared_ptr depotLocker = player->getDepotLocker(depotId); if (depotLocker) { depotLocker->setParent(player); pushUserdata(L, depotLocker); @@ -724,7 +724,7 @@ int PlayerFunctions::luaPlayerGetDepotLocker(lua_State* L) { int PlayerFunctions::luaPlayerGetStashCounter(lua_State* L) { // player:getStashCount() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t sizeStash = getStashSize(player->getStashItems()); lua_pushnumber(L, sizeStash); @@ -736,7 +736,7 @@ int PlayerFunctions::luaPlayerGetStashCounter(lua_State* L) { int PlayerFunctions::luaPlayerGetDepotChest(lua_State* L) { // player:getDepotChest(depotId[, autoCreate = false]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -744,7 +744,7 @@ int PlayerFunctions::luaPlayerGetDepotChest(lua_State* L) { uint32_t depotId = getNumber(L, 2); bool autoCreate = getBoolean(L, 3, false); - DepotChest* depotChest = player->getDepotChest(depotId, autoCreate); + std::shared_ptr depotChest = player->getDepotChest(depotId, autoCreate); if (depotChest) { player->setLastDepotId(depotId); pushUserdata(L, depotChest); @@ -757,13 +757,13 @@ int PlayerFunctions::luaPlayerGetDepotChest(lua_State* L) { int PlayerFunctions::luaPlayerGetInbox(lua_State* L) { // player:getInbox() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - Inbox* inbox = player->getInbox(); + std::shared_ptr inbox = player->getInbox(); if (inbox) { pushUserdata(L, inbox); setItemMetatable(L, -1, inbox); @@ -775,7 +775,7 @@ int PlayerFunctions::luaPlayerGetInbox(lua_State* L) { int PlayerFunctions::luaPlayerGetSkullTime(lua_State* L) { // player:getSkullTime() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSkullTicks()); } else { @@ -786,7 +786,7 @@ int PlayerFunctions::luaPlayerGetSkullTime(lua_State* L) { int PlayerFunctions::luaPlayerSetSkullTime(lua_State* L) { // player:setSkullTime(skullTime) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setSkullTicks(getNumber(L, 2)); pushBoolean(L, true); @@ -798,7 +798,7 @@ int PlayerFunctions::luaPlayerSetSkullTime(lua_State* L) { int PlayerFunctions::luaPlayerGetDeathPenalty(lua_State* L) { // player:getDeathPenalty() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, static_cast(player->getLostPercent() * 100)); } else { @@ -809,7 +809,7 @@ int PlayerFunctions::luaPlayerGetDeathPenalty(lua_State* L) { int PlayerFunctions::luaPlayerGetExperience(lua_State* L) { // player:getExperience() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getExperience()); } else { @@ -820,7 +820,7 @@ int PlayerFunctions::luaPlayerGetExperience(lua_State* L) { int PlayerFunctions::luaPlayerAddExperience(lua_State* L) { // player:addExperience(experience[, sendText = false]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { int64_t experience = getNumber(L, 2); bool sendText = getBoolean(L, 3, false); @@ -834,7 +834,7 @@ int PlayerFunctions::luaPlayerAddExperience(lua_State* L) { int PlayerFunctions::luaPlayerRemoveExperience(lua_State* L) { // player:removeExperience(experience[, sendText = false]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { int64_t experience = getNumber(L, 2); bool sendText = getBoolean(L, 3, false); @@ -848,7 +848,7 @@ int PlayerFunctions::luaPlayerRemoveExperience(lua_State* L) { int PlayerFunctions::luaPlayerGetLevel(lua_State* L) { // player:getLevel() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getLevel()); } else { @@ -859,7 +859,7 @@ int PlayerFunctions::luaPlayerGetLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetMagicShieldCapacityFlat(lua_State* L) { // player:getMagicShieldCapacityFlat(useCharges) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMagicShieldCapacityFlat(getBoolean(L, 2, false))); } else { @@ -870,7 +870,7 @@ int PlayerFunctions::luaPlayerGetMagicShieldCapacityFlat(lua_State* L) { int PlayerFunctions::luaPlayerGetMagicShieldCapacityPercent(lua_State* L) { // player:getMagicShieldCapacityPercent(useCharges) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMagicShieldCapacityPercent(getBoolean(L, 2, false))); } else { @@ -881,7 +881,7 @@ int PlayerFunctions::luaPlayerGetMagicShieldCapacityPercent(lua_State* L) { int PlayerFunctions::luaPlayerSendSpellCooldown(lua_State* L) { // player:sendSpellCooldown(spellId, time) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -897,7 +897,7 @@ int PlayerFunctions::luaPlayerSendSpellCooldown(lua_State* L) { int PlayerFunctions::luaPlayerSendSpellGroupCooldown(lua_State* L) { // player:sendSpellGroupCooldown(groupId, time) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -913,7 +913,7 @@ int PlayerFunctions::luaPlayerSendSpellGroupCooldown(lua_State* L) { int PlayerFunctions::luaPlayerGetMagicLevel(lua_State* L) { // player:getMagicLevel() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMagicLevel()); } else { @@ -924,7 +924,7 @@ int PlayerFunctions::luaPlayerGetMagicLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseMagicLevel(lua_State* L) { // player:getBaseMagicLevel() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getBaseMagicLevel()); } else { @@ -935,7 +935,7 @@ int PlayerFunctions::luaPlayerGetBaseMagicLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetMana(lua_State* L) { // player:getMana() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMana()); } else { @@ -946,7 +946,7 @@ int PlayerFunctions::luaPlayerGetMana(lua_State* L) { int PlayerFunctions::luaPlayerAddMana(lua_State* L) { // player:addMana(manaChange[, animationOnLoss = false]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -968,7 +968,7 @@ int PlayerFunctions::luaPlayerAddMana(lua_State* L) { int PlayerFunctions::luaPlayerGetMaxMana(lua_State* L) { // player:getMaxMana() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMaxMana()); } else { @@ -979,7 +979,7 @@ int PlayerFunctions::luaPlayerGetMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerSetMaxMana(lua_State* L) { // player:setMaxMana(maxMana) - Player* player = getPlayer(L, 1); + std::shared_ptr player = getPlayer(L, 1); if (player) { player->manaMax = getNumber(L, 2); player->mana = std::min(player->mana, player->manaMax); @@ -994,7 +994,7 @@ int PlayerFunctions::luaPlayerSetMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerGetManaSpent(lua_State* L) { // player:getManaSpent() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSpentMana()); } else { @@ -1005,7 +1005,7 @@ int PlayerFunctions::luaPlayerGetManaSpent(lua_State* L) { int PlayerFunctions::luaPlayerAddManaSpent(lua_State* L) { // player:addManaSpent(amount) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->addManaSpent(getNumber(L, 2)); pushBoolean(L, true); @@ -1017,7 +1017,7 @@ int PlayerFunctions::luaPlayerAddManaSpent(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseMaxHealth(lua_State* L) { // player:getBaseMaxHealth() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->healthMax); } else { @@ -1028,7 +1028,7 @@ int PlayerFunctions::luaPlayerGetBaseMaxHealth(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseMaxMana(lua_State* L) { // player:getBaseMaxMana() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->manaMax); } else { @@ -1040,7 +1040,7 @@ int PlayerFunctions::luaPlayerGetBaseMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerGetSkillLevel(lua_State* L) { // player:getSkillLevel(skillType) skills_t skillType = getNumber(L, 2); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->skills[skillType].level); } else { @@ -1052,7 +1052,7 @@ int PlayerFunctions::luaPlayerGetSkillLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetEffectiveSkillLevel(lua_State* L) { // player:getEffectiveSkillLevel(skillType) skills_t skillType = getNumber(L, 2); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->getSkillLevel(skillType)); } else { @@ -1064,7 +1064,7 @@ int PlayerFunctions::luaPlayerGetEffectiveSkillLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetSkillPercent(lua_State* L) { // player:getSkillPercent(skillType) skills_t skillType = getNumber(L, 2); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->skills[skillType].percent); } else { @@ -1076,7 +1076,7 @@ int PlayerFunctions::luaPlayerGetSkillPercent(lua_State* L) { int PlayerFunctions::luaPlayerGetSkillTries(lua_State* L) { // player:getSkillTries(skillType) skills_t skillType = getNumber(L, 2); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->skills[skillType].tries); } else { @@ -1087,7 +1087,7 @@ int PlayerFunctions::luaPlayerGetSkillTries(lua_State* L) { int PlayerFunctions::luaPlayerAddSkillTries(lua_State* L) { // player:addSkillTries(skillType, tries) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { skills_t skillType = getNumber(L, 2); uint64_t tries = getNumber(L, 3); @@ -1101,7 +1101,7 @@ int PlayerFunctions::luaPlayerAddSkillTries(lua_State* L) { int PlayerFunctions::luaPlayerSetLevel(lua_State* L) { // player:setLevel(level) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t level = getNumber(L, 2); player->level = level; @@ -1117,7 +1117,7 @@ int PlayerFunctions::luaPlayerSetLevel(lua_State* L) { int PlayerFunctions::luaPlayerSetMagicLevel(lua_State* L) { // player:setMagicLevel(level[, manaSpent]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t level = getNumber(L, 2); player->magLevel = level; @@ -1141,7 +1141,7 @@ int PlayerFunctions::luaPlayerSetMagicLevel(lua_State* L) { int PlayerFunctions::luaPlayerSetSkillLevel(lua_State* L) { // player:setSkillLevel(skillType, level[, tries]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { skills_t skillType = getNumber(L, 2); uint16_t level = getNumber(L, 3); @@ -1166,7 +1166,7 @@ int PlayerFunctions::luaPlayerSetSkillLevel(lua_State* L) { int PlayerFunctions::luaPlayerAddOfflineTrainingTime(lua_State* L) { // player:addOfflineTrainingTime(time) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { int32_t time = getNumber(L, 2); player->addOfflineTrainingTime(time); @@ -1180,7 +1180,7 @@ int PlayerFunctions::luaPlayerAddOfflineTrainingTime(lua_State* L) { int PlayerFunctions::luaPlayerGetOfflineTrainingTime(lua_State* L) { // player:getOfflineTrainingTime() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getOfflineTrainingTime()); } else { @@ -1191,7 +1191,7 @@ int PlayerFunctions::luaPlayerGetOfflineTrainingTime(lua_State* L) { int PlayerFunctions::luaPlayerRemoveOfflineTrainingTime(lua_State* L) { // player:removeOfflineTrainingTime(time) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { int32_t time = getNumber(L, 2); player->removeOfflineTrainingTime(time); @@ -1205,7 +1205,7 @@ int PlayerFunctions::luaPlayerRemoveOfflineTrainingTime(lua_State* L) { int PlayerFunctions::luaPlayerAddOfflineTrainingTries(lua_State* L) { // player:addOfflineTrainingTries(skillType, tries) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { skills_t skillType = getNumber(L, 2); uint64_t tries = getNumber(L, 3); @@ -1218,7 +1218,7 @@ int PlayerFunctions::luaPlayerAddOfflineTrainingTries(lua_State* L) { int PlayerFunctions::luaPlayerGetOfflineTrainingSkill(lua_State* L) { // player:getOfflineTrainingSkill() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getOfflineTrainingSkill()); } else { @@ -1229,7 +1229,7 @@ int PlayerFunctions::luaPlayerGetOfflineTrainingSkill(lua_State* L) { int PlayerFunctions::luaPlayerSetOfflineTrainingSkill(lua_State* L) { // player:setOfflineTrainingSkill(skillId) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { int8_t skillId = getNumber(L, 2); player->setOfflineTrainingSkill(skillId); @@ -1242,7 +1242,7 @@ int PlayerFunctions::luaPlayerSetOfflineTrainingSkill(lua_State* L) { int PlayerFunctions::luaPlayerOpenStash(lua_State* L) { // player:openStash(isNpc) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); bool isNpc = getBoolean(L, 2, false); if (player) { player->sendOpenStash(isNpc); @@ -1256,7 +1256,7 @@ int PlayerFunctions::luaPlayerOpenStash(lua_State* L) { int PlayerFunctions::luaPlayerGetItemCount(lua_State* L) { // player:getItemCount(itemId[, subType = -1]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1280,7 +1280,7 @@ int PlayerFunctions::luaPlayerGetItemCount(lua_State* L) { int PlayerFunctions::luaPlayerGetStashItemCount(lua_State* L) { // player:getStashItemCount(itemId) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1309,7 +1309,7 @@ int PlayerFunctions::luaPlayerGetStashItemCount(lua_State* L) { int PlayerFunctions::luaPlayerGetItemById(lua_State* L) { // player:getItemById(itemId, deepSearch[, subType = -1]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1328,7 +1328,7 @@ int PlayerFunctions::luaPlayerGetItemById(lua_State* L) { bool deepSearch = getBoolean(L, 3); int32_t subType = getNumber(L, 4, -1); - Item* item = g_game().findItemOfType(player, itemId, deepSearch, subType); + std::shared_ptr item = g_game().findItemOfType(player, itemId, deepSearch, subType); if (item) { pushUserdata(L, item); setItemMetatable(L, -1, item); @@ -1340,7 +1340,7 @@ int PlayerFunctions::luaPlayerGetItemById(lua_State* L) { int PlayerFunctions::luaPlayerGetVocation(lua_State* L) { // player:getVocation() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushUserdata(L, player->getVocation()); setMetatable(L, -1, "Vocation"); @@ -1352,7 +1352,7 @@ int PlayerFunctions::luaPlayerGetVocation(lua_State* L) { int PlayerFunctions::luaPlayerSetVocation(lua_State* L) { // player:setVocation(id or name or userdata) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1381,7 +1381,7 @@ int PlayerFunctions::luaPlayerSetVocation(lua_State* L) { int PlayerFunctions::luaPlayerGetSex(lua_State* L) { // player:getSex() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSex()); } else { @@ -1392,7 +1392,7 @@ int PlayerFunctions::luaPlayerGetSex(lua_State* L) { int PlayerFunctions::luaPlayerSetSex(lua_State* L) { // player:setSex(newSex) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { PlayerSex_t newSex = getNumber(L, 2); player->setSex(newSex); @@ -1405,7 +1405,7 @@ int PlayerFunctions::luaPlayerSetSex(lua_State* L) { int PlayerFunctions::luaPlayerGetPronoun(lua_State* L) { // player:getPronoun() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getPronoun()); } else { @@ -1416,7 +1416,7 @@ int PlayerFunctions::luaPlayerGetPronoun(lua_State* L) { int PlayerFunctions::luaPlayerSetPronoun(lua_State* L) { // player:setPronoun(newPronoun) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { PlayerPronoun_t newPronoun = getNumber(L, 2); player->setPronoun(newPronoun); @@ -1429,7 +1429,7 @@ int PlayerFunctions::luaPlayerSetPronoun(lua_State* L) { int PlayerFunctions::luaPlayerGetTown(lua_State* L) { // player:getTown() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushUserdata(L, player->getTown()); setMetatable(L, -1, "Town"); @@ -1447,7 +1447,7 @@ int PlayerFunctions::luaPlayerSetTown(lua_State* L) { return 1; } - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setTown(town); pushBoolean(L, true); @@ -1459,7 +1459,7 @@ int PlayerFunctions::luaPlayerSetTown(lua_State* L) { int PlayerFunctions::luaPlayerGetGuild(lua_State* L) { // player:getGuild() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1478,7 +1478,7 @@ int PlayerFunctions::luaPlayerGetGuild(lua_State* L) { int PlayerFunctions::luaPlayerSetGuild(lua_State* L) { // player:setGuild(guild) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1493,7 +1493,7 @@ int PlayerFunctions::luaPlayerSetGuild(lua_State* L) { int PlayerFunctions::luaPlayerGetGuildLevel(lua_State* L) { // player:getGuildLevel() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && player->getGuild()) { lua_pushnumber(L, player->getGuildRank()->level); } else { @@ -1505,7 +1505,7 @@ int PlayerFunctions::luaPlayerGetGuildLevel(lua_State* L) { int PlayerFunctions::luaPlayerSetGuildLevel(lua_State* L) { // player:setGuildLevel(level) uint8_t level = getNumber(L, 2); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getGuild()) { lua_pushnil(L); return 1; @@ -1524,7 +1524,7 @@ int PlayerFunctions::luaPlayerSetGuildLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetGuildNick(lua_State* L) { // player:getGuildNick() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushString(L, player->getGuildNick()); } else { @@ -1536,7 +1536,7 @@ int PlayerFunctions::luaPlayerGetGuildNick(lua_State* L) { int PlayerFunctions::luaPlayerSetGuildNick(lua_State* L) { // player:setGuildNick(nick) const std::string &nick = getString(L, 2); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setGuildNick(nick); pushBoolean(L, true); @@ -1548,7 +1548,7 @@ int PlayerFunctions::luaPlayerSetGuildNick(lua_State* L) { int PlayerFunctions::luaPlayerGetGroup(lua_State* L) { // player:getGroup() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushUserdata(L, player->getGroup()); setMetatable(L, -1, "Group"); @@ -1566,7 +1566,7 @@ int PlayerFunctions::luaPlayerSetGroup(lua_State* L) { return 1; } - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setGroup(group); pushBoolean(L, true); @@ -1581,7 +1581,7 @@ int PlayerFunctions::luaPlayerSetSpecialContainersAvailable(lua_State* L) { bool supplyStashMenu = getBoolean(L, 2, false); bool marketMenu = getBoolean(L, 3, false); bool depotSearchMenu = getBoolean(L, 4, false); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setSpecialMenuAvailable(supplyStashMenu, marketMenu, depotSearchMenu); pushBoolean(L, true); @@ -1593,7 +1593,7 @@ int PlayerFunctions::luaPlayerSetSpecialContainersAvailable(lua_State* L) { int PlayerFunctions::luaPlayerGetStamina(lua_State* L) { // player:getStamina() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getStaminaMinutes()); } else { @@ -1605,7 +1605,7 @@ int PlayerFunctions::luaPlayerGetStamina(lua_State* L) { int PlayerFunctions::luaPlayerSetStamina(lua_State* L) { // player:setStamina(stamina) uint16_t stamina = getNumber(L, 2); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->staminaMinutes = std::min(2520, stamina); player->sendStats(); @@ -1617,7 +1617,7 @@ int PlayerFunctions::luaPlayerSetStamina(lua_State* L) { int PlayerFunctions::luaPlayerGetSoul(lua_State* L) { // player:getSoul() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSoul()); } else { @@ -1629,7 +1629,7 @@ int PlayerFunctions::luaPlayerGetSoul(lua_State* L) { int PlayerFunctions::luaPlayerAddSoul(lua_State* L) { // player:addSoul(soulChange) int32_t soulChange = getNumber(L, 2); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->changeSoul(soulChange); pushBoolean(L, true); @@ -1641,7 +1641,7 @@ int PlayerFunctions::luaPlayerAddSoul(lua_State* L) { int PlayerFunctions::luaPlayerGetMaxSoul(lua_State* L) { // player:getMaxSoul() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && player->vocation) { lua_pushnumber(L, player->vocation->getSoulMax()); } else { @@ -1652,7 +1652,7 @@ int PlayerFunctions::luaPlayerGetMaxSoul(lua_State* L) { int PlayerFunctions::luaPlayerGetBankBalance(lua_State* L) { // player:getBankBalance() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getBankBalance()); } else { @@ -1663,7 +1663,7 @@ int PlayerFunctions::luaPlayerGetBankBalance(lua_State* L) { int PlayerFunctions::luaPlayerSetBankBalance(lua_State* L) { // player:setBankBalance(bankBalance) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1676,7 +1676,7 @@ int PlayerFunctions::luaPlayerSetBankBalance(lua_State* L) { int PlayerFunctions::luaPlayerGetStorageValue(lua_State* L) { // player:getStorageValue(key) - const auto &player = getUserdata(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1691,7 +1691,7 @@ int PlayerFunctions::luaPlayerSetStorageValue(lua_State* L) { // player:setStorageValue(key, value) int32_t value = getNumber(L, 3); uint32_t key = getNumber(L, 2); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (IS_IN_KEYRANGE(key, RESERVED_RANGE)) { std::ostringstream ss; ss << "Accessing reserved range: " << key; @@ -1711,7 +1711,7 @@ int PlayerFunctions::luaPlayerSetStorageValue(lua_State* L) { int PlayerFunctions::luaPlayerGetStorageValueByName(lua_State* L) { // player:getStorageValueByName(name) - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -1725,7 +1725,7 @@ int PlayerFunctions::luaPlayerGetStorageValueByName(lua_State* L) { int PlayerFunctions::luaPlayerSetStorageValueByName(lua_State* L) { // player:setStorageValueByName(storageName, value) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -1742,7 +1742,7 @@ int PlayerFunctions::luaPlayerSetStorageValueByName(lua_State* L) { int PlayerFunctions::luaPlayerAddItem(lua_State* L) { // player:addItem(itemId, count = 1, canDropOnMap = true, subType = 1, slot = CONST_SLOT_WHEREEVER, tier = 0) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { pushBoolean(L, false); return 1; @@ -1796,7 +1796,7 @@ int PlayerFunctions::luaPlayerAddItem(lua_State* L) { subType -= stackCount; } - Item* item = Item::CreateItem(itemId, stackCount); + std::shared_ptr item = Item::CreateItem(itemId, stackCount); if (!item) { if (!hasTable) { lua_pushnil(L); @@ -1810,7 +1810,7 @@ int PlayerFunctions::luaPlayerAddItem(lua_State* L) { ReturnValue ret = g_game().internalPlayerAddItem(player, item, canDropOnMap, slot); if (ret != RETURNVALUE_NOERROR) { - delete item; + if (!hasTable) { lua_pushnil(L); } @@ -1833,14 +1833,14 @@ int PlayerFunctions::luaPlayerAddItem(lua_State* L) { int PlayerFunctions::luaPlayerAddItemEx(lua_State* L) { // player:addItemEx(item[, canDropOnMap = false[, index = INDEX_WHEREEVER[, flags = 0]]]) // player:addItemEx(item[, canDropOnMap = true[, slot = CONST_SLOT_WHEREEVER]]) - Item* item = getUserdata(L, 2); + std::shared_ptr item = getUserdataShared(L, 2); if (!item) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); pushBoolean(L, false); return 1; } - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1872,7 +1872,7 @@ int PlayerFunctions::luaPlayerAddItemEx(lua_State* L) { int PlayerFunctions::luaPlayerRemoveStashItem(lua_State* L) { // player:removeStashItem(itemId, count) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1902,7 +1902,7 @@ int PlayerFunctions::luaPlayerRemoveStashItem(lua_State* L) { int PlayerFunctions::luaPlayerRemoveItem(lua_State* L) { // player:removeItem(itemId, count[, subType = -1[, ignoreEquipped = false]]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1928,13 +1928,13 @@ int PlayerFunctions::luaPlayerRemoveItem(lua_State* L) { int PlayerFunctions::luaPlayerSendContainer(lua_State* L) { // player:sendContainer(container) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - Container* container = getUserdata(L, 2); + std::shared_ptr container = getUserdataShared(L, 2); if (!container) { lua_pushnil(L); return 1; @@ -1947,13 +1947,13 @@ int PlayerFunctions::luaPlayerSendContainer(lua_State* L) { int PlayerFunctions::luaPlayerSendUpdateContainer(lua_State* L) { // player:sendUpdateContainer(container) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto container = getUserdata(L, 2); + const auto container = getUserdataShared(L, 2); if (!container) { reportErrorFunc("Container is nullptr"); return 1; @@ -1966,7 +1966,7 @@ int PlayerFunctions::luaPlayerSendUpdateContainer(lua_State* L) { int PlayerFunctions::luaPlayerGetMoney(lua_State* L) { // player:getMoney() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMoney()); } else { @@ -1978,7 +1978,7 @@ int PlayerFunctions::luaPlayerGetMoney(lua_State* L) { int PlayerFunctions::luaPlayerAddMoney(lua_State* L) { // player:addMoney(money) uint64_t money = getNumber(L, 2); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { g_game().addMoney(player, money); pushBoolean(L, true); @@ -1990,7 +1990,7 @@ int PlayerFunctions::luaPlayerAddMoney(lua_State* L) { int PlayerFunctions::luaPlayerRemoveMoney(lua_State* L) { // player:removeMoney(money[, flags = 0[, useBank = true]]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint64_t money = getNumber(L, 2); int32_t flags = getNumber(L, 3, 0); @@ -2004,7 +2004,7 @@ int PlayerFunctions::luaPlayerRemoveMoney(lua_State* L) { int PlayerFunctions::luaPlayerShowTextDialog(lua_State* L) { // player:showTextDialog(id or name or userdata[, text[, canWrite[, length]]]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2019,7 +2019,7 @@ int PlayerFunctions::luaPlayerShowTextDialog(lua_State* L) { text = getString(L, 3); } - Item* item; + std::shared_ptr item; if (isNumber(L, 2)) { item = Item::CreateItem(getNumber(L, 2)); } else if (isString(L, 2)) { @@ -2030,7 +2030,7 @@ int PlayerFunctions::luaPlayerShowTextDialog(lua_State* L) { return 1; } - item = getUserdata(L, 2); + item = getUserdataShared(L, 2); } else { item = nullptr; } @@ -2061,7 +2061,7 @@ int PlayerFunctions::luaPlayerSendTextMessage(lua_State* L) { // player:sendTextMessage(type, text[, position, primaryValue = 0, primaryColor = TEXTCOLOR_NONE[, secondaryValue = 0, secondaryColor = TEXTCOLOR_NONE]]) // player:sendTextMessage(type, text, channelId) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2072,8 +2072,8 @@ int PlayerFunctions::luaPlayerSendTextMessage(lua_State* L) { TextMessage message(getNumber(L, 2), getString(L, 3)); if (parameters == 4) { uint16_t channelId = getNumber(L, 4); - ChatChannel* channel = g_chat().getChannel(*player, channelId); - if (!channel || !channel->hasUser(*player)) { + ChatChannel* channel = g_chat().getChannel(player, channelId); + if (!channel || !channel->hasUser(player)) { pushBoolean(L, false); return 1; } @@ -2099,7 +2099,7 @@ int PlayerFunctions::luaPlayerSendTextMessage(lua_State* L) { int PlayerFunctions::luaPlayerSendChannelMessage(lua_State* L) { // player:sendChannelMessage(author, text, type, channelId) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2116,13 +2116,13 @@ int PlayerFunctions::luaPlayerSendChannelMessage(lua_State* L) { int PlayerFunctions::luaPlayerSendPrivateMessage(lua_State* L) { // player:sendPrivateMessage(speaker, text[, type]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const Player* speaker = getUserdata(L, 2); + std::shared_ptr speaker = getUserdataShared(L, 2); const std::string &text = getString(L, 3); SpeakClasses type = getNumber(L, 4, TALKTYPE_PRIVATE_FROM); player->sendPrivateMessage(speaker, type, text); @@ -2132,13 +2132,13 @@ int PlayerFunctions::luaPlayerSendPrivateMessage(lua_State* L) { int PlayerFunctions::luaPlayerChannelSay(lua_State* L) { // player:channelSay(speaker, type, text, channelId) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - Creature* speaker = getCreature(L, 2); + std::shared_ptr speaker = getCreature(L, 2); SpeakClasses type = getNumber(L, 3); const std::string &text = getString(L, 4); uint16_t channelId = getNumber(L, 5); @@ -2150,7 +2150,7 @@ int PlayerFunctions::luaPlayerChannelSay(lua_State* L) { int PlayerFunctions::luaPlayerOpenChannel(lua_State* L) { // player:openChannel(channelId) uint16_t channelId = getNumber(L, 2); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { g_game().playerOpenChannel(player->getID(), channelId); pushBoolean(L, true); @@ -2162,20 +2162,20 @@ int PlayerFunctions::luaPlayerOpenChannel(lua_State* L) { int PlayerFunctions::luaPlayerGetSlotItem(lua_State* L) { // player:getSlotItem(slot) - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } uint32_t slot = getNumber(L, 2); - Thing* thing = player->getThing(slot); + std::shared_ptr thing = player->getThing(slot); if (!thing) { lua_pushnil(L); return 1; } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item) { pushUserdata(L, item); setItemMetatable(L, -1, item); @@ -2187,7 +2187,7 @@ int PlayerFunctions::luaPlayerGetSlotItem(lua_State* L) { int PlayerFunctions::luaPlayerGetParty(lua_State* L) { // player:getParty() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2205,7 +2205,7 @@ int PlayerFunctions::luaPlayerGetParty(lua_State* L) { int PlayerFunctions::luaPlayerAddOutfit(lua_State* L) { // player:addOutfit(lookType) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->addOutfit(getNumber(L, 2), 0); pushBoolean(L, true); @@ -2217,7 +2217,7 @@ int PlayerFunctions::luaPlayerAddOutfit(lua_State* L) { int PlayerFunctions::luaPlayerAddOutfitAddon(lua_State* L) { // player:addOutfitAddon(lookType, addon) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); uint8_t addon = getNumber(L, 3); @@ -2231,7 +2231,7 @@ int PlayerFunctions::luaPlayerAddOutfitAddon(lua_State* L) { int PlayerFunctions::luaPlayerRemoveOutfit(lua_State* L) { // player:removeOutfit(lookType) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); pushBoolean(L, player->removeOutfit(lookType)); @@ -2243,7 +2243,7 @@ int PlayerFunctions::luaPlayerRemoveOutfit(lua_State* L) { int PlayerFunctions::luaPlayerRemoveOutfitAddon(lua_State* L) { // player:removeOutfitAddon(lookType, addon) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); uint8_t addon = getNumber(L, 3); @@ -2256,7 +2256,7 @@ int PlayerFunctions::luaPlayerRemoveOutfitAddon(lua_State* L) { int PlayerFunctions::luaPlayerHasOutfit(lua_State* L) { // player:hasOutfit(lookType[, addon = 0]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); uint8_t addon = getNumber(L, 3, 0); @@ -2269,7 +2269,7 @@ int PlayerFunctions::luaPlayerHasOutfit(lua_State* L) { int PlayerFunctions::luaPlayerSendOutfitWindow(lua_State* L) { // player:sendOutfitWindow() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->sendOutfitWindow(); pushBoolean(L, true); @@ -2281,7 +2281,7 @@ int PlayerFunctions::luaPlayerSendOutfitWindow(lua_State* L) { int PlayerFunctions::luaPlayerAddMount(lua_State* L) { // player:addMount(mountId or mountName) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2304,7 +2304,7 @@ int PlayerFunctions::luaPlayerAddMount(lua_State* L) { int PlayerFunctions::luaPlayerRemoveMount(lua_State* L) { // player:removeMount(mountId or mountName) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2327,7 +2327,7 @@ int PlayerFunctions::luaPlayerRemoveMount(lua_State* L) { int PlayerFunctions::luaPlayerHasMount(lua_State* L) { // player:hasMount(mountId or mountName) - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2350,7 +2350,7 @@ int PlayerFunctions::luaPlayerHasMount(lua_State* L) { int PlayerFunctions::luaPlayerAddFamiliar(lua_State* L) { // player:addFamiliar(lookType) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->addFamiliar(getNumber(L, 2)); pushBoolean(L, true); @@ -2362,7 +2362,7 @@ int PlayerFunctions::luaPlayerAddFamiliar(lua_State* L) { int PlayerFunctions::luaPlayerRemoveFamiliar(lua_State* L) { // player:removeFamiliar(lookType) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); pushBoolean(L, player->removeFamiliar(lookType)); @@ -2374,7 +2374,7 @@ int PlayerFunctions::luaPlayerRemoveFamiliar(lua_State* L) { int PlayerFunctions::luaPlayerHasFamiliar(lua_State* L) { // player:hasFamiliar(lookType) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); pushBoolean(L, player->canFamiliar(lookType)); @@ -2386,7 +2386,7 @@ int PlayerFunctions::luaPlayerHasFamiliar(lua_State* L) { int PlayerFunctions::luaPlayerSetFamiliarLooktype(lua_State* L) { // player:setFamiliarLooktype(lookType) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setFamiliarLooktype(getNumber(L, 2)); pushBoolean(L, true); @@ -2398,7 +2398,7 @@ int PlayerFunctions::luaPlayerSetFamiliarLooktype(lua_State* L) { int PlayerFunctions::luaPlayerGetFamiliarLooktype(lua_State* L) { // player:getFamiliarLooktype() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->defaultOutfit.lookFamiliarsType); } else { @@ -2409,7 +2409,7 @@ int PlayerFunctions::luaPlayerGetFamiliarLooktype(lua_State* L) { int PlayerFunctions::luaPlayerGetPremiumDays(lua_State* L) { // player:getPremiumDays() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && player->getAccount()) { lua_pushnumber(L, player->getAccount()->getPremiumRemainingDays()); } else { @@ -2420,7 +2420,7 @@ int PlayerFunctions::luaPlayerGetPremiumDays(lua_State* L) { int PlayerFunctions::luaPlayerAddPremiumDays(lua_State* L) { // player:addPremiumDays(days) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { lua_pushnil(L); return 1; @@ -2449,7 +2449,7 @@ int PlayerFunctions::luaPlayerAddPremiumDays(lua_State* L) { int PlayerFunctions::luaPlayerRemovePremiumDays(lua_State* L) { // player:removePremiumDays(days) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { lua_pushnil(L); return 1; @@ -2478,7 +2478,7 @@ int PlayerFunctions::luaPlayerRemovePremiumDays(lua_State* L) { int PlayerFunctions::luaPlayerGetTibiaCoins(lua_State* L) { // player:getTibiaCoins() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2496,7 +2496,7 @@ int PlayerFunctions::luaPlayerGetTibiaCoins(lua_State* L) { int PlayerFunctions::luaPlayerAddTibiaCoins(lua_State* L) { // player:addTibiaCoins(coins) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2522,7 +2522,7 @@ int PlayerFunctions::luaPlayerAddTibiaCoins(lua_State* L) { int PlayerFunctions::luaPlayerRemoveTibiaCoins(lua_State* L) { // player:removeTibiaCoins(coins) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2547,7 +2547,7 @@ int PlayerFunctions::luaPlayerRemoveTibiaCoins(lua_State* L) { int PlayerFunctions::luaPlayerGetTransferableCoins(lua_State* L) { // player:getTransferableCoins() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2565,7 +2565,7 @@ int PlayerFunctions::luaPlayerGetTransferableCoins(lua_State* L) { int PlayerFunctions::luaPlayerAddTransferableCoins(lua_State* L) { // player:addTransferableCoins(coins) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2591,7 +2591,7 @@ int PlayerFunctions::luaPlayerAddTransferableCoins(lua_State* L) { int PlayerFunctions::luaPlayerRemoveTransferableCoins(lua_State* L) { // player:removeTransferableCoins(coins) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2618,7 +2618,7 @@ int PlayerFunctions::luaPlayerRemoveTransferableCoins(lua_State* L) { int PlayerFunctions::luaPlayerHasBlessing(lua_State* L) { // player:hasBlessing(blessing) uint8_t blessing = getNumber(L, 2); - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->hasBlessing(blessing)); } else { @@ -2629,7 +2629,7 @@ int PlayerFunctions::luaPlayerHasBlessing(lua_State* L) { int PlayerFunctions::luaPlayerAddBlessing(lua_State* L) { // player:addBlessing(blessing) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2646,7 +2646,7 @@ int PlayerFunctions::luaPlayerAddBlessing(lua_State* L) { int PlayerFunctions::luaPlayerRemoveBlessing(lua_State* L) { // player:removeBlessing(blessing) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2667,7 +2667,7 @@ int PlayerFunctions::luaPlayerRemoveBlessing(lua_State* L) { int PlayerFunctions::luaPlayerGetBlessingCount(lua_State* L) { // player:getBlessingCount(index) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); uint8_t index = getNumber(L, 2); if (index == 0) { index = 1; @@ -2683,7 +2683,7 @@ int PlayerFunctions::luaPlayerGetBlessingCount(lua_State* L) { int PlayerFunctions::luaPlayerCanLearnSpell(lua_State* L) { // player:canLearnSpell(spellName) - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2717,7 +2717,7 @@ int PlayerFunctions::luaPlayerCanLearnSpell(lua_State* L) { int PlayerFunctions::luaPlayerLearnSpell(lua_State* L) { // player:learnSpell(spellName) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { const std::string &spellName = getString(L, 2); player->learnInstantSpell(spellName); @@ -2730,7 +2730,7 @@ int PlayerFunctions::luaPlayerLearnSpell(lua_State* L) { int PlayerFunctions::luaPlayerForgetSpell(lua_State* L) { // player:forgetSpell(spellName) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { const std::string &spellName = getString(L, 2); player->forgetInstantSpell(spellName); @@ -2743,7 +2743,7 @@ int PlayerFunctions::luaPlayerForgetSpell(lua_State* L) { int PlayerFunctions::luaPlayerHasLearnedSpell(lua_State* L) { // player:hasLearnedSpell(spellName) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { const std::string &spellName = getString(L, 2); pushBoolean(L, player->hasLearnedInstantSpell(spellName)); @@ -2755,7 +2755,7 @@ int PlayerFunctions::luaPlayerHasLearnedSpell(lua_State* L) { int PlayerFunctions::luaPlayerSendTutorial(lua_State* L) { // player:sendTutorial(tutorialId) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint8_t tutorialId = getNumber(L, 2); player->sendTutorial(tutorialId); @@ -2768,14 +2768,14 @@ int PlayerFunctions::luaPlayerSendTutorial(lua_State* L) { int PlayerFunctions::luaPlayerOpenImbuementWindow(lua_State* L) { // player:openImbuementWindow(item) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); return 1; } - Item* item = getUserdata(L, 2); + std::shared_ptr item = getUserdataShared(L, 2); if (!item) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); pushBoolean(L, false); @@ -2788,7 +2788,7 @@ int PlayerFunctions::luaPlayerOpenImbuementWindow(lua_State* L) { int PlayerFunctions::luaPlayerCloseImbuementWindow(lua_State* L) { // player:closeImbuementWindow() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -2801,7 +2801,7 @@ int PlayerFunctions::luaPlayerCloseImbuementWindow(lua_State* L) { int PlayerFunctions::luaPlayerAddMapMark(lua_State* L) { // player:addMapMark(position, type, description) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { const Position &position = getPosition(L, 2); uint8_t type = getNumber(L, 3); @@ -2816,14 +2816,14 @@ int PlayerFunctions::luaPlayerAddMapMark(lua_State* L) { int PlayerFunctions::luaPlayerSave(lua_State* L) { // player:save() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { if (!player->isOffline()) { player->loginPosition = player->getPosition(); } pushBoolean(L, IOLoginData::savePlayer(player)); if (player->isOffline()) { - delete player; // avoiding memory leak + // avoiding memory leak } } else { lua_pushnil(L); @@ -2833,7 +2833,7 @@ int PlayerFunctions::luaPlayerSave(lua_State* L) { int PlayerFunctions::luaPlayerPopupFYI(lua_State* L) { // player:popupFYI(message) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { const std::string &message = getString(L, 2); player->sendFYIBox(message); @@ -2846,7 +2846,7 @@ int PlayerFunctions::luaPlayerPopupFYI(lua_State* L) { int PlayerFunctions::luaPlayerIsPzLocked(lua_State* L) { // player:isPzLocked() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->isPzLocked()); } else { @@ -2857,7 +2857,7 @@ int PlayerFunctions::luaPlayerIsPzLocked(lua_State* L) { int PlayerFunctions::luaPlayerGetClient(lua_State* L) { // player:getClient() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_createtable(L, 0, 2); setField(L, "version", player->getProtocolVersion()); @@ -2870,7 +2870,7 @@ int PlayerFunctions::luaPlayerGetClient(lua_State* L) { int PlayerFunctions::luaPlayerGetHouse(lua_State* L) { // player:getHouse() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2888,7 +2888,7 @@ int PlayerFunctions::luaPlayerGetHouse(lua_State* L) { int PlayerFunctions::luaPlayerSendHouseWindow(lua_State* L) { // player:sendHouseWindow(house, listId) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2908,7 +2908,7 @@ int PlayerFunctions::luaPlayerSendHouseWindow(lua_State* L) { int PlayerFunctions::luaPlayerSetEditHouse(lua_State* L) { // player:setEditHouse(house, listId) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2928,7 +2928,7 @@ int PlayerFunctions::luaPlayerSetEditHouse(lua_State* L) { int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { // player:setGhostMode(enabled) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2942,13 +2942,13 @@ int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { player->switchGhostMode(); - Tile* tile = player->getTile(); + std::shared_ptr tile = player->getTile(); const Position &position = player->getPosition(); SpectatorHashSet spectators; g_game().map.getSpectators(spectators, position, true, true); - for (Creature* spectator : spectators) { - Player* tmpPlayer = spectator->getPlayer(); + for (auto spectator : spectators) { + auto tmpPlayer = spectator->getPlayer(); if (tmpPlayer != player && !tmpPlayer->isAccessPlayer()) { if (enabled) { tmpPlayer->sendRemoveTileThing(position, tile->getStackposOfCreature(tmpPlayer, player)); @@ -2981,13 +2981,13 @@ int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { int PlayerFunctions::luaPlayerGetContainerId(lua_State* L) { // player:getContainerId(container) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - Container* container = getUserdata(L, 2); + std::shared_ptr container = getUserdataShared(L, 2); if (container) { lua_pushnumber(L, player->getContainerID(container)); } else { @@ -2998,13 +2998,13 @@ int PlayerFunctions::luaPlayerGetContainerId(lua_State* L) { int PlayerFunctions::luaPlayerGetContainerById(lua_State* L) { // player:getContainerById(id) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - Container* container = player->getContainerByID(getNumber(L, 2)); + std::shared_ptr container = player->getContainerByID(getNumber(L, 2)); if (container) { pushUserdata(L, container); setMetatable(L, -1, "Container"); @@ -3016,7 +3016,7 @@ int PlayerFunctions::luaPlayerGetContainerById(lua_State* L) { int PlayerFunctions::luaPlayerGetContainerIndex(lua_State* L) { // player:getContainerIndex(id) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getContainerIndex(getNumber(L, 2))); } else { @@ -3027,7 +3027,7 @@ int PlayerFunctions::luaPlayerGetContainerIndex(lua_State* L) { int PlayerFunctions::luaPlayerGetInstantSpells(lua_State* L) { // player:getInstantSpells() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3052,7 +3052,7 @@ int PlayerFunctions::luaPlayerGetInstantSpells(lua_State* L) { int PlayerFunctions::luaPlayerCanCast(lua_State* L) { // player:canCast(spell) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); const auto spell = getUserdataShared(L, 2); if (player && spell) { pushBoolean(L, spell->canCast(player)); @@ -3064,7 +3064,7 @@ int PlayerFunctions::luaPlayerCanCast(lua_State* L) { int PlayerFunctions::luaPlayerHasChaseMode(lua_State* L) { // player:hasChaseMode() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->chaseMode); } else { @@ -3075,7 +3075,7 @@ int PlayerFunctions::luaPlayerHasChaseMode(lua_State* L) { int PlayerFunctions::luaPlayerHasSecureMode(lua_State* L) { // player:hasSecureMode() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->secureMode); } else { @@ -3086,7 +3086,7 @@ int PlayerFunctions::luaPlayerHasSecureMode(lua_State* L) { int PlayerFunctions::luaPlayerGetFightMode(lua_State* L) { // player:getFightMode() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->fightMode); } else { @@ -3097,7 +3097,7 @@ int PlayerFunctions::luaPlayerGetFightMode(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseXpGain(lua_State* L) { // player:getBaseXpGain() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getBaseXpGain()); } else { @@ -3108,7 +3108,7 @@ int PlayerFunctions::luaPlayerGetBaseXpGain(lua_State* L) { int PlayerFunctions::luaPlayerSetBaseXpGain(lua_State* L) { // player:setBaseXpGain(value) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setBaseXpGain(getNumber(L, 2)); player->sendStats(); @@ -3121,7 +3121,7 @@ int PlayerFunctions::luaPlayerSetBaseXpGain(lua_State* L) { int PlayerFunctions::luaPlayerGetVoucherXpBoost(lua_State* L) { // player:getVoucherXpBoost() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getVoucherXpBoost()); } else { @@ -3132,7 +3132,7 @@ int PlayerFunctions::luaPlayerGetVoucherXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetVoucherXpBoost(lua_State* L) { // player:setVoucherXpBoost(value) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setVoucherXpBoost(getNumber(L, 2)); player->sendStats(); @@ -3145,7 +3145,7 @@ int PlayerFunctions::luaPlayerSetVoucherXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerGetGrindingXpBoost(lua_State* L) { // player:getGrindingXpBoost() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getGrindingXpBoost()); } else { @@ -3156,7 +3156,7 @@ int PlayerFunctions::luaPlayerGetGrindingXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetGrindingXpBoost(lua_State* L) { // player:setGrindingXpBoost(value) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setGrindingXpBoost(getNumber(L, 2)); player->sendStats(); @@ -3169,7 +3169,7 @@ int PlayerFunctions::luaPlayerSetGrindingXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerGetStoreXpBoost(lua_State* L) { // player:getStoreXpBoost() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getStoreXpBoost()); } else { @@ -3180,7 +3180,7 @@ int PlayerFunctions::luaPlayerGetStoreXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetStoreXpBoost(lua_State* L) { // player:setStoreXpBoost(value) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t experience = getNumber(L, 2); player->setStoreXpBoost(experience); @@ -3193,7 +3193,7 @@ int PlayerFunctions::luaPlayerSetStoreXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerGetStaminaXpBoost(lua_State* L) { // player:getStaminaXpBoost() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getStaminaXpBoost()); } else { @@ -3204,7 +3204,7 @@ int PlayerFunctions::luaPlayerGetStaminaXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetStaminaXpBoost(lua_State* L) { // player:setStaminaXpBoost(value) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setStaminaXpBoost(getNumber(L, 2)); player->sendStats(); @@ -3217,7 +3217,7 @@ int PlayerFunctions::luaPlayerSetStaminaXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetExpBoostStamina(lua_State* L) { // player:setExpBoostStamina(percent) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t stamina = getNumber(L, 2); player->setExpBoostStamina(stamina); @@ -3231,7 +3231,7 @@ int PlayerFunctions::luaPlayerSetExpBoostStamina(lua_State* L) { int PlayerFunctions::luaPlayerGetExpBoostStamina(lua_State* L) { // player:getExpBoostStamina() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getExpBoostStamina()); } else { @@ -3242,7 +3242,7 @@ int PlayerFunctions::luaPlayerGetExpBoostStamina(lua_State* L) { int PlayerFunctions::luaPlayerGetIdleTime(lua_State* L) { // player:getIdleTime() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getIdleTime()); } else { @@ -3253,7 +3253,7 @@ int PlayerFunctions::luaPlayerGetIdleTime(lua_State* L) { int PlayerFunctions::luaPlayerGetFreeBackpackSlots(lua_State* L) { // player:getFreeBackpackSlots() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); } @@ -3263,7 +3263,7 @@ int PlayerFunctions::luaPlayerGetFreeBackpackSlots(lua_State* L) { } int PlayerFunctions::luaPlayerIsOffline(lua_State* L) { - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->isOffline()); } else { @@ -3275,7 +3275,7 @@ int PlayerFunctions::luaPlayerIsOffline(lua_State* L) { int PlayerFunctions::luaPlayerOpenMarket(lua_State* L) { // player:openMarket() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3289,7 +3289,7 @@ int PlayerFunctions::luaPlayerOpenMarket(lua_State* L) { // Forge int PlayerFunctions::luaPlayerOpenForge(lua_State* L) { // player:openForge() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3303,7 +3303,7 @@ int PlayerFunctions::luaPlayerOpenForge(lua_State* L) { int PlayerFunctions::luaPlayerCloseForge(lua_State* L) { // player:closeForge() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3317,7 +3317,7 @@ int PlayerFunctions::luaPlayerCloseForge(lua_State* L) { int PlayerFunctions::luaPlayerAddForgeDusts(lua_State* L) { // player:addForgeDusts(amount) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3331,7 +3331,7 @@ int PlayerFunctions::luaPlayerAddForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerRemoveForgeDusts(lua_State* L) { // player:removeForgeDusts(amount) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3345,7 +3345,7 @@ int PlayerFunctions::luaPlayerRemoveForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeDusts(lua_State* L) { // player:getForgeDusts() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3358,7 +3358,7 @@ int PlayerFunctions::luaPlayerGetForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerSetForgeDusts(lua_State* L) { // player:setForgeDusts() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3372,7 +3372,7 @@ int PlayerFunctions::luaPlayerSetForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerAddForgeDustLevel(lua_State* L) { // player:addForgeDustLevel(amount) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3386,7 +3386,7 @@ int PlayerFunctions::luaPlayerAddForgeDustLevel(lua_State* L) { int PlayerFunctions::luaPlayerRemoveForgeDustLevel(lua_State* L) { // player:removeForgeDustLevel(amount) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3400,7 +3400,7 @@ int PlayerFunctions::luaPlayerRemoveForgeDustLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeDustLevel(lua_State* L) { // player:getForgeDustLevel() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3413,7 +3413,7 @@ int PlayerFunctions::luaPlayerGetForgeDustLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeSlivers(lua_State* L) { // player:getForgeSlivers() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3427,7 +3427,7 @@ int PlayerFunctions::luaPlayerGetForgeSlivers(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeCores(lua_State* L) { // player:getForgeCores() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3441,7 +3441,7 @@ int PlayerFunctions::luaPlayerGetForgeCores(lua_State* L) { int PlayerFunctions::luaPlayerSetFaction(lua_State* L) { // player:setFaction(factionId) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3456,7 +3456,7 @@ int PlayerFunctions::luaPlayerSetFaction(lua_State* L) { int PlayerFunctions::luaPlayerGetFaction(lua_State* L) { // player:getFaction() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3469,7 +3469,7 @@ int PlayerFunctions::luaPlayerGetFaction(lua_State* L) { int PlayerFunctions::luaPlayerIsUIExhausted(lua_State* L) { // player:isUIExhausted() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3483,7 +3483,7 @@ int PlayerFunctions::luaPlayerIsUIExhausted(lua_State* L) { int PlayerFunctions::luaPlayerUpdateUIExhausted(lua_State* L) { // player:updateUIExhausted(exhaustionTime = 250) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3498,7 +3498,7 @@ int PlayerFunctions::luaPlayerUpdateUIExhausted(lua_State* L) { // Bosstiary Cooldown Timer int PlayerFunctions::luaPlayerBosstiaryCooldownTimer(lua_State* L) { // player:sendBosstiaryCooldownTimer() - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3512,7 +3512,7 @@ int PlayerFunctions::luaPlayerBosstiaryCooldownTimer(lua_State* L) { int PlayerFunctions::luaPlayerGetBosstiaryLevel(lua_State* L) { // player:getBosstiaryLevel(name) - if (Player* player = getUserdata(L, 1); + if (std::shared_ptr player = getUserdataShared(L, 1); player) { const auto mtype = g_monsters().getMonsterType(getString(L, 2)); if (mtype) { @@ -3534,7 +3534,7 @@ int PlayerFunctions::luaPlayerGetBosstiaryLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetBosstiaryKills(lua_State* L) { // player:getBosstiaryKills(name) - if (Player* player = getUserdata(L, 1); + if (std::shared_ptr player = getUserdataShared(L, 1); player) { const auto mtype = g_monsters().getMonsterType(getString(L, 2)); if (mtype) { @@ -3556,7 +3556,7 @@ int PlayerFunctions::luaPlayerGetBosstiaryKills(lua_State* L) { int PlayerFunctions::luaPlayerAddBosstiaryKill(lua_State* L) { // player:addBosstiaryKill(name[, amount = 1]) - if (Player* player = getUserdata(L, 1); + if (std::shared_ptr player = getUserdataShared(L, 1); player) { const auto mtype = g_monsters().getMonsterType(getString(L, 2)); if (mtype) { @@ -3573,7 +3573,7 @@ int PlayerFunctions::luaPlayerAddBosstiaryKill(lua_State* L) { int PlayerFunctions::luaPlayerSetBossPoints(lua_State* L) { // player:setBossPoints() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3587,7 +3587,7 @@ int PlayerFunctions::luaPlayerSetBossPoints(lua_State* L) { int PlayerFunctions::luaPlayerSetRemoveBossTime(lua_State* L) { // player:setRemoveBossTime() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3601,7 +3601,7 @@ int PlayerFunctions::luaPlayerSetRemoveBossTime(lua_State* L) { int PlayerFunctions::luaPlayerGetSlotBossId(lua_State* L) { // player:getSlotBossId(slotId) - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3616,7 +3616,7 @@ int PlayerFunctions::luaPlayerGetSlotBossId(lua_State* L) { int PlayerFunctions::luaPlayerGetBossBonus(lua_State* L) { // player:getBossBonus(slotId) - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3638,7 +3638,7 @@ int PlayerFunctions::luaPlayerGetBossBonus(lua_State* L) { int PlayerFunctions::luaPlayerSendSingleSoundEffect(lua_State* L) { // player:sendSingleSoundEffect(soundId[, actor = true]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3655,7 +3655,7 @@ int PlayerFunctions::luaPlayerSendSingleSoundEffect(lua_State* L) { int PlayerFunctions::luaPlayerSendDoubleSoundEffect(lua_State* L) { // player:sendDoubleSoundEffect(mainSoundId, secondarySoundId[, actor = true]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3673,7 +3673,7 @@ int PlayerFunctions::luaPlayerSendDoubleSoundEffect(lua_State* L) { int PlayerFunctions::luaPlayerGetName(lua_State* L) { // player:getName() - const auto player = getUserdata(L, 1); + const auto player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3686,7 +3686,7 @@ int PlayerFunctions::luaPlayerGetName(lua_State* L) { int PlayerFunctions::luaPlayerHasGroupFlag(lua_State* L) { // player:hasGroupFlag(flag) - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3699,7 +3699,7 @@ int PlayerFunctions::luaPlayerHasGroupFlag(lua_State* L) { int PlayerFunctions::luaPlayerSetGroupFlag(lua_State* L) { // player:setGroupFlag(flag) - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3712,7 +3712,7 @@ int PlayerFunctions::luaPlayerSetGroupFlag(lua_State* L) { int PlayerFunctions::luaPlayerRemoveGroupFlag(lua_State* L) { // player:removeGroupFlag(flag) - const Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3726,7 +3726,7 @@ int PlayerFunctions::luaPlayerRemoveGroupFlag(lua_State* L) { // Hazard system int PlayerFunctions::luaPlayerAddHazardSystemPoints(lua_State* L) { // player:setHazardSystemPoints(amount) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { pushBoolean(L, false); reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); @@ -3740,7 +3740,7 @@ int PlayerFunctions::luaPlayerAddHazardSystemPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetHazardSystemPoints(lua_State* L) { // player:getHazardSystemPoints() - const auto player = getUserdata(L, 1); + const auto player = getUserdataShared(L, 1); if (!player) { pushBoolean(L, false); reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); @@ -3753,7 +3753,7 @@ int PlayerFunctions::luaPlayerGetHazardSystemPoints(lua_State* L) { int PlayerFunctions::luaPlayerSetLoyaltyBonus(lua_State* L) { // player:setLoyaltyBonus(amount) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3766,7 +3766,7 @@ int PlayerFunctions::luaPlayerSetLoyaltyBonus(lua_State* L) { int PlayerFunctions::luaPlayerGetLoyaltyBonus(lua_State* L) { // player:getLoyaltyBonus() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3778,7 +3778,7 @@ int PlayerFunctions::luaPlayerGetLoyaltyBonus(lua_State* L) { int PlayerFunctions::luaPlayerGetLoyaltyPoints(lua_State* L) { // player:getLoyaltyPoints() - const auto &player = getUserdata(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3790,7 +3790,7 @@ int PlayerFunctions::luaPlayerGetLoyaltyPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetLoyaltyTitle(lua_State* L) { // player:getLoyaltyTitle() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3802,7 +3802,7 @@ int PlayerFunctions::luaPlayerGetLoyaltyTitle(lua_State* L) { int PlayerFunctions::luaPlayerSetLoyaltyTitle(lua_State* L) { // player:setLoyaltyTitle(name) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3816,7 +3816,7 @@ int PlayerFunctions::luaPlayerSetLoyaltyTitle(lua_State* L) { // Wheel of destiny system int PlayerFunctions::luaPlayerInstantSkillWOD(lua_State* L) { // player:instantSkillWOD(name[, value]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3834,7 +3834,7 @@ int PlayerFunctions::luaPlayerInstantSkillWOD(lua_State* L) { int PlayerFunctions::luaPlayerUpgradeSpellWOD(lua_State* L) { // player:upgradeSpellsWOD([name[, add]]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3864,7 +3864,7 @@ int PlayerFunctions::luaPlayerUpgradeSpellWOD(lua_State* L) { int PlayerFunctions::luaPlayerRevelationStageWOD(lua_State* L) { // player:revelationStagesWOD([name[, set]]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3890,7 +3890,7 @@ int PlayerFunctions::luaPlayerRevelationStageWOD(lua_State* L) { int PlayerFunctions::luaPlayerReloadData(lua_State* L) { // player:reloadData() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3907,7 +3907,7 @@ int PlayerFunctions::luaPlayerReloadData(lua_State* L) { int PlayerFunctions::luaPlayerOnThinkWheelOfDestiny(lua_State* L) { // player:onThinkWheelOfDestiny([force = false]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3920,7 +3920,7 @@ int PlayerFunctions::luaPlayerOnThinkWheelOfDestiny(lua_State* L) { int PlayerFunctions::luaPlayerAvatarTimer(lua_State* L) { // player:avatarTimer([value]) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3937,7 +3937,7 @@ int PlayerFunctions::luaPlayerAvatarTimer(lua_State* L) { int PlayerFunctions::luaPlayerGetWheelSpellAdditionalArea(lua_State* L) { // player:getWheelSpellAdditionalArea(spellname) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3964,7 +3964,7 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalArea(lua_State* L) { int PlayerFunctions::luaPlayerGetWheelSpellAdditionalTarget(lua_State* L) { // player:getWheelSpellAdditionalTarget(spellname) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3991,7 +3991,7 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalTarget(lua_State* L) { int PlayerFunctions::luaPlayerGetWheelSpellAdditionalDuration(lua_State* L) { // player:getWheelSpellAdditionalDuration(spellname) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -4018,7 +4018,7 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalDuration(lua_State* L) { int PlayerFunctions::luaPlayerUpdateConcoction(lua_State* L) { // player:updateConcoction(itemid, timeLeft) - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -4030,7 +4030,7 @@ int PlayerFunctions::luaPlayerUpdateConcoction(lua_State* L) { int PlayerFunctions::luaPlayerClearSpellCooldowns(lua_State* L) { // player:clearSpellCooldowns() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -4042,7 +4042,7 @@ int PlayerFunctions::luaPlayerClearSpellCooldowns(lua_State* L) { int PlayerFunctions::luaPlayerIsVip(lua_State* L) { // player:isVip() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -4054,7 +4054,7 @@ int PlayerFunctions::luaPlayerIsVip(lua_State* L) { int PlayerFunctions::luaPlayerGetVipDays(lua_State* L) { // player:getVipDays() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -4067,7 +4067,7 @@ int PlayerFunctions::luaPlayerGetVipDays(lua_State* L) { int PlayerFunctions::luaPlayerGetVipTime(lua_State* L) { // player:getVipTime() - Player* player = getUserdata(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -4080,7 +4080,7 @@ int PlayerFunctions::luaPlayerGetVipTime(lua_State* L) { int PlayerFunctions::luaPlayerKV(lua_State* L) { // player:kv() - auto player = getUserdata(L, 1); + auto player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/items/container_functions.cpp b/src/lua/functions/items/container_functions.cpp index efd01eae743..3e0904e5262 100644 --- a/src/lua/functions/items/container_functions.cpp +++ b/src/lua/functions/items/container_functions.cpp @@ -17,7 +17,7 @@ int ContainerFunctions::luaContainerCreate(lua_State* L) { // Container(uid) uint32_t id = getNumber(L, 2); - Container* container = getScriptEnv()->getContainerByUID(id); + std::shared_ptr container = getScriptEnv()->getContainerByUID(id); if (container) { pushUserdata(L, container); setMetatable(L, -1, "Container"); @@ -29,7 +29,7 @@ int ContainerFunctions::luaContainerCreate(lua_State* L) { int ContainerFunctions::luaContainerGetSize(lua_State* L) { // container:getSize() - Container* container = getUserdata(L, 1); + std::shared_ptr container = getUserdataShared(L, 1); if (container) { lua_pushnumber(L, container->size()); } else { @@ -40,7 +40,7 @@ int ContainerFunctions::luaContainerGetSize(lua_State* L) { int ContainerFunctions::luaContainerGetCapacity(lua_State* L) { // container:getCapacity() - Container* container = getUserdata(L, 1); + std::shared_ptr container = getUserdataShared(L, 1); if (container) { lua_pushnumber(L, container->capacity()); } else { @@ -51,7 +51,7 @@ int ContainerFunctions::luaContainerGetCapacity(lua_State* L) { int ContainerFunctions::luaContainerGetEmptySlots(lua_State* L) { // container:getEmptySlots([recursive = false]) - Container* container = getUserdata(L, 1); + std::shared_ptr container = getUserdataShared(L, 1); if (!container) { lua_pushnil(L); return 1; @@ -61,7 +61,7 @@ int ContainerFunctions::luaContainerGetEmptySlots(lua_State* L) { bool recursive = getBoolean(L, 2, false); if (recursive) { for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { - if (Container* tmpContainer = (*it)->getContainer()) { + if (std::shared_ptr tmpContainer = (*it)->getContainer()) { slots += tmpContainer->capacity() - tmpContainer->size(); } } @@ -72,7 +72,7 @@ int ContainerFunctions::luaContainerGetEmptySlots(lua_State* L) { int ContainerFunctions::luaContainerGetItemHoldingCount(lua_State* L) { // container:getItemHoldingCount() - Container* container = getUserdata(L, 1); + std::shared_ptr container = getUserdataShared(L, 1); if (container) { lua_pushnumber(L, container->getItemHoldingCount()); } else { @@ -83,14 +83,14 @@ int ContainerFunctions::luaContainerGetItemHoldingCount(lua_State* L) { int ContainerFunctions::luaContainerGetItem(lua_State* L) { // container:getItem(index) - Container* container = getUserdata(L, 1); + std::shared_ptr container = getUserdataShared(L, 1); if (!container) { lua_pushnil(L); return 1; } uint32_t index = getNumber(L, 2); - Item* item = container->getItemByIndex(index); + std::shared_ptr item = container->getItemByIndex(index); if (item) { pushUserdata(L, item); setItemMetatable(L, -1, item); @@ -102,8 +102,8 @@ int ContainerFunctions::luaContainerGetItem(lua_State* L) { int ContainerFunctions::luaContainerHasItem(lua_State* L) { // container:hasItem(item) - Item* item = getUserdata(L, 2); - Container* container = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 2); + std::shared_ptr container = getUserdataShared(L, 1); if (container) { pushBoolean(L, container->isHoldingItem(item)); } else { @@ -114,7 +114,7 @@ int ContainerFunctions::luaContainerHasItem(lua_State* L) { int ContainerFunctions::luaContainerAddItem(lua_State* L) { // container:addItem(itemId[, count/subType = 1[, index = INDEX_WHEREEVER[, flags = 0]]]) - Container* container = getUserdata(L, 1); + std::shared_ptr container = getUserdataShared(L, 1); if (!container) { lua_pushnil(L); reportErrorFunc("Container is nullptr"); @@ -139,7 +139,7 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) { count = std::min(count, it.stackSize); } - Item* item = Item::CreateItem(itemId, count); + std::shared_ptr item = Item::CreateItem(itemId, count); if (!item) { lua_pushnil(L); reportErrorFunc("Item is nullptr"); @@ -156,20 +156,19 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) { } else { reportErrorFunc(fmt::format("Cannot add item to container, error code: '{}'", getReturnMessage(ret))); delete item; - lua_pushnil(L); } return 1; } int ContainerFunctions::luaContainerAddItemEx(lua_State* L) { // container:addItemEx(item[, index = INDEX_WHEREEVER[, flags = 0]]) - Item* item = getUserdata(L, 2); + std::shared_ptr item = getUserdataShared(L, 2); if (!item) { lua_pushnil(L); return 1; } - Container* container = getUserdata(L, 1); + std::shared_ptr container = getUserdataShared(L, 1); if (!container) { lua_pushnil(L); return 1; @@ -193,7 +192,7 @@ int ContainerFunctions::luaContainerAddItemEx(lua_State* L) { int ContainerFunctions::luaContainerGetCorpseOwner(lua_State* L) { // container:getCorpseOwner() - Container* container = getUserdata(L, 1); + std::shared_ptr container = getUserdataShared(L, 1); if (container) { lua_pushnumber(L, container->getCorpseOwner()); } else { @@ -204,7 +203,7 @@ int ContainerFunctions::luaContainerGetCorpseOwner(lua_State* L) { int ContainerFunctions::luaContainerGetItemCountById(lua_State* L) { // container:getItemCountById(itemId[, subType = -1]) - Container* container = getUserdata(L, 1); + std::shared_ptr container = getUserdataShared(L, 1); if (!container) { lua_pushnil(L); return 1; @@ -228,7 +227,7 @@ int ContainerFunctions::luaContainerGetItemCountById(lua_State* L) { int ContainerFunctions::luaContainerGetContentDescription(lua_State* L) { // container:getContentDescription([oldProtocol]) - Container* container = getUserdata(L, 1); + std::shared_ptr container = getUserdataShared(L, 1); if (container) { pushString(L, container->getContentDescription(getBoolean(L, 2, false))); } else { @@ -239,19 +238,19 @@ int ContainerFunctions::luaContainerGetContentDescription(lua_State* L) { int ContainerFunctions::luaContainerGetItems(lua_State* L) { // container:getItems([recursive = false]) - const Container* container = getUserdata(L, 1); + std::shared_ptr container = getUserdataShared(L, 1); if (!container) { lua_pushnil(L); return 1; } bool recursive = getBoolean(L, 2, false); - std::vector items = container->getItems(recursive); + std::vector> items = container->getItems(recursive); lua_createtable(L, static_cast(items.size()), 0); int index = 0; - for (Item* item : items) { + for (std::shared_ptr item : items) { index++; pushUserdata(L, item); setItemMetatable(L, -1, item); @@ -262,14 +261,14 @@ int ContainerFunctions::luaContainerGetItems(lua_State* L) { int ContainerFunctions::luaContainerRegisterReward(lua_State* L) { // container:registerReward() - Container* container = getUserdata(L, 1); + std::shared_ptr container = getUserdataShared(L, 1); if (!container) { lua_pushnil(L); return 1; } int64_t rewardId = getTimeMsNow(); - Item* rewardContainer = Item::CreateItem(ITEM_REWARD_CONTAINER); + std::shared_ptr rewardContainer = Item::CreateItem(ITEM_REWARD_CONTAINER); rewardContainer->setAttribute(ItemAttribute_t::DATE, rewardId); container->setAttribute(ItemAttribute_t::DATE, rewardId); container->internalAddThing(rewardContainer); diff --git a/src/lua/functions/items/item_functions.cpp b/src/lua/functions/items/item_functions.cpp index 76e5cde3120..1fb527cd07a 100644 --- a/src/lua/functions/items/item_functions.cpp +++ b/src/lua/functions/items/item_functions.cpp @@ -22,7 +22,7 @@ int ItemFunctions::luaItemCreate(lua_State* L) { // Item(uid) uint32_t id = getNumber(L, 2); - Item* item = getScriptEnv()->getItemByUID(id); + std::shared_ptr item = getScriptEnv()->getItemByUID(id); if (item) { pushUserdata(L, item); setItemMetatable(L, -1, item); @@ -34,19 +34,19 @@ int ItemFunctions::luaItemCreate(lua_State* L) { int ItemFunctions::luaItemIsItem(lua_State* L) { // item:isItem() - pushBoolean(L, getUserdata(L, 1) != nullptr); + pushBoolean(L, getUserdataShared(L, 1) != nullptr); return 1; } int ItemFunctions::luaItemGetParent(lua_State* L) { // item:getParent() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; } - Cylinder* parent = item->getParent(); + std::shared_ptr parent = item->getParent(); if (!parent) { lua_pushnil(L); return 1; @@ -58,13 +58,13 @@ int ItemFunctions::luaItemGetParent(lua_State* L) { int ItemFunctions::luaItemGetTopParent(lua_State* L) { // item:getTopParent() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; } - Cylinder* topParent = item->getTopParent(); + std::shared_ptr topParent = item->getTopParent(); if (!topParent) { lua_pushnil(L); return 1; @@ -76,7 +76,7 @@ int ItemFunctions::luaItemGetTopParent(lua_State* L) { int ItemFunctions::luaItemGetId(lua_State* L) { // item:getId() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { lua_pushnumber(L, item->getID()); } else { @@ -87,13 +87,13 @@ int ItemFunctions::luaItemGetId(lua_State* L) { int ItemFunctions::luaItemClone(lua_State* L) { // item:clone() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; } - Item* clone = item->clone(); + std::shared_ptr clone = item->clone(); if (!clone) { lua_pushnil(L); return 1; @@ -109,13 +109,13 @@ int ItemFunctions::luaItemClone(lua_State* L) { int ItemFunctions::luaItemSplit(lua_State* L) { // item:split([count = 1]) - Item** itemPtr = getRawUserdata(L, 1); + std::shared_ptr* itemPtr = getRawUserDataShared(L, 1); if (!itemPtr) { lua_pushnil(L); return 1; } - Item* item = *itemPtr; + std::shared_ptr item = *itemPtr; if (!item || !item->isStackable() || item->isRemoved()) { lua_pushnil(L); return 1; @@ -124,7 +124,7 @@ int ItemFunctions::luaItemSplit(lua_State* L) { uint16_t count = std::min(getNumber(L, 2, 1), item->getItemCount()); uint16_t diff = item->getItemCount() - count; - Item* splitItem = item->clone(); + std::shared_ptr splitItem = item->clone(); if (!splitItem) { lua_pushnil(L); return 1; @@ -135,7 +135,7 @@ int ItemFunctions::luaItemSplit(lua_State* L) { ScriptEnvironment* env = getScriptEnv(); uint32_t uid = env->addThing(item); - Item* newItem = g_game().transformItem(item, item->getID(), diff); + std::shared_ptr newItem = g_game().transformItem(item, item->getID(), diff); if (item->isRemoved()) { env->removeItemByUID(uid); } @@ -156,7 +156,7 @@ int ItemFunctions::luaItemSplit(lua_State* L) { int ItemFunctions::luaItemRemove(lua_State* L) { // item:remove([count = -1]) - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { int32_t count = getNumber(L, 2, -1); pushBoolean(L, g_game().internalRemoveItem(item, count) == RETURNVALUE_NOERROR); @@ -168,7 +168,7 @@ int ItemFunctions::luaItemRemove(lua_State* L) { int ItemFunctions::luaItemGetUniqueId(lua_State* L) { // item:getUniqueId() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { uint32_t uniqueId = item->getAttribute(ItemAttribute_t::UNIQUEID); if (uniqueId == 0) { @@ -183,7 +183,7 @@ int ItemFunctions::luaItemGetUniqueId(lua_State* L) { int ItemFunctions::luaItemGetActionId(lua_State* L) { // item:getActionId() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { auto actionId = item->getAttribute(ItemAttribute_t::ACTIONID); lua_pushnumber(L, actionId); @@ -196,7 +196,7 @@ int ItemFunctions::luaItemGetActionId(lua_State* L) { int ItemFunctions::luaItemSetActionId(lua_State* L) { // item:setActionId(actionId) uint16_t actionId = getNumber(L, 2); - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { item->setAttribute(ItemAttribute_t::ACTIONID, actionId); pushBoolean(L, true); @@ -208,7 +208,7 @@ int ItemFunctions::luaItemSetActionId(lua_State* L) { int ItemFunctions::luaItemGetCount(lua_State* L) { // item:getCount() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { lua_pushnumber(L, item->getItemCount()); } else { @@ -219,7 +219,7 @@ int ItemFunctions::luaItemGetCount(lua_State* L) { int ItemFunctions::luaItemGetCharges(lua_State* L) { // item:getCharges() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { lua_pushnumber(L, item->getCharges()); } else { @@ -230,7 +230,7 @@ int ItemFunctions::luaItemGetCharges(lua_State* L) { int ItemFunctions::luaItemGetFluidType(lua_State* L) { // item:getFluidType() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { lua_pushnumber(L, static_cast(item->getAttribute(ItemAttribute_t::FLUIDTYPE))); } else { @@ -241,7 +241,7 @@ int ItemFunctions::luaItemGetFluidType(lua_State* L) { int ItemFunctions::luaItemGetWeight(lua_State* L) { // item:getWeight() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { lua_pushnumber(L, item->getWeight()); } else { @@ -252,7 +252,7 @@ int ItemFunctions::luaItemGetWeight(lua_State* L) { int ItemFunctions::luaItemGetSubType(lua_State* L) { // item:getSubType() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { lua_pushnumber(L, item->getSubType()); } else { @@ -263,7 +263,7 @@ int ItemFunctions::luaItemGetSubType(lua_State* L) { int ItemFunctions::luaItemGetName(lua_State* L) { // item:getName() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { pushString(L, item->getName()); } else { @@ -274,7 +274,7 @@ int ItemFunctions::luaItemGetName(lua_State* L) { int ItemFunctions::luaItemGetPluralName(lua_State* L) { // item:getPluralName() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { pushString(L, item->getPluralName()); } else { @@ -285,7 +285,7 @@ int ItemFunctions::luaItemGetPluralName(lua_State* L) { int ItemFunctions::luaItemGetArticle(lua_State* L) { // item:getArticle() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { pushString(L, item->getArticle()); } else { @@ -296,7 +296,7 @@ int ItemFunctions::luaItemGetArticle(lua_State* L) { int ItemFunctions::luaItemGetPosition(lua_State* L) { // item:getPosition() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { pushPosition(L, item->getPosition()); } else { @@ -307,13 +307,13 @@ int ItemFunctions::luaItemGetPosition(lua_State* L) { int ItemFunctions::luaItemGetTile(lua_State* L) { // item:getTile() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; } - Tile* tile = item->getTile(); + std::shared_ptr tile = item->getTile(); if (tile) { pushUserdata(L, tile); setMetatable(L, -1, "Tile"); @@ -325,7 +325,7 @@ int ItemFunctions::luaItemGetTile(lua_State* L) { int ItemFunctions::luaItemHasAttribute(lua_State* L) { // item:hasAttribute(key) - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -346,7 +346,7 @@ int ItemFunctions::luaItemHasAttribute(lua_State* L) { int ItemFunctions::luaItemGetAttribute(lua_State* L) { // item:getAttribute(key) - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -378,7 +378,7 @@ int ItemFunctions::luaItemGetAttribute(lua_State* L) { int ItemFunctions::luaItemSetAttribute(lua_State* L) { // item:setAttribute(key, value) - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -437,7 +437,7 @@ int ItemFunctions::luaItemSetAttribute(lua_State* L) { int ItemFunctions::luaItemRemoveAttribute(lua_State* L) { // item:removeAttribute(key) - const Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -456,11 +456,7 @@ int ItemFunctions::luaItemRemoveAttribute(lua_State* L) { if (ret) { ret = (attribute != ItemAttribute_t::DURATION_TIMESTAMP); if (ret) { - // We will convert the item to non-const in order to use it to set values - auto noConstItem = std::bit_cast(item); - if (noConstItem) { - noConstItem->removeAttribute(attribute); - } + item->removeAttribute(attribute); } else { reportErrorFunc("Attempt to erase protected key \"duration timestamp\""); } @@ -473,7 +469,7 @@ int ItemFunctions::luaItemRemoveAttribute(lua_State* L) { int ItemFunctions::luaItemGetCustomAttribute(lua_State* L) { // item:getCustomAttribute(key) - const Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -499,7 +495,7 @@ int ItemFunctions::luaItemGetCustomAttribute(lua_State* L) { int ItemFunctions::luaItemSetCustomAttribute(lua_State* L) { // item:setCustomAttribute(key, value) - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -540,7 +536,7 @@ int ItemFunctions::luaItemSetCustomAttribute(lua_State* L) { int ItemFunctions::luaItemRemoveCustomAttribute(lua_State* L) { // item:removeCustomAttribute(key) - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -558,7 +554,7 @@ int ItemFunctions::luaItemRemoveCustomAttribute(lua_State* L) { int ItemFunctions::luaItemSerializeAttributes(lua_State* L) { // item:serializeAttributes() - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -575,30 +571,30 @@ int ItemFunctions::luaItemSerializeAttributes(lua_State* L) { int ItemFunctions::luaItemMoveTo(lua_State* L) { // item:moveTo(position or cylinder[, flags]) - Item** itemPtr = getRawUserdata(L, 1); + std::shared_ptr* itemPtr = getRawUserDataShared(L, 1); if (!itemPtr) { lua_pushnil(L); return 1; } - Item* item = *itemPtr; + std::shared_ptr item = *itemPtr; if (!item || item->isRemoved()) { lua_pushnil(L); return 1; } - Cylinder* toCylinder; + std::shared_ptr toCylinder; if (isUserdata(L, 2)) { const LuaData_t type = getUserdataType(L, 2); switch (type) { case LuaData_t::Container: - toCylinder = getUserdata(L, 2); + toCylinder = getUserdataShared(L, 2); break; case LuaData_t::Player: - toCylinder = getUserdata(L, 2); + toCylinder = getUserdataShared(L, 2); break; case LuaData_t::Tile: - toCylinder = getUserdata(L, 2); + toCylinder = getUserdataShared(L, 2); break; default: toCylinder = nullptr; @@ -623,7 +619,7 @@ int ItemFunctions::luaItemMoveTo(lua_State* L) { if (item->getParent() == VirtualCylinder::virtualCylinder) { pushBoolean(L, g_game().internalAddItem(toCylinder, item, INDEX_WHEREEVER, flags) == RETURNVALUE_NOERROR); } else { - Item* moveItem = nullptr; + std::shared_ptr moveItem = nullptr; ReturnValue ret = g_game().internalMoveItem(item->getParent(), toCylinder, INDEX_WHEREEVER, item, item->getItemCount(), &moveItem, flags); if (moveItem) { *itemPtr = moveItem; @@ -635,13 +631,13 @@ int ItemFunctions::luaItemMoveTo(lua_State* L) { int ItemFunctions::luaItemTransform(lua_State* L) { // item:transform(itemId[, count/subType = -1]) - Item** itemPtr = getRawUserdata(L, 1); + std::shared_ptr* itemPtr = getRawUserDataShared(L, 1); if (!itemPtr) { lua_pushnil(L); return 1; } - Item*&item = *itemPtr; + std::shared_ptr &item = *itemPtr; if (!item) { lua_pushnil(L); return 1; @@ -672,7 +668,7 @@ int ItemFunctions::luaItemTransform(lua_State* L) { ScriptEnvironment* env = getScriptEnv(); uint32_t uid = env->addThing(item); - Item* newItem = g_game().transformItem(item, itemId, subType); + std::shared_ptr newItem = g_game().transformItem(item, itemId, subType); if (item->isRemoved()) { env->removeItemByUID(uid); } @@ -688,7 +684,7 @@ int ItemFunctions::luaItemTransform(lua_State* L) { int ItemFunctions::luaItemDecay(lua_State* L) { // item:decay(decayId) - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { if (isNumber(L, 2)) { ItemType &it = Item::items.getItemType(item->getID()); @@ -705,13 +701,13 @@ int ItemFunctions::luaItemDecay(lua_State* L) { int ItemFunctions::luaItemMoveToSlot(lua_State* L) { // item:moveToSlot(player, slot) - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item || item->isRemoved()) { lua_pushnil(L); return 1; } - Player* player = getUserdata(L, 2); + std::shared_ptr player = getUserdataShared(L, 2); if (!player) { lua_pushnil(L); return 1; @@ -719,7 +715,7 @@ int ItemFunctions::luaItemMoveToSlot(lua_State* L) { Slots_t slot = getNumber(L, 3, CONST_SLOT_WHEREEVER); - Item* moveItem = nullptr; + std::shared_ptr moveItem = nullptr; ReturnValue ret = g_game().internalMoveItem(item->getParent(), player, slot, item, item->getItemCount(), nullptr); if (moveItem) { item = moveItem; @@ -731,7 +727,7 @@ int ItemFunctions::luaItemMoveToSlot(lua_State* L) { int ItemFunctions::luaItemGetDescription(lua_State* L) { // item:getDescription(distance) - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { int32_t distance = getNumber(L, 2); pushString(L, item->getDescription(distance)); @@ -743,7 +739,7 @@ int ItemFunctions::luaItemGetDescription(lua_State* L) { int ItemFunctions::luaItemHasProperty(lua_State* L) { // item:hasProperty(property) - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (item) { ItemProperty property = getNumber(L, 2); pushBoolean(L, item->hasProperty(property)); @@ -755,7 +751,7 @@ int ItemFunctions::luaItemHasProperty(lua_State* L) { int ItemFunctions::luaItemGetImbuement(lua_State* L) { // item:getImbuement() - const Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); pushBoolean(L, false); @@ -786,7 +782,7 @@ int ItemFunctions::luaItemGetImbuement(lua_State* L) { int ItemFunctions::luaItemGetImbuementSlot(lua_State* L) { // item:getImbuementSlot() - const Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); pushBoolean(L, false); @@ -800,7 +796,7 @@ int ItemFunctions::luaItemGetImbuementSlot(lua_State* L) { int ItemFunctions::luaItemSetDuration(lua_State* L) { // item:setDuration(minDuration, maxDuration = 0, decayTo = 0, showDuration = true) // Example: item:setDuration(10000, 20000, 2129, false) = random duration from range 10000/20000 - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); pushBoolean(L, false); @@ -837,7 +833,7 @@ int ItemFunctions::luaItemSetDuration(lua_State* L) { int ItemFunctions::luaItemIsInsideDepot(lua_State* L) { // item:isInsideDepot([includeInbox = false]) - const Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); pushBoolean(L, false); @@ -864,7 +860,7 @@ int ItemFunctions::luaItemIsContainer(lua_State* L) { int ItemFunctions::luaItemGetTier(lua_State* L) { // item:getTier() - const Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); pushBoolean(L, false); @@ -877,7 +873,7 @@ int ItemFunctions::luaItemGetTier(lua_State* L) { int ItemFunctions::luaItemSetTier(lua_State* L) { // item:setTier(tier) - Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); pushBoolean(L, false); @@ -891,7 +887,7 @@ int ItemFunctions::luaItemSetTier(lua_State* L) { int ItemFunctions::luaItemGetClassification(lua_State* L) { // item:getClassification() - const Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); pushBoolean(L, false); @@ -904,7 +900,7 @@ int ItemFunctions::luaItemGetClassification(lua_State* L) { int ItemFunctions::luaItemCanReceiveAutoCarpet(lua_State* L) { // item:canReceiveAutoCarpet() - const Item* item = getUserdata(L, 1); + std::shared_ptr item = getUserdataShared(L, 1); if (!item) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/lua_functions_loader.cpp b/src/lua/functions/lua_functions_loader.cpp index 2f1d526bcd2..944849b1e6f 100644 --- a/src/lua/functions/lua_functions_loader.cpp +++ b/src/lua/functions/lua_functions_loader.cpp @@ -145,7 +145,7 @@ void LuaFunctionsLoader::pushVariant(lua_State* L, const LuaVariant &var) { setMetatable(L, -1, "Variant"); } -void LuaFunctionsLoader::pushThing(lua_State* L, Thing* thing) { +void LuaFunctionsLoader::pushThing(lua_State* L, std::shared_ptr thing) { if (!thing) { lua_createtable(L, 0, 4); setField(L, "uid", 0); @@ -155,10 +155,10 @@ void LuaFunctionsLoader::pushThing(lua_State* L, Thing* thing) { return; } - if (Item* item = thing->getItem()) { + if (std::shared_ptr item = thing->getItem()) { pushUserdata(L, item); setItemMetatable(L, -1, item); - } else if (Creature* creature = thing->getCreature()) { + } else if (std::shared_ptr creature = thing->getCreature()) { pushUserdata(L, creature); setCreatureMetatable(L, -1, creature); } else { @@ -166,14 +166,14 @@ void LuaFunctionsLoader::pushThing(lua_State* L, Thing* thing) { } } -void LuaFunctionsLoader::pushCylinder(lua_State* L, Cylinder* cylinder) { - if (Creature* creature = cylinder->getCreature()) { +void LuaFunctionsLoader::pushCylinder(lua_State* L, std::shared_ptr cylinder) { + if (std::shared_ptr creature = cylinder->getCreature()) { pushUserdata(L, creature); setCreatureMetatable(L, -1, creature); - } else if (Item* parentItem = cylinder->getItem()) { + } else if (std::shared_ptr parentItem = cylinder->getItem()) { pushUserdata(L, parentItem); setItemMetatable(L, -1, parentItem); - } else if (Tile* tile = cylinder->getTile()) { + } else if (std::shared_ptr tile = cylinder->getTile()) { pushUserdata(L, tile); setMetatable(L, -1, "Tile"); } else if (cylinder == VirtualCylinder::virtualCylinder) { @@ -245,7 +245,7 @@ void LuaFunctionsLoader::setWeakMetatable(lua_State* L, int32_t index, const std lua_setmetatable(L, index - 1); } -void LuaFunctionsLoader::setItemMetatable(lua_State* L, int32_t index, const Item* item) { +void LuaFunctionsLoader::setItemMetatable(lua_State* L, int32_t index, std::shared_ptr item) { if (item && item->getContainer()) { luaL_getmetatable(L, "Container"); } else if (item && item->getTeleport()) { @@ -256,7 +256,7 @@ void LuaFunctionsLoader::setItemMetatable(lua_State* L, int32_t index, const Ite lua_setmetatable(L, index - 1); } -void LuaFunctionsLoader::setCreatureMetatable(lua_State* L, int32_t index, const Creature* creature) { +void LuaFunctionsLoader::setCreatureMetatable(lua_State* L, int32_t index, std::shared_ptr creature) { if (creature && creature->getPlayer()) { luaL_getmetatable(L, "Player"); } else if (creature && creature->getMonster()) { @@ -406,28 +406,28 @@ LuaVariant LuaFunctionsLoader::getVariant(lua_State* L, int32_t arg) { return var; } -Thing* LuaFunctionsLoader::getThing(lua_State* L, int32_t arg) { - Thing* thing; +std::shared_ptr LuaFunctionsLoader::getThing(lua_State* L, int32_t arg) { + std::shared_ptr thing; if (lua_getmetatable(L, arg) != 0) { lua_rawgeti(L, -1, 't'); switch (getNumber(L, -1)) { case LuaData_t::Item: - thing = getUserdata(L, arg); + thing = getUserdataShared(L, arg); break; case LuaData_t::Container: - thing = getUserdata(L, arg); + thing = getUserdataShared(L, arg); break; case LuaData_t::Teleport: - thing = getUserdata(L, arg); + thing = getUserdataShared(L, arg); break; case LuaData_t::Player: - thing = getUserdata(L, arg); + thing = getUserdataShared(L, arg); break; case LuaData_t::Monster: - thing = getUserdata(L, arg); + thing = getUserdataShared(L, arg); break; case LuaData_t::Npc: - thing = getUserdata(L, arg); + thing = getUserdataShared(L, arg); break; default: thing = nullptr; @@ -440,16 +440,16 @@ Thing* LuaFunctionsLoader::getThing(lua_State* L, int32_t arg) { return thing; } -Creature* LuaFunctionsLoader::getCreature(lua_State* L, int32_t arg) { +std::shared_ptr LuaFunctionsLoader::getCreature(lua_State* L, int32_t arg) { if (isUserdata(L, arg)) { - return getUserdata(L, arg); + return getUserdataShared(L, arg); } return g_game().getCreatureByID(getNumber(L, arg)); } -Player* LuaFunctionsLoader::getPlayer(lua_State* L, int32_t arg, bool allowOffline /* = false */) { +std::shared_ptr LuaFunctionsLoader::getPlayer(lua_State* L, int32_t arg, bool allowOffline /* = false */) { if (isUserdata(L, arg)) { - return getUserdata(L, arg); + return getUserdataShared(L, arg); } else if (isNumber(L, arg)) { return g_game().getPlayerByID(getNumber(L, arg), allowOffline); } else if (isString(L, arg)) { diff --git a/src/lua/functions/lua_functions_loader.hpp b/src/lua/functions/lua_functions_loader.hpp index 3eca065cd36..d4d312247a0 100644 --- a/src/lua/functions/lua_functions_loader.hpp +++ b/src/lua/functions/lua_functions_loader.hpp @@ -37,11 +37,11 @@ class LuaFunctionsLoader { static void reportError(const char* function, const std::string &error_desc, bool stack_trace = false); static int luaErrorHandler(lua_State* L); - static void pushThing(lua_State* L, Thing* thing); + static void pushThing(lua_State* L, std::shared_ptr thing); static void pushVariant(lua_State* L, const LuaVariant &var); static void pushString(lua_State* L, const std::string &value); static void pushCallback(lua_State* L, int32_t callback); - static void pushCylinder(lua_State* L, Cylinder* cylinder); + static void pushCylinder(lua_State* L, std::shared_ptr cylinder); static std::string popString(lua_State* L); static int32_t popCallback(lua_State* L); @@ -54,8 +54,8 @@ class LuaFunctionsLoader { static void setMetatable(lua_State* L, int32_t index, const std::string &name); static void setWeakMetatable(lua_State* L, int32_t index, const std::string &name); - static void setItemMetatable(lua_State* L, int32_t index, const Item* item); - static void setCreatureMetatable(lua_State* L, int32_t index, const Creature* creature); + static void setItemMetatable(lua_State* L, int32_t index, std::shared_ptr item); + static void setCreatureMetatable(lua_State* L, int32_t index, std::shared_ptr creature); template static typename std::enable_if::value, T>::type @@ -107,9 +107,9 @@ class LuaFunctionsLoader { static Outfit_t getOutfit(lua_State* L, int32_t arg); static LuaVariant getVariant(lua_State* L, int32_t arg); - static Thing* getThing(lua_State* L, int32_t arg); - static Creature* getCreature(lua_State* L, int32_t arg); - static Player* getPlayer(lua_State* L, int32_t arg, bool allowOffline = false); + static std::shared_ptr getThing(lua_State* L, int32_t arg); + static std::shared_ptr getCreature(lua_State* L, int32_t arg); + static std::shared_ptr getPlayer(lua_State* L, int32_t arg, bool allowOffline = false); static std::shared_ptr getGuild(lua_State* L, int32_t arg, bool allowOffline = false); template diff --git a/src/lua/functions/map/house_functions.cpp b/src/lua/functions/map/house_functions.cpp index 72129001ca5..18c4d66b0fa 100644 --- a/src/lua/functions/map/house_functions.cpp +++ b/src/lua/functions/map/house_functions.cpp @@ -131,8 +131,8 @@ int HouseFunctions::luaHouseSetOwnerGuid(lua_State* L) { int HouseFunctions::luaHouseStartTrade(lua_State* L) { // house:startTrade(player, tradePartner) House* house = getUserdata(L, 1); - Player* player = getUserdata(L, 2); - Player* tradePartner = getUserdata(L, 3); + std::shared_ptr player = getUserdataShared(L, 2); + std::shared_ptr tradePartner = getUserdataShared(L, 3); if (!player || !tradePartner || !house) { lua_pushnil(L); @@ -159,7 +159,7 @@ int HouseFunctions::luaHouseStartTrade(lua_State* L) { return 1; } - Item* transferItem = house->getTransferItem(); + std::shared_ptr transferItem = house->getTransferItem(); if (!transferItem) { lua_pushnumber(L, RETURNVALUE_YOUCANNOTTRADETHISHOUSE); return 1; @@ -186,7 +186,7 @@ int HouseFunctions::luaHouseGetBeds(lua_State* L) { lua_createtable(L, beds.size(), 0); int index = 0; - for (BedItem* bedItem : beds) { + for (std::shared_ptr bedItem : beds) { pushUserdata(L, bedItem); setItemMetatable(L, -1, bedItem); lua_rawseti(L, -2, ++index); @@ -217,7 +217,7 @@ int HouseFunctions::luaHouseGetDoors(lua_State* L) { lua_createtable(L, doors.size(), 0); int index = 0; - for (Door* door : doors) { + for (std::shared_ptr door : doors) { pushUserdata(L, door); setItemMetatable(L, -1, door); lua_rawseti(L, -2, ++index); @@ -244,7 +244,7 @@ int HouseFunctions::luaHouseGetDoorIdByPosition(lua_State* L) { return 1; } - Door* door = house->getDoorByPosition(getPosition(L, 2)); + std::shared_ptr door = house->getDoorByPosition(getPosition(L, 2)); if (door) { lua_pushnumber(L, door->getDoorId()); } else { @@ -265,7 +265,7 @@ int HouseFunctions::luaHouseGetTiles(lua_State* L) { lua_newtable(L); int index = 0; - for (Tile* tile : tiles) { + for (std::shared_ptr tile : tiles) { pushUserdata(L, tile); setMetatable(L, -1, "Tile"); lua_rawseti(L, -2, ++index); @@ -285,10 +285,10 @@ int HouseFunctions::luaHouseGetItems(lua_State* L) { lua_newtable(L); int index = 0; - for (Tile* tile : tiles) { + for (std::shared_ptr tile : tiles) { TileItemVector* itemVector = tile->getItemList(); if (itemVector) { - for (Item* item : *itemVector) { + for (auto &item : *itemVector) { pushUserdata(L, item); setItemMetatable(L, -1, item); lua_rawseti(L, -2, ++index); @@ -318,7 +318,7 @@ int HouseFunctions::luaHouseCanEditAccessList(lua_State* L) { } uint32_t listId = getNumber(L, 2); - Player* player = getPlayer(L, 3); + std::shared_ptr player = getPlayer(L, 3); pushBoolean(L, house->canEditAccessList(listId, player)); return 1; @@ -377,7 +377,7 @@ int HouseFunctions::luaHouseIsInvited(lua_State* L) { return 1; } - Player* player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); if (!player) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/map/position_functions.cpp b/src/lua/functions/map/position_functions.cpp index 7636e87d7a2..ba0633a819e 100644 --- a/src/lua/functions/map/position_functions.cpp +++ b/src/lua/functions/map/position_functions.cpp @@ -149,7 +149,7 @@ int PositionFunctions::luaPositionSendMagicEffect(lua_State* L) { // position:sendMagicEffect(magicEffect[, player = nullptr]) SpectatorHashSet spectators; if (lua_gettop(L) >= 3) { - Player* player = getPlayer(L, 3); + std::shared_ptr player = getPlayer(L, 3); if (player) { spectators.insert(player); } @@ -177,7 +177,7 @@ int PositionFunctions::luaPositionRemoveMagicEffect(lua_State* L) { // position:removeMagicEffect(magicEffect[, player = nullptr]) SpectatorHashSet spectators; if (lua_gettop(L) >= 3) { - Player* player = getPlayer(L, 3); + std::shared_ptr player = getPlayer(L, 3); if (player) { spectators.insert(player); } @@ -205,7 +205,7 @@ int PositionFunctions::luaPositionSendDistanceEffect(lua_State* L) { // position:sendDistanceEffect(positionEx, distanceEffect[, player = nullptr]) SpectatorHashSet spectators; if (lua_gettop(L) >= 4) { - Player* player = getPlayer(L, 4); + std::shared_ptr player = getPlayer(L, 4); if (player) { spectators.insert(player); } @@ -233,7 +233,7 @@ int PositionFunctions::luaPositionSendSingleSoundEffect(lua_State* L) { // position:sendSingleSoundEffect(soundId[, actor = nullptr]) const Position &position = getPosition(L, 1); SoundEffect_t soundEffect = getNumber(L, 2); - Creature* actor = getCreature(L, 3); + std::shared_ptr actor = getCreature(L, 3); g_game().sendSingleSoundEffect(position, soundEffect, actor); pushBoolean(L, true); @@ -245,7 +245,7 @@ int PositionFunctions::luaPositionSendDoubleSoundEffect(lua_State* L) { const Position &position = getPosition(L, 1); SoundEffect_t mainSoundEffect = getNumber(L, 2); SoundEffect_t secondarySoundEffect = getNumber(L, 3); - Creature* actor = getCreature(L, 4); + std::shared_ptr actor = getCreature(L, 4); g_game().sendDoubleSoundEffect(position, mainSoundEffect, secondarySoundEffect, actor); pushBoolean(L, true); diff --git a/src/lua/functions/map/teleport_functions.cpp b/src/lua/functions/map/teleport_functions.cpp index edb93a4dc9c..05a4b408f61 100644 --- a/src/lua/functions/map/teleport_functions.cpp +++ b/src/lua/functions/map/teleport_functions.cpp @@ -18,7 +18,7 @@ int TeleportFunctions::luaTeleportCreate(lua_State* L) { // Teleport(uid) uint32_t id = getNumber(L, 2); - Item* item = getScriptEnv()->getItemByUID(id); + std::shared_ptr item = getScriptEnv()->getItemByUID(id); if (item && item->getTeleport()) { pushUserdata(L, item); setMetatable(L, -1, "Teleport"); @@ -30,7 +30,7 @@ int TeleportFunctions::luaTeleportCreate(lua_State* L) { int TeleportFunctions::luaTeleportGetDestination(lua_State* L) { // teleport:getDestination() - Teleport* teleport = getUserdata(L, 1); + std::shared_ptr teleport = getUserdataShared(L, 1); if (teleport) { pushPosition(L, teleport->getDestPos()); } else { @@ -41,7 +41,7 @@ int TeleportFunctions::luaTeleportGetDestination(lua_State* L) { int TeleportFunctions::luaTeleportSetDestination(lua_State* L) { // teleport:setDestination(position) - Teleport* teleport = getUserdata(L, 1); + std::shared_ptr teleport = getUserdataShared(L, 1); if (teleport) { teleport->setDestPos(getPosition(L, 2)); pushBoolean(L, true); diff --git a/src/lua/functions/map/tile_functions.cpp b/src/lua/functions/map/tile_functions.cpp index 625b9ffe6d4..1081014ab57 100644 --- a/src/lua/functions/map/tile_functions.cpp +++ b/src/lua/functions/map/tile_functions.cpp @@ -15,7 +15,7 @@ int TileFunctions::luaTileCreate(lua_State* L) { // Tile(x, y, z) // Tile(position) - Tile* tile; + std::shared_ptr tile; if (isTable(L, 2)) { tile = g_game().map.getTile(getPosition(L, 2)); } else { @@ -36,7 +36,7 @@ int TileFunctions::luaTileCreate(lua_State* L) { int TileFunctions::luaTileGetPosition(lua_State* L) { // tile:getPosition() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (tile) { pushPosition(L, tile->getPosition()); } else { @@ -47,7 +47,7 @@ int TileFunctions::luaTileGetPosition(lua_State* L) { int TileFunctions::luaTileGetGround(lua_State* L) { // tile:getGround() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (tile && tile->getGround()) { pushUserdata(L, tile->getGround()); setItemMetatable(L, -1, tile->getGround()); @@ -60,22 +60,22 @@ int TileFunctions::luaTileGetGround(lua_State* L) { int TileFunctions::luaTileGetThing(lua_State* L) { // tile:getThing(index) int32_t index = getNumber(L, 2); - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - Thing* thing = tile->getThing(index); + std::shared_ptr thing = tile->getThing(index); if (!thing) { lua_pushnil(L); return 1; } - if (Creature* creature = thing->getCreature()) { + if (std::shared_ptr creature = thing->getCreature()) { pushUserdata(L, creature); setCreatureMetatable(L, -1, creature); - } else if (Item* item = thing->getItem()) { + } else if (std::shared_ptr item = thing->getItem()) { pushUserdata(L, item); setItemMetatable(L, -1, item); } else { @@ -86,7 +86,7 @@ int TileFunctions::luaTileGetThing(lua_State* L) { int TileFunctions::luaTileGetThingCount(lua_State* L) { // tile:getThingCount() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (tile) { lua_pushnumber(L, tile->getThingCount()); } else { @@ -97,23 +97,23 @@ int TileFunctions::luaTileGetThingCount(lua_State* L) { int TileFunctions::luaTileGetTopVisibleThing(lua_State* L) { // tile:getTopVisibleThing(creature) - Creature* creature = getCreature(L, 2); - Tile* tile = getUserdata(L, 1); + std::shared_ptr creature = getCreature(L, 2); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - Thing* thing = tile->getTopVisibleThing(creature); + std::shared_ptr thing = tile->getTopVisibleThing(creature); if (!thing) { lua_pushnil(L); return 1; } - if (Creature* visibleCreature = thing->getCreature()) { + if (std::shared_ptr visibleCreature = thing->getCreature()) { pushUserdata(L, visibleCreature); setCreatureMetatable(L, -1, visibleCreature); - } else if (Item* visibleItem = thing->getItem()) { + } else if (std::shared_ptr visibleItem = thing->getItem()) { pushUserdata(L, visibleItem); setItemMetatable(L, -1, visibleItem); } else { @@ -124,13 +124,13 @@ int TileFunctions::luaTileGetTopVisibleThing(lua_State* L) { int TileFunctions::luaTileGetTopTopItem(lua_State* L) { // tile:getTopTopItem() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - Item* item = tile->getTopTopItem(); + std::shared_ptr item = tile->getTopTopItem(); if (item) { pushUserdata(L, item); setItemMetatable(L, -1, item); @@ -142,13 +142,13 @@ int TileFunctions::luaTileGetTopTopItem(lua_State* L) { int TileFunctions::luaTileGetTopDownItem(lua_State* L) { // tile:getTopDownItem() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - Item* item = tile->getTopDownItem(); + std::shared_ptr item = tile->getTopDownItem(); if (item) { pushUserdata(L, item); setItemMetatable(L, -1, item); @@ -160,13 +160,13 @@ int TileFunctions::luaTileGetTopDownItem(lua_State* L) { int TileFunctions::luaTileGetFieldItem(lua_State* L) { // tile:getFieldItem() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - Item* item = tile->getFieldItem(); + std::shared_ptr item = tile->getFieldItem(); if (item) { pushUserdata(L, item); setItemMetatable(L, -1, item); @@ -178,7 +178,7 @@ int TileFunctions::luaTileGetFieldItem(lua_State* L) { int TileFunctions::luaTileGetItemById(lua_State* L) { // tile:getItemById(itemId[, subType = -1]) - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -196,7 +196,7 @@ int TileFunctions::luaTileGetItemById(lua_State* L) { } int32_t subType = getNumber(L, 3, -1); - Item* item = g_game().findItemOfType(tile, itemId, false, subType); + std::shared_ptr item = g_game().findItemOfType(tile, itemId, false, subType); if (item) { pushUserdata(L, item); setItemMetatable(L, -1, item); @@ -208,7 +208,7 @@ int TileFunctions::luaTileGetItemById(lua_State* L) { int TileFunctions::luaTileGetItemByType(lua_State* L) { // tile:getItemByType(itemType) - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -246,7 +246,7 @@ int TileFunctions::luaTileGetItemByType(lua_State* L) { return 1; } - if (Item* item = tile->getGround()) { + if (std::shared_ptr item = tile->getGround()) { const ItemType &it = Item::items[item->getID()]; if (it.type == itemType) { pushUserdata(L, item); @@ -256,7 +256,7 @@ int TileFunctions::luaTileGetItemByType(lua_State* L) { } if (const TileItemVector* items = tile->getItemList()) { - for (Item* item : *items) { + for (auto &item : *items) { const ItemType &it = Item::items[item->getID()]; if (it.type == itemType) { pushUserdata(L, item); @@ -272,7 +272,7 @@ int TileFunctions::luaTileGetItemByType(lua_State* L) { int TileFunctions::luaTileGetItemByTopOrder(lua_State* L) { // tile:getItemByTopOrder(topOrder) - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -280,7 +280,7 @@ int TileFunctions::luaTileGetItemByTopOrder(lua_State* L) { int32_t topOrder = getNumber(L, 2); - Item* item = tile->getItemByTopOrder(topOrder); + std::shared_ptr item = tile->getItemByTopOrder(topOrder); if (!item) { lua_pushnil(L); return 1; @@ -293,7 +293,7 @@ int TileFunctions::luaTileGetItemByTopOrder(lua_State* L) { int TileFunctions::luaTileGetItemCountById(lua_State* L) { // tile:getItemCountById(itemId[, subType = -1]) - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -318,13 +318,13 @@ int TileFunctions::luaTileGetItemCountById(lua_State* L) { int TileFunctions::luaTileGetBottomCreature(lua_State* L) { // tile:getBottomCreature() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - const Creature* creature = tile->getBottomCreature(); + std::shared_ptr creature = tile->getBottomCreature(); if (!creature) { lua_pushnil(L); return 1; @@ -337,13 +337,13 @@ int TileFunctions::luaTileGetBottomCreature(lua_State* L) { int TileFunctions::luaTileGetTopCreature(lua_State* L) { // tile:getTopCreature() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - Creature* creature = tile->getTopCreature(); + std::shared_ptr creature = tile->getTopCreature(); if (!creature) { lua_pushnil(L); return 1; @@ -356,19 +356,19 @@ int TileFunctions::luaTileGetTopCreature(lua_State* L) { int TileFunctions::luaTileGetBottomVisibleCreature(lua_State* L) { // tile:getBottomVisibleCreature(creature) - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - Creature* creature = getCreature(L, 2); + std::shared_ptr creature = getCreature(L, 2); if (!creature) { lua_pushnil(L); return 1; } - const Creature* visibleCreature = tile->getBottomVisibleCreature(creature); + std::shared_ptr visibleCreature = tile->getBottomVisibleCreature(creature); if (visibleCreature) { pushUserdata(L, visibleCreature); setCreatureMetatable(L, -1, visibleCreature); @@ -380,19 +380,19 @@ int TileFunctions::luaTileGetBottomVisibleCreature(lua_State* L) { int TileFunctions::luaTileGetTopVisibleCreature(lua_State* L) { // tile:getTopVisibleCreature(creature) - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - Creature* creature = getCreature(L, 2); + std::shared_ptr creature = getCreature(L, 2); if (!creature) { lua_pushnil(L); return 1; } - Creature* visibleCreature = tile->getTopVisibleCreature(creature); + std::shared_ptr visibleCreature = tile->getTopVisibleCreature(creature); if (visibleCreature) { pushUserdata(L, visibleCreature); setCreatureMetatable(L, -1, visibleCreature); @@ -404,7 +404,7 @@ int TileFunctions::luaTileGetTopVisibleCreature(lua_State* L) { int TileFunctions::luaTileGetItems(lua_State* L) { // tile:getItems() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -419,7 +419,7 @@ int TileFunctions::luaTileGetItems(lua_State* L) { lua_createtable(L, itemVector->size(), 0); int index = 0; - for (Item* item : *itemVector) { + for (auto &item : *itemVector) { pushUserdata(L, item); setItemMetatable(L, -1, item); lua_rawseti(L, -2, ++index); @@ -429,7 +429,7 @@ int TileFunctions::luaTileGetItems(lua_State* L) { int TileFunctions::luaTileGetItemCount(lua_State* L) { // tile:getItemCount() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -441,7 +441,7 @@ int TileFunctions::luaTileGetItemCount(lua_State* L) { int TileFunctions::luaTileGetDownItemCount(lua_State* L) { // tile:getDownItemCount() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (tile) { lua_pushnumber(L, tile->getDownItemCount()); } else { @@ -452,7 +452,7 @@ int TileFunctions::luaTileGetDownItemCount(lua_State* L) { int TileFunctions::luaTileGetTopItemCount(lua_State* L) { // tile:getTopItemCount() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -464,7 +464,7 @@ int TileFunctions::luaTileGetTopItemCount(lua_State* L) { int TileFunctions::luaTileGetCreatures(lua_State* L) { // tile:getCreatures() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -479,7 +479,7 @@ int TileFunctions::luaTileGetCreatures(lua_State* L) { lua_createtable(L, creatureVector->size(), 0); int index = 0; - for (Creature* creature : *creatureVector) { + for (auto &creature : *creatureVector) { pushUserdata(L, creature); setCreatureMetatable(L, -1, creature); lua_rawseti(L, -2, ++index); @@ -489,7 +489,7 @@ int TileFunctions::luaTileGetCreatures(lua_State* L) { int TileFunctions::luaTileGetCreatureCount(lua_State* L) { // tile:getCreatureCount() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -501,15 +501,15 @@ int TileFunctions::luaTileGetCreatureCount(lua_State* L) { int TileFunctions::luaTileHasProperty(lua_State* L) { // tile:hasProperty(property[, item]) - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - Item* item; + std::shared_ptr item; if (lua_gettop(L) >= 3) { - item = getUserdata(L, 3); + item = getUserdataShared(L, 3); } else { item = nullptr; } @@ -525,13 +525,13 @@ int TileFunctions::luaTileHasProperty(lua_State* L) { int TileFunctions::luaTileGetThingIndex(lua_State* L) { // tile:getThingIndex(thing) - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - Thing* thing = getThing(L, 2); + std::shared_ptr thing = getThing(L, 2); if (thing) { lua_pushnumber(L, tile->getThingIndex(thing)); } else { @@ -542,7 +542,7 @@ int TileFunctions::luaTileGetThingIndex(lua_State* L) { int TileFunctions::luaTileHasFlag(lua_State* L) { // tile:hasFlag(flag) - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (tile) { TileFlags_t flag = getNumber(L, 2); pushBoolean(L, tile->hasFlag(flag)); @@ -554,16 +554,16 @@ int TileFunctions::luaTileHasFlag(lua_State* L) { int TileFunctions::luaTileQueryAdd(lua_State* L) { // tile:queryAdd(thing[, flags]) - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - Thing* thing = getThing(L, 2); + std::shared_ptr thing = getThing(L, 2); if (thing) { uint32_t flags = getNumber(L, 3, 0); - lua_pushnumber(L, tile->queryAdd(0, *thing, 1, flags)); + lua_pushnumber(L, tile->queryAdd(0, thing, 1, flags)); } else { lua_pushnil(L); } @@ -572,7 +572,7 @@ int TileFunctions::luaTileQueryAdd(lua_State* L) { int TileFunctions::luaTileAddItem(lua_State* L) { // tile:addItem(itemId[, count/subType = 1[, flags = 0]]) - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -591,7 +591,7 @@ int TileFunctions::luaTileAddItem(lua_State* L) { uint32_t subType = getNumber(L, 3, 1); - Item* item = Item::CreateItem(itemId, std::min(subType, Item::items[itemId].stackSize)); + std::shared_ptr item = Item::CreateItem(itemId, std::min(subType, Item::items[itemId].stackSize)); if (!item) { lua_pushnil(L); return 1; @@ -604,7 +604,7 @@ int TileFunctions::luaTileAddItem(lua_State* L) { pushUserdata(L, item); setItemMetatable(L, -1, item); } else { - delete item; + lua_pushnil(L); } return 1; @@ -612,13 +612,13 @@ int TileFunctions::luaTileAddItem(lua_State* L) { int TileFunctions::luaTileAddItemEx(lua_State* L) { // tile:addItemEx(item[, flags = 0]) - Item* item = getUserdata(L, 2); + std::shared_ptr item = getUserdataShared(L, 2); if (!item) { lua_pushnil(L); return 1; } - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -641,13 +641,13 @@ int TileFunctions::luaTileAddItemEx(lua_State* L) { int TileFunctions::luaTileGetHouse(lua_State* L) { // tile:getHouse() - Tile* tile = getUserdata(L, 1); + std::shared_ptr tile = getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - if (HouseTile* houseTile = dynamic_cast(tile)) { + if (std::shared_ptr houseTile = std::dynamic_pointer_cast(tile)) { pushUserdata(L, houseTile->getHouse()); setMetatable(L, -1, "House"); } else { diff --git a/src/lua/modules/modules.cpp b/src/lua/modules/modules.cpp index 402095bb4eb..18d1107ff76 100644 --- a/src/lua/modules/modules.cpp +++ b/src/lua/modules/modules.cpp @@ -78,7 +78,7 @@ Module* Modules::getEventByRecvbyte(uint8_t recvbyte, bool force) { } void Modules::executeOnRecvbyte(uint32_t playerId, NetworkMessage &msg, uint8_t byte) const { - Player* player = g_game().getPlayerByID(playerId); + std::shared_ptr player = g_game().getPlayerByID(playerId); if (!player) { return; } @@ -152,7 +152,7 @@ void Module::clearEvent() { loaded = false; } -void Module::executeOnRecvbyte(Player* player, NetworkMessage &msg) { +void Module::executeOnRecvbyte(std::shared_ptr player, NetworkMessage &msg) { // onRecvbyte(player, msg, recvbyte) if (!scriptInterface->reserveScriptEnv()) { g_logger().error("Call stack overflow. Too many lua script calls being nested {}", player->getName()); diff --git a/src/lua/modules/modules.hpp b/src/lua/modules/modules.hpp index 222c88826ad..f72baf94fe1 100644 --- a/src/lua/modules/modules.hpp +++ b/src/lua/modules/modules.hpp @@ -35,7 +35,7 @@ class Module final : public Event { void copyEvent(Module* creatureEvent); // scripting - void executeOnRecvbyte(Player* player, NetworkMessage &msg); + void executeOnRecvbyte(std::shared_ptr player, NetworkMessage &msg); // uint8_t getRecvbyte() { diff --git a/src/lua/scripts/lua_environment.cpp b/src/lua/scripts/lua_environment.cpp index 605e7d86419..af41513be61 100644 --- a/src/lua/scripts/lua_environment.cpp +++ b/src/lua/scripts/lua_environment.cpp @@ -21,7 +21,6 @@ LuaEnvironment::LuaEnvironment() : LuaEnvironment::~LuaEnvironment() { if (!testInterface) { - delete testInterface; } LuaEnvironment::shuttingDown = true; diff --git a/src/lua/scripts/luascript.cpp b/src/lua/scripts/luascript.cpp index 469805e8abd..d7d12dfe238 100644 --- a/src/lua/scripts/luascript.cpp +++ b/src/lua/scripts/luascript.cpp @@ -14,7 +14,7 @@ ScriptEnvironment::DBResultMap ScriptEnvironment::tempResults; uint32_t ScriptEnvironment::lastResultId = 0; -std::multimap ScriptEnvironment::tempItems; +std::multimap> ScriptEnvironment::tempItems; ScriptEnvironment LuaFunctionsLoader::scriptEnv[16]; int32_t LuaFunctionsLoader::scriptEnvIndex = -1; diff --git a/src/lua/scripts/script_environment.cpp b/src/lua/scripts/script_environment.cpp index 50718cd8444..aa257d433c3 100644 --- a/src/lua/scripts/script_environment.cpp +++ b/src/lua/scripts/script_environment.cpp @@ -33,7 +33,7 @@ void ScriptEnvironment::resetEnv() { auto pair = tempItems.equal_range(this); auto it = pair.first; while (it != pair.second) { - Item* item = it->second; + std::shared_ptr item = it->second; if (item->getParent() == VirtualCylinder::virtualCylinder) { g_game().ReleaseItem(item); } @@ -62,17 +62,17 @@ void ScriptEnvironment::getEventInfo(int32_t &retScriptId, LuaScriptInterface*&r retTimerEvent = this->timerEvent; } -uint32_t ScriptEnvironment::addThing(Thing* thing) { +uint32_t ScriptEnvironment::addThing(std::shared_ptr thing) { if (!thing || thing->isRemoved()) { return 0; } - Creature* creature = thing->getCreature(); + std::shared_ptr creature = thing->getCreature(); if (creature) { return creature->getID(); } - Item* item = thing->getItem(); + std::shared_ptr item = thing->getItem(); if (item && item->hasAttribute(ItemAttribute_t::UNIQUEID)) { return item->getAttribute(ItemAttribute_t::UNIQUEID); } @@ -87,20 +87,20 @@ uint32_t ScriptEnvironment::addThing(Thing* thing) { return lastUID; } -void ScriptEnvironment::insertItem(uint32_t uid, Item* item) { +void ScriptEnvironment::insertItem(uint32_t uid, std::shared_ptr item) { auto result = localMap.emplace(uid, item); if (!result.second) { g_logger().error("Thing uid already taken: {}", uid); } } -Thing* ScriptEnvironment::getThingByUID(uint32_t uid) { +std::shared_ptr ScriptEnvironment::getThingByUID(uint32_t uid) { if (uid >= 0x10000000) { return g_game().getCreatureByID(uid); } if (uid <= std::numeric_limits::max()) { - Item* item = g_game().getUniqueItem(static_cast(uid)); + std::shared_ptr item = g_game().getUniqueItem(static_cast(uid)); if (item && !item->isRemoved()) { return item; } @@ -109,7 +109,7 @@ Thing* ScriptEnvironment::getThingByUID(uint32_t uid) { auto it = localMap.find(uid); if (it != localMap.end()) { - Item* item = it->second; + std::shared_ptr item = it->second; if (!item->isRemoved()) { return item; } @@ -117,16 +117,16 @@ Thing* ScriptEnvironment::getThingByUID(uint32_t uid) { return nullptr; } -Item* ScriptEnvironment::getItemByUID(uint32_t uid) { - Thing* thing = getThingByUID(uid); +std::shared_ptr ScriptEnvironment::getItemByUID(uint32_t uid) { + std::shared_ptr thing = getThingByUID(uid); if (!thing) { return nullptr; } return thing->getItem(); } -Container* ScriptEnvironment::getContainerByUID(uint32_t uid) { - Item* item = getItemByUID(uid); +std::shared_ptr ScriptEnvironment::getContainerByUID(uint32_t uid) { + std::shared_ptr item = getItemByUID(uid); if (!item) { return nullptr; } @@ -145,11 +145,11 @@ void ScriptEnvironment::removeItemByUID(uint32_t uid) { } } -void ScriptEnvironment::addTempItem(Item* item) { +void ScriptEnvironment::addTempItem(std::shared_ptr item) { tempItems.emplace(this, item); } -void ScriptEnvironment::removeTempItem(Item* item) { +void ScriptEnvironment::removeTempItem(std::shared_ptr item) { for (auto it = tempItems.begin(), end = tempItems.end(); it != end; ++it) { if (it->second == item) { tempItems.erase(it); diff --git a/src/lua/scripts/script_environment.hpp b/src/lua/scripts/script_environment.hpp index ac3fedf9c3f..4c219b0a0ef 100644 --- a/src/lua/scripts/script_environment.hpp +++ b/src/lua/scripts/script_environment.hpp @@ -52,25 +52,25 @@ class ScriptEnvironment { void getEventInfo(int32_t &scriptId, LuaScriptInterface*&scriptInterface, int32_t &callbackId, bool &timerEvent) const; - void addTempItem(Item* item); - static void removeTempItem(Item* item); - uint32_t addThing(Thing* thing); - void insertItem(uint32_t uid, Item* item); + void addTempItem(std::shared_ptr item); + static void removeTempItem(std::shared_ptr item); + uint32_t addThing(std::shared_ptr thing); + void insertItem(uint32_t uid, std::shared_ptr item); static DBResult_ptr getResultByID(uint32_t id); static uint32_t addResult(DBResult_ptr res); static bool removeResult(uint32_t id); - void setNpc(Npc* npc) { + void setNpc(std::shared_ptr npc) { curNpc = npc; } - Npc* getNpc() const { + std::shared_ptr getNpc() const { return curNpc; } - Thing* getThingByUID(uint32_t uid); - Item* getItemByUID(uint32_t uid); - Container* getContainerByUID(uint32_t uid); + std::shared_ptr getThingByUID(uint32_t uid); + std::shared_ptr getItemByUID(uint32_t uid); + std::shared_ptr getContainerByUID(uint32_t uid); void removeItemByUID(uint32_t uid); private: @@ -81,13 +81,13 @@ class ScriptEnvironment { LuaScriptInterface* interface; // for npc scripts - Npc* curNpc = nullptr; + std::shared_ptr curNpc = nullptr; // temporary item list - static std::multimap tempItems; + static std::multimap> tempItems; // local item map - phmap::flat_hash_map localMap; + phmap::flat_hash_map> localMap; uint32_t lastUID = std::numeric_limits::max(); // script file id diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index 87ab09c857c..2509f5164d2 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -18,13 +18,13 @@ House::House(uint32_t houseId) : id(houseId) { } -void House::addTile(HouseTile* tile) { +void House::addTile(std::shared_ptr tile) { tile->setFlag(TILESTATE_PROTECTIONZONE); houseTiles.push_back(tile); updateDoorDescription(); } -void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, Player* player /* = nullptr*/) { +void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, std::shared_ptr player /* = nullptr*/) { if (updateDatabase && owner != guid) { Database &db = Database::getInstance(); @@ -47,7 +47,7 @@ void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, Player* pla transferToDepot(); } - for (HouseTile* tile : houseTiles) { + for (std::shared_ptr tile : houseTiles) { if (const CreatureVector* creatures = tile->getCreatures()) { for (int32_t i = creatures->size(); --i >= 0;) { kickPlayer(nullptr, (*creatures)[i]->getPlayer()); @@ -56,7 +56,7 @@ void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, Player* pla } // Remove players from beds - for (BedItem* bed : bedsList) { + for (std::shared_ptr bed : bedsList) { if (bed->getSleeper() != 0) { bed->wakeUp(nullptr); } @@ -68,7 +68,7 @@ void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, Player* pla setAccessList(SUBOWNER_LIST, ""); setAccessList(GUEST_LIST, ""); - for (Door* door : doorList) { + for (std::shared_ptr door : doorList) { door->setAccessList(""); } } else { @@ -114,9 +114,9 @@ void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, Player* pla void House::updateDoorDescription() const { std::ostringstream ss; if (owner != 0) { - ss << "It belongs to house '" << houseName << "'. " << ownerName << " owns this house."; + ss << "It belongs to house '" << houseName << "'. " << ownerName << " owns static_self_cast() house."; } else { - ss << "It belongs to house '" << houseName << "'. Nobody owns this house."; + ss << "It belongs to house '" << houseName << "'. Nobody owns static_self_cast() house."; } ss << " It is " << getSize() << " square meters."; @@ -136,7 +136,7 @@ void House::updateDoorDescription() const { } } -AccessHouseLevel_t House::getHouseAccessLevel(const Player* player) { +AccessHouseLevel_t House::getHouseAccessLevel(std::shared_ptr player) { if (!player) { return HOUSE_OWNER; } @@ -166,12 +166,12 @@ AccessHouseLevel_t House::getHouseAccessLevel(const Player* player) { return HOUSE_NOT_INVITED; } -bool House::kickPlayer(Player* player, Player* target) { +bool House::kickPlayer(std::shared_ptr player, std::shared_ptr target) { if (!target) { return false; } - HouseTile* houseTile = dynamic_cast(target->getTile()); + std::shared_ptr houseTile = std::dynamic_pointer_cast(target->getTile()); if (!houseTile || houseTile->getHouse() != this) { return false; } @@ -194,7 +194,7 @@ void House::setAccessList(uint32_t listId, const std::string &textlist) { } else if (listId == SUBOWNER_LIST) { subOwnerList.parseList(textlist); } else { - Door* door = getDoorByNumber(listId); + std::shared_ptr door = getDoorByNumber(listId); if (door) { door->setAccessList(textlist); } @@ -204,10 +204,10 @@ void House::setAccessList(uint32_t listId, const std::string &textlist) { } // kick uninvited players - for (HouseTile* tile : houseTiles) { + for (std::shared_ptr tile : houseTiles) { if (CreatureVector* creatures = tile->getCreatures()) { for (int32_t i = creatures->size(); --i >= 0;) { - Player* player = (*creatures)[i]->getPlayer(); + std::shared_ptr player = (*creatures)[i]->getPlayer(); if (player && !isInvited(player)) { kickPlayer(nullptr, player); } @@ -221,29 +221,29 @@ bool House::transferToDepot() const { return false; } - Player* player = g_game().getPlayerByGUID(owner); + std::shared_ptr player = g_game().getPlayerByGUID(owner); if (player) { transferToDepot(player); } else { - Player tmpPlayer(nullptr); - if (!IOLoginData::loadPlayerById(&tmpPlayer, owner)) { + std::shared_ptr tmpPlayer = std::make_shared(nullptr); + if (!IOLoginData::loadPlayerById(tmpPlayer, owner)) { return false; } - transferToDepot(&tmpPlayer); - IOLoginData::savePlayer(&tmpPlayer); + transferToDepot(tmpPlayer); + IOLoginData::savePlayer(tmpPlayer); } return true; } -bool House::transferToDepot(Player* player) const { +bool House::transferToDepot(std::shared_ptr player) const { if (townId == 0 || owner == 0) { return false; } ItemList moveItemList; - for (HouseTile* tile : houseTiles) { + for (std::shared_ptr tile : houseTiles) { if (const TileItemVector* items = tile->getItemList()) { - for (Item* item : *items) { + for (auto &item : *items) { if (item->isWrapable()) { handleWrapableItem(moveItemList, item, player, tile); } else if (item->isPickupable()) { @@ -255,18 +255,18 @@ bool House::transferToDepot(Player* player) const { } } - for (Item* item : moveItemList) { + for (std::shared_ptr item : moveItemList) { g_game().internalMoveItem(item->getParent(), player->getInbox(), INDEX_WHEREEVER, item, item->getItemCount(), nullptr, FLAG_NOLIMIT); } return true; } -void House::handleWrapableItem(ItemList &moveItemList, Item* item, Player* player, HouseTile* houseTile) const { +void House::handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, std::shared_ptr player, std::shared_ptr houseTile) const { if (item->isWrapContainer()) { handleContainer(moveItemList, item); } - Item* newItem = g_game().wrapItem(item, houseTile->getHouse()); + std::shared_ptr newItem = g_game().wrapItem(item, houseTile->getHouse()); if (newItem->isRemoved() && !newItem->getParent()) { g_logger().warn("[{}] item removed during wrapping - check ground type - player name: {} item id: {} position: {}", __FUNCTION__, player->getName(), item->getID(), houseTile->getPosition().toString()); return; @@ -275,9 +275,9 @@ void House::handleWrapableItem(ItemList &moveItemList, Item* item, Player* playe moveItemList.push_back(newItem); } -void House::handleContainer(ItemList &moveItemList, Item* item) const { +void House::handleContainer(ItemList &moveItemList, std::shared_ptr item) const { if (const auto container = item->getContainer()) { - for (Item* containerItem : container->getItemList()) { + for (std::shared_ptr containerItem : container->getItemList()) { moveItemList.push_back(containerItem); } } @@ -292,7 +292,7 @@ bool House::getAccessList(uint32_t listId, std::string &list) const { return true; } - Door* door = getDoorByNumber(listId); + std::shared_ptr door = getDoorByNumber(listId); if (!door) { return false; } @@ -300,18 +300,18 @@ bool House::getAccessList(uint32_t listId, std::string &list) const { return door->getAccessList(list); } -bool House::isInvited(const Player* player) { +bool House::isInvited(std::shared_ptr player) { return getHouseAccessLevel(player) != HOUSE_NOT_INVITED; } -void House::addDoor(Door* door) { +void House::addDoor(std::shared_ptr door) { door->incrementReferenceCounter(); doorList.push_back(door); door->setHouse(this); updateDoorDescription(); } -void House::removeDoor(Door* door) { +void House::removeDoor(std::shared_ptr door) { auto it = std::find(doorList.begin(), doorList.end(), door); if (it != doorList.end()) { door->decrementReferenceCounter(); @@ -319,18 +319,18 @@ void House::removeDoor(Door* door) { } } -void House::addBed(BedItem* bed) { +void House::addBed(std::shared_ptr bed) { bedsList.push_back(bed); bed->setHouse(this); } -void House::removeBed(BedItem* bed) { +void House::removeBed(std::shared_ptr bed) { bed->setHouse(nullptr); bedsList.remove(bed); } -Door* House::getDoorByNumber(uint32_t doorId) const { - for (Door* door : doorList) { +std::shared_ptr House::getDoorByNumber(uint32_t doorId) const { + for (std::shared_ptr door : doorList) { if (door->getDoorId() == doorId) { return door; } @@ -338,8 +338,8 @@ Door* House::getDoorByNumber(uint32_t doorId) const { return nullptr; } -Door* House::getDoorByPosition(const Position &pos) { - for (Door* door : doorList) { +std::shared_ptr House::getDoorByPosition(const Position &pos) { + for (std::shared_ptr door : doorList) { if (door->getPosition() == pos) { return door; } @@ -347,7 +347,7 @@ Door* House::getDoorByPosition(const Position &pos) { return nullptr; } -bool House::canEditAccessList(uint32_t listId, const Player* player) { +bool House::canEditAccessList(uint32_t listId, std::shared_ptr player) { switch (getHouseAccessLevel(player)) { case HOUSE_OWNER: return true; @@ -360,7 +360,7 @@ bool House::canEditAccessList(uint32_t listId, const Player* player) { } } -HouseTransferItem* House::getTransferItem() { +std::shared_ptr House::getTransferItem() { if (transferItem != nullptr) { return nullptr; } @@ -373,7 +373,7 @@ HouseTransferItem* House::getTransferItem() { void House::resetTransferItem() { if (transferItem) { - Item* tmpItem = transferItem; + std::shared_ptr tmpItem = transferItem; transferItem = nullptr; transfer_container.setParent(nullptr); @@ -382,8 +382,8 @@ void House::resetTransferItem() { } } -HouseTransferItem* HouseTransferItem::createHouseTransferItem(House* house) { - HouseTransferItem* transferItem = new HouseTransferItem(house); +std::shared_ptr HouseTransferItem::createHouseTransferItem(House* house) { + std::shared_ptr transferItem = std::make_shared(house); transferItem->incrementReferenceCounter(); transferItem->setID(ITEM_DOCUMENT_RO); transferItem->setSubType(1); @@ -393,13 +393,13 @@ HouseTransferItem* HouseTransferItem::createHouseTransferItem(House* house) { return transferItem; } -void HouseTransferItem::onTradeEvent(TradeEvents_t event, Player* owner) { +void HouseTransferItem::onTradeEvent(TradeEvents_t event, std::shared_ptr owner) { if (event == ON_TRADE_TRANSFER) { if (house) { - house->executeTransfer(this, owner); + house->executeTransfer(static_self_cast(), owner); } - g_game().internalRemoveItem(this, 1); + g_game().internalRemoveItem(static_self_cast(), 1); } else if (event == ON_TRADE_CANCEL) { if (house) { house->resetTransferItem(); @@ -407,7 +407,7 @@ void HouseTransferItem::onTradeEvent(TradeEvents_t event, Player* owner) { } } -bool House::executeTransfer(HouseTransferItem* item, Player* newOwner) { +bool House::executeTransfer(std::shared_ptr item, std::shared_ptr newOwner) { if (transferItem != item) { return false; } @@ -459,7 +459,7 @@ void AccessList::parseList(const std::string &list) { } void AccessList::addPlayer(const std::string &name) { - const Player* player = g_game().getPlayerByName(name); + std::shared_ptr player = g_game().getPlayerByName(name); if (player) { playerList.insert(player->getGUID()); } else { @@ -507,7 +507,7 @@ void AccessList::addGuildRank(const std::string &name, const std::string &guildN } } -bool AccessList::isInList(const Player* player) { +bool AccessList::isInList(std::shared_ptr player) { if (allowEveryone) { return true; } @@ -553,7 +553,7 @@ void Door::setHouse(House* newHouse) { } } -bool Door::canUse(const Player* player) { +bool Door::canUse(std::shared_ptr player) { if (!house) { return true; } @@ -586,7 +586,7 @@ void Door::onRemoved() { Item::onRemoved(); if (house) { - house->removeDoor(this); + house->removeDoor(static_self_cast()); } } @@ -673,15 +673,15 @@ void Houses::payHouses(RentPeriod_t rentPeriod) const { continue; } - Player player(nullptr); - if (!IOLoginData::loadPlayerById(&player, ownerId)) { + std::shared_ptr player = std::make_shared(nullptr); + if (!IOLoginData::loadPlayerById(player, ownerId)) { // Player doesn't exist, reset house owner house->setOwner(0); continue; } - if (player.getBankBalance() >= rent) { - player.setBankBalance(player.getBankBalance() - rent); + if (player->getBankBalance() >= rent) { + player->setBankBalance(player->getBankBalance() - rent); time_t paidUntil = currentTime; switch (rentPeriod) { @@ -706,7 +706,7 @@ void Houses::payHouses(RentPeriod_t rentPeriod) const { if (house->getPayRentWarnings() < 7) { int32_t daysLeft = 7 - house->getPayRentWarnings(); - Item* letter = Item::CreateItem(ITEM_LETTER_STAMPED); + std::shared_ptr letter = Item::CreateItem(ITEM_LETTER_STAMPED); std::string period; switch (rentPeriod) { @@ -731,16 +731,16 @@ void Houses::payHouses(RentPeriod_t rentPeriod) const { } std::ostringstream ss; - ss << "Warning! \nThe " << period << " rent of " << house->getRent() << " gold for your house \"" << house->getName() << "\" is payable. Have it within " << daysLeft << " days or you will lose this house."; + ss << "Warning! \nThe " << period << " rent of " << house->getRent() << " gold for your house \"" << house->getName() << "\" is payable. Have it within " << daysLeft << " days or you will lose static_self_cast() house."; letter->setAttribute(ItemAttribute_t::TEXT, ss.str()); - g_game().internalAddItem(player.getInbox(), letter, INDEX_WHEREEVER, FLAG_NOLIMIT); + g_game().internalAddItem(player->getInbox(), letter, INDEX_WHEREEVER, FLAG_NOLIMIT); house->setPayRentWarnings(house->getPayRentWarnings() + 1); } else { - house->setOwner(0, true, &player); + house->setOwner(0, true, player); } } - IOLoginData::savePlayer(&player); + IOLoginData::savePlayer(player); } } diff --git a/src/map/house/house.hpp b/src/map/house/house.hpp index 3095e7e1692..d5331001372 100644 --- a/src/map/house/house.hpp +++ b/src/map/house/house.hpp @@ -25,7 +25,7 @@ class AccessList { void addGuild(const std::string &name); void addGuildRank(const std::string &name, const std::string &rankName); - bool isInList(const Player* player); + bool isInList(std::shared_ptr player); void getList(std::string &list) const; @@ -44,11 +44,8 @@ class Door final : public Item { Door(const Door &) = delete; Door &operator=(const Door &) = delete; - Door* getDoor() override { - return this; - } - const Door* getDoor() const override { - return this; + std::shared_ptr getDoor() override { + return static_self_cast(); } House* getHouse() { @@ -66,7 +63,7 @@ class Door final : public Item { return getAttribute(ItemAttribute_t::DOORID); } - bool canUse(const Player* player); + bool canUse(std::shared_ptr player); void setAccessList(const std::string &textlist); bool getAccessList(std::string &list) const; @@ -81,17 +78,17 @@ class Door final : public Item { friend class House; }; -using HouseTileList = std::list; -using HouseBedItemList = std::list; +using HouseTileList = std::list>; +using HouseBedItemList = std::list>; class HouseTransferItem final : public Item { public: - static HouseTransferItem* createHouseTransferItem(House* house); + static std::shared_ptr createHouseTransferItem(House* house); explicit HouseTransferItem(House* newHouse) : Item(0), house(newHouse) { } - void onTradeEvent(TradeEvents_t event, Player* owner) override; + void onTradeEvent(TradeEvents_t event, std::shared_ptr owner) override; bool canTransform() const override { return false; } @@ -104,20 +101,20 @@ class House { public: explicit House(uint32_t houseId); - void addTile(HouseTile* tile); + void addTile(std::shared_ptr tile); void updateDoorDescription() const; - bool canEditAccessList(uint32_t listId, const Player* player); + bool canEditAccessList(uint32_t listId, std::shared_ptr player); // listId special = values: // GUEST_LIST = guest list // SUBOWNER_LIST = subowner list void setAccessList(uint32_t listId, const std::string &textlist); bool getAccessList(uint32_t listId, std::string &list) const; - bool isInvited(const Player* player); + bool isInvited(std::shared_ptr player); - AccessHouseLevel_t getHouseAccessLevel(const Player* player); - bool kickPlayer(Player* player, Player* target); + AccessHouseLevel_t getHouseAccessLevel(std::shared_ptr player); + bool kickPlayer(std::shared_ptr player, std::shared_ptr target); void setEntryPos(Position pos) { posEntry = pos; @@ -133,7 +130,7 @@ class House { return houseName; } - void setOwner(uint32_t guid, bool updateDatabase = true, Player* player = nullptr); + void setOwner(uint32_t guid, bool updateDatabase = true, std::shared_ptr player = nullptr); uint32_t getOwner() const { return owner; } @@ -176,25 +173,25 @@ class House { return id; } - void addDoor(Door* door); - void removeDoor(Door* door); - Door* getDoorByNumber(uint32_t doorId) const; - Door* getDoorByPosition(const Position &pos); + void addDoor(std::shared_ptr door); + void removeDoor(std::shared_ptr door); + std::shared_ptr getDoorByNumber(uint32_t doorId) const; + std::shared_ptr getDoorByPosition(const Position &pos); - HouseTransferItem* getTransferItem(); + std::shared_ptr getTransferItem(); void resetTransferItem(); - bool executeTransfer(HouseTransferItem* item, Player* player); + bool executeTransfer(std::shared_ptr item, std::shared_ptr player); const HouseTileList &getTiles() const { return houseTiles; } - const std::list &getDoors() const { + const std::list> &getDoors() const { return doorList; } - void addBed(BedItem* bed); - void removeBed(BedItem* bed); + void addBed(std::shared_ptr bed); + void removeBed(std::shared_ptr bed); const HouseBedItemList &getBeds() const { return bedsList; } @@ -212,7 +209,7 @@ class House { private: bool transferToDepot() const; - bool transferToDepot(Player* player) const; + bool transferToDepot(std::shared_ptr player) const; AccessList guestList; AccessList subOwnerList; @@ -220,13 +217,13 @@ class House { Container transfer_container { ITEM_LOCKER }; HouseTileList houseTiles; - std::list doorList; + std::list> doorList; HouseBedItemList bedsList; std::string houseName; std::string ownerName; - HouseTransferItem* transferItem = nullptr; + std::shared_ptr transferItem = nullptr; time_t paidUntil = 0; @@ -244,8 +241,8 @@ class House { bool isLoaded = false; - void handleContainer(ItemList &moveItemList, Item* item) const; - void handleWrapableItem(ItemList &moveItemList, Item* item, Player* player, HouseTile* houseTile) const; + void handleContainer(ItemList &moveItemList, std::shared_ptr item) const; + void handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, std::shared_ptr player, std::shared_ptr houseTile) const; }; using HouseMap = std::map; diff --git a/src/map/house/housetile.cpp b/src/map/house/housetile.cpp index 9a3368e75d1..615a7862c8e 100644 --- a/src/map/house/housetile.cpp +++ b/src/map/house/housetile.cpp @@ -18,55 +18,55 @@ HouseTile::HouseTile(int32_t initX, int32_t initY, int32_t initZ, House* initHouse) : DynamicTile(initX, initY, initZ), house(initHouse) { } -void HouseTile::addThing(int32_t index, Thing* thing) { +void HouseTile::addThing(int32_t index, std::shared_ptr thing) { Tile::addThing(index, thing); if (!thing || !thing->getParent()) { return; } - if (Item* item = thing->getItem()) { + if (std::shared_ptr item = thing->getItem()) { updateHouse(item); } } -void HouseTile::internalAddThing(uint32_t index, Thing* thing) { +void HouseTile::internalAddThing(uint32_t index, std::shared_ptr thing) { Tile::internalAddThing(index, thing); if (!thing || !thing->getParent()) { return; } - if (Item* item = thing->getItem()) { + if (std::shared_ptr item = thing->getItem()) { updateHouse(item); } } -void HouseTile::updateHouse(Item* item) { - if (item->getParent() != this) { +void HouseTile::updateHouse(std::shared_ptr item) { + if (item->getParent().get() != this) { return; } - Door* door = item->getDoor(); + std::shared_ptr door = item->getDoor(); if (door) { if (door->getDoorId() != 0) { house->addDoor(door); } } else { - BedItem* bed = item->getBed(); + std::shared_ptr bed = item->getBed(); if (bed) { house->addBed(bed); } } } -ReturnValue HouseTile::queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t tileFlags, Creature* actor /* = nullptr*/) const { - if (const Creature* creature = thing.getCreature()) { - if (const Player* player = creature->getPlayer()) { +ReturnValue HouseTile::queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t tileFlags, std::shared_ptr actor /* = nullptr*/) { + if (std::shared_ptr creature = thing->getCreature()) { + if (std::shared_ptr player = creature->getPlayer()) { if (!house->isInvited(player)) { return RETURNVALUE_PLAYERISNOTINVITED; } - } else if (const Monster* monster = creature->getMonster()) { + } else if (std::shared_ptr monster = creature->getMonster()) { if (monster->isSummon()) { if (!house->isInvited(monster->getMaster()->getPlayer())) { return RETURNVALUE_NOTPOSSIBLE; @@ -78,8 +78,8 @@ ReturnValue HouseTile::queryAdd(int32_t index, const Thing &thing, uint32_t coun } } } - } else if (thing.getItem() && actor) { - Player* actorPlayer = actor->getPlayer(); + } else if (thing->getItem() && actor) { + std::shared_ptr actorPlayer = actor->getPlayer(); if (house && (!house->isInvited(actorPlayer) || house->getHouseAccessLevel(actorPlayer) == HOUSE_GUEST) && g_configManager().getBoolean(ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { return RETURNVALUE_CANNOTTHROW; } @@ -87,12 +87,12 @@ ReturnValue HouseTile::queryAdd(int32_t index, const Thing &thing, uint32_t coun return Tile::queryAdd(index, thing, count, tileFlags, actor); } -Tile* HouseTile::queryDestination(int32_t &index, const Thing &thing, Item** destItem, uint32_t &tileFlags) { - if (const Creature* creature = thing.getCreature()) { - if (const Player* player = creature->getPlayer()) { +std::shared_ptr HouseTile::queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &tileFlags) { + if (std::shared_ptr creature = thing->getCreature()) { + if (std::shared_ptr player = creature->getPlayer()) { if (!house->isInvited(player)) { const Position &entryPos = house->getEntryPosition(); - Tile* destTile = g_game().map.getTile(entryPos); + std::shared_ptr destTile = g_game().map.getTile(entryPos); if (!destTile) { g_logger().error("[HouseTile::queryDestination] - " "Entry not correct for house name: {} " @@ -100,7 +100,7 @@ Tile* HouseTile::queryDestination(int32_t &index, const Thing &thing, Item** des house->getName(), house->getId(), entryPos.toString()); destTile = g_game().map.getTile(player->getTemplePosition()); if (!destTile) { - destTile = &(Tile::nullptr_tile); + destTile = Tile::nullptr_tile; } } @@ -114,14 +114,14 @@ Tile* HouseTile::queryDestination(int32_t &index, const Thing &thing, Item** des return Tile::queryDestination(index, thing, destItem, tileFlags); } -ReturnValue HouseTile::queryRemove(const Thing &thing, uint32_t count, uint32_t flags, Creature* actor /*= nullptr*/) const { - const Item* item = thing.getItem(); +ReturnValue HouseTile::queryRemove(const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor /*= nullptr*/) { + std::shared_ptr item = thing->getItem(); if (!item) { return RETURNVALUE_NOTPOSSIBLE; } if (actor && g_configManager().getBoolean(ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { - Player* actorPlayer = actor->getPlayer(); + std::shared_ptr actorPlayer = actor->getPlayer(); if (house && !house->isInvited(actorPlayer)) { return RETURNVALUE_NOTPOSSIBLE; } else if (house && house->getHouseAccessLevel(actorPlayer) == HOUSE_GUEST) { diff --git a/src/map/house/housetile.hpp b/src/map/house/housetile.hpp index 05aa5ba1a9d..916f040aa94 100644 --- a/src/map/house/housetile.hpp +++ b/src/map/house/housetile.hpp @@ -18,21 +18,21 @@ class HouseTile final : public DynamicTile { HouseTile(int32_t x, int32_t y, int32_t z, House* house); // cylinder implementations - ReturnValue queryAdd(int32_t index, const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; + ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; - Tile* queryDestination(int32_t &index, const Thing &thing, Item** destItem, uint32_t &flags) override; + std::shared_ptr queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &flags) override; - ReturnValue queryRemove(const Thing &thing, uint32_t count, uint32_t flags, Creature* actor = nullptr) const override; + ReturnValue queryRemove(const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; - void addThing(int32_t index, Thing* thing) override; - void virtual internalAddThing(uint32_t index, Thing* thing) override; + void addThing(int32_t index, std::shared_ptr thing) override; + void virtual internalAddThing(uint32_t index, std::shared_ptr thing) override; House* getHouse() override { return house; } private: - void updateHouse(Item* item); + void updateHouse(std::shared_ptr item); House* house; }; diff --git a/src/map/map.cpp b/src/map/map.cpp index b9458a3fb8f..f31bf45f6ff 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -133,13 +133,13 @@ bool Map::save() { return false; } -Tile* Map::getOrCreateTile(uint16_t x, uint16_t y, uint8_t z, bool isDynamic) { +std::shared_ptr Map::getOrCreateTile(uint16_t x, uint16_t y, uint8_t z, bool isDynamic) { auto tile = getTile(x, y, z); if (!tile) { if (isDynamic) { - tile = new DynamicTile(x, y, z); + tile = std::make_shared(x, y, z); } else { - tile = new StaticTile(x, y, z); + tile = std::make_shared(x, y, z); } setTile(x, y, z, tile); @@ -148,7 +148,7 @@ Tile* Map::getOrCreateTile(uint16_t x, uint16_t y, uint8_t z, bool isDynamic) { return tile; } -Tile* Map::getTile(uint16_t x, uint16_t y, uint8_t z) { +std::shared_ptr Map::getTile(uint16_t x, uint16_t y, uint8_t z) { if (z >= MAP_MAX_LAYERS) { return nullptr; } @@ -167,7 +167,7 @@ Tile* Map::getTile(uint16_t x, uint16_t y, uint8_t z) { return tile ? tile : getOrCreateTileFromCache(floor, x, y); } -void Map::setTile(uint16_t x, uint16_t y, uint8_t z, Tile* newTile) { +void Map::setTile(uint16_t x, uint16_t y, uint8_t z, std::shared_ptr newTile) { if (z >= MAP_MAX_LAYERS) { g_logger().error("Attempt to set tile on invalid coordinate: {}", Position(x, y, z).toString()); return; @@ -180,8 +180,8 @@ void Map::setTile(uint16_t x, uint16_t y, uint8_t z, Tile* newTile) { } } -bool Map::placeCreature(const Position ¢erPos, Creature* creature, bool extendedPos /* = false*/, bool forceLogin /* = false*/) { - Monster* monster = creature->getMonster(); +bool Map::placeCreature(const Position ¢erPos, std::shared_ptr creature, bool extendedPos /* = false*/, bool forceLogin /* = false*/) { + auto monster = creature->getMonster(); if (monster) { monster->ignoreFieldDamage = true; } @@ -189,10 +189,10 @@ bool Map::placeCreature(const Position ¢erPos, Creature* creature, bool exte bool foundTile; bool placeInPZ; - Tile* tile = getTile(centerPos.x, centerPos.y, centerPos.z); + std::shared_ptr tile = getTile(centerPos.x, centerPos.y, centerPos.z); if (tile) { placeInPZ = tile->hasFlag(TILESTATE_PROTECTIONZONE); - ReturnValue ret = tile->queryAdd(0, *creature, 1, FLAG_IGNOREBLOCKITEM | FLAG_IGNOREFIELDDAMAGE); + ReturnValue ret = tile->queryAdd(0, creature, 1, FLAG_IGNOREBLOCKITEM | FLAG_IGNOREFIELDDAMAGE); foundTile = forceLogin || ret == RETURNVALUE_NOERROR || ret == RETURNVALUE_PLAYERISNOTINVITED; if (monster) { monster->ignoreFieldDamage = false; @@ -248,7 +248,7 @@ bool Map::placeCreature(const Position ¢erPos, Creature* creature, bool exte monster->ignoreFieldDamage = true; } - if (tile->queryAdd(0, *creature, 1, FLAG_IGNOREBLOCKITEM | FLAG_IGNOREFIELDDAMAGE) == RETURNVALUE_NOERROR) { + if (tile->queryAdd(0, creature, 1, FLAG_IGNOREBLOCKITEM | FLAG_IGNOREFIELDDAMAGE) == RETURNVALUE_NOERROR) { if (!extendedPos || isSightClear(centerPos, tryPos, false)) { foundTile = true; break; @@ -267,9 +267,9 @@ bool Map::placeCreature(const Position ¢erPos, Creature* creature, bool exte int32_t index = 0; uint32_t flags = 0; - Item* toItem = nullptr; + std::shared_ptr toItem = nullptr; - Cylinder* toCylinder = tile->queryDestination(index, *creature, &toItem, flags); + auto toCylinder = tile->queryDestination(index, creature, &toItem, flags); toCylinder->internalAddThing(creature); const Position &dest = toCylinder->getPosition(); @@ -277,29 +277,29 @@ bool Map::placeCreature(const Position ¢erPos, Creature* creature, bool exte return true; } -void Map::moveCreature(Creature &creature, Tile &newTile, bool forceTeleport /* = false*/) { - Tile &oldTile = *creature.getTile(); +void Map::moveCreature(const std::shared_ptr &creature, const std::shared_ptr &newTile, bool forceTeleport /* = false*/) { + auto oldTile = creature->getTile(); - Position oldPos = oldTile.getPosition(); - Position newPos = newTile.getPosition(); + Position oldPos = oldTile->getPosition(); + Position newPos = newTile->getPosition(); - auto fromZones = oldTile.getZones(); - auto toZones = newTile.getZones(); - if (auto ret = g_game().beforeCreatureZoneChange(&creature, fromZones, toZones); ret != RETURNVALUE_NOERROR) { + auto fromZones = oldTile->getZones(); + auto toZones = newTile->getZones(); + if (auto ret = g_game().beforeCreatureZoneChange(creature, fromZones, toZones); ret != RETURNVALUE_NOERROR) { return; } - bool teleport = forceTeleport || !newTile.getGround() || !Position::areInRange<1, 1, 0>(oldPos, newPos); + bool teleport = forceTeleport || !newTile->getGround() || !Position::areInRange<1, 1, 0>(oldPos, newPos); SpectatorHashSet spectators; getSpectators(spectators, oldPos, true); getSpectators(spectators, newPos, true); std::vector oldStackPosVector; - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { - if (tmpPlayer->canSeeCreature(&creature)) { - oldStackPosVector.push_back(oldTile.getClientIndexOfCreature(tmpPlayer, &creature)); + for (std::shared_ptr spectator : spectators) { + if (auto tmpPlayer = spectator->getPlayer()) { + if (tmpPlayer->canSeeCreature(creature)) { + oldStackPosVector.push_back(oldTile->getClientIndexOfCreature(tmpPlayer, creature)); } else { oldStackPosVector.push_back(-1); } @@ -307,54 +307,54 @@ void Map::moveCreature(Creature &creature, Tile &newTile, bool forceTeleport /* } // remove the creature - oldTile.removeThing(&creature, 0); + oldTile->removeThing(creature, 0); auto leaf = getQTNode(oldPos.x, oldPos.y); auto new_leaf = getQTNode(newPos.x, newPos.y); // Switch the node ownership if (leaf != new_leaf) { - leaf->removeCreature(&creature); - new_leaf->addCreature(&creature); + leaf->removeCreature(creature); + new_leaf->addCreature(creature); } // add the creature - newTile.addThing(&creature); + newTile->addThing(creature); if (!teleport) { if (oldPos.y > newPos.y) { - creature.setDirection(DIRECTION_NORTH); + creature->setDirection(DIRECTION_NORTH); } else if (oldPos.y < newPos.y) { - creature.setDirection(DIRECTION_SOUTH); + creature->setDirection(DIRECTION_SOUTH); } if (oldPos.x < newPos.x) { - creature.setDirection(DIRECTION_EAST); + creature->setDirection(DIRECTION_EAST); } else if (oldPos.x > newPos.x) { - creature.setDirection(DIRECTION_WEST); + creature->setDirection(DIRECTION_WEST); } } // send to client size_t i = 0; - for (Creature* spectator : spectators) { - if (Player* tmpPlayer = spectator->getPlayer()) { + for (auto spectator : spectators) { + if (auto tmpPlayer = spectator->getPlayer()) { // Use the correct stackpos int32_t stackpos = oldStackPosVector[i++]; if (stackpos != -1) { - tmpPlayer->sendCreatureMove(&creature, newPos, newTile.getStackposOfCreature(tmpPlayer, &creature), oldPos, stackpos, teleport); + tmpPlayer->sendCreatureMove(creature, newPos, newTile->getStackposOfCreature(tmpPlayer, creature), oldPos, stackpos, teleport); } } } // event method - for (Creature* spectator : spectators) { - spectator->onCreatureMove(&creature, &newTile, newPos, &oldTile, oldPos, teleport); + for (std::shared_ptr spectator : spectators) { + spectator->onCreatureMove(creature, newTile, newPos, oldTile, oldPos, teleport); } - oldTile.postRemoveNotification(&creature, &newTile, 0); - newTile.postAddNotification(&creature, &oldTile, 0); - g_game().afterCreatureZoneChange(&creature, fromZones, toZones); + oldTile->postRemoveNotification(creature, newTile, 0); + newTile->postAddNotification(creature, oldTile, 0); + g_game().afterCreatureZoneChange(creature, fromZones, toZones); } void Map::getSpectatorsInternal(SpectatorHashSet &spectators, const Position ¢erPos, int32_t minRangeX, int32_t maxRangeX, int32_t minRangeY, int32_t maxRangeY, int32_t minRangeZ, int32_t maxRangeZ, bool onlyPlayers) const { @@ -385,7 +385,7 @@ void Map::getSpectatorsInternal(SpectatorHashSet &spectators, const Position &ce for (int_fast32_t nx = startx1; nx <= endx2; nx += FLOOR_SIZE) { if (leafE) { const auto &node_list = (onlyPlayers ? leafE->player_list : leafE->creature_list); - for (Creature* creature : node_list) { + for (std::shared_ptr creature : node_list) { const Position &cpos = creature->getPosition(); if (minRangeZ > cpos.z || maxRangeZ < cpos.z) { continue; @@ -452,7 +452,7 @@ void Map::getSpectators(SpectatorHashSet &spectators, const Position ¢erPos, } } else { const SpectatorHashSet &cachedSpectators = it->second; - for (Creature* spectator : cachedSpectators) { + for (std::shared_ptr spectator : cachedSpectators) { if (spectator->getPlayer()) { spectators.insert(spectator); } @@ -567,7 +567,7 @@ bool Map::checkSightLine(const Position &fromPos, const Position &toPos) { start.x += mx; } - const Tile* tile = getTile(start.x, start.y, start.z); + const std::shared_ptr tile = getTile(start.x, start.y, start.z); if (tile && tile->hasProperty(CONST_PROP_BLOCKPROJECTILE)) { return false; } @@ -575,7 +575,7 @@ bool Map::checkSightLine(const Position &fromPos, const Position &toPos) { // now we need to perform a jump between floors to see if everything is clear (literally) while (start.z != destination.z) { - const Tile* tile = getTile(start.x, start.y, start.z); + const std::shared_ptr tile = getTile(start.x, start.y, start.z); if (tile && tile->getThingCount() > 0) { return false; } @@ -595,8 +595,8 @@ bool Map::isSightClear(const Position &fromPos, const Position &toPos, bool floo return checkSightLine(fromPos, toPos) || checkSightLine(toPos, fromPos); } -const Tile* Map::canWalkTo(const Creature &creature, const Position &pos) { - int32_t walkCache = creature.getWalkCache(pos); +std::shared_ptr Map::canWalkTo(const std::shared_ptr &creature, const Position &pos) { + int32_t walkCache = creature->getWalkCache(pos); if (walkCache == 0) { return nullptr; } else if (walkCache == 1) { @@ -604,8 +604,8 @@ const Tile* Map::canWalkTo(const Creature &creature, const Position &pos) { } // used for non-cached tiles - Tile* tile = getTile(pos.x, pos.y, pos.z); - if (creature.getTile() != tile) { + std::shared_ptr tile = getTile(pos.x, pos.y, pos.z); + if (creature->getTile() != tile) { if (!tile || tile->queryAdd(0, creature, 1, FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) != RETURNVALUE_NOERROR) { return nullptr; } @@ -613,8 +613,8 @@ const Tile* Map::canWalkTo(const Creature &creature, const Position &pos) { return tile; } -bool Map::getPathMatching(const Creature &creature, std::forward_list &dirList, const FrozenPathingConditionCall &pathCondition, const FindPathParams &fpp) { - Position pos = creature.getPosition(); +bool Map::getPathMatching(const std::shared_ptr &creature, std::forward_list &dirList, const FrozenPathingConditionCall &pathCondition, const FindPathParams &fpp) { + Position pos = creature->getPosition(); Position endPos; AStarNodes nodes(pos.x, pos.y); @@ -706,7 +706,7 @@ bool Map::getPathMatching(const Creature &creature, std::forward_list continue; } - const Tile* tile; + std::shared_ptr tile; AStarNode* neighborNode = nodes.getNodeByPosition(pos.x, pos.y); if (neighborNode) { tile = getTile(pos.x, pos.y, pos.z); @@ -732,7 +732,7 @@ bool Map::getPathMatching(const Creature &creature, std::forward_list neighborNode->parent = n; nodes.openNode(neighborNode); } else { - // Does not exist in the open/closed list, create a new node + // Does not exist in the open/closed list, create a std::make_shared neighborNode = nodes.createOpenNode(n, pos.x, pos.y, newf); if (!neighborNode) { if (found) { @@ -880,7 +880,7 @@ bool Map::getPathMatching(const Position &start, std::forward_list &d continue; } - const Tile* tile; + std::shared_ptr tile; AStarNode* neighborNode = nodes.getNodeByPosition(pos.x, pos.y); if (neighborNode) { tile = getTile(pos.x, pos.y, pos.z); @@ -906,7 +906,7 @@ bool Map::getPathMatching(const Position &start, std::forward_list &d neighborNode->parent = n; nodes.openNode(neighborNode); } else { - // Does not exist in the open/closed list, create a new node + // Does not exist in the open/closed list, create a std::make_shared neighborNode = nodes.createOpenNode(n, pos.x, pos.y, newf); if (!neighborNode) { if (found) { @@ -969,7 +969,7 @@ uint32_t Map::clean() { g_game().setGameState(GAME_STATE_MAINTAIN); } - std::vector toRemove; + std::vector> toRemove; for (auto tile : g_game().getTilesToClean()) { if (!tile) { continue; diff --git a/src/map/map.hpp b/src/map/map.hpp index 7e7d3a2f68b..0a98fc23a52 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -75,13 +75,13 @@ class Map : protected MapCache { * Get a single tile. * \returns A pointer to that tile. */ - Tile* getTile(uint16_t x, uint16_t y, uint8_t z); - Tile* getTile(const Position &pos) { + std::shared_ptr getTile(uint16_t x, uint16_t y, uint8_t z); + std::shared_ptr getTile(const Position &pos) { return getTile(pos.x, pos.y, pos.z); } - Tile* getOrCreateTile(uint16_t x, uint16_t y, uint8_t z, bool isDynamic = false); - Tile* getOrCreateTile(const Position &pos, bool isDynamic = false) { + std::shared_ptr getOrCreateTile(uint16_t x, uint16_t y, uint8_t z, bool isDynamic = false); + std::shared_ptr getOrCreateTile(const Position &pos, bool isDynamic = false) { return getOrCreateTile(pos.x, pos.y, pos.z, isDynamic); } @@ -92,9 +92,9 @@ class Map : protected MapCache { * \param extendedPos If true, the creature will in first-hand be placed 2 tiles away * \param forceLogin If true, placing the creature will not fail becase of obstacles (creatures/chests) */ - bool placeCreature(const Position ¢erPos, Creature* creature, bool extendedPos = false, bool forceLogin = false); + bool placeCreature(const Position ¢erPos, std::shared_ptr creature, bool extendedPos = false, bool forceLogin = false); - void moveCreature(Creature &creature, Tile &newTile, bool forceTeleport = false); + void moveCreature(const std::shared_ptr &creature, const std::shared_ptr &newTile, bool forceTeleport = false); void getSpectators(SpectatorHashSet &spectators, const Position ¢erPos, bool multifloor = false, bool onlyPlayers = false, int32_t minRangeX = 0, int32_t maxRangeX = 0, int32_t minRangeY = 0, int32_t maxRangeY = 0); @@ -122,9 +122,9 @@ class Map : protected MapCache { bool isSightClear(const Position &fromPos, const Position &toPos, bool floorCheck); bool checkSightLine(const Position &fromPos, const Position &toPos); - const Tile* canWalkTo(const Creature &creature, const Position &pos); + std::shared_ptr canWalkTo(const std::shared_ptr &creature, const Position &pos); - bool getPathMatching(const Creature &creature, std::forward_list &dirList, const FrozenPathingConditionCall &pathCondition, const FindPathParams &fpp); + bool getPathMatching(const std::shared_ptr &creature, std::forward_list &dirList, const FrozenPathingConditionCall &pathCondition, const FindPathParams &fpp); bool getPathMatching(const Position &startPos, std::forward_list &dirList, const FrozenPathingConditionCall &pathCondition, const FindPathParams &fpp); @@ -149,8 +149,8 @@ class Map : protected MapCache { /** * Set a single tile. */ - void setTile(uint16_t x, uint16_t y, uint8_t z, Tile* newTile); - void setTile(const Position &pos, Tile* newTile) { + void setTile(uint16_t x, uint16_t y, uint8_t z, std::shared_ptr newTile); + void setTile(const Position &pos, std::shared_ptr newTile) { setTile(pos.x, pos.y, pos.z, newTile); } diff --git a/src/map/mapcache.cpp b/src/map/mapcache.cpp index 7660b762973..e99500946e4 100644 --- a/src/map/mapcache.cpp +++ b/src/map/mapcache.cpp @@ -22,14 +22,14 @@ #include "io/iomap.hpp" -static phmap::flat_hash_map items; -static phmap::flat_hash_map tiles; +static phmap::flat_hash_map> items; +static phmap::flat_hash_map> tiles; -BasicItemPtr static_tryGetItemFromCache(const BasicItemPtr &ref) { +std::shared_ptr static_tryGetItemFromCache(const std::shared_ptr &ref) { return ref ? items.try_emplace(ref->hash(), ref).first->second : nullptr; } -BasicTilePtr static_tryGetTileFromCache(const BasicTilePtr &ref) { +std::shared_ptr static_tryGetTileFromCache(const std::shared_ptr &ref) { return ref ? tiles.try_emplace(ref->hash(), ref).first->second : nullptr; } @@ -38,7 +38,7 @@ void MapCache::flush() { tiles.clear(); } -void MapCache::parseItemAttr(const BasicItemPtr &BasicItem, Item* item) { +void MapCache::parseItemAttr(const std::shared_ptr &BasicItem, std::shared_ptr item) { if (BasicItem->charges > 0) { item->setSubType(BasicItem->charges); } @@ -72,7 +72,7 @@ void MapCache::parseItemAttr(const BasicItemPtr &BasicItem, Item* item) { item->setAttribute(ItemAttribute_t::DESCRIPTION, STRING_CACHE[BasicItem.description]);*/ } -Item* MapCache::createItem(const BasicItemPtr &BasicItem, Position position) { +std::shared_ptr MapCache::createItem(const std::shared_ptr &BasicItem, Position position) { auto item = Item::CreateItem(BasicItem->id, position); if (!item) { return nullptr; @@ -100,7 +100,7 @@ Item* MapCache::createItem(const BasicItemPtr &BasicItem, Position position) { return item; } -Tile* MapCache::getOrCreateTileFromCache(const std::unique_ptr &floor, uint16_t x, uint16_t y) { +std::shared_ptr MapCache::getOrCreateTileFromCache(const std::unique_ptr &floor, uint16_t x, uint16_t y) { const auto &cachedTile = floor->getTileCache(x, y); if (!cachedTile) { return floor->getTile(x, y); @@ -110,15 +110,15 @@ Tile* MapCache::getOrCreateTileFromCache(const std::unique_ptr &floor, ui auto map = static_cast(this); - Tile* tile = nullptr; + std::shared_ptr tile = nullptr; if (cachedTile->isHouse()) { const auto house = map->houses.getHouse(cachedTile->houseId); - tile = new HouseTile(x, y, z, house); - house->addTile(static_cast(tile)); + tile = std::make_shared(x, y, z, house); + house->addTile(std::static_pointer_cast(tile)); } else if (cachedTile->isStatic) { - tile = new StaticTile(x, y, z); + tile = std::make_shared(x, y, z); } else { - tile = new DynamicTile(x, y, z); + tile = std::make_shared(x, y, z); } auto pos = Position(x, y, z); @@ -141,7 +141,7 @@ Tile* MapCache::getOrCreateTileFromCache(const std::unique_ptr &floor, ui return tile; } -void MapCache::setBasicTile(uint16_t x, uint16_t y, uint8_t z, const BasicTilePtr &newTile) { +void MapCache::setBasicTile(uint16_t x, uint16_t y, uint8_t z, const std::shared_ptr &newTile) { if (z >= MAP_MAX_LAYERS) { g_logger().error("Attempt to set tile on invalid coordinate: {}", Position(x, y, z).toString()); return; @@ -155,7 +155,7 @@ void MapCache::setBasicTile(uint16_t x, uint16_t y, uint8_t z, const BasicTilePt } } -BasicItemPtr MapCache::tryReplaceItemFromCache(const BasicItemPtr &ref) { +std::shared_ptr MapCache::tryReplaceItemFromCache(const std::shared_ptr &ref) { return static_tryGetItemFromCache(ref); } diff --git a/src/map/mapcache.hpp b/src/map/mapcache.hpp index 2de994e7b67..7dda032b78b 100644 --- a/src/map/mapcache.hpp +++ b/src/map/mapcache.hpp @@ -20,10 +20,6 @@ class Item; class Position; class FileStream; -using TilePtr = std::unique_ptr; -using BasicItemPtr = std::shared_ptr; -using BasicTilePtr = std::shared_ptr; - #pragma pack(1) struct BasicItem { std::string text; @@ -39,7 +35,7 @@ struct BasicItem { uint8_t destZ { 0 }; - std::vector items; + std::vector> items; bool unserializeItemNode(FileStream &propStream, uint16_t x, uint16_t y, uint8_t z); void readAttr(FileStream &propStream); @@ -57,8 +53,8 @@ struct BasicItem { }; struct BasicTile { - BasicItemPtr ground { nullptr }; - std::vector items; + std::shared_ptr ground { nullptr }; + std::vector> items; uint32_t flags { 0 }, houseId { 0 }; uint8_t type { TILESTATE_NONE }; @@ -89,19 +85,19 @@ struct Floor { explicit Floor(uint8_t z) : z(z) {}; - Tile* getTile(uint16_t x, uint16_t y) const { - return tiles[x & FLOOR_MASK][y & FLOOR_MASK].first.get(); + std::shared_ptr getTile(uint16_t x, uint16_t y) const { + return tiles[x & FLOOR_MASK][y & FLOOR_MASK].first; } - void setTile(uint16_t x, uint16_t y, Tile* tile) { - tiles[x & FLOOR_MASK][y & FLOOR_MASK].first.reset(tile); + void setTile(uint16_t x, uint16_t y, std::shared_ptr tile) { + tiles[x & FLOOR_MASK][y & FLOOR_MASK].first = tile; } - BasicTilePtr getTileCache(uint16_t x, uint16_t y) const { + std::shared_ptr getTileCache(uint16_t x, uint16_t y) const { return tiles[x & FLOOR_MASK][y & FLOOR_MASK].second; } - void setTileCache(uint16_t x, uint16_t y, const BasicTilePtr &newTile) { + void setTileCache(uint16_t x, uint16_t y, const std::shared_ptr &newTile) { tiles[x & FLOOR_MASK][y & FLOOR_MASK].second = newTile; } @@ -110,7 +106,7 @@ struct Floor { } private: - std::pair tiles[FLOOR_SIZE][FLOOR_SIZE] = {}; + std::pair, std::shared_ptr> tiles[FLOOR_SIZE][FLOOR_SIZE] = {}; uint8_t z { 0 }; }; @@ -118,18 +114,18 @@ class MapCache { public: virtual ~MapCache() = default; - void setBasicTile(uint16_t x, uint16_t y, uint8_t z, const BasicTilePtr &BasicTile); + void setBasicTile(uint16_t x, uint16_t y, uint8_t z, const std::shared_ptr &BasicTile); - BasicItemPtr tryReplaceItemFromCache(const BasicItemPtr &ref); + std::shared_ptr tryReplaceItemFromCache(const std::shared_ptr &ref); void flush(); protected: - Tile* getOrCreateTileFromCache(const std::unique_ptr &floor, uint16_t x, uint16_t y); + std::shared_ptr getOrCreateTileFromCache(const std::unique_ptr &floor, uint16_t x, uint16_t y); QTreeNode root; private: - void parseItemAttr(const BasicItemPtr &BasicItem, Item* item); - Item* createItem(const BasicItemPtr &BasicItem, Position position); + void parseItemAttr(const std::shared_ptr &BasicItem, std::shared_ptr item); + std::shared_ptr createItem(const std::shared_ptr &BasicItem, Position position); }; diff --git a/src/map/utils/astarnodes.cpp b/src/map/utils/astarnodes.cpp index 969a8996742..36265dd7f12 100644 --- a/src/map/utils/astarnodes.cpp +++ b/src/map/utils/astarnodes.cpp @@ -104,23 +104,23 @@ int_fast32_t AStarNodes::getMapWalkCost(AStarNode* node, const Position &neighbo return MAP_NORMALWALKCOST; } -int_fast32_t AStarNodes::getTileWalkCost(const Creature &creature, const Tile* tile) { +int_fast32_t AStarNodes::getTileWalkCost(const std::shared_ptr &creature, std::shared_ptr tile) { int_fast32_t cost = 0; - if (tile->getTopVisibleCreature(&creature) != nullptr) { + if (tile->getTopVisibleCreature(creature) != nullptr) { // destroy creature cost cost += MAP_NORMALWALKCOST * 3; } - if (const MagicField* field = tile->getFieldItem()) { + if (std::shared_ptr field = tile->getFieldItem()) { CombatType_t combatType = field->getCombatType(); - const Monster* monster = creature.getMonster(); - if (!creature.isImmune(combatType) && !creature.hasCondition(Combat::DamageToConditionType(combatType)) && (monster && !monster->canWalkOnFieldType(combatType))) { + std::shared_ptr monster = creature->getMonster(); + if (!creature->isImmune(combatType) && !creature->hasCondition(Combat::DamageToConditionType(combatType)) && (monster && !monster->canWalkOnFieldType(combatType))) { cost += MAP_NORMALWALKCOST * 18; } /** * Make player try to avoid magic fields, when calculating pathing */ - const Player* player = creature.getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player && !field->isBlocking() && field->getDamage() != 0) { cost += MAP_NORMALWALKCOST * 18; } diff --git a/src/map/utils/astarnodes.hpp b/src/map/utils/astarnodes.hpp index e7cd421cca3..eba694de218 100644 --- a/src/map/utils/astarnodes.hpp +++ b/src/map/utils/astarnodes.hpp @@ -31,7 +31,7 @@ class AStarNodes { AStarNode* getNodeByPosition(uint32_t x, uint32_t y); static int_fast32_t getMapWalkCost(AStarNode* node, const Position &neighborPos, bool preferDiagonal = false); - static int_fast32_t getTileWalkCost(const Creature &creature, const Tile* tile); + static int_fast32_t getTileWalkCost(const std::shared_ptr &creature, std::shared_ptr tile); private: static constexpr int32_t MAX_NODES = 512; diff --git a/src/map/utils/qtreenode.cpp b/src/map/utils/qtreenode.cpp index 5351c0cb105..06cfef62f87 100644 --- a/src/map/utils/qtreenode.cpp +++ b/src/map/utils/qtreenode.cpp @@ -71,7 +71,7 @@ QTreeLeafNode* QTreeNode::getBestLeaf(uint32_t x, uint32_t y, uint32_t level) { return tempLeaf; } -void QTreeLeafNode::addCreature(Creature* c) { +void QTreeLeafNode::addCreature(std::shared_ptr c) { creature_list.push_back(c); if (c->getPlayer()) { @@ -79,7 +79,7 @@ void QTreeLeafNode::addCreature(Creature* c) { } } -void QTreeLeafNode::removeCreature(Creature* c) { +void QTreeLeafNode::removeCreature(std::shared_ptr c) { auto iter = std::find(creature_list.begin(), creature_list.end(), c); assert(iter != creature_list.end()); *iter = creature_list.back(); diff --git a/src/map/utils/qtreenode.hpp b/src/map/utils/qtreenode.hpp index 95d3ed18926..798e020fe03 100644 --- a/src/map/utils/qtreenode.hpp +++ b/src/map/utils/qtreenode.hpp @@ -21,7 +21,6 @@ class QTreeNode { virtual ~QTreeNode() { for (auto* ptr : child) { - delete ptr; } }; @@ -76,8 +75,8 @@ class QTreeLeafNode final : public QTreeNode { return array[z]; } - void addCreature(Creature* c); - void removeCreature(Creature* c); + void addCreature(std::shared_ptr c); + void removeCreature(std::shared_ptr c); private: static bool newLeaf; @@ -86,8 +85,8 @@ class QTreeLeafNode final : public QTreeNode { std::unique_ptr array[MAP_MAX_LAYERS] = {}; - std::vector creature_list; - std::vector player_list; + std::vector> creature_list; + std::vector> player_list; friend class Map; friend class MapCache; diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index f4b70f31d4d..ffb5586c1ae 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -61,7 +61,7 @@ namespace { return totalIterationCount; } - void addOutfitAndMountBytes(NetworkMessage &msg, const Item* item, const CustomAttribute* attribute, const std::string &head, const std::string &body, const std::string &legs, const std::string &feet, bool addAddon = false, bool addByte = false) { + void addOutfitAndMountBytes(NetworkMessage &msg, std::shared_ptr item, const CustomAttribute* attribute, const std::string &head, const std::string &body, const std::string &legs, const std::string &feet, bool addAddon = false, bool addByte = false) { auto look = attribute->getAttribute(); msg.add(look); if (look != 0) { @@ -106,9 +106,9 @@ namespace { * @param msg The network message to which the imbuement damage should be added. * @param player Pointer to the player for whom the imbuement damage should be handled. */ - void handleImbuementDamage(NetworkMessage &msg, Player* player) { + void handleImbuementDamage(NetworkMessage &msg, std::shared_ptr player) { bool imbueDmg = false; - Item* weapon = player->getWeapon(); + std::shared_ptr weapon = player->getWeapon(); if (weapon) { uint8_t slots = Item::items[weapon->getID()].imbuementSlot; if (slots > 0) { @@ -144,7 +144,7 @@ namespace { * * @param[in] player The pointer to the player whose equipped items are considered. */ - void calculateAbsorbValues(Player* player, NetworkMessage &msg, uint8_t &combats) { + void calculateAbsorbValues(std::shared_ptr player, NetworkMessage &msg, uint8_t &combats) { alignas(16) uint16_t damageReduction[COMBAT_COUNT] = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }; for (int32_t slot = CONST_SLOT_FIRST; slot <= CONST_SLOT_LAST; ++slot) { @@ -152,7 +152,7 @@ namespace { continue; } - Item* item = player->getInventoryItem(static_cast(slot)); + std::shared_ptr item = player->getInventoryItem(static_cast(slot)); if (!item) { continue; } @@ -309,7 +309,7 @@ void ProtocolGame::AddItem(NetworkMessage &msg, uint16_t id, uint8_t count, uint } } -void ProtocolGame::AddItem(NetworkMessage &msg, const Item* item) { +void ProtocolGame::AddItem(NetworkMessage &msg, std::shared_ptr item) { if (!item) { return; } @@ -343,7 +343,7 @@ void ProtocolGame::AddItem(NetworkMessage &msg, const Item* item) { if (it.isContainer()) { uint8_t containerType = 0; - const Container* container = item->getContainer(); + std::shared_ptr container = item->getContainer(); if (container && containerType == 0 && container->getHoldingPlayer() == player) { uint32_t lootFlags = 0; for (auto itt : player->quickLootContainers) { @@ -362,7 +362,7 @@ void ProtocolGame::AddItem(NetworkMessage &msg, const Item* item) { // Quiver ammo count if (container && containerType == 0 && item->isQuiver() && player->getThing(CONST_SLOT_RIGHT) == item) { uint16_t ammoTotal = 0; - for (Item* listItem : container->getItemList()) { + for (std::shared_ptr listItem : container->getItemList()) { if (player->getLevel() >= Item::items[listItem->getID()].minReqLevel) { ammoTotal += listItem->getItemCount(); } @@ -473,9 +473,9 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS } // dispatcher thread - Player* foundPlayer = g_game().getPlayerUniqueLogin(name); + std::shared_ptr foundPlayer = g_game().getPlayerUniqueLogin(name); if (!foundPlayer) { - player = new Player(getThis()); + player = std::make_shared(getThis()); player->setName(name); g_game().addPlayerUniqueLogin(player); @@ -600,7 +600,7 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS void ProtocolGame::connect(const std::string &playerName, OperatingSystem_t operatingSystem) { eventConnect = 0; - Player* foundPlayer = g_game().getPlayerUniqueLogin(playerName); + std::shared_ptr foundPlayer = g_game().getPlayerUniqueLogin(playerName); if (!foundPlayer) { disconnectClient("You are already logged in."); return; @@ -616,7 +616,7 @@ void ProtocolGame::connect(const std::string &playerName, OperatingSystem_t oper player->incrementReferenceCounter(); g_game().addPlayerUniqueLogin(player); - g_chat().removeUserFromAllChannels(*player); + g_chat().removeUserFromAllChannels(player); player->clearModalWindows(); player->setOperatingSystem(operatingSystem); player->isConnecting = false; @@ -733,7 +733,7 @@ void ProtocolGame::onRecvFirstMessage(NetworkMessage &msg) { std::string characterName = msg.getString(); - const Player* foundPlayer = g_game().getPlayerUniqueLogin(characterName); + std::shared_ptr foundPlayer = g_game().getPlayerUniqueLogin(characterName); if (foundPlayer && foundPlayer->client) { foundPlayer->client->disconnectClient("You are already connected through another client. Please use only one client at a time!"); } @@ -1330,13 +1330,13 @@ void ProtocolGame::parseHotkeyEquip(NetworkMessage &msg) { addGameTask(&Game::playerEquipItem, player->getID(), itemId, Item::items[itemId].upgradeClassification > 0, tier); } -void ProtocolGame::GetTileDescription(const Tile* tile, NetworkMessage &msg) { +void ProtocolGame::GetTileDescription(std::shared_ptr tile, NetworkMessage &msg) { if (oldProtocol) { msg.add(0x00); // Env effects } int32_t count; - Item* ground = tile->getGround(); + std::shared_ptr ground = tile->getGround(); if (ground) { AddItem(msg, ground); count = 1; @@ -1362,7 +1362,7 @@ void ProtocolGame::GetTileDescription(const Tile* tile, NetworkMessage &msg) { if (creatures) { bool playerAdded = false; for (auto it = creatures->rbegin(); it != creatures->rend(); ++it) { - const Creature* creature = *it; + std::shared_ptr creature = *it; if (!player->canSeeCreature(creature)) { continue; } @@ -1424,7 +1424,7 @@ void ProtocolGame::GetMapDescription(int32_t x, int32_t y, int32_t z, int32_t wi void ProtocolGame::GetFloorDescription(NetworkMessage &msg, int32_t x, int32_t y, int32_t z, int32_t width, int32_t height, int32_t offset, int32_t &skip) { for (int32_t nx = 0; nx < width; nx++) { for (int32_t ny = 0; ny < height; ny++) { - const Tile* tile = g_game().map.getTile(static_cast(x + nx + offset), static_cast(y + ny + offset), static_cast(z)); + std::shared_ptr tile = g_game().map.getTile(static_cast(x + nx + offset), static_cast(y + ny + offset), static_cast(z)); if (tile) { if (skip >= 0) { msg.addByte(skip); @@ -1458,8 +1458,8 @@ void ProtocolGame::checkCreatureAsKnown(uint32_t id, bool &known, uint32_t &remo continue; } // We need to protect party players from removing - Creature* creature = g_game().getCreatureByID(*it); - if (const Player * checkPlayer; + std::shared_ptr creature = g_game().getCreatureByID(*it); + if (std::shared_ptr checkPlayer; creature && (checkPlayer = creature->getPlayer()) != nullptr) { if (player->getParty() != checkPlayer->getParty() && !canSee(creature)) { removedKnown = *it; @@ -1486,7 +1486,7 @@ void ProtocolGame::checkCreatureAsKnown(uint32_t id, bool &known, uint32_t &remo } } -bool ProtocolGame::canSee(const Creature* c) const { +bool ProtocolGame::canSee(std::shared_ptr c) const { if (!c || !player || c->isRemoved()) { return false; } @@ -1973,7 +1973,7 @@ void ProtocolGame::sendSessionEndInformation(SessionEndInformations information) disconnect(); } -void ProtocolGame::sendItemInspection(uint16_t itemId, uint8_t itemCount, const Item* item, bool cyclopedia) { +void ProtocolGame::sendItemInspection(uint16_t itemId, uint8_t itemCount, std::shared_ptr item, bool cyclopedia) { if (oldProtocol) { return; } @@ -2398,7 +2398,7 @@ void ProtocolGame::sendTeamFinderList() { std::map teamFinder = g_game().getTeamFinderList(); msg.add(teamFinder.size()); for (auto it : teamFinder) { - const Player* leader = g_game().getPlayerByGUID(it.first); + std::shared_ptr leader = g_game().getPlayerByGUID(it.first); if (!leader) { return; } @@ -2417,7 +2417,7 @@ void ProtocolGame::sendTeamFinderList() { msg.addByte(teamAssemble->vocationIDs); msg.add(teamAssemble->teamSlots); for (auto itt : teamAssemble->membersMap) { - const Player* member = g_game().getPlayerByGUID(it.first); + std::shared_ptr member = g_game().getPlayerByGUID(it.first); if (member) { if (itt.first == player->getGUID()) { status = itt.second; @@ -2509,14 +2509,14 @@ void ProtocolGame::sendLeaderTeamFinder(bool reset) { uint16_t membersSize = 1; for (auto memberPair : teamAssemble->membersMap) { - const Player* member = g_game().getPlayerByGUID(memberPair.first); + std::shared_ptr member = g_game().getPlayerByGUID(memberPair.first); if (member) { membersSize += 1; } } msg.add(membersSize); - const Player* leader = g_game().getPlayerByGUID(teamAssemble->leaderGuid); + std::shared_ptr leader = g_game().getPlayerByGUID(teamAssemble->leaderGuid); if (!leader) { return; } @@ -2528,7 +2528,7 @@ void ProtocolGame::sendLeaderTeamFinder(bool reset) { msg.addByte(3); for (auto memberPair : teamAssemble->membersMap) { - const Player* member = g_game().getPlayerByGUID(memberPair.first); + std::shared_ptr member = g_game().getPlayerByGUID(memberPair.first); if (!member) { continue; } @@ -2601,7 +2601,7 @@ void ProtocolGame::createLeaderTeamFinder(NetworkMessage &msg) { teamAssemble->leaderGuid = player->getGUID(); if (teamAssemble->partyBool && player->getParty()) { - for (Player* member : player->getParty()->getMembers()) { + for (std::shared_ptr member : player->getParty()->getMembers()) { if (member && member->getGUID() != player->getGUID()) { members.insert({ member->getGUID(), 3 }); } @@ -2658,7 +2658,7 @@ void ProtocolGame::parseLeaderFinderWindow(NetworkMessage &msg) { } case 2: { uint32_t memberID = msg.get(); - const Player* member = g_game().getPlayerByGUID(memberID); + std::shared_ptr member = g_game().getPlayerByGUID(memberID); if (!member) { return; } @@ -2722,7 +2722,7 @@ void ProtocolGame::parseMemberFinderWindow(NetworkMessage &msg) { player->sendTeamFinderList(); } else { uint32_t leaderID = msg.get(); - const Player* leader = g_game().getPlayerByGUID(leaderID); + std::shared_ptr leader = g_game().getPlayerByGUID(leaderID); if (!leader) { return; } @@ -3142,7 +3142,7 @@ void ProtocolGame::sendChannelEvent(uint16_t channelId, const std::string &playe writeToOutputBuffer(msg); } -void ProtocolGame::sendCreatureOutfit(const Creature* creature, const Outfit_t &outfit) { +void ProtocolGame::sendCreatureOutfit(std::shared_ptr creature, const Outfit_t &outfit) { if (!canSee(creature)) { return; } @@ -3160,7 +3160,7 @@ void ProtocolGame::sendCreatureOutfit(const Creature* creature, const Outfit_t & writeToOutputBuffer(msg); } -void ProtocolGame::sendCreatureLight(const Creature* creature) { +void ProtocolGame::sendCreatureLight(std::shared_ptr creature) { if (!canSee(creature)) { return; } @@ -3170,7 +3170,7 @@ void ProtocolGame::sendCreatureLight(const Creature* creature) { writeToOutputBuffer(msg); } -void ProtocolGame::addCreatureIcon(NetworkMessage &msg, const Creature* creature) { +void ProtocolGame::addCreatureIcon(NetworkMessage &msg, std::shared_ptr creature) { if (!creature || !player || oldProtocol) { return; } @@ -3187,7 +3187,7 @@ void ProtocolGame::addCreatureIcon(NetworkMessage &msg, const Creature* creature } } -void ProtocolGame::sendCreatureIcon(const Creature* creature) { +void ProtocolGame::sendCreatureIcon(std::shared_ptr creature) { if (!creature || !player || oldProtocol) { return; } @@ -3219,7 +3219,7 @@ void ProtocolGame::sendTibiaTime(int32_t time) { writeToOutputBuffer(msg); } -void ProtocolGame::sendCreatureWalkthrough(const Creature* creature, bool walkthrough) { +void ProtocolGame::sendCreatureWalkthrough(std::shared_ptr creature, bool walkthrough) { if (!canSee(creature)) { return; } @@ -3231,7 +3231,7 @@ void ProtocolGame::sendCreatureWalkthrough(const Creature* creature, bool walkth writeToOutputBuffer(msg); } -void ProtocolGame::sendCreatureShield(const Creature* creature) { +void ProtocolGame::sendCreatureShield(std::shared_ptr creature) { if (!canSee(creature)) { return; } @@ -3243,7 +3243,7 @@ void ProtocolGame::sendCreatureShield(const Creature* creature) { writeToOutputBuffer(msg); } -void ProtocolGame::sendCreatureEmblem(const Creature* creature) { +void ProtocolGame::sendCreatureEmblem(std::shared_ptr creature) { if (!creature || !canSee(creature) || oldProtocol) { return; } @@ -3265,7 +3265,7 @@ void ProtocolGame::sendCreatureEmblem(const Creature* creature) { writeToOutputBuffer(msg); } -void ProtocolGame::sendCreatureSkull(const Creature* creature) { +void ProtocolGame::sendCreatureSkull(std::shared_ptr creature) { if (g_game().getWorldType() != WORLD_TYPE_PVP) { return; } @@ -3281,7 +3281,7 @@ void ProtocolGame::sendCreatureSkull(const Creature* creature) { writeToOutputBuffer(msg); } -void ProtocolGame::sendCreatureType(const Creature* creature, uint8_t creatureType) { +void ProtocolGame::sendCreatureType(std::shared_ptr creature, uint8_t creatureType) { NetworkMessage msg; msg.addByte(0x95); msg.add(creature->getID()); @@ -3290,7 +3290,7 @@ void ProtocolGame::sendCreatureType(const Creature* creature, uint8_t creatureTy } msg.addByte(creatureType); // type or any byte idk if (!oldProtocol && creatureType == CREATURETYPE_SUMMON_PLAYER) { - const Creature* master = creature->getMaster(); + std::shared_ptr master = creature->getMaster(); if (master) { msg.add(master->getID()); } else { @@ -3301,7 +3301,7 @@ void ProtocolGame::sendCreatureType(const Creature* creature, uint8_t creatureTy writeToOutputBuffer(msg); } -void ProtocolGame::sendCreatureSquare(const Creature* creature, SquareColor_t color) { +void ProtocolGame::sendCreatureSquare(std::shared_ptr creature, SquareColor_t color) { if (!canSee(creature)) { return; } @@ -3485,7 +3485,7 @@ void ProtocolGame::sendCyclopediaCharacterCombatStats() { msg.addByte(haveBlesses); msg.addByte(blessings); - const Item* weapon = player->getWeapon(); + std::shared_ptr weapon = player->getWeapon(); if (weapon) { const ItemType &it = Item::items[weapon->getID()]; if (it.weaponType == WEAPON_WAND) { @@ -3496,7 +3496,7 @@ void ProtocolGame::sendCyclopediaCharacterCombatStats() { } else if (it.weaponType == WEAPON_DISTANCE || it.weaponType == WEAPON_AMMO || it.weaponType == WEAPON_MISSILE) { int32_t attackValue = weapon->getAttack(); if (it.weaponType == WEAPON_AMMO) { - const Item* weaponItem = player->getWeapon(true); + std::shared_ptr weaponItem = player->getWeapon(true); if (weaponItem) { attackValue += weaponItem->getAttack(); } @@ -3802,7 +3802,7 @@ void ProtocolGame::sendCyclopediaCharacterInspection() { auto startInventory = msg.getBufferPosition(); msg.skipBytes(1); for (std::underlying_type::type slot = CONST_SLOT_FIRST; slot <= CONST_SLOT_LAST; slot++) { - Item* inventoryItem = player->getInventoryItem(static_cast(slot)); + std::shared_ptr inventoryItem = player->getInventoryItem(static_cast(slot)); if (inventoryItem) { ++inventoryItems; @@ -4152,7 +4152,7 @@ void ProtocolGame::sendChannelsDialog() { NetworkMessage msg; msg.addByte(0xAB); - const ChannelList &list = g_chat().getChannelList(*player); + const ChannelList &list = g_chat().getChannelList(player); msg.addByte(list.size()); for (ChatChannel* channel : list) { msg.add(channel->getId()); @@ -4226,7 +4226,7 @@ void ProtocolGame::sendUnjustifiedPoints(const uint8_t &dayProgress, const uint8 writeToOutputBuffer(msg); } -void ProtocolGame::sendContainer(uint8_t cid, const Container* container, bool hasParent, uint16_t firstIndex) { +void ProtocolGame::sendContainer(uint8_t cid, std::shared_ptr container, bool hasParent, uint16_t firstIndex) { if (!player) { return; } @@ -4311,7 +4311,7 @@ void ProtocolGame::sendContainer(uint8_t cid, const Container* container, bool h } if (!toSendCategory) { - Container* container = player->getContainerByID(cid); + std::shared_ptr container = player->getContainerByID(cid); if (container) { container->removeAttribute(ItemAttribute_t::STORE_INBOX_CATEGORY); } @@ -4336,7 +4336,7 @@ void ProtocolGame::sendLootContainers() { NetworkMessage msg; msg.addByte(0xC0); msg.addByte(player->quickLootFallbackToMainContainer ? 1 : 0); - std::map quickLoot; + std::map> quickLoot; for (auto it : player->quickLootContainers) { if (it.second && !it.second->isRemoved()) { quickLoot[it.first] = it.second; @@ -4351,7 +4351,7 @@ void ProtocolGame::sendLootContainers() { writeToOutputBuffer(msg); } -void ProtocolGame::sendLootStats(Item* item, uint8_t count) { +void ProtocolGame::sendLootStats(std::shared_ptr item, uint8_t count) { if (!item) { return; } @@ -4361,7 +4361,7 @@ void ProtocolGame::sendLootStats(Item* item, uint8_t count) { return; } - Item* lootedItem = nullptr; + std::shared_ptr lootedItem = nullptr; lootedItem = item->clone(); lootedItem->setItemCount(count); @@ -4375,7 +4375,7 @@ void ProtocolGame::sendLootStats(Item* item, uint8_t count) { lootedItem = nullptr; } -void ProtocolGame::sendShop(Npc* npc) { +void ProtocolGame::sendShop(std::shared_ptr npc) { NetworkMessage msg; msg.addByte(0x7A); msg.addString(npc->getName()); @@ -4532,7 +4532,7 @@ void ProtocolGame::sendMarketEnter(uint32_t depotId) { msg.addByte(static_cast(std::min(IOMarket::getPlayerOfferCount(player->getGUID()), std::numeric_limits::max()))); - DepotLocker* depotLocker = player->getDepotLocker(depotId); + std::shared_ptr depotLocker = player->getDepotLocker(depotId); if (!depotLocker) { msg.add(0x00); writeToOutputBuffer(msg); @@ -4600,19 +4600,20 @@ void ProtocolGame::updateCoinBalance() { } g_dispatcher().addTask( - std::bind([](uint32_t playerId) { - Player* threadPlayer = g_game().getPlayerByID(playerId); - if (threadPlayer && threadPlayer->getAccount()) { - - auto [coins, errCoin] = threadPlayer->getAccount()->getCoins(account::CoinType::COIN); - auto [transferCoins, errTCoin] = threadPlayer->getAccount()->getCoins(account::CoinType::TRANSFERABLE); - - threadPlayer->coinBalance = coins; - threadPlayer->coinTransferableBalance = transferCoins; - threadPlayer->sendCoinBalance(); - } - }, - player->getID()), + std::bind( + [](uint32_t playerId) { + auto threadPlayer = g_game().getPlayerByID(playerId); + if (threadPlayer && threadPlayer->getAccount()) { + auto [coins, errCoin] = threadPlayer->getAccount()->getCoins(account::CoinType::COIN); + auto [transferCoins, errTCoin] = threadPlayer->getAccount()->getCoins(account::CoinType::TRANSFERABLE); + + threadPlayer->coinBalance = coins; + threadPlayer->coinTransferableBalance = transferCoins; + threadPlayer->sendCoinBalance(); + } + }, + player->getID() + ), "ProtocolGame::updateCoinBalance" ); } @@ -5503,7 +5504,7 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { writeToOutputBuffer(msg); } -void ProtocolGame::sendTradeItemRequest(const std::string &traderName, const Item* item, bool ack) { +void ProtocolGame::sendTradeItemRequest(const std::string &traderName, std::shared_ptr item, bool ack) { NetworkMessage msg; if (ack) { @@ -5514,15 +5515,15 @@ void ProtocolGame::sendTradeItemRequest(const std::string &traderName, const Ite msg.addString(traderName); - if (const Container* tradeContainer = item->getContainer()) { - std::list listContainer { tradeContainer }; - std::list itemList { tradeContainer }; + if (std::shared_ptr tradeContainer = item->getContainer()) { + std::list> listContainer { tradeContainer }; + std::list> itemList { tradeContainer }; while (!listContainer.empty()) { - const Container* container = listContainer.front(); + std::shared_ptr container = listContainer.front(); listContainer.pop_front(); - for (Item* containerItem : container->getItemList()) { - Container* tmpContainer = containerItem->getContainer(); + for (std::shared_ptr containerItem : container->getItemList()) { + std::shared_ptr tmpContainer = containerItem->getContainer(); if (tmpContainer) { listContainer.push_back(tmpContainer); } @@ -5531,7 +5532,7 @@ void ProtocolGame::sendTradeItemRequest(const std::string &traderName, const Ite } msg.addByte(itemList.size()); - for (const Item* listItem : itemList) { + for (std::shared_ptr listItem : itemList) { AddItem(msg, listItem); } } else { @@ -5554,7 +5555,7 @@ void ProtocolGame::sendCloseContainer(uint8_t cid) { writeToOutputBuffer(msg); } -void ProtocolGame::sendCreatureTurn(const Creature* creature, uint32_t stackPos) { +void ProtocolGame::sendCreatureTurn(std::shared_ptr creature, uint32_t stackPos) { if (!canSee(creature)) { return; } @@ -5570,7 +5571,7 @@ void ProtocolGame::sendCreatureTurn(const Creature* creature, uint32_t stackPos) writeToOutputBuffer(msg); } -void ProtocolGame::sendCreatureSay(const Creature* creature, SpeakClasses type, const std::string &text, const Position* pos /* = nullptr*/) { +void ProtocolGame::sendCreatureSay(std::shared_ptr creature, SpeakClasses type, const std::string &text, const Position* pos /* = nullptr*/) { NetworkMessage msg; msg.addByte(0xAA); @@ -5584,7 +5585,7 @@ void ProtocolGame::sendCreatureSay(const Creature* creature, SpeakClasses type, } // Add level only for players - if (const Player* speaker = creature->getPlayer()) { + if (std::shared_ptr speaker = creature->getPlayer()) { msg.add(speaker->getLevel()); } else { msg.add(0x00); @@ -5606,7 +5607,7 @@ void ProtocolGame::sendCreatureSay(const Creature* creature, SpeakClasses type, writeToOutputBuffer(msg); } -void ProtocolGame::sendToChannel(const Creature* creature, SpeakClasses type, const std::string &text, uint16_t channelId) { +void ProtocolGame::sendToChannel(std::shared_ptr creature, SpeakClasses type, const std::string &text, uint16_t channelId) { NetworkMessage msg; msg.addByte(0xAA); @@ -5630,7 +5631,7 @@ void ProtocolGame::sendToChannel(const Creature* creature, SpeakClasses type, co } // Add level only for players - if (const Player* speaker = creature->getPlayer()) { + if (std::shared_ptr speaker = creature->getPlayer()) { msg.add(speaker->getLevel()); } else { msg.add(0x00); @@ -5648,7 +5649,7 @@ void ProtocolGame::sendToChannel(const Creature* creature, SpeakClasses type, co writeToOutputBuffer(msg); } -void ProtocolGame::sendPrivateMessage(const Player* speaker, SpeakClasses type, const std::string &text) { +void ProtocolGame::sendPrivateMessage(std::shared_ptr speaker, SpeakClasses type, const std::string &text) { NetworkMessage msg; msg.addByte(0xAA); static uint32_t statementId = 0; @@ -5683,7 +5684,7 @@ void ProtocolGame::sendCancelTarget() { writeToOutputBuffer(msg); } -void ProtocolGame::sendChangeSpeed(const Creature* creature, uint16_t speed) { +void ProtocolGame::sendChangeSpeed(std::shared_ptr creature, uint16_t speed) { NetworkMessage msg; msg.addByte(0x8F); msg.add(creature->getID()); @@ -5817,7 +5818,7 @@ void ProtocolGame::removeMagicEffect(const Position &pos, uint16_t type) { writeToOutputBuffer(msg); } -void ProtocolGame::sendCreatureHealth(const Creature* creature) { +void ProtocolGame::sendCreatureHealth(std::shared_ptr creature) { if (creature->isHealthHidden()) { return; } @@ -5834,7 +5835,7 @@ void ProtocolGame::sendCreatureHealth(const Creature* creature) { writeToOutputBuffer(msg); } -void ProtocolGame::sendPartyCreatureUpdate(const Creature* target) { +void ProtocolGame::sendPartyCreatureUpdate(std::shared_ptr target) { if (!player || oldProtocol) { return; } @@ -5852,7 +5853,7 @@ void ProtocolGame::sendPartyCreatureUpdate(const Creature* target) { writeToOutputBuffer(msg); } -void ProtocolGame::sendPartyCreatureShield(const Creature* target) { +void ProtocolGame::sendPartyCreatureShield(std::shared_ptr target) { uint32_t cid = target->getID(); if (knownCreatureSet.find(cid) == knownCreatureSet.end()) { sendPartyCreatureUpdate(target); @@ -5866,7 +5867,7 @@ void ProtocolGame::sendPartyCreatureShield(const Creature* target) { writeToOutputBuffer(msg); } -void ProtocolGame::sendPartyCreatureSkull(const Creature* target) { +void ProtocolGame::sendPartyCreatureSkull(std::shared_ptr target) { if (g_game().getWorldType() != WORLD_TYPE_PVP) { return; } @@ -5884,7 +5885,7 @@ void ProtocolGame::sendPartyCreatureSkull(const Creature* target) { writeToOutputBuffer(msg); } -void ProtocolGame::sendPartyCreatureHealth(const Creature* target, uint8_t healthPercent) { +void ProtocolGame::sendPartyCreatureHealth(std::shared_ptr target, uint8_t healthPercent) { uint32_t cid = target->getID(); if (knownCreatureSet.find(cid) == knownCreatureSet.end()) { sendPartyCreatureUpdate(target); @@ -5898,7 +5899,7 @@ void ProtocolGame::sendPartyCreatureHealth(const Creature* target, uint8_t healt writeToOutputBuffer(msg); } -void ProtocolGame::sendPartyPlayerMana(const Player* target, uint8_t manaPercent) { +void ProtocolGame::sendPartyPlayerMana(std::shared_ptr target, uint8_t manaPercent) { uint32_t cid = target->getID(); if (knownCreatureSet.find(cid) == knownCreatureSet.end()) { sendPartyCreatureUpdate(target); @@ -5916,7 +5917,7 @@ void ProtocolGame::sendPartyPlayerMana(const Player* target, uint8_t manaPercent writeToOutputBuffer(msg); } -void ProtocolGame::sendPartyCreatureShowStatus(const Creature* target, bool showStatus) { +void ProtocolGame::sendPartyCreatureShowStatus(std::shared_ptr target, bool showStatus) { uint32_t cid = target->getID(); if (knownCreatureSet.find(cid) == knownCreatureSet.end()) { sendPartyCreatureUpdate(target); @@ -5934,7 +5935,7 @@ void ProtocolGame::sendPartyCreatureShowStatus(const Creature* target, bool show writeToOutputBuffer(msg); } -void ProtocolGame::sendPartyPlayerVocation(const Player* target) { +void ProtocolGame::sendPartyPlayerVocation(std::shared_ptr target) { uint32_t cid = target->getID(); if (knownCreatureSet.find(cid) == knownCreatureSet.end()) { sendPartyCreatureUpdate(target); @@ -5953,7 +5954,7 @@ void ProtocolGame::sendPartyPlayerVocation(const Player* target) { writeToOutputBuffer(msg); } -void ProtocolGame::sendPlayerVocation(const Player* target) { +void ProtocolGame::sendPlayerVocation(std::shared_ptr target) { if (!player || oldProtocol) { return; } @@ -5982,7 +5983,7 @@ void ProtocolGame::sendMapDescription(const Position &pos) { writeToOutputBuffer(msg); } -void ProtocolGame::sendAddTileItem(const Position &pos, uint32_t stackpos, const Item* item) { +void ProtocolGame::sendAddTileItem(const Position &pos, uint32_t stackpos, std::shared_ptr item) { if (!canSee(pos)) { return; } @@ -5995,7 +5996,7 @@ void ProtocolGame::sendAddTileItem(const Position &pos, uint32_t stackpos, const writeToOutputBuffer(msg); } -void ProtocolGame::sendUpdateTileItem(const Position &pos, uint32_t stackpos, const Item* item) { +void ProtocolGame::sendUpdateTileItem(const Position &pos, uint32_t stackpos, std::shared_ptr item) { if (!canSee(pos)) { return; } @@ -6018,7 +6019,7 @@ void ProtocolGame::sendRemoveTileThing(const Position &pos, uint32_t stackpos) { writeToOutputBuffer(msg); } -void ProtocolGame::sendUpdateTile(const Tile* tile, const Position &pos) { +void ProtocolGame::sendUpdateTile(std::shared_ptr tile, const Position &pos) { if (!canSee(pos)) { return; } @@ -6080,7 +6081,7 @@ void ProtocolGame::sendAllowBugReport() { writeToOutputBuffer(msg); } -void ProtocolGame::sendAddCreature(const Creature* creature, const Position &pos, int32_t stackpos, bool isLogin) { +void ProtocolGame::sendAddCreature(std::shared_ptr creature, const Position &pos, int32_t stackpos, bool isLogin) { if (!canSee(pos)) { return; } @@ -6102,7 +6103,7 @@ void ProtocolGame::sendAddCreature(const Creature* creature, const Position &pos writeToOutputBuffer(msg); if (isLogin) { - if (const Player* creaturePlayer = creature->getPlayer()) { + if (std::shared_ptr creaturePlayer = creature->getPlayer()) { if (!creaturePlayer->isAccessPlayer() || creaturePlayer->getAccountType() == account::ACCOUNT_TYPE_NORMAL) { sendMagicEffect(pos, CONST_ME_TELEPORT); } @@ -6184,7 +6185,7 @@ void ProtocolGame::sendAddCreature(const Creature* creature, const Position &pos for (const VIPEntry &entry : vipEntries) { VipStatus_t vipStatus; - const Player* vipPlayer = g_game().getPlayerByGUID(entry.guid); + std::shared_ptr vipPlayer = g_game().getPlayerByGUID(entry.guid); if (!vipPlayer) { vipStatus = VIPSTATUS_OFFLINE; } else { @@ -6197,7 +6198,7 @@ void ProtocolGame::sendAddCreature(const Creature* creature, const Position &pos for (const VIPEntry &entry : vipEntries) { VipStatus_t vipStatus; - const Player* vipPlayer = g_game().getPlayerByGUID(entry.guid); + std::shared_ptr vipPlayer = g_game().getPlayerByGUID(entry.guid); if (!vipPlayer || vipPlayer->isInGhostMode()) { vipStatus = VIPSTATUS_OFFLINE; } else { @@ -6209,10 +6210,10 @@ void ProtocolGame::sendAddCreature(const Creature* creature, const Position &pos } sendInventoryIds(); - Item* slotItem = player->getInventoryItem(CONST_SLOT_BACKPACK); + std::shared_ptr slotItem = player->getInventoryItem(CONST_SLOT_BACKPACK); if (slotItem) { - Container* mainBackpack = slotItem->getContainer(); - Container* hasQuickLootContainer = player->getLootContainer(OBJECTCATEGORY_DEFAULT); + std::shared_ptr mainBackpack = slotItem->getContainer(); + std::shared_ptr hasQuickLootContainer = player->getLootContainer(OBJECTCATEGORY_DEFAULT); if (mainBackpack && !hasQuickLootContainer) { player->setLootContainer(OBJECTCATEGORY_DEFAULT, mainBackpack); sendInventoryItem(CONST_SLOT_BACKPACK, player->getInventoryItem(CONST_SLOT_BACKPACK)); @@ -6236,7 +6237,7 @@ void ProtocolGame::sendAddCreature(const Creature* creature, const Position &pos } } -void ProtocolGame::sendMoveCreature(const Creature* creature, const Position &newPos, int32_t newStackPos, const Position &oldPos, int32_t oldStackPos, bool teleport) { +void ProtocolGame::sendMoveCreature(std::shared_ptr creature, const Position &newPos, int32_t newStackPos, const Position &oldPos, int32_t oldStackPos, bool teleport) { if (creature == player) { if (oldStackPos >= 10) { sendMapDescription(newPos); @@ -6298,7 +6299,7 @@ void ProtocolGame::sendMoveCreature(const Creature* creature, const Position &ne } } -void ProtocolGame::sendInventoryItem(Slots_t slot, const Item* item) { +void ProtocolGame::sendInventoryItem(Slots_t slot, std::shared_ptr item) { NetworkMessage msg; if (item) { msg.addByte(0x78); @@ -6340,7 +6341,7 @@ void ProtocolGame::sendInventoryIds() { writeToOutputBuffer(msg); } -void ProtocolGame::sendAddContainerItem(uint8_t cid, uint16_t slot, const Item* item) { +void ProtocolGame::sendAddContainerItem(uint8_t cid, uint16_t slot, std::shared_ptr item) { NetworkMessage msg; msg.addByte(0x70); msg.addByte(cid); @@ -6349,7 +6350,7 @@ void ProtocolGame::sendAddContainerItem(uint8_t cid, uint16_t slot, const Item* writeToOutputBuffer(msg); } -void ProtocolGame::sendUpdateContainerItem(uint8_t cid, uint16_t slot, const Item* item) { +void ProtocolGame::sendUpdateContainerItem(uint8_t cid, uint16_t slot, std::shared_ptr item) { NetworkMessage msg; msg.addByte(0x71); msg.addByte(cid); @@ -6358,7 +6359,7 @@ void ProtocolGame::sendUpdateContainerItem(uint8_t cid, uint16_t slot, const Ite writeToOutputBuffer(msg); } -void ProtocolGame::sendRemoveContainerItem(uint8_t cid, uint16_t slot, const Item* lastItem) { +void ProtocolGame::sendRemoveContainerItem(uint8_t cid, uint16_t slot, std::shared_ptr lastItem) { NetworkMessage msg; msg.addByte(0x72); msg.addByte(cid); @@ -6371,7 +6372,7 @@ void ProtocolGame::sendRemoveContainerItem(uint8_t cid, uint16_t slot, const Ite writeToOutputBuffer(msg); } -void ProtocolGame::sendTextWindow(uint32_t windowTextId, Item* item, uint16_t maxlen, bool canWrite) { +void ProtocolGame::sendTextWindow(uint32_t windowTextId, std::shared_ptr item, uint16_t maxlen, bool canWrite) { NetworkMessage msg; msg.addByte(0x96); msg.add(windowTextId); @@ -6644,7 +6645,7 @@ void ProtocolGame::sendOutfitWindow() { writeToOutputBuffer(msg); } -void ProtocolGame::sendPodiumWindow(const Item* podium, const Position &position, uint16_t itemId, uint8_t stackpos) { +void ProtocolGame::sendPodiumWindow(std::shared_ptr podium, const Position &position, uint16_t itemId, uint8_t stackpos) { if (!podium || oldProtocol) { g_logger().error("[{}] item is nullptr", __FUNCTION__); return; @@ -6989,9 +6990,9 @@ void ProtocolGame::sendModalWindow(const ModalWindow &modalWindow) { } ////////////// Add common messages -void ProtocolGame::AddCreature(NetworkMessage &msg, const Creature* creature, bool known, uint32_t remove) { +void ProtocolGame::AddCreature(NetworkMessage &msg, std::shared_ptr creature, bool known, uint32_t remove) { CreatureType_t creatureType = creature->getType(); - const Player* otherPlayer = creature->getPlayer(); + std::shared_ptr otherPlayer = creature->getPlayer(); if (known) { msg.add(0x62); @@ -7007,7 +7008,7 @@ void ProtocolGame::AddCreature(NetworkMessage &msg, const Creature* creature, bo } if (!oldProtocol && creatureType == CREATURETYPE_SUMMON_PLAYER) { - if (const Creature* master = creature->getMaster()) { + if (std::shared_ptr master = creature->getMaster()) { msg.add(master->getID()); } else { msg.add(0x00); @@ -7059,8 +7060,8 @@ void ProtocolGame::AddCreature(NetworkMessage &msg, const Creature* creature, bo } if (!oldProtocol && creatureType == CREATURETYPE_MONSTER) { - if (const Creature* master = creature->getMaster()) { - if (const Player* masterPlayer = master->getPlayer()) { + if (std::shared_ptr master = creature->getMaster()) { + if (std::shared_ptr masterPlayer = master->getPlayer()) { creatureType = CREATURETYPE_SUMMON_PLAYER; } } @@ -7073,7 +7074,7 @@ void ProtocolGame::AddCreature(NetworkMessage &msg, const Creature* creature, bo } if (!oldProtocol && creatureType == CREATURETYPE_SUMMON_PLAYER) { - if (const Creature* master = creature->getMaster()) { + if (std::shared_ptr master = creature->getMaster()) { msg.add(master->getID()); } else { msg.add(0x00); @@ -7081,7 +7082,7 @@ void ProtocolGame::AddCreature(NetworkMessage &msg, const Creature* creature, bo } if (!oldProtocol && creatureType == CREATURETYPE_PLAYER) { - if (const Player* otherCreature = creature->getPlayer()) { + if (std::shared_ptr otherCreature = creature->getPlayer()) { msg.addByte(otherCreature->getVocation()->getClientId()); } else { msg.addByte(0); @@ -7260,7 +7261,7 @@ void ProtocolGame::addImbuementInfo(NetworkMessage &msg, uint16_t imbuementId) c msg.add(baseImbuement->protectionPrice); } -void ProtocolGame::openImbuementWindow(Item* item) { +void ProtocolGame::openImbuementWindow(std::shared_ptr item) { if (!item || item->isRemoved()) { return; } @@ -7373,7 +7374,7 @@ void ProtocolGame::updatePartyTrackerAnalyzer(const Party* party) { msg.addByte(static_cast(party->membersData.size())); for (const PartyAnalyzer* analyzer : party->membersData) { msg.add(analyzer->id); - if (const Player* member = g_game().getPlayerByID(analyzer->id); + if (std::shared_ptr member = g_game().getPlayerByID(analyzer->id); !member || !member->getParty() || member->getParty() != party) { msg.addByte(0); } else { @@ -7399,7 +7400,7 @@ void ProtocolGame::updatePartyTrackerAnalyzer(const Party* party) { writeToOutputBuffer(msg); } -void ProtocolGame::AddCreatureLight(NetworkMessage &msg, const Creature* creature) { +void ProtocolGame::AddCreatureLight(NetworkMessage &msg, std::shared_ptr creature) { LightInfo lightInfo = creature->getCreatureLight(); msg.addByte(0x8D); @@ -7419,7 +7420,7 @@ void ProtocolGame::RemoveTileThing(NetworkMessage &msg, const Position &pos, uin msg.addByte(stackpos); } -void ProtocolGame::sendKillTrackerUpdate(Container* corpse, const std::string &name, const Outfit_t creatureOutfit) { +void ProtocolGame::sendKillTrackerUpdate(std::shared_ptr corpse, const std::string &name, const Outfit_t creatureOutfit) { if (oldProtocol) { return; } @@ -7446,7 +7447,7 @@ void ProtocolGame::sendKillTrackerUpdate(Container* corpse, const std::string &n writeToOutputBuffer(msg); } -void ProtocolGame::sendUpdateSupplyTracker(const Item* item) { +void ProtocolGame::sendUpdateSupplyTracker(std::shared_ptr item) { if (oldProtocol || !player || !item) { return; } @@ -7514,14 +7515,14 @@ void ProtocolGame::sendTaskHuntingData(const TaskHuntingSlot* slot) { } else if (slot->state == PreyTaskDataState_Inactive) { // Empty } else if (slot->state == PreyTaskDataState_Selection) { - const Player* user = player; + std::shared_ptr user = player; msg.add(static_cast(slot->raceIdList.size())); std::for_each(slot->raceIdList.begin(), slot->raceIdList.end(), [&msg, user](uint16_t raceid) { msg.add(raceid); msg.addByte(user->isCreatureUnlockedOnTaskHunting(g_monsters().getMonsterTypeByRaceId(raceid)) ? 0x01 : 0x00); }); } else if (slot->state == PreyTaskDataState_ListSelection) { - const Player* user = player; + std::shared_ptr user = player; const std::map bestiaryList = g_game().getBestiaryList(); msg.add(static_cast(bestiaryList.size())); std::for_each(bestiaryList.begin(), bestiaryList.end(), [&msg, user](auto mType) { @@ -7570,7 +7571,7 @@ void ProtocolGame::sendTaskHuntingData(const TaskHuntingSlot* slot) { writeToOutputBuffer(msg); } -void ProtocolGame::MoveUpCreature(NetworkMessage &msg, const Creature* creature, const Position &newPos, const Position &oldPos) { +void ProtocolGame::MoveUpCreature(NetworkMessage &msg, std::shared_ptr creature, const Position &newPos, const Position &oldPos) { if (creature != player) { return; } @@ -7614,7 +7615,7 @@ void ProtocolGame::MoveUpCreature(NetworkMessage &msg, const Creature* creature, GetMapDescription(oldPos.x - MAP_MAX_CLIENT_VIEW_PORT_X, oldPos.y - MAP_MAX_CLIENT_VIEW_PORT_Y, newPos.z, (MAP_MAX_CLIENT_VIEW_PORT_X + 1) * 2, 1, msg); } -void ProtocolGame::MoveDownCreature(NetworkMessage &msg, const Creature* creature, const Position &newPos, const Position &oldPos) { +void ProtocolGame::MoveDownCreature(NetworkMessage &msg, std::shared_ptr creature, const Position &newPos, const Position &oldPos) { if (creature != player) { return; } @@ -7733,7 +7734,7 @@ void ProtocolGame::parseInventoryImbuements(NetworkMessage &msg) { addGameTask(&Game::playerRequestInventoryImbuements, player->getID(), isTrackerOpen); } -void ProtocolGame::sendInventoryImbuements(const std::map items) { +void ProtocolGame::sendInventoryImbuements(const std::map> items) { if (oldProtocol) { return; } @@ -7771,7 +7772,7 @@ void ProtocolGame::sendInventoryImbuements(const std::map items) msg.add(imbuement->getIconID()); msg.add(imbuementInfo.duration); - const Tile* playerTile = player->getTile(); + std::shared_ptr playerTile = player->getTile(); // Check if the player is in a protection zone bool isInProtectionZone = playerTile && playerTile->hasFlag(TILESTATE_PROTECTIONZONE); // Check if the player is in fight mode @@ -7822,7 +7823,7 @@ void ProtocolGame::sendItemsPrice() { writeToOutputBuffer(msg); } -void ProtocolGame::reloadCreature(const Creature* creature) { +void ProtocolGame::reloadCreature(std::shared_ptr creature) { if (!creature || !canSee(creature)) { return; } @@ -8055,7 +8056,7 @@ void ProtocolGame::parseOpenParentContainer(NetworkMessage &msg) { addGameTask(&Game::playerRequestOpenContainerFromDepotSearch, player->getID(), pos); } -void ProtocolGame::sendUpdateCreature(const Creature* creature) { +void ProtocolGame::sendUpdateCreature(std::shared_ptr creature) { if (oldProtocol || !creature || !player) { return; } @@ -8082,7 +8083,7 @@ void ProtocolGame::sendUpdateCreature(const Creature* creature) { writeToOutputBuffer(msg); } -void ProtocolGame::getForgeInfoMap(const Item* item, std::map> &itemsMap) const { +void ProtocolGame::getForgeInfoMap(std::shared_ptr item, std::map> &itemsMap) const { std::map itemInfo; itemInfo.insert({ item->getTier(), item->getItemCount() }); auto [first, inserted] = itemsMap.try_emplace(item->getID(), itemInfo); @@ -8102,7 +8103,7 @@ void ProtocolGame::sendForgeSkillStats(NetworkMessage &msg) const { std::vector slots { CONST_SLOT_LEFT, CONST_SLOT_ARMOR, CONST_SLOT_HEAD }; for (const auto &slot : slots) { double_t skill = 0; - if (const Item* item = player->getInventoryItem(slot); item) { + if (std::shared_ptr item = player->getInventoryItem(slot); item) { const ItemType &it = Item::items[item->getID()]; if (it.isWeapon()) { skill = item->getFatalChance() * 100; @@ -8378,7 +8379,7 @@ void ProtocolGame::sendPodiumDetails(NetworkMessage &msg, const phmap::parallel_ } } -void ProtocolGame::sendMonsterPodiumWindow(const Item* podium, const Position &position, uint16_t itemId, uint8_t stackPos) { +void ProtocolGame::sendMonsterPodiumWindow(std::shared_ptr podium, const Position &position, uint16_t itemId, uint8_t stackPos) { if (!podium || oldProtocol) { g_logger().error("[{}] item is nullptr", __FUNCTION__); return; diff --git a/src/server/network/protocol/protocolgame.hpp b/src/server/network/protocol/protocolgame.hpp index 1b57e3c130d..a167ab9559e 100644 --- a/src/server/network/protocol/protocolgame.hpp +++ b/src/server/network/protocol/protocolgame.hpp @@ -60,7 +60,7 @@ class ProtocolGame final : public Protocol { void login(const std::string &name, uint32_t accnumber, OperatingSystem_t operatingSystem); void logout(bool displayEffect, bool forced); - void AddItem(NetworkMessage &msg, const Item* item); + void AddItem(NetworkMessage &msg, std::shared_ptr item); void AddItem(NetworkMessage &msg, uint16_t id, uint8_t count, uint8_t tier); uint16_t getVersion() const { @@ -86,7 +86,7 @@ class ProtocolGame final : public Protocol { void checkCreatureAsKnown(uint32_t id, bool &known, uint32_t &removedKnown); bool canSee(int32_t x, int32_t y, int32_t z) const; - bool canSee(const Creature*) const; + bool canSee(std::shared_ptr) const; bool canSee(const Position &pos) const; // we have all the parse methods @@ -124,7 +124,7 @@ class ProtocolGame final : public Protocol { void sendSessionEndInformation(SessionEndInformations information); - void sendItemInspection(uint16_t itemId, uint8_t itemCount, const Item* item, bool cyclopedia); + void sendItemInspection(uint16_t itemId, uint8_t itemCount, std::shared_ptr item, bool cyclopedia); void parseInspectionObject(NetworkMessage &msg); void parseCyclopediaCharacterInfo(NetworkMessage &msg); @@ -232,12 +232,12 @@ class ProtocolGame final : public Protocol { void sendChannel(uint16_t channelId, const std::string &channelName, const UsersMap* channelUsers, const InvitedMap* invitedUsers); void sendOpenPrivateChannel(const std::string &receiver); void sendExperienceTracker(int64_t rawExp, int64_t finalExp); - void sendToChannel(const Creature* creature, SpeakClasses type, const std::string &text, uint16_t channelId); - void sendPrivateMessage(const Player* speaker, SpeakClasses type, const std::string &text); + void sendToChannel(std::shared_ptr creature, SpeakClasses type, const std::string &text, uint16_t channelId); + void sendPrivateMessage(std::shared_ptr speaker, SpeakClasses type, const std::string &text); void sendIcons(uint32_t icons); void sendFYIBox(const std::string &message); - void openImbuementWindow(Item* item); + void openImbuementWindow(std::shared_ptr item); void sendImbuementResult(const std::string message); void closeImbuementWindow(); @@ -266,7 +266,7 @@ class ProtocolGame final : public Protocol { void parseSendBosstiarySlots(); void parseBosstiarySlot(NetworkMessage &msg); void sendPodiumDetails(NetworkMessage &msg, const phmap::parallel_flat_hash_set &toSendMonsters, bool isBoss) const; - void sendMonsterPodiumWindow(const Item* podium, const Position &position, uint16_t itemId, uint8_t stackPos); + void sendMonsterPodiumWindow(std::shared_ptr podium, const Position &position, uint16_t itemId, uint8_t stackPos); void parseSetMonsterPodium(NetworkMessage &msg) const; void sendBosstiaryCooldownTimer(); void sendBosstiaryEntryChanged(uint32_t bossid); @@ -276,28 +276,28 @@ class ProtocolGame final : public Protocol { void sendMagicEffect(const Position &pos, uint16_t type); void removeMagicEffect(const Position &pos, uint16_t type); void sendRestingStatus(uint8_t protection); - void sendCreatureHealth(const Creature* creature); - void sendPartyCreatureUpdate(const Creature* target); - void sendPartyCreatureShield(const Creature* target); - void sendPartyCreatureSkull(const Creature* target); - void sendPartyCreatureHealth(const Creature* target, uint8_t healthPercent); - void sendPartyPlayerMana(const Player* target, uint8_t manaPercent); - void sendPartyCreatureShowStatus(const Creature* target, bool showStatus); - void sendPartyPlayerVocation(const Player* target); - void sendPlayerVocation(const Player* target); + void sendCreatureHealth(std::shared_ptr creature); + void sendPartyCreatureUpdate(std::shared_ptr target); + void sendPartyCreatureShield(std::shared_ptr target); + void sendPartyCreatureSkull(std::shared_ptr target); + void sendPartyCreatureHealth(std::shared_ptr target, uint8_t healthPercent); + void sendPartyPlayerMana(std::shared_ptr target, uint8_t manaPercent); + void sendPartyCreatureShowStatus(std::shared_ptr target, bool showStatus); + void sendPartyPlayerVocation(std::shared_ptr target); + void sendPlayerVocation(std::shared_ptr target); void sendSkills(); void sendPing(); void sendPingBack(); - void sendCreatureTurn(const Creature* creature, uint32_t stackpos); - void sendCreatureSay(const Creature* creature, SpeakClasses type, const std::string &text, const Position* pos = nullptr); + void sendCreatureTurn(std::shared_ptr creature, uint32_t stackpos); + void sendCreatureSay(std::shared_ptr creature, SpeakClasses type, const std::string &text, const Position* pos = nullptr); // Unjust Panel void sendUnjustifiedPoints(const uint8_t &dayProgress, const uint8_t &dayLeft, const uint8_t &weekProgress, const uint8_t &weekLeft, const uint8_t &monthProgress, const uint8_t &monthLeft, const uint8_t &skullDuration); void sendCancelWalk(); - void sendChangeSpeed(const Creature* creature, uint16_t speed); + void sendChangeSpeed(std::shared_ptr creature, uint16_t speed); void sendCancelTarget(); - void sendCreatureOutfit(const Creature* creature, const Outfit_t &outfit); + void sendCreatureOutfit(std::shared_ptr creature, const Outfit_t &outfit); void sendStats(); void sendBasicData(); void sendTextMessage(const TextMessage &message); @@ -320,13 +320,13 @@ class ProtocolGame final : public Protocol { void sendCyclopediaCharacterBadges(); void sendCyclopediaCharacterTitles(); - void sendCreatureWalkthrough(const Creature* creature, bool walkthrough); - void sendCreatureShield(const Creature* creature); - void sendCreatureEmblem(const Creature* creature); - void sendCreatureSkull(const Creature* creature); - void sendCreatureType(const Creature* creature, uint8_t creatureType); + void sendCreatureWalkthrough(std::shared_ptr creature, bool walkthrough); + void sendCreatureShield(std::shared_ptr creature); + void sendCreatureEmblem(std::shared_ptr creature); + void sendCreatureSkull(std::shared_ptr creature); + void sendCreatureType(std::shared_ptr creature, uint8_t creatureType); - void sendShop(Npc* npc); + void sendShop(std::shared_ptr npc); void sendCloseShop(); void sendClientCheck(); void sendGameNews(); @@ -342,15 +342,15 @@ class ProtocolGame final : public Protocol { void sendMarketCancelOffer(const MarketOfferEx &offer); void sendMarketBrowseOwnHistory(const HistoryMarketOfferList &buyOffers, const HistoryMarketOfferList &sellOffers); void sendMarketDetail(uint16_t itemId, uint8_t tier); - void sendTradeItemRequest(const std::string &traderName, const Item* item, bool ack); + void sendTradeItemRequest(const std::string &traderName, std::shared_ptr item, bool ack); void sendCloseTrade(); void updatePartyTrackerAnalyzer(const Party* party); void sendTextWindow(uint32_t windowTextId, uint32_t itemId, const std::string &text); - void sendTextWindow(uint32_t windowTextId, Item* item, uint16_t maxlen, bool canWrite); + void sendTextWindow(uint32_t windowTextId, std::shared_ptr item, uint16_t maxlen, bool canWrite); void sendHouseWindow(uint32_t windowTextId, const std::string &text); void sendOutfitWindow(); - void sendPodiumWindow(const Item* podium, const Position &position, uint16_t itemId, uint8_t stackpos); + void sendPodiumWindow(std::shared_ptr podium, const Position &position, uint16_t itemId, uint8_t stackpos); void sendUpdatedVIPStatus(uint32_t guid, VipStatus_t newStatus); void sendVIP(uint32_t guid, const std::string &name, const std::string &description, uint32_t icon, bool notify, VipStatus_t status); @@ -360,13 +360,13 @@ class ProtocolGame final : public Protocol { void sendFightModes(); - void sendCreatureLight(const Creature* creature); - void sendCreatureIcon(const Creature* creature); - void sendUpdateCreature(const Creature* creature); + void sendCreatureLight(std::shared_ptr creature); + void sendCreatureIcon(std::shared_ptr creature); + void sendUpdateCreature(std::shared_ptr creature); void sendWorldLight(const LightInfo &lightInfo); void sendTibiaTime(int32_t time); - void sendCreatureSquare(const Creature* creature, SquareColor_t color); + void sendCreatureSquare(std::shared_ptr creature, SquareColor_t color); void sendSpellCooldown(uint16_t spellId, uint32_t time); void sendSpellGroupCooldown(SpellGroup_t groupId, uint32_t time); @@ -381,36 +381,36 @@ class ProtocolGame final : public Protocol { // tiles void sendMapDescription(const Position &pos); - void sendAddTileItem(const Position &pos, uint32_t stackpos, const Item* item); - void sendUpdateTileItem(const Position &pos, uint32_t stackpos, const Item* item); + void sendAddTileItem(const Position &pos, uint32_t stackpos, std::shared_ptr item); + void sendUpdateTileItem(const Position &pos, uint32_t stackpos, std::shared_ptr item); void sendRemoveTileThing(const Position &pos, uint32_t stackpos); - void sendUpdateTile(const Tile* tile, const Position &pos); + void sendUpdateTile(std::shared_ptr tile, const Position &pos); - void sendAddCreature(const Creature* creature, const Position &pos, int32_t stackpos, bool isLogin); - void sendMoveCreature(const Creature* creature, const Position &newPos, int32_t newStackPos, const Position &oldPos, int32_t oldStackPos, bool teleport); + void sendAddCreature(std::shared_ptr creature, const Position &pos, int32_t stackpos, bool isLogin); + void sendMoveCreature(std::shared_ptr creature, const Position &newPos, int32_t newStackPos, const Position &oldPos, int32_t oldStackPos, bool teleport); // containers - void sendAddContainerItem(uint8_t cid, uint16_t slot, const Item* item); - void sendUpdateContainerItem(uint8_t cid, uint16_t slot, const Item* item); - void sendRemoveContainerItem(uint8_t cid, uint16_t slot, const Item* lastItem); + void sendAddContainerItem(uint8_t cid, uint16_t slot, std::shared_ptr item); + void sendUpdateContainerItem(uint8_t cid, uint16_t slot, std::shared_ptr item); + void sendRemoveContainerItem(uint8_t cid, uint16_t slot, std::shared_ptr lastItem); - void sendContainer(uint8_t cid, const Container* container, bool hasParent, uint16_t firstIndex); + void sendContainer(uint8_t cid, std::shared_ptr container, bool hasParent, uint16_t firstIndex); void sendCloseContainer(uint8_t cid); // quickloot void sendLootContainers(); - void sendLootStats(Item* item, uint8_t count); + void sendLootStats(std::shared_ptr item, uint8_t count); // inventory - void sendInventoryItem(Slots_t slot, const Item* item); + void sendInventoryItem(Slots_t slot, std::shared_ptr item); void sendInventoryIds(); // messages void sendModalWindow(const ModalWindow &modalWindow); // analyzers - void sendKillTrackerUpdate(Container* corpse, const std::string &name, const Outfit_t creatureOutfit); - void sendUpdateSupplyTracker(const Item* item); + void sendKillTrackerUpdate(std::shared_ptr corpse, const std::string &name, const Outfit_t creatureOutfit); + void sendUpdateSupplyTracker(std::shared_ptr item); void sendUpdateImpactTracker(CombatType_t type, int32_t amount); void sendUpdateInputAnalyzer(CombatType_t type, int32_t amount, std::string target); @@ -419,7 +419,7 @@ class ProtocolGame final : public Protocol { // Help functions // translate a tile to clientreadable format - void GetTileDescription(const Tile* tile, NetworkMessage &msg); + void GetTileDescription(std::shared_ptr tile, NetworkMessage &msg); // translate a floor to clientreadable format void GetFloorDescription(NetworkMessage &msg, int32_t x, int32_t y, int32_t z, int32_t width, int32_t height, int32_t offset, int32_t &skip); @@ -427,7 +427,7 @@ class ProtocolGame final : public Protocol { // translate a map area to clientreadable format void GetMapDescription(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height, NetworkMessage &msg); - void AddCreature(NetworkMessage &msg, const Creature* creature, bool known, uint32_t remove); + void AddCreature(NetworkMessage &msg, std::shared_ptr creature, bool known, uint32_t remove); void AddPlayerStats(NetworkMessage &msg); void AddOutfit(NetworkMessage &msg, const Outfit_t &outfit, bool addMount = true); void AddPlayerSkills(NetworkMessage &msg); @@ -435,15 +435,15 @@ class ProtocolGame final : public Protocol { void sendPremiumTrigger(); void sendMessageDialog(const std::string &message); void AddWorldLight(NetworkMessage &msg, LightInfo lightInfo); - void AddCreatureLight(NetworkMessage &msg, const Creature* creature); + void AddCreatureLight(NetworkMessage &msg, std::shared_ptr creature); // tiles static void RemoveTileThing(NetworkMessage &msg, const Position &pos, uint32_t stackpos); void sendTaskHuntingData(const TaskHuntingSlot* slot); - void MoveUpCreature(NetworkMessage &msg, const Creature* creature, const Position &newPos, const Position &oldPos); - void MoveDownCreature(NetworkMessage &msg, const Creature* creature, const Position &newPos, const Position &oldPos); + void MoveUpCreature(NetworkMessage &msg, std::shared_ptr creature, const Position &newPos, const Position &oldPos); + void MoveDownCreature(NetworkMessage &msg, std::shared_ptr creature, const Position &newPos, const Position &oldPos); // shop void AddHiddenShopItem(NetworkMessage &msg); @@ -456,12 +456,12 @@ class ProtocolGame final : public Protocol { void sendFeatures(); void parseInventoryImbuements(NetworkMessage &msg); - void sendInventoryImbuements(const std::map items); + void sendInventoryImbuements(const std::map> items); // reloadCreature - void reloadCreature(const Creature* creature); + void reloadCreature(std::shared_ptr creature); - void getForgeInfoMap(const Item* item, std::map> &itemsMap) const; + void getForgeInfoMap(std::shared_ptr item, std::map> &itemsMap) const; // Wheel void parseOpenWheel(NetworkMessage &msg); @@ -472,7 +472,7 @@ class ProtocolGame final : public Protocol { friend class PlayerWheel; phmap::flat_hash_set knownCreatureSet; - Player* player = nullptr; + std::shared_ptr player = nullptr; uint32_t eventConnect = 0; uint32_t challengeTimestamp = 0; @@ -497,7 +497,7 @@ class ProtocolGame final : public Protocol { void sendSpecialContainersAvailable(); void addBless(); void parsePacketDead(uint8_t recvbyte); - void addCreatureIcon(NetworkMessage &msg, const Creature* creature); + void addCreatureIcon(NetworkMessage &msg, std::shared_ptr creature); void sendSingleSoundEffect(const Position &pos, SoundEffect_t id, SourceEffect_t source); void sendDoubleSoundEffect(const Position &pos, SoundEffect_t mainSoundId, SourceEffect_t mainSource, SoundEffect_t secondarySoundId, SourceEffect_t secondarySource); diff --git a/tests/fixture/lib/logging/in_memory_logger.hpp b/tests/fixture/lib/logging/in_memory_logger.hpp index 581a453ee80..0b1f9972888 100644 --- a/tests/fixture/lib/logging/in_memory_logger.hpp +++ b/tests/fixture/lib/logging/in_memory_logger.hpp @@ -18,67 +18,67 @@ namespace di = boost::di; class InMemoryLogger : public Logger { - private: - struct LogEntry { - std::string level; - std::string message; - }; - - public: - mutable std::vector logs; - - InMemoryLogger() = default; - InMemoryLogger(const InMemoryLogger &) {} - InMemoryLogger(const InMemoryLogger &&) {} - - static di::extension::injector<> & install(di::extension::injector<> &injector) { - injector.install(di::bind.to().in(di::singleton)); - return injector; - } - - InMemoryLogger &reset() { - logs.clear(); - return *this; - } - - bool hasLogEntry(const std::string& lvl, const std::string& expectedMsg) const { - for (const auto& entry : logs) { - if (entry.level == lvl && entry.message == expectedMsg) { - return true; - } +private: + struct LogEntry { + std::string level; + std::string message; + }; + +public: + mutable std::vector logs; + + InMemoryLogger() = default; + InMemoryLogger(const InMemoryLogger &) { } + InMemoryLogger(const InMemoryLogger &&) { } + + static di::extension::injector<> &install(di::extension::injector<> &injector) { + injector.install(di::bind.to().in(di::singleton)); + return injector; + } + + InMemoryLogger &reset() { + logs.clear(); + return *this; + } + + bool hasLogEntry(const std::string &lvl, const std::string &expectedMsg) const { + for (const auto &entry : logs) { + if (entry.level == lvl && entry.message == expectedMsg) { + return true; } - - return false; } - void setLevel(const std::string &name) override { - // For the stub, setting a level might not have any behavior. - // But you can implement level filtering if you like. - } + return false; + } - [[nodiscard]] std::string getLevel() const override { - // For simplicity, let's just return a default level. You can adjust as needed. - return "DEBUG"; - } + void setLevel(const std::string &name) override { + // For the stub, setting a level might not have any behavior. + // But you can implement level filtering if you like. + } - virtual void log(std::string lvl, fmt::basic_string_view msg) const override { - logs.push_back({lvl, {msg.data(), msg.size()}}); - } + [[nodiscard]] std::string getLevel() const override { + // For simplicity, let's just return a default level. You can adjust as needed. + return "DEBUG"; + } - // Helper methods for testing - size_t logCount() const { - return logs.size(); - } + virtual void log(std::string lvl, fmt::basic_string_view msg) const override { + logs.push_back({ lvl, { msg.data(), msg.size() } }); + } - std::pair getLogEntry(size_t index) const { - if (index < logs.size()) { - return {logs[index].level, logs[index].message}; - } - return {"", ""}; // Return empty pair for out-of-bounds. Alternatively, you could throw an exception. + // Helper methods for testing + size_t logCount() const { + return logs.size(); + } + + std::pair getLogEntry(size_t index) const { + if (index < logs.size()) { + return { logs[index].level, logs[index].message }; } + return { "", "" }; // Return empty pair for out-of-bounds. Alternatively, you could throw an exception. + } }; template <> struct TestInjection { - using type = InMemoryLogger; -}; \ No newline at end of file + using type = InMemoryLogger; +}; diff --git a/tests/fixture/test_injection.hpp b/tests/fixture/test_injection.hpp index 31a64acf721..f69ede1e21a 100644 --- a/tests/fixture/test_injection.hpp +++ b/tests/fixture/test_injection.hpp @@ -1,12 +1,12 @@ /** -* Canary - A free and open-source MMORPG server emulator -* Copyright (©) 2019-2023 OpenTibiaBR -* Repository: https://github.com/opentibiabr/canary -* License: https://github.com/opentibiabr/canary/blob/main/LICENSE -* Contributors: https://github.com/opentibiabr/canary/graphs/contributors -* Website: https://docs.opentibiabr.com/ + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2023 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ */ #pragma once template -struct TestInjection {}; \ No newline at end of file +struct TestInjection { }; diff --git a/tests/unit/lib/di/soft_singleton_test.cpp b/tests/unit/lib/di/soft_singleton_test.cpp index 99bb194e75c..6a2bb97f118 100644 --- a/tests/unit/lib/di/soft_singleton_test.cpp +++ b/tests/unit/lib/di/soft_singleton_test.cpp @@ -1,11 +1,11 @@ /** -* Canary - A free and open-source MMORPG server emulator -* Copyright (©) 2019-2023 OpenTibiaBR -* Repository: https://github.com/opentibiabr/canary -* License: https://github.com/opentibiabr/canary/blob/main/LICENSE -* Contributors: https://github.com/opentibiabr/canary/graphs/contributors -* Website: https://docs.opentibiabr.com/ -*/ + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2023 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ #include "pch.hpp" #include @@ -18,35 +18,33 @@ using namespace boost::ut; suite<"lib"> softSingletonTest = [] { test("SoftSingleton warns about multiple instances") = [] { - di::extension::injector<> injector{}; + di::extension::injector<> injector {}; DI::setTestContainer(&InMemoryLogger::install(injector)); - SoftSingleton softSingleton{"Test"}; - SoftSingletonGuard guard{softSingleton}; - SoftSingletonGuard guard2{softSingleton}; + SoftSingleton softSingleton { "Test" }; + SoftSingletonGuard guard { softSingleton }; + SoftSingletonGuard guard2 { softSingleton }; softSingleton.increment(); auto &logger = dynamic_cast(injector.create()); expect(eq(2, logger.logCount()) >> fatal); expect( - eq(std::string{"warning"}, logger.logs[0].level) and - eq(std::string{"2 instances created for Test. This is a soft singleton, you probably want to use g_test instead."}, logger.logs[0].message) - ); + eq(std::string { "warning" }, logger.logs[0].level) and eq(std::string { "2 instances created for Test. This is a soft singleton, you probably want to use g_test instead." }, logger.logs[0].message) + ); expect( - eq(std::string{"warning"}, logger.logs[1].level) and - eq(std::string{"3 instances created for Test. This is a soft singleton, you probably want to use g_test instead."}, logger.logs[1].message) - ); + eq(std::string { "warning" }, logger.logs[1].level) and eq(std::string { "3 instances created for Test. This is a soft singleton, you probably want to use g_test instead." }, logger.logs[1].message) + ); }; test("SoftSingleton doesn't warn if instance was released") = [] { - di::extension::injector<> injector{}; + di::extension::injector<> injector {}; DI::setTestContainer(&InMemoryLogger::install(injector)); - SoftSingleton softSingleton{"Test"}; + SoftSingleton softSingleton { "Test" }; - [&softSingleton] { SoftSingletonGuard guard{softSingleton}; }(); + [&softSingleton] { SoftSingletonGuard guard { softSingleton }; }(); // Lambda scope, guard was destructed. - [&softSingleton] { SoftSingletonGuard guard{softSingleton}; }(); + [&softSingleton] { SoftSingletonGuard guard { softSingleton }; }(); // Lambda scope, guard2 was destructed. softSingleton.increment(); diff --git a/tests/unit/lib/logging/in_memory_logger.hpp b/tests/unit/lib/logging/in_memory_logger.hpp index 581a453ee80..0b1f9972888 100644 --- a/tests/unit/lib/logging/in_memory_logger.hpp +++ b/tests/unit/lib/logging/in_memory_logger.hpp @@ -18,67 +18,67 @@ namespace di = boost::di; class InMemoryLogger : public Logger { - private: - struct LogEntry { - std::string level; - std::string message; - }; - - public: - mutable std::vector logs; - - InMemoryLogger() = default; - InMemoryLogger(const InMemoryLogger &) {} - InMemoryLogger(const InMemoryLogger &&) {} - - static di::extension::injector<> & install(di::extension::injector<> &injector) { - injector.install(di::bind.to().in(di::singleton)); - return injector; - } - - InMemoryLogger &reset() { - logs.clear(); - return *this; - } - - bool hasLogEntry(const std::string& lvl, const std::string& expectedMsg) const { - for (const auto& entry : logs) { - if (entry.level == lvl && entry.message == expectedMsg) { - return true; - } +private: + struct LogEntry { + std::string level; + std::string message; + }; + +public: + mutable std::vector logs; + + InMemoryLogger() = default; + InMemoryLogger(const InMemoryLogger &) { } + InMemoryLogger(const InMemoryLogger &&) { } + + static di::extension::injector<> &install(di::extension::injector<> &injector) { + injector.install(di::bind.to().in(di::singleton)); + return injector; + } + + InMemoryLogger &reset() { + logs.clear(); + return *this; + } + + bool hasLogEntry(const std::string &lvl, const std::string &expectedMsg) const { + for (const auto &entry : logs) { + if (entry.level == lvl && entry.message == expectedMsg) { + return true; } - - return false; } - void setLevel(const std::string &name) override { - // For the stub, setting a level might not have any behavior. - // But you can implement level filtering if you like. - } + return false; + } - [[nodiscard]] std::string getLevel() const override { - // For simplicity, let's just return a default level. You can adjust as needed. - return "DEBUG"; - } + void setLevel(const std::string &name) override { + // For the stub, setting a level might not have any behavior. + // But you can implement level filtering if you like. + } - virtual void log(std::string lvl, fmt::basic_string_view msg) const override { - logs.push_back({lvl, {msg.data(), msg.size()}}); - } + [[nodiscard]] std::string getLevel() const override { + // For simplicity, let's just return a default level. You can adjust as needed. + return "DEBUG"; + } - // Helper methods for testing - size_t logCount() const { - return logs.size(); - } + virtual void log(std::string lvl, fmt::basic_string_view msg) const override { + logs.push_back({ lvl, { msg.data(), msg.size() } }); + } - std::pair getLogEntry(size_t index) const { - if (index < logs.size()) { - return {logs[index].level, logs[index].message}; - } - return {"", ""}; // Return empty pair for out-of-bounds. Alternatively, you could throw an exception. + // Helper methods for testing + size_t logCount() const { + return logs.size(); + } + + std::pair getLogEntry(size_t index) const { + if (index < logs.size()) { + return { logs[index].level, logs[index].message }; } + return { "", "" }; // Return empty pair for out-of-bounds. Alternatively, you could throw an exception. + } }; template <> struct TestInjection { - using type = InMemoryLogger; -}; \ No newline at end of file + using type = InMemoryLogger; +}; diff --git a/tests/unit/main.cpp b/tests/unit/main.cpp index 5cf3982af0c..0f8a83d0097 100644 --- a/tests/unit/main.cpp +++ b/tests/unit/main.cpp @@ -2,4 +2,4 @@ using namespace boost::ut; -int main() {} +int main() { } diff --git a/tests/unit/security/rsa_test.cpp b/tests/unit/security/rsa_test.cpp index 710ea45d2cb..a613fc465f4 100644 --- a/tests/unit/security/rsa_test.cpp +++ b/tests/unit/security/rsa_test.cpp @@ -1,11 +1,11 @@ /** -* Canary - A free and open-source MMORPG server emulator -* Copyright (©) 2019-2023 OpenTibiaBR -* Repository: https://github.com/opentibiabr/canary -* License: https://github.com/opentibiabr/canary/blob/main/LICENSE -* Contributors: https://github.com/opentibiabr/canary/graphs/contributors -* Website: https://docs.opentibiabr.com/ -*/ + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2023 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ #include "pch.hpp" #include @@ -17,17 +17,16 @@ using namespace boost::ut; suite<"security"> rsaTest = [] { test("RSA::start logs error for missing .pem file") = [] { - di::extension::injector<> injector{}; + di::extension::injector<> injector {}; DI::setTestContainer(&InMemoryLogger::install(injector)); DI::create().start(); auto &logger = dynamic_cast(injector.create()); - expect(eq(1, logger.logs.size()) >> fatal); + expect(eq(1, logger.logs.size()) >> fatal); expect( - eq(std::string{"error"}, logger.logs[0].level) and - eq(std::string{"File key.pem not found or have problem on loading... Setting standard rsa key\n"}, logger.logs[0].message) - ); + eq(std::string { "error" }, logger.logs[0].level) and eq(std::string { "File key.pem not found or have problem on loading... Setting standard rsa key\n" }, logger.logs[0].message) + ); }; }; diff --git a/tests/unit/utils/position_functions_test.cpp b/tests/unit/utils/position_functions_test.cpp index 52341fd8d64..82e2696322d 100644 --- a/tests/unit/utils/position_functions_test.cpp +++ b/tests/unit/utils/position_functions_test.cpp @@ -8,35 +8,35 @@ using namespace boost::ut; suite<"utils"> getDirectionToTest = [] { struct GetDirectionToTestCase { - Position from, to; - Direction expected, expectedForExactDiagonal; + Position from, to; + Direction expected, expectedForExactDiagonal; - [[nodiscard]] std::string toString() const { - return fmt::format("from {} to {}", from.toString(), to.toString()); - } + [[nodiscard]] std::string toString() const { + return fmt::format("from {} to {}", from.toString(), to.toString()); + } }; - std::vector getDirectionToTestCases{ - GetDirectionToTestCase{ Position{}, Position{}, DIRECTION_SOUTH, DIRECTION_SOUTH }, - GetDirectionToTestCase{ Position{0,0,0}, Position{0,0,0}, DIRECTION_SOUTH, DIRECTION_SOUTH }, - GetDirectionToTestCase{ Position{100,100,100}, Position{100,100,100}, DIRECTION_SOUTH, DIRECTION_SOUTH }, - GetDirectionToTestCase{ Position{125,1123,5}, Position{125,1153,5}, DIRECTION_SOUTH, DIRECTION_SOUTH }, - GetDirectionToTestCase{ Position{5555,3212,15}, Position{5555,3211,15}, DIRECTION_NORTH, DIRECTION_NORTH }, - GetDirectionToTestCase{ Position{32132,65000,11}, Position{31512,65000,11}, DIRECTION_WEST, DIRECTION_WEST }, - GetDirectionToTestCase{ Position{5123,6554,7}, Position{40000,6554,7}, DIRECTION_EAST, DIRECTION_EAST }, - GetDirectionToTestCase{ Position{25200,33173,8}, Position{5200,13173,7}, DIRECTION_NORTHWEST, DIRECTION_NORTHWEST }, - GetDirectionToTestCase{ Position{22137,6,9}, Position{22141,2,15}, DIRECTION_NORTHEAST, DIRECTION_NORTHEAST }, - GetDirectionToTestCase{ Position{32011,2197,1}, Position{32135,2321,13}, DIRECTION_SOUTHEAST, DIRECTION_SOUTHEAST }, - GetDirectionToTestCase{ Position{13121,5213,5}, Position{5213,13121,5}, DIRECTION_SOUTHWEST, DIRECTION_SOUTHWEST }, - - GetDirectionToTestCase{ Position{123,122,0}, Position{0,0,0}, DIRECTION_NORTHWEST, DIRECTION_WEST }, - GetDirectionToTestCase{ Position{122,123,0}, Position{0,0,0}, DIRECTION_NORTHWEST, DIRECTION_NORTH }, - GetDirectionToTestCase{ Position{0,122,0}, Position{123,0,0}, DIRECTION_NORTHEAST, DIRECTION_EAST }, - GetDirectionToTestCase{ Position{0,123,0}, Position{122,0,0}, DIRECTION_NORTHEAST, DIRECTION_NORTH }, - GetDirectionToTestCase{ Position{0,0,0}, Position{123,122,0}, DIRECTION_SOUTHEAST, DIRECTION_EAST }, - GetDirectionToTestCase{ Position{0,0,0}, Position{122,123,0}, DIRECTION_SOUTHEAST, DIRECTION_SOUTH }, - GetDirectionToTestCase{ Position{123,0,0}, Position{0,122,0}, DIRECTION_SOUTHWEST, DIRECTION_WEST }, - GetDirectionToTestCase{ Position{122,0,0}, Position{0,123,0}, DIRECTION_SOUTHWEST, DIRECTION_SOUTH }, + std::vector getDirectionToTestCases { + GetDirectionToTestCase { Position {}, Position {}, DIRECTION_SOUTH, DIRECTION_SOUTH }, + GetDirectionToTestCase { Position { 0, 0, 0 }, Position { 0, 0, 0 }, DIRECTION_SOUTH, DIRECTION_SOUTH }, + GetDirectionToTestCase { Position { 100, 100, 100 }, Position { 100, 100, 100 }, DIRECTION_SOUTH, DIRECTION_SOUTH }, + GetDirectionToTestCase { Position { 125, 1123, 5 }, Position { 125, 1153, 5 }, DIRECTION_SOUTH, DIRECTION_SOUTH }, + GetDirectionToTestCase { Position { 5555, 3212, 15 }, Position { 5555, 3211, 15 }, DIRECTION_NORTH, DIRECTION_NORTH }, + GetDirectionToTestCase { Position { 32132, 65000, 11 }, Position { 31512, 65000, 11 }, DIRECTION_WEST, DIRECTION_WEST }, + GetDirectionToTestCase { Position { 5123, 6554, 7 }, Position { 40000, 6554, 7 }, DIRECTION_EAST, DIRECTION_EAST }, + GetDirectionToTestCase { Position { 25200, 33173, 8 }, Position { 5200, 13173, 7 }, DIRECTION_NORTHWEST, DIRECTION_NORTHWEST }, + GetDirectionToTestCase { Position { 22137, 6, 9 }, Position { 22141, 2, 15 }, DIRECTION_NORTHEAST, DIRECTION_NORTHEAST }, + GetDirectionToTestCase { Position { 32011, 2197, 1 }, Position { 32135, 2321, 13 }, DIRECTION_SOUTHEAST, DIRECTION_SOUTHEAST }, + GetDirectionToTestCase { Position { 13121, 5213, 5 }, Position { 5213, 13121, 5 }, DIRECTION_SOUTHWEST, DIRECTION_SOUTHWEST }, + + GetDirectionToTestCase { Position { 123, 122, 0 }, Position { 0, 0, 0 }, DIRECTION_NORTHWEST, DIRECTION_WEST }, + GetDirectionToTestCase { Position { 122, 123, 0 }, Position { 0, 0, 0 }, DIRECTION_NORTHWEST, DIRECTION_NORTH }, + GetDirectionToTestCase { Position { 0, 122, 0 }, Position { 123, 0, 0 }, DIRECTION_NORTHEAST, DIRECTION_EAST }, + GetDirectionToTestCase { Position { 0, 123, 0 }, Position { 122, 0, 0 }, DIRECTION_NORTHEAST, DIRECTION_NORTH }, + GetDirectionToTestCase { Position { 0, 0, 0 }, Position { 123, 122, 0 }, DIRECTION_SOUTHEAST, DIRECTION_EAST }, + GetDirectionToTestCase { Position { 0, 0, 0 }, Position { 122, 123, 0 }, DIRECTION_SOUTHEAST, DIRECTION_SOUTH }, + GetDirectionToTestCase { Position { 123, 0, 0 }, Position { 0, 122, 0 }, DIRECTION_SOUTHWEST, DIRECTION_WEST }, + GetDirectionToTestCase { Position { 122, 0, 0 }, Position { 0, 123, 0 }, DIRECTION_SOUTHWEST, DIRECTION_SOUTH }, }; for (auto getDirectionToTestCase : getDirectionToTestCases) { diff --git a/tests/unit/utils/string_functions_test.cpp b/tests/unit/utils/string_functions_test.cpp index 659f4b19594..aa4860b2696 100644 --- a/tests/unit/utils/string_functions_test.cpp +++ b/tests/unit/utils/string_functions_test.cpp @@ -8,14 +8,14 @@ using namespace boost::ut; suite<"utils"> replaceStringTest = [] { struct ReplaceStringTestCase { - std::string subject, search, replace, expected; + std::string subject, search, replace, expected; - [[nodiscard]] std::string toString() const { - return fmt::format("replace {} in {} by {}", search, subject, replace); - } + [[nodiscard]] std::string toString() const { + return fmt::format("replace {} in {} by {}", search, subject, replace); + } }; - std::vector replaceStringTestCases{ + std::vector replaceStringTestCases { ReplaceStringTestCase { "", "", "", "" }, ReplaceStringTestCase { "all together", " ", "_", "all_together" }, ReplaceStringTestCase { "beautiful", "u", "", "beatifl" }, @@ -26,7 +26,7 @@ suite<"utils"> replaceStringTest = [] { for (const auto &replaceStringTestCase : replaceStringTestCases) { test(replaceStringTestCase.toString()) = [&replaceStringTestCase] { - auto [subject, search, replace, expected] = replaceStringTestCase; + auto [subject, search, replace, expected] = replaceStringTestCase; replaceString(subject, search, replace); expect(eq(expected, subject)) << fmt::format("{} != {}", expected, subject); }; From f3b06f85fad534e2c5a9d724d92bd6b099409010 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Mon, 11 Sep 2023 19:55:49 -0700 Subject: [PATCH 02/67] improve: remove manual ref counts --- src/creatures/creature.cpp | 2 -- src/creatures/creature.hpp | 9 ----- src/creatures/monsters/monster.cpp | 18 +--------- .../monsters/spawns/spawn_monster.cpp | 4 --- src/creatures/npcs/spawns/spawn_npc.cpp | 4 --- src/creatures/players/player.cpp | 36 ------------------- src/game/game.cpp | 27 -------------- src/game/game.hpp | 1 - src/items/containers/container.cpp | 1 - src/items/decay/decay.cpp | 1 - src/items/item.cpp | 3 -- src/items/item.hpp | 10 ------ src/items/tile.cpp | 4 --- src/items/tile.hpp | 12 ------- src/map/house/house.cpp | 3 -- src/server/network/protocol/protocolgame.cpp | 3 -- 16 files changed, 1 insertion(+), 137 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 30f7cf3ac06..078f2363219 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -1219,7 +1219,6 @@ bool Creature::setMaster(std::shared_ptr newMaster, bool reloadCreatur g_game().reloadCreature(static_self_cast()); } if (newMaster) { - incrementReferenceCounter(); newMaster->summons.push_back(static_self_cast()); } @@ -1230,7 +1229,6 @@ bool Creature::setMaster(std::shared_ptr newMaster, bool reloadCreatur auto summon = std::find(oldMaster->summons.begin(), oldMaster->summons.end(), getCreature()); if (summon != oldMaster->summons.end()) { oldMaster->summons.erase(summon); - decrementReferenceCounter(); } } return true; diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index f4ea157372f..61a6ea0f326 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -314,7 +314,6 @@ class Creature : virtual public Thing, public SharedObject { void removeMaster() { if (master) { master = nullptr; - decrementReferenceCounter(); } } @@ -523,13 +522,6 @@ class Creature : virtual public Thing, public SharedObject { bool getPathTo(const Position &targetPos, std::forward_list &dirList, const FindPathParams &fpp); bool getPathTo(const Position &targetPos, std::forward_list &dirList, int32_t minTargetDist, int32_t maxTargetDist, bool fullPathSearch = true, bool clearSight = true, int32_t maxSearchDist = 7); - void incrementReferenceCounter() { - ++referenceCounter; - } - void decrementReferenceCounter() { - if (--referenceCounter == 0) { - } - } struct CountBlock_t { int32_t total; int64_t ticks; @@ -681,7 +673,6 @@ class Creature : virtual public Thing, public SharedObject { bool summoned = false; uint64_t lastStep = 0; - uint32_t referenceCounter = 0; uint32_t id = 0; uint32_t scriptEventsBitField = 0; uint32_t eventWalk = 0; diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index b1e11ccd79a..47928d22d02 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -292,16 +292,12 @@ void Monster::onCreatureSay(std::shared_ptr creature, SpeakClasses typ void Monster::addFriend(std::shared_ptr creature) { assert(creature.get() != this); - auto result = friendList.insert(creature); - if (result.second) { - creature->incrementReferenceCounter(); - } + friendList.insert(creature); } void Monster::removeFriend(std::shared_ptr creature) { auto it = friendList.find(creature); if (it != friendList.end()) { - creature->decrementReferenceCounter(); friendList.erase(it); } } @@ -309,7 +305,6 @@ void Monster::removeFriend(std::shared_ptr creature) { void Monster::addTarget(std::shared_ptr creature, bool pushFront /* = false*/) { assert(creature.get() != this); if (std::find(targetList.begin(), targetList.end(), creature) == targetList.end()) { - creature->incrementReferenceCounter(); if (pushFront) { targetList.push_front(creature); } else { @@ -332,7 +327,6 @@ void Monster::removeTarget(std::shared_ptr creature) { totalPlayersOnScreen--; } - creature->decrementReferenceCounter(); targetList.erase(it); } } @@ -342,7 +336,6 @@ void Monster::updateTargetList() { while (friendIterator != friendList.end()) { std::shared_ptr creature = *friendIterator; if (creature->getHealth() <= 0 || !canSee(creature->getPosition())) { - creature->decrementReferenceCounter(); friendIterator = friendList.erase(friendIterator); } else { ++friendIterator; @@ -353,7 +346,6 @@ void Monster::updateTargetList() { while (targetIterator != targetList.end()) { std::shared_ptr creature = *targetIterator; if (creature->getHealth() <= 0 || !canSee(creature->getPosition())) { - creature->decrementReferenceCounter(); targetIterator = targetList.erase(targetIterator); } else { ++targetIterator; @@ -371,16 +363,10 @@ void Monster::updateTargetList() { } void Monster::clearTargetList() { - for (std::shared_ptr creature : targetList) { - creature->decrementReferenceCounter(); - } targetList.clear(); } void Monster::clearFriendList() { - for (std::shared_ptr creature : friendList) { - creature->decrementReferenceCounter(); - } friendList.clear(); } @@ -613,8 +599,6 @@ void Monster::onFollowCreatureComplete(std::shared_ptr creature) { targetList.push_front(target); } else if (!isSummon()) { targetList.push_back(target); - } else { - target->decrementReferenceCounter(); } } } diff --git a/src/creatures/monsters/spawns/spawn_monster.cpp b/src/creatures/monsters/spawns/spawn_monster.cpp index 4e39623723d..045038e6e45 100644 --- a/src/creatures/monsters/spawns/spawn_monster.cpp +++ b/src/creatures/monsters/spawns/spawn_monster.cpp @@ -151,7 +151,6 @@ SpawnMonster::~SpawnMonster() { for (const auto &it : spawnedMonsterMap) { std::shared_ptr monster = it.second; monster->setSpawnMonster(nullptr); - monster->decrementReferenceCounter(); } } @@ -186,7 +185,6 @@ bool SpawnMonster::spawnMonster(uint32_t spawnMonsterId, const std::shared_ptrsetDirection(dir); monster->setSpawnMonster(this); monster->setMasterPos(pos); - monster->incrementReferenceCounter(); spawnedMonsterMap.insert(spawned_pair(spawnMonsterId, monster)); spawnMonsterMap[spawnMonsterId].lastSpawn = OTSYS_TIME(); @@ -261,7 +259,6 @@ void SpawnMonster::cleanup() { std::shared_ptr monster = it->second; if (monster->isRemoved()) { spawnMonsterMap[spawnMonsterId].lastSpawn = OTSYS_TIME(); - monster->decrementReferenceCounter(); it = spawnedMonsterMap.erase(it); } else { ++it; @@ -293,7 +290,6 @@ bool SpawnMonster::addMonster(const std::string &name, const Position &pos, Dire void SpawnMonster::removeMonster(std::shared_ptr monster) { for (auto it = spawnedMonsterMap.begin(), end = spawnedMonsterMap.end(); it != end; ++it) { if (it->second == monster) { - monster->decrementReferenceCounter(); spawnedMonsterMap.erase(it); break; } diff --git a/src/creatures/npcs/spawns/spawn_npc.cpp b/src/creatures/npcs/spawns/spawn_npc.cpp index db98fe59bbd..9d29598792f 100644 --- a/src/creatures/npcs/spawns/spawn_npc.cpp +++ b/src/creatures/npcs/spawns/spawn_npc.cpp @@ -139,7 +139,6 @@ SpawnNpc::~SpawnNpc() { for (const auto &it : spawnedNpcMap) { auto npc = it.second; npc->setSpawnNpc(nullptr); - npc->decrementReferenceCounter(); } } @@ -174,7 +173,6 @@ bool SpawnNpc::spawnNpc(uint32_t spawnId, NpcType* npcType, const Position &pos, npc->setDirection(dir); npc->setSpawnNpc(this); npc->setMasterPos(pos); - npc->incrementReferenceCounter(); spawnedNpcMap.insert(spawned_pair(spawnId, npc)); spawnNpcMap[spawnId].lastSpawnNpc = OTSYS_TIME(); @@ -240,7 +238,6 @@ void SpawnNpc::cleanup() { auto npc = it->second; if (npc->isRemoved()) { spawnNpcMap[spawnId].lastSpawnNpc = OTSYS_TIME(); - npc->decrementReferenceCounter(); it = spawnedNpcMap.erase(it); } else { ++it; @@ -272,7 +269,6 @@ bool SpawnNpc::addNpc(const std::string &name, const Position &pos, Direction di void SpawnNpc::removeNpc(std::shared_ptr npc) { for (auto it = spawnedNpcMap.begin(), end = spawnedNpcMap.end(); it != end; ++it) { if (it->second == npc) { - npc->decrementReferenceCounter(); spawnedNpcMap.erase(it); break; } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 1d89d59d137..e7ae9419960 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -39,7 +39,6 @@ Player::Player(ProtocolGame_ptr p) : lastPong(lastPing), inbox(std::make_shared(ITEM_INBOX)), client(std::move(p)) { - inbox->incrementReferenceCounter(); m_wheelPlayer = std::make_unique(*this); } @@ -48,22 +47,12 @@ Player::~Player() { if (item) { item->setParent(nullptr); item->stopDecaying(); - item->decrementReferenceCounter(); } } for (const auto &it : depotLockerMap) { it.second->removeInbox(inbox); it.second->stopDecaying(); - it.second->decrementReferenceCounter(); - } - - for (const auto &it : rewardMap) { - it.second->decrementReferenceCounter(); - } - - for (const auto &it : quickLootContainers) { - it.second->decrementReferenceCounter(); } for (PreySlot* slot : preys) { @@ -77,7 +66,6 @@ Player::~Player() { } inbox->stopDecaying(); - inbox->decrementReferenceCounter(); setWriteItem(nullptr); setEditHouse(nullptr); @@ -770,16 +758,11 @@ void Player::addContainer(uint8_t cid, std::shared_ptr container) { return; } - if (container->getID() == ITEM_BROWSEFIELD) { - container->incrementReferenceCounter(); - } - auto it = openContainers.find(cid); if (it != openContainers.end()) { OpenContainer &openContainer = it->second; auto oldContainer = openContainer.container; if (oldContainer->getID() == ITEM_BROWSEFIELD) { - oldContainer->decrementReferenceCounter(); } openContainer.container = container; @@ -803,7 +786,6 @@ void Player::closeContainer(uint8_t cid) { openContainers.erase(it); if (container && container->getID() == ITEM_BROWSEFIELD) { - container->decrementReferenceCounter(); } } @@ -1033,14 +1015,12 @@ std::shared_ptr Player::setLootContainer(ObjectCategory_t category, s previousContainer->setAttribute(ItemAttribute_t::QUICKLOOTCONTAINER, flags); } - previousContainer->decrementReferenceCounter(); quickLootContainers.erase(it); } if (container) { previousContainer = container; quickLootContainers[category] = container; - container->incrementReferenceCounter(); if (!loading) { auto flags = container->getAttribute(ItemAttribute_t::QUICKLOOTCONTAINER); auto sendAttribute = flags | 1 << category; @@ -1095,7 +1075,6 @@ void Player::checkLootContainers(std::shared_ptr item) { shouldSend = true; it = quickLootContainers.erase(it); lootContainer->removeAttribute(ItemAttribute_t::QUICKLOOTCONTAINER); - lootContainer->decrementReferenceCounter(); } else { ++it; } @@ -1154,7 +1133,6 @@ std::shared_ptr Player::getDepotChest(uint32_t depotId, bool autoCre depotChest = std::make_shared(ITEM_DEPOT_XX); } - depotChest->incrementReferenceCounter(); depotChests[depotId] = depotChest; return depotChest; } @@ -1211,7 +1189,6 @@ std::shared_ptr Player::getReward(const uint64_t rewardId, const bool au } auto reward = std::make_shared(); - reward->incrementReferenceCounter(); reward->setAttribute(ItemAttribute_t::DATE, rewardId); rewardMap[rewardId] = reward; g_game().internalAddItem(getRewardChest(), reward, INDEX_WHEREEVER, FLAG_NOLIMIT); @@ -1307,28 +1284,15 @@ std::shared_ptr Player::getWriteItem(uint32_t &retWindowTextId, uint16_t & } void Player::setImbuingItem(std::shared_ptr item) { - if (imbuingItem) { - imbuingItem->decrementReferenceCounter(); - } - - if (item) { - item->incrementReferenceCounter(); - } - imbuingItem = item; } void Player::setWriteItem(std::shared_ptr item, uint16_t maxWriteLength /*= 0*/) { windowTextId++; - if (writeItem) { - writeItem->decrementReferenceCounter(); - } - if (item) { writeItem = item; this->maxWriteLen = maxWriteLength; - writeItem->incrementReferenceCounter(); } else { writeItem = nullptr; this->maxWriteLen = 0; diff --git a/src/game/game.cpp b/src/game/game.cpp index 3eb0d50fd3b..210acb83981 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -854,7 +854,6 @@ bool Game::internalPlaceCreature(std::shared_ptr creature, const Posit return false; } - creature->incrementReferenceCounter(); creature->setID(); creature->addList(); @@ -3530,9 +3529,7 @@ void Game::playerMoveUpContainer(uint32_t playerId, uint8_t cid) { auto it = browseFields.find(tile); if (it == browseFields.end()) { parentContainer = std::make_shared(tile); - parentContainer->incrementReferenceCounter(); browseFields[tile] = parentContainer; - g_scheduler().addEvent(30000, std::bind(&Game::decreaseBrowseFieldRef, this, tile->getPosition()), "Game::decreaseBrowseFieldRef"); } else { parentContainer = it->second; } @@ -4002,9 +3999,7 @@ void Game::playerBrowseField(uint32_t playerId, const Position &pos) { auto it = browseFields.find(tile); if (it == browseFields.end()) { container = std::make_shared(tile); - container->incrementReferenceCounter(); browseFields[tile] = container; - g_scheduler().addEvent(30000, std::bind(&Game::decreaseBrowseFieldRef, this, tile->getPosition()), "Game::decreaseBrowseFieldRef"); } else { container = it->second; } @@ -4316,7 +4311,6 @@ bool Game::internalStartTrade(std::shared_ptr player, std::shared_ptrtradePartner = tradePartner; player->tradeItem = tradeItem; player->tradeState = TRADE_INITIATED; - tradeItem->incrementReferenceCounter(); tradeItems[tradeItem] = player->getID(); player->sendTradeItemRequest(player->getName(), tradeItem, true); @@ -5707,7 +5701,6 @@ void Game::addCreatureCheck(std::shared_ptr creature) { creature->inCheckCreaturesVector = true; checkCreatureLists[uniform_random(0, EVENT_CREATURECOUNT - 1)].push_back(creature); - creature->incrementReferenceCounter(); } void Game::removeCreatureCheck(std::shared_ptr creature) { @@ -7411,15 +7404,7 @@ void Game::shutdown() { } void Game::cleanup() { - // free memory - for (auto creature : ToReleaseCreatures) { - creature->decrementReferenceCounter(); - } ToReleaseCreatures.clear(); - - for (auto item : ToReleaseItems) { - item->decrementReferenceCounter(); - } ToReleaseItems.clear(); } @@ -9252,18 +9237,6 @@ void Game::removeGuild(uint32_t guildId) { guilds.erase(guildId); } -void Game::decreaseBrowseFieldRef(const Position &pos) { - std::shared_ptr tile = map.getTile(pos.x, pos.y, pos.z); - if (!tile) { - return; - } - - auto it = browseFields.find(tile); - if (it != browseFields.end()) { - it->second->decrementReferenceCounter(); - } -} - void Game::internalRemoveItems(const std::vector> itemVector, uint32_t amount, bool stackable) { if (stackable) { for (std::shared_ptr item : itemVector) { diff --git a/src/game/game.hpp b/src/game/game.hpp index dd9bbbf2500..6d0e7a633a0 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -495,7 +495,6 @@ class Game { std::shared_ptr getGuildByName(const std::string &name, bool allowOffline = false) const; void addGuild(const std::shared_ptr guild); void removeGuild(uint32_t guildId); - void decreaseBrowseFieldRef(const Position &pos); phmap::flat_hash_map, std::shared_ptr> browseFields; diff --git a/src/items/containers/container.cpp b/src/items/containers/container.cpp index 8dcf094d944..8f80d18c9e5 100644 --- a/src/items/containers/container.cpp +++ b/src/items/containers/container.cpp @@ -55,7 +55,6 @@ Container::~Container() { } else { for (std::shared_ptr item : itemlist) { item->setParent(nullptr); - item->decrementReferenceCounter(); } } } diff --git a/src/items/decay/decay.cpp b/src/items/decay/decay.cpp index ef655b74933..aaed3c193f2 100644 --- a/src/items/decay/decay.cpp +++ b/src/items/decay/decay.cpp @@ -49,7 +49,6 @@ void Decay::startDecay(std::shared_ptr item) { } } - item->incrementReferenceCounter(); item->setDecaying(DECAYING_TRUE); item->setAttribute(ItemAttribute_t::DURATION_TIMESTAMP, timestamp); decayMap[timestamp].push_back(item); diff --git a/src/items/item.cpp b/src/items/item.cpp index e75115520d9..694ba3009ab 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -63,8 +63,6 @@ std::shared_ptr Item::CreateItem(const uint16_t type, uint16_t count /*= 0 newItem = std::make_shared(type, count); } } - - newItem->incrementReferenceCounter(); } else if (type > 0 && itemPosition) { auto position = *itemPosition; g_logger().warn("[Item::CreateItem] Item with id '{}', in position '{}' not exists in the appearances.dat and cannot be created.", type, position.toString()); @@ -143,7 +141,6 @@ std::shared_ptr Item::CreateItemAsContainer(const uint16_t type, uint } std::shared_ptr newItem = std::make_shared(type, size); - newItem->incrementReferenceCounter(); return newItem; } diff --git a/src/items/item.hpp b/src/items/item.hpp index 8cfef48b54e..c9e47077c20 100644 --- a/src/items/item.hpp +++ b/src/items/item.hpp @@ -563,14 +563,6 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { bool hasMarketAttributes() const; - void incrementReferenceCounter() { - ++referenceCounter; - } - void decrementReferenceCounter() { - if (--referenceCounter == 0) { - } - } - std::shared_ptr getParent() const override { return parent; } @@ -683,8 +675,6 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { protected: std::shared_ptr parent = nullptr; - uint32_t referenceCounter = 0; - uint16_t id; // the same id as in ItemType uint8_t count = 1; // number of stacked items diff --git a/src/items/tile.cpp b/src/items/tile.cpp index 92740203daf..08d1c406d70 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -1442,13 +1442,9 @@ void Tile::postAddNotification(std::shared_ptr thing, std::shared_ptr creature = thing->getCreature(); std::shared_ptr item; if (creature) { - creature->incrementReferenceCounter(); item = nullptr; } else { item = thing->getItem(); - if (item) { - item->incrementReferenceCounter(); - } } if (link == LINK_OWNER) { diff --git a/src/items/tile.hpp b/src/items/tile.hpp index bbc24441087..c5943591067 100644 --- a/src/items/tile.hpp +++ b/src/items/tile.hpp @@ -277,11 +277,6 @@ class DynamicTile : public Tile { public: DynamicTile(uint16_t x, uint16_t y, uint8_t z) : Tile(x, y, z) { } - ~DynamicTile() { - for (std::shared_ptr item : items) { - item->decrementReferenceCounter(); - } - } // non-copyable DynamicTile(const DynamicTile &) = delete; @@ -317,13 +312,6 @@ class StaticTile final : public Tile { public: StaticTile(uint16_t x, uint16_t y, uint8_t z) : Tile(x, y, z) { } - ~StaticTile() { - if (items) { - for (auto &item : *items) { - item->decrementReferenceCounter(); - } - } - } // non-copyable StaticTile(const StaticTile &) = delete; diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index 2509f5164d2..3e61141c8fb 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -305,7 +305,6 @@ bool House::isInvited(std::shared_ptr player) { } void House::addDoor(std::shared_ptr door) { - door->incrementReferenceCounter(); doorList.push_back(door); door->setHouse(this); updateDoorDescription(); @@ -314,7 +313,6 @@ void House::addDoor(std::shared_ptr door) { void House::removeDoor(std::shared_ptr door) { auto it = std::find(doorList.begin(), doorList.end(), door); if (it != doorList.end()) { - door->decrementReferenceCounter(); doorList.erase(it); } } @@ -384,7 +382,6 @@ void House::resetTransferItem() { std::shared_ptr HouseTransferItem::createHouseTransferItem(House* house) { std::shared_ptr transferItem = std::make_shared(house); - transferItem->incrementReferenceCounter(); transferItem->setID(ITEM_DOCUMENT_RO); transferItem->setSubType(1); std::ostringstream ss; diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index ffb5586c1ae..576ce8ae777 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -449,7 +449,6 @@ void ProtocolGame::release() { // dispatcher thread if (player && player->client == shared_from_this()) { player->client.reset(); - player->decrementReferenceCounter(); player = nullptr; } @@ -479,7 +478,6 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS player->setName(name); g_game().addPlayerUniqueLogin(player); - player->incrementReferenceCounter(); player->setID(); if (!IOLoginDataLoad::preLoadPlayer(player, name)) { @@ -613,7 +611,6 @@ void ProtocolGame::connect(const std::string &playerName, OperatingSystem_t oper } player = foundPlayer; - player->incrementReferenceCounter(); g_game().addPlayerUniqueLogin(player); g_chat().removeUserFromAllChannels(player); From d5c4f5895ff4f9da98ca2301449b5948035e66db Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Mon, 11 Sep 2023 22:48:39 -0700 Subject: [PATCH 03/67] fix: cylinder parent circular reference --- src/creatures/creature.cpp | 4 -- src/creatures/creature.hpp | 8 +-- src/creatures/monsters/monster.cpp | 5 -- src/creatures/monsters/monster.hpp | 1 - src/creatures/npcs/npc.hpp | 2 +- src/creatures/players/player.cpp | 16 ++---- src/game/game.cpp | 31 +++++++---- src/game/game.hpp | 2 +- src/items/containers/container.cpp | 31 ++++++----- src/items/containers/container.hpp | 5 +- src/items/containers/depot/depotchest.cpp | 5 +- src/items/containers/depot/depotchest.hpp | 2 +- src/items/containers/depot/depotlocker.cpp | 10 ++-- src/items/containers/inbox/inbox.cpp | 5 +- src/items/containers/inbox/inbox.hpp | 2 +- src/items/containers/rewards/reward.cpp | 2 +- src/items/containers/rewards/reward.hpp | 2 +- src/items/containers/rewards/rewardchest.cpp | 12 +++-- src/items/item.cpp | 4 +- src/items/item.hpp | 11 ++-- src/items/thing.hpp | 2 +- src/items/tile.cpp | 54 ++++++++++++-------- src/map/house/house.cpp | 5 +- 23 files changed, 121 insertions(+), 100 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 078f2363219..6960fadc9c2 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -30,10 +30,6 @@ Creature::~Creature() { summon->setAttackedCreature(nullptr); summon->removeMaster(); } - - for (Condition* condition : conditions) { - condition->endCondition(static_self_cast()); - } } bool Creature::canSee(const Position &myPos, const Position &pos, int32_t viewRangeX, int32_t viewRangeY) { diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index 61a6ea0f326..56b017c8970 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -493,9 +493,11 @@ class Creature : virtual public Thing, public SharedObject { std::shared_ptr getParent() const override final { return tile; } - void setParent(std::shared_ptr cylinder) override final { - tile = std::static_pointer_cast(cylinder); - position = tile->getPosition(); + void setParent(std::weak_ptr cylinder) override final { + if (!cylinder.expired()) { + tile = std::static_pointer_cast(cylinder.lock()); + position = tile->getPosition(); + } } const Position &getPosition() override final { diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 47928d22d02..5b5e3c1f410 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -56,11 +56,6 @@ Monster::Monster(const std::shared_ptr mType) : } } -Monster::~Monster() { - clearTargetList(); - clearFriendList(); -} - void Monster::addList() { g_game().addMonster(static_self_cast()); } diff --git a/src/creatures/monsters/monster.hpp b/src/creatures/monsters/monster.hpp index a71a981077b..9df3e95fee1 100644 --- a/src/creatures/monsters/monster.hpp +++ b/src/creatures/monsters/monster.hpp @@ -27,7 +27,6 @@ class Monster final : public Creature { static int32_t despawnRadius; explicit Monster(const std::shared_ptr mType); - ~Monster(); // non-copyable Monster(const Monster &) = delete; diff --git a/src/creatures/npcs/npc.hpp b/src/creatures/npcs/npc.hpp index 6ad97ea20a2..73a847730d4 100644 --- a/src/creatures/npcs/npc.hpp +++ b/src/creatures/npcs/npc.hpp @@ -104,7 +104,7 @@ class Npc final : public Creature { return false; } - bool canInteract(const Position &pos, uint32_t range = 4) ; + bool canInteract(const Position &pos, uint32_t range = 4); bool canSeeInvisibility() const override { return true; } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index e7ae9419960..a52ae343794 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -45,7 +45,7 @@ Player::Player(ProtocolGame_ptr p) : Player::~Player() { for (std::shared_ptr item : inventory) { if (item) { - item->setParent(nullptr); + item->resetParent(); item->stopDecaying(); } } @@ -55,16 +55,6 @@ Player::~Player() { it.second->stopDecaying(); } - for (PreySlot* slot : preys) { - if (slot) { - } - } - - for (TaskHuntingSlot* slot : taskHunting) { - if (slot) { - } - } - inbox->stopDecaying(); setWriteItem(nullptr); @@ -3534,7 +3524,7 @@ void Player::removeThing(std::shared_ptr thing, uint32_t count) { // event methods onRemoveInventoryItem(item); - item->setParent(nullptr); + item->resetParent(); inventory[index] = nullptr; } else { uint8_t newCount = static_cast(std::max(0, item->getItemCount() - count)); @@ -3553,7 +3543,7 @@ void Player::removeThing(std::shared_ptr thing, uint32_t count) { // event methods onRemoveInventoryItem(item); - item->setParent(nullptr); + item->resetParent(); inventory[index] = nullptr; } } diff --git a/src/game/game.cpp b/src/game/game.cpp index 210acb83981..576e30494b6 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1652,6 +1652,11 @@ ReturnValue Game::checkMoveItemToCylinder(std::shared_ptr player, std::s return RETURNVALUE_NOERROR; } +bool isMatchingCylinder(const std::weak_ptr &weakCylinder, const std::shared_ptr &targetCylinder) { + auto lockedCylinder = weakCylinder.lock(); + return lockedCylinder && lockedCylinder == targetCylinder; +} + ReturnValue Game::internalMoveItem(std::shared_ptr fromCylinder, std::shared_ptr toCylinder, int32_t index, std::shared_ptr item, uint32_t count, std::shared_ptr* movedItem, uint32_t flags /*= 0*/, std::shared_ptr actor /*=nullptr*/, std::shared_ptr tradeItem /* = nullptr*/, bool checkTile /* = true*/) { if (fromCylinder == nullptr) { g_logger().error("[{}] fromCylinder is nullptr", __FUNCTION__); @@ -1665,7 +1670,7 @@ ReturnValue Game::internalMoveItem(std::shared_ptr fromCylinder, std:: if (checkTile) { if (std::shared_ptr fromTile = fromCylinder->getTile()) { auto it = browseFields.find(fromTile); - if (it != browseFields.end() && it->second == fromCylinder) { + if (it != browseFields.end() && isMatchingCylinder(it->second, fromCylinder)) { fromCylinder = fromTile; } } @@ -2005,7 +2010,7 @@ ReturnValue Game::internalRemoveItem(std::shared_ptr item, int32_t count / std::shared_ptr fromTile = cylinder->getTile(); if (fromTile) { auto it = browseFields.find(fromTile); - if (it != browseFields.end() && it->second == cylinder) { + if (it != browseFields.end() && isMatchingCylinder(it->second, cylinder)) { cylinder = fromTile; } } @@ -2264,7 +2269,7 @@ std::shared_ptr Game::transformItem(std::shared_ptr item, uint16_t n std::shared_ptr fromTile = cylinder->getTile(); if (fromTile) { auto it = browseFields.find(fromTile); - if (it != browseFields.end() && it->second == cylinder) { + if (it != browseFields.end() && isMatchingCylinder(it->second, cylinder)) { cylinder = fromTile; } } @@ -3527,11 +3532,11 @@ void Game::playerMoveUpContainer(uint32_t playerId, uint8_t cid) { } auto it = browseFields.find(tile); - if (it == browseFields.end()) { - parentContainer = std::make_shared(tile); + if (it == browseFields.end() || it->second.expired()) { + parentContainer = Container::create(tile); browseFields[tile] = parentContainer; } else { - parentContainer = it->second; + parentContainer = it->second.lock(); } } @@ -3997,11 +4002,11 @@ void Game::playerBrowseField(uint32_t playerId, const Position &pos) { std::shared_ptr container; auto it = browseFields.find(tile); - if (it == browseFields.end()) { - container = std::make_shared(tile); + if (it == browseFields.end() || it->second.expired()) { + container = Container::create(tile); browseFields[tile] = container; } else { - container = it->second; + container = it->second.lock(); } uint8_t dummyContainerId = 0xF - ((pos.x % 3) * 3 + (pos.y % 3)); @@ -7406,6 +7411,14 @@ void Game::shutdown() { void Game::cleanup() { ToReleaseCreatures.clear(); ToReleaseItems.clear(); + + for (auto it = browseFields.begin(); it != browseFields.end();) { + if (it->second.expired()) { + it = browseFields.erase(it); + } else { + ++it; + } + } } void Game::ReleaseCreature(std::shared_ptr creature) { diff --git a/src/game/game.hpp b/src/game/game.hpp index 6d0e7a633a0..cce1c21e5a3 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -496,7 +496,7 @@ class Game { void addGuild(const std::shared_ptr guild); void removeGuild(uint32_t guildId); - phmap::flat_hash_map, std::shared_ptr> browseFields; + phmap::flat_hash_map, std::weak_ptr> browseFields; void internalRemoveItems(const std::vector> itemVector, uint32_t amount, bool stackable); diff --git a/src/items/containers/container.cpp b/src/items/containers/container.cpp index 8f80d18c9e5..df6878222c9 100644 --- a/src/items/containers/container.cpp +++ b/src/items/containers/container.cpp @@ -30,32 +30,35 @@ Container::Container(uint16_t initType, uint16_t initSize, bool initUnlocked /*= unlocked(initUnlocked), pagination(initPagination) { } -Container::Container(std::shared_ptr tile) : - Container(ITEM_BROWSEFIELD, 30, false, true) { +std::shared_ptr Container::create(uint16_t type) { + return std::make_shared(type); +} + +std::shared_ptr Container::create(uint16_t type, uint16_t size, bool unlocked /*= true*/, bool pagination /*= false*/) { + return std::make_shared(type, size, unlocked, pagination); +} + +std::shared_ptr Container::create(std::shared_ptr tile) { + auto container = std::make_shared(ITEM_BROWSEFIELD, 30, false, true); TileItemVector* itemVector = tile->getItemList(); if (itemVector) { for (auto &item : *itemVector) { if (((item->getContainer() || item->hasProperty(CONST_PROP_MOVEABLE)) || (item->isWrapable() && !item->hasProperty(CONST_PROP_MOVEABLE) && !item->hasProperty(CONST_PROP_BLOCKPATH))) && !item->hasAttribute(ItemAttribute_t::UNIQUEID)) { - itemlist.push_front(item); - item->setParent(getContainer()); + container->itemlist.push_front(item); + item->setParent(container); } } } - setParent(tile); + container->setParent(tile); + return container; } Container::~Container() { if (getID() == ITEM_BROWSEFIELD) { - g_game().browseFields.erase(getTile()); - for (std::shared_ptr item : itemlist) { item->setParent(parent); } - } else { - for (std::shared_ptr item : itemlist) { - item->setParent(nullptr); - } } } @@ -703,7 +706,7 @@ void Container::replaceThing(uint32_t index, std::shared_ptr thing) { onUpdateContainerItem(index, replacedItem, item); } - replacedItem->setParent(nullptr); + replacedItem->resetParent(); } void Container::removeThing(std::shared_ptr thing, uint32_t count) { @@ -735,7 +738,7 @@ void Container::removeThing(std::shared_ptr thing, uint32_t count) { onRemoveContainerItem(index, item); } - item->setParent(nullptr); + item->resetParent(); itemlist.erase(itemlist.begin() + index); } } @@ -894,7 +897,7 @@ void Container::removeItem(std::shared_ptr thing, bool sendUpdateToClient } itemlist.erase(it); - itemToRemove->setParent(nullptr); + itemToRemove->resetParent(); } } diff --git a/src/items/containers/container.hpp b/src/items/containers/container.hpp index 3d50dff6c62..e461e2598f4 100644 --- a/src/items/containers/container.hpp +++ b/src/items/containers/container.hpp @@ -39,9 +39,12 @@ class Container : public Item, public Cylinder { public: explicit Container(uint16_t type); Container(uint16_t type, uint16_t size, bool unlocked = true, bool pagination = false); - explicit Container(std::shared_ptr type); ~Container(); + static std::shared_ptr create(uint16_t type); + static std::shared_ptr create(uint16_t type, uint16_t size, bool unlocked = true, bool pagination = false); + static std::shared_ptr create(std::shared_ptr type); + // non-copyable Container(const Container &) = delete; Container &operator=(const Container &) = delete; diff --git a/src/items/containers/depot/depotchest.cpp b/src/items/containers/depot/depotchest.cpp index b3edfbd82ac..77fef916e77 100644 --- a/src/items/containers/depot/depotchest.cpp +++ b/src/items/containers/depot/depotchest.cpp @@ -68,8 +68,9 @@ void DepotChest::postRemoveNotification(std::shared_ptr thing, std::share } std::shared_ptr DepotChest::getParent() const { - if (parent && parent->getParent()) { - return parent->getParent()->getParent(); + auto parentLocked = parent.lock(); + if (parentLocked && parentLocked->getParent()) { + return parentLocked->getParent()->getParent(); } return nullptr; } diff --git a/src/items/containers/depot/depotchest.hpp b/src/items/containers/depot/depotchest.hpp index 8cded7616fb..22f11cd573e 100644 --- a/src/items/containers/depot/depotchest.hpp +++ b/src/items/containers/depot/depotchest.hpp @@ -40,7 +40,7 @@ class DepotChest final : public Container { std::shared_ptr getParent() const override; std::shared_ptr getRealParent() const override { - return parent; + return parent.lock(); } private: diff --git a/src/items/containers/depot/depotlocker.cpp b/src/items/containers/depot/depotlocker.cpp index cfa40b8e833..53ed57c29ed 100644 --- a/src/items/containers/depot/depotlocker.cpp +++ b/src/items/containers/depot/depotlocker.cpp @@ -29,14 +29,16 @@ ReturnValue DepotLocker::queryAdd(int32_t, const std::shared_ptr &, uint3 } void DepotLocker::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { - if (parent != nullptr) { - parent->postAddNotification(thing, oldParent, index, LINK_PARENT); + auto parentLocked = parent.lock(); + if (parentLocked) { + parentLocked->postAddNotification(thing, oldParent, index, LINK_PARENT); } } void DepotLocker::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { - if (parent != nullptr) { - parent->postRemoveNotification(thing, newParent, index, LINK_PARENT); + auto parentLocked = parent.lock(); + if (parentLocked) { + parentLocked->postRemoveNotification(thing, newParent, index, LINK_PARENT); } } diff --git a/src/items/containers/inbox/inbox.cpp b/src/items/containers/inbox/inbox.cpp index d18ee024362..77e981b2de2 100644 --- a/src/items/containers/inbox/inbox.cpp +++ b/src/items/containers/inbox/inbox.cpp @@ -67,8 +67,9 @@ void Inbox::postRemoveNotification(std::shared_ptr thing, std::shared_ptr } std::shared_ptr Inbox::getParent() const { - if (parent) { - return parent->getParent(); + auto parentLocked = parent.lock(); + if (parentLocked) { + return parentLocked->getParent(); } return nullptr; } diff --git a/src/items/containers/inbox/inbox.hpp b/src/items/containers/inbox/inbox.hpp index be7d74885fc..d6d74ae5f67 100644 --- a/src/items/containers/inbox/inbox.hpp +++ b/src/items/containers/inbox/inbox.hpp @@ -39,7 +39,7 @@ class Inbox final : public Container { std::shared_ptr getParent() const override; std::shared_ptr getRealParent() const override { - return parent; + return parent.lock(); } private: diff --git a/src/items/containers/rewards/reward.cpp b/src/items/containers/rewards/reward.cpp index 2170400bcc5..7f1c4313069 100644 --- a/src/items/containers/rewards/reward.cpp +++ b/src/items/containers/rewards/reward.cpp @@ -54,5 +54,5 @@ void Reward::postRemoveNotification(std::shared_ptr thing, std::shared_pt } std::shared_ptr Reward::getParent() const { - return parent; + return parent.lock(); } diff --git a/src/items/containers/rewards/reward.hpp b/src/items/containers/rewards/reward.hpp index d231f8a0a80..3065d3e0f5e 100644 --- a/src/items/containers/rewards/reward.hpp +++ b/src/items/containers/rewards/reward.hpp @@ -32,6 +32,6 @@ class Reward : public Container { std::shared_ptr getParent() const final; std::shared_ptr getRealParent() const final { - return parent; + return parent.lock(); } }; diff --git a/src/items/containers/rewards/rewardchest.cpp b/src/items/containers/rewards/rewardchest.cpp index 2b02421cdfd..d7f46d74ce6 100644 --- a/src/items/containers/rewards/rewardchest.cpp +++ b/src/items/containers/rewards/rewardchest.cpp @@ -27,14 +27,16 @@ ReturnValue RewardChest::queryAdd(int32_t, const std::shared_ptr &, uint3 } void RewardChest::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { - if (parent != nullptr) { - parent->postAddNotification(thing, oldParent, index, LINK_PARENT); + auto parentLocked = parent.lock(); + if (parentLocked) { + parentLocked->postAddNotification(thing, oldParent, index, LINK_PARENT); } } void RewardChest::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { - if (parent != nullptr) { - parent->postRemoveNotification(thing, newParent, index, LINK_PARENT); + auto parentLocked = parent.lock(); + if (parentLocked) { + parentLocked->postRemoveNotification(thing, newParent, index, LINK_PARENT); } } @@ -52,6 +54,6 @@ void RewardChest::removeItem(std::shared_ptr thing, bool /* sendToClient auto it = std::ranges::find(itemlist.begin(), itemlist.end(), itemToRemove); if (it != itemlist.end()) { itemlist.erase(it); - itemToRemove->setParent(nullptr); + itemToRemove->resetParent(); } } diff --git a/src/items/item.cpp b/src/items/item.cpp index 694ba3009ab..35cef90f539 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -3095,7 +3095,7 @@ std::shared_ptr Item::transform(uint16_t itemId, uint16_t itemCount /*= -1 std::shared_ptr fromTile = cylinder->getTile(); if (fromTile) { auto it = g_game().browseFields.find(fromTile); - if (it != g_game().browseFields.end() && it->second == cylinder) { + if (it != g_game().browseFields.end() && it->second.lock() == cylinder) { cylinder = fromTile; } } @@ -3116,7 +3116,7 @@ std::shared_ptr Item::transform(uint16_t itemId, uint16_t itemCount /*= -1 cylinder->replaceThing(itemIndex, newItem); cylinder->postAddNotification(newItem, cylinder, itemIndex); - setParent(nullptr); + resetParent(); cylinder->postRemoveNotification(static_self_cast(), cylinder, itemIndex); stopDecaying(); g_game().ReleaseItem(static_self_cast()); diff --git a/src/items/item.hpp b/src/items/item.hpp index c9e47077c20..e6cf69566e7 100644 --- a/src/items/item.hpp +++ b/src/items/item.hpp @@ -564,15 +564,18 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { bool hasMarketAttributes() const; std::shared_ptr getParent() const override { - return parent; + return parent.lock(); } - void setParent(std::shared_ptr cylinder) override { + void setParent(std::weak_ptr cylinder) override { parent = cylinder; } + void resetParent() { + parent.reset(); + } std::shared_ptr getTopParent(); std::shared_ptr getTile() override; bool isRemoved() const override { - return !parent || parent->isRemoved(); + return parent.expired() || getParent()->isRemoved(); } bool isInsideDepot(bool includeInbox = false) const; @@ -673,7 +676,7 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { void checkDecayMapItemOnMove(); protected: - std::shared_ptr parent = nullptr; + std::weak_ptr parent; uint16_t id; // the same id as in ItemType uint8_t count = 1; // number of stacked items diff --git a/src/items/thing.hpp b/src/items/thing.hpp index 956c01468f3..8ee2643468e 100644 --- a/src/items/thing.hpp +++ b/src/items/thing.hpp @@ -35,7 +35,7 @@ class Thing { return getParent(); } - virtual void setParent(std::shared_ptr) { + virtual void setParent(std::weak_ptr) { // } diff --git a/src/items/tile.cpp b/src/items/tile.cpp index 08d1c406d70..3e6317760d0 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -340,8 +340,11 @@ void Tile::onAddTileItem(std::shared_ptr item) { if ((item->hasProperty(CONST_PROP_MOVEABLE) || item->getContainer()) || (item->isWrapable() && !item->hasProperty(CONST_PROP_MOVEABLE) && !item->hasProperty(CONST_PROP_BLOCKPATH))) { auto it = g_game().browseFields.find(static_self_cast()); if (it != g_game().browseFields.end()) { - it->second->addItemBack(item); - item->setParent(static_self_cast()); + auto lockedCylinder = it->second.lock(); + if (lockedCylinder) { + lockedCylinder->addItemBack(item); + item->setParent(getTile()); + } } } @@ -409,20 +412,26 @@ void Tile::onAddTileItem(std::shared_ptr item) { void Tile::onUpdateTileItem(std::shared_ptr oldItem, const ItemType &oldType, std::shared_ptr newItem, const ItemType &newType) { if ((newItem->hasProperty(CONST_PROP_MOVEABLE) || newItem->getContainer()) || (newItem->isWrapable() && newItem->hasProperty(CONST_PROP_MOVEABLE) && !oldItem->hasProperty(CONST_PROP_BLOCKPATH))) { - auto it = g_game().browseFields.find(static_self_cast()); + auto it = g_game().browseFields.find(getTile()); if (it != g_game().browseFields.end()) { - int32_t index = it->second->getThingIndex(oldItem); - if (index != -1) { - it->second->replaceThing(index, newItem); - newItem->setParent(static_self_cast()); + auto lockedCylinder = it->second.lock(); + if (lockedCylinder) { + int32_t index = lockedCylinder->getThingIndex(oldItem); + if (index != -1) { + lockedCylinder->replaceThing(index, newItem); + newItem->setParent(static_self_cast()); + } } } } else if ((oldItem->hasProperty(CONST_PROP_MOVEABLE) || oldItem->getContainer()) || (oldItem->isWrapable() && !oldItem->hasProperty(CONST_PROP_MOVEABLE) && !oldItem->hasProperty(CONST_PROP_BLOCKPATH))) { - auto it = g_game().browseFields.find(static_self_cast()); + auto it = g_game().browseFields.find(getTile()); if (it != g_game().browseFields.end()) { - std::shared_ptr oldParent = oldItem->getParent(); - it->second->removeThing(oldItem, oldItem->getItemCount()); - oldItem->setParent(oldParent); + auto lockedCylinder = it->second.lock(); + if (lockedCylinder) { + std::shared_ptr oldParent = oldItem->getParent(); + lockedCylinder->removeThing(oldItem, oldItem->getItemCount()); + oldItem->setParent(oldParent); + } } } @@ -446,9 +455,12 @@ void Tile::onUpdateTileItem(std::shared_ptr oldItem, const ItemType &oldTy void Tile::onRemoveTileItem(const SpectatorHashSet &spectators, const std::vector &oldStackPosVector, std::shared_ptr item) { if ((item->hasProperty(CONST_PROP_MOVEABLE) || item->getContainer()) || (item->isWrapable() && !item->hasProperty(CONST_PROP_MOVEABLE) && !item->hasProperty(CONST_PROP_BLOCKPATH))) { - auto it = g_game().browseFields.find(static_self_cast()); + auto it = g_game().browseFields.find(getTile()); if (it != g_game().browseFields.end()) { - it->second->removeThing(item, item->getItemCount()); + auto lockedCylinder = it->second.lock(); + if (lockedCylinder) { + lockedCylinder->removeThing(item, item->getItemCount()); + } } } for (const auto zone : getZones()) { @@ -958,7 +970,7 @@ void Tile::addThing(int32_t, std::shared_ptr thing) { const ItemType &oldType = Item::items[ground->getID()]; std::shared_ptr oldGround = ground; - ground->setParent(nullptr); + ground->resetParent(); g_game().ReleaseItem(ground); ground = item; resetTileFlags(oldGround); @@ -976,7 +988,7 @@ void Tile::addThing(int32_t, std::shared_ptr thing) { } removeThing(oldSplash, 1); - oldSplash->setParent(nullptr); + oldSplash->resetParent(); g_game().ReleaseItem(oldSplash); postRemoveNotification(oldSplash, nullptr, 0); break; @@ -1013,13 +1025,13 @@ void Tile::addThing(int32_t, std::shared_ptr thing) { if (oldField->isReplaceable()) { removeThing(oldField, 1); - oldField->setParent(nullptr); + oldField->resetParent(); g_game().ReleaseItem(oldField); postRemoveNotification(oldField, nullptr, 0); break; } else { // This magic field cannot be replaced. - item->setParent(nullptr); + item->resetParent(); g_game().ReleaseItem(item); return; } @@ -1122,7 +1134,7 @@ void Tile::replaceThing(uint32_t index, std::shared_ptr thing) { const ItemType &newType = Item::items[item->getID()]; onUpdateTileItem(oldItem, oldType, item, newType); - oldItem->setParent(nullptr); + oldItem->resetParent(); return /*RETURNVALUE_NOERROR*/; } } @@ -1152,7 +1164,7 @@ void Tile::removeThing(std::shared_ptr thing, uint32_t count) { } if (item == ground) { - ground->setParent(nullptr); + ground->resetParent(); ground = nullptr; SpectatorHashSet spectators; @@ -1182,7 +1194,7 @@ void Tile::removeThing(std::shared_ptr thing, uint32_t count) { } } - item->setParent(nullptr); + item->resetParent(); items->erase(it); onRemoveTileItem(spectators, oldStackPosVector, item); } else { @@ -1207,7 +1219,7 @@ void Tile::removeThing(std::shared_ptr thing, uint32_t count) { } } - item->setParent(nullptr); + item->resetParent(); items->erase(it); items->decreaseDownItemCount(); onRemoveTileItem(spectators, oldStackPosVector, item); diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index 3e61141c8fb..6b747a57fcd 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -363,7 +363,7 @@ std::shared_ptr House::getTransferItem() { return nullptr; } - transfer_container.setParent(nullptr); + transfer_container.resetParent(); transferItem = HouseTransferItem::createHouseTransferItem(this); transfer_container.addThing(transferItem); return transferItem; @@ -373,8 +373,7 @@ void House::resetTransferItem() { if (transferItem) { std::shared_ptr tmpItem = transferItem; transferItem = nullptr; - transfer_container.setParent(nullptr); - + transfer_container.resetParent(); transfer_container.removeThing(tmpItem, tmpItem->getItemCount()); g_game().ReleaseItem(tmpItem); } From 60e4ffe99220be02ec82fd85446b3a2a103514e8 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Tue, 12 Sep 2023 17:57:33 -0700 Subject: [PATCH 04/67] fix: weak ptrs for creature factions --- src/creatures/monsters/monster.cpp | 87 ++++++++++++++++-------------- src/creatures/monsters/monster.hpp | 38 ++++++++++--- 2 files changed, 79 insertions(+), 46 deletions(-) diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 5b5e3c1f410..50810f39d69 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -287,23 +287,22 @@ void Monster::onCreatureSay(std::shared_ptr creature, SpeakClasses typ void Monster::addFriend(std::shared_ptr creature) { assert(creature.get() != this); - friendList.insert(creature); + friendList.try_emplace(creature->getID(), creature); } void Monster::removeFriend(std::shared_ptr creature) { - auto it = friendList.find(creature); - if (it != friendList.end()) { - friendList.erase(it); - } + friendList.erase(creature->getID()); } void Monster::addTarget(std::shared_ptr creature, bool pushFront /* = false*/) { assert(creature.get() != this); - if (std::find(targetList.begin(), targetList.end(), creature) == targetList.end()) { + auto cid = creature->getID(); + targetListMap.try_emplace(cid, creature); + if (std::find(targetIDList.begin(), targetIDList.end(), cid) == targetIDList.end()) { if (pushFront) { - targetList.push_front(creature); + targetIDList.push_front(cid); } else { - targetList.push_back(creature); + targetIDList.push_back(cid); } if (!master && getFaction() != FACTION_DEFAULT && creature->getPlayer()) { totalPlayersOnScreen++; @@ -316,32 +315,34 @@ void Monster::removeTarget(std::shared_ptr creature) { return; } - auto it = std::find(targetList.begin(), targetList.end(), creature); - if (it != targetList.end()) { + auto it = std::find(targetIDList.begin(), targetIDList.end(), creature->getID()); + if (it != targetIDList.end()) { if (!master && getFaction() != FACTION_DEFAULT && creature->getPlayer()) { totalPlayersOnScreen--; } - targetList.erase(it); + targetIDList.erase(it); + targetListMap.erase(creature->getID()); } } void Monster::updateTargetList() { auto friendIterator = friendList.begin(); while (friendIterator != friendList.end()) { - std::shared_ptr creature = *friendIterator; - if (creature->getHealth() <= 0 || !canSee(creature->getPosition())) { + auto creature = (*friendIterator).second.lock(); + if (!creature || creature->getHealth() <= 0 || !canSee(creature->getPosition())) { friendIterator = friendList.erase(friendIterator); } else { ++friendIterator; } } - auto targetIterator = targetList.begin(); - while (targetIterator != targetList.end()) { - std::shared_ptr creature = *targetIterator; - if (creature->getHealth() <= 0 || !canSee(creature->getPosition())) { - targetIterator = targetList.erase(targetIterator); + auto targetIterator = targetIDList.begin(); + while (targetIterator != targetIDList.end()) { + auto creature = targetListMap[*targetIterator].lock(); + if (!creature || creature->getHealth() <= 0 || !canSee(creature->getPosition())) { + targetIterator = targetIDList.erase(targetIterator); + targetListMap.erase(*targetIterator); } else { ++targetIterator; } @@ -358,7 +359,8 @@ void Monster::updateTargetList() { } void Monster::clearTargetList() { - targetList.clear(); + targetIDList.clear(); + targetListMap.clear(); } void Monster::clearFriendList() { @@ -434,7 +436,7 @@ void Monster::onCreatureLeave(std::shared_ptr creature) { // update targetList if (isOpponent(creature)) { removeTarget(creature); - if (targetList.empty()) { + if (targetIDList.empty()) { updateIdleStatus(); } } @@ -464,8 +466,9 @@ bool Monster::searchTarget(TargetSearchType_t searchType /*= TARGETSEARCH_DEFAUL std::list> resultList; const Position &myPos = getPosition(); - for (std::shared_ptr creature : targetList) { - if (isTarget(creature)) { + for (auto cid : targetIDList) { + auto creature = targetListMap[cid].lock(); + if (creature && isTarget(creature)) { if ((static_self_cast()->targetDistance == 1) || canUseAttack(myPos, creature)) { resultList.push_back(creature); } @@ -500,7 +503,7 @@ bool Monster::searchTarget(TargetSearchType_t searchType /*= TARGETSEARCH_DEFAUL } } else { int32_t minRange = std::numeric_limits::max(); - for (std::shared_ptr creature : targetList) { + for (auto creature : getTargetList()) { if (!isTarget(creature)) { continue; } @@ -575,7 +578,7 @@ bool Monster::searchTarget(TargetSearchType_t searchType /*= TARGETSEARCH_DEFAUL } // lets just pick the first target in the list - for (std::shared_ptr target : targetList) { + for (auto target : getTargetList()) { if (selectTarget(target)) { return true; } @@ -584,17 +587,23 @@ bool Monster::searchTarget(TargetSearchType_t searchType /*= TARGETSEARCH_DEFAUL } void Monster::onFollowCreatureComplete(std::shared_ptr creature) { - if (creature) { - auto it = std::find(targetList.begin(), targetList.end(), creature); - if (it != targetList.end()) { - std::shared_ptr target = (*it); - targetList.erase(it); - - if (hasFollowPath) { - targetList.push_front(target); - } else if (!isSummon()) { - targetList.push_back(target); - } + if (!creature) { + return; + } + auto it = std::find(targetIDList.begin(), targetIDList.end(), creature->getID()); + if (it != targetIDList.end()) { + auto target = targetListMap[*it].lock(); + if (!target) { + return; + } + targetIDList.erase(it); + + if (hasFollowPath) { + targetIDList.push_front(target->getID()); + } else if (!isSummon()) { + targetIDList.push_back(target->getID()); + } else { + targetListMap.erase(target->getID()); } } } @@ -647,8 +656,8 @@ bool Monster::selectTarget(std::shared_ptr creature) { return false; } - auto it = std::find(targetList.begin(), targetList.end(), creature); - if (it == targetList.end()) { + auto it = std::find(targetIDList.begin(), targetIDList.end(), creature->getID()); + if (it == targetIDList.end()) { // Target not found in our target list. return false; } @@ -682,7 +691,7 @@ void Monster::updateIdleStatus() { bool idle = false; if (conditions.empty()) { - if (!isSummon() && targetList.empty()) { + if (!isSummon() && targetIDList.empty()) { idle = true; } else if ((!isSummon() && totalPlayersOnScreen == 0 || isSummon() && master->getMonster() && master->getMonster()->totalPlayersOnScreen == 0) && getFaction() != FACTION_DEFAULT) { idle = true; @@ -773,7 +782,7 @@ void Monster::onThink(uint32_t interval) { // This happens just after a master orders an attack, so lets follow it aswell. setFollowCreature(attackedCreature); } - } else if (!targetList.empty()) { + } else if (!targetIDList.empty()) { if (!followCreature || !hasFollowPath) { searchTarget(TARGETSEARCH_NEAREST); } else if (isFleeing()) { diff --git a/src/creatures/monsters/monster.hpp b/src/creatures/monsters/monster.hpp index 9df3e95fee1..3291941cf62 100644 --- a/src/creatures/monsters/monster.hpp +++ b/src/creatures/monsters/monster.hpp @@ -20,6 +20,9 @@ class Spawn; using CreatureHashSet = phmap::flat_hash_set>; using CreatureList = std::list>; +using CreatureWeakHashMap = phmap::flat_hash_map>; +using CreatureIDList = std::list; + class Monster final : public Creature { public: static std::shared_ptr createMonster(const std::string &name); @@ -182,11 +185,31 @@ class Monster final : public Creature { bool searchTarget(TargetSearchType_t searchType = TARGETSEARCH_DEFAULT); bool selectTarget(std::shared_ptr creature); - const CreatureList &getTargetList() const { - return targetList; - } - const CreatureHashSet &getFriendList() const { - return friendList; + CreatureList getTargetList() { + std::list> list; + for (auto it = targetIDList.begin(); it != targetIDList.end();) { + auto cid = *it; + if (auto targetCreature = targetListMap[cid].lock()) { + list.push_back(targetCreature); + ++it; + } else { + it = targetIDList.erase(it); + targetListMap.erase(cid); + } + } + return list; + } + CreatureHashSet getFriendList() { + CreatureHashSet set; + for (auto it = friendList.begin(); it != friendList.end();) { + if (auto friendCreature = it->second.lock()) { + set.insert(friendCreature); + ++it; + } else { + it = friendList.erase(it); + } + } + return set; } bool isTarget(std::shared_ptr creature); @@ -301,8 +324,9 @@ class Monster final : public Creature { bool isImmune(CombatType_t combatType) const override; private: - CreatureHashSet friendList; - CreatureList targetList; + CreatureWeakHashMap friendList; + CreatureIDList targetIDList; + CreatureWeakHashMap targetListMap; time_t timeToChangeFiendish = 0; From 9e2c5918198e92a0b72c7393597c0f3bee4b67fe Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Tue, 12 Sep 2023 18:14:23 -0700 Subject: [PATCH 05/67] fix: registerSharedClass --- src/lua/functions/creatures/creature_functions.hpp | 2 +- src/lua/functions/creatures/monster/monster_functions.hpp | 2 +- src/lua/functions/creatures/npc/npc_functions.hpp | 2 +- src/lua/functions/creatures/player/player_functions.hpp | 2 +- src/lua/functions/items/container_functions.hpp | 2 +- src/lua/functions/items/item_functions.hpp | 2 +- src/lua/functions/map/teleport_functions.hpp | 2 +- src/lua/functions/map/tile_functions.hpp | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lua/functions/creatures/creature_functions.hpp b/src/lua/functions/creatures/creature_functions.hpp index 426e4859104..af86c5c7097 100644 --- a/src/lua/functions/creatures/creature_functions.hpp +++ b/src/lua/functions/creatures/creature_functions.hpp @@ -18,7 +18,7 @@ class CreatureFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "Creature", "", CreatureFunctions::luaCreatureCreate); + registerSharedClass(L, "Creature", "", CreatureFunctions::luaCreatureCreate); registerMetaMethod(L, "Creature", "__eq", CreatureFunctions::luaUserdataCompare); registerMethod(L, "Creature", "getEvents", CreatureFunctions::luaCreatureGetEvents); registerMethod(L, "Creature", "registerEvent", CreatureFunctions::luaCreatureRegisterEvent); diff --git a/src/lua/functions/creatures/monster/monster_functions.hpp b/src/lua/functions/creatures/monster/monster_functions.hpp index 95f972f1ff6..9dbb3f81cc9 100644 --- a/src/lua/functions/creatures/monster/monster_functions.hpp +++ b/src/lua/functions/creatures/monster/monster_functions.hpp @@ -18,7 +18,7 @@ class MonsterFunctions final : LuaScriptInterface { private: static void init(lua_State* L) { - registerClass(L, "Monster", "Creature", MonsterFunctions::luaMonsterCreate); + registerSharedClass(L, "Monster", "Creature", MonsterFunctions::luaMonsterCreate); registerMetaMethod(L, "Monster", "__eq", MonsterFunctions::luaUserdataCompare); registerMethod(L, "Monster", "isMonster", MonsterFunctions::luaMonsterIsMonster); registerMethod(L, "Monster", "getType", MonsterFunctions::luaMonsterGetType); diff --git a/src/lua/functions/creatures/npc/npc_functions.hpp b/src/lua/functions/creatures/npc/npc_functions.hpp index 80b10275493..7671780e720 100644 --- a/src/lua/functions/creatures/npc/npc_functions.hpp +++ b/src/lua/functions/creatures/npc/npc_functions.hpp @@ -16,7 +16,7 @@ class NpcFunctions final : LuaScriptInterface { private: static void init(lua_State* L) { - registerClass(L, "Npc", "Creature", NpcFunctions::luaNpcCreate); + registerSharedClass(L, "Npc", "Creature", NpcFunctions::luaNpcCreate); registerMetaMethod(L, "Npc", "__eq", NpcFunctions::luaUserdataCompare); registerMethod(L, "Npc", "isNpc", NpcFunctions::luaNpcIsNpc); registerMethod(L, "Npc", "setMasterPos", NpcFunctions::luaNpcSetMasterPos); diff --git a/src/lua/functions/creatures/player/player_functions.hpp b/src/lua/functions/creatures/player/player_functions.hpp index ff047fb125d..14075cb6906 100644 --- a/src/lua/functions/creatures/player/player_functions.hpp +++ b/src/lua/functions/creatures/player/player_functions.hpp @@ -19,7 +19,7 @@ class PlayerFunctions final : LuaScriptInterface { private: static void init(lua_State* L) { - registerClass(L, "Player", "Creature", PlayerFunctions::luaPlayerCreate); + registerSharedClass(L, "Player", "Creature", PlayerFunctions::luaPlayerCreate); registerMetaMethod(L, "Player", "__eq", PlayerFunctions::luaUserdataCompare); registerMethod(L, "Player", "resetCharmsBestiary", PlayerFunctions::luaPlayerResetCharmsMonsters); diff --git a/src/lua/functions/items/container_functions.hpp b/src/lua/functions/items/container_functions.hpp index a716f31c1ca..ce182326702 100644 --- a/src/lua/functions/items/container_functions.hpp +++ b/src/lua/functions/items/container_functions.hpp @@ -15,7 +15,7 @@ class ContainerFunctions final : LuaScriptInterface { public: private: static void init(lua_State* L) { - registerClass(L, "Container", "Item", ContainerFunctions::luaContainerCreate); + registerSharedClass(L, "Container", "Item", ContainerFunctions::luaContainerCreate); registerMetaMethod(L, "Container", "__eq", ContainerFunctions::luaUserdataCompare); registerMethod(L, "Container", "getSize", ContainerFunctions::luaContainerGetSize); diff --git a/src/lua/functions/items/item_functions.hpp b/src/lua/functions/items/item_functions.hpp index a9100b2316a..b5b3b62ebed 100644 --- a/src/lua/functions/items/item_functions.hpp +++ b/src/lua/functions/items/item_functions.hpp @@ -18,7 +18,7 @@ class ItemFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "Item", "", ItemFunctions::luaItemCreate); + registerSharedClass(L, "Item", "", ItemFunctions::luaItemCreate); registerMetaMethod(L, "Item", "__eq", ItemFunctions::luaUserdataCompare); registerMethod(L, "Item", "isItem", ItemFunctions::luaItemIsItem); diff --git a/src/lua/functions/map/teleport_functions.hpp b/src/lua/functions/map/teleport_functions.hpp index e1e35f265e2..6c02c162028 100644 --- a/src/lua/functions/map/teleport_functions.hpp +++ b/src/lua/functions/map/teleport_functions.hpp @@ -14,7 +14,7 @@ class TeleportFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "Teleport", "Item", TeleportFunctions::luaTeleportCreate); + registerSharedClass(L, "Teleport", "Item", TeleportFunctions::luaTeleportCreate); registerMetaMethod(L, "Teleport", "__eq", TeleportFunctions::luaUserdataCompare); registerMethod(L, "Teleport", "getDestination", TeleportFunctions::luaTeleportGetDestination); diff --git a/src/lua/functions/map/tile_functions.hpp b/src/lua/functions/map/tile_functions.hpp index 149a09e21b5..24e0a87d864 100644 --- a/src/lua/functions/map/tile_functions.hpp +++ b/src/lua/functions/map/tile_functions.hpp @@ -14,7 +14,7 @@ class TileFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "Tile", "", TileFunctions::luaTileCreate); + registerSharedClass(L, "Tile", "", TileFunctions::luaTileCreate); registerMetaMethod(L, "Tile", "__eq", TileFunctions::luaUserdataCompare); registerMethod(L, "Tile", "getPosition", TileFunctions::luaTileGetPosition); From c40b91990550b72efbcda64879b73b6e0d2c6541 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Tue, 12 Sep 2023 18:33:41 -0700 Subject: [PATCH 06/67] improve: remove spurious helper function --- src/game/game.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index 576e30494b6..18ca97a2076 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1652,11 +1652,6 @@ ReturnValue Game::checkMoveItemToCylinder(std::shared_ptr player, std::s return RETURNVALUE_NOERROR; } -bool isMatchingCylinder(const std::weak_ptr &weakCylinder, const std::shared_ptr &targetCylinder) { - auto lockedCylinder = weakCylinder.lock(); - return lockedCylinder && lockedCylinder == targetCylinder; -} - ReturnValue Game::internalMoveItem(std::shared_ptr fromCylinder, std::shared_ptr toCylinder, int32_t index, std::shared_ptr item, uint32_t count, std::shared_ptr* movedItem, uint32_t flags /*= 0*/, std::shared_ptr actor /*=nullptr*/, std::shared_ptr tradeItem /* = nullptr*/, bool checkTile /* = true*/) { if (fromCylinder == nullptr) { g_logger().error("[{}] fromCylinder is nullptr", __FUNCTION__); @@ -1669,8 +1664,7 @@ ReturnValue Game::internalMoveItem(std::shared_ptr fromCylinder, std:: if (checkTile) { if (std::shared_ptr fromTile = fromCylinder->getTile()) { - auto it = browseFields.find(fromTile); - if (it != browseFields.end() && isMatchingCylinder(it->second, fromCylinder)) { + if (fromTile && browseFields.contains(fromTile) && browseFields[fromTile].lock() == fromCylinder) { fromCylinder = fromTile; } } @@ -2009,8 +2003,7 @@ ReturnValue Game::internalRemoveItem(std::shared_ptr item, int32_t count / } std::shared_ptr fromTile = cylinder->getTile(); if (fromTile) { - auto it = browseFields.find(fromTile); - if (it != browseFields.end() && isMatchingCylinder(it->second, cylinder)) { + if (fromTile && browseFields.contains(fromTile) && browseFields[fromTile].lock() == cylinder) { cylinder = fromTile; } } @@ -2267,11 +2260,8 @@ std::shared_ptr Game::transformItem(std::shared_ptr item, uint16_t n } std::shared_ptr fromTile = cylinder->getTile(); - if (fromTile) { - auto it = browseFields.find(fromTile); - if (it != browseFields.end() && isMatchingCylinder(it->second, cylinder)) { - cylinder = fromTile; - } + if (fromTile && browseFields.contains(fromTile) && browseFields[fromTile].lock() == cylinder) { + cylinder = fromTile; } int32_t itemIndex = cylinder->getThingIndex(item); From 191e6557c0aa687f6c2c8a2288961d4140a03150 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Tue, 12 Sep 2023 19:12:23 -0700 Subject: [PATCH 07/67] fix: push shared pointer to lua correctly --- src/creatures/interactions/chat.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/creatures/interactions/chat.cpp b/src/creatures/interactions/chat.cpp index 6aaf7390e91..33659479618 100644 --- a/src/creatures/interactions/chat.cpp +++ b/src/creatures/interactions/chat.cpp @@ -154,7 +154,7 @@ bool ChatChannel::executeCanJoinEvent(const std::shared_ptr &player) { lua_State* L = scriptInterface->getLuaState(); scriptInterface->pushFunction(canJoinEvent); - LuaScriptInterface::pushUserdata(L, &player); + LuaScriptInterface::pushUserdata(L, player); LuaScriptInterface::setMetatable(L, -1, "Player"); return scriptInterface->callFunction(1); @@ -180,7 +180,7 @@ bool ChatChannel::executeOnJoinEvent(const std::shared_ptr &player) { lua_State* L = scriptInterface->getLuaState(); scriptInterface->pushFunction(onJoinEvent); - LuaScriptInterface::pushUserdata(L, &player); + LuaScriptInterface::pushUserdata(L, player); LuaScriptInterface::setMetatable(L, -1, "Player"); return scriptInterface->callFunction(1); @@ -206,7 +206,7 @@ bool ChatChannel::executeOnLeaveEvent(const std::shared_ptr &player) { lua_State* L = scriptInterface->getLuaState(); scriptInterface->pushFunction(onLeaveEvent); - LuaScriptInterface::pushUserdata(L, &player); + LuaScriptInterface::pushUserdata(L, player); LuaScriptInterface::setMetatable(L, -1, "Player"); return scriptInterface->callFunction(1); @@ -232,7 +232,7 @@ bool ChatChannel::executeOnSpeakEvent(const std::shared_ptr &player, Spe lua_State* L = scriptInterface->getLuaState(); scriptInterface->pushFunction(onSpeakEvent); - LuaScriptInterface::pushUserdata(L, &player); + LuaScriptInterface::pushUserdata(L, player); LuaScriptInterface::setMetatable(L, -1, "Player"); lua_pushnumber(L, type); From f1b6ac859f2c1e3c524ed30c97cf5b8fb6c73b51 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Tue, 12 Sep 2023 21:00:00 -0700 Subject: [PATCH 08/67] fix: copy args before invoking callbacks --- src/lua/callbacks/events_callbacks.hpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/lua/callbacks/events_callbacks.hpp b/src/lua/callbacks/events_callbacks.hpp index e8e556068da..7eb471430ef 100644 --- a/src/lua/callbacks/events_callbacks.hpp +++ b/src/lua/callbacks/events_callbacks.hpp @@ -78,8 +78,14 @@ class EventsCallbacks { template void executeCallback(EventCallback_t eventType, CallbackFunc callbackFunc, Args &&... args) { for (const auto &callback : getCallbacksByType(eventType)) { + auto argsCopy = std::make_tuple(args...); if (callback && callback->isLoadedCallback()) { - ((*callback).*callbackFunc)(std::forward(args)...); + std::apply( + [&callback, &callbackFunc](auto &&... args) { + ((*callback).*callbackFunc)(std::forward(args)...); + }, + argsCopy + ); } } } @@ -96,8 +102,14 @@ class EventsCallbacks { bool allCallbacksSucceeded = true; for (const auto &callback : getCallbacksByType(eventType)) { - if (callback && callback->isLoadedCallback()) { // Verifique se o callback é não nulo - bool callbackResult = ((*callback).*callbackFunc)(std::forward(args)...); + auto argsCopy = std::make_tuple(args...); + if (callback && callback->isLoadedCallback()) { + bool callbackResult = std::apply( + [&callback, &callbackFunc](auto &&... args) { + return ((*callback).*callbackFunc)(std::forward(args)...); + }, + argsCopy + ); allCallbacksSucceeded = allCallbacksSucceeded && callbackResult; } } From 6367f1d92fb3504bd99d9b8e7d4a3a6c158aebd5 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 13 Sep 2023 22:56:17 -0300 Subject: [PATCH 09/67] fix: pass itemvector to const reference --- src/game/game.cpp | 2 +- src/game/game.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index 18ca97a2076..1122705df60 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -9240,7 +9240,7 @@ void Game::removeGuild(uint32_t guildId) { guilds.erase(guildId); } -void Game::internalRemoveItems(const std::vector> itemVector, uint32_t amount, bool stackable) { +void Game::internalRemoveItems(const std::vector> &itemVector, uint32_t amount, bool stackable) { if (stackable) { for (std::shared_ptr item : itemVector) { if (item->getItemCount() > amount) { diff --git a/src/game/game.hpp b/src/game/game.hpp index cce1c21e5a3..b8d2bf13b32 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -498,7 +498,7 @@ class Game { phmap::flat_hash_map, std::weak_ptr> browseFields; - void internalRemoveItems(const std::vector> itemVector, uint32_t amount, bool stackable); + void internalRemoveItems(const std::vector> &itemVector, uint32_t amount, bool stackable); std::shared_ptr getBedBySleeper(uint32_t guid) const; void setBedSleeper(std::shared_ptr bed, uint32_t guid); From 19f57a3b57464b074d9c15fd5de358d52e1b404e Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 14 Sep 2023 18:21:55 -0700 Subject: [PATCH 10/67] fix: house door text --- src/map/house/house.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index 6b747a57fcd..52d1a5966ba 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -114,9 +114,9 @@ void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, std::shared void House::updateDoorDescription() const { std::ostringstream ss; if (owner != 0) { - ss << "It belongs to house '" << houseName << "'. " << ownerName << " owns static_self_cast() house."; + ss << "It belongs to house '" << houseName << "'. " << ownerName << " owns this house."; } else { - ss << "It belongs to house '" << houseName << "'. Nobody owns static_self_cast() house."; + ss << "It belongs to house '" << houseName << "'. Nobody owns this house."; } ss << " It is " << getSize() << " square meters."; From f8709b147e867e88fd360c40df5bd408ae00c2cf Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sat, 16 Sep 2023 10:11:49 -0700 Subject: [PATCH 11/67] improve: correctly handle ptrs in Creature --- src/creatures/creature.cpp | 79 ++++++++---- src/creatures/creature.hpp | 54 ++++---- src/creatures/monsters/monster.cpp | 136 +++++++++++---------- src/creatures/monsters/monster.hpp | 6 +- src/creatures/players/player.cpp | 24 +++- src/creatures/players/player.hpp | 6 +- src/game/game.cpp | 2 +- src/items/containers/container.cpp | 10 +- src/items/containers/container.hpp | 2 +- src/items/containers/depot/depotchest.cpp | 2 +- src/items/containers/depot/depotchest.hpp | 6 +- src/items/containers/depot/depotlocker.hpp | 2 +- src/items/containers/inbox/inbox.cpp | 2 +- src/items/containers/inbox/inbox.hpp | 6 +- src/items/containers/rewards/reward.cpp | 2 +- src/items/containers/rewards/reward.hpp | 4 +- src/items/cylinder.hpp | 2 +- src/items/item.cpp | 6 +- src/items/item.hpp | 10 +- src/items/thing.hpp | 6 +- src/items/tile.hpp | 2 +- 21 files changed, 212 insertions(+), 157 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 6960fadc9c2..490e58e51cc 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -26,7 +26,7 @@ Creature::Creature() { } Creature::~Creature() { - for (std::shared_ptr summon : summons) { + for (std::shared_ptr summon : m_summons) { summon->setAttackedCreature(nullptr); summon->removeMaster(); } @@ -107,10 +107,13 @@ void Creature::onThink(uint32_t interval) { updateMapCache(); } + auto followCreature = getFollowCreature(); + auto master = getMaster(); if (followCreature && master != followCreature && !canSeeCreature(followCreature)) { onCreatureDisappear(followCreature, false); } + auto attackedCreature = getAttackedCreature(); if (attackedCreature && master != attackedCreature && !canSeeCreature(attackedCreature)) { onCreatureDisappear(attackedCreature, false); } @@ -143,11 +146,15 @@ void Creature::onThink(uint32_t interval) { } void Creature::onAttacking(uint32_t interval) { + auto attackedCreature = getAttackedCreature(); if (!attackedCreature) { return; } onAttacked(); + if (!attackedCreature) { + return; + } attackedCreature->onAttacked(); if (g_game().isSightClear(getPosition(), attackedCreature->getPosition(), true)) { @@ -391,18 +398,19 @@ void Creature::onRemoveCreature(std::shared_ptr creature, bool) { } void Creature::onCreatureDisappear(std::shared_ptr creature, bool isLogout) { - if (attackedCreature == creature) { + if (getAttackedCreature() == creature) { setAttackedCreature(nullptr); onAttackedCreatureDisappear(isLogout); } - if (followCreature == creature) { + if (getFollowCreature() == creature) { setFollowCreature(nullptr); onFollowCreatureDisappear(isLogout); } } void Creature::onChangeZone(ZoneType_t zone) { + auto attackedCreature = getAttackedCreature(); if (attackedCreature && zone == ZONE_PROTECTION) { onCreatureDisappear(attackedCreature, false); } @@ -410,11 +418,14 @@ void Creature::onChangeZone(ZoneType_t zone) { void Creature::onAttackedCreatureChangeZone(ZoneType_t zone) { if (zone == ZONE_PROTECTION) { - onCreatureDisappear(attackedCreature, false); + auto attackedCreature = getAttackedCreature(); + if (attackedCreature) { + onCreatureDisappear(attackedCreature, false); + } } } -void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) const { +void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) { if (hasSummons()) { std::vector> despawnMonsterList; for (std::shared_ptr creature : getSummons()) { @@ -424,6 +435,7 @@ void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) cons const Position &pos = creature->getPosition(); std::shared_ptr monster = creature->getMonster(); + auto tile = getTile(); bool protectionZoneCheck = tile ? tile->hasFlag(TILESTATE_PROTECTIONZONE) : false; // Check if any of our summons is out of range (+/- 0 floors or 15 tiles away) bool checkSummonDist = Position::getDistanceZ(newPos, pos) > 0 || (std::max(Position::getDistanceX(newPos, pos), Position::getDistanceY(newPos, pos)) > 15); @@ -588,6 +600,7 @@ void Creature::onCreatureMove(std::shared_ptr creature, std::shared_pt } } + auto followCreature = getFollowCreature(); if (followCreature && (creature == getCreature() || creature == followCreature)) { if (hasFollowPath) { isUpdatingPath = true; @@ -599,7 +612,8 @@ void Creature::onCreatureMove(std::shared_ptr creature, std::shared_pt } } - if (creature == attackedCreature || (creature == getCreature() && attackedCreature)) { + auto attackedCreature = getAttackedCreature(); + if (attackedCreature && (creature == attackedCreature || creature == getCreature())) { if (newPos.z != oldPos.z || !canSee(attackedCreature->getPosition())) { onCreatureDisappear(attackedCreature, false); } else { @@ -683,14 +697,14 @@ void Creature::onDeath() { g_game().removeCreature(static_self_cast(), false); } - if (master) { + if (getMaster()) { removeMaster(); } } bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared_ptr mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified) { if (!lootDrop && getMonster()) { - if (master) { + if (getMaster()) { // Scripting event onDeath const CreatureEventList &deathEvents = getCreatureEvents(CREATURE_EVENT_DEATH); for (const auto deathEventPtr : deathEvents) { @@ -920,24 +934,25 @@ BlockType_t Creature::blockHit(std::shared_ptr attacker, CombatType_t bool Creature::setAttackedCreature(std::shared_ptr creature) { if (creature) { auto monster = getMonster(); + auto tile = getTile(); if (monster && monster->isFamiliar() && tile && tile->hasFlag(TILESTATE_PROTECTIONZONE)) { return false; } const Position &creaturePos = creature->getPosition(); if (creaturePos.z != getPosition().z || !canSee(creaturePos)) { - attackedCreature = nullptr; + m_attackedCreature.reset(); return false; } - attackedCreature = creature; - onAttackedCreature(attackedCreature); - attackedCreature->onAttacked(); + m_attackedCreature = creature; + onAttackedCreature(creature); + creature->onAttacked(); } else { - attackedCreature = nullptr; + m_attackedCreature.reset(); } - for (std::shared_ptr summon : summons) { + for (std::shared_ptr summon : m_summons) { summon->setAttackedCreature(creature); } return true; @@ -952,6 +967,7 @@ void Creature::getPathSearchParams(std::shared_ptr, FindPathParams &fp } void Creature::goToFollowCreature() { + auto followCreature = getFollowCreature(); if (followCreature) { if (isSummon() && !getMonster()->isFamiliar() && !canFollowMaster()) { hasFollowPath = false; @@ -1001,25 +1017,29 @@ void Creature::goToFollowCreature() { onFollowCreatureComplete(followCreature); } -bool Creature::canFollowMaster() const { +bool Creature::canFollowMaster() { + auto master = getMaster(); + if (!master) { + return false; + } auto tile = master->getTile(); return tile && !tile->hasFlag(TILESTATE_PROTECTIONZONE) && (canSeeInvisibility() || !master->isInvisible()); } bool Creature::setFollowCreature(std::shared_ptr creature) { if (creature) { - if (followCreature == creature) { + if (getFollowCreature() == creature) { return true; } if (hasCondition(CONDITION_FEARED)) { - followCreature = nullptr; + m_followCreature.reset(); return false; } const Position &creaturePos = creature->getPosition(); if (creaturePos.z != getPosition().z || !canSee(creaturePos)) { - followCreature = nullptr; + m_followCreature.reset(); return false; } @@ -1030,11 +1050,11 @@ bool Creature::setFollowCreature(std::shared_ptr creature) { hasFollowPath = false; forceUpdateFollowPath = false; - followCreature = creature; + m_followCreature = creature; isUpdatingPath = true; } else { isUpdatingPath = false; - followCreature = nullptr; + m_followCreature.reset(); } onFollowCreature(creature); @@ -1102,6 +1122,7 @@ void Creature::onEndCondition(ConditionType_t) { } void Creature::onTickCondition(ConditionType_t type, bool &bRemove) { + auto tile = getTile(); std::shared_ptr field = tile ? tile->getFieldItem() : nullptr; if (!field) { return; @@ -1157,6 +1178,7 @@ void Creature::onAttackedCreatureKilled(std::shared_ptr target) { } bool Creature::onKilledCreature(std::shared_ptr target, bool lastHit) { + auto master = getMaster(); if (master) { master->onKilledCreature(target, lastHit); } @@ -1170,6 +1192,7 @@ bool Creature::onKilledCreature(std::shared_ptr target, bool lastHit) } void Creature::onGainExperience(uint64_t gainExp, std::shared_ptr target) { + auto master = getMaster(); if (gainExp == 0 || !master) { return; } @@ -1202,8 +1225,9 @@ void Creature::onGainExperience(uint64_t gainExp, std::shared_ptr targ bool Creature::setMaster(std::shared_ptr newMaster, bool reloadCreature /* = false*/) { // Persists if this creature has ever been a summon this->summoned = true; + auto oldMaster = getMaster(); - if (!newMaster && !master) { + if (!newMaster && !oldMaster) { return false; } @@ -1215,16 +1239,15 @@ bool Creature::setMaster(std::shared_ptr newMaster, bool reloadCreatur g_game().reloadCreature(static_self_cast()); } if (newMaster) { - newMaster->summons.push_back(static_self_cast()); + newMaster->m_summons.push_back(static_self_cast()); } - std::shared_ptr oldMaster = master; - master = newMaster; + m_master = newMaster; if (oldMaster) { - auto summon = std::find(oldMaster->summons.begin(), oldMaster->summons.end(), getCreature()); - if (summon != oldMaster->summons.end()) { - oldMaster->summons.erase(summon); + auto summon = std::find(oldMaster->m_summons.begin(), oldMaster->m_summons.end(), getCreature()); + if (summon != oldMaster->m_summons.end()) { + oldMaster->m_summons.erase(summon); } } return true; @@ -1416,6 +1439,7 @@ int64_t Creature::getStepDuration() { calculatedStepSpeed = (stepSpeed > -Creature::speedB) ? calculatedStepSpeed : 1; uint32_t groundSpeed = 150; + auto tile = getTile(); if (tile && tile->getGround()) { std::shared_ptr ground = tile->getGround(); const ItemType &it = Item::items[ground->getID()]; @@ -1777,6 +1801,7 @@ const phmap::parallel_flat_hash_set> Creature::getZones() } void Creature::iconChanged() { + auto tile = getTile(); if (!tile) { return; } diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index 56b017c8970..0ce29cd7161 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -135,7 +135,7 @@ class Creature : virtual public Thing, public SharedObject { bool isPushable() override { return getWalkDelay() <= 0; } - bool isRemoved() const override final { + bool isRemoved() override final { return isInternalRemoved; } virtual bool canSeeInvisibility() const { @@ -255,9 +255,9 @@ class Creature : virtual public Thing, public SharedObject { return defaultOutfit; } bool isInvisible() const; - ZoneType_t getZoneType() const { - if (tile) { - return tile->getZoneType(); + ZoneType_t getZoneType() { + if (getTile()) { + return getTile()->getZoneType(); } return ZONE_NORMAL; @@ -278,7 +278,7 @@ class Creature : virtual public Thing, public SharedObject { // follow functions std::shared_ptr getFollowCreature() const { - return followCreature; + return m_followCreature.lock(); } virtual bool setFollowCreature(std::shared_ptr creature); @@ -288,7 +288,7 @@ class Creature : virtual public Thing, public SharedObject { // combat functions std::shared_ptr getAttackedCreature() { - return attackedCreature; + return m_attackedCreature.lock(); } virtual bool setAttackedCreature(std::shared_ptr creature); @@ -312,13 +312,13 @@ class Creature : virtual public Thing, public SharedObject { bool setMaster(std::shared_ptr newMaster, bool reloadCreature = false); void removeMaster() { - if (master) { - master = nullptr; + if (getMaster()) { + m_master.reset(); } } bool isSummon() const { - return master != nullptr; + return !m_master.expired(); } /** @@ -328,11 +328,11 @@ class Creature : virtual public Thing, public SharedObject { return summoned; } std::shared_ptr getMaster() const { - return master; + return m_master.lock(); } const std::list> &getSummons() const { - return summons; + return m_summons; } virtual int32_t getArmor() const { @@ -445,7 +445,7 @@ class Creature : virtual public Thing, public SharedObject { * @return true * @return false */ - void checkSummonMove(const Position &newPos, bool teleportSummon = false) const; + void checkSummonMove(const Position &newPos, bool teleportSummon = false); virtual void onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport); virtual void onAttackedCreatureDisappear(bool) { } @@ -460,7 +460,7 @@ class Creature : virtual public Thing, public SharedObject { } size_t getSummonCount() const { - return summons.size(); + return m_summons.size(); } /** @@ -470,7 +470,7 @@ class Creature : virtual public Thing, public SharedObject { * @return false = empty */ bool hasSummons() const { - if (!summons.empty()) { + if (!m_summons.empty()) { return true; } return false; @@ -490,13 +490,15 @@ class Creature : virtual public Thing, public SharedObject { bool registerCreatureEvent(const std::string &name); bool unregisterCreatureEvent(const std::string &name); - std::shared_ptr getParent() const override final { - return tile; + std::shared_ptr getParent() override final { + return getTile(); } void setParent(std::weak_ptr cylinder) override final { - if (!cylinder.expired()) { - tile = std::static_pointer_cast(cylinder.lock()); - position = tile->getPosition(); + auto lockedCylinder = cylinder.lock(); + if (lockedCylinder) { + auto newParent = lockedCylinder->getTile(); + position = newParent->getPosition(); + m_tile = newParent; } } @@ -505,7 +507,7 @@ class Creature : virtual public Thing, public SharedObject { } std::shared_ptr getTile() override final { - return tile; + return m_tile.lock(); } int32_t getWalkCache(const Position &pos); @@ -653,16 +655,16 @@ class Creature : virtual public Thing, public SharedObject { CountMap damageMap; - std::list> summons; + std::list> m_summons; CreatureEventList eventsList; ConditionList conditions; std::forward_list listWalkDir; - std::shared_ptr tile = nullptr; - std::shared_ptr attackedCreature = nullptr; - std::shared_ptr master = nullptr; - std::shared_ptr followCreature = nullptr; + std::weak_ptr m_tile; + std::weak_ptr m_attackedCreature; + std::weak_ptr m_master; + std::weak_ptr m_followCreature; /** * We need to persist if this creature is summon or not because when we @@ -763,7 +765,7 @@ class Creature : virtual public Thing, public SharedObject { friend class CreatureFunctions; private: - bool canFollowMaster() const; + bool canFollowMaster(); bool isLostSummon(); void handleLostSummon(bool teleportSummons); }; diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 50810f39d69..764eb1f037c 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -227,6 +227,7 @@ void Monster::onCreatureMove(std::shared_ptr creature, std::shared_ptr updateIdleStatus(); if (!isSummon()) { + auto followCreature = getFollowCreature(); if (followCreature) { const Position &followPosition = followCreature->getPosition(); const Position &pos = getPosition(); @@ -304,7 +305,7 @@ void Monster::addTarget(std::shared_ptr creature, bool pushFront /* = } else { targetIDList.push_back(cid); } - if (!master && getFaction() != FACTION_DEFAULT && creature->getPlayer()) { + if (!getMaster() && getFaction() != FACTION_DEFAULT && creature->getPlayer()) { totalPlayersOnScreen++; } } @@ -317,7 +318,7 @@ void Monster::removeTarget(std::shared_ptr creature) { auto it = std::find(targetIDList.begin(), targetIDList.end(), creature->getID()); if (it != targetIDList.end()) { - if (!master && getFaction() != FACTION_DEFAULT && creature->getPlayer()) { + if (!getMaster() && getFaction() != FACTION_DEFAULT && creature->getPlayer()) { totalPlayersOnScreen--; } @@ -689,11 +690,12 @@ void Monster::setIdle(bool idle) { void Monster::updateIdleStatus() { bool idle = false; + auto master = getMaster(); if (conditions.empty()) { if (!isSummon() && targetIDList.empty()) { idle = true; - } else if ((!isSummon() && totalPlayersOnScreen == 0 || isSummon() && master->getMonster() && master->getMonster()->totalPlayersOnScreen == 0) && getFaction() != FACTION_DEFAULT) { + } else if (master && (!isSummon() && totalPlayersOnScreen == 0 || isSummon() && master->getMonster() && master->getMonster()->totalPlayersOnScreen == 0) && getFaction() != FACTION_DEFAULT) { idle = true; } } @@ -767,6 +769,8 @@ void Monster::onThink(uint32_t interval) { if (!isIdle) { addEventWalk(); + auto attackedCreature = getAttackedCreature(); + auto followCreature = getFollowCreature(); if (isSummon()) { if (!attackedCreature) { if (getMaster() && getMaster()->getAttackedCreature()) { @@ -801,6 +805,7 @@ void Monster::onThink(uint32_t interval) { } void Monster::doAttacking(uint32_t interval) { + auto attackedCreature = getAttackedCreature(); if (!attackedCreature || (isSummon() && attackedCreature.get() == this)) { return; } @@ -821,10 +826,6 @@ void Monster::doAttacking(uint32_t interval) { for (const spellBlock_t &spellBlock : mType->info.attackSpells) { bool inRange = false; - if (attackedCreature == nullptr) { - break; - } - if (spellBlock.spell == nullptr || spellBlock.isMelee && isFleeing()) { continue; } @@ -855,7 +856,7 @@ void Monster::doAttacking(uint32_t interval) { continue; } - spellBlock.spell->castSpell(static_self_cast(), attackedCreature); + spellBlock.spell->castSpell(getMonster(), attackedCreature); if (spellBlock.isMelee) { extraMeleeAttack = false; @@ -995,14 +996,14 @@ void Monster::onThinkDefense(uint32_t interval) { } } - if (!isSummon() && summons.size() < mType->info.maxSummons && hasFollowPath) { + if (!isSummon() && m_summons.size() < mType->info.maxSummons && hasFollowPath) { for (const summonBlock_t &summonBlock : mType->info.summons) { if (summonBlock.speed > defenseTicks) { resetTicks = false; continue; } - if (summons.size() >= mType->info.maxSummons) { + if (m_summons.size() >= mType->info.maxSummons) { continue; } @@ -1012,7 +1013,7 @@ void Monster::onThinkDefense(uint32_t interval) { } uint32_t summonCount = 0; - for (std::shared_ptr summon : summons) { + for (std::shared_ptr summon : m_summons) { if (summon->getName() == summonBlock.name) { ++summonCount; } @@ -1178,7 +1179,7 @@ bool Monster::getNextStep(Direction &nextDirection, uint32_t &flags) { bool result = false; - if (followCreature && hasFollowPath) { + if (getFollowCreature() && hasFollowPath) { doFollowCreature(flags, nextDirection, result); } else { doRandomStep(nextDirection, result); @@ -1219,6 +1220,8 @@ void Monster::doFollowCreature(uint32_t &flags, Direction &nextDirection, bool & updateMapCache(); } // target dancing + auto attackedCreature = getAttackedCreature(); + auto followCreature = getFollowCreature(); if (attackedCreature && attackedCreature == followCreature) { if (isFleeing()) { result = getDanceStep(getPosition(), nextDirection, false, false); @@ -1247,9 +1250,11 @@ bool Monster::getRandomStep(const Position &creaturePos, Direction &moveDirectio } bool Monster::getDanceStep(const Position &creaturePos, Direction &moveDirection, bool keepAttack /*= true*/, bool keepDistance /*= true*/) { + auto attackedCreature = getAttackedCreature(); + if (!attackedCreature) { + return false; + } bool canDoAttackNow = canUseAttack(creaturePos, attackedCreature); - - assert(attackedCreature != nullptr); const Position ¢erPos = attackedCreature->getPosition(); int_fast32_t offset_x = Position::getOffsetX(creaturePos, centerPos); @@ -1266,13 +1271,12 @@ bool Monster::getDanceStep(const Position &creaturePos, Direction &moveDirection } std::vector dirList; - if (!keepDistance || offset_y >= 0) { uint32_t tmpDist = std::max(distance_x, std::abs((creaturePos.getY() - 1) - centerPos.getY())); if (tmpDist == centerToDist && canWalkTo(creaturePos, DIRECTION_NORTH)) { bool result = true; - if (keepAttack) { + if (attackedCreature && keepAttack) { result = (!canDoAttackNow || canUseAttack(Position(creaturePos.x, creaturePos.y - 1, creaturePos.z), attackedCreature)); } @@ -1287,7 +1291,7 @@ bool Monster::getDanceStep(const Position &creaturePos, Direction &moveDirection if (tmpDist == centerToDist && canWalkTo(creaturePos, DIRECTION_SOUTH)) { bool result = true; - if (keepAttack) { + if (attackedCreature && keepAttack) { result = (!canDoAttackNow || canUseAttack(Position(creaturePos.x, creaturePos.y + 1, creaturePos.z), attackedCreature)); } @@ -1302,7 +1306,7 @@ bool Monster::getDanceStep(const Position &creaturePos, Direction &moveDirection if (tmpDist == centerToDist && canWalkTo(creaturePos, DIRECTION_EAST)) { bool result = true; - if (keepAttack) { + if (attackedCreature && keepAttack) { result = (!canDoAttackNow || canUseAttack(Position(creaturePos.x + 1, creaturePos.y, creaturePos.z), attackedCreature)); } @@ -1317,7 +1321,7 @@ bool Monster::getDanceStep(const Position &creaturePos, Direction &moveDirection if (tmpDist == centerToDist && canWalkTo(creaturePos, DIRECTION_WEST)) { bool result = true; - if (keepAttack) { + if (attackedCreature && keepAttack) { result = (!canDoAttackNow || canUseAttack(Position(creaturePos.x - 1, creaturePos.y, creaturePos.z), attackedCreature)); } @@ -1848,11 +1852,11 @@ void Monster::death(std::shared_ptr) { } setAttackedCreature(nullptr); - for (std::shared_ptr summon : summons) { + for (std::shared_ptr summon : m_summons) { summon->changeHealth(-summon->getHealth()); summon->removeMaster(); } - summons.clear(); + m_summons.clear(); clearTargetList(); clearFriendList(); @@ -1923,59 +1927,61 @@ bool Monster::getCombatValues(int32_t &min, int32_t &max) { void Monster::updateLookDirection() { Direction newDir = getDirection(); + auto attackedCreature = getAttackedCreature(); + if (!attackedCreature) { + return; + } + + const Position &pos = getPosition(); + const Position &attackedCreaturePos = attackedCreature->getPosition(); + int_fast32_t offsetx = Position::getOffsetX(attackedCreaturePos, pos); + int_fast32_t offsety = Position::getOffsetY(attackedCreaturePos, pos); - if (attackedCreature) { - const Position &pos = getPosition(); - const Position &attackedCreaturePos = attackedCreature->getPosition(); - int_fast32_t offsetx = Position::getOffsetX(attackedCreaturePos, pos); - int_fast32_t offsety = Position::getOffsetY(attackedCreaturePos, pos); - - int32_t dx = std::abs(offsetx); - int32_t dy = std::abs(offsety); - if (dx > dy) { - // look EAST/WEST - if (offsetx < 0) { + int32_t dx = std::abs(offsetx); + int32_t dy = std::abs(offsety); + if (dx > dy) { + // look EAST/WEST + if (offsetx < 0) { + newDir = DIRECTION_WEST; + } else { + newDir = DIRECTION_EAST; + } + } else if (dx < dy) { + // look NORTH/SOUTH + if (offsety < 0) { + newDir = DIRECTION_NORTH; + } else { + newDir = DIRECTION_SOUTH; + } + } else { + Direction dir = getDirection(); + if (offsetx < 0 && offsety < 0) { + if (dir == DIRECTION_SOUTH) { newDir = DIRECTION_WEST; - } else { - newDir = DIRECTION_EAST; - } - } else if (dx < dy) { - // look NORTH/SOUTH - if (offsety < 0) { + } else if (dir == DIRECTION_EAST) { newDir = DIRECTION_NORTH; - } else { + } + } else if (offsetx < 0 && offsety > 0) { + if (dir == DIRECTION_NORTH) { + newDir = DIRECTION_WEST; + } else if (dir == DIRECTION_EAST) { newDir = DIRECTION_SOUTH; } + } else if (offsetx > 0 && offsety < 0) { + if (dir == DIRECTION_SOUTH) { + newDir = DIRECTION_EAST; + } else if (dir == DIRECTION_WEST) { + newDir = DIRECTION_NORTH; + } } else { - Direction dir = getDirection(); - if (offsetx < 0 && offsety < 0) { - if (dir == DIRECTION_SOUTH) { - newDir = DIRECTION_WEST; - } else if (dir == DIRECTION_EAST) { - newDir = DIRECTION_NORTH; - } - } else if (offsetx < 0 && offsety > 0) { - if (dir == DIRECTION_NORTH) { - newDir = DIRECTION_WEST; - } else if (dir == DIRECTION_EAST) { - newDir = DIRECTION_SOUTH; - } - } else if (offsetx > 0 && offsety < 0) { - if (dir == DIRECTION_SOUTH) { - newDir = DIRECTION_EAST; - } else if (dir == DIRECTION_WEST) { - newDir = DIRECTION_NORTH; - } - } else { - if (dir == DIRECTION_NORTH) { - newDir = DIRECTION_EAST; - } else if (dir == DIRECTION_WEST) { - newDir = DIRECTION_SOUTH; - } + if (dir == DIRECTION_NORTH) { + newDir = DIRECTION_EAST; + } else if (dir == DIRECTION_WEST) { + newDir = DIRECTION_SOUTH; } } } - g_game().internalCreatureTurn(static_self_cast(), newDir); + g_game().internalCreatureTurn(getMonster(), newDir); } void Monster::dropLoot(std::shared_ptr corpse, std::shared_ptr) { diff --git a/src/creatures/monsters/monster.hpp b/src/creatures/monsters/monster.hpp index 3291941cf62..5f589af0e28 100644 --- a/src/creatures/monsters/monster.hpp +++ b/src/creatures/monsters/monster.hpp @@ -87,13 +87,15 @@ class Monster final : public Creature { } Faction_t getFaction() const override { - if (master) { - return master->getFaction(); + auto master = getMaster(); + if (getMaster()) { + return getMaster()->getFaction(); } return mType->info.faction; } bool isEnemyFaction(Faction_t faction) const { + auto master = getMaster(); if (master && master->getMonster()) { return master->getMonster()->isEnemyFaction(faction); } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index a52ae343794..f71a097af5f 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -445,7 +445,7 @@ float Player::getDefenseFactor() const { } } -uint32_t Player::getClientIcons() const { +uint32_t Player::getClientIcons() { uint32_t icons = 0; for (Condition* condition : conditions) { if (!isSuppress(condition->getType())) { @@ -457,6 +457,7 @@ uint32_t Player::getClientIcons() const { icons |= ICON_REDSWORDS; } + auto tile = getTile(); if (tile && tile->hasFlag(TILESTATE_PROTECTIONZONE)) { icons |= ICON_PIGEON; client->sendRestingStatus(1); @@ -1254,6 +1255,7 @@ void Player::sendPing() { } int64_t noPongTime = timeNow - lastPong; + auto attackedCreature = getAttackedCreature(); if ((hasLostConnection || noPongTime >= 7000) && attackedCreature && attackedCreature->getPlayer()) { setAttackedCreature(nullptr); } @@ -1637,7 +1639,7 @@ void Player::onFollowCreatureDisappear(bool isLogout) { void Player::onChangeZone(ZoneType_t zone) { if (zone == ZONE_PROTECTION) { - if (attackedCreature && !hasFlag(PlayerFlags_t::IgnoreProtectionZone)) { + if (getAttackedCreature() && !hasFlag(PlayerFlags_t::IgnoreProtectionZone)) { setAttackedCreature(nullptr); onAttackedCreatureDisappear(false); } @@ -1665,6 +1667,10 @@ void Player::onChangeZone(ZoneType_t zone) { } void Player::onAttackedCreatureChangeZone(ZoneType_t zone) { + auto attackedCreature = getAttackedCreature(); + if (!attackedCreature) { + return; + } if (zone == ZONE_PROTECTION) { if (!hasFlag(PlayerFlags_t::IgnoreProtectionZone)) { setAttackedCreature(nullptr); @@ -1783,6 +1789,7 @@ void Player::onWalk(Direction &dir) { void Player::onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport) { Creature::onCreatureMove(creature, newTile, newPos, oldTile, oldPos, teleport); + auto followCreature = getFollowCreature(); if (hasFollowPath && (creature == followCreature || (creature.get() == this && followCreature))) { isUpdatingPath = false; g_dispatcher().addTask(std::bind(&Game::updateCreatureWalk, &g_game(), getID()), "Game::updateCreatureWalk"); @@ -4155,9 +4162,9 @@ bool Player::setAttackedCreature(std::shared_ptr creature) { return false; } + auto followCreature = getFollowCreature(); if (chaseMode && creature) { if (followCreature != creature) { - // chase opponent setFollowCreature(creature); } } else if (followCreature) { @@ -4178,7 +4185,7 @@ void Player::goToFollowCreature() { Creature::goToFollowCreature(); - if (followCreature && !hasFollowPath) { + if (getFollowCreature() && !hasFollowPath) { lastFailedFollow = OTSYS_TIME(); } } @@ -4198,6 +4205,11 @@ void Player::doAttacking(uint32_t) { return; } + auto attackedCreature = getAttackedCreature(); + if (!attackedCreature) { + return; + } + if ((OTSYS_TIME() - lastAttack) >= getAttackSpeed()) { bool result = false; @@ -4252,6 +4264,8 @@ void Player::onFollowCreature(std::shared_ptr creature) { void Player::setChaseMode(bool mode) { bool prevChaseMode = chaseMode; chaseMode = mode; + auto attackedCreature = getAttackedCreature(); + auto followCreature = getFollowCreature(); if (prevChaseMode != chaseMode) { if (chaseMode) { @@ -7653,7 +7667,7 @@ void Player::sendLootMessage(const std::string &message) const { } } -std::shared_ptr Player::getLootPouch() const { +std::shared_ptr Player::getLootPouch() { // Allow players with CM access or higher have the loot pouch anywhere auto parentItem = getParent() ? getParent()->getItem() : nullptr; if (isPlayerGroup() && parentItem && parentItem->getID() != ITEM_STORE_INBOX) { diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 3137d023824..6fd33ae8209 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -280,7 +280,7 @@ class Player final : public Creature, public Cylinder, public Bankable { return inbox; } - uint32_t getClientIcons() const; + uint32_t getClientIcons(); const GuildWarVector &getGuildWarVector() const { return guildWarVector; @@ -1309,7 +1309,7 @@ class Player final : public Creature, public Cylinder, public Bankable { } } void sendClosePrivate(uint16_t channelId); - void sendIcons() const { + void sendIcons() { if (client) { client->sendIcons(getClientIcons()); } @@ -2502,7 +2502,7 @@ class Player final : public Creature, public Cylinder, public Bankable { void sendLootMessage(const std::string &message) const; - std::shared_ptr getLootPouch() const; + std::shared_ptr getLootPouch(); private: static uint32_t playerFirstID; diff --git a/src/game/game.cpp b/src/game/game.cpp index 1122705df60..68e95389f99 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -937,7 +937,7 @@ bool Game::removeCreature(std::shared_ptr creature, bool isLogout /* = removeCreatureCheck(creature); - for (auto summon : creature->summons) { + for (auto summon : creature->m_summons) { summon->setSkillLoss(false); removeCreature(summon); } diff --git a/src/items/containers/container.cpp b/src/items/containers/container.cpp index df6878222c9..4a08c2a3ba9 100644 --- a/src/items/containers/container.cpp +++ b/src/items/containers/container.cpp @@ -102,8 +102,14 @@ std::shared_ptr Container::getRootContainer() { return getTopParentContainer(); } -bool Container::hasParent() const { - return getID() != ITEM_BROWSEFIELD && std::dynamic_pointer_cast(getParent()) == nullptr; +bool Container::hasParent() { + auto parent = getParent(); + if (!parent) { + return false; + } + auto creature = parent->getCreature(); + bool isPlayer = creature && creature->getPlayer() != nullptr; + return getID() != ITEM_BROWSEFIELD && !isPlayer; } void Container::addItem(std::shared_ptr item) { diff --git a/src/items/containers/container.hpp b/src/items/containers/container.hpp index e461e2598f4..81561120042 100644 --- a/src/items/containers/container.hpp +++ b/src/items/containers/container.hpp @@ -103,7 +103,7 @@ class Container : public Item, public Cylinder { } bool countsToLootAnalyzerBalance(); - bool hasParent() const; + bool hasParent(); void addItem(std::shared_ptr item); StashContainerList getStowableItems() const; bool isStoreInbox() const; diff --git a/src/items/containers/depot/depotchest.cpp b/src/items/containers/depot/depotchest.cpp index 77fef916e77..7471cdd0dbe 100644 --- a/src/items/containers/depot/depotchest.cpp +++ b/src/items/containers/depot/depotchest.cpp @@ -67,7 +67,7 @@ void DepotChest::postRemoveNotification(std::shared_ptr thing, std::share } } -std::shared_ptr DepotChest::getParent() const { +std::shared_ptr DepotChest::getParent() { auto parentLocked = parent.lock(); if (parentLocked && parentLocked->getParent()) { return parentLocked->getParent()->getParent(); diff --git a/src/items/containers/depot/depotchest.hpp b/src/items/containers/depot/depotchest.hpp index 22f11cd573e..75ea88154d2 100644 --- a/src/items/containers/depot/depotchest.hpp +++ b/src/items/containers/depot/depotchest.hpp @@ -34,12 +34,12 @@ class DepotChest final : public Container { bool canRemove() const override { return false; } - bool isRemoved() const override { + bool isRemoved() override { return false; } - std::shared_ptr getParent() const override; - std::shared_ptr getRealParent() const override { + std::shared_ptr getParent() override; + std::shared_ptr getRealParent() override { return parent.lock(); } diff --git a/src/items/containers/depot/depotlocker.hpp b/src/items/containers/depot/depotlocker.hpp index aac143ccf0a..b8f33c15c70 100644 --- a/src/items/containers/depot/depotlocker.hpp +++ b/src/items/containers/depot/depotlocker.hpp @@ -41,7 +41,7 @@ class DepotLocker final : public Container { bool canRemove() const override { return false; } - bool isRemoved() const override { + bool isRemoved() override { return false; } diff --git a/src/items/containers/inbox/inbox.cpp b/src/items/containers/inbox/inbox.cpp index 77e981b2de2..79d5ee1aa35 100644 --- a/src/items/containers/inbox/inbox.cpp +++ b/src/items/containers/inbox/inbox.cpp @@ -66,7 +66,7 @@ void Inbox::postRemoveNotification(std::shared_ptr thing, std::shared_ptr } } -std::shared_ptr Inbox::getParent() const { +std::shared_ptr Inbox::getParent() { auto parentLocked = parent.lock(); if (parentLocked) { return parentLocked->getParent(); diff --git a/src/items/containers/inbox/inbox.hpp b/src/items/containers/inbox/inbox.hpp index d6d74ae5f67..9687e02bf4c 100644 --- a/src/items/containers/inbox/inbox.hpp +++ b/src/items/containers/inbox/inbox.hpp @@ -33,12 +33,12 @@ class Inbox final : public Container { bool canRemove() const override { return false; } - bool isRemoved() const override { + bool isRemoved() override { return false; } - std::shared_ptr getParent() const override; - std::shared_ptr getRealParent() const override { + std::shared_ptr getParent() override; + std::shared_ptr getRealParent() override { return parent.lock(); } diff --git a/src/items/containers/rewards/reward.cpp b/src/items/containers/rewards/reward.cpp index 7f1c4313069..09f5a9c3aed 100644 --- a/src/items/containers/rewards/reward.cpp +++ b/src/items/containers/rewards/reward.cpp @@ -53,6 +53,6 @@ void Reward::postRemoveNotification(std::shared_ptr thing, std::shared_pt } } -std::shared_ptr Reward::getParent() const { +std::shared_ptr Reward::getParent() { return parent.lock(); } diff --git a/src/items/containers/rewards/reward.hpp b/src/items/containers/rewards/reward.hpp index 3065d3e0f5e..6a0071a4daa 100644 --- a/src/items/containers/rewards/reward.hpp +++ b/src/items/containers/rewards/reward.hpp @@ -30,8 +30,8 @@ class Reward : public Container { return true; } - std::shared_ptr getParent() const final; - std::shared_ptr getRealParent() const final { + std::shared_ptr getParent() final; + std::shared_ptr getRealParent() final { return parent.lock(); } }; diff --git a/src/items/cylinder.hpp b/src/items/cylinder.hpp index 424060b3b2e..bab34b5ce04 100644 --- a/src/items/cylinder.hpp +++ b/src/items/cylinder.hpp @@ -207,7 +207,7 @@ class VirtualCylinder final : public Cylinder { std::string getDescription(int32_t) override { return {}; } - bool isRemoved() const override { + bool isRemoved() override { return false; } }; diff --git a/src/items/item.cpp b/src/items/item.cpp index 35cef90f539..03dd550080a 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -344,7 +344,7 @@ uint16_t Item::getSubType() const { return static_cast(count); } -std::shared_ptr Item::getHoldingPlayer() const { +std::shared_ptr Item::getHoldingPlayer() { std::shared_ptr p = getParent(); while (p) { if (p->getCreature()) { @@ -3023,7 +3023,7 @@ void Item::addUniqueId(uint16_t uniqueId) { } } -bool Item::canDecay() const { +bool Item::canDecay() { if (isRemoved() || isDecayDisabled()) { return false; } @@ -3150,7 +3150,7 @@ bool Item::hasMarketAttributes() const { return true; } -bool Item::isInsideDepot(bool includeInbox /* = false*/) const { +bool Item::isInsideDepot(bool includeInbox /* = false*/) { if (std::shared_ptr thisContainer = getContainer(); thisContainer && (thisContainer->getDepotLocker() || thisContainer->isDepotChest() || (includeInbox && thisContainer->isInbox()))) { return true; } diff --git a/src/items/item.hpp b/src/items/item.hpp index e6cf69566e7..3bb839ccd32 100644 --- a/src/items/item.hpp +++ b/src/items/item.hpp @@ -301,7 +301,7 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { void setID(uint16_t newid); // Returns the player that is holding this item in his inventory - std::shared_ptr getHoldingPlayer() const; + std::shared_ptr getHoldingPlayer(); WeaponType_t getWeaponType() const { return items[id].weaponType; @@ -537,7 +537,7 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { return items[id].decayTime * 1000; } - bool canDecay() const; + bool canDecay(); virtual bool canRemove() const { return true; @@ -563,7 +563,7 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { bool hasMarketAttributes() const; - std::shared_ptr getParent() const override { + std::shared_ptr getParent() override { return parent.lock(); } void setParent(std::weak_ptr cylinder) override { @@ -574,11 +574,11 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { } std::shared_ptr getTopParent(); std::shared_ptr getTile() override; - bool isRemoved() const override { + bool isRemoved() override { return parent.expired() || getParent()->isRemoved(); } - bool isInsideDepot(bool includeInbox = false) const; + bool isInsideDepot(bool includeInbox = false); /** * @brief Get the Imbuement Info object diff --git a/src/items/thing.hpp b/src/items/thing.hpp index 8ee2643468e..0a6161783b3 100644 --- a/src/items/thing.hpp +++ b/src/items/thing.hpp @@ -28,10 +28,10 @@ class Thing { virtual std::string getDescription(int32_t lookDistance) = 0; - virtual std::shared_ptr getParent() const { + virtual std::shared_ptr getParent() { return nullptr; } - virtual std::shared_ptr getRealParent() const { + virtual std::shared_ptr getRealParent() { return getParent(); } @@ -66,7 +66,7 @@ class Thing { return nullptr; } - virtual bool isRemoved() const { + virtual bool isRemoved() { return true; } }; diff --git a/src/items/tile.hpp b/src/items/tile.hpp index c5943591067..7e9c4973c59 100644 --- a/src/items/tile.hpp +++ b/src/items/tile.hpp @@ -235,7 +235,7 @@ class Tile : public Cylinder, public SharedObject { return tilePos; } - bool isRemoved() const override final { + bool isRemoved() override final { return false; } From 7c4f78cd654eec209fe77acd04eea1a34345e02a Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sat, 16 Sep 2023 10:30:50 -0700 Subject: [PATCH 12/67] improve: turn summons into weak_ptr --- src/creatures/creature.cpp | 21 +++++++++++----- src/creatures/creature.hpp | 24 +++++++++++++++++-- src/creatures/monsters/monster.cpp | 11 ++++++--- src/creatures/players/grouping/party.cpp | 24 +++++++++++++++---- src/game/game.cpp | 6 ++++- .../creatures/creature_functions.cpp | 6 ++++- 6 files changed, 75 insertions(+), 17 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 490e58e51cc..6859dec7e1a 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -26,7 +26,11 @@ Creature::Creature() { } Creature::~Creature() { - for (std::shared_ptr summon : m_summons) { + for (auto summonPtr : m_summons) { + auto summon = summonPtr.lock(); + if (!summon) { + continue; + } summon->setAttackedCreature(nullptr); summon->removeMaster(); } @@ -428,7 +432,8 @@ void Creature::onAttackedCreatureChangeZone(ZoneType_t zone) { void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) { if (hasSummons()) { std::vector> despawnMonsterList; - for (std::shared_ptr creature : getSummons()) { + for (auto summonPtr : getSummons()) { + auto creature = summonPtr.lock(); if (!creature) { continue; } @@ -952,7 +957,11 @@ bool Creature::setAttackedCreature(std::shared_ptr creature) { m_attackedCreature.reset(); } - for (std::shared_ptr summon : m_summons) { + for (auto summonPtr : m_summons) { + auto summon = summonPtr.lock(); + if (!summon) { + continue; + } summon->setAttackedCreature(creature); } return true; @@ -1245,9 +1254,9 @@ bool Creature::setMaster(std::shared_ptr newMaster, bool reloadCreatur m_master = newMaster; if (oldMaster) { - auto summon = std::find(oldMaster->m_summons.begin(), oldMaster->m_summons.end(), getCreature()); - if (summon != oldMaster->m_summons.end()) { - oldMaster->m_summons.erase(summon); + auto summon = getSummon(getID()); + if (summon) { + oldMaster->removeSummon(summon); } } return true; diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index 0ce29cd7161..69399b216ed 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -331,10 +331,30 @@ class Creature : virtual public Thing, public SharedObject { return m_master.lock(); } - const std::list> &getSummons() const { + const std::list> &getSummons() const { return m_summons; } + std::shared_ptr getSummon(uint32_t creatureId) { + for (const auto &summon : m_summons) { + if (summon.expired()) { + continue; + } + + if (summon.lock()->getID() == creatureId) { + return summon.lock(); + } + } + + return nullptr; + } + + void removeSummon(std::shared_ptr summon) { + m_summons.remove_if([&summon](const std::weak_ptr &weakSummon) { + return weakSummon.expired() || weakSummon.lock() == summon; + }); + } + virtual int32_t getArmor() const { return 0; } @@ -655,7 +675,7 @@ class Creature : virtual public Thing, public SharedObject { CountMap damageMap; - std::list> m_summons; + std::list> m_summons; CreatureEventList eventsList; ConditionList conditions; diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 764eb1f037c..f46a96704da 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -1013,8 +1013,9 @@ void Monster::onThinkDefense(uint32_t interval) { } uint32_t summonCount = 0; - for (std::shared_ptr summon : m_summons) { - if (summon->getName() == summonBlock.name) { + for (auto summonPtr : m_summons) { + auto summon = summonPtr.lock(); + if (summon && summon->getName() == summonBlock.name) { ++summonCount; } } @@ -1852,7 +1853,11 @@ void Monster::death(std::shared_ptr) { } setAttackedCreature(nullptr); - for (std::shared_ptr summon : m_summons) { + for (auto summonPtr : m_summons) { + auto summon = summonPtr.lock(); + if (!summon) { + continue; + } summon->changeHealth(-summon->getHealth()); summon->removeMaster(); } diff --git a/src/creatures/players/grouping/party.cpp b/src/creatures/players/grouping/party.cpp index ad765f0545b..10cabc30e89 100644 --- a/src/creatures/players/grouping/party.cpp +++ b/src/creatures/players/grouping/party.cpp @@ -509,11 +509,19 @@ void Party::showPlayerStatus(std::shared_ptr player, std::shared_ptrsendPartyCreatureShowStatus(member, showStatus); member->sendPartyCreatureShowStatus(player, showStatus); if (showStatus) { - for (std::shared_ptr summon : member->getSummons()) { + for (auto summonPtr : member->getSummons()) { + auto summon = summonPtr.lock(); + if (!summon) { + continue; + } player->sendPartyCreatureShowStatus(summon, showStatus); player->sendPartyCreatureHealth(summon, std::ceil((static_cast(summon->getHealth()) / std::max(summon->getMaxHealth(), 1)) * 100)); } - for (std::shared_ptr summon : player->getSummons()) { + for (auto summonPtr : player->getSummons()) { + auto summon = summonPtr.lock(); + if (!summon) { + continue; + } member->sendPartyCreatureShowStatus(summon, showStatus); member->sendPartyCreatureHealth(summon, std::ceil((static_cast(summon->getHealth()) / std::max(summon->getMaxHealth(), 1)) * 100)); } @@ -522,10 +530,18 @@ void Party::showPlayerStatus(std::shared_ptr player, std::shared_ptrsendPartyPlayerMana(member, std::ceil((static_cast(member->getMana()) / std::max(member->getMaxMana(), 1)) * 100)); member->sendPartyPlayerMana(player, std::ceil((static_cast(player->getMana()) / std::max(player->getMaxMana(), 1)) * 100)); } else { - for (std::shared_ptr summon : player->getSummons()) { + for (auto summonPtr : player->getSummons()) { + auto summon = summonPtr.lock(); + if (!summon) { + continue; + } member->sendPartyCreatureShowStatus(summon, showStatus); } - for (std::shared_ptr summon : member->getSummons()) { + for (auto summonPtr : member->getSummons()) { + auto summon = summonPtr.lock(); + if (!summon) { + continue; + } player->sendPartyCreatureShowStatus(summon, showStatus); } } diff --git a/src/game/game.cpp b/src/game/game.cpp index 68e95389f99..1141ab8aec2 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -937,7 +937,11 @@ bool Game::removeCreature(std::shared_ptr creature, bool isLogout /* = removeCreatureCheck(creature); - for (auto summon : creature->m_summons) { + for (auto summonPtr : creature->m_summons) { + auto summon = summonPtr.lock(); + if (!summon) { + continue; + } summon->setSkillLoss(false); removeCreature(summon); } diff --git a/src/lua/functions/creatures/creature_functions.cpp b/src/lua/functions/creatures/creature_functions.cpp index aaa02677db7..52da97e5180 100644 --- a/src/lua/functions/creatures/creature_functions.cpp +++ b/src/lua/functions/creatures/creature_functions.cpp @@ -859,7 +859,11 @@ int CreatureFunctions::luaCreatureGetSummons(lua_State* L) { lua_createtable(L, creature->getSummonCount(), 0); int index = 0; - for (std::shared_ptr summon : creature->getSummons()) { + for (auto summonPtr : creature->getSummons()) { + auto summon = summonPtr.lock(); + if (!summon) { + continue; + } pushUserdata(L, summon); setCreatureMetatable(L, -1, summon); lua_rawseti(L, -2, ++index); From 088bc836cf93cd5c8e7483bf5349ec8adfacb892 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sat, 16 Sep 2023 14:45:17 -0700 Subject: [PATCH 13/67] improve: more weak_ptrs --- src/creatures/combat/spells.cpp | 17 +- src/creatures/combat/spells.hpp | 4 +- src/creatures/creature.cpp | 3 - src/creatures/creature.hpp | 4 +- src/creatures/monsters/monster.cpp | 8 +- src/creatures/npcs/npc.cpp | 8 +- src/creatures/npcs/npc.hpp | 3 +- src/creatures/players/grouping/guild.cpp | 14 +- src/creatures/players/grouping/guild.hpp | 13 +- src/creatures/players/grouping/party.cpp | 235 +++++++++++++++++------ src/creatures/players/grouping/party.hpp | 36 ++-- src/creatures/players/player.cpp | 8 +- src/creatures/players/player.hpp | 6 +- src/game/bank/bank.cpp | 31 ++- src/game/bank/bank.hpp | 5 +- src/game/game.cpp | 37 +--- src/game/game.hpp | 8 +- src/game/scheduling/task.hpp | 1 + src/game/zones/zone.cpp | 12 +- src/game/zones/zone.hpp | 3 +- src/items/decay/decay.cpp | 21 +- src/items/decay/decay.hpp | 2 +- src/items/item.cpp | 1 - src/items/tile.cpp | 11 -- src/lua/callbacks/creaturecallback.cpp | 4 + src/lua/callbacks/creaturecallback.hpp | 4 +- src/lua/global/shared_object.hpp | 119 ++++++++++++ src/lua/scripts/script_environment.cpp | 3 - src/map/house/house.cpp | 1 - 29 files changed, 436 insertions(+), 186 deletions(-) diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 018df87982b..f92bbdadcca 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -238,15 +238,15 @@ Position Spells::getCasterPosition(std::shared_ptr creature, Direction CombatSpell::CombatSpell(const std::shared_ptr newCombat, bool newNeedTarget, bool newNeedDirection) : Script(&g_spells().getScriptInterface()), - combat(newCombat), + m_combat(newCombat), needDirection(newNeedDirection), needTarget(newNeedTarget) { // Empty } bool CombatSpell::loadScriptCombat() { - combat = g_luaEnvironment().getCombatObject(g_luaEnvironment().lastCombatId); - return combat != nullptr; + m_combat = g_luaEnvironment().getCombatObject(g_luaEnvironment().lastCombatId); + return !m_combat.expired(); } bool CombatSpell::castSpell(std::shared_ptr creature) { @@ -270,6 +270,11 @@ bool CombatSpell::castSpell(std::shared_ptr creature) { pos = creature->getPosition(); } + auto combat = getCombat(); + if (!combat) { + return false; + } + if (soundCastEffect != SoundEffect_t::SILENCE) { combat->setParam(COMBAT_PARAM_CASTSOUND, static_cast(soundCastEffect)); } @@ -283,9 +288,13 @@ bool CombatSpell::castSpell(std::shared_ptr creature) { } bool CombatSpell::castSpell(std::shared_ptr creature, std::shared_ptr target) { + auto combat = getCombat(); + if (!combat) { + return false; + } + if (isLoadedCallback()) { LuaVariant var; - if (combat->hasArea()) { var.type = VARIANT_POSITION; diff --git a/src/creatures/combat/spells.hpp b/src/creatures/combat/spells.hpp index a158cddeb2d..1248c2a970d 100644 --- a/src/creatures/combat/spells.hpp +++ b/src/creatures/combat/spells.hpp @@ -104,7 +104,7 @@ class CombatSpell final : public Script, public BaseSpell, public std::enable_sh bool loadScriptCombat(); std::shared_ptr getCombat() { - return combat; + return m_combat.lock(); } private: @@ -112,7 +112,7 @@ class CombatSpell final : public Script, public BaseSpell, public std::enable_sh return "onCastSpell"; } - std::shared_ptr combat; + std::weak_ptr m_combat; bool needDirection; bool needTarget; diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 6859dec7e1a..b0d09a77d64 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -156,9 +156,6 @@ void Creature::onAttacking(uint32_t interval) { } onAttacked(); - if (!attackedCreature) { - return; - } attackedCreature->onAttacked(); if (g_game().isSightClear(getPosition(), attackedCreature->getPosition(), true)) { diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index 69399b216ed..f7ce33fb422 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -331,7 +331,7 @@ class Creature : virtual public Thing, public SharedObject { return m_master.lock(); } - const std::list> &getSummons() const { + const weak::list &getSummons() const { return m_summons; } @@ -675,7 +675,7 @@ class Creature : virtual public Thing, public SharedObject { CountMap damageMap; - std::list> m_summons; + weak::list m_summons; CreatureEventList eventsList; ConditionList conditions; diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index f46a96704da..eecd6757135 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -1277,7 +1277,7 @@ bool Monster::getDanceStep(const Position &creaturePos, Direction &moveDirection if (tmpDist == centerToDist && canWalkTo(creaturePos, DIRECTION_NORTH)) { bool result = true; - if (attackedCreature && keepAttack) { + if (keepAttack) { result = (!canDoAttackNow || canUseAttack(Position(creaturePos.x, creaturePos.y - 1, creaturePos.z), attackedCreature)); } @@ -1292,7 +1292,7 @@ bool Monster::getDanceStep(const Position &creaturePos, Direction &moveDirection if (tmpDist == centerToDist && canWalkTo(creaturePos, DIRECTION_SOUTH)) { bool result = true; - if (attackedCreature && keepAttack) { + if (keepAttack) { result = (!canDoAttackNow || canUseAttack(Position(creaturePos.x, creaturePos.y + 1, creaturePos.z), attackedCreature)); } @@ -1307,7 +1307,7 @@ bool Monster::getDanceStep(const Position &creaturePos, Direction &moveDirection if (tmpDist == centerToDist && canWalkTo(creaturePos, DIRECTION_EAST)) { bool result = true; - if (attackedCreature && keepAttack) { + if (keepAttack) { result = (!canDoAttackNow || canUseAttack(Position(creaturePos.x + 1, creaturePos.y, creaturePos.z), attackedCreature)); } @@ -1322,7 +1322,7 @@ bool Monster::getDanceStep(const Position &creaturePos, Direction &moveDirection if (tmpDist == centerToDist && canWalkTo(creaturePos, DIRECTION_WEST)) { bool result = true; - if (attackedCreature && keepAttack) { + if (keepAttack) { result = (!canDoAttackNow || canUseAttack(Position(creaturePos.x - 1, creaturePos.y, creaturePos.z), attackedCreature)); } diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index f15b0578ec4..5bbe777a3bd 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -648,13 +648,15 @@ void Npc::addShopPlayer(std::shared_ptr player) { } void Npc::removeShopPlayer(std::shared_ptr player) { - if (player) { - shopPlayerSet.erase(player); + if (!player) { + return; } + weak::erase(shopPlayerSet, player); } void Npc::closeAllShopWindows() { - for (auto shopPlayer : shopPlayerSet) { + for (auto shopPlayerPtr : shopPlayerSet) { + auto shopPlayer = shopPlayerPtr.lock(); if (shopPlayer) { shopPlayer->closeShopWindow(); } diff --git a/src/creatures/npcs/npc.hpp b/src/creatures/npcs/npc.hpp index 73a847730d4..b354e40245c 100644 --- a/src/creatures/npcs/npc.hpp +++ b/src/creatures/npcs/npc.hpp @@ -10,6 +10,7 @@ #pragma once #include "creatures/npcs/npcs.hpp" +#include "creatures/players/player.hpp" #include "declarations.hpp" #include "items/tile.hpp" #include "lib/di/container.hpp" @@ -174,7 +175,7 @@ class Npc final : public Creature { std::map playerInteractions; - std::set> shopPlayerSet; + weak::parallel_flat_hash_set shopPlayerSet; NpcType* npcType; SpawnNpc* spawnNpc = nullptr; diff --git a/src/creatures/players/grouping/guild.cpp b/src/creatures/players/grouping/guild.cpp index c7af6c2a613..835b54bd3a2 100644 --- a/src/creatures/players/grouping/guild.cpp +++ b/src/creatures/players/grouping/guild.cpp @@ -14,15 +14,21 @@ void Guild::addMember(std::shared_ptr player) { membersOnline.push_back(player); - for (std::shared_ptr member : membersOnline) { + for (auto member : getMembersOnline()) { g_game().updatePlayerHelpers(member); } } void Guild::removeMember(std::shared_ptr player) { - membersOnline.remove(player); - for (std::shared_ptr member : membersOnline) { - g_game().updatePlayerHelpers(member); + // loop over to udpate all members and delete the player from the list + for (auto it = membersOnline.begin(); it != membersOnline.end(); ++it) { + if (auto member = it->lock()) { + if (member == player) { + it = membersOnline.erase(it); + } else { + g_game().updatePlayerHelpers(member); + } + } } g_game().updatePlayerHelpers(player); diff --git a/src/creatures/players/grouping/guild.hpp b/src/creatures/players/grouping/guild.hpp index 497ff49f52b..894d63318cf 100644 --- a/src/creatures/players/grouping/guild.hpp +++ b/src/creatures/players/grouping/guild.hpp @@ -48,8 +48,15 @@ class Guild : public Bankable { const std::string &getName() const { return name; } - const std::list> &getMembersOnline() const { - return membersOnline; + std::vector> getMembersOnline() const { + auto result = std::vector>(membersOnline.size()); + std::transform(membersOnline.begin(), membersOnline.end(), result.begin(), [](const std::weak_ptr &weak) { + return weak.lock(); + }); + return result; + } + uint32_t getMemberCountOnline() const { + return membersOnline.size(); } uint32_t getMemberCount() const { return memberCount; @@ -81,7 +88,7 @@ class Guild : public Bankable { } private: - std::list> membersOnline; + weak::list membersOnline; std::vector ranks; std::string name; uint64_t bankBalance = 0; diff --git a/src/creatures/players/grouping/party.cpp b/src/creatures/players/grouping/party.cpp index 10cabc30e89..b2d8fae9f76 100644 --- a/src/creatures/players/grouping/party.cpp +++ b/src/creatures/players/grouping/party.cpp @@ -16,8 +16,8 @@ #include "lua/callbacks/events_callbacks.hpp" Party::Party(std::shared_ptr initLeader) : - leader(initLeader) { - leader->setParty(this); + m_leader(initLeader) { + initLeader->setParty(this); if (g_configManager().getBoolean(PARTY_AUTO_SHARE_EXPERIENCE)) { setSharedExperience(initLeader, true); } @@ -32,8 +32,11 @@ void Party::disband() { return; } - std::shared_ptr currentLeader = leader; - leader = nullptr; + auto currentLeader = getLeader(); + if (!currentLeader) { + return; + } + m_leader.reset(); currentLeader->setParty(nullptr); currentLeader->sendClosePrivate(CHANNEL_PARTY); @@ -42,22 +45,23 @@ void Party::disband() { currentLeader->sendCreatureSkull(currentLeader); currentLeader->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, "Your party has been disbanded."); - for (std::shared_ptr invitee : inviteList) { + for (auto invitee : getInvitees()) { invitee->removePartyInvitation(this); currentLeader->sendCreatureShield(invitee); } inviteList.clear(); - for (std::shared_ptr member : memberList) { + auto members = getMembers(); + for (auto member : members) { member->setParty(nullptr); member->sendClosePrivate(CHANNEL_PARTY); member->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, "Your party has been disbanded."); } - for (std::shared_ptr member : memberList) { + for (auto member : members) { g_game().updatePlayerShield(member); - for (std::shared_ptr otherMember : memberList) { + for (auto otherMember : members) { otherMember->sendCreatureSkull(member); } @@ -77,6 +81,11 @@ bool Party::leaveParty(std::shared_ptr player) { return false; } + auto leader = getLeader(); + if (!leader) { + return false; + } + if (player->getParty() != this && leader != player) { return false; } @@ -95,7 +104,18 @@ bool Party::leaveParty(std::shared_ptr player) { if (memberList.size() == 1 && inviteList.empty()) { missingLeader = true; } else { - passPartyLeadership(memberList.front()); + auto newLeader = memberList.front().lock(); + while (!newLeader) { + memberList.erase(memberList.begin()); + if (memberList.empty()) { + missingLeader = true; + break; + } + newLeader = memberList.front().lock(); + } + if (newLeader) { + passPartyLeadership(newLeader); + } } } else { missingLeader = true; @@ -103,17 +123,14 @@ bool Party::leaveParty(std::shared_ptr player) { } // since we already passed the leadership, we remove the player from the list - auto it = std::find(memberList.begin(), memberList.end(), player); - if (it != memberList.end()) { - memberList.erase(it); - } + weak::erase(memberList, player); player->setParty(nullptr); player->sendClosePrivate(CHANNEL_PARTY); g_game().updatePlayerShield(player); g_game().updatePlayerHelpers(player); - for (std::shared_ptr member : memberList) { + for (auto member : getMembers()) { member->sendCreatureSkull(player); player->sendPlayerPartyIcons(member); member->sendPartyCreatureUpdate(player); @@ -143,34 +160,32 @@ bool Party::leaveParty(std::shared_ptr player) { } bool Party::passPartyLeadership(std::shared_ptr player) { - if (!player || leader == player || player->getParty() != this) { + auto leader = getLeader(); + if (!leader || !player || leader == player || player->getParty() != this) { return false; } // Remove it before to broadcast the message correctly - auto it = std::find(memberList.begin(), memberList.end(), player); - if (it != memberList.end()) { - memberList.erase(it); - } + weak::erase(memberList, player); std::ostringstream ss; ss << player->getName() << " is now the leader of the party."; broadcastPartyMessage(MESSAGE_PARTY_MANAGEMENT, ss.str(), true); - std::shared_ptr oldLeader = leader; - leader = player; + auto oldLeader = leader; + m_leader = player; memberList.insert(memberList.begin(), oldLeader); updateSharedExperience(); updateTrackerAnalyzer(); - for (std::shared_ptr member : memberList) { + for (auto member : getMembers()) { member->sendPartyCreatureShield(oldLeader); member->sendPartyCreatureShield(leader); } - for (std::shared_ptr invitee : inviteList) { + for (auto invitee : getInvitees()) { invitee->sendCreatureShield(oldLeader); invitee->sendCreatureShield(leader); } @@ -183,6 +198,11 @@ bool Party::passPartyLeadership(std::shared_ptr player) { } bool Party::joinParty(const std::shared_ptr &player) { + auto leader = getLeader(); + if (!leader) { + return false; + } + if (!g_events().eventPartyOnJoin(this, player)) { return false; } @@ -191,7 +211,7 @@ bool Party::joinParty(const std::shared_ptr &player) { return false; } - auto it = std::find(inviteList.begin(), inviteList.end(), player); + auto it = weak::find(inviteList, player); if (it == inviteList.end()) { return false; } @@ -206,7 +226,7 @@ bool Party::joinParty(const std::shared_ptr &player) { g_game().updatePlayerShield(player); - for (std::shared_ptr member : memberList) { + for (auto member : getMembers()) { member->sendCreatureSkull(player); player->sendPlayerPartyIcons(member); } @@ -233,7 +253,12 @@ bool Party::joinParty(const std::shared_ptr &player) { } bool Party::removeInvite(const std::shared_ptr &player, bool removeFromPlayer /* = true*/) { - auto it = std::find(inviteList.begin(), inviteList.end(), player); + auto leader = getLeader(); + if (!leader) { + return false; + } + + auto it = weak::find(inviteList, player); if (it == inviteList.end()) { return false; } @@ -250,7 +275,7 @@ bool Party::removeInvite(const std::shared_ptr &player, bool removeFromP if (empty()) { disband(); } else { - for (auto member : memberList) { + for (auto member : getMembers()) { g_game().updatePlayerHelpers(member); } @@ -261,6 +286,11 @@ bool Party::removeInvite(const std::shared_ptr &player, bool removeFromP } void Party::revokeInvitation(const std::shared_ptr &player) { + auto leader = getLeader(); + if (!leader) { + return; + } + std::ostringstream ss; ss << leader->getName() << " has revoked " << leader->getPossessivePronoun() << " invitation."; player->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); @@ -273,6 +303,11 @@ void Party::revokeInvitation(const std::shared_ptr &player) { } bool Party::invitePlayer(const std::shared_ptr &player) { + auto leader = getLeader(); + if (!leader) { + return false; + } + if (isPlayerInvited(player)) { return false; } @@ -290,7 +325,7 @@ bool Party::invitePlayer(const std::shared_ptr &player) { inviteList.push_back(player); - for (auto member : memberList) { + for (auto member : getMembers()) { g_game().updatePlayerHelpers(member); } @@ -307,13 +342,18 @@ bool Party::invitePlayer(const std::shared_ptr &player) { return true; } -bool Party::isPlayerInvited(std::shared_ptr player) const { - return std::find(inviteList.begin(), inviteList.end(), player) != inviteList.end(); +bool Party::isPlayerInvited(const std::shared_ptr &player) const { + return weak::find(inviteList, player) != inviteList.end(); } void Party::updateAllPartyIcons() { - for (std::shared_ptr member : memberList) { - for (std::shared_ptr otherMember : memberList) { + auto leader = getLeader(); + if (!leader) { + return; + } + auto members = getMembers(); + for (auto member : members) { + for (auto otherMember : members) { member->sendPartyCreatureShield(otherMember); } @@ -325,14 +365,18 @@ void Party::updateAllPartyIcons() { } void Party::broadcastPartyMessage(MessageClasses msgClass, const std::string &msg, bool sendToInvitations /*= false*/) { - for (std::shared_ptr member : memberList) { + auto leader = getLeader(); + if (!leader) { + return; + } + for (auto member : getMembers()) { member->sendTextMessage(msgClass, msg); } leader->sendTextMessage(msgClass, msg); if (sendToInvitations) { - for (std::shared_ptr invitee : inviteList) { + for (auto invitee : getInvitees()) { invitee->sendTextMessage(msgClass, msg); } } @@ -366,6 +410,7 @@ const char* Party::getSharedExpReturnMessage(SharedExpStatus_t value) { } bool Party::setSharedExperience(std::shared_ptr player, bool newSharedExpActive, bool silent /*= false*/) { + auto leader = getLeader(); if (!player || leader != player) { return false; } @@ -393,21 +438,30 @@ bool Party::setSharedExperience(std::shared_ptr player, bool newSharedEx } void Party::shareExperience(uint64_t experience, std::shared_ptr target /* = nullptr*/) { + auto leader = getLeader(); + if (!leader) { + return; + } + uint64_t shareExperience = experience; g_events().eventPartyOnShareExperience(this, shareExperience); g_callbacks().executeCallback(EventCallback_t::partyOnShareExperience, &EventCallback::partyOnShareExperience, this, shareExperience); - for (std::shared_ptr member : memberList) { + for (auto member : getMembers()) { member->onGainSharedExperience(shareExperience, target); } leader->onGainSharedExperience(shareExperience, target); } -bool Party::canUseSharedExperience(std::shared_ptr player) const { +bool Party::canUseSharedExperience(std::shared_ptr player) { return getMemberSharedExperienceStatus(player) == SHAREDEXP_OK; } -SharedExpStatus_t Party::getMemberSharedExperienceStatus(std::shared_ptr player) const { +SharedExpStatus_t Party::getMemberSharedExperienceStatus(std::shared_ptr player) { + auto leader = getLeader(); + if (!leader) { + return SHAREDEXP_EMPTYPARTY; + } if (memberList.empty()) { return SHAREDEXP_EMPTYPARTY; } @@ -430,9 +484,14 @@ SharedExpStatus_t Party::getMemberSharedExperienceStatus(std::shared_ptr return SHAREDEXP_OK; } -uint32_t Party::getHighestLevel() const { +uint32_t Party::getHighestLevel() { + auto leader = getLeader(); + if (!leader) { + return 0; + } + uint32_t highestLevel = leader->getLevel(); - for (std::shared_ptr member : memberList) { + for (auto member : getMembers()) { if (member->getLevel() > highestLevel) { highestLevel = member->getLevel(); } @@ -440,13 +499,17 @@ uint32_t Party::getHighestLevel() const { return highestLevel; } -uint32_t Party::getMinLevel() const { +uint32_t Party::getMinLevel() { return static_cast(std::ceil((static_cast(getHighestLevel()) * 2) / 3)); } -uint32_t Party::getLowestLevel() const { +uint32_t Party::getLowestLevel() { + auto leader = getLeader(); + if (!leader) { + return 0; + } uint32_t lowestLevel = leader->getLevel(); - for (std::shared_ptr member : memberList) { + for (auto member : getMembers()) { if (member->getLevel() < lowestLevel) { lowestLevel = member->getLevel(); } @@ -454,11 +517,11 @@ uint32_t Party::getLowestLevel() const { return lowestLevel; } -uint32_t Party::getMaxLevel() const { +uint32_t Party::getMaxLevel() { return static_cast(std::floor((static_cast(getLowestLevel()) * 3) / 2)); } -bool Party::isPlayerActive(std::shared_ptr player) const { +bool Party::isPlayerActive(std::shared_ptr player) { auto it = ticksMap.find(player->getID()); if (it == ticksMap.end()) { return false; @@ -469,12 +532,16 @@ bool Party::isPlayerActive(std::shared_ptr player) const { } SharedExpStatus_t Party::getSharedExperienceStatus() { + auto leader = getLeader(); + if (!leader) { + return SHAREDEXP_EMPTYPARTY; + } SharedExpStatus_t leaderStatus = getMemberSharedExperienceStatus(leader); if (leaderStatus != SHAREDEXP_OK) { return leaderStatus; } - for (std::shared_ptr member : memberList) { + for (auto member : getMembers()) { SharedExpStatus_t memberStatus = getMemberSharedExperienceStatus(member); if (memberStatus != SHAREDEXP_OK) { return memberStatus; @@ -499,6 +566,11 @@ void Party::clearPlayerPoints(std::shared_ptr player) { } bool Party::canOpenCorpse(uint32_t ownerId) const { + auto leader = getLeader(); + if (!leader) { + return false; + } + if (std::shared_ptr player = g_game().getPlayerByID(ownerId)) { return leader->getID() == ownerId || player->getParty() == this; } @@ -548,8 +620,13 @@ void Party::showPlayerStatus(std::shared_ptr player, std::shared_ptr player) { + auto leader = getLeader(); + if (!leader) { + return; + } + int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE); - for (std::shared_ptr member : memberList) { + for (auto member : getMembers()) { bool condition = (maxDistance == 0 || (Position::getDistanceX(player->getPosition(), member->getPosition()) <= maxDistance && Position::getDistanceY(player->getPosition(), member->getPosition()) <= maxDistance)); if (condition) { showPlayerStatus(player, member, true); @@ -566,9 +643,14 @@ void Party::updatePlayerStatus(std::shared_ptr player) { } void Party::updatePlayerStatus(std::shared_ptr player, const Position &oldPos, const Position &newPos) { + auto leader = getLeader(); + if (!leader) { + return; + } + int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE); if (maxDistance != 0) { - for (std::shared_ptr member : memberList) { + for (auto member : getMembers()) { bool condition1 = (Position::getDistanceX(oldPos, member->getPosition()) <= maxDistance && Position::getDistanceY(oldPos, member->getPosition()) <= maxDistance); bool condition2 = (Position::getDistanceX(newPos, member->getPosition()) <= maxDistance && Position::getDistanceY(newPos, member->getPosition()) <= maxDistance); if (condition1 && !condition2) { @@ -589,22 +671,35 @@ void Party::updatePlayerStatus(std::shared_ptr player, const Position &o } void Party::updatePlayerHealth(std::shared_ptr player, std::shared_ptr target, uint8_t healthPercent) { + auto leader = getLeader(); + if (!leader) { + return; + } + int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE); - for (std::shared_ptr member : memberList) { - bool condition = (maxDistance == 0 || (Position::getDistanceX(player->getPosition(), member->getPosition()) <= maxDistance && Position::getDistanceY(player->getPosition(), member->getPosition()) <= maxDistance)); + auto playerPosition = player->getPosition(); + auto leaderPosition = leader->getPosition(); + for (auto member : getMembers()) { + auto memberPosition = member->getPosition(); + bool condition = (maxDistance == 0 || (Position::getDistanceX(playerPosition, memberPosition) <= maxDistance && Position::getDistanceY(playerPosition, memberPosition) <= maxDistance)); if (condition) { member->sendPartyCreatureHealth(target, healthPercent); } } - bool condition = (maxDistance == 0 || (Position::getDistanceX(player->getPosition(), leader->getPosition()) <= maxDistance && Position::getDistanceY(player->getPosition(), leader->getPosition()) <= maxDistance)); + bool condition = (maxDistance == 0 || (Position::getDistanceX(playerPosition, leaderPosition) <= maxDistance && Position::getDistanceY(playerPosition, leaderPosition) <= maxDistance)); if (condition) { leader->sendPartyCreatureHealth(target, healthPercent); } } void Party::updatePlayerMana(std::shared_ptr player, uint8_t manaPercent) { + auto leader = getLeader(); + if (!leader) { + return; + } + int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE); - for (std::shared_ptr member : memberList) { + for (auto member : getMembers()) { bool condition = (maxDistance == 0 || (Position::getDistanceX(player->getPosition(), member->getPosition()) <= maxDistance && Position::getDistanceY(player->getPosition(), member->getPosition()) <= maxDistance)); if (condition) { member->sendPartyPlayerMana(player, manaPercent); @@ -617,8 +712,13 @@ void Party::updatePlayerMana(std::shared_ptr player, uint8_t manaPercent } void Party::updatePlayerVocation(std::shared_ptr player) { + auto leader = getLeader(); + if (!leader) { + return; + } + int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE); - for (std::shared_ptr member : memberList) { + for (auto member : getMembers()) { bool condition = (maxDistance == 0 || (Position::getDistanceX(player->getPosition(), member->getPosition()) <= maxDistance && Position::getDistanceY(player->getPosition(), member->getPosition()) <= maxDistance)); if (condition) { member->sendPartyPlayerVocation(player); @@ -630,17 +730,25 @@ void Party::updatePlayerVocation(std::shared_ptr player) { } } -void Party::updateTrackerAnalyzer() const { - for (std::shared_ptr member : memberList) { - member->updatePartyTrackerAnalyzer(); +void Party::updateTrackerAnalyzer() { + auto leader = getLeader(); + if (!leader) { + return; } - if (leader) { - leader->updatePartyTrackerAnalyzer(); + for (auto member : getMembers()) { + member->updatePartyTrackerAnalyzer(); } + + leader->updatePartyTrackerAnalyzer(); } void Party::addPlayerLoot(std::shared_ptr player, std::shared_ptr item) { + auto leader = getLeader(); + if (!leader) { + return; + } + PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); @@ -664,6 +772,11 @@ void Party::addPlayerLoot(std::shared_ptr player, std::shared_ptr } void Party::addPlayerSupply(std::shared_ptr player, std::shared_ptr item) { + auto leader = getLeader(); + if (!leader) { + return; + } + PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); @@ -708,7 +821,8 @@ void Party::addPlayerHealing(std::shared_ptr player, uint64_t amount) { } void Party::switchAnalyzerPriceType() { - if (leader == nullptr) { + auto leader = getLeader(); + if (!leader) { return; } @@ -727,6 +841,11 @@ void Party::resetAnalyzer() { } void Party::reloadPrices() { + auto leader = getLeader(); + if (!leader) { + return; + } + for (PartyAnalyzer* analyzer : membersData) { if (priceType == MARKET_PRICE) { analyzer->lootPrice = g_game().getItemMarketPrice(analyzer->lootMap, false); diff --git a/src/creatures/players/grouping/party.hpp b/src/creatures/players/grouping/party.hpp index aaebabb4d9c..f856b486966 100644 --- a/src/creatures/players/grouping/party.hpp +++ b/src/creatures/players/grouping/party.hpp @@ -24,20 +24,18 @@ enum SharedExpStatus_t : uint8_t { class Player; class Party; -using PlayerVector = std::vector>; - class Party { public: explicit Party(std::shared_ptr leader); std::shared_ptr getLeader() const { - return leader; + return m_leader.lock(); } - PlayerVector &getMembers() { - return memberList; + std::vector> getMembers() { + return weak::lock(memberList); } - const PlayerVector &getInvitees() const { - return inviteList; + std::vector> getInvitees() { + return weak::lock(inviteList); } size_t getMemberCount() const { return memberList.size(); @@ -55,7 +53,7 @@ class Party { bool removeInvite(const std::shared_ptr &player, bool removeFromPlayer = true); - bool isPlayerInvited(std::shared_ptr player) const; + bool isPlayerInvited(const std::shared_ptr &player) const; void updateAllPartyIcons(); void broadcastPartyMessage(MessageClasses msgClass, const std::string &msg, bool sendToInvitations = false); bool empty() const { @@ -71,8 +69,8 @@ class Party { bool isSharedExperienceEnabled() const { return sharedExpEnabled; } - bool canUseSharedExperience(std::shared_ptr player) const; - SharedExpStatus_t getMemberSharedExperienceStatus(std::shared_ptr player) const; + bool canUseSharedExperience(std::shared_ptr player); + SharedExpStatus_t getMemberSharedExperienceStatus(std::shared_ptr player); void updateSharedExperience(); void updatePlayerTicks(std::shared_ptr player, uint32_t points); @@ -85,7 +83,7 @@ class Party { void updatePlayerMana(std::shared_ptr player, uint8_t manaPercent); void updatePlayerVocation(std::shared_ptr player); - void updateTrackerAnalyzer() const; + void updateTrackerAnalyzer(); void addPlayerLoot(std::shared_ptr player, std::shared_ptr item); void addPlayerSupply(std::shared_ptr player, std::shared_ptr item); void addPlayerDamage(std::shared_ptr player, uint64_t amount); @@ -117,19 +115,19 @@ class Party { private: const char* getSharedExpReturnMessage(SharedExpStatus_t value); - bool isPlayerActive(std::shared_ptr player) const; + bool isPlayerActive(std::shared_ptr player); SharedExpStatus_t getSharedExperienceStatus(); - uint32_t getHighestLevel() const; - uint32_t getLowestLevel() const; - uint32_t getMinLevel() const; - uint32_t getMaxLevel() const; + uint32_t getHighestLevel(); + uint32_t getLowestLevel(); + uint32_t getMinLevel(); + uint32_t getMaxLevel(); std::map ticksMap; - PlayerVector memberList; - PlayerVector inviteList; + weak::vector memberList; + weak::vector inviteList; - std::shared_ptr leader; + std::weak_ptr m_leader; bool sharedExpActive = false; bool sharedExpEnabled = false; diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index f71a097af5f..bee6fdccd24 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -1441,6 +1441,12 @@ void Player::openImbuementWindow(std::shared_ptr item) { client->openImbuementWindow(item); } +void Player::sendSaleItemList(const std::map &inventoryMap) const { + if (client && shopOwner) { + client->sendSaleItemList(shopOwner->getShopItemVector(), inventoryMap); + } +} + void Player::sendMarketEnter(uint32_t depotId) { if (!client || this->getLastDepotId() == -1 || !depotId) { return; @@ -5912,7 +5918,7 @@ uint16_t Player::getHelpers() const { helpers = helperSet.size(); } else if (guild) { - helpers = guild->getMembersOnline().size(); + helpers = guild->getMemberCountOnline(); } else if (party) { helpers = party->getMemberCount() + party->getInvitationCount() + 1; } else { diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 6fd33ae8209..7ff7e02a505 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -1386,11 +1386,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendShop(npc); } } - void sendSaleItemList(const std::map &inventoryMap) const { - if (client && shopOwner) { - client->sendSaleItemList(shopOwner->getShopItemVector(), inventoryMap); - } - } + void sendSaleItemList(const std::map &inventoryMap) const; void sendCloseShop() const { if (client) { client->sendCloseShop(); diff --git a/src/game/bank/bank.cpp b/src/game/bank/bank.cpp index 56be07141e5..56e06150bdb 100644 --- a/src/game/bank/bank.cpp +++ b/src/game/bank/bank.cpp @@ -15,10 +15,11 @@ #include "io/iologindata.hpp" Bank::Bank(const std::shared_ptr bankable) : - bankable(bankable) { + m_bankable(bankable) { } Bank::~Bank() { + auto bankable = getBankable(); if (bankable == nullptr || bankable->isOnline()) { return; } @@ -48,7 +49,8 @@ bool Bank::debit(uint64_t amount) { } bool Bank::balance(uint64_t amount) const { - if (bankable == nullptr) { + auto bankable = getBankable(); + if (!bankable) { return 0; } bankable->setBankBalance(amount); @@ -56,7 +58,8 @@ bool Bank::balance(uint64_t amount) const { } uint64_t Bank::balance() { - if (bankable == nullptr) { + auto bankable = getBankable(); + if (!bankable) { return 0; } return bankable->getBankBalance(); @@ -78,10 +81,18 @@ const std::set deniedNames = { const uint32_t minTownId = 3; bool Bank::transferTo(const std::shared_ptr destination, uint64_t amount) { - if (destination == nullptr) { + if (!destination) { return false; } - if (destination->bankable->getPlayer() != nullptr) { + auto bankable = getBankable(); + if (!bankable) { + return false; + } + auto destinationBankable = destination->getBankable(); + if (!destinationBankable) { + return false; + } + if (destinationBankable->getPlayer() != nullptr) { auto player = bankable->getPlayer(); auto name = asLowerCaseString(player->getName()); replaceString(name, " ", ""); @@ -109,6 +120,10 @@ bool Bank::withdraw(std::shared_ptr player, uint64_t amount) { } bool Bank::deposit(const std::shared_ptr destination) { + auto bankable = getBankable(); + if (!bankable) { + return false; + } if (bankable->getPlayer() == nullptr) { return false; } @@ -117,7 +132,11 @@ bool Bank::deposit(const std::shared_ptr destination) { } bool Bank::deposit(const std::shared_ptr destination, uint64_t amount) { - if (destination == nullptr) { + if (!destination) { + return false; + } + auto bankable = getBankable(); + if (!bankable) { return false; } if (!g_game().removeMoney(bankable->getPlayer(), amount)) { diff --git a/src/game/bank/bank.hpp b/src/game/bank/bank.hpp index c6db5aaae35..b04a02a9998 100644 --- a/src/game/bank/bank.hpp +++ b/src/game/bank/bank.hpp @@ -48,5 +48,8 @@ class Bank : public SharedObject { bool deposit(const std::shared_ptr destination, uint64_t amount); private: - std::shared_ptr bankable; + std::shared_ptr getBankable() const { + return m_bankable.lock(); + } + std::weak_ptr m_bankable; }; diff --git a/src/game/game.cpp b/src/game/game.cpp index 1141ab8aec2..c2b14b7e4b4 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -742,7 +742,7 @@ std::shared_ptr Game::getCreatureByName(const std::string &s) { auto m_it = mappedPlayerNames.find(lowerCaseName); if (m_it != mappedPlayerNames.end()) { - return m_it->second; + return m_it->second.lock(); } for (const auto &it : npcs) { @@ -791,7 +791,7 @@ std::shared_ptr Game::getPlayerByName(const std::string &s, bool loadTmp tmpPlayer->setOnline(false); return tmpPlayer; } - return it->second; + return it->second.lock(); } std::shared_ptr Game::getPlayerByGUID(const uint32_t &guid) { @@ -933,7 +933,6 @@ bool Game::removeCreature(std::shared_ptr creature, bool isLogout /* = creature->removeList(); creature->setRemoved(); - ReleaseCreature(creature); removeCreatureCheck(creature); @@ -1801,7 +1800,6 @@ ReturnValue Game::internalMoveItem(std::shared_ptr fromCylinder, std:: if (item->isRemoved()) { item->stopDecaying(); - ReleaseItem(item); } } @@ -1956,7 +1954,6 @@ ReturnValue Game::internalAddItem(std::shared_ptr toCylinder, std::sha std::shared_ptr remainderItem = item->clone(); remainderItem->setItemCount(count); if (internalAddItem(destCylinder, remainderItem, INDEX_WHEREEVER, flags, false) != RETURNVALUE_NOERROR) { - ReleaseItem(remainderItem); remainderCount = count; } } else { @@ -1970,7 +1967,6 @@ ReturnValue Game::internalAddItem(std::shared_ptr toCylinder, std::sha } else { // fully merged with toItem, item will be destroyed item->onRemoved(); - ReleaseItem(item); int32_t itemIndex = toCylinder->getThingIndex(toItem); if (itemIndex != -1) { @@ -2039,7 +2035,6 @@ ReturnValue Game::internalRemoveItem(std::shared_ptr item, int32_t count / if (item->isRemoved()) { item->onRemoved(); item->stopDecaying(); - ReleaseItem(item); } cylinder->postRemoveNotification(item, nullptr, index); @@ -2062,7 +2057,6 @@ ReturnValue Game::internalPlayerAddItem(std::shared_ptr player, std::sha std::shared_ptr remainderItem = Item::CreateItem(item->getID(), remainderCount); ReturnValue remaindRet = internalAddItem(player->getTile(), remainderItem, INDEX_WHEREEVER, FLAG_NOLIMIT); if (remaindRet != RETURNVALUE_NOERROR) { - ReleaseItem(remainderItem); player->sendLootStats(item, static_cast(item->getItemCount())); } } @@ -2298,7 +2292,6 @@ std::shared_ptr Game::transformItem(std::shared_ptr item, uint16_t n std::shared_ptr newParent = item->getParent(); if (newParent == nullptr) { item->stopDecaying(); - ReleaseItem(item); return nullptr; } @@ -4369,13 +4362,11 @@ void Game::playerAcceptTrade(uint32_t playerId) { auto it = tradeItems.find(tradeItem1); if (it != tradeItems.end()) { - ReleaseItem(it->first); tradeItems.erase(it); } it = tradeItems.find(tradeItem2); if (it != tradeItems.end()) { - ReleaseItem(it->first); tradeItems.erase(it); } @@ -4541,7 +4532,6 @@ void Game::internalCloseTrade(std::shared_ptr player) { if (player->getTradeItem()) { auto it = tradeItems.find(player->getTradeItem()); if (it != tradeItems.end()) { - ReleaseItem(it->first); tradeItems.erase(it); } @@ -4559,7 +4549,6 @@ void Game::internalCloseTrade(std::shared_ptr player) { if (tradePartner->getTradeItem()) { auto it = tradeItems.find(tradePartner->getTradeItem()); if (it != tradeItems.end()) { - ReleaseItem(it->first); tradeItems.erase(it); } @@ -5726,7 +5715,6 @@ void Game::checkCreatures(size_t index) { ++it; } else { creature->inCheckCreaturesVector = false; - ReleaseCreature(creature); checkCreatureList[it] = checkCreatureList.back(); checkCreatureList.pop_back(); @@ -7403,9 +7391,6 @@ void Game::shutdown() { } void Game::cleanup() { - ToReleaseCreatures.clear(); - ToReleaseItems.clear(); - for (auto it = browseFields.begin(); it != browseFields.end();) { if (it->second.expired()) { it = browseFields.erase(it); @@ -7415,18 +7400,6 @@ void Game::cleanup() { } } -void Game::ReleaseCreature(std::shared_ptr creature) { - ToReleaseCreatures.push_back(creature); -} - -void Game::ReleaseItem(std::shared_ptr item) { - if (!item) { - return; - } - - ToReleaseItems.push_back(item); -} - void Game::addBestiaryList(uint16_t raceid, std::string name) { auto it = BestiaryList.find(raceid); if (it != BestiaryList.end()) { @@ -9720,7 +9693,7 @@ std::shared_ptr Game::getPlayerUniqueLogin(const std::string &playerName } auto it = m_uniqueLoginPlayerNames.find(asLowerCaseString(playerName)); - return (it != m_uniqueLoginPlayerNames.end()) ? it->second : nullptr; + return (it != m_uniqueLoginPlayerNames.end()) ? it->second.lock() : nullptr; } void Game::removePlayerUniqueLogin(const std::string &playerName) { @@ -9739,8 +9712,8 @@ void Game::removePlayerUniqueLogin(std::shared_ptr player) { return; } - const std::string &lowercase_name = asLowerCaseString(player->getName()); - m_uniqueLoginPlayerNames.erase(lowercase_name); + const std::string &lowercaseName = asLowerCaseString(player->getName()); + m_uniqueLoginPlayerNames.erase(lowercaseName); } void Game::playerCheckActivity(const std::string &playerName, int interval) { diff --git a/src/game/game.hpp b/src/game/game.hpp index b8d2bf13b32..eb6de64001a 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -364,8 +364,6 @@ class Game { void cleanup(); void shutdown(); void dieSafely(std::string errorMsg); - void ReleaseCreature(std::shared_ptr creature); - void ReleaseItem(std::shared_ptr item); void addBestiaryList(uint16_t raceid, std::string name); const std::map &getBestiaryList() const { return BestiaryList; @@ -734,9 +732,9 @@ class Game { */ ReturnValue collectRewardChestItems(std::shared_ptr player, uint32_t maxMoveItems = 0); - phmap::flat_hash_map> m_uniqueLoginPlayerNames; + phmap::flat_hash_map> m_uniqueLoginPlayerNames; phmap::flat_hash_map> players; - phmap::flat_hash_map> mappedPlayerNames; + phmap::flat_hash_map> mappedPlayerNames; phmap::flat_hash_map> guilds; phmap::flat_hash_map> uniqueItems; std::map stages; @@ -751,9 +749,7 @@ class Game { std::string boostedCreature = ""; std::vector> CharmList; - std::vector> ToReleaseCreatures; std::vector> checkCreatureLists[EVENT_CREATURECOUNT]; - std::vector> ToReleaseItems; std::vector registeredMagicEffects; std::vector registeredDistanceEffects; diff --git a/src/game/scheduling/task.hpp b/src/game/scheduling/task.hpp index 99d452e6a60..a0d02a722ae 100644 --- a/src/game/scheduling/task.hpp +++ b/src/game/scheduling/task.hpp @@ -63,6 +63,7 @@ class Task { "ProtocolGame::parsePacketFromDispatcher", "Raids::checkRaids", "SpawnMonster::checkSpawnMonster", + "SpawnMonster::scheduleSpawn", "SpawnNpc::checkSpawnNpc", "Webhook::run", "sendRecvMessageCallback", diff --git a/src/game/zones/zone.cpp b/src/game/zones/zone.cpp index 2df32e215ca..3edea621499 100644 --- a/src/game/zones/zone.cpp +++ b/src/game/zones/zone.cpp @@ -148,7 +148,14 @@ const phmap::parallel_flat_hash_set> &Zone::getNpcs() const } const phmap::parallel_flat_hash_set> &Zone::getItems() const { - return itemsCache; + static phmap::parallel_flat_hash_set> items; + items.clear(); + for (const auto &item : itemsCache) { + if (auto itemPtr = item.lock()) { + items.insert(itemPtr); + } + } + return items; } void Zone::removePlayers() const { @@ -266,5 +273,6 @@ void Zone::itemRemoved(std::shared_ptr item) { if (!item) { return; } - itemsCache.erase(item); + std::weak_ptr weakItem = item; + itemsCache.erase(weakItem); } diff --git a/src/game/zones/zone.hpp b/src/game/zones/zone.hpp index 46c8edb08a0..88943bdc904 100644 --- a/src/game/zones/zone.hpp +++ b/src/game/zones/zone.hpp @@ -10,6 +10,7 @@ #pragma once #include "game/movement/position.hpp" +#include "items/item.hpp" class Tile; class Creature; @@ -127,7 +128,7 @@ class Zone { std::string name; phmap::parallel_flat_hash_set positions; - phmap::parallel_flat_hash_set> itemsCache; + weak::parallel_flat_hash_set itemsCache; phmap::parallel_flat_hash_set creaturesCache; phmap::parallel_flat_hash_set monstersCache; phmap::parallel_flat_hash_set npcsCache; diff --git a/src/items/decay/decay.cpp b/src/items/decay/decay.cpp index aaed3c193f2..816caadef6f 100644 --- a/src/items/decay/decay.cpp +++ b/src/items/decay/decay.cpp @@ -61,30 +61,30 @@ void Decay::stopDecay(std::shared_ptr item) { if (item->hasAttribute(ItemAttribute_t::DURATION_TIMESTAMP)) { auto it = decayMap.find(timestamp); if (it != decayMap.end()) { - std::vector> &decayItems = it->second; + auto &decayItems = it->second; size_t i = 0, end = decayItems.size(); + auto decayItem = decayItems[i].lock(); if (end == 1) { - if (item == decayItems[i]) { + if (item == decayItem) { if (item->hasAttribute(ItemAttribute_t::DURATION)) { // Incase we removed duration attribute don't assign new duration item->setDuration(item->getDuration()); } item->removeAttribute(ItemAttribute_t::DECAYSTATE); - g_game().ReleaseItem(item); decayMap.erase(it); } return; } while (i < end) { - if (item == decayItems[i]) { + decayItem = decayItems[i].lock(); + if (item == decayItem) { if (item->hasAttribute(ItemAttribute_t::DURATION)) { // Incase we removed duration attribute don't assign new duration item->setDuration(item->getDuration()); } item->removeAttribute(ItemAttribute_t::DECAYSTATE); - g_game().ReleaseItem(item); decayItems[i] = decayItems.back(); decayItems.pop_back(); @@ -113,12 +113,15 @@ void Decay::checkDecay() { } // Iterating here is unsafe so let's copy our items into temporary vector - std::vector> &decayItems = it->second; - tempItems.insert(tempItems.end(), decayItems.begin(), decayItems.end()); + auto &decayItems = it->second; + tempItems.reserve(tempItems.size() + decayItems.size()); + for (auto &decayItem : decayItems) { + tempItems.push_back(decayItem.lock()); + } it = decayMap.erase(it); } - for (std::shared_ptr item : tempItems) { + for (auto item : tempItems) { if (!item->canDecay()) { item->setDuration(item->getDuration()); item->setDecaying(DECAYING_FALSE); @@ -126,8 +129,6 @@ void Decay::checkDecay() { item->setDecaying(DECAYING_FALSE); internalDecayItem(item); } - - g_game().ReleaseItem(item); } if (it != end) { diff --git a/src/items/decay/decay.hpp b/src/items/decay/decay.hpp index f5eb60d1542..1cfbbc03c0b 100644 --- a/src/items/decay/decay.hpp +++ b/src/items/decay/decay.hpp @@ -30,7 +30,7 @@ class Decay { void internalDecayItem(std::shared_ptr item); uint32_t eventId { 0 }; - std::map>> decayMap; + std::map> decayMap; }; constexpr auto g_decay = Decay::getInstance; diff --git a/src/items/item.cpp b/src/items/item.cpp index 03dd550080a..0a34f34a255 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -3119,7 +3119,6 @@ std::shared_ptr Item::transform(uint16_t itemId, uint16_t itemCount /*= -1 resetParent(); cylinder->postRemoveNotification(static_self_cast(), cylinder, itemIndex); stopDecaying(); - g_game().ReleaseItem(static_self_cast()); newItem->startDecaying(); return newItem; } diff --git a/src/items/tile.cpp b/src/items/tile.cpp index 3e6317760d0..030ba0ab8c7 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -971,7 +971,6 @@ void Tile::addThing(int32_t, std::shared_ptr thing) { std::shared_ptr oldGround = ground; ground->resetParent(); - g_game().ReleaseItem(ground); ground = item; resetTileFlags(oldGround); setTileFlags(item); @@ -989,7 +988,6 @@ void Tile::addThing(int32_t, std::shared_ptr thing) { removeThing(oldSplash, 1); oldSplash->resetParent(); - g_game().ReleaseItem(oldSplash); postRemoveNotification(oldSplash, nullptr, 0); break; } @@ -1026,13 +1024,11 @@ void Tile::addThing(int32_t, std::shared_ptr thing) { removeThing(oldField, 1); oldField->resetParent(); - g_game().ReleaseItem(oldField); postRemoveNotification(oldField, nullptr, 0); break; } else { // This magic field cannot be replaced. item->resetParent(); - g_game().ReleaseItem(item); return; } } @@ -1484,13 +1480,6 @@ void Tile::postAddNotification(std::shared_ptr thing, std::shared_ptr(), true); } } - - // release the reference to this item onces we are finished - if (creature) { - g_game().ReleaseCreature(creature); - } else if (item) { - g_game().ReleaseItem(item); - } } void Tile::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { diff --git a/src/lua/callbacks/creaturecallback.cpp b/src/lua/callbacks/creaturecallback.cpp index 5a099f434be..df5845f46c0 100644 --- a/src/lua/callbacks/creaturecallback.cpp +++ b/src/lua/callbacks/creaturecallback.cpp @@ -15,6 +15,7 @@ bool CreatureCallback::startScriptInterface(int32_t scriptId) { } if (!scriptInterface->reserveScriptEnv()) { + auto targetCreature = m_targetCreature.lock(); g_logger().error( "[CreatureCallback::startScriptInterface] - {} {} Call stack overflow. Too many lua script calls being nested.", getCreatureClass(targetCreature), @@ -50,6 +51,9 @@ void CreatureCallback::pushSpecificCreature(std::shared_ptr creature) } std::string CreatureCallback::getCreatureClass(std::shared_ptr creature) { + if (!creature) { + return ""; + } if (creature->getNpc()) { return "Npc"; } diff --git a/src/lua/callbacks/creaturecallback.hpp b/src/lua/callbacks/creaturecallback.hpp index 16d91d0c966..4b017e773d5 100644 --- a/src/lua/callbacks/creaturecallback.hpp +++ b/src/lua/callbacks/creaturecallback.hpp @@ -17,7 +17,7 @@ class Creature; class CreatureCallback { public: CreatureCallback(LuaScriptInterface* scriptInterface, std::shared_ptr targetCreature) : - scriptInterface(scriptInterface), targetCreature(targetCreature) {}; + scriptInterface(scriptInterface), m_targetCreature(targetCreature) {}; ~CreatureCallback() { } bool startScriptInterface(int32_t scriptId); @@ -59,7 +59,7 @@ class CreatureCallback { private: LuaScriptInterface* scriptInterface; - std::shared_ptr targetCreature; + std::weak_ptr m_targetCreature; uint32_t params = 0; lua_State* L = nullptr; }; diff --git a/src/lua/global/shared_object.hpp b/src/lua/global/shared_object.hpp index 571fdf171c9..cdd082cc788 100644 --- a/src/lua/global/shared_object.hpp +++ b/src/lua/global/shared_object.hpp @@ -9,6 +9,8 @@ #pragma once +#include + class SharedObject; using SharedObjectPtr = std::shared_ptr; @@ -42,3 +44,120 @@ class SharedObject : public std::enable_shared_from_this { return std::dynamic_pointer_cast(source); } }; + +namespace weak { + template + struct Hash { + std::size_t operator()(const std::weak_ptr &wp) const { + auto sp = wp.lock(); + return std::hash>()(sp); + } + }; + + template + struct Equal { + bool operator()(const std::weak_ptr &lhs, const std::weak_ptr &rhs) const { + return lhs.lock() == rhs.lock(); + } + }; + + template + using parallel_flat_hash_set = phmap::parallel_flat_hash_set, Hash, Equal>; + + template + using vector = std::vector>; + + template + using list = std::list>; + + template + typename list::iterator find(const list &lst, const std::shared_ptr &item) { + return std::find_if(lst.begin(), lst.end(), [item](const std::weak_ptr &weak) { + return weak.lock() == item; + }); + } + + template + typename weak::vector::const_iterator find(const weak::vector &vec, const std::shared_ptr &item) { + return std::find_if(vec.cbegin(), vec.cend(), [item](const std::weak_ptr &weak) { + return weak.lock() == item; + }); + } + + template + typename weak::vector::iterator find(weak::vector &vec, const std::shared_ptr &item) { + return std::find_if(vec.begin(), vec.end(), [item](const std::weak_ptr &weak) { + return weak.lock() == item; + }); + } + + template + bool erase(parallel_flat_hash_set &set, const std::shared_ptr &item) { + return set.erase(item) > 0; + } + + template + bool erase(vector &vec, const std::shared_ptr &item) { + auto it = find(vec, item); + if (it != vec.end()) { + vec.erase(it); + return true; + } + return false; + } + + template + bool erase(list &lst, const std::shared_ptr &item) { + auto it = find(lst, item); + if (it != lst.end()) { + lst.erase(it); + return true; + } + return false; + } + + template + std::vector> lock(vector &vec) { + std::vector> result; + result.reserve(vec.size()); + for (auto it = vec.begin(); it != vec.end();) { + if (auto shared = it->lock()) { + result.push_back(shared); + ++it; + } else { + it = vec.erase(it); + } + } + return result; + } + + template + std::vector> lock(list &lst) { + std::vector> result; + result.reserve(lst.size()); + for (auto it = lst.begin(); it != lst.end();) { + if (auto shared = it->lock()) { + result.push_back(shared); + ++it; + } else { + it = lst.erase(it); + } + } + return result; + } + + template + phmap::parallel_flat_hash_set> lock(parallel_flat_hash_set &set) { + phmap::parallel_flat_hash_set> result; + result.reserve(set.size()); + for (auto it = set.begin(); it != set.end();) { + if (auto shared = it->lock()) { + result.insert(shared); + ++it; + } else { + it = set.erase(it); + } + } + return result; + } +} diff --git a/src/lua/scripts/script_environment.cpp b/src/lua/scripts/script_environment.cpp index aa257d433c3..8899a954f69 100644 --- a/src/lua/scripts/script_environment.cpp +++ b/src/lua/scripts/script_environment.cpp @@ -34,9 +34,6 @@ void ScriptEnvironment::resetEnv() { auto it = pair.first; while (it != pair.second) { std::shared_ptr item = it->second; - if (item->getParent() == VirtualCylinder::virtualCylinder) { - g_game().ReleaseItem(item); - } it = tempItems.erase(it); } } diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index 52d1a5966ba..4b1864d43f5 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -375,7 +375,6 @@ void House::resetTransferItem() { transferItem = nullptr; transfer_container.resetParent(); transfer_container.removeThing(tmpItem, tmpItem->getItemCount()); - g_game().ReleaseItem(tmpItem); } } From c730714b1de20b8d9289a63a21461e7af95c89a8 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sat, 16 Sep 2023 16:49:52 -0700 Subject: [PATCH 14/67] fix: missing tile --- src/creatures/players/player.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index bee6fdccd24..aa9180921f7 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -5600,7 +5600,8 @@ bool Player::toggleMount(bool mount) { return false; } - if (!group->access && tile->hasFlag(TILESTATE_PROTECTIONZONE)) { + auto tile = getTile(); + if (!group->access && tile && tile->hasFlag(TILESTATE_PROTECTIONZONE)) { sendCancelMessage(RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE); return false; } From 617e4bb077529e09948d6db1b60e9a7d992ce901 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sat, 16 Sep 2023 18:43:32 -0700 Subject: [PATCH 15/67] improve: check parent on decay --- src/items/containers/container.cpp | 2 +- src/items/containers/depot/depotchest.cpp | 2 +- src/items/containers/depot/depotchest.hpp | 2 +- src/items/containers/depot/depotlocker.cpp | 4 ++-- src/items/containers/inbox/inbox.cpp | 2 +- src/items/containers/inbox/inbox.hpp | 2 +- src/items/containers/rewards/reward.cpp | 2 +- src/items/containers/rewards/reward.hpp | 2 +- src/items/containers/rewards/rewardchest.cpp | 4 ++-- src/items/item.hpp | 14 +++++++++----- 10 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/items/containers/container.cpp b/src/items/containers/container.cpp index 4a08c2a3ba9..3d71bdb72dc 100644 --- a/src/items/containers/container.cpp +++ b/src/items/containers/container.cpp @@ -57,7 +57,7 @@ std::shared_ptr Container::create(std::shared_ptr tile) { Container::~Container() { if (getID() == ITEM_BROWSEFIELD) { for (std::shared_ptr item : itemlist) { - item->setParent(parent); + item->setParent(m_parent); } } } diff --git a/src/items/containers/depot/depotchest.cpp b/src/items/containers/depot/depotchest.cpp index 7471cdd0dbe..01191579840 100644 --- a/src/items/containers/depot/depotchest.cpp +++ b/src/items/containers/depot/depotchest.cpp @@ -68,7 +68,7 @@ void DepotChest::postRemoveNotification(std::shared_ptr thing, std::share } std::shared_ptr DepotChest::getParent() { - auto parentLocked = parent.lock(); + auto parentLocked = m_parent.lock(); if (parentLocked && parentLocked->getParent()) { return parentLocked->getParent()->getParent(); } diff --git a/src/items/containers/depot/depotchest.hpp b/src/items/containers/depot/depotchest.hpp index 75ea88154d2..069bad38209 100644 --- a/src/items/containers/depot/depotchest.hpp +++ b/src/items/containers/depot/depotchest.hpp @@ -40,7 +40,7 @@ class DepotChest final : public Container { std::shared_ptr getParent() override; std::shared_ptr getRealParent() override { - return parent.lock(); + return m_parent.lock(); } private: diff --git a/src/items/containers/depot/depotlocker.cpp b/src/items/containers/depot/depotlocker.cpp index 53ed57c29ed..c431e8bd58e 100644 --- a/src/items/containers/depot/depotlocker.cpp +++ b/src/items/containers/depot/depotlocker.cpp @@ -29,14 +29,14 @@ ReturnValue DepotLocker::queryAdd(int32_t, const std::shared_ptr &, uint3 } void DepotLocker::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { - auto parentLocked = parent.lock(); + auto parentLocked = m_parent.lock(); if (parentLocked) { parentLocked->postAddNotification(thing, oldParent, index, LINK_PARENT); } } void DepotLocker::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { - auto parentLocked = parent.lock(); + auto parentLocked = m_parent.lock(); if (parentLocked) { parentLocked->postRemoveNotification(thing, newParent, index, LINK_PARENT); } diff --git a/src/items/containers/inbox/inbox.cpp b/src/items/containers/inbox/inbox.cpp index 79d5ee1aa35..7859cd3be3f 100644 --- a/src/items/containers/inbox/inbox.cpp +++ b/src/items/containers/inbox/inbox.cpp @@ -67,7 +67,7 @@ void Inbox::postRemoveNotification(std::shared_ptr thing, std::shared_ptr } std::shared_ptr Inbox::getParent() { - auto parentLocked = parent.lock(); + auto parentLocked = m_parent.lock(); if (parentLocked) { return parentLocked->getParent(); } diff --git a/src/items/containers/inbox/inbox.hpp b/src/items/containers/inbox/inbox.hpp index 9687e02bf4c..058f96e029a 100644 --- a/src/items/containers/inbox/inbox.hpp +++ b/src/items/containers/inbox/inbox.hpp @@ -39,7 +39,7 @@ class Inbox final : public Container { std::shared_ptr getParent() override; std::shared_ptr getRealParent() override { - return parent.lock(); + return m_parent.lock(); } private: diff --git a/src/items/containers/rewards/reward.cpp b/src/items/containers/rewards/reward.cpp index 09f5a9c3aed..62ef98b0c7e 100644 --- a/src/items/containers/rewards/reward.cpp +++ b/src/items/containers/rewards/reward.cpp @@ -54,5 +54,5 @@ void Reward::postRemoveNotification(std::shared_ptr thing, std::shared_pt } std::shared_ptr Reward::getParent() { - return parent.lock(); + return m_parent.lock(); } diff --git a/src/items/containers/rewards/reward.hpp b/src/items/containers/rewards/reward.hpp index 6a0071a4daa..f372fbfb74b 100644 --- a/src/items/containers/rewards/reward.hpp +++ b/src/items/containers/rewards/reward.hpp @@ -32,6 +32,6 @@ class Reward : public Container { std::shared_ptr getParent() final; std::shared_ptr getRealParent() final { - return parent.lock(); + return m_parent.lock(); } }; diff --git a/src/items/containers/rewards/rewardchest.cpp b/src/items/containers/rewards/rewardchest.cpp index d7f46d74ce6..00729491139 100644 --- a/src/items/containers/rewards/rewardchest.cpp +++ b/src/items/containers/rewards/rewardchest.cpp @@ -27,14 +27,14 @@ ReturnValue RewardChest::queryAdd(int32_t, const std::shared_ptr &, uint3 } void RewardChest::postAddNotification(std::shared_ptr thing, std::shared_ptr oldParent, int32_t index, CylinderLink_t) { - auto parentLocked = parent.lock(); + auto parentLocked = m_parent.lock(); if (parentLocked) { parentLocked->postAddNotification(thing, oldParent, index, LINK_PARENT); } } void RewardChest::postRemoveNotification(std::shared_ptr thing, std::shared_ptr newParent, int32_t index, CylinderLink_t) { - auto parentLocked = parent.lock(); + auto parentLocked = m_parent.lock(); if (parentLocked) { parentLocked->postRemoveNotification(thing, newParent, index, LINK_PARENT); } diff --git a/src/items/item.hpp b/src/items/item.hpp index 3bb839ccd32..9febd27a917 100644 --- a/src/items/item.hpp +++ b/src/items/item.hpp @@ -564,18 +564,22 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { bool hasMarketAttributes() const; std::shared_ptr getParent() override { - return parent.lock(); + return m_parent.lock(); } void setParent(std::weak_ptr cylinder) override { - parent = cylinder; + m_parent = cylinder; } void resetParent() { - parent.reset(); + m_parent.reset(); } std::shared_ptr getTopParent(); std::shared_ptr getTile() override; bool isRemoved() override { - return parent.expired() || getParent()->isRemoved(); + auto parent = getParent(); + if (parent) { + return parent->isRemoved(); + } + return true; } bool isInsideDepot(bool includeInbox = false); @@ -676,7 +680,7 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { void checkDecayMapItemOnMove(); protected: - std::weak_ptr parent; + std::weak_ptr m_parent; uint16_t id; // the same id as in ItemType uint8_t count = 1; // number of stacked items From 0313923b87b2b838e6271287fbd0cd40ecfa649b Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sat, 16 Sep 2023 18:54:52 -0700 Subject: [PATCH 16/67] improve: only decay valid items --- src/items/decay/decay.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/items/decay/decay.cpp b/src/items/decay/decay.cpp index 816caadef6f..7d98a0836ce 100644 --- a/src/items/decay/decay.cpp +++ b/src/items/decay/decay.cpp @@ -114,9 +114,10 @@ void Decay::checkDecay() { // Iterating here is unsafe so let's copy our items into temporary vector auto &decayItems = it->second; - tempItems.reserve(tempItems.size() + decayItems.size()); - for (auto &decayItem : decayItems) { - tempItems.push_back(decayItem.lock()); + auto lockedDecayItems = weak::lock(decayItems); + tempItems.reserve(tempItems.size() + lockedDecayItems.size()); + for (auto &decayItem : lockedDecayItems) { + tempItems.push_back(decayItem); } it = decayMap.erase(it); } From 5fabf2e826b1090073a35ee9c8e9d884ac6b6ff0 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sat, 16 Sep 2023 19:48:43 -0700 Subject: [PATCH 17/67] fix: spell combats --- src/creatures/combat/spells.cpp | 2 +- src/creatures/combat/spells.hpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index f92bbdadcca..46c5ba8f604 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -246,7 +246,7 @@ CombatSpell::CombatSpell(const std::shared_ptr newCombat, bool newNeedTa bool CombatSpell::loadScriptCombat() { m_combat = g_luaEnvironment().getCombatObject(g_luaEnvironment().lastCombatId); - return !m_combat.expired(); + return m_combat != nullptr; } bool CombatSpell::castSpell(std::shared_ptr creature) { diff --git a/src/creatures/combat/spells.hpp b/src/creatures/combat/spells.hpp index 1248c2a970d..f95f8aa40b3 100644 --- a/src/creatures/combat/spells.hpp +++ b/src/creatures/combat/spells.hpp @@ -103,8 +103,8 @@ class CombatSpell final : public Script, public BaseSpell, public std::enable_sh bool executeCastSpell(std::shared_ptr creature, const LuaVariant &var) const; bool loadScriptCombat(); - std::shared_ptr getCombat() { - return m_combat.lock(); + std::shared_ptr getCombat() const { + return m_combat; } private: @@ -112,7 +112,7 @@ class CombatSpell final : public Script, public BaseSpell, public std::enable_sh return "onCastSpell"; } - std::weak_ptr m_combat; + std::shared_ptr m_combat; bool needDirection; bool needTarget; From bbe1f905f58f9c32a10c7d0d2f736da2cbedb038 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sun, 17 Sep 2023 11:29:41 -0700 Subject: [PATCH 18/67] improve: move summons back to shared with more efficient data strctures --- src/creatures/creature.cpp | 31 ++++++------------- src/creatures/creature.hpp | 26 +++++----------- src/creatures/monsters/monster.cpp | 6 ++-- src/creatures/players/grouping/party.cpp | 24 +++----------- src/game/game.cpp | 6 +--- .../creatures/creature_functions.cpp | 12 +++---- 6 files changed, 29 insertions(+), 76 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index b0d09a77d64..ab594f8c68a 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -26,11 +26,7 @@ Creature::Creature() { } Creature::~Creature() { - for (auto summonPtr : m_summons) { - auto summon = summonPtr.lock(); - if (!summon) { - continue; - } + for (auto &[_, summon] : m_summons) { summon->setAttackedCreature(nullptr); summon->removeMaster(); } @@ -429,14 +425,9 @@ void Creature::onAttackedCreatureChangeZone(ZoneType_t zone) { void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) { if (hasSummons()) { std::vector> despawnMonsterList; - for (auto summonPtr : getSummons()) { - auto creature = summonPtr.lock(); - if (!creature) { - continue; - } - - const Position &pos = creature->getPosition(); - std::shared_ptr monster = creature->getMonster(); + for (auto &[_, summon] : getSummons()) { + const Position &pos = summon->getPosition(); + std::shared_ptr monster = summon->getMonster(); auto tile = getTile(); bool protectionZoneCheck = tile ? tile->hasFlag(TILESTATE_PROTECTIONZONE) : false; // Check if any of our summons is out of range (+/- 0 floors or 15 tiles away) @@ -445,7 +436,7 @@ void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) { bool checkRemoveDist = Position::getDistanceZ(newPos, pos) > 2 || (std::max(Position::getDistanceX(newPos, pos), Position::getDistanceY(newPos, pos)) > 30); if (monster && monster->isFamiliar() && checkSummonDist || teleportSummon && !protectionZoneCheck && checkSummonDist) { - auto creatureMaster = creature->getMaster(); + auto creatureMaster = summon->getMaster(); if (!creatureMaster) { continue; } @@ -454,14 +445,14 @@ void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) { if (masterTile->hasFlag(TILESTATE_TELEPORT)) { g_logger().warn("[{}] cannot teleport summon, position has teleport. {}", __FUNCTION__, creatureMaster->getPosition().toString()); } else { - g_game().internalTeleport(creature, creatureMaster->getPosition(), true); + g_game().internalTeleport(summon, creatureMaster->getPosition(), true); continue; } } } if (monster && monster->isSummon() && !monster->isFamiliar() && !teleportSummon && checkRemoveDist) { - despawnMonsterList.push_back(creature); + despawnMonsterList.push_back(summon); } } @@ -954,11 +945,7 @@ bool Creature::setAttackedCreature(std::shared_ptr creature) { m_attackedCreature.reset(); } - for (auto summonPtr : m_summons) { - auto summon = summonPtr.lock(); - if (!summon) { - continue; - } + for (auto &[_, summon] : m_summons) { summon->setAttackedCreature(creature); } return true; @@ -1245,7 +1232,7 @@ bool Creature::setMaster(std::shared_ptr newMaster, bool reloadCreatur g_game().reloadCreature(static_self_cast()); } if (newMaster) { - newMaster->m_summons.push_back(static_self_cast()); + newMaster->m_summons.try_emplace(getID(), static_self_cast()); } m_master = newMaster; diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index f7ce33fb422..a81b6da7f7b 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -331,28 +331,18 @@ class Creature : virtual public Thing, public SharedObject { return m_master.lock(); } - const weak::list &getSummons() const { + const phmap::flat_hash_map> &getSummons() const { return m_summons; } - std::shared_ptr getSummon(uint32_t creatureId) { - for (const auto &summon : m_summons) { - if (summon.expired()) { - continue; - } - - if (summon.lock()->getID() == creatureId) { - return summon.lock(); - } - } - - return nullptr; + const std::shared_ptr &getSummon(uint32_t creatureId) { + return m_summons.at(creatureId); } - void removeSummon(std::shared_ptr summon) { - m_summons.remove_if([&summon](const std::weak_ptr &weakSummon) { - return weakSummon.expired() || weakSummon.lock() == summon; - }); + void removeSummon(const std::shared_ptr &summon) { + if (summon) { + m_summons.erase(summon->getID()); + } } virtual int32_t getArmor() const { @@ -675,7 +665,7 @@ class Creature : virtual public Thing, public SharedObject { CountMap damageMap; - weak::list m_summons; + phmap::flat_hash_map> m_summons; CreatureEventList eventsList; ConditionList conditions; diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index eecd6757135..efe022d9d93 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -1013,8 +1013,7 @@ void Monster::onThinkDefense(uint32_t interval) { } uint32_t summonCount = 0; - for (auto summonPtr : m_summons) { - auto summon = summonPtr.lock(); + for (auto &[_, summon] : m_summons) { if (summon && summon->getName() == summonBlock.name) { ++summonCount; } @@ -1853,8 +1852,7 @@ void Monster::death(std::shared_ptr) { } setAttackedCreature(nullptr); - for (auto summonPtr : m_summons) { - auto summon = summonPtr.lock(); + for (auto &[_, summon] : m_summons) { if (!summon) { continue; } diff --git a/src/creatures/players/grouping/party.cpp b/src/creatures/players/grouping/party.cpp index b2d8fae9f76..dfbb2638995 100644 --- a/src/creatures/players/grouping/party.cpp +++ b/src/creatures/players/grouping/party.cpp @@ -581,19 +581,11 @@ void Party::showPlayerStatus(std::shared_ptr player, std::shared_ptrsendPartyCreatureShowStatus(member, showStatus); member->sendPartyCreatureShowStatus(player, showStatus); if (showStatus) { - for (auto summonPtr : member->getSummons()) { - auto summon = summonPtr.lock(); - if (!summon) { - continue; - } + for (auto &[_, summon] : member->getSummons()) { player->sendPartyCreatureShowStatus(summon, showStatus); player->sendPartyCreatureHealth(summon, std::ceil((static_cast(summon->getHealth()) / std::max(summon->getMaxHealth(), 1)) * 100)); } - for (auto summonPtr : player->getSummons()) { - auto summon = summonPtr.lock(); - if (!summon) { - continue; - } + for (auto &[_, summon] : player->getSummons()) { member->sendPartyCreatureShowStatus(summon, showStatus); member->sendPartyCreatureHealth(summon, std::ceil((static_cast(summon->getHealth()) / std::max(summon->getMaxHealth(), 1)) * 100)); } @@ -602,18 +594,10 @@ void Party::showPlayerStatus(std::shared_ptr player, std::shared_ptrsendPartyPlayerMana(member, std::ceil((static_cast(member->getMana()) / std::max(member->getMaxMana(), 1)) * 100)); member->sendPartyPlayerMana(player, std::ceil((static_cast(player->getMana()) / std::max(player->getMaxMana(), 1)) * 100)); } else { - for (auto summonPtr : player->getSummons()) { - auto summon = summonPtr.lock(); - if (!summon) { - continue; - } + for (auto &[_, summon] : player->getSummons()) { member->sendPartyCreatureShowStatus(summon, showStatus); } - for (auto summonPtr : member->getSummons()) { - auto summon = summonPtr.lock(); - if (!summon) { - continue; - } + for (auto &[_, summon] : member->getSummons()) { player->sendPartyCreatureShowStatus(summon, showStatus); } } diff --git a/src/game/game.cpp b/src/game/game.cpp index c2b14b7e4b4..377a3bc1986 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -936,11 +936,7 @@ bool Game::removeCreature(std::shared_ptr creature, bool isLogout /* = removeCreatureCheck(creature); - for (auto summonPtr : creature->m_summons) { - auto summon = summonPtr.lock(); - if (!summon) { - continue; - } + for (auto &[_, summon] : creature->m_summons) { summon->setSkillLoss(false); removeCreature(summon); } diff --git a/src/lua/functions/creatures/creature_functions.cpp b/src/lua/functions/creatures/creature_functions.cpp index 52da97e5180..8890ca96708 100644 --- a/src/lua/functions/creatures/creature_functions.cpp +++ b/src/lua/functions/creatures/creature_functions.cpp @@ -859,14 +859,12 @@ int CreatureFunctions::luaCreatureGetSummons(lua_State* L) { lua_createtable(L, creature->getSummonCount(), 0); int index = 0; - for (auto summonPtr : creature->getSummons()) { - auto summon = summonPtr.lock(); - if (!summon) { - continue; + for (auto &[_, summon] : creature->getSummons()) { + if (summon) { + pushUserdata(L, summon); + setCreatureMetatable(L, -1, summon); + lua_rawseti(L, -2, ++index); } - pushUserdata(L, summon); - setCreatureMetatable(L, -1, summon); - lua_rawseti(L, -2, ++index); } return 1; } From acd4cd4c033468b6d3119061a6116ffda96d26e3 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sun, 17 Sep 2023 12:20:28 -0700 Subject: [PATCH 19/67] improve: zone ptrs --- src/game/zones/zone.cpp | 38 +++++++++++++++----------------------- src/game/zones/zone.hpp | 16 ++++++++-------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/game/zones/zone.cpp b/src/game/zones/zone.cpp index 3edea621499..42ed036ed2c 100644 --- a/src/game/zones/zone.cpp +++ b/src/game/zones/zone.cpp @@ -66,7 +66,7 @@ bool Zone::isPositionInZone(const Position &pos) const { return positions.contains(pos); } -Position Zone::getRemoveDestination(std::shared_ptr creature /* = nullptr */) const { +Position Zone::getRemoveDestination(const std::shared_ptr &creature /* = nullptr */) const { if (!creature || !creature->getPlayer()) { return Position(); } @@ -87,11 +87,11 @@ const phmap::parallel_flat_hash_set &Zone::getPositions() const { return positions; } -const phmap::parallel_flat_hash_set> &Zone::getTiles() const { - static phmap::parallel_flat_hash_set> tiles; +const phmap::parallel_flat_hash_set &> &Zone::getTiles() const { + static phmap::parallel_flat_hash_set &> tiles; tiles.clear(); for (const auto &position : positions) { - std::shared_ptr tile = g_game().map.getTile(position); + const auto &tile = g_game().map.getTile(position); if (tile) { tiles.insert(tile); } @@ -103,7 +103,7 @@ const phmap::parallel_flat_hash_set> &Zone::getCreatur static phmap::parallel_flat_hash_set> creatures; creatures.clear(); for (const auto creatureId : creaturesCache) { - auto creature = g_game().getCreatureByID(creatureId); + const auto &creature = g_game().getCreatureByID(creatureId); if (creature) { creatures.insert(creature); } @@ -115,7 +115,7 @@ const phmap::parallel_flat_hash_set> &Zone::getPlayers() static phmap::parallel_flat_hash_set> players; players.clear(); for (const auto playerId : playersCache) { - auto player = g_game().getPlayerByID(playerId); + const auto &player = g_game().getPlayerByID(playerId); if (player) { players.insert(player); } @@ -127,7 +127,7 @@ const phmap::parallel_flat_hash_set> &Zone::getMonsters static phmap::parallel_flat_hash_set> monsters; monsters.clear(); for (const auto monsterId : monstersCache) { - auto monster = g_game().getMonsterByID(monsterId); + const auto &monster = g_game().getMonsterByID(monsterId); if (monster) { monsters.insert(monster); } @@ -139,7 +139,7 @@ const phmap::parallel_flat_hash_set> &Zone::getNpcs() const static phmap::parallel_flat_hash_set> npcs; npcs.clear(); for (const auto npcId : npcsCache) { - auto npc = g_game().getNpcByID(npcId); + const auto &npc = g_game().getNpcByID(npcId); if (npc) { npcs.insert(npc); } @@ -148,14 +148,7 @@ const phmap::parallel_flat_hash_set> &Zone::getNpcs() const } const phmap::parallel_flat_hash_set> &Zone::getItems() const { - static phmap::parallel_flat_hash_set> items; - items.clear(); - for (const auto &item : itemsCache) { - if (auto itemPtr = item.lock()) { - items.insert(itemPtr); - } - } - return items; + return itemsCache; } void Zone::removePlayers() const { @@ -201,7 +194,7 @@ const phmap::parallel_flat_hash_set> &Zone::getZones() { return zonesSet; } -void Zone::creatureAdded(std::shared_ptr creature) { +void Zone::creatureAdded(const std::shared_ptr &creature) { if (!creature) { return; } @@ -234,7 +227,7 @@ void Zone::creatureAdded(std::shared_ptr creature) { } } -void Zone::creatureRemoved(std::shared_ptr creature) { +void Zone::creatureRemoved(const std::shared_ptr &creature) { if (!creature) { return; } @@ -250,7 +243,7 @@ void Zone::creatureRemoved(std::shared_ptr creature) { } } -void Zone::thingAdded(std::shared_ptr thing) { +void Zone::thingAdded(const std::shared_ptr &thing) { if (!thing) { return; } @@ -262,17 +255,16 @@ void Zone::thingAdded(std::shared_ptr thing) { } } -void Zone::itemAdded(std::shared_ptr item) { +void Zone::itemAdded(const std::shared_ptr &item) { if (!item) { return; } itemsCache.insert(item); } -void Zone::itemRemoved(std::shared_ptr item) { +void Zone::itemRemoved(const std::shared_ptr &item) { if (!item) { return; } - std::weak_ptr weakItem = item; - itemsCache.erase(weakItem); + itemsCache.erase(item); } diff --git a/src/game/zones/zone.hpp b/src/game/zones/zone.hpp index 88943bdc904..12b91a799ea 100644 --- a/src/game/zones/zone.hpp +++ b/src/game/zones/zone.hpp @@ -94,24 +94,24 @@ class Zone { void addArea(Area area); void subtractArea(Area area); bool isPositionInZone(const Position &position) const; - Position getRemoveDestination(std::shared_ptr creature = nullptr) const; + Position getRemoveDestination(const std::shared_ptr &creature = nullptr) const; void setRemoveDestination(const Position &position) { removeDestination = position; } const phmap::parallel_flat_hash_set &getPositions() const; - const phmap::parallel_flat_hash_set> &getTiles() const; + const phmap::parallel_flat_hash_set &> &getTiles() const; const phmap::parallel_flat_hash_set> &getCreatures() const; const phmap::parallel_flat_hash_set> &getPlayers() const; const phmap::parallel_flat_hash_set> &getMonsters() const; const phmap::parallel_flat_hash_set> &getNpcs() const; const phmap::parallel_flat_hash_set> &getItems() const; - void creatureAdded(std::shared_ptr creature); - void creatureRemoved(std::shared_ptr creature); - void thingAdded(std::shared_ptr thing); - void itemAdded(std::shared_ptr item); - void itemRemoved(std::shared_ptr item); + void creatureAdded(const std::shared_ptr &creature); + void creatureRemoved(const std::shared_ptr &creature); + void thingAdded(const std::shared_ptr &thing); + void itemAdded(const std::shared_ptr &item); + void itemRemoved(const std::shared_ptr &item); void removePlayers() const; void removeMonsters() const; @@ -128,7 +128,7 @@ class Zone { std::string name; phmap::parallel_flat_hash_set positions; - weak::parallel_flat_hash_set itemsCache; + phmap::parallel_flat_hash_set> itemsCache; phmap::parallel_flat_hash_set creaturesCache; phmap::parallel_flat_hash_set monstersCache; phmap::parallel_flat_hash_set npcsCache; From e4bd0cf8fc385c1822752ea1d38bb1a5f3de74bc Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sun, 17 Sep 2023 12:29:54 -0700 Subject: [PATCH 20/67] improve: revert decay to shared_ptr --- src/game/zones/zone.cpp | 4 ++-- src/game/zones/zone.hpp | 2 +- src/items/decay/decay.cpp | 17 ++++++++--------- src/items/decay/decay.hpp | 8 ++++---- src/lua/functions/core/game/zone_functions.cpp | 2 +- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/game/zones/zone.cpp b/src/game/zones/zone.cpp index 42ed036ed2c..dc0958e6c1d 100644 --- a/src/game/zones/zone.cpp +++ b/src/game/zones/zone.cpp @@ -87,8 +87,8 @@ const phmap::parallel_flat_hash_set &Zone::getPositions() const { return positions; } -const phmap::parallel_flat_hash_set &> &Zone::getTiles() const { - static phmap::parallel_flat_hash_set &> tiles; +const phmap::parallel_flat_hash_set> &Zone::getTiles() const { + static phmap::parallel_flat_hash_set> tiles; tiles.clear(); for (const auto &position : positions) { const auto &tile = g_game().map.getTile(position); diff --git a/src/game/zones/zone.hpp b/src/game/zones/zone.hpp index 12b91a799ea..f2f9545e808 100644 --- a/src/game/zones/zone.hpp +++ b/src/game/zones/zone.hpp @@ -100,7 +100,7 @@ class Zone { } const phmap::parallel_flat_hash_set &getPositions() const; - const phmap::parallel_flat_hash_set &> &getTiles() const; + const phmap::parallel_flat_hash_set> &getTiles() const; const phmap::parallel_flat_hash_set> &getCreatures() const; const phmap::parallel_flat_hash_set> &getPlayers() const; const phmap::parallel_flat_hash_set> &getMonsters() const; diff --git a/src/items/decay/decay.cpp b/src/items/decay/decay.cpp index 7d98a0836ce..25ff2b3003f 100644 --- a/src/items/decay/decay.cpp +++ b/src/items/decay/decay.cpp @@ -13,7 +13,7 @@ #include "game/game.hpp" #include "game/scheduling/scheduler.hpp" -void Decay::startDecay(std::shared_ptr item) { +void Decay::startDecay(const std::shared_ptr &item) { if (!item) { return; } @@ -55,7 +55,7 @@ void Decay::startDecay(std::shared_ptr item) { } } -void Decay::stopDecay(std::shared_ptr item) { +void Decay::stopDecay(const std::shared_ptr &item) { if (item->hasAttribute(ItemAttribute_t::DECAYSTATE)) { auto timestamp = item->getAttribute(ItemAttribute_t::DURATION_TIMESTAMP); if (item->hasAttribute(ItemAttribute_t::DURATION_TIMESTAMP)) { @@ -64,7 +64,7 @@ void Decay::stopDecay(std::shared_ptr item) { auto &decayItems = it->second; size_t i = 0, end = decayItems.size(); - auto decayItem = decayItems[i].lock(); + auto decayItem = decayItems[i]; if (end == 1) { if (item == decayItem) { if (item->hasAttribute(ItemAttribute_t::DURATION)) { @@ -78,7 +78,7 @@ void Decay::stopDecay(std::shared_ptr item) { return; } while (i < end) { - decayItem = decayItems[i].lock(); + decayItem = decayItems[i]; if (item == decayItem) { if (item->hasAttribute(ItemAttribute_t::DURATION)) { // Incase we removed duration attribute don't assign new duration @@ -114,15 +114,14 @@ void Decay::checkDecay() { // Iterating here is unsafe so let's copy our items into temporary vector auto &decayItems = it->second; - auto lockedDecayItems = weak::lock(decayItems); - tempItems.reserve(tempItems.size() + lockedDecayItems.size()); - for (auto &decayItem : lockedDecayItems) { + tempItems.reserve(tempItems.size() + decayItems.size()); + for (auto &decayItem : decayItems) { tempItems.push_back(decayItem); } it = decayMap.erase(it); } - for (auto item : tempItems) { + for (const auto &item : tempItems) { if (!item->canDecay()) { item->setDuration(item->getDuration()); item->setDecaying(DECAYING_FALSE); @@ -137,7 +136,7 @@ void Decay::checkDecay() { } } -void Decay::internalDecayItem(std::shared_ptr item) { +void Decay::internalDecayItem(const std::shared_ptr &item) { const ItemType &it = Item::items[item->getID()]; if (it.decayTo != 0) { std::shared_ptr player = item->getHoldingPlayer(); diff --git a/src/items/decay/decay.hpp b/src/items/decay/decay.hpp index 1cfbbc03c0b..481be26c610 100644 --- a/src/items/decay/decay.hpp +++ b/src/items/decay/decay.hpp @@ -22,15 +22,15 @@ class Decay { return inject(); } - void startDecay(std::shared_ptr item); - void stopDecay(std::shared_ptr item); + void startDecay(const std::shared_ptr &item); + void stopDecay(const std::shared_ptr &item); private: void checkDecay(); - void internalDecayItem(std::shared_ptr item); + void internalDecayItem(const std::shared_ptr &item); uint32_t eventId { 0 }; - std::map> decayMap; + phmap::flat_hash_map>> decayMap; }; constexpr auto g_decay = Decay::getInstance; diff --git a/src/lua/functions/core/game/zone_functions.cpp b/src/lua/functions/core/game/zone_functions.cpp index 8c4d06d02dd..d1b341a1aea 100644 --- a/src/lua/functions/core/game/zone_functions.cpp +++ b/src/lua/functions/core/game/zone_functions.cpp @@ -135,7 +135,7 @@ int ZoneFunctions::luaZoneGetTiles(lua_State* L) { int index = 0; for (auto tile : tiles) { index++; - pushUserdata(L, tile); + pushUserdata(L, tile.get()); setMetatable(L, -1, "Tile"); lua_rawseti(L, -2, index); } From abdff844f45657c94e74f6d7134865fa6244b6d2 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sun, 17 Sep 2023 13:06:33 -0700 Subject: [PATCH 21/67] improve: revert party to shared_ptr --- src/creatures/players/grouping/party.cpp | 20 +++++++++++++------- src/creatures/players/grouping/party.hpp | 8 ++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/creatures/players/grouping/party.cpp b/src/creatures/players/grouping/party.cpp index dfbb2638995..9eff4a76786 100644 --- a/src/creatures/players/grouping/party.cpp +++ b/src/creatures/players/grouping/party.cpp @@ -104,14 +104,14 @@ bool Party::leaveParty(std::shared_ptr player) { if (memberList.size() == 1 && inviteList.empty()) { missingLeader = true; } else { - auto newLeader = memberList.front().lock(); + auto newLeader = memberList.front(); while (!newLeader) { memberList.erase(memberList.begin()); if (memberList.empty()) { missingLeader = true; break; } - newLeader = memberList.front().lock(); + newLeader = memberList.front(); } if (newLeader) { passPartyLeadership(newLeader); @@ -123,7 +123,10 @@ bool Party::leaveParty(std::shared_ptr player) { } // since we already passed the leadership, we remove the player from the list - weak::erase(memberList, player); + auto it = std::find(memberList.begin(), memberList.end(), player); + if (it != memberList.end()) { + memberList.erase(it); + } player->setParty(nullptr); player->sendClosePrivate(CHANNEL_PARTY); @@ -166,7 +169,10 @@ bool Party::passPartyLeadership(std::shared_ptr player) { } // Remove it before to broadcast the message correctly - weak::erase(memberList, player); + auto it = std::find(memberList.begin(), memberList.end(), player); + if (it != memberList.end()) { + memberList.erase(it); + } std::ostringstream ss; ss << player->getName() << " is now the leader of the party."; @@ -211,7 +217,7 @@ bool Party::joinParty(const std::shared_ptr &player) { return false; } - auto it = weak::find(inviteList, player); + auto it = std::find(inviteList.begin(), inviteList.end(), player); if (it == inviteList.end()) { return false; } @@ -258,7 +264,7 @@ bool Party::removeInvite(const std::shared_ptr &player, bool removeFromP return false; } - auto it = weak::find(inviteList, player); + auto it = std::find(inviteList.begin(), inviteList.end(), player); if (it == inviteList.end()) { return false; } @@ -343,7 +349,7 @@ bool Party::invitePlayer(const std::shared_ptr &player) { } bool Party::isPlayerInvited(const std::shared_ptr &player) const { - return weak::find(inviteList, player) != inviteList.end(); + return std::find(inviteList.begin(), inviteList.end(), player) != inviteList.end(); } void Party::updateAllPartyIcons() { diff --git a/src/creatures/players/grouping/party.hpp b/src/creatures/players/grouping/party.hpp index f856b486966..d6c0e9ea6bc 100644 --- a/src/creatures/players/grouping/party.hpp +++ b/src/creatures/players/grouping/party.hpp @@ -32,10 +32,10 @@ class Party { return m_leader.lock(); } std::vector> getMembers() { - return weak::lock(memberList); + return memberList; } std::vector> getInvitees() { - return weak::lock(inviteList); + return inviteList; } size_t getMemberCount() const { return memberList.size(); @@ -124,8 +124,8 @@ class Party { std::map ticksMap; - weak::vector memberList; - weak::vector inviteList; + std::vector> memberList; + std::vector> inviteList; std::weak_ptr m_leader; From 3e729b25d90ab5338fcc53d46380a0a75cdbea78 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sun, 17 Sep 2023 13:14:00 -0700 Subject: [PATCH 22/67] improve: more careful weak_ptrs in npc --- src/creatures/npcs/npc.cpp | 19 ++-- src/creatures/npcs/npc.hpp | 6 +- src/creatures/players/grouping/guild.cpp | 15 +-- src/creatures/players/grouping/guild.hpp | 14 +-- src/lua/global/shared_object.hpp | 117 ----------------------- 5 files changed, 24 insertions(+), 147 deletions(-) diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index 5bbe777a3bd..b8775ee148a 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -110,7 +110,7 @@ void Npc::onRemoveCreature(std::shared_ptr creature, bool isLogout) { spawnNpc->startSpawnNpcCheck(); } - shopPlayerSet.clear(); + shopPlayerMap.clear(); } void Npc::onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport) { @@ -643,25 +643,28 @@ bool Npc::getRandomStep(Direction &moveDirection) { return false; } -void Npc::addShopPlayer(std::shared_ptr player) { - shopPlayerSet.insert(player); +void Npc::addShopPlayer(const std::shared_ptr &player) { + if (!player) { + return; + } + shopPlayerMap.try_emplace(player->getID(), player); } -void Npc::removeShopPlayer(std::shared_ptr player) { +void Npc::removeShopPlayer(const std::shared_ptr &player) { if (!player) { return; } - weak::erase(shopPlayerSet, player); + shopPlayerMap.erase(player->getID()); } void Npc::closeAllShopWindows() { - for (auto shopPlayerPtr : shopPlayerSet) { - auto shopPlayer = shopPlayerPtr.lock(); + for (auto &[_, playerPtr] : shopPlayerMap) { + auto shopPlayer = playerPtr.lock(); if (shopPlayer) { shopPlayer->closeShopWindow(); } } - shopPlayerSet.clear(); + shopPlayerMap.clear(); } void Npc::handlePlayerMove(std::shared_ptr player, const Position &newPos) { diff --git a/src/creatures/npcs/npc.hpp b/src/creatures/npcs/npc.hpp index b354e40245c..3af93863fc3 100644 --- a/src/creatures/npcs/npc.hpp +++ b/src/creatures/npcs/npc.hpp @@ -156,8 +156,8 @@ class Npc final : public Creature { internalLight = npcType->info.light; } - void addShopPlayer(std::shared_ptr player); - void removeShopPlayer(std::shared_ptr player); + void addShopPlayer(const std::shared_ptr &player); + void removeShopPlayer(const std::shared_ptr &player); void closeAllShopWindows(); static uint32_t npcAutoID; @@ -175,7 +175,7 @@ class Npc final : public Creature { std::map playerInteractions; - weak::parallel_flat_hash_set shopPlayerSet; + phmap::flat_hash_map> shopPlayerMap; NpcType* npcType; SpawnNpc* spawnNpc = nullptr; diff --git a/src/creatures/players/grouping/guild.cpp b/src/creatures/players/grouping/guild.cpp index 835b54bd3a2..14b59b8e9d5 100644 --- a/src/creatures/players/grouping/guild.cpp +++ b/src/creatures/players/grouping/guild.cpp @@ -12,23 +12,18 @@ #include "creatures/players/grouping/guild.hpp" #include "game/game.hpp" -void Guild::addMember(std::shared_ptr player) { +void Guild::addMember(const std::shared_ptr &player) { membersOnline.push_back(player); for (auto member : getMembersOnline()) { g_game().updatePlayerHelpers(member); } } -void Guild::removeMember(std::shared_ptr player) { +void Guild::removeMember(const std::shared_ptr &player) { // loop over to udpate all members and delete the player from the list - for (auto it = membersOnline.begin(); it != membersOnline.end(); ++it) { - if (auto member = it->lock()) { - if (member == player) { - it = membersOnline.erase(it); - } else { - g_game().updatePlayerHelpers(member); - } - } + membersOnline.remove(player); + for (const auto &member : membersOnline) { + g_game().updatePlayerHelpers(member); } g_game().updatePlayerHelpers(player); diff --git a/src/creatures/players/grouping/guild.hpp b/src/creatures/players/grouping/guild.hpp index 894d63318cf..ee16c469c26 100644 --- a/src/creatures/players/grouping/guild.hpp +++ b/src/creatures/players/grouping/guild.hpp @@ -29,8 +29,8 @@ class Guild : public Bankable { Guild(uint32_t initId, std::string initName) : name(std::move(initName)), id(initId) { } - void addMember(std::shared_ptr player); - void removeMember(std::shared_ptr player); + void addMember(const std::shared_ptr &player); + void removeMember(const std::shared_ptr &player); bool isGuild() { return true; @@ -48,12 +48,8 @@ class Guild : public Bankable { const std::string &getName() const { return name; } - std::vector> getMembersOnline() const { - auto result = std::vector>(membersOnline.size()); - std::transform(membersOnline.begin(), membersOnline.end(), result.begin(), [](const std::weak_ptr &weak) { - return weak.lock(); - }); - return result; + std::list> getMembersOnline() const { + return membersOnline; } uint32_t getMemberCountOnline() const { return membersOnline.size(); @@ -88,7 +84,7 @@ class Guild : public Bankable { } private: - weak::list membersOnline; + std::list> membersOnline; std::vector ranks; std::string name; uint64_t bankBalance = 0; diff --git a/src/lua/global/shared_object.hpp b/src/lua/global/shared_object.hpp index cdd082cc788..62cc26b33f5 100644 --- a/src/lua/global/shared_object.hpp +++ b/src/lua/global/shared_object.hpp @@ -44,120 +44,3 @@ class SharedObject : public std::enable_shared_from_this { return std::dynamic_pointer_cast(source); } }; - -namespace weak { - template - struct Hash { - std::size_t operator()(const std::weak_ptr &wp) const { - auto sp = wp.lock(); - return std::hash>()(sp); - } - }; - - template - struct Equal { - bool operator()(const std::weak_ptr &lhs, const std::weak_ptr &rhs) const { - return lhs.lock() == rhs.lock(); - } - }; - - template - using parallel_flat_hash_set = phmap::parallel_flat_hash_set, Hash, Equal>; - - template - using vector = std::vector>; - - template - using list = std::list>; - - template - typename list::iterator find(const list &lst, const std::shared_ptr &item) { - return std::find_if(lst.begin(), lst.end(), [item](const std::weak_ptr &weak) { - return weak.lock() == item; - }); - } - - template - typename weak::vector::const_iterator find(const weak::vector &vec, const std::shared_ptr &item) { - return std::find_if(vec.cbegin(), vec.cend(), [item](const std::weak_ptr &weak) { - return weak.lock() == item; - }); - } - - template - typename weak::vector::iterator find(weak::vector &vec, const std::shared_ptr &item) { - return std::find_if(vec.begin(), vec.end(), [item](const std::weak_ptr &weak) { - return weak.lock() == item; - }); - } - - template - bool erase(parallel_flat_hash_set &set, const std::shared_ptr &item) { - return set.erase(item) > 0; - } - - template - bool erase(vector &vec, const std::shared_ptr &item) { - auto it = find(vec, item); - if (it != vec.end()) { - vec.erase(it); - return true; - } - return false; - } - - template - bool erase(list &lst, const std::shared_ptr &item) { - auto it = find(lst, item); - if (it != lst.end()) { - lst.erase(it); - return true; - } - return false; - } - - template - std::vector> lock(vector &vec) { - std::vector> result; - result.reserve(vec.size()); - for (auto it = vec.begin(); it != vec.end();) { - if (auto shared = it->lock()) { - result.push_back(shared); - ++it; - } else { - it = vec.erase(it); - } - } - return result; - } - - template - std::vector> lock(list &lst) { - std::vector> result; - result.reserve(lst.size()); - for (auto it = lst.begin(); it != lst.end();) { - if (auto shared = it->lock()) { - result.push_back(shared); - ++it; - } else { - it = lst.erase(it); - } - } - return result; - } - - template - phmap::parallel_flat_hash_set> lock(parallel_flat_hash_set &set) { - phmap::parallel_flat_hash_set> result; - result.reserve(set.size()); - for (auto it = set.begin(); it != set.end();) { - if (auto shared = it->lock()) { - result.insert(shared); - ++it; - } else { - it = set.erase(it); - } - } - return result; - } -} From f60e28668ca22303a7d25707b85b9306e1968687 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sun, 17 Sep 2023 14:48:47 -0700 Subject: [PATCH 23/67] improve: use const refs for player where appropriate --- src/creatures/combat/combat.cpp | 51 +- src/creatures/combat/combat.hpp | 14 +- src/creatures/combat/condition.cpp | 56 +- src/creatures/combat/condition.hpp | 8 +- src/creatures/combat/spells.cpp | 53 +- src/creatures/combat/spells.hpp | 28 +- src/creatures/creature.cpp | 10 +- src/creatures/monsters/monster.cpp | 6 +- src/creatures/npcs/npc.cpp | 26 +- src/creatures/npcs/npc.hpp | 16 +- src/creatures/players/grouping/party.cpp | 40 +- src/creatures/players/grouping/party.hpp | 38 +- .../players/imbuements/imbuements.cpp | 2 +- .../players/imbuements/imbuements.hpp | 2 +- src/creatures/players/management/waitlist.cpp | 6 +- src/creatures/players/management/waitlist.hpp | 6 +- src/creatures/players/player.cpp | 58 +-- src/creatures/players/player.hpp | 34 +- src/creatures/players/wheel/player_wheel.cpp | 14 +- src/game/bank/bank.cpp | 8 +- src/game/bank/bank.hpp | 6 +- src/game/game.cpp | 469 ++++++++--------- src/game/game.hpp | 92 ++-- src/io/functions/iologindata_load_player.cpp | 54 +- src/io/functions/iologindata_load_player.hpp | 54 +- src/io/functions/iologindata_save_player.cpp | 30 +- src/io/functions/iologindata_save_player.hpp | 30 +- src/io/io_bosstiary.cpp | 8 +- src/io/io_bosstiary.hpp | 8 +- src/io/iobestiary.cpp | 22 +- src/io/iobestiary.hpp | 22 +- src/io/iologindata.cpp | 10 +- src/io/iologindata.hpp | 10 +- src/io/ioprey.cpp | 6 +- src/io/ioprey.hpp | 6 +- src/items/bed.cpp | 14 +- src/items/bed.hpp | 14 +- src/items/containers/mailbox/mailbox.cpp | 2 +- src/items/decay/decay.cpp | 2 +- src/items/item.cpp | 2 +- src/items/item.hpp | 2 +- src/items/tile.cpp | 26 +- src/items/tile.hpp | 6 +- src/items/weapons/weapons.cpp | 38 +- src/items/weapons/weapons.hpp | 48 +- src/kv/README.md | 4 +- src/lua/callbacks/creaturecallback.cpp | 2 +- src/lua/callbacks/event_callback.cpp | 52 +- src/lua/callbacks/event_callback.hpp | 52 +- src/lua/creature/actions.cpp | 20 +- src/lua/creature/actions.hpp | 18 +- src/lua/creature/creatureevent.cpp | 18 +- src/lua/creature/creatureevent.hpp | 18 +- src/lua/creature/events.cpp | 50 +- src/lua/creature/events.hpp | 50 +- src/lua/creature/movement.cpp | 6 +- src/lua/creature/movement.hpp | 4 +- src/lua/creature/talkaction.cpp | 6 +- src/lua/creature/talkaction.hpp | 6 +- .../functions/core/game/bank_functions.cpp | 6 +- .../functions/core/game/game_functions.cpp | 4 +- .../functions/core/game/global_functions.cpp | 14 +- .../core/game/modal_window_functions.cpp | 2 +- .../functions/core/game/zone_functions.cpp | 2 +- .../network/network_message_functions.cpp | 4 +- .../creatures/combat/combat_functions.cpp | 2 +- .../creatures/creature_functions.cpp | 6 +- .../creatures/monster/monster_functions.cpp | 2 +- .../functions/creatures/npc/npc_functions.cpp | 6 +- .../creatures/player/guild_functions.cpp | 2 +- .../creatures/player/party_functions.cpp | 18 +- .../creatures/player/player_functions.cpp | 484 +++++++++--------- src/lua/functions/items/item_functions.cpp | 2 +- src/lua/functions/map/house_functions.cpp | 8 +- src/lua/functions/map/position_functions.cpp | 6 +- src/lua/modules/modules.cpp | 4 +- src/lua/modules/modules.hpp | 2 +- src/map/house/house.cpp | 32 +- src/map/house/house.hpp | 22 +- src/map/house/housetile.cpp | 8 +- src/map/map.cpp | 4 +- src/map/utils/astarnodes.cpp | 2 +- src/protobuf/appearances.pb.cc | 300 +++++------ src/protobuf/appearances.pb.h | 52 +- src/protobuf/appearances.proto | 2 +- src/server/network/protocol/protocolgame.cpp | 60 +-- src/server/network/protocol/protocolgame.hpp | 8 +- 87 files changed, 1436 insertions(+), 1391 deletions(-) diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index 10c7b2ee67d..36cdbbb3716 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -19,7 +19,7 @@ #include "creatures/monsters/monsters.hpp" #include "items/weapons/weapons.hpp" -int32_t Combat::getLevelFormula(std::shared_ptr player, const std::shared_ptr wheelSpell, const CombatDamage &damage) const { +int32_t Combat::getLevelFormula(const std::shared_ptr &player, const std::shared_ptr &wheelSpell, const CombatDamage &damage) const { if (!player) { return 0; } @@ -47,7 +47,7 @@ CombatDamage Combat::getCombatDamage(std::shared_ptr creature, std::sh damage.runeSpellName = runeSpellName; // Wheel of destiny std::shared_ptr wheelSpell = nullptr; - std::shared_ptr attackerPlayer = creature ? creature->getPlayer() : nullptr; + const std::shared_ptr &attackerPlayer = creature ? creature->getPlayer() : nullptr; if (attackerPlayer) { wheelSpell = attackerPlayer->wheel()->getCombatDataSpell(damage); } @@ -61,7 +61,7 @@ CombatDamage Combat::getCombatDamage(std::shared_ptr creature, std::sh int32_t min, max; if (creature->getCombatValues(min, max)) { damage.primary.value = normal_random(min, max); - } else if (std::shared_ptr player = creature->getPlayer()) { + } else if (const auto &player = creature->getPlayer()) { if (params.valueCallback) { params.valueCallback->getMinMaxValues(player, damage, params.useCharges); } else if (formulaType == COMBAT_FORMULA_LEVELMAGIC) { @@ -187,8 +187,8 @@ bool Combat::isPlayerCombat(std::shared_ptr target) { return false; } -ReturnValue Combat::canTargetCreature(std::shared_ptr player, std::shared_ptr target) { - if (player == target) { +ReturnValue Combat::canTargetCreature(const std::shared_ptr &player, const std::shared_ptr &target) { + if (!player || !target || player == target) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } @@ -260,7 +260,7 @@ ReturnValue Combat::canDoCombat(std::shared_ptr caster, std::shared_pt return RETURNVALUE_FIRSTGOUPSTAIRS; } - if (std::shared_ptr player = caster->getPlayer()) { + if (const auto &player = caster->getPlayer()) { if (player->hasFlag(PlayerFlags_t::IgnoreProtectionZone)) { return RETURNVALUE_NOERROR; } @@ -274,7 +274,11 @@ bool Combat::isInPvpZone(std::shared_ptr attacker, std::shared_ptrgetZoneType() == ZONE_PVP && target->getZoneType() == ZONE_PVP; } -bool Combat::isProtected(std::shared_ptr attacker, std::shared_ptr target) { +bool Combat::isProtected(const std::shared_ptr &attacker, const std::shared_ptr &target) { + if (!attacker || !target) { + return true; + } + uint32_t protectionLevel = g_configManager().getNumber(PROTECTION_LEVEL); if (target->getLevel() < protectionLevel || attacker->getLevel() < protectionLevel) { return true; @@ -308,7 +312,7 @@ ReturnValue Combat::canDoCombat(std::shared_ptr attacker, std::shared_ if (attacker) { const std::shared_ptr attackerMaster = attacker->getMaster(); - auto targetPlayer = target ? target->getPlayer() : nullptr; + const auto &targetPlayer = target ? target->getPlayer() : nullptr; if (targetPlayer) { if (targetPlayer->hasFlag(PlayerFlags_t::CannotBeAttacked)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; @@ -316,7 +320,7 @@ ReturnValue Combat::canDoCombat(std::shared_ptr attacker, std::shared_ const std::shared_ptr targetPlayerTile = targetPlayer->getTile(); - if (const std::shared_ptr attackerPlayer = attacker->getPlayer()) { + if (const auto &attackerPlayer = attacker->getPlayer()) { if (attackerPlayer->hasFlag(PlayerFlags_t::CannotAttackPlayer)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } @@ -339,7 +343,7 @@ ReturnValue Combat::canDoCombat(std::shared_ptr attacker, std::shared_ } if (attackerMaster) { - if (const std::shared_ptr masterAttackerPlayer = attackerMaster->getPlayer()) { + if (const auto &masterAttackerPlayer = attackerMaster->getPlayer()) { if (masterAttackerPlayer->hasFlag(PlayerFlags_t::CannotAttackPlayer)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } @@ -364,7 +368,7 @@ ReturnValue Combat::canDoCombat(std::shared_ptr attacker, std::shared_ return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE; } - if (const std::shared_ptr attackerPlayer = attacker->getPlayer()) { + if (const auto &attackerPlayer = attacker->getPlayer()) { if (attackerPlayer->hasFlag(PlayerFlags_t::CannotAttackMonster)) { return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE; } @@ -610,7 +614,10 @@ void Combat::CombatHealthFunc(std::shared_ptr caster, std::shared_ptr< } } -CombatDamage Combat::applyImbuementElementalDamage(std::shared_ptr attackerPlayer, std::shared_ptr item, CombatDamage damage) { +CombatDamage Combat::applyImbuementElementalDamage(const std::shared_ptr &attackerPlayer, std::shared_ptr item, CombatDamage damage) { + if (!attackerPlayer) { + return damage; + } if (!item) { return damage; } @@ -662,8 +669,8 @@ void Combat::CombatManaFunc(std::shared_ptr caster, std::shared_ptr player) { - if (player->isImmuneFear()) { +bool Combat::checkFearConditionAffected(const std::shared_ptr &player) { + if (!player || player->isImmuneFear()) { return false; } @@ -861,7 +868,7 @@ void Combat::addDistanceEffect(std::shared_ptr caster, const Position return; } - std::shared_ptr player = caster->getPlayer(); + const auto &player = caster->getPlayer(); if (!player) { return; } @@ -1071,7 +1078,7 @@ void Combat::CombatFunc(std::shared_ptr caster, const Position &origin } // Wheel of destiny get beam affected total - std::shared_ptr casterPlayer = caster ? caster->getPlayer() : nullptr; + const auto &casterPlayer = caster ? caster->getPlayer() : nullptr; uint8_t beamAffectedTotal = casterPlayer ? casterPlayer->wheel()->getBeamAffectedTotal(tmpDamage) : 0; uint8_t beamAffectedCurrent = 0; @@ -1163,7 +1170,7 @@ void Combat::doCombatHealth(std::shared_ptr caster, std::shared_ptrgetPlayer()->getInventoryItem(CONST_SLOT_LEFT); + if (const auto &playerWeapon = caster->getPlayer()->getInventoryItem(CONST_SLOT_LEFT); playerWeapon != nullptr && playerWeapon->getTier()) { double_t fatalChance = playerWeapon->getFatalChance(); double_t randomChance = uniform_random(0, 10000) / 100; @@ -1204,7 +1211,7 @@ void Combat::doCombatHealth(std::shared_ptr caster, const Position &po } // Fatal hit (onslaught) - if (auto playerWeapon = caster->getPlayer()->getInventoryItem(CONST_SLOT_LEFT); + if (const auto &playerWeapon = caster->getPlayer()->getInventoryItem(CONST_SLOT_LEFT); playerWeapon != nullptr && playerWeapon->getTier() > 0) { double_t fatalChance = playerWeapon->getFatalChance(); double_t randomChance = uniform_random(0, 10000) / 100; @@ -1457,7 +1464,7 @@ bool Combat::isValidChainTarget(std::shared_ptr caster, std::shared_pt //**********************************************************// -uint32_t ValueCallback::getMagicLevelSkill(std::shared_ptr player, const CombatDamage &damage) const { +uint32_t ValueCallback::getMagicLevelSkill(const std::shared_ptr &player, const CombatDamage &damage) const { if (!player) { return 0; } @@ -1477,7 +1484,7 @@ uint32_t ValueCallback::getMagicLevelSkill(std::shared_ptr player, const return magicLevelSkill + player->getSpecializedMagicLevel(damage.primary.type, true); } -void ValueCallback::getMinMaxValues(std::shared_ptr player, CombatDamage &damage, bool useCharges) const { +void ValueCallback::getMinMaxValues(const std::shared_ptr &player, CombatDamage &damage, bool useCharges) const { // onGetPlayerMinMaxValues(...) if (!scriptInterface->reserveScriptEnv()) { g_logger().error("[ValueCallback::getMinMaxValues - Player {} formula {}] " @@ -2068,9 +2075,9 @@ void MagicField::onStepInField(const std::shared_ptr &creature) { } } - std::shared_ptr targetPlayer = creature->getPlayer(); + const auto &targetPlayer = creature->getPlayer(); if (targetPlayer) { - const std::shared_ptr attackerPlayer = g_game().getPlayerByID(ownerId); + const auto &attackerPlayer = g_game().getPlayerByID(ownerId); if (attackerPlayer) { if (Combat::isProtected(attackerPlayer, targetPlayer)) { harmfulField = false; diff --git a/src/creatures/combat/combat.hpp b/src/creatures/combat/combat.hpp index 780b1b5eb2c..604f293d3f2 100644 --- a/src/creatures/combat/combat.hpp +++ b/src/creatures/combat/combat.hpp @@ -33,8 +33,8 @@ class ValueCallback final : public CallBack { * @param damage The combat damage information. * @return The magic level skill of the player. */ - uint32_t getMagicLevelSkill(std::shared_ptr player, const CombatDamage &damage) const; - void getMinMaxValues(std::shared_ptr player, CombatDamage &damage, bool useCharges) const; + uint32_t getMagicLevelSkill(const std::shared_ptr &player, const CombatDamage &damage) const; + void getMinMaxValues(const std::shared_ptr &player, CombatDamage &damage, bool useCharges) const; private: formulaType_t type; @@ -271,11 +271,11 @@ class Combat { static void getCombatArea(const Position ¢erPos, const Position &targetPos, const AreaCombat* area, std::forward_list> &list); static bool isInPvpZone(std::shared_ptr attacker, std::shared_ptr target); - static bool isProtected(std::shared_ptr attacker, std::shared_ptr target); + static bool isProtected(const std::shared_ptr &attacker, const std::shared_ptr &target); static bool isPlayerCombat(std::shared_ptr target); static CombatType_t ConditionToDamageType(ConditionType_t type); static ConditionType_t DamageToConditionType(CombatType_t type); - static ReturnValue canTargetCreature(std::shared_ptr attacker, std::shared_ptr target); + static ReturnValue canTargetCreature(const std::shared_ptr &attacker, const std::shared_ptr &target); static ReturnValue canDoCombat(std::shared_ptr caster, std::shared_ptr tile, bool aggressive); static ReturnValue canDoCombat(std::shared_ptr attacker, std::shared_ptr target, bool aggressive); static void postCombatEffects(std::shared_ptr caster, const Position &origin, const Position &pos, const CombatParams ¶ms); @@ -336,7 +336,7 @@ class Combat { static void CombatFunc(std::shared_ptr caster, const Position &origin, const Position &pos, const AreaCombat* area, const CombatParams ¶ms, CombatFunction func, CombatDamage* data); static void CombatHealthFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); - static CombatDamage applyImbuementElementalDamage(std::shared_ptr attackerPlayer, std::shared_ptr item, CombatDamage damage); + static CombatDamage applyImbuementElementalDamage(const std::shared_ptr &attackerPlayer, std::shared_ptr item, CombatDamage damage); static void CombatManaFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* damage); /** * @brief Checks if a fear condition can be applied to a player. @@ -352,7 +352,7 @@ class Combat { * @param player Pointer to the Player object to be checked. * @return true if the fear condition can be applied, false otherwise. */ - static bool checkFearConditionAffected(std::shared_ptr player); + static bool checkFearConditionAffected(const std::shared_ptr &player); static void CombatConditionFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); static void CombatDispelFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); static void CombatNullFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); @@ -367,7 +367,7 @@ class Combat { * @param damage The combat damage. * @return The calculated level formula. */ - int32_t getLevelFormula(std::shared_ptr player, const std::shared_ptr wheelSpell, const CombatDamage &damage) const; + int32_t getLevelFormula(const std::shared_ptr &player, const std::shared_ptr &wheelSpell, const CombatDamage &damage) const; CombatDamage getCombatDamage(std::shared_ptr creature, std::shared_ptr target) const; bool doCombatChain(std::shared_ptr caster, std::shared_ptr target, bool aggressive) const; diff --git a/src/creatures/combat/condition.cpp b/src/creatures/combat/condition.cpp index b4e09da0d58..68802f378bc 100644 --- a/src/creatures/combat/condition.cpp +++ b/src/creatures/combat/condition.cpp @@ -437,7 +437,7 @@ void ConditionAttributes::addCondition(std::shared_ptr creature, const updateCharmChanceModifier(creature); disableDefense = conditionAttrs.disableDefense; - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { updatePercentSkills(player); updateSkills(player); updatePercentStats(player); @@ -541,7 +541,7 @@ bool ConditionAttributes::startCondition(std::shared_ptr creature) { updatePercentIncreases(creature); updateIncreases(creature); updateCharmChanceModifier(creature); - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { updatePercentSkills(player); updateSkills(player); updatePercentStats(player); @@ -551,7 +551,10 @@ bool ConditionAttributes::startCondition(std::shared_ptr creature) { return true; } -void ConditionAttributes::updatePercentStats(std::shared_ptr player) { +void ConditionAttributes::updatePercentStats(const std::shared_ptr &player) { + if (!player) { + return; + } for (int32_t i = STAT_FIRST; i <= STAT_LAST; ++i) { if (statsPercent[i] == 0) { continue; @@ -577,7 +580,10 @@ void ConditionAttributes::updatePercentStats(std::shared_ptr player) { } } -void ConditionAttributes::updateStats(std::shared_ptr player) { +void ConditionAttributes::updateStats(const std::shared_ptr &player) { + if (!player) { + return; + } bool needUpdate = false; for (int32_t i = STAT_FIRST; i <= STAT_LAST; ++i) { @@ -593,7 +599,10 @@ void ConditionAttributes::updateStats(std::shared_ptr player) { } } -void ConditionAttributes::updatePercentSkills(std::shared_ptr player) { +void ConditionAttributes::updatePercentSkills(const std::shared_ptr &player) { + if (!player) { + return; + } for (uint8_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { skills_t skill = static_cast(i); if (skillsPercent[skill] == 0) { @@ -605,7 +614,10 @@ void ConditionAttributes::updatePercentSkills(std::shared_ptr player) { } } -void ConditionAttributes::updateSkills(std::shared_ptr player) { +void ConditionAttributes::updateSkills(const std::shared_ptr &player) { + if (!player) { + return; + } bool needUpdateSkills = false; for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { @@ -694,7 +706,7 @@ bool ConditionAttributes::executeCondition(std::shared_ptr creature, i } void ConditionAttributes::endCondition(std::shared_ptr creature) { - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player) { bool needUpdate = false; @@ -1101,14 +1113,14 @@ bool ConditionRegeneration::startCondition(std::shared_ptr creature) { return false; } - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { player->sendStats(); } return true; } void ConditionRegeneration::endCondition(std::shared_ptr creature) { - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { player->sendStats(); } } @@ -1126,7 +1138,7 @@ void ConditionRegeneration::addCondition(std::shared_ptr creature, con manaGain = conditionRegen.manaGain; } - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { player->sendStats(); } } @@ -1163,7 +1175,7 @@ void ConditionRegeneration::serialize(PropWriteStream &propWriteStream) { bool ConditionRegeneration::executeCondition(std::shared_ptr creature, int32_t interval) { internalHealthTicks += interval; internalManaTicks += interval; - auto player = creature->getPlayer(); + const auto &player = creature->getPlayer(); int32_t PlayerdailyStreak = 0; if (player) { PlayerdailyStreak = player->getStorageValue(STORAGEVALUE_DAILYREWARD); @@ -1245,7 +1257,7 @@ bool ConditionRegeneration::setParam(ConditionParam_t param, int32_t value) { } uint32_t ConditionRegeneration::getHealthTicks(std::shared_ptr creature) const { - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player != nullptr && isBuff) { return healthTicks / g_configManager().getFloat(RATE_SPELL_COOLDOWN); @@ -1255,7 +1267,7 @@ uint32_t ConditionRegeneration::getHealthTicks(std::shared_ptr creatur } uint32_t ConditionRegeneration::getManaTicks(std::shared_ptr creature) const { - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player != nullptr && isBuff) { return manaTicks / g_configManager().getFloat(RATE_SPELL_COOLDOWN); @@ -1276,7 +1288,7 @@ bool ConditionManaShield::startCondition(std::shared_ptr creature) { creature->setManaShield(manaShield); creature->setMaxManaShield(manaShield); - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { player->sendStats(); } @@ -1286,7 +1298,7 @@ bool ConditionManaShield::startCondition(std::shared_ptr creature) { void ConditionManaShield::endCondition(std::shared_ptr creature) { creature->setManaShield(0); creature->setMaxManaShield(0); - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { player->sendStats(); } } @@ -1301,7 +1313,7 @@ void ConditionManaShield::addCondition(std::shared_ptr creature, const creature->setManaShield(manaShield); creature->setMaxManaShield(manaShield); - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { player->sendStats(); } } @@ -1379,7 +1391,7 @@ void ConditionSoul::serialize(PropWriteStream &propWriteStream) { bool ConditionSoul::executeCondition(std::shared_ptr creature, int32_t interval) { internalSoulTicks += interval; - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { if (player->getZoneType() != ZONE_PROTECTION) { if (internalSoulTicks >= soulTicks) { internalSoulTicks = 0; @@ -2053,7 +2065,7 @@ void ConditionFeared::endCondition(std::shared_ptr creature) { /* * After a player is feared there's a 10 seconds before he can feared again. */ - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player) { player->setImmuneFear(); } @@ -2439,7 +2451,7 @@ void ConditionSpellCooldown::addCondition(std::shared_ptr creature, co setTicks(addCondition->getTicks()); if (subId != 0 && ticks > 0) { - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player) { player->sendSpellCooldown(subId, ticks); } @@ -2453,7 +2465,7 @@ bool ConditionSpellCooldown::startCondition(std::shared_ptr creature) } if (subId != 0 && ticks > 0) { - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player) { player->sendSpellCooldown(subId, ticks); } @@ -2470,7 +2482,7 @@ void ConditionSpellGroupCooldown::addCondition(std::shared_ptr creatur setTicks(addCondition->getTicks()); if (subId != 0 && ticks > 0) { - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player) { player->sendSpellGroupCooldown(static_cast(subId), ticks); } @@ -2484,7 +2496,7 @@ bool ConditionSpellGroupCooldown::startCondition(std::shared_ptr creat } if (subId != 0 && ticks > 0) { - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player) { player->sendSpellGroupCooldown(static_cast(subId), ticks); } diff --git a/src/creatures/combat/condition.hpp b/src/creatures/combat/condition.hpp index d2704c4c49d..a99e0721f66 100644 --- a/src/creatures/combat/condition.hpp +++ b/src/creatures/combat/condition.hpp @@ -150,10 +150,10 @@ class ConditionAttributes final : public ConditionGeneric { bool disableDefense = false; - void updatePercentStats(std::shared_ptr player); - void updateStats(std::shared_ptr player); - void updatePercentSkills(std::shared_ptr player); - void updateSkills(std::shared_ptr player); + void updatePercentStats(const std::shared_ptr & player); + void updateStats(const std::shared_ptr & player); + void updatePercentSkills(const std::shared_ptr & player); + void updateSkills(const std::shared_ptr & player); void updateBuffs(std::shared_ptr creature); // 12.72 mechanics diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 46c5ba8f604..255e16a8a73 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -19,7 +19,10 @@ Spells::Spells() = default; Spells::~Spells() = default; -TalkActionResult_t Spells::playerSaySpell(std::shared_ptr player, std::string &words) { +TalkActionResult_t Spells::playerSaySpell(const std::shared_ptr &player, std::string &words) { + if (!player) { + return TALKACTION_FAILED; + } std::string str_words = words; if (player->hasCondition(CONDITION_FEARED)) { @@ -357,8 +360,8 @@ bool CombatSpell::executeCastSpell(std::shared_ptr creature, const Lua return getScriptInterface()->callFunction(2); } -bool Spell::playerSpellCheck(std::shared_ptr player) const { - if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) { +bool Spell::playerSpellCheck(const std::shared_ptr &player) const { + if (!player || player->hasFlag(PlayerFlags_t::CannotUseSpells)) { return false; } @@ -461,7 +464,10 @@ bool Spell::playerSpellCheck(std::shared_ptr player) const { return true; } -bool Spell::playerInstantSpellCheck(std::shared_ptr player, const Position &toPos) const { +bool Spell::playerInstantSpellCheck(const std::shared_ptr &player, const Position &toPos) const { + if (!player) { + return false; + } if (toPos.x == 0xFFFF) { return true; } @@ -501,7 +507,7 @@ bool Spell::playerInstantSpellCheck(std::shared_ptr player, const Positi return true; } -bool Spell::playerRuneSpellCheck(std::shared_ptr player, const Position &toPos) { +bool Spell::playerRuneSpellCheck(const std::shared_ptr &player, const Position &toPos) { if (!playerSpellCheck(player)) { return false; } @@ -559,7 +565,7 @@ bool Spell::playerRuneSpellCheck(std::shared_ptr player, const Position } if (aggressive && needTarget && topVisibleCreature && player->hasSecureMode()) { - const std::shared_ptr targetPlayer = topVisibleCreature->getPlayer(); + const auto &targetPlayer = topVisibleCreature->getPlayer(); if (targetPlayer && targetPlayer != player && player->getSkullClient(targetPlayer) == SKULL_NONE && !Combat::isInPvpZone(player, targetPlayer)) { player->sendCancelMessage(RETURNVALUE_TURNSECUREMODETOATTACKUNMARKEDPLAYERS); g_game().addMagicEffect(player->getPosition(), CONST_ME_POFF); @@ -606,7 +612,10 @@ void Spell::setWheelOfDestinyBoost(WheelSpellBoost_t boost, WheelSpellGrade_t gr } } -void Spell::applyCooldownConditions(std::shared_ptr player) const { +void Spell::applyCooldownConditions(const std::shared_ptr &player) const { + if (!player) { + return; + } WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0; auto rate_cooldown = (int32_t)g_configManager().getFloat(RATE_SPELL_COOLDOWN); @@ -644,7 +653,10 @@ void Spell::applyCooldownConditions(std::shared_ptr player) const { } } -void Spell::postCastSpell(std::shared_ptr player, bool finishedCast /*= true*/, bool payCost /*= true*/) const { +void Spell::postCastSpell(const std::shared_ptr &player, bool finishedCast /*= true*/, bool payCost /*= true*/) const { + if (!player) { + return; + } if (finishedCast) { if (!player->hasFlag(PlayerFlags_t::HasNoExhaustion)) { applyCooldownConditions(player); @@ -664,7 +676,10 @@ void Spell::postCastSpell(std::shared_ptr player, bool finishedCast /*= } } -void Spell::postCastSpell(std::shared_ptr player, uint32_t manaCost, uint32_t soulCost) { +void Spell::postCastSpell(const std::shared_ptr &player, uint32_t manaCost, uint32_t soulCost) { + if (!player) { + return; + } if (manaCost > 0) { player->addManaSpent(manaCost); player->changeMana(-static_cast(manaCost)); @@ -677,7 +692,10 @@ void Spell::postCastSpell(std::shared_ptr player, uint32_t manaCost, uin } } -uint32_t Spell::getManaCost(std::shared_ptr player) const { +uint32_t Spell::getManaCost(const std::shared_ptr &player) const { + if (!player) { + return 0; + } if (mana != 0) { WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); if (getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0) { @@ -707,7 +725,7 @@ uint32_t Spell::getManaCost(std::shared_ptr player) const { return 0; } -bool InstantSpell::playerCastInstant(std::shared_ptr player, std::string ¶m) { +bool InstantSpell::playerCastInstant(const std::shared_ptr &player, std::string ¶m) { if (!playerSpellCheck(player)) { return false; } @@ -901,7 +919,11 @@ bool InstantSpell::executeCastSpell(std::shared_ptr creature, const Lu return getScriptInterface()->callFunction(2); } -bool InstantSpell::canCast(std::shared_ptr player) const { +bool InstantSpell::canCast(const std::shared_ptr &player) const { + if (!player) { + return false; + } + if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) { return false; } @@ -923,7 +945,10 @@ bool InstantSpell::canCast(std::shared_ptr player) const { return false; } -ReturnValue RuneSpell::canExecuteAction(std::shared_ptr player, const Position &toPos) { +ReturnValue RuneSpell::canExecuteAction(const std::shared_ptr &player, const Position &toPos) { + if (!player) { + return RETURNVALUE_NOTPOSSIBLE; + } if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) { return RETURNVALUE_CANNOTUSETHISOBJECT; } @@ -944,7 +969,7 @@ ReturnValue RuneSpell::canExecuteAction(std::shared_ptr player, const Po return RETURNVALUE_NOERROR; } -bool RuneSpell::executeUse(std::shared_ptr player, std::shared_ptr item, const Position &, std::shared_ptr target, const Position &toPosition, bool isHotkey) { +bool RuneSpell::executeUse(const std::shared_ptr &player, std::shared_ptr item, const Position &, std::shared_ptr target, const Position &toPosition, bool isHotkey) { if (!playerRuneSpellCheck(player, toPosition)) { return false; } diff --git a/src/creatures/combat/spells.hpp b/src/creatures/combat/spells.hpp index f95f8aa40b3..90dd57f5f45 100644 --- a/src/creatures/combat/spells.hpp +++ b/src/creatures/combat/spells.hpp @@ -44,7 +44,7 @@ class Spells final : public Scripts { std::shared_ptr getInstantSpellById(uint16_t spellId); - TalkActionResult_t playerSaySpell(std::shared_ptr player, std::string &words); + TalkActionResult_t playerSaySpell(const std::shared_ptr &player, std::string &words); static Position getCasterPosition(std::shared_ptr creature, Direction dir); @@ -73,7 +73,7 @@ class Spells final : public Scripts { constexpr auto g_spells = Spells::getInstance; -using RuneSpellFunction = std::function spell, std::shared_ptr player, const Position &posTo)>; +using RuneSpellFunction = std::function spell, const std::shared_ptr &player, const Position &posTo)>; class BaseSpell { public: @@ -135,14 +135,14 @@ class Spell : public BaseSpell { spellId = id; } - void postCastSpell(std::shared_ptr player, bool finishedCast = true, bool payCost = true) const; - static void postCastSpell(std::shared_ptr player, uint32_t manaCost, uint32_t soulCost); + void postCastSpell(const std::shared_ptr &player, bool finishedCast = true, bool payCost = true) const; + static void postCastSpell(const std::shared_ptr &player, uint32_t manaCost, uint32_t soulCost); [[nodiscard]] virtual bool isInstant() const = 0; [[nodiscard]] bool isLearnable() const { return learnable; } - uint32_t getManaCost(std::shared_ptr player) const; + uint32_t getManaCost(const std::shared_ptr &player) const; [[nodiscard]] uint32_t getSoulCost() const { return soul; } @@ -338,10 +338,10 @@ class Spell : public BaseSpell { } protected: - void applyCooldownConditions(std::shared_ptr player) const; - bool playerSpellCheck(std::shared_ptr player) const; - bool playerInstantSpellCheck(std::shared_ptr player, const Position &toPos) const; - bool playerRuneSpellCheck(std::shared_ptr player, const Position &toPos); + void applyCooldownConditions(const std::shared_ptr &player) const; + bool playerSpellCheck(const std::shared_ptr &player) const; + bool playerInstantSpellCheck(const std::shared_ptr &player, const Position &toPos) const; + bool playerRuneSpellCheck(const std::shared_ptr &player, const Position &toPos); VocSpellMap vocSpellMap; @@ -388,7 +388,7 @@ class InstantSpell final : public Script, public Spell { public: using Script::Script; - virtual bool playerCastInstant(std::shared_ptr player, std::string ¶m); + virtual bool playerCastInstant(const std::shared_ptr &player, std::string ¶m); bool castSpell(std::shared_ptr creature) override; bool castSpell(std::shared_ptr creature, std::shared_ptr target) override; @@ -429,7 +429,7 @@ class InstantSpell final : public Script, public Spell { void setBlockWalls(bool w) { checkLineOfSight = w; } - bool canCast(std::shared_ptr player) const; + bool canCast(const std::shared_ptr &player) const; bool canThrowSpell(std::shared_ptr creature, std::shared_ptr target) const; private: @@ -448,15 +448,15 @@ class RuneSpell final : public Action, public Spell { public: using Action::Action; - ReturnValue canExecuteAction(std::shared_ptr player, const Position &toPos) override; + ReturnValue canExecuteAction(const std::shared_ptr &player, const Position &toPos) override; bool hasOwnErrorHandler() override { return true; } - std::shared_ptr getTarget(std::shared_ptr, std::shared_ptr targetCreature, const Position &, uint8_t) const override { + std::shared_ptr getTarget(const std::shared_ptr &, std::shared_ptr targetCreature, const Position &, uint8_t) const override { return targetCreature; } - bool executeUse(std::shared_ptr player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey) override; + bool executeUse(const std::shared_ptr &player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey) override; bool castSpell(std::shared_ptr creature) override; bool castSpell(std::shared_ptr creature, std::shared_ptr target) override; diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index ab594f8c68a..e8d7a7b9efc 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -173,7 +173,7 @@ void Creature::onCreatureWalk() { if (getNextStep(dir, flags)) { ReturnValue ret = g_game().internalMoveCreature(static_self_cast(), dir, flags); if (ret != RETURNVALUE_NOERROR) { - if (std::shared_ptr player = getPlayer()) { + if (const auto &player = getPlayer()) { player->sendCancelMessage(ret); player->sendCancelWalk(); } @@ -487,7 +487,7 @@ void Creature::onCreatureMove(std::shared_ptr creature, std::shared_pt handleLostSummon(configTeleportSummons); } - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { if (player->isExerciseTraining()) { player->setTraining(false); } @@ -650,7 +650,7 @@ void Creature::onDeath() { if (attacker != getCreature()) { uint64_t gainExp = getGainedExperience(attacker); - if (std::shared_ptr attackerPlayer = attacker->getPlayer()) { + if (const auto &attackerPlayer = attacker->getPlayer()) { attackerPlayer->removeAttacked(getPlayer()); Party* party = attackerPlayer->getParty(); @@ -739,7 +739,7 @@ bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared corpse->startDecaying(); bool corpses = corpse->isRewardCorpse() || (corpse->getID() == ITEM_MALE_CORPSE || corpse->getID() == ITEM_FEMALE_CORPSE); if (corpse->getContainer() && mostDamageCreature && mostDamageCreature->getPlayer() && !corpses) { - auto player = mostDamageCreature->getPlayer(); + const auto &player = mostDamageCreature->getPlayer(); std::ostringstream lootMessage; lootMessage << "Loot of " << getNameDescription() << ": " << corpse->getContainer()->getContentDescription(player->getProtocolVersion() < 1200); auto suffix = corpse->getContainer()->getAttribute(ItemAttribute_t::LOOTMESSAGE_SUFFIX); @@ -1806,7 +1806,7 @@ void Creature::iconChanged() { continue; } - auto player = spectator->getPlayer(); + const auto &player = spectator->getPlayer(); if (player) { player->sendCreatureIcon(getCreature()); } diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index efe022d9d93..ee929e6f986 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -386,7 +386,7 @@ void Monster::onCreatureEnter(std::shared_ptr creature) { bool Monster::isFriend(std::shared_ptr creature) const { if (isSummon() && getMaster()->getPlayer()) { - std::shared_ptr masterPlayer = getMaster()->getPlayer(); + const auto &masterPlayer = getMaster()->getPlayer(); std::shared_ptr tmpPlayer = nullptr; if (creature->getPlayer()) { @@ -620,7 +620,7 @@ BlockType_t Monster::blockHit(std::shared_ptr attacker, CombatType_t c } // Wheel of destiny - std::shared_ptr player = attacker ? attacker->getPlayer() : nullptr; + const auto &player = attacker ? attacker->getPlayer() : nullptr; if (player && player->wheel()->getInstant("Ballistic Mastery")) { elementMod -= player->wheel()->checkElementSensitiveReduction(combatType); } @@ -2048,7 +2048,7 @@ bool Monster::challengeCreature(std::shared_ptr creature, int targetCh challengeFocusDuration = targetChangeCooldown; targetChangeTicks = 0; // Wheel of destiny - std::shared_ptr player = creature ? creature->getPlayer() : nullptr; + const auto &player = creature ? creature->getPlayer() : nullptr; if (player && !player->isRemoved()) { player->wheel()->healIfBattleHealingActive(); } diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index b8775ee148a..e38d999688b 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -72,7 +72,7 @@ bool Npc::canInteract(const Position &pos, uint32_t range /* = 4 */) { void Npc::onCreatureAppear(std::shared_ptr creature, bool isLogin) { Creature::onCreatureAppear(creature, isLogin); - if (auto player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { onPlayerAppear(player); } @@ -102,7 +102,7 @@ void Npc::onRemoveCreature(std::shared_ptr creature, bool isLogout) { return; } - if (auto player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { onPlayerDisappear(player); } @@ -134,7 +134,7 @@ void Npc::onCreatureMove(std::shared_ptr creature, std::shared_ptrgetPlayer()) { + if (const auto &player = creature->getPlayer()) { handlePlayerMove(player, newPos); } } @@ -147,7 +147,7 @@ void Npc::manageIdle() { } } -void Npc::onPlayerAppear(std::shared_ptr player) { +void Npc::onPlayerAppear(const std::shared_ptr &player) { if (player->hasFlag(PlayerFlags_t::IgnoredByNpcs) || playerSpectators.contains(player)) { return; } @@ -155,7 +155,7 @@ void Npc::onPlayerAppear(std::shared_ptr player) { manageIdle(); } -void Npc::onPlayerDisappear(std::shared_ptr player) { +void Npc::onPlayerDisappear(const std::shared_ptr &player) { removePlayerInteraction(player); if (!player->hasFlag(PlayerFlags_t::IgnoredByNpcs) && playerSpectators.contains(player)) { playerSpectators.erase(player); @@ -231,7 +231,7 @@ void Npc::onThink(uint32_t interval) { } } -void Npc::onPlayerBuyItem(std::shared_ptr player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore, bool inBackpacks) { +void Npc::onPlayerBuyItem(const std::shared_ptr &player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore, bool inBackpacks) { if (player == nullptr) { g_logger().error("[Npc::onPlayerBuyItem] - Player is nullptr"); return; @@ -304,13 +304,13 @@ void Npc::onPlayerBuyItem(std::shared_ptr player, uint16_t itemId, uint8 } } -void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore) { +void Npc::onPlayerSellItem(const std::shared_ptr &player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore) { uint64_t totalPrice = 0; onPlayerSellItem(player, itemId, subType, amount, ignore, totalPrice); } void Npc::onPlayerSellAllLoot(uint32_t playerId, uint16_t itemId, bool ignore, uint64_t totalPrice) { - std::shared_ptr player = g_game().getPlayerByID(playerId); + const auto &player = g_game().getPlayerByID(playerId); if (!player) { return; } @@ -359,7 +359,7 @@ void Npc::onPlayerSellAllLoot(uint32_t playerId, uint16_t itemId, bool ignore, u } } -void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore, uint64_t &totalPrice, std::shared_ptr parent /*= nullptr*/) { +void Npc::onPlayerSellItem(const std::shared_ptr &player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore, uint64_t &totalPrice, std::shared_ptr parent /*= nullptr*/) { if (!player) { return; } @@ -441,7 +441,7 @@ void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint } } -void Npc::onPlayerCheckItem(std::shared_ptr player, uint16_t itemId, uint8_t subType) { +void Npc::onPlayerCheckItem(const std::shared_ptr &player, uint16_t itemId, uint8_t subType) { if (!player) { return; } @@ -462,7 +462,7 @@ void Npc::onPlayerCheckItem(std::shared_ptr player, uint16_t itemId, uin } void Npc::onPlayerCloseChannel(std::shared_ptr creature) { - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (!player) { return; } @@ -583,7 +583,7 @@ void Npc::setPlayerInteraction(uint32_t playerId, uint16_t topicId /*= 0*/) { playerInteractions[playerId] = topicId; } -void Npc::removePlayerInteraction(std::shared_ptr player) { +void Npc::removePlayerInteraction(const std::shared_ptr &player) { if (playerInteractions.contains(player->getID())) { playerInteractions.erase(player->getID()); player->closeShopWindow(true); @@ -667,7 +667,7 @@ void Npc::closeAllShopWindows() { shopPlayerMap.clear(); } -void Npc::handlePlayerMove(std::shared_ptr player, const Position &newPos) { +void Npc::handlePlayerMove(const std::shared_ptr &player, const Position &newPos) { if (!canInteract(newPos)) { removePlayerInteraction(player); } diff --git a/src/creatures/npcs/npc.hpp b/src/creatures/npcs/npc.hpp index 3af93863fc3..91544b4a31f 100644 --- a/src/creatures/npcs/npc.hpp +++ b/src/creatures/npcs/npc.hpp @@ -117,7 +117,7 @@ class Npc final : public Creature { } void setPlayerInteraction(uint32_t playerId, uint16_t topicId = 0); - void removePlayerInteraction(std::shared_ptr player); + void removePlayerInteraction(const std::shared_ptr &player); void resetPlayerInteractions(); bool isInteractingWithPlayer(uint32_t playerId) { @@ -140,11 +140,11 @@ class Npc final : public Creature { void onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport) override; void onCreatureSay(std::shared_ptr creature, SpeakClasses type, const std::string &text) override; void onThink(uint32_t interval) override; - void onPlayerBuyItem(std::shared_ptr player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore, bool inBackpacks); + void onPlayerBuyItem(const std::shared_ptr &player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore, bool inBackpacks); void onPlayerSellAllLoot(uint32_t playerId, uint16_t itemid, bool ignore, uint64_t totalPrice); - void onPlayerSellItem(std::shared_ptr player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore); - void onPlayerSellItem(std::shared_ptr player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore, uint64_t &totalPrice, std::shared_ptr parent = nullptr); - void onPlayerCheckItem(std::shared_ptr player, uint16_t itemid, uint8_t count); + void onPlayerSellItem(const std::shared_ptr &player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore); + void onPlayerSellItem(const std::shared_ptr &player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore, uint64_t &totalPrice, std::shared_ptr parent = nullptr); + void onPlayerCheckItem(const std::shared_ptr &player, uint16_t itemid, uint8_t count); void onPlayerCloseChannel(std::shared_ptr creature); void onPlacedCreature() override; @@ -194,10 +194,10 @@ class Npc final : public Creature { friend class LuaScriptInterface; friend class Map; - void onPlayerAppear(std::shared_ptr player); - void onPlayerDisappear(std::shared_ptr player); + void onPlayerAppear(const std::shared_ptr &player); + void onPlayerDisappear(const std::shared_ptr &player); void manageIdle(); - void handlePlayerMove(std::shared_ptr player, const Position &newPos); + void handlePlayerMove(const std::shared_ptr &player, const Position &newPos); void loadPlayerSpectators(); }; diff --git a/src/creatures/players/grouping/party.cpp b/src/creatures/players/grouping/party.cpp index 9eff4a76786..56d34a4a0dd 100644 --- a/src/creatures/players/grouping/party.cpp +++ b/src/creatures/players/grouping/party.cpp @@ -15,7 +15,7 @@ #include "lua/callbacks/event_callback.hpp" #include "lua/callbacks/events_callbacks.hpp" -Party::Party(std::shared_ptr initLeader) : +Party::Party(const std::shared_ptr &initLeader) : m_leader(initLeader) { initLeader->setParty(this); if (g_configManager().getBoolean(PARTY_AUTO_SHARE_EXPERIENCE)) { @@ -76,7 +76,7 @@ void Party::disband() { membersData.clear(); } -bool Party::leaveParty(std::shared_ptr player) { +bool Party::leaveParty(const std::shared_ptr &player) { if (!player) { return false; } @@ -162,7 +162,7 @@ bool Party::leaveParty(std::shared_ptr player) { return true; } -bool Party::passPartyLeadership(std::shared_ptr player) { +bool Party::passPartyLeadership(const std::shared_ptr &player) { auto leader = getLeader(); if (!leader || !player || leader == player || player->getParty() != this) { return false; @@ -415,7 +415,7 @@ const char* Party::getSharedExpReturnMessage(SharedExpStatus_t value) { } } -bool Party::setSharedExperience(std::shared_ptr player, bool newSharedExpActive, bool silent /*= false*/) { +bool Party::setSharedExperience(const std::shared_ptr &player, bool newSharedExpActive, bool silent /*= false*/) { auto leader = getLeader(); if (!player || leader != player) { return false; @@ -459,11 +459,11 @@ void Party::shareExperience(uint64_t experience, std::shared_ptr targe leader->onGainSharedExperience(shareExperience, target); } -bool Party::canUseSharedExperience(std::shared_ptr player) { +bool Party::canUseSharedExperience(const std::shared_ptr &player) { return getMemberSharedExperienceStatus(player) == SHAREDEXP_OK; } -SharedExpStatus_t Party::getMemberSharedExperienceStatus(std::shared_ptr player) { +SharedExpStatus_t Party::getMemberSharedExperienceStatus(const std::shared_ptr &player) { auto leader = getLeader(); if (!leader) { return SHAREDEXP_EMPTYPARTY; @@ -527,7 +527,7 @@ uint32_t Party::getMaxLevel() { return static_cast(std::floor((static_cast(getLowestLevel()) * 3) / 2)); } -bool Party::isPlayerActive(std::shared_ptr player) { +bool Party::isPlayerActive(const std::shared_ptr &player) { auto it = ticksMap.find(player->getID()); if (it == ticksMap.end()) { return false; @@ -556,14 +556,14 @@ SharedExpStatus_t Party::getSharedExperienceStatus() { return SHAREDEXP_OK; } -void Party::updatePlayerTicks(std::shared_ptr player, uint32_t points) { +void Party::updatePlayerTicks(const std::shared_ptr &player, uint32_t points) { if (points != 0 && !player->hasFlag(PlayerFlags_t::NotGainInFight)) { ticksMap[player->getID()] = OTSYS_TIME(); updateSharedExperience(); } } -void Party::clearPlayerPoints(std::shared_ptr player) { +void Party::clearPlayerPoints(const std::shared_ptr &player) { auto it = ticksMap.find(player->getID()); if (it != ticksMap.end()) { ticksMap.erase(it); @@ -577,13 +577,13 @@ bool Party::canOpenCorpse(uint32_t ownerId) const { return false; } - if (std::shared_ptr player = g_game().getPlayerByID(ownerId)) { + if (const auto &player = g_game().getPlayerByID(ownerId)) { return leader->getID() == ownerId || player->getParty() == this; } return false; } -void Party::showPlayerStatus(std::shared_ptr player, std::shared_ptr member, bool showStatus) { +void Party::showPlayerStatus(const std::shared_ptr &player, const std::shared_ptr &member, bool showStatus) { player->sendPartyCreatureShowStatus(member, showStatus); member->sendPartyCreatureShowStatus(player, showStatus); if (showStatus) { @@ -609,7 +609,7 @@ void Party::showPlayerStatus(std::shared_ptr player, std::shared_ptr player) { +void Party::updatePlayerStatus(const std::shared_ptr &player) { auto leader = getLeader(); if (!leader) { return; @@ -632,7 +632,7 @@ void Party::updatePlayerStatus(std::shared_ptr player) { } } -void Party::updatePlayerStatus(std::shared_ptr player, const Position &oldPos, const Position &newPos) { +void Party::updatePlayerStatus(const std::shared_ptr &player, const Position &oldPos, const Position &newPos) { auto leader = getLeader(); if (!leader) { return; @@ -660,7 +660,7 @@ void Party::updatePlayerStatus(std::shared_ptr player, const Position &o } } -void Party::updatePlayerHealth(std::shared_ptr player, std::shared_ptr target, uint8_t healthPercent) { +void Party::updatePlayerHealth(const std::shared_ptr &player, std::shared_ptr target, uint8_t healthPercent) { auto leader = getLeader(); if (!leader) { return; @@ -682,7 +682,7 @@ void Party::updatePlayerHealth(std::shared_ptr player, std::shared_ptr player, uint8_t manaPercent) { +void Party::updatePlayerMana(const std::shared_ptr &player, uint8_t manaPercent) { auto leader = getLeader(); if (!leader) { return; @@ -701,7 +701,7 @@ void Party::updatePlayerMana(std::shared_ptr player, uint8_t manaPercent } } -void Party::updatePlayerVocation(std::shared_ptr player) { +void Party::updatePlayerVocation(const std::shared_ptr &player) { auto leader = getLeader(); if (!leader) { return; @@ -733,7 +733,7 @@ void Party::updateTrackerAnalyzer() { leader->updatePartyTrackerAnalyzer(); } -void Party::addPlayerLoot(std::shared_ptr player, std::shared_ptr item) { +void Party::addPlayerLoot(const std::shared_ptr &player, std::shared_ptr item) { auto leader = getLeader(); if (!leader) { return; @@ -761,7 +761,7 @@ void Party::addPlayerLoot(std::shared_ptr player, std::shared_ptr updateTrackerAnalyzer(); } -void Party::addPlayerSupply(std::shared_ptr player, std::shared_ptr item) { +void Party::addPlayerSupply(const std::shared_ptr &player, std::shared_ptr item) { auto leader = getLeader(); if (!leader) { return; @@ -788,7 +788,7 @@ void Party::addPlayerSupply(std::shared_ptr player, std::shared_ptr player, uint64_t amount) { +void Party::addPlayerDamage(const std::shared_ptr &player, uint64_t amount) { PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); @@ -799,7 +799,7 @@ void Party::addPlayerDamage(std::shared_ptr player, uint64_t amount) { updateTrackerAnalyzer(); } -void Party::addPlayerHealing(std::shared_ptr player, uint64_t amount) { +void Party::addPlayerHealing(const std::shared_ptr &player, uint64_t amount) { PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); diff --git a/src/creatures/players/grouping/party.hpp b/src/creatures/players/grouping/party.hpp index d6c0e9ea6bc..3d8ecfe343f 100644 --- a/src/creatures/players/grouping/party.hpp +++ b/src/creatures/players/grouping/party.hpp @@ -26,7 +26,7 @@ class Party; class Party { public: - explicit Party(std::shared_ptr leader); + explicit Party(const std::shared_ptr & leader); std::shared_ptr getLeader() const { return m_leader.lock(); @@ -48,8 +48,8 @@ class Party { bool invitePlayer(const std::shared_ptr &player); bool joinParty(const std::shared_ptr &player); void revokeInvitation(const std::shared_ptr &player); - bool passPartyLeadership(std::shared_ptr player); - bool leaveParty(std::shared_ptr player); + bool passPartyLeadership(const std::shared_ptr & player); + bool leaveParty(const std::shared_ptr & player); bool removeInvite(const std::shared_ptr &player, bool removeFromPlayer = true); @@ -62,32 +62,32 @@ class Party { bool canOpenCorpse(uint32_t ownerId) const; void shareExperience(uint64_t experience, std::shared_ptr target = nullptr); - bool setSharedExperience(std::shared_ptr player, bool sharedExpActive, bool silent = false); + bool setSharedExperience(const std::shared_ptr & player, bool sharedExpActive, bool silent = false); bool isSharedExperienceActive() const { return sharedExpActive; } bool isSharedExperienceEnabled() const { return sharedExpEnabled; } - bool canUseSharedExperience(std::shared_ptr player); - SharedExpStatus_t getMemberSharedExperienceStatus(std::shared_ptr player); + bool canUseSharedExperience(const std::shared_ptr & player); + SharedExpStatus_t getMemberSharedExperienceStatus(const std::shared_ptr & player); void updateSharedExperience(); - void updatePlayerTicks(std::shared_ptr player, uint32_t points); - void clearPlayerPoints(std::shared_ptr player); + void updatePlayerTicks(const std::shared_ptr & player, uint32_t points); + void clearPlayerPoints(const std::shared_ptr & player); - void showPlayerStatus(std::shared_ptr player, std::shared_ptr member, bool showStatus); - void updatePlayerStatus(std::shared_ptr player); - void updatePlayerStatus(std::shared_ptr player, const Position &oldPos, const Position &newPos); - void updatePlayerHealth(std::shared_ptr player, std::shared_ptr target, uint8_t healthPercent); - void updatePlayerMana(std::shared_ptr player, uint8_t manaPercent); - void updatePlayerVocation(std::shared_ptr player); + void showPlayerStatus(const std::shared_ptr & player, const std::shared_ptr & member, bool showStatus); + void updatePlayerStatus(const std::shared_ptr & player); + void updatePlayerStatus(const std::shared_ptr & player, const Position &oldPos, const Position &newPos); + void updatePlayerHealth(const std::shared_ptr & player, std::shared_ptr target, uint8_t healthPercent); + void updatePlayerMana(const std::shared_ptr & player, uint8_t manaPercent); + void updatePlayerVocation(const std::shared_ptr & player); void updateTrackerAnalyzer(); - void addPlayerLoot(std::shared_ptr player, std::shared_ptr item); - void addPlayerSupply(std::shared_ptr player, std::shared_ptr item); - void addPlayerDamage(std::shared_ptr player, uint64_t amount); - void addPlayerHealing(std::shared_ptr player, uint64_t amount); + void addPlayerLoot(const std::shared_ptr & player, std::shared_ptr item); + void addPlayerSupply(const std::shared_ptr & player, std::shared_ptr item); + void addPlayerDamage(const std::shared_ptr & player, uint64_t amount); + void addPlayerHealing(const std::shared_ptr & player, uint64_t amount); void switchAnalyzerPriceType(); void resetAnalyzer(); void reloadPrices(); @@ -115,7 +115,7 @@ class Party { private: const char* getSharedExpReturnMessage(SharedExpStatus_t value); - bool isPlayerActive(std::shared_ptr player); + bool isPlayerActive(const std::shared_ptr & player); SharedExpStatus_t getSharedExperienceStatus(); uint32_t getHighestLevel(); uint32_t getLowestLevel(); diff --git a/src/creatures/players/imbuements/imbuements.cpp b/src/creatures/players/imbuements/imbuements.cpp index 2d27d15bb3a..1c2d1c00ea9 100644 --- a/src/creatures/players/imbuements/imbuements.cpp +++ b/src/creatures/players/imbuements/imbuements.cpp @@ -336,7 +336,7 @@ CategoryImbuement* Imbuements::getCategoryByID(uint16_t id) { return categoryImbuements != categoriesImbuement.end() ? &*categoryImbuements : nullptr; } -std::vector Imbuements::getImbuements(std::shared_ptr player, std::shared_ptr item) { +std::vector Imbuements::getImbuements(const std::shared_ptr &player, std::shared_ptr item) { std::vector imbuements; for (auto &[key, value] : imbuementMap) { diff --git a/src/creatures/players/imbuements/imbuements.hpp b/src/creatures/players/imbuements/imbuements.hpp index 69c5219a0d8..ee9bd3d7db3 100644 --- a/src/creatures/players/imbuements/imbuements.hpp +++ b/src/creatures/players/imbuements/imbuements.hpp @@ -60,7 +60,7 @@ class Imbuements { BaseImbuement* getBaseByID(uint16_t id); CategoryImbuement* getCategoryByID(uint16_t id); - std::vector getImbuements(std::shared_ptr player, std::shared_ptr item); + std::vector getImbuements(const std::shared_ptr &player, std::shared_ptr item); protected: friend class Imbuement; diff --git a/src/creatures/players/management/waitlist.cpp b/src/creatures/players/management/waitlist.cpp index ff1ad2b00bd..ab4e4d80d80 100644 --- a/src/creatures/players/management/waitlist.cpp +++ b/src/creatures/players/management/waitlist.cpp @@ -59,7 +59,7 @@ std::size_t WaitingList::getTime(std::size_t slot) { } } -bool WaitingList::clientLogin(std::shared_ptr player) { +bool WaitingList::clientLogin(const std::shared_ptr &player) { if (player->hasFlag(PlayerFlags_t::CanAlwaysLogin) || player->getAccountType() >= account::ACCOUNT_TYPE_GAMEMASTER) { return true; } @@ -85,7 +85,7 @@ bool WaitingList::clientLogin(std::shared_ptr player) { return false; } -void WaitingList::addPlayerToList(std::shared_ptr player) { +void WaitingList::addPlayerToList(const std::shared_ptr &player) { auto it = info->playerReferences.find(player->getGUID()); if (it != info->playerReferences.end()) { std::size_t slot; @@ -111,7 +111,7 @@ void WaitingList::addPlayerToList(std::shared_ptr player) { } } -std::size_t WaitingList::getClientSlot(std::shared_ptr player) { +std::size_t WaitingList::getClientSlot(const std::shared_ptr &player) { auto it = info->playerReferences.find(player->getGUID()); if (it == info->playerReferences.end()) { return 0; diff --git a/src/creatures/players/management/waitlist.hpp b/src/creatures/players/management/waitlist.hpp index 28b65c7cad0..5a659100d43 100644 --- a/src/creatures/players/management/waitlist.hpp +++ b/src/creatures/players/management/waitlist.hpp @@ -34,13 +34,13 @@ class WaitingList { public: WaitingList(); static WaitingList &getInstance(); - bool clientLogin(std::shared_ptr player); - std::size_t getClientSlot(std::shared_ptr player); + bool clientLogin(const std::shared_ptr & player); + std::size_t getClientSlot(const std::shared_ptr & player); static std::size_t getTime(std::size_t slot); private: void cleanupList(WaitList &list); std::size_t getTimeout(std::size_t slot); - void addPlayerToList(std::shared_ptr player); + void addPlayerToList(const std::shared_ptr & player); std::unique_ptr info; }; diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index aa9180921f7..2fe1ebcdc6e 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -917,7 +917,7 @@ bool Player::canWalkthrough(std::shared_ptr creature) { return true; } - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); std::shared_ptr monster = creature->getMonster(); std::shared_ptr npc = creature->getNpc(); if (monster) { @@ -938,7 +938,7 @@ bool Player::canWalkthrough(std::shared_ptr creature) { return false; } - std::shared_ptr thisPlayer = getPlayer(); + const auto &thisPlayer = getPlayer(); if ((OTSYS_TIME() - lastWalkthroughAttempt) > 2000) { thisPlayer->setLastWalkthroughAttempt(OTSYS_TIME()); return false; @@ -973,7 +973,7 @@ bool Player::canWalkthroughEx(std::shared_ptr creature) { return true; } - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); std::shared_ptr npc = creature->getNpc(); if (player) { std::shared_ptr playerTile = player->getTile(); @@ -2539,7 +2539,7 @@ void Player::death(std::shared_ptr lastHitCreature) { for (const auto &it : damageMap) { CountBlock_t cb = it.second; if ((OTSYS_TIME() - cb.ticks) <= inFightTicks) { - std::shared_ptr damageDealer = g_game().getPlayerByID(it.first); + const auto &damageDealer = g_game().getPlayerByID(it.first); if (damageDealer) { playerDmg += cb.total; sumLevels += damageDealer->getLevel(); @@ -2764,7 +2764,7 @@ bool Player::spawn() { continue; } - if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendCreatureAppear(static_self_cast(), pos, true); } @@ -2808,10 +2808,10 @@ void Player::despawn() { continue; } - if (const auto player = spectator->getPlayer()) { + if (const auto &player = spectator->getPlayer()) { oldStackPosVector.push_back(player->canSeeCreature(static_self_cast()) ? tile->getStackposOfCreature(player, getPlayer()) : -1); } - if (auto player = spectator->getPlayer()) { + if (const auto &player = spectator->getPlayer()) { player->sendRemoveTileThing(tile->getPosition(), oldStackPosVector[i++]); } @@ -2901,7 +2901,7 @@ void Player::removePlayer(bool displayEffect, bool forced /*= true*/) { } } -void Player::notifyStatusChange(std::shared_ptr loginPlayer, VipStatus_t status, bool message) { +void Player::notifyStatusChange(const std::shared_ptr &loginPlayer, VipStatus_t status, bool message) { if (!client) { return; } @@ -4253,7 +4253,7 @@ void Player::doAttacking(uint32_t) { uint64_t Player::getGainedExperience(std::shared_ptr attacker) const { if (g_configManager().getBoolean(EXPERIENCE_FROM_PLAYERS)) { - auto attackerPlayer = attacker->getPlayer(); + const auto &attackerPlayer = attacker->getPlayer(); if (attackerPlayer && attackerPlayer.get() != this && skillLoss && std::abs(static_cast(attackerPlayer->getLevel() - level)) <= g_configManager().getNumber(EXP_FROM_PLAYERS_LEVEL_RANGE)) { return std::max(0, std::floor(getLostExperience() * getDamageRatio(attacker) * 0.75)); } @@ -4469,7 +4469,7 @@ void Player::onAttackedCreature(std::shared_ptr target) { return; } - auto targetPlayer = target->getPlayer(); + const auto &targetPlayer = target->getPlayer(); if (targetPlayer && !isPartner(targetPlayer) && !isGuildMate(targetPlayer)) { if (!pzLocked && g_game().getWorldType() == WORLD_TYPE_PVP_ENFORCED) { pzLocked = true; @@ -4546,7 +4546,7 @@ void Player::onTargetCreatureGainHealth(std::shared_ptr target, int32_ if (isPartner(tmpPlayer) && (tmpPlayer != getPlayer())) { tmpPlayer = target->getPlayer(); } else if (std::shared_ptr targetMaster = target->getMaster()) { - if (std::shared_ptr targetMasterPlayer = targetMaster->getPlayer()) { + if (const auto &targetMasterPlayer = targetMaster->getPlayer()) { tmpPlayer = targetMasterPlayer; } } @@ -4566,7 +4566,7 @@ bool Player::onKilledCreature(std::shared_ptr target, bool lastHit /* Creature::onKilledCreature(target, lastHit); - if (auto targetPlayer = target->getPlayer()) { + if (const auto &targetPlayer = target->getPlayer()) { if (targetPlayer && targetPlayer->getZoneType() == ZONE_PVP) { targetPlayer->setDropLoot(false); targetPlayer->setSkillLoss(false); @@ -4576,7 +4576,7 @@ bool Player::onKilledCreature(std::shared_ptr target, bool lastHit /* for (auto &kill : targetPlayer->unjustifiedKills) { if (kill.target == getGUID() && kill.unavenged) { kill.unavenged = false; - auto it = attackedSet.find(targetPlayer->guid); + const auto &it = attackedSet.find(targetPlayer->guid); attackedSet.erase(it); break; } @@ -4596,7 +4596,7 @@ bool Player::onKilledCreature(std::shared_ptr target, bool lastHit /* } else if (std::shared_ptr monster = target->getMonster()) { // Access to the monster's map damage to check if the player attacked it for (auto [playerId, damage] : monster->getDamageMap()) { - auto damagePlayer = g_game().getPlayerByID(playerId); + const auto &damagePlayer = g_game().getPlayerByID(playerId); if (!damagePlayer) { continue; } @@ -4924,7 +4924,7 @@ Skulls_t Player::getSkullClient(std::shared_ptr creature) { return SKULL_NONE; } - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player && player->getSkull() == SKULL_NONE) { if (player.get() == this) { for (const auto &kill : unjustifiedKills) { @@ -4949,7 +4949,7 @@ Skulls_t Player::getSkullClient(std::shared_ptr creature) { return Creature::getSkullClient(creature); } -bool Player::hasKilled(std::shared_ptr player) const { +bool Player::hasKilled(const std::shared_ptr &player) const { for (const auto &kill : unjustifiedKills) { if (kill.target == player->getGUID() && (time(nullptr) - kill.time) < g_configManager().getNumber(ORANGE_SKULL_DURATION) * 24 * 60 * 60 && kill.unavenged) { return true; @@ -4959,7 +4959,7 @@ bool Player::hasKilled(std::shared_ptr player) const { return false; } -bool Player::hasAttacked(std::shared_ptr attacked) const { +bool Player::hasAttacked(const std::shared_ptr &attacked) const { if (hasFlag(PlayerFlags_t::NotGainInFight) || !attacked) { return false; } @@ -4967,7 +4967,7 @@ bool Player::hasAttacked(std::shared_ptr attacked) const { return attackedSet.find(attacked->guid) != attackedSet.end(); } -void Player::addAttacked(std::shared_ptr attacked) { +void Player::addAttacked(const std::shared_ptr &attacked) { if (hasFlag(PlayerFlags_t::NotGainInFight) || !attacked || attacked == getPlayer()) { return; } @@ -4975,7 +4975,7 @@ void Player::addAttacked(std::shared_ptr attacked) { attackedSet.insert(attacked->guid); } -void Player::removeAttacked(std::shared_ptr attacked) { +void Player::removeAttacked(const std::shared_ptr &attacked) { if (!attacked || attacked == getPlayer()) { return; } @@ -4990,7 +4990,7 @@ void Player::clearAttacked() { attackedSet.clear(); } -void Player::addUnjustifiedDead(std::shared_ptr attacked) { +void Player::addUnjustifiedDead(const std::shared_ptr &attacked) { if (hasFlag(PlayerFlags_t::NotGainInFight) || attacked == getPlayer() || g_game().getWorldType() == WORLD_TYPE_PVP_ENFORCED) { return; } @@ -5112,7 +5112,7 @@ bool Player::hasLearnedInstantSpell(const std::string &spellName) const { return false; } -bool Player::isInWar(std::shared_ptr player) const { +bool Player::isInWar(const std::shared_ptr &player) const { if (!player || !guild) { return false; } @@ -5391,7 +5391,7 @@ void Player::setTransferableTibiaCoins(int32_t v) { coinTransferableBalance = v; } -PartyShields_t Player::getPartyShield(std::shared_ptr player) { +PartyShields_t Player::getPartyShield(const std::shared_ptr &player) { if (!player) { return SHIELD_NONE; } @@ -5445,28 +5445,28 @@ PartyShields_t Player::getPartyShield(std::shared_ptr player) { return SHIELD_NONE; } -bool Player::isInviting(std::shared_ptr player) const { +bool Player::isInviting(const std::shared_ptr &player) const { if (!player || !party || party->getLeader().get() != this) { return false; } return party->isPlayerInvited(player); } -bool Player::isPartner(std::shared_ptr player) const { +bool Player::isPartner(const std::shared_ptr &player) const { if (!player || !party || player.get() == this) { return false; } return party == player->party; } -bool Player::isGuildMate(std::shared_ptr player) const { +bool Player::isGuildMate(const std::shared_ptr &player) const { if (!player || !guild) { return false; } return guild == player->guild; } -void Player::sendPlayerPartyIcons(std::shared_ptr player) { +void Player::sendPlayerPartyIcons(const std::shared_ptr &player) { sendPartyCreatureShield(player); sendPartyCreatureSkull(player); } @@ -5492,7 +5492,7 @@ void Player::clearPartyInvitations() { invitePartyList.clear(); } -GuildEmblems_t Player::getGuildEmblem(std::shared_ptr player) const { +GuildEmblems_t Player::getGuildEmblem(const std::shared_ptr &player) const { if (!player) { return GUILDEMBLEM_NONE; } @@ -6798,7 +6798,7 @@ bool Player::saySpell( int32_t valueEmote = 0; // Send to client for (std::shared_ptr spectator : spectators) { - if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { valueEmote = tmpPlayer->getStorageValue(STORAGEVALUE_EMOTE); if (!ghostMode || tmpPlayer->canSeeCreature(static_self_cast())) { if (valueEmote == 1) { @@ -6812,7 +6812,7 @@ bool Player::saySpell( // Execute lua event method for (std::shared_ptr spectator : spectators) { - auto tmpPlayer = spectator->getPlayer(); + const auto &tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; } diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 7ff7e02a505..4daadb070fb 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -257,7 +257,7 @@ class Player final : public Creature, public Cylinder, public Bankable { guildRank = newGuildRank; } - bool isGuildMate(std::shared_ptr player) const; + bool isGuildMate(const std::shared_ptr &player) const; [[nodiscard]] const std::string &getGuildNick() const { return guildNick; @@ -266,7 +266,7 @@ class Player final : public Creature, public Cylinder, public Bankable { guildNick = nick; } - bool isInWar(std::shared_ptr player) const; + bool isInWar(const std::shared_ptr &player) const; bool isInWarList(uint32_t guild_id) const; void setLastWalkthroughAttempt(int64_t walkthroughAttempt) { @@ -383,17 +383,17 @@ class Player final : public Creature, public Cylinder, public Bankable { int32_t getReflectFlat(CombatType_t combat, bool useCharges = false) const override; - PartyShields_t getPartyShield(std::shared_ptr player); - bool isInviting(std::shared_ptr player) const; - bool isPartner(std::shared_ptr player) const; - void sendPlayerPartyIcons(std::shared_ptr player); + PartyShields_t getPartyShield(const std::shared_ptr &player); + bool isInviting(const std::shared_ptr &player) const; + bool isPartner(const std::shared_ptr &player) const; + void sendPlayerPartyIcons(const std::shared_ptr &player); bool addPartyInvitation(Party* party); void removePartyInvitation(Party* party); void clearPartyInvitations(); void sendUnjustifiedPoints(); - GuildEmblems_t getGuildEmblem(std::shared_ptr player) const; + GuildEmblems_t getGuildEmblem(const std::shared_ptr &player) const; uint64_t getSpentMana() const { return manaSpent; @@ -787,7 +787,7 @@ class Player final : public Creature, public Cylinder, public Bankable { } // V.I.P. functions - void notifyStatusChange(std::shared_ptr player, VipStatus_t status, bool message = true); + void notifyStatusChange(const std::shared_ptr &player, VipStatus_t status, bool message = true); bool removeVIP(uint32_t vipGuid); bool addVIP(uint32_t vipGuid, const std::string &vipName, VipStatus_t status); bool addVIPInternal(uint32_t vipGuid); @@ -919,11 +919,11 @@ class Player final : public Creature, public Cylinder, public Bankable { skullTicks = ticks; } - bool hasAttacked(std::shared_ptr attacked) const; - void addAttacked(std::shared_ptr attacked); - void removeAttacked(std::shared_ptr attacked); + bool hasAttacked(const std::shared_ptr &attacked) const; + void addAttacked(const std::shared_ptr &attacked); + void removeAttacked(const std::shared_ptr &attacked); void clearAttacked(); - void addUnjustifiedDead(std::shared_ptr attacked); + void addUnjustifiedDead(const std::shared_ptr &attacked); void sendCreatureEmblem(std::shared_ptr creature) const { if (client) { client->sendCreatureEmblem(creature); @@ -952,7 +952,7 @@ class Player final : public Creature, public Cylinder, public Bankable { bool canLogout(); - bool hasKilled(std::shared_ptr player) const; + bool hasKilled(const std::shared_ptr &player) const; size_t getMaxVIPEntries() const; size_t getMaxDepotItems() const; @@ -1042,7 +1042,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->reloadCreature(creature); } } - void sendPrivateMessage(std::shared_ptr speaker, SpeakClasses type, const std::string &text) { + void sendPrivateMessage(const std::shared_ptr &speaker, SpeakClasses type, const std::string &text) { if (client) { client->sendPrivateMessage(speaker, type, text); } @@ -1277,7 +1277,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendPartyCreatureHealth(creature, healthPercent); } } - void sendPartyPlayerMana(std::shared_ptr player, uint8_t manaPercent) const { + void sendPartyPlayerMana(const std::shared_ptr &player, uint8_t manaPercent) const { if (client) { client->sendPartyPlayerMana(player, manaPercent); } @@ -1287,12 +1287,12 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendPartyCreatureShowStatus(creature, showStatus); } } - void sendPartyPlayerVocation(std::shared_ptr player) const { + void sendPartyPlayerVocation(const std::shared_ptr &player) const { if (client) { client->sendPartyPlayerVocation(player); } } - void sendPlayerVocation(std::shared_ptr player) const { + void sendPlayerVocation(const std::shared_ptr &player) const { if (client) { client->sendPlayerVocation(player); } diff --git a/src/creatures/players/wheel/player_wheel.cpp b/src/creatures/players/wheel/player_wheel.cpp index bdf64fc63b0..08b050d0911 100644 --- a/src/creatures/players/wheel/player_wheel.cpp +++ b/src/creatures/players/wheel/player_wheel.cpp @@ -632,7 +632,7 @@ bool PlayerWheel::getSpellAdditionalArea(const std::string &spellName) const { return false; } - auto vocationEnum = getPlayerVocationEnum(); + const auto &vocationEnum = getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { return checkSpellArea(g_game().getIOWheel()->getWheelBonusData().spells.knight, spellName, stage); } else if (vocationEnum == Vocation_t::VOCATION_PALADIN_CIP) { @@ -652,7 +652,7 @@ int PlayerWheel::getSpellAdditionalTarget(const std::string &spellName) const { return 0; } - auto vocationEnum = getPlayerVocationEnum(); + const auto &vocationEnum = getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { return checkSpellAdditionalTarget(g_game().getIOWheel()->getWheelBonusData().spells.knight, spellName, stage); } else if (vocationEnum == Vocation_t::VOCATION_PALADIN_CIP) { @@ -672,7 +672,7 @@ int PlayerWheel::getSpellAdditionalDuration(const std::string &spellName) const return 0; } - auto vocationEnum = getPlayerVocationEnum(); + const auto &vocationEnum = getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { return checkSpellAdditionalDuration(g_game().getIOWheel()->getWheelBonusData().spells.knight, spellName, stage); } else if (vocationEnum == Vocation_t::VOCATION_PALADIN_CIP) { @@ -1376,7 +1376,7 @@ void PlayerWheel::printPlayerWheelMethodsBonusData(const PlayerWheelMethodsBonus void PlayerWheel::loadDedicationAndConvictionPerks() { using VocationBonusFunction = std::function &, uint16_t, uint8_t, PlayerWheelMethodsBonusData &)>; auto &wheelFunctions = g_game().getIOWheel()->getWheelMapFunctions(); - auto vocationCipId = getPlayerVocationEnum(); + const auto &vocationCipId = getPlayerVocationEnum(); if (vocationCipId < VOCATION_KNIGHT_CIP || vocationCipId > VOCATION_DRUID_CIP) { return; } @@ -1421,7 +1421,7 @@ void PlayerWheel::loadRevelationPerks() { m_playerBonusData.stats.healing += statsHealing; auto redStageValue = static_cast(redStageEnum); - auto vocationEnum = getPlayerVocationEnum(); + const auto &vocationEnum = getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_DRUID_CIP) { m_playerBonusData.stages.blessingOfTheGrove = redStageValue; } else if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { @@ -1448,7 +1448,7 @@ void PlayerWheel::loadRevelationPerks() { m_playerBonusData.stats.healing += statsHealing; auto purpleStage = static_cast(purpleStageEnum); - auto vocationEnum = getPlayerVocationEnum(); + const auto &vocationEnum = getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { m_playerBonusData.avatar.steel = purpleStage; for (uint8_t i = 0; i < purpleStage; ++i) { @@ -1479,7 +1479,7 @@ void PlayerWheel::loadRevelationPerks() { m_playerBonusData.stats.healing += statsHealing; auto blueStage = static_cast(blueStageEnum); - auto vocationEnum = getPlayerVocationEnum(); + const auto &vocationEnum = getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { m_playerBonusData.stages.combatMastery = blueStage; } else if (vocationEnum == Vocation_t::VOCATION_SORCERER_CIP) { diff --git a/src/game/bank/bank.cpp b/src/game/bank/bank.cpp index 56e06150bdb..d7b3d67b224 100644 --- a/src/game/bank/bank.cpp +++ b/src/game/bank/bank.cpp @@ -23,7 +23,7 @@ Bank::~Bank() { if (bankable == nullptr || bankable->isOnline()) { return; } - std::shared_ptr player = bankable->getPlayer(); + const auto &player = bankable->getPlayer(); if (player && !player->isOnline()) { IOLoginData::savePlayer(player); @@ -93,7 +93,7 @@ bool Bank::transferTo(const std::shared_ptr destination, uint64_t amount) return false; } if (destinationBankable->getPlayer() != nullptr) { - auto player = bankable->getPlayer(); + const auto &player = bankable->getPlayer(); auto name = asLowerCaseString(player->getName()); replaceString(name, " ", ""); if (deniedNames.contains(name)) { @@ -111,7 +111,7 @@ bool Bank::transferTo(const std::shared_ptr destination, uint64_t amount) return debit(amount) && destination->credit(amount); } -bool Bank::withdraw(std::shared_ptr player, uint64_t amount) { +bool Bank::withdraw(const std::shared_ptr &player, uint64_t amount) { if (!debit(amount)) { return false; } @@ -127,7 +127,7 @@ bool Bank::deposit(const std::shared_ptr destination) { if (bankable->getPlayer() == nullptr) { return false; } - auto amount = bankable->getPlayer()->getMoney(); + const auto &amount = bankable->getPlayer()->getMoney(); return deposit(destination, amount); } diff --git a/src/game/bank/bank.hpp b/src/game/bank/bank.hpp index b04a02a9998..792e5cc6dbb 100644 --- a/src/game/bank/bank.hpp +++ b/src/game/bank/bank.hpp @@ -43,13 +43,13 @@ class Bank : public SharedObject { uint64_t balance(); bool hasBalance(uint64_t amount); bool transferTo(const std::shared_ptr destination, uint64_t amount); - bool withdraw(std::shared_ptr player, uint64_t amount); + bool withdraw(const std::shared_ptr &player, uint64_t amount); bool deposit(const std::shared_ptr destination); bool deposit(const std::shared_ptr destination, uint64_t amount); private: std::shared_ptr getBankable() const { - return m_bankable.lock(); + return m_bankable; } - std::weak_ptr m_bankable; + std::shared_ptr m_bankable; }; diff --git a/src/game/game.cpp b/src/game/game.cpp index 377a3bc1986..cfc52afa117 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -91,7 +91,7 @@ namespace InternalGame { } } - bool playerCanUseItemOnHouseTile(std::shared_ptr player, std::shared_ptr item) { + bool playerCanUseItemOnHouseTile(const std::shared_ptr &player, std::shared_ptr item) { if (!player || !item) { return false; } @@ -124,7 +124,7 @@ namespace InternalGame { return true; } - bool playerCanUseItemWithOnHouseTile(std::shared_ptr player, std::shared_ptr item, const Position &toPos, int toStackPos, int toItemId) { + bool playerCanUseItemWithOnHouseTile(const std::shared_ptr &player, std::shared_ptr item, const Position &toPos, int toStackPos, int toItemId) { if (!player || !item) { return false; } @@ -499,7 +499,7 @@ void Game::loadMap(const std::string &path, const Position &pos) { map.loadMap(path, false, false, false, false, pos); } -std::shared_ptr Game::internalGetCylinder(std::shared_ptr player, const Position &pos) { +std::shared_ptr Game::internalGetCylinder(const std::shared_ptr &player, const Position &pos) { if (pos.x != 0xFFFF) { return map.getTile(pos); } @@ -514,7 +514,7 @@ std::shared_ptr Game::internalGetCylinder(std::shared_ptr play return player; } -std::shared_ptr Game::internalGetThing(std::shared_ptr player, const Position &pos, int32_t index, uint32_t itemId, StackPosType_t type) { +std::shared_ptr Game::internalGetThing(const std::shared_ptr &player, const Position &pos, int32_t index, uint32_t itemId, StackPosType_t type) { if (pos.x != 0xFFFF) { std::shared_ptr tile = map.getTile(pos); if (!tile) { @@ -661,7 +661,7 @@ void Game::internalGetPosition(std::shared_ptr item, Position &pos, uint8_ std::shared_ptr topParent = item->getTopParent(); if (topParent) { - if (std::shared_ptr player = std::dynamic_pointer_cast(topParent)) { + if (const auto &player = std::dynamic_pointer_cast(topParent)) { pos.x = 0xFFFF; std::shared_ptr container = std::dynamic_pointer_cast(item->getParent()); @@ -783,7 +783,7 @@ std::shared_ptr Game::getPlayerByName(const std::string &s, bool loadTmp if (!loadTmp) { return nullptr; } - std::shared_ptr tmpPlayer = std::make_shared(nullptr); + const auto &tmpPlayer = std::make_shared(nullptr); if (!IOLoginData::loadPlayerByName(tmpPlayer, s)) { return nullptr; @@ -794,7 +794,7 @@ std::shared_ptr Game::getPlayerByName(const std::string &s, bool loadTmp return it->second.lock(); } -std::shared_ptr Game::getPlayerByGUID(const uint32_t &guid) { +std::shared_ptr Game::getPlayerByGUID(const uint32_t &guid, bool loadTmp /* = false */) { if (guid == 0) { return nullptr; } @@ -803,7 +803,16 @@ std::shared_ptr Game::getPlayerByGUID(const uint32_t &guid) { return it.second; } } - return nullptr; + if (!loadTmp) { + return nullptr; + } + + const auto &tmpPlayer = std::make_shared(nullptr); + if (!IOLoginData::loadPlayerById(tmpPlayer, guid)) { + return nullptr; + } + tmpPlayer->setOnline(false); + return tmpPlayer; } ReturnValue Game::getPlayerByNameWildcard(const std::string &s, std::shared_ptr &player) { @@ -874,7 +883,7 @@ bool Game::placeCreature(std::shared_ptr creature, const Position &pos SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true); for (std::shared_ptr spectator : spectators) { - if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendCreatureAppear(creature, creature->getPosition(), true); hasPlayerSpectators = true; } @@ -902,7 +911,7 @@ bool Game::removeCreature(std::shared_ptr creature, bool isLogout /* = SpectatorHashSet spectators; map.getSpectators(spectators, tile->getPosition(), true); for (auto spectator : spectators) { - if (auto player = spectator->getPlayer()) { + if (const auto &player = spectator->getPlayer()) { oldStackPosVector.push_back(player->canSeeCreature(creature) ? tile->getStackposOfCreature(player, creature) : -1); } } @@ -914,7 +923,7 @@ bool Game::removeCreature(std::shared_ptr creature, bool isLogout /* = // send to client size_t i = 0; for (auto spectator : spectators) { - if (auto player = spectator->getPlayer()) { + if (const auto &player = spectator->getPlayer()) { player->sendRemoveTileThing(tilePosition, oldStackPosVector[i++]); } } @@ -942,7 +951,7 @@ bool Game::removeCreature(std::shared_ptr creature, bool isLogout /* = } if (creature->getPlayer() && isLogout) { - auto it = teamFinderMap.find(creature->getPlayer()->getGUID()); + const auto &it = teamFinderMap.find(creature->getPlayer()->getGUID()); if (it != teamFinderMap.end()) { teamFinderMap.erase(it); } @@ -960,7 +969,7 @@ void Game::executeDeath(uint32_t creatureId) { } void Game::playerTeleport(uint32_t playerId, const Position &newPosition) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || !player->hasFlag(PlayerFlags_t::CanMapClickTeleport)) { return; } @@ -971,7 +980,7 @@ void Game::playerTeleport(uint32_t playerId, const Position &newPosition) { } } -void Game::playerInspectItem(std::shared_ptr player, const Position &pos) { +void Game::playerInspectItem(const std::shared_ptr &player, const Position &pos) { std::shared_ptr thing = internalGetThing(player, pos, 0, 0, STACKPOS_TOPDOWN_ITEM); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); @@ -987,7 +996,7 @@ void Game::playerInspectItem(std::shared_ptr player, const Position &pos player->sendItemInspection(item->getID(), static_cast(item->getItemCount()), item, false); } -void Game::playerInspectItem(std::shared_ptr player, uint16_t itemId, uint8_t itemCount, bool cyclopedia) { +void Game::playerInspectItem(const std::shared_ptr &player, uint16_t itemId, uint8_t itemCount, bool cyclopedia) { player->sendItemInspection(itemId, itemCount, nullptr, cyclopedia); } @@ -1041,7 +1050,7 @@ FILELOADER_ERRORS Game::loadAppearanceProtobuf(const std::string &file) { } void Game::playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -1103,7 +1112,7 @@ void Game::playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t } void Game::playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, const Position &movingCreatureOrigPos, const Position &toPos) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -1122,7 +1131,7 @@ void Game::playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, playerMoveCreature(player, movingCreature, movingCreatureOrigPos, toTile); } -void Game::playerMoveCreature(std::shared_ptr player, std::shared_ptr movingCreature, const Position &movingCreatureOrigPos, std::shared_ptr toTile) { +void Game::playerMoveCreature(const std::shared_ptr &player, std::shared_ptr movingCreature, const Position &movingCreatureOrigPos, std::shared_ptr toTile) { if (!player->canDoAction()) { uint32_t delay = 600; std::shared_ptr task = createPlayerTask(delay, std::bind(&Game::playerMoveCreatureByID, this, player->getID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()), "Game::playerMoveCreatureByID"); @@ -1219,7 +1228,7 @@ ReturnValue Game::internalMoveCreature(std::shared_ptr creature, Direc creature->setLastPosition(creature->getPosition()); const Position ¤tPos = creature->getPosition(); Position destPos = getNextPosition(direction, currentPos); - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); bool diagonalMovement = (direction & DIRECTION_DIAGONAL_MASK) != 0; if (player && !diagonalMovement) { @@ -1329,14 +1338,14 @@ ReturnValue Game::internalMoveCreature(const std::shared_ptr &creature } void Game::playerMoveItemByPlayerID(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } playerMoveItem(player, fromPos, itemId, fromStackPos, toPos, count, nullptr, nullptr); } -void Game::playerMoveItem(std::shared_ptr player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder) { +void Game::playerMoveItem(const std::shared_ptr &player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder) { if (!player->canDoAction()) { uint32_t delay = player->getNextActionTime(); std::shared_ptr task = createPlayerTask(delay, std::bind(&Game::playerMoveItemByPlayerID, this, player->getID(), fromPos, itemId, fromStackPos, toPos, count), "Game::playerMoveItemByPlayerID"); @@ -1556,7 +1565,7 @@ bool Game::isTryingToStow(const Position &toPos, std::shared_ptr toCyl return toCylinder->getContainer() && toCylinder->getItem()->getID() == ITEM_LOCKER && toPos.getZ() == ITEM_SUPPLY_STASH_INDEX; } -ReturnValue Game::checkMoveItemToCylinder(std::shared_ptr player, std::shared_ptr fromCylinder, std::shared_ptr toCylinder, std::shared_ptr item, Position toPos) { +ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr &player, std::shared_ptr fromCylinder, std::shared_ptr toCylinder, std::shared_ptr item, Position toPos) { if (!player || !toCylinder || !item) { return RETURNVALUE_NOTPOSSIBLE; } @@ -1862,7 +1871,7 @@ ReturnValue Game::internalMoveItem(std::shared_ptr fromCylinder, std:: auto fromContainer = fromCylinder ? fromCylinder->getContainer() : nullptr; auto toContainer = toCylinder ? toCylinder->getContainer() : nullptr; - auto player = actor ? actor->getPlayer() : nullptr; + const auto &player = actor ? actor->getPlayer() : nullptr; if (player) { // Update containers player->onSendContainer(toContainer); @@ -1875,7 +1884,7 @@ ReturnValue Game::internalMoveItem(std::shared_ptr fromCylinder, std:: return ret; } - if (std::shared_ptr player = actor->getPlayer()) { + if (const auto &player = actor->getPlayer()) { // Refresh depot search window if necessary if (player->isDepotSearchOpenOnItem(item->getID()) && ((fromCylinder->getItem() && fromCylinder->getItem()->isInsideDepot(true)) || (toCylinder->getItem() && toCylinder->getItem()->isInsideDepot(true)))) { player->requestDepotSearchItem(item->getID(), item->getTier()); @@ -2046,7 +2055,7 @@ ReturnValue Game::internalRemoveItem(std::shared_ptr item, int32_t count / return RETURNVALUE_NOERROR; } -ReturnValue Game::internalPlayerAddItem(std::shared_ptr player, std::shared_ptr item, bool dropOnMap /*= true*/, Slots_t slot /*= CONST_SLOT_WHEREEVER*/) { +ReturnValue Game::internalPlayerAddItem(const std::shared_ptr &player, std::shared_ptr item, bool dropOnMap /*= true*/, Slots_t slot /*= CONST_SLOT_WHEREEVER*/) { uint32_t remainderCount = 0; ReturnValue ret = internalAddItem(player, item, static_cast(slot), 0, false, remainderCount); if (remainderCount != 0) { @@ -2163,7 +2172,7 @@ bool Game::removeMoney(std::shared_ptr cylinder, uint64_t money, uint3 } } - std::shared_ptr player = useBalance ? std::dynamic_pointer_cast(cylinder) : nullptr; + const auto &player = useBalance ? std::dynamic_pointer_cast(cylinder) : nullptr; uint64_t balance = 0; if (useBalance && player) { balance = player->getBankBalance(); @@ -2405,7 +2414,7 @@ ReturnValue Game::internalTeleport(std::shared_ptr thing, const Position return RETURNVALUE_NOTPOSSIBLE; } -void Game::internalQuickLootCorpse(std::shared_ptr player, std::shared_ptr corpse) { +void Game::internalQuickLootCorpse(const std::shared_ptr &player, std::shared_ptr corpse) { if (!player || !corpse) { return; } @@ -2548,7 +2557,7 @@ void Game::internalQuickLootCorpse(std::shared_ptr player, std::shared_p player->lastQuickLootNotification = OTSYS_TIME(); } -std::shared_ptr Game::findLootContainer(std::shared_ptr player, bool &fallbackConsumed, ObjectCategory_t category) { +std::shared_ptr Game::findLootContainer(const std::shared_ptr &player, bool &fallbackConsumed, ObjectCategory_t category) { auto lootContainer = player->getLootContainer(category); if (!lootContainer && player->quickLootFallbackToMainContainer && !fallbackConsumed) { auto fallbackItem = player->getInventoryItem(CONST_SLOT_BACKPACK); @@ -2589,7 +2598,7 @@ std::shared_ptr Game::findNextAvailableContainer(ContainerIterator &c return nullptr; } -bool Game::handleFallbackLogic(std::shared_ptr player, std::shared_ptr &lootContainer, ContainerIterator &containerIterator, const bool &fallbackConsumed) { +bool Game::handleFallbackLogic(const std::shared_ptr &player, std::shared_ptr &lootContainer, ContainerIterator &containerIterator, const bool &fallbackConsumed) { if (fallbackConsumed || !player->quickLootFallbackToMainContainer) { return false; } @@ -2605,7 +2614,7 @@ bool Game::handleFallbackLogic(std::shared_ptr player, std::shared_ptr item, std::shared_ptr lootContainer, uint32_t &remainderCount, std::shared_ptr player) { +ReturnValue Game::processMoveOrAddItemToLootContainer(std::shared_ptr item, std::shared_ptr lootContainer, uint32_t &remainderCount, const std::shared_ptr &player) { std::shared_ptr moveItem = nullptr; ReturnValue ret; if (item->getParent()) { @@ -2619,7 +2628,7 @@ ReturnValue Game::processMoveOrAddItemToLootContainer(std::shared_ptr item return ret; } -ReturnValue Game::processLootItems(std::shared_ptr player, std::shared_ptr lootContainer, std::shared_ptr item, bool &fallbackConsumed) { +ReturnValue Game::processLootItems(const std::shared_ptr &player, std::shared_ptr lootContainer, std::shared_ptr item, bool &fallbackConsumed) { std::shared_ptr lastSubContainer = nullptr; uint32_t remainderCount = item->getItemCount(); ContainerIterator containerIterator = lootContainer->iterator(); @@ -2641,7 +2650,7 @@ ReturnValue Game::processLootItems(std::shared_ptr player, std::shared_p return ret; } -ReturnValue Game::internalCollectLootItems(std::shared_ptr player, std::shared_ptr item, ObjectCategory_t category /* = OBJECTCATEGORY_DEFAULT*/) { +ReturnValue Game::internalCollectLootItems(const std::shared_ptr &player, std::shared_ptr item, ObjectCategory_t category /* = OBJECTCATEGORY_DEFAULT*/) { if (!player || !item) { return RETURNVALUE_NOTPOSSIBLE; } @@ -2678,7 +2687,7 @@ ReturnValue Game::internalCollectLootItems(std::shared_ptr player, std:: return processLootItems(player, lootContainer, item, fallbackConsumed); } -ReturnValue Game::collectRewardChestItems(std::shared_ptr player, uint32_t maxMoveItems /* = 0*/) { +ReturnValue Game::collectRewardChestItems(const std::shared_ptr &player, uint32_t maxMoveItems /* = 0*/) { // Check if have item on player reward chest std::shared_ptr rewardChest = player->getRewardChest(); if (rewardChest->empty()) { @@ -2854,7 +2863,7 @@ Slots_t getSlotType(const ItemType &it) { // Implementation of player invoked events void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = false*/, uint8_t tier /* = 0*/) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -2898,7 +2907,7 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = } void Game::playerMove(uint32_t playerId, Direction direction) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -2911,7 +2920,7 @@ void Game::playerMove(uint32_t playerId, Direction direction) { } void Game::forcePlayerMove(uint32_t playerId, Direction direction) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -2923,7 +2932,7 @@ void Game::forcePlayerMove(uint32_t playerId, Direction direction) { player->startAutoWalk(std::forward_list { direction }, true); } -bool Game::playerBroadcastMessage(std::shared_ptr player, const std::string &text) const { +bool Game::playerBroadcastMessage(const std::shared_ptr &player, const std::string &text) const { if (!player->hasFlag(PlayerFlags_t::CanBroadcast)) { return false; } @@ -2938,7 +2947,7 @@ bool Game::playerBroadcastMessage(std::shared_ptr player, const std::str } void Game::playerCreatePrivateChannel(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || !player->isPremium()) { return; } @@ -2952,7 +2961,7 @@ void Game::playerCreatePrivateChannel(uint32_t playerId) { } void Game::playerChannelInvite(uint32_t playerId, const std::string &name) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -2962,7 +2971,7 @@ void Game::playerChannelInvite(uint32_t playerId, const std::string &name) { return; } - std::shared_ptr invitePlayer = getPlayerByName(name); + const auto &invitePlayer = getPlayerByName(name); if (!invitePlayer) { return; } @@ -2975,7 +2984,7 @@ void Game::playerChannelInvite(uint32_t playerId, const std::string &name) { } void Game::playerChannelExclude(uint32_t playerId, const std::string &name) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -2985,7 +2994,7 @@ void Game::playerChannelExclude(uint32_t playerId, const std::string &name) { return; } - std::shared_ptr excludePlayer = getPlayerByName(name); + const auto &excludePlayer = getPlayerByName(name); if (!excludePlayer) { return; } @@ -2998,7 +3007,7 @@ void Game::playerChannelExclude(uint32_t playerId, const std::string &name) { } void Game::playerRequestChannels(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3007,7 +3016,7 @@ void Game::playerRequestChannels(uint32_t playerId) { } void Game::playerOpenChannel(uint32_t playerId, uint16_t channelId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3029,7 +3038,7 @@ void Game::playerOpenChannel(uint32_t playerId, uint16_t channelId) { } void Game::playerCloseChannel(uint32_t playerId, uint16_t channelId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3038,7 +3047,7 @@ void Game::playerCloseChannel(uint32_t playerId, uint16_t channelId) { } void Game::playerOpenPrivateChannel(uint32_t playerId, std::string &receiver) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3057,7 +3066,7 @@ void Game::playerOpenPrivateChannel(uint32_t playerId, std::string &receiver) { } void Game::playerCloseNpcChannel(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3072,7 +3081,7 @@ void Game::playerCloseNpcChannel(uint32_t playerId) { } void Game::playerReceivePing(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3081,7 +3090,7 @@ void Game::playerReceivePing(uint32_t playerId) { } void Game::playerReceivePingBack(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3090,7 +3099,7 @@ void Game::playerReceivePingBack(uint32_t playerId) { } void Game::playerAutoWalk(uint32_t playerId, const std::forward_list &listDir) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3101,7 +3110,7 @@ void Game::playerAutoWalk(uint32_t playerId, const std::forward_list } void Game::forcePlayerAutoWalk(uint32_t playerId, const std::forward_list &listDir) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3118,7 +3127,7 @@ void Game::forcePlayerAutoWalk(uint32_t playerId, const std::forward_list player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3127,7 +3136,7 @@ void Game::playerStopAutoWalk(uint32_t playerId) { } void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t fromStackPos, uint16_t fromItemId, const Position &toPos, uint8_t toStackPos, uint16_t toItemId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3256,7 +3265,7 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f } void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPos, uint8_t index, uint16_t itemId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3350,7 +3359,7 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo } void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uint8_t fromStackPos, uint32_t creatureId, uint16_t itemId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3479,7 +3488,7 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin } void Game::playerCloseContainer(uint32_t playerId, uint8_t cid) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3489,7 +3498,7 @@ void Game::playerCloseContainer(uint32_t playerId, uint8_t cid) { } void Game::playerMoveUpContainer(uint32_t playerId, uint8_t cid) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3536,7 +3545,7 @@ void Game::playerMoveUpContainer(uint32_t playerId, uint8_t cid) { } void Game::playerUpdateContainer(uint32_t playerId, uint8_t cid) { - std::shared_ptr player = getPlayerByGUID(playerId); + const auto &player = getPlayerByGUID(playerId); if (!player) { return; } @@ -3550,7 +3559,7 @@ void Game::playerUpdateContainer(uint32_t playerId, uint8_t cid) { } void Game::playerRotateItem(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3590,7 +3599,7 @@ void Game::playerRotateItem(uint32_t playerId, const Position &pos, uint8_t stac } void Game::playerConfigureShowOffSocket(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || pos.x == 0xFFFF) { return; } @@ -3632,7 +3641,7 @@ void Game::playerConfigureShowOffSocket(uint32_t playerId, const Position &pos, } void Game::playerSetShowOffSocket(uint32_t playerId, Outfit_t &outfit, const Position &pos, uint8_t stackPos, const uint16_t itemId, uint8_t podiumVisible, uint8_t direction) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || pos.x == 0xFFFF) { return; } @@ -3748,14 +3757,14 @@ void Game::playerSetShowOffSocket(uint32_t playerId, Outfit_t &outfit, const Pos // Send to client for (auto spectator : spectators) { - if (auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendUpdateTileItem(tile, pos, item); } } } void Game::playerWrapableItem(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3861,7 +3870,7 @@ std::shared_ptr Game::wrapItem(std::shared_ptr item, House* house) { return newItem; } -void Game::unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* house, std::shared_ptr player) { +void Game::unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* house, const std::shared_ptr &player) { auto hiddenCharges = item->getAttribute(DATE); const ItemType &newiType = Item::items.getItemType(unWrapId); if (player != nullptr && house != nullptr && newiType.isBed() && house->getMaxBeds() > -1 && house->getBedCount() >= house->getMaxBeds()) { @@ -3887,7 +3896,7 @@ void Game::unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* hous } void Game::playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std::string &text) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -3907,7 +3916,7 @@ void Game::playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std:: std::shared_ptr topParent = writeItem->getTopParent(); - std::shared_ptr owner = std::dynamic_pointer_cast(topParent); + const auto &owner = std::dynamic_pointer_cast(topParent); if (owner && owner != player) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -3946,7 +3955,7 @@ void Game::playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std:: } void Game::playerBrowseField(uint32_t playerId, const Position &pos) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4004,7 +4013,7 @@ void Game::playerBrowseField(uint32_t playerId, const Position &pos) { } void Game::playerStowItem(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackpos, uint8_t count, bool allItems) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4040,7 +4049,7 @@ void Game::playerStowItem(uint32_t playerId, const Position &pos, uint16_t itemI } void Game::playerStashWithdraw(uint32_t playerId, uint16_t itemId, uint32_t count, uint8_t) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4113,7 +4122,7 @@ void Game::playerStashWithdraw(uint32_t playerId, uint16_t itemId, uint32_t coun } void Game::playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_t index, uint8_t containerCategory) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4138,7 +4147,7 @@ void Game::playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_ } void Game::playerUpdateHouseWindow(uint32_t playerId, uint8_t listId, uint32_t windowTextId, const std::string &text) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4155,12 +4164,12 @@ void Game::playerUpdateHouseWindow(uint32_t playerId, uint8_t listId, uint32_t w } void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t stackPos, uint32_t tradePlayerId, uint16_t itemId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } - std::shared_ptr tradePartner = getPlayerByID(tradePlayerId); + const auto &tradePartner = getPlayerByID(tradePlayerId); if (!tradePartner || tradePartner == player) { player->sendTextMessage(MESSAGE_FAILURE, "Sorry, not possible."); return; @@ -4287,7 +4296,7 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st internalStartTrade(player, tradePartner, tradeItem); } -bool Game::internalStartTrade(std::shared_ptr player, std::shared_ptr tradePartner, std::shared_ptr tradeItem) { +bool Game::internalStartTrade(const std::shared_ptr &player, const std::shared_ptr &tradePartner, std::shared_ptr tradeItem) { if (player->tradeState != TRADE_NONE && !(player->tradeState == TRADE_ACKNOWLEDGE && player->tradePartner == tradePartner)) { player->sendCancelMessage(RETURNVALUE_YOUAREALREADYTRADING); return false; @@ -4319,7 +4328,7 @@ bool Game::internalStartTrade(std::shared_ptr player, std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4328,7 +4337,7 @@ void Game::playerAcceptTrade(uint32_t playerId) { return; } - std::shared_ptr tradePartner = player->tradePartner; + const auto &tradePartner = player->tradePartner; if (!tradePartner) { return; } @@ -4452,12 +4461,12 @@ std::string Game::getTradeErrorDescription(ReturnValue ret, std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } - std::shared_ptr tradePartner = player->tradePartner; + const auto &tradePartner = player->tradePartner; if (!tradePartner) { return; } @@ -4511,7 +4520,7 @@ void Game::playerLookInTrade(uint32_t playerId, bool lookAtCounterOffer, uint8_t } void Game::playerCloseTrade(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4519,8 +4528,8 @@ void Game::playerCloseTrade(uint32_t playerId) { internalCloseTrade(player); } -void Game::internalCloseTrade(std::shared_ptr player) { - std::shared_ptr tradePartner = player->tradePartner; +void Game::internalCloseTrade(const std::shared_ptr &player) { + const auto &tradePartner = player->tradePartner; if ((tradePartner && tradePartner->getTradeState() == TRADE_TRANSFER) || player->getTradeState() == TRADE_TRANSFER) { return; } @@ -4565,7 +4574,7 @@ void Game::playerBuyItem(uint32_t playerId, uint16_t itemId, uint8_t count, uint return; } - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4603,7 +4612,7 @@ void Game::playerSellItem(uint32_t playerId, uint16_t itemId, uint8_t count, uin return; } - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4633,7 +4642,7 @@ void Game::playerSellItem(uint32_t playerId, uint16_t itemId, uint8_t count, uin } void Game::playerCloseShop(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4642,7 +4651,7 @@ void Game::playerCloseShop(uint32_t playerId) { } void Game::playerLookInShop(uint32_t playerId, uint16_t itemId, uint8_t count) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4672,7 +4681,7 @@ void Game::playerLookInShop(uint32_t playerId, uint16_t itemId, uint8_t count) { } void Game::playerLookAt(uint32_t playerId, uint16_t itemId, const Position &pos, uint8_t stackPos) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4707,7 +4716,7 @@ void Game::playerLookAt(uint32_t playerId, uint16_t itemId, const Position &pos, } void Game::playerLookInBattleList(uint32_t playerId, uint32_t creatureId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4742,7 +4751,7 @@ void Game::playerLookInBattleList(uint32_t playerId, uint32_t creatureId) { } void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, std::shared_ptr defaultItem, bool lootAllCorpses, bool autoLoot) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4872,7 +4881,7 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item } } -void Game::playerLootAllCorpses(std::shared_ptr player, const Position &pos, bool lootAllCorpses) { +void Game::playerLootAllCorpses(const std::shared_ptr &player, const Position &pos, bool lootAllCorpses) { if (lootAllCorpses) { std::shared_ptr tile = g_game().map.getTile(pos.x, pos.y, pos.z); if (!tile) { @@ -4922,7 +4931,7 @@ void Game::playerLootAllCorpses(std::shared_ptr player, const Position & } void Game::playerSetLootContainer(uint32_t playerId, ObjectCategory_t category, const Position &pos, uint16_t itemId, uint8_t stackPos) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || pos.x != 0xffff) { return; } @@ -4961,7 +4970,7 @@ void Game::playerSetLootContainer(uint32_t playerId, ObjectCategory_t category, } void Game::playerClearLootContainer(uint32_t playerId, ObjectCategory_t category) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4978,7 +4987,7 @@ void Game::playerClearLootContainer(uint32_t playerId, ObjectCategory_t category } void Game::playerOpenLootContainer(uint32_t playerId, ObjectCategory_t category) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -4992,7 +5001,7 @@ void Game::playerOpenLootContainer(uint32_t playerId, ObjectCategory_t category) } void Game::playerSetQuickLootFallback(uint32_t playerId, bool fallback) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5001,7 +5010,7 @@ void Game::playerSetQuickLootFallback(uint32_t playerId, bool fallback) { } void Game::playerQuickLootBlackWhitelist(uint32_t playerId, QuickLootFilter_t filter, const std::vector itemIds) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5014,7 +5023,7 @@ void Game::playerQuickLootBlackWhitelist(uint32_t playerId, QuickLootFilter_t fi * Depot search system ******************************************************************************/ void Game::playerRequestDepotItems(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || !player->isDepotSearchAvailable()) { return; } @@ -5029,7 +5038,7 @@ void Game::playerRequestDepotItems(uint32_t playerId) { } void Game::playerRequestCloseDepotSearch(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || !player->isDepotSearchOpen()) { return; } @@ -5039,7 +5048,7 @@ void Game::playerRequestCloseDepotSearch(uint32_t playerId) { } void Game::playerRequestDepotSearchItem(uint32_t playerId, uint16_t itemId, uint8_t tier) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || !player->isDepotSearchOpen()) { return; } @@ -5054,7 +5063,7 @@ void Game::playerRequestDepotSearchItem(uint32_t playerId, uint16_t itemId, uint } void Game::playerRequestDepotSearchRetrieve(uint32_t playerId, uint16_t itemId, uint8_t tier, uint8_t type) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || !player->isDepotSearchOpenOnItem(itemId)) { return; } @@ -5069,7 +5078,7 @@ void Game::playerRequestDepotSearchRetrieve(uint32_t playerId, uint16_t itemId, } void Game::playerRequestOpenContainerFromDepotSearch(uint32_t playerId, const Position &pos) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || !player->isDepotSearchOpen()) { return; } @@ -5084,7 +5093,7 @@ void Game::playerRequestOpenContainerFromDepotSearch(uint32_t playerId, const Po } void Game::playerCancelAttackAndFollow(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5095,7 +5104,7 @@ void Game::playerCancelAttackAndFollow(uint32_t playerId) { } void Game::playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5126,7 +5135,7 @@ void Game::playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId) { } void Game::playerFollowCreature(uint32_t playerId, uint32_t creatureId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5137,7 +5146,7 @@ void Game::playerFollowCreature(uint32_t playerId, uint32_t creatureId) { } void Game::playerSetFightModes(uint32_t playerId, FightMode_t fightMode, bool chaseMode, bool secureMode) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5152,12 +5161,12 @@ void Game::playerRequestAddVip(uint32_t playerId, const std::string &name) { return; } - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } - std::shared_ptr vipPlayer = getPlayerByName(name); + const auto &vipPlayer = getPlayerByName(name); if (!vipPlayer) { uint32_t guid; bool specialVip; @@ -5188,7 +5197,7 @@ void Game::playerRequestAddVip(uint32_t playerId, const std::string &name) { } void Game::playerRequestRemoveVip(uint32_t playerId, uint32_t guid) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5197,7 +5206,7 @@ void Game::playerRequestRemoveVip(uint32_t playerId, uint32_t guid) { } void Game::playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::string &description, uint32_t icon, bool notify) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5206,7 +5215,7 @@ void Game::playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::str } void Game::playerApplyImbuement(uint32_t playerId, uint16_t imbuementid, uint8_t slot, bool protectionCharm) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5235,7 +5244,7 @@ void Game::playerApplyImbuement(uint32_t playerId, uint16_t imbuementid, uint8_t } void Game::playerClearImbuement(uint32_t playerid, uint8_t slot) { - std::shared_ptr player = getPlayerByID(playerid); + const auto &player = getPlayerByID(playerid); if (!player) { return; } @@ -5253,7 +5262,7 @@ void Game::playerClearImbuement(uint32_t playerid, uint8_t slot) { } void Game::playerCloseImbuementWindow(uint32_t playerid) { - std::shared_ptr player = getPlayerByID(playerid); + const auto &player = getPlayerByID(playerid); if (!player) { return; } @@ -5263,7 +5272,7 @@ void Game::playerCloseImbuementWindow(uint32_t playerid) { } void Game::playerTurn(uint32_t playerId, Direction dir) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5285,7 +5294,7 @@ void Game::playerRequestOutfit(uint32_t playerId) { return; } - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5294,7 +5303,7 @@ void Game::playerRequestOutfit(uint32_t playerId) { } void Game::playerToggleMount(uint32_t playerId, bool mount) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5307,7 +5316,7 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, uint8_t isMoun return; } - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5369,7 +5378,7 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, uint8_t isMoun } void Game::playerShowQuestLog(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5379,7 +5388,7 @@ void Game::playerShowQuestLog(uint32_t playerId) { } void Game::playerShowQuestLine(uint32_t playerId, uint16_t questId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5389,7 +5398,7 @@ void Game::playerShowQuestLine(uint32_t playerId, uint16_t questId) { } void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, const std::string &receiver, const std::string &text) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -5453,7 +5462,7 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, c } } -bool Game::playerSaySpell(std::shared_ptr player, SpeakClasses type, const std::string &text) { +bool Game::playerSaySpell(const std::shared_ptr &player, SpeakClasses type, const std::string &text) { if (player->walkExhausted()) { return true; } @@ -5482,13 +5491,13 @@ bool Game::playerSaySpell(std::shared_ptr player, SpeakClasses type, con return false; } -void Game::playerWhisper(std::shared_ptr player, const std::string &text) { +void Game::playerWhisper(const std::shared_ptr &player, const std::string &text) { SpectatorHashSet spectators; map.getSpectators(spectators, player->getPosition(), false, false, MAP_MAX_CLIENT_VIEW_PORT_X, MAP_MAX_CLIENT_VIEW_PORT_X, MAP_MAX_CLIENT_VIEW_PORT_Y, MAP_MAX_CLIENT_VIEW_PORT_Y); // send to client for (auto spectator : spectators) { - if (auto spectatorPlayer = spectator->getPlayer()) { + if (const auto &spectatorPlayer = spectator->getPlayer()) { if (!Position::areInRange<1, 1>(player->getPosition(), spectatorPlayer->getPosition())) { spectatorPlayer->sendCreatureSay(player, TALKTYPE_WHISPER, "pspsps"); } else { @@ -5503,7 +5512,7 @@ void Game::playerWhisper(std::shared_ptr player, const std::string &text } } -bool Game::playerYell(std::shared_ptr player, const std::string &text) { +bool Game::playerYell(const std::shared_ptr &player, const std::string &text) { if (player->getLevel() == 1) { player->sendTextMessage(MESSAGE_FAILURE, "You may not yell as long as you are on level 1."); return false; @@ -5523,8 +5532,8 @@ bool Game::playerYell(std::shared_ptr player, const std::string &text) { return true; } -bool Game::playerSpeakTo(std::shared_ptr player, SpeakClasses type, const std::string &receiver, const std::string &text) { - std::shared_ptr toPlayer = getPlayerByName(receiver); +bool Game::playerSpeakTo(const std::shared_ptr &player, SpeakClasses type, const std::string &receiver, const std::string &text) { + const auto &toPlayer = getPlayerByName(receiver); if (!toPlayer) { player->sendTextMessage(MESSAGE_FAILURE, "A player with this name is not online."); return false; @@ -5549,7 +5558,7 @@ bool Game::playerSpeakTo(std::shared_ptr player, SpeakClasses type, cons return true; } -void Game::playerSpeakToNpc(std::shared_ptr player, const std::string &text) { +void Game::playerSpeakToNpc(const std::shared_ptr &player, const std::string &text) { if (player == nullptr) { g_logger().error("[Game::playerSpeakToNpc] - Player is nullptr"); return; @@ -5590,7 +5599,7 @@ bool Game::internalCreatureTurn(std::shared_ptr creature, Direction di return false; } - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { player->cancelPush(); } creature->setDirection(dir); @@ -5599,7 +5608,7 @@ bool Game::internalCreatureTurn(std::shared_ptr creature, Direction di SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); for (auto spectator : spectators) { - auto tmpPlayer = spectator->getPlayer(); + const auto &tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; } @@ -5635,7 +5644,7 @@ bool Game::internalCreatureSay(std::shared_ptr creature, SpeakClasses // send to client for (auto spectator : spectators) { - if (auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { if (!ghostMode || tmpPlayer->canSeeCreature(creature)) { tmpPlayer->sendCreatureSay(creature, type, text, pos); } @@ -5760,7 +5769,7 @@ void Game::changePlayerSpeed(const std::shared_ptr &player, int32_t varS continue; } - std::shared_ptr playerSpectator = creatureSpectator->getPlayer(); + const auto &playerSpectator = creatureSpectator->getPlayer(); if (playerSpectator == nullptr) { g_logger().error("[Game::changePlayerSpeed] - Player spectator is nullptr"); continue; @@ -5829,7 +5838,7 @@ void Game::reloadCreature(std::shared_ptr creature) { SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), false, true); for (auto spectator : spectators) { - auto tmpPlayer = spectator->getPlayer(); + const auto &tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; } @@ -5845,7 +5854,7 @@ void Game::sendSingleSoundEffect(const Position &pos, SoundEffect_t soundId, std SpectatorHashSet spectators; map.getSpectators(spectators, pos, false, true); for (auto spectator : spectators) { - if (auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { SourceEffect_t source = SourceEffect_t::CREATURES; if (!actor || actor->getNpc()) { source = SourceEffect_t::GLOBAL; @@ -5869,7 +5878,7 @@ void Game::sendDoubleSoundEffect(const Position &pos, SoundEffect_t mainSoundEff SpectatorHashSet spectators; map.getSpectators(spectators, pos, false, true); for (auto spectator : spectators) { - if (auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { SourceEffect_t source = SourceEffect_t::CREATURES; if (!actor || actor->getNpc()) { source = SourceEffect_t::GLOBAL; @@ -5898,8 +5907,8 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr attack } // Skill dodge (ruse) - if (std::shared_ptr targetPlayer = target->getPlayer()) { - if (auto playerArmor = targetPlayer->getInventoryItem(CONST_SLOT_ARMOR); + if (const auto &targetPlayer = target->getPlayer()) { + if (const auto &playerArmor = targetPlayer->getInventoryItem(CONST_SLOT_ARMOR); playerArmor != nullptr && playerArmor->getTier()) { double_t chance = playerArmor->getDodgeChance(); double_t randomChance = uniform_random(0, 10000) / 100; @@ -5923,7 +5932,7 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr attack CombatParams damageReflectedParams; BlockType_t primaryBlockType, secondaryBlockType; - std::shared_ptr targetPlayer = target->getPlayer(); + const auto &targetPlayer = target->getPlayer(); if (damage.primary.type != COMBAT_NONE) { // Damage reflection primary @@ -6180,7 +6189,7 @@ void Game::combatGetTypeInfo(CombatType_t combatType, std::shared_ptr } // Hazard combat helpers -void Game::handleHazardSystemAttack(CombatDamage &damage, std::shared_ptr player, std::shared_ptr monster, bool isPlayerAttacker) { +void Game::handleHazardSystemAttack(CombatDamage &damage, const std::shared_ptr &player, std::shared_ptr monster, bool isPlayerAttacker) { if (damage.primary.value != 0 && monster->getHazard()) { if (isPlayerAttacker) { player->parseAttackDealtHazardSystem(damage, monster); @@ -6190,14 +6199,14 @@ void Game::handleHazardSystemAttack(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr targetMonster) { +void Game::notifySpectators(const SpectatorHashSet &spectators, const Position &targetPos, const std::shared_ptr &attackerPlayer, std::shared_ptr targetMonster) { if (!spectators.empty()) { for (auto spectator : spectators) { if (!spectator) { continue; } - const auto tmpPlayer = spectator->getPlayer(); + const auto &tmpPlayer = spectator->getPlayer(); if (!tmpPlayer || tmpPlayer->getPosition().z != targetPos.z) { continue; } @@ -6219,7 +6228,7 @@ void Game::notifySpectators(const SpectatorHashSet &spectators, const Position & } // Wheel of destiny combat helpers -void Game::applyWheelOfDestinyHealing(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr target) { +void Game::applyWheelOfDestinyHealing(CombatDamage &damage, const std::shared_ptr &attackerPlayer, std::shared_ptr target) { damage.primary.value += (damage.primary.value * damage.healingMultiplier) / 100.; if (attackerPlayer) { @@ -6242,7 +6251,7 @@ void Game::applyWheelOfDestinyHealing(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr target) const { +void Game::applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, const std::shared_ptr &attackerPlayer, std::shared_ptr target) const { // If damage is 0, it means the target is immune to the damage type, or that we missed. if (damage.primary.value == 0 && damage.secondary.value == 0) { return; @@ -6279,7 +6288,7 @@ int32_t Game::applyHealthChange(CombatDamage &damage, std::shared_ptr int32_t targetHealth = target->getHealth(); // Wheel of destiny (Gift of Life) - if (std::shared_ptr targetPlayer = target->getPlayer()) { + if (const auto &targetPlayer = target->getPlayer()) { if (targetPlayer->wheel()->getInstant("Gift of Life") && targetPlayer->wheel()->getGiftOfCooldown() == 0 && (damage.primary.value + damage.secondary.value) >= targetHealth) { int32_t overkillMultiplier = (damage.primary.value + damage.secondary.value) - targetHealth; overkillMultiplier = (overkillMultiplier * 100) / targetPlayer->getMaxHealth(); @@ -6315,7 +6324,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt attackerPlayer = nullptr; } - auto targetPlayer = target->getPlayer(); + const auto &targetPlayer = target->getPlayer(); if (attackerPlayer && targetPlayer && attackerPlayer->getSkull() == SKULL_BLACK && attackerPlayer->getSkullClient(targetPlayer) == SKULL_NONE) { return false; } @@ -6363,7 +6372,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt SpectatorHashSet spectators; map.getSpectators(spectators, targetPos, false, true); for (auto spectator : spectators) { - auto tmpPlayer = spectator->getPlayer(); + const auto &tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; @@ -6423,7 +6432,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt attackerPlayer = nullptr; } - auto targetPlayer = target->getPlayer(); + const auto &targetPlayer = target->getPlayer(); if (attackerPlayer && targetPlayer && attackerPlayer->getSkull() == SKULL_BLACK && attackerPlayer->getSkullClient(targetPlayer) == SKULL_NONE) { return false; } @@ -6584,7 +6593,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt continue; } - std::shared_ptr tmpPlayer = spectator->getPlayer(); + const auto &tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; } @@ -6721,7 +6730,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt return true; } -void Game::updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, std::shared_ptr player) const { +void Game::updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, const std::shared_ptr &player) const { if (!player) { return; } @@ -6787,7 +6796,7 @@ void Game::sendMessages( std::string spectatorMessage; for (std::shared_ptr spectator : spectators) { - std::shared_ptr tmpPlayer = spectator->getPlayer(); + const auto &tmpPlayer = spectator->getPlayer(); if (tmpPlayer->getPosition().z != targetPos.z) { continue; } @@ -6892,7 +6901,7 @@ void Game::sendEffects( } void Game::applyCharmRune( - std::shared_ptr targetMonster, std::shared_ptr attackerPlayer, std::shared_ptr target, const int32_t &realDamage + std::shared_ptr targetMonster, const std::shared_ptr &attackerPlayer, std::shared_ptr target, const int32_t &realDamage ) const { if (!targetMonster || !attackerPlayer) { return; @@ -6988,7 +6997,7 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< attackerPlayer = nullptr; } - auto targetPlayer = target->getPlayer(); + const auto &targetPlayer = target->getPlayer(); if (attackerPlayer && targetPlayer && attackerPlayer->getSkull() == SKULL_BLACK && attackerPlayer->getSkullClient(targetPlayer) == SKULL_NONE) { return false; } @@ -7034,7 +7043,7 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< SpectatorHashSet spectators; map.getSpectators(spectators, targetPos, false, true); for (auto spectator : spectators) { - auto tmpPlayer = spectator->getPlayer(); + const auto &tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; @@ -7074,7 +7083,7 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< attackerPlayer = nullptr; } - auto targetPlayer = target->getPlayer(); + const auto &targetPlayer = target->getPlayer(); if (attackerPlayer && targetPlayer && attackerPlayer->getSkull() == SKULL_BLACK && attackerPlayer->getSkullClient(targetPlayer) == SKULL_NONE) { return false; } @@ -7134,7 +7143,7 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< SpectatorHashSet spectators; map.getSpectators(spectators, targetPos, false, true); for (auto spectator : spectators) { - auto tmpPlayer = spectator->getPlayer(); + const auto &tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; @@ -7190,32 +7199,32 @@ void Game::addCreatureHealth(std::shared_ptr target) { void Game::addCreatureHealth(const SpectatorHashSet &spectators, std::shared_ptr target) { uint8_t healthPercent = std::ceil((static_cast(target->getHealth()) / std::max(target->getMaxHealth(), 1)) * 100); - if (std::shared_ptr targetPlayer = target->getPlayer()) { + if (const auto &targetPlayer = target->getPlayer()) { if (Party* party = targetPlayer->getParty()) { party->updatePlayerHealth(targetPlayer, target, healthPercent); } } else if (std::shared_ptr master = target->getMaster()) { - if (std::shared_ptr masterPlayer = master->getPlayer()) { + if (const auto &masterPlayer = master->getPlayer()) { if (Party* party = masterPlayer->getParty()) { party->updatePlayerHealth(masterPlayer, target, healthPercent); } } } for (std::shared_ptr spectator : spectators) { - if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendCreatureHealth(target); } } } -void Game::addPlayerMana(std::shared_ptr target) { +void Game::addPlayerMana(const std::shared_ptr &target) { if (Party* party = target->getParty()) { uint8_t manaPercent = std::ceil((static_cast(target->getMana()) / std::max(target->getMaxMana(), 1)) * 100); party->updatePlayerMana(target, manaPercent); } } -void Game::addPlayerVocation(std::shared_ptr target) { +void Game::addPlayerVocation(const std::shared_ptr &target) { if (Party* party = target->getParty()) { party->updatePlayerVocation(target); } @@ -7224,7 +7233,7 @@ void Game::addPlayerVocation(std::shared_ptr target) { map.getSpectators(spectators, target->getPosition(), true, true); for (auto spectator : spectators) { - if (auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendPlayerVocation(target); } } @@ -7238,7 +7247,7 @@ void Game::addMagicEffect(const Position &pos, uint16_t effect) { void Game::addMagicEffect(const SpectatorHashSet &spectators, const Position &pos, uint16_t effect) { for (auto spectator : spectators) { - if (auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendMagicEffect(pos, effect); } } @@ -7252,7 +7261,7 @@ void Game::removeMagicEffect(const Position &pos, uint16_t effect) { void Game::removeMagicEffect(const SpectatorHashSet &spectators, const Position &pos, uint16_t effect) { for (auto spectator : spectators) { - if (const auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->removeMagicEffect(pos, effect); } } @@ -7267,7 +7276,7 @@ void Game::addDistanceEffect(const Position &fromPos, const Position &toPos, uin void Game::addDistanceEffect(const SpectatorHashSet &spectators, const Position &fromPos, const Position &toPos, uint16_t effect) { for (auto spectator : spectators) { - if (auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendDistanceShoot(fromPos, toPos, effect); } } @@ -7417,7 +7426,7 @@ void Game::updateCreatureWalkthrough(std::shared_ptr creature) { SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); for (auto spectator : spectators) { - auto tmpPlayer = spectator->getPlayer(); + const auto &tmpPlayer = spectator->getPlayer(); tmpPlayer->sendCreatureWalkthrough(creature, tmpPlayer->canWalkthroughEx(creature)); } } @@ -7434,7 +7443,7 @@ void Game::updateCreatureSkull(std::shared_ptr creature) { } } -void Game::updatePlayerShield(std::shared_ptr player) { +void Game::updatePlayerShield(const std::shared_ptr &player) { SpectatorHashSet spectators; map.getSpectators(spectators, player->getPosition(), true, true); for (auto spectator : spectators) { @@ -7467,7 +7476,7 @@ void Game::updateCreatureType(std::shared_ptr creature) { map.getSpectators(spectators, creature->getPosition(), true, true); if (creatureType == CREATURETYPE_SUMMON_OTHERS) { for (auto spectator : spectators) { - auto player = spectator->getPlayer(); + const auto &player = spectator->getPlayer(); if (!player) { continue; } @@ -7480,7 +7489,7 @@ void Game::updateCreatureType(std::shared_ptr creature) { } } else { for (auto spectator : spectators) { - if (auto player = spectator->getPlayer()) { + if (const auto &player = spectator->getPlayer()) { player->sendCreatureType(creature, creatureType); } } @@ -7558,12 +7567,12 @@ void Game::playerInviteToParty(uint32_t playerId, uint32_t invitedId) { return; } - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } - std::shared_ptr invitedPlayer = getPlayerByID(invitedId); + const auto &invitedPlayer = getPlayerByID(invitedId); if (!invitedPlayer || invitedPlayer->isInviting(player)) { return; } @@ -7585,7 +7594,7 @@ void Game::playerInviteToParty(uint32_t playerId, uint32_t invitedId) { party->invitePlayer(invitedPlayer); } -void Game::updatePlayerHelpers(std::shared_ptr player) { +void Game::updatePlayerHelpers(const std::shared_ptr &player) { if (!player) { return; } @@ -7604,12 +7613,12 @@ void Game::updatePlayerHelpers(std::shared_ptr player) { } void Game::playerJoinParty(uint32_t playerId, uint32_t leaderId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } - std::shared_ptr leader = getPlayerByID(leaderId); + const auto &leader = getPlayerByID(leaderId); if (!leader || !leader->isInviting(player)) { return; } @@ -7628,7 +7637,7 @@ void Game::playerJoinParty(uint32_t playerId, uint32_t leaderId) { } void Game::playerRevokePartyInvitation(uint32_t playerId, uint32_t invitedId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -7638,7 +7647,7 @@ void Game::playerRevokePartyInvitation(uint32_t playerId, uint32_t invitedId) { return; } - std::shared_ptr invitedPlayer = getPlayerByID(invitedId); + const auto &invitedPlayer = getPlayerByID(invitedId); if (!invitedPlayer || !player->isInviting(invitedPlayer)) { return; } @@ -7647,7 +7656,7 @@ void Game::playerRevokePartyInvitation(uint32_t playerId, uint32_t invitedId) { } void Game::playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -7657,7 +7666,7 @@ void Game::playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId) { return; } - std::shared_ptr newLeader = getPlayerByID(newLeaderId); + const auto &newLeader = getPlayerByID(newLeaderId); if (!newLeader || !player->isPartner(newLeader)) { return; } @@ -7666,7 +7675,7 @@ void Game::playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId) { } void Game::playerLeaveParty(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -7680,7 +7689,7 @@ void Game::playerLeaveParty(uint32_t playerId) { } void Game::playerEnableSharedPartyExperience(uint32_t playerId, bool sharedExpActive) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -7695,7 +7704,7 @@ void Game::playerEnableSharedPartyExperience(uint32_t playerId, bool sharedExpAc } void Game::sendGuildMotd(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -7707,7 +7716,7 @@ void Game::sendGuildMotd(uint32_t playerId) { } void Game::kickPlayer(uint32_t playerId, bool displayEffect) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -7715,7 +7724,7 @@ void Game::kickPlayer(uint32_t playerId, bool displayEffect) { player->removePlayer(displayEffect); } -void Game::playerCyclopediaCharacterInfo(std::shared_ptr player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page) { +void Game::playerCyclopediaCharacterInfo(const std::shared_ptr &player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page) { uint32_t playerGUID = player->getGUID(); if (characterID != playerGUID) { // For now allow viewing only our character since we don't have tournaments supported @@ -7740,7 +7749,7 @@ void Game::playerCyclopediaCharacterInfo(std::shared_ptr player, uint32_ uint32_t playerID = player->getID(); std::function callback = [playerID, page, entriesPerPage](DBResult_ptr result, bool) { - std::shared_ptr player = g_game().getPlayerByID(playerID); + const auto &player = g_game().getPlayerByID(playerID); if (!player) { return; } @@ -7805,7 +7814,7 @@ void Game::playerCyclopediaCharacterInfo(std::shared_ptr player, uint32_ uint32_t playerID = player->getID(); std::function callback = [playerID, page, entriesPerPage](DBResult_ptr result, bool) { - std::shared_ptr player = g_game().getPlayerByID(playerID); + const auto &player = g_game().getPlayerByID(playerID); if (!player) { return; } @@ -7875,7 +7884,7 @@ void Game::playerCyclopediaCharacterInfo(std::shared_ptr player, uint32_ } } -void Game::playerHighscores(std::shared_ptr player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &, uint16_t page, uint8_t entriesPerPage) { +void Game::playerHighscores(const std::shared_ptr &player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &, uint16_t page, uint8_t entriesPerPage) { if (player->hasAsyncOngoingTask(PlayerAsyncTask_Highscore)) { return; } @@ -7959,7 +7968,7 @@ void Game::playerHighscores(std::shared_ptr player, HighscoreType_t type uint32_t playerID = player->getID(); std::function callback = [playerID, category, vocation, entriesPerPage](DBResult_ptr result, bool) { - std::shared_ptr player = g_game().getPlayerByID(playerID); + const auto &player = g_game().getPlayerByID(playerID); if (!player) { return; } @@ -7994,7 +8003,7 @@ void Game::playerHighscores(std::shared_ptr player, HighscoreType_t type } void Game::playerReportRuleViolationReport(uint32_t playerId, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8004,7 +8013,7 @@ void Game::playerReportRuleViolationReport(uint32_t playerId, const std::string } void Game::playerReportBug(uint32_t playerId, const std::string &message, const Position &position, uint8_t category) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8014,7 +8023,7 @@ void Game::playerReportBug(uint32_t playerId, const std::string &message, const } void Game::playerDebugAssert(uint32_t playerId, const std::string &assertLine, const std::string &date, const std::string &description, const std::string &comment) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8029,7 +8038,7 @@ void Game::playerDebugAssert(uint32_t playerId, const std::string &assertLine, c } void Game::playerPreyAction(uint32_t playerId, uint8_t slot, uint8_t action, uint8_t option, int8_t index, uint16_t raceId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8038,7 +8047,7 @@ void Game::playerPreyAction(uint32_t playerId, uint8_t slot, uint8_t action, uin } void Game::playerTaskHuntingAction(uint32_t playerId, uint8_t slot, uint8_t action, bool upgrade, uint16_t raceId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8047,7 +8056,7 @@ void Game::playerTaskHuntingAction(uint32_t playerId, uint8_t slot, uint8_t acti } void Game::playerNpcGreet(uint32_t playerId, uint32_t npcId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8071,7 +8080,7 @@ void Game::playerNpcGreet(uint32_t playerId, uint32_t npcId) { } void Game::playerLeaveMarket(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8080,7 +8089,7 @@ void Game::playerLeaveMarket(uint32_t playerId) { } void Game::playerBrowseMarket(uint32_t playerId, uint16_t itemId, uint8_t tier) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8105,7 +8114,7 @@ void Game::playerBrowseMarket(uint32_t playerId, uint16_t itemId, uint8_t tier) } void Game::playerBrowseMarketOwnOffers(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8120,7 +8129,7 @@ void Game::playerBrowseMarketOwnOffers(uint32_t playerId) { } void Game::playerBrowseMarketOwnHistory(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8206,7 +8215,7 @@ namespace { } } // namespace -bool checkCanInitCreateMarketOffer(std::shared_ptr player, uint8_t type, const ItemType &it, uint16_t amount, uint64_t price, std::ostringstream &offerStatus) { +bool checkCanInitCreateMarketOffer(const std::shared_ptr &player, uint8_t type, const ItemType &it, uint16_t amount, uint64_t price, std::ostringstream &offerStatus) { if (!player) { offerStatus << "Failed to load player"; return false; @@ -8272,7 +8281,7 @@ void Game::playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t ite // Initialize variables // Before creating the offer we will compare it with the RETURN VALUE ERROR std::ostringstream offerStatus; - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); const ItemType &it = Item::items[itemId]; // Make sure everything is ok before the create market offer starts @@ -8364,7 +8373,7 @@ void Game::playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t ite } void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || !player->getAccount()) { return; } @@ -8448,7 +8457,7 @@ void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter, uint16_t amount) { std::ostringstream offerStatus; - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || !player->getAccount()) { offerStatus << "Failed to load player"; return; @@ -8492,14 +8501,10 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 return; } - std::shared_ptr buyerPlayer = getPlayerByGUID(offer.playerId); + const auto buyerPlayer = getPlayerByGUID(offer.playerId, true); if (!buyerPlayer) { - buyerPlayer = std::make_shared(nullptr); - if (!IOLoginData::loadPlayerById(buyerPlayer, offer.playerId)) { - - offerStatus << "Failed to load buyer player " << player->getName(); - return; - } + offerStatus << "Failed to load buyer player " << player->getName(); + return; } if (!buyerPlayer->getAccount()) { @@ -8597,14 +8602,10 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 IOLoginData::savePlayer(buyerPlayer); } } else if (offer.type == MARKETACTION_SELL) { - std::shared_ptr sellerPlayer = getPlayerByGUID(offer.playerId); + const auto sellerPlayer = getPlayerByGUID(offer.playerId, true); if (!sellerPlayer) { - sellerPlayer = std::make_shared(nullptr); - if (!IOLoginData::loadPlayerById(sellerPlayer, offer.playerId)) { - offerStatus << "Failed to load seller player"; - - return; - } + offerStatus << "Failed to load seller player"; + return; } if (player == sellerPlayer || player->getAccount() == sellerPlayer->getAccount()) { @@ -8723,7 +8724,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 } void Game::parsePlayerExtendedOpcode(uint32_t playerId, uint8_t opcode, const std::string &buffer) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8742,7 +8743,7 @@ void Game::forceRemoveCondition(uint32_t creatureId, ConditionType_t conditionTy creature->removeCondition(conditionType, conditionId, true); } -void Game::sendOfflineTrainingDialog(std::shared_ptr player) { +void Game::sendOfflineTrainingDialog(const std::shared_ptr &player) { if (!player) { return; } @@ -8753,7 +8754,7 @@ void Game::sendOfflineTrainingDialog(std::shared_ptr player) { } void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, uint8_t button, uint8_t choice) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8787,7 +8788,7 @@ void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, ui } void Game::playerForgeFuseItems(uint32_t playerId, uint16_t itemId, uint8_t tier, bool usedCore, bool reduceTierLoss) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8812,7 +8813,7 @@ void Game::playerForgeFuseItems(uint32_t playerId, uint16_t itemId, uint8_t tier } void Game::playerForgeTransferItemTier(uint32_t playerId, uint16_t donorItemId, uint8_t tier, uint16_t receiveItemId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8821,7 +8822,7 @@ void Game::playerForgeTransferItemTier(uint32_t playerId, uint16_t donorItemId, } void Game::playerForgeResourceConversion(uint32_t playerId, uint8_t action) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8836,7 +8837,7 @@ void Game::playerForgeResourceConversion(uint32_t playerId, uint8_t action) { } void Game::playerBrowseForgeHistory(uint32_t playerId, uint8_t page) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8851,7 +8852,7 @@ void Game::playerBrowseForgeHistory(uint32_t playerId, uint8_t page) { } void Game::playerBosstiarySlot(uint32_t playerId, uint8_t slotId, uint32_t selectedBossId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -8877,7 +8878,7 @@ void Game::playerBosstiarySlot(uint32_t playerId, uint8_t slotId, uint32_t selec } void Game::playerSetMonsterPodium(uint32_t playerId, uint32_t monsterRaceId, const Position &pos, uint8_t stackPos, const uint16_t itemId, uint8_t direction, const std::pair &podiumAndMonsterVisible) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || pos.x == 0xFFFF) { return; } @@ -8973,14 +8974,14 @@ void Game::playerSetMonsterPodium(uint32_t playerId, uint32_t monsterRaceId, con // Send to client for (auto spectator : spectators) { - if (auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendUpdateTileItem(tile, pos, item); } } } void Game::playerRotatePodium(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -9065,7 +9066,7 @@ void Game::playerRotatePodium(uint32_t playerId, const Position &pos, uint8_t st } void Game::playerRequestInventoryImbuements(uint32_t playerId, bool isTrackerOpen) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player || player->isRemoved()) { return; } @@ -9097,7 +9098,7 @@ void Game::playerRequestInventoryImbuements(uint32_t playerId, bool isTrackerOpe } void Game::playerOpenWheel(uint32_t playerId, uint32_t ownerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -9117,7 +9118,7 @@ void Game::playerOpenWheel(uint32_t playerId, uint32_t ownerId) { } void Game::playerSaveWheel(uint32_t playerId, NetworkMessage &msg) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -9135,7 +9136,7 @@ void Game::playerSaveWheel(uint32_t playerId, NetworkMessage &msg) { ********************/ void Game::updatePlayerSaleItems(uint32_t playerId) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -9145,14 +9146,14 @@ void Game::updatePlayerSaleItems(uint32_t playerId) { player->setScheduledSaleUpdate(false); } -void Game::addPlayer(std::shared_ptr player) { +void Game::addPlayer(const std::shared_ptr &player) { const std::string &lowercase_name = asLowerCaseString(player->getName()); mappedPlayerNames[lowercase_name] = player; wildcardTree.insert(lowercase_name); players[player->getID()] = player; } -void Game::removePlayer(std::shared_ptr player) { +void Game::removePlayer(const std::shared_ptr &player) { const std::string &lowercase_name = asLowerCaseString(player->getName()); mappedPlayerNames.erase(lowercase_name); wildcardTree.remove(lowercase_name); @@ -9328,7 +9329,7 @@ void Game::sendUpdateCreature(std::shared_ptr creature) { SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true); for (auto spectator : spectators) { - if (const auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendUpdateCreature(creature); } } @@ -9640,7 +9641,7 @@ bool Game::addInfluencedMonster(std::shared_ptr monster) { return false; } -bool Game::addItemStoreInbox(std::shared_ptr player, uint32_t itemId) { +bool Game::addItemStoreInbox(const std::shared_ptr &player, uint32_t itemId) { std::shared_ptr decoKit = Item::CreateItem(ITEM_DECORATION_KIT, 1); if (!decoKit) { return false; @@ -9672,7 +9673,7 @@ bool Game::addItemStoreInbox(std::shared_ptr player, uint32_t itemId) { return true; } -void Game::addPlayerUniqueLogin(std::shared_ptr player) { +void Game::addPlayerUniqueLogin(const std::shared_ptr &player) { if (!player) { g_logger().error("Attempted to add null player to unique player names list"); return; @@ -9702,7 +9703,7 @@ void Game::removePlayerUniqueLogin(const std::string &playerName) { m_uniqueLoginPlayerNames.erase(lowercase_name); } -void Game::removePlayerUniqueLogin(std::shared_ptr player) { +void Game::removePlayerUniqueLogin(const std::shared_ptr &player) { if (!player) { g_logger().error("Attempted to remove null player from unique player names list."); return; @@ -9713,7 +9714,7 @@ void Game::removePlayerUniqueLogin(std::shared_ptr player) { } void Game::playerCheckActivity(const std::string &playerName, int interval) { - std::shared_ptr player = getPlayerUniqueLogin(playerName); + const auto &player = getPlayerUniqueLogin(playerName); if (!player) { return; } @@ -9746,7 +9747,7 @@ void Game::playerCheckActivity(const std::string &playerName, int interval) { } void Game::playerRewardChestCollect(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, uint32_t maxMoveItems /* = 0*/) { - std::shared_ptr player = getPlayerByID(playerId); + const auto &player = getPlayerByID(playerId); if (!player) { return; } @@ -9788,7 +9789,7 @@ void Game::playerRewardChestCollect(uint32_t playerId, const Position &pos, uint } } -bool Game::tryRetrieveStashItems(std::shared_ptr player, std::shared_ptr item) { +bool Game::tryRetrieveStashItems(const std::shared_ptr &player, std::shared_ptr item) { return internalCollectLootItems(player, item, OBJECTCATEGORY_STASHRETRIEVE) == RETURNVALUE_NOERROR; } diff --git a/src/game/game.hpp b/src/game/game.hpp index eb6de64001a..0858546d946 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -98,8 +98,8 @@ class Game { teamFinderMap.erase(leaderGuid); } - std::shared_ptr internalGetCylinder(std::shared_ptr player, const Position &pos); - std::shared_ptr internalGetThing(std::shared_ptr player, const Position &pos, int32_t index, uint32_t itemId, StackPosType_t type); + std::shared_ptr internalGetCylinder(const std::shared_ptr &player, const Position &pos); + std::shared_ptr internalGetThing(const std::shared_ptr &player, const Position &pos, int32_t index, uint32_t itemId, StackPosType_t type); static void internalGetPosition(std::shared_ptr item, Position &pos, uint8_t &stackpos); static std::string getTradeErrorDescription(ReturnValue ret, std::shared_ptr item); @@ -118,7 +118,7 @@ class Game { std::shared_ptr getPlayerByName(const std::string &s, bool allowOffline = false); - std::shared_ptr getPlayerByGUID(const uint32_t &guid); + std::shared_ptr getPlayerByGUID(const uint32_t &guid, bool allowOffline = false); ReturnValue getPlayerByNameWildcard(const std::string &s, std::shared_ptr &player); @@ -176,14 +176,14 @@ class Game { ReturnValue internalMoveCreature(std::shared_ptr creature, Direction direction, uint32_t flags = 0); ReturnValue internalMoveCreature(const std::shared_ptr &creature, const std::shared_ptr &toTile, uint32_t flags = 0); - ReturnValue checkMoveItemToCylinder(std::shared_ptr player, std::shared_ptr fromCylinder, std::shared_ptr toCylinder, std::shared_ptr item, Position toPos); + ReturnValue checkMoveItemToCylinder(const std::shared_ptr &player, std::shared_ptr fromCylinder, std::shared_ptr toCylinder, std::shared_ptr item, Position toPos); ReturnValue internalMoveItem(std::shared_ptr fromCylinder, std::shared_ptr toCylinder, int32_t index, std::shared_ptr item, uint32_t count, std::shared_ptr* movedItem, uint32_t flags = 0, std::shared_ptr actor = nullptr, std::shared_ptr tradeItem = nullptr, bool checkTile = true); ReturnValue internalAddItem(std::shared_ptr toCylinder, std::shared_ptr item, int32_t index = INDEX_WHEREEVER, uint32_t flags = 0, bool test = false); ReturnValue internalAddItem(std::shared_ptr toCylinder, std::shared_ptr item, int32_t index, uint32_t flags, bool test, uint32_t &remainderCount); ReturnValue internalRemoveItem(std::shared_ptr item, int32_t count = -1, bool test = false, uint32_t flags = 0, bool force = false); - ReturnValue internalPlayerAddItem(std::shared_ptr player, std::shared_ptr item, bool dropOnMap = true, Slots_t slot = CONST_SLOT_WHEREEVER); + ReturnValue internalPlayerAddItem(const std::shared_ptr &player, std::shared_ptr item, bool dropOnMap = true, Slots_t slot = CONST_SLOT_WHEREEVER); std::shared_ptr findItemOfType(std::shared_ptr cylinder, uint16_t itemId, bool depthSearch = true, int32_t subType = -1) const; @@ -241,30 +241,30 @@ class Game { void playerRequestInventoryImbuements(uint32_t playerId, bool isTrackerOpen); - bool addItemStoreInbox(std::shared_ptr player, uint32_t itemId); + bool addItemStoreInbox(const std::shared_ptr &player, uint32_t itemId); void playerRewardChestCollect(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, uint32_t maxMoveItems = 0); void playerReportRuleViolationReport(uint32_t playerId, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation); - void playerCyclopediaCharacterInfo(std::shared_ptr player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page); + void playerCyclopediaCharacterInfo(const std::shared_ptr &player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page); - void playerHighscores(std::shared_ptr player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &worldName, uint16_t page, uint8_t entriesPerPage); + void playerHighscores(const std::shared_ptr &player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &worldName, uint16_t page, uint8_t entriesPerPage); void updatePlayerSaleItems(uint32_t playerId); - bool internalStartTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr tradeItem); - void internalCloseTrade(std::shared_ptr player); - bool playerBroadcastMessage(std::shared_ptr player, const std::string &text) const; + bool internalStartTrade(const std::shared_ptr &player, const std::shared_ptr &partner, std::shared_ptr tradeItem); + void internalCloseTrade(const std::shared_ptr &player); + bool playerBroadcastMessage(const std::shared_ptr &player, const std::string &text) const; void broadcastMessage(const std::string &text, MessageClasses type) const; // Implementation of player invoked events void playerTeleport(uint32_t playerId, const Position &pos); void playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count); void playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, const Position &movingCreatureOrigPos, const Position &toPos); - void playerMoveCreature(std::shared_ptr playerId, std::shared_ptr movingCreature, const Position &movingCreatureOrigPos, std::shared_ptr toTile); + void playerMoveCreature(const std::shared_ptr &playerId, std::shared_ptr movingCreature, const Position &movingCreatureOrigPos, std::shared_ptr toTile); void playerMoveItemByPlayerID(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count); - void playerMoveItem(std::shared_ptr player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder); + void playerMoveItem(const std::shared_ptr &player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder); void playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier = false, uint8_t tier = 0); void playerMove(uint32_t playerId, Direction direction); void forcePlayerMove(uint32_t playerId, Direction direction); @@ -312,7 +312,7 @@ class Game { void playerLookAt(uint32_t playerId, uint16_t itemId, const Position &pos, uint8_t stackPos); void playerLookInBattleList(uint32_t playerId, uint32_t creatureId); void playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, std::shared_ptr defaultItem = nullptr, bool lootAllCorpses = false, bool autoLoot = false); - void playerLootAllCorpses(std::shared_ptr player, const Position &pos, bool lootAllCorpses); + void playerLootAllCorpses(const std::shared_ptr &player, const Position &pos, bool lootAllCorpses); void playerSetLootContainer(uint32_t playerId, ObjectCategory_t category, const Position &pos, uint16_t itemId, uint8_t stackPos); void playerClearLootContainer(uint32_t playerId, ObjectCategory_t category); ; @@ -325,7 +325,7 @@ class Game { void playerRequestDepotSearchItem(uint32_t playerId, uint16_t itemId, uint8_t tier); void playerRequestDepotSearchRetrieve(uint32_t playerId, uint16_t itemId, uint8_t tier, uint8_t type); void playerRequestOpenContainerFromDepotSearch(uint32_t playerId, const Position &pos); - void playerMoveThingFromDepotSearch(std::shared_ptr player, uint16_t itemId, uint8_t tier, uint8_t count, const Position &fromPos, const Position &toPos, bool allItems = false); + void playerMoveThingFromDepotSearch(const std::shared_ptr &player, uint16_t itemId, uint8_t tier, uint8_t count, const Position &fromPos, const Position &toPos, bool allItems = false); void playerRequestAddVip(uint32_t playerId, const std::string &name); void playerRequestRemoveVip(uint32_t playerId, uint32_t guid); @@ -359,7 +359,7 @@ class Game { void playerOpenWheel(uint32_t playerId, uint32_t ownerId); void playerSaveWheel(uint32_t playerId, NetworkMessage &msg); - void updatePlayerHelpers(std::shared_ptr player); + void updatePlayerHelpers(const std::shared_ptr &player); void cleanup(); void shutdown(); @@ -390,7 +390,7 @@ class Game { void updateCreatureIcon(const std::shared_ptr creature); void reloadCreature(const std::shared_ptr creature); void updateCreatureSkull(std::shared_ptr player); - void updatePlayerShield(std::shared_ptr player); + void updatePlayerShield(const std::shared_ptr &player); void updateCreatureType(std::shared_ptr creature); void updateCreatureWalkthrough(const std::shared_ptr creature); @@ -410,16 +410,16 @@ class Game { void combatGetTypeInfo(CombatType_t combatType, std::shared_ptr target, TextColor_t &color, uint16_t &effect); // Hazard combat helpers - void handleHazardSystemAttack(CombatDamage &damage, std::shared_ptr player, const std::shared_ptr monster, bool isPlayerAttacker); - void notifySpectators(const SpectatorHashSet &spectators, const Position &targetPos, std::shared_ptr attackerPlayer, std::shared_ptr targetMonster); + void handleHazardSystemAttack(CombatDamage &damage, const std::shared_ptr &player, const std::shared_ptr monster, bool isPlayerAttacker); + void notifySpectators(const SpectatorHashSet &spectators, const Position &targetPos, const std::shared_ptr &attackerPlayer, std::shared_ptr targetMonster); // Wheel of destiny combat helpers - void applyWheelOfDestinyHealing(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr target); - void applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr target) const; + void applyWheelOfDestinyHealing(CombatDamage &damage, const std::shared_ptr &attackerPlayer, std::shared_ptr target); + void applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, const std::shared_ptr &attackerPlayer, std::shared_ptr target) const; int32_t applyHealthChange(CombatDamage &damage, std::shared_ptr target) const; bool combatChangeHealth(std::shared_ptr attacker, std::shared_ptr target, CombatDamage &damage, bool isEvent = false); - void applyCharmRune(std::shared_ptr targetMonster, std::shared_ptr attackerPlayer, std::shared_ptr target, const int32_t &realDamage) const; + void applyCharmRune(std::shared_ptr targetMonster, const std::shared_ptr &attackerPlayer, std::shared_ptr target, const int32_t &realDamage) const; void applyManaLeech( std::shared_ptr attackerPlayer, std::shared_ptr targetMonster, std::shared_ptr target, const CombatDamage &damage, const int32_t &realDamage @@ -434,8 +434,8 @@ class Game { // Animation help functions void addCreatureHealth(const std::shared_ptr target); static void addCreatureHealth(const SpectatorHashSet &spectators, const std::shared_ptr target); - void addPlayerMana(const std::shared_ptr target); - void addPlayerVocation(const std::shared_ptr target); + void addPlayerMana(const std::shared_ptr &target); + void addPlayerVocation(const std::shared_ptr &target); void addMagicEffect(const Position &pos, uint16_t effect); static void addMagicEffect(const SpectatorHashSet &spectators, const Position &pos, uint16_t effect); void removeMagicEffect(const Position &pos, uint16_t effect); @@ -461,7 +461,7 @@ class Game { motdNum++; } - void sendOfflineTrainingDialog(std::shared_ptr player); + void sendOfflineTrainingDialog(const std::shared_ptr &player); const std::map> &getItemsPrice() const { return itemsPriceMap; @@ -480,8 +480,8 @@ class Game { return itemsClassifications; } - void addPlayer(std::shared_ptr player); - void removePlayer(std::shared_ptr player); + void addPlayer(const std::shared_ptr &player); + void removePlayer(const std::shared_ptr &player); void addNpc(std::shared_ptr npc); void removeNpc(std::shared_ptr npc); @@ -528,8 +528,8 @@ class Game { tilesToClean.clear(); } - void playerInspectItem(std::shared_ptr player, const Position &pos); - void playerInspectItem(std::shared_ptr player, uint16_t itemId, uint8_t itemCount, bool cyclopedia); + void playerInspectItem(const std::shared_ptr &player, const Position &pos); + void playerInspectItem(const std::shared_ptr &player, uint16_t itemId, uint8_t itemCount, bool cyclopedia); void addCharmRune(const std::shared_ptr charm) { CharmList.push_back(charm); @@ -587,7 +587,7 @@ class Game { * * @param player A pointer to the Player object to add. */ - void addPlayerUniqueLogin(std::shared_ptr player); + void addPlayerUniqueLogin(const std::shared_ptr &player); /** * @brief Gets a player from the unique login map using their name. @@ -616,7 +616,7 @@ class Game { * * @param player A pointer to the Player object to remove. */ - void removePlayerUniqueLogin(std::shared_ptr player); + void removePlayerUniqueLogin(const std::shared_ptr &player); void playerCheckActivity(const std::string &playerName, int interval); /** @@ -629,7 +629,7 @@ class Game { * @param item Pointer to the item to be checked. * @return True if stash items can be retrieved, false otherwise. */ - bool tryRetrieveStashItems(std::shared_ptr player, std::shared_ptr item); + bool tryRetrieveStashItems(const std::shared_ptr &player, std::shared_ptr item); ReturnValue beforeCreatureZoneChange(std::shared_ptr creature, const phmap::parallel_flat_hash_set> &fromZones, const phmap::parallel_flat_hash_set> &toZones, bool force = false) const; void afterCreatureZoneChange(std::shared_ptr creature, const phmap::parallel_flat_hash_set> &fromZones, const phmap::parallel_flat_hash_set> &toZones) const; @@ -642,11 +642,11 @@ class Game { std::set fiendishMonsters; std::set influencedMonsters; void checkImbuements(); - bool playerSaySpell(std::shared_ptr player, SpeakClasses type, const std::string &text); - void playerWhisper(std::shared_ptr player, const std::string &text); - bool playerYell(std::shared_ptr player, const std::string &text); - bool playerSpeakTo(std::shared_ptr player, SpeakClasses type, const std::string &receiver, const std::string &text); - void playerSpeakToNpc(std::shared_ptr player, const std::string &text); + bool playerSaySpell(const std::shared_ptr &player, SpeakClasses type, const std::string &text); + void playerWhisper(const std::shared_ptr &player, const std::string &text); + bool playerYell(const std::shared_ptr &player, const std::string &text); + bool playerSpeakTo(const std::shared_ptr &player, SpeakClasses type, const std::string &receiver, const std::string &text); + void playerSpeakToNpc(const std::shared_ptr &player, const std::string &text); std::shared_ptr createPlayerTask(uint32_t delay, std::function f, std::string context) const; /** @@ -654,7 +654,7 @@ class Game { * \param player Player pointer * \param corpse Container pointer to be looted */ - void internalQuickLootCorpse(std::shared_ptr player, std::shared_ptr corpse); + void internalQuickLootCorpse(const std::shared_ptr &player, std::shared_ptr corpse); /** * @brief Finds the container for loot based on the given parameters. @@ -668,7 +668,7 @@ class Game { * * @return Pointer to the loot container or nullptr if not found. */ - std::shared_ptr findLootContainer(std::shared_ptr player, bool &fallbackConsumed, ObjectCategory_t category); + std::shared_ptr findLootContainer(const std::shared_ptr &player, bool &fallbackConsumed, ObjectCategory_t category); /** * @brief Finds the next available sub-container within a container. @@ -689,7 +689,7 @@ class Game { * @param fallbackConsumed Reference to a boolean flag indicating whether a fallback has been consumed. * @return True if fallback logic was handled, false otherwise. */ - bool handleFallbackLogic(std::shared_ptr player, std::shared_ptr &lootContainer, ContainerIterator &containerIterator, const bool &fallbackConsumed); + bool handleFallbackLogic(const std::shared_ptr &player, std::shared_ptr &lootContainer, ContainerIterator &containerIterator, const bool &fallbackConsumed); /** * @brief Processes the movement or addition of an item to a loot container. @@ -700,7 +700,7 @@ class Game { * @param player Pointer to the player object. * @return Return value indicating success or error. */ - ReturnValue processMoveOrAddItemToLootContainer(std::shared_ptr item, std::shared_ptr lootContainer, uint32_t &remainderCount, std::shared_ptr player); + ReturnValue processMoveOrAddItemToLootContainer(std::shared_ptr item, std::shared_ptr lootContainer, uint32_t &remainderCount, const std::shared_ptr &player); /** * @brief Processes loot items and places them into the appropriate containers. @@ -711,7 +711,7 @@ class Game { * @param fallbackConsumed Reference to a boolean flag indicating whether a fallback has been consumed. * @return Return value indicating success or error. */ - ReturnValue processLootItems(std::shared_ptr player, std::shared_ptr lootContainer, std::shared_ptr item, bool &fallbackConsumed); + ReturnValue processLootItems(const std::shared_ptr &player, std::shared_ptr lootContainer, std::shared_ptr item, bool &fallbackConsumed); /** * @brief Internally collects loot items from a given item and places them into the loot container. @@ -721,7 +721,7 @@ class Game { * @param category Category of the item (default is OBJECTCATEGORY_DEFAULT). * @return Return value indicating success or error. */ - ReturnValue internalCollectLootItems(std::shared_ptr player, std::shared_ptr item, ObjectCategory_t category = OBJECTCATEGORY_DEFAULT); + ReturnValue internalCollectLootItems(const std::shared_ptr &player, std::shared_ptr item, ObjectCategory_t category = OBJECTCATEGORY_DEFAULT); /** * @brief Collects items from the reward chest. @@ -730,7 +730,7 @@ class Game { * @param maxMoveItems Maximum number of items to move (default is 0, which means no limit). * @return Return value indicating success or error. */ - ReturnValue collectRewardChestItems(std::shared_ptr player, uint32_t maxMoveItems = 0); + ReturnValue collectRewardChestItems(const std::shared_ptr &player, uint32_t maxMoveItems = 0); phmap::flat_hash_map> m_uniqueLoginPlayerNames; phmap::flat_hash_map> players; @@ -816,7 +816,7 @@ class Game { const SpectatorHashSet &spectators, int32_t realDamage ); - void updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, std::shared_ptr player) const; + void updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, const std::shared_ptr &player) const; void sendEffects( std::shared_ptr target, const CombatDamage &damage, const Position &targetPos, @@ -848,7 +848,7 @@ class Game { const std::string &damageString, std::string &spectatorMessage ) const; - void unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* house, std::shared_ptr player); + void unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* house, const std::shared_ptr &player); // Variable members (m_) std::unique_ptr m_IOWheel; diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index b89c7257c63..f5e601e38c6 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -49,7 +49,7 @@ void IOLoginDataLoad::loadItems(ItemsMap &itemsMap, DBResult_ptr result, const s } } -bool IOLoginDataLoad::preLoadPlayer(std::shared_ptr player, const std::string &name) { +bool IOLoginDataLoad::preLoadPlayer(const std::shared_ptr & player, const std::string &name) { Database &db = Database::getInstance(); std::ostringstream query; @@ -103,7 +103,7 @@ bool IOLoginDataLoad::preLoadPlayer(std::shared_ptr player, const std::s return true; } -bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr player, DBResult_ptr result) { +bool IOLoginDataLoad::loadPlayerFirst(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return false; @@ -183,7 +183,7 @@ bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr player, DBResult_p return true; } -void IOLoginDataLoad::loadPlayerExperience(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerExperience(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -206,7 +206,7 @@ void IOLoginDataLoad::loadPlayerExperience(std::shared_ptr player, DBRes } } -void IOLoginDataLoad::loadPlayerBlessings(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerBlessings(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -219,7 +219,7 @@ void IOLoginDataLoad::loadPlayerBlessings(std::shared_ptr player, DBResu } } -void IOLoginDataLoad::loadPlayerConditions(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerConditions(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -239,7 +239,7 @@ void IOLoginDataLoad::loadPlayerConditions(std::shared_ptr player, DBRes } } -void IOLoginDataLoad::loadPlayerDefaultOutfit(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerDefaultOutfit(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -270,7 +270,7 @@ void IOLoginDataLoad::loadPlayerDefaultOutfit(std::shared_ptr player, DB player->currentOutfit = player->defaultOutfit; } -void IOLoginDataLoad::loadPlayerSkullSystem(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerSkullSystem(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -292,7 +292,7 @@ void IOLoginDataLoad::loadPlayerSkullSystem(std::shared_ptr player, DBRe } } -void IOLoginDataLoad::loadPlayerSkill(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerSkill(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -314,7 +314,7 @@ void IOLoginDataLoad::loadPlayerSkill(std::shared_ptr player, DBResult_p } } -void IOLoginDataLoad::loadPlayerKills(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerKills(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -333,7 +333,7 @@ void IOLoginDataLoad::loadPlayerKills(std::shared_ptr player, DBResult_p } } -void IOLoginDataLoad::loadPlayerGuild(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerGuild(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -383,7 +383,7 @@ void IOLoginDataLoad::loadPlayerGuild(std::shared_ptr player, DBResult_p } } -void IOLoginDataLoad::loadPlayerStashItems(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerStashItems(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -399,7 +399,7 @@ void IOLoginDataLoad::loadPlayerStashItems(std::shared_ptr player, DBRes } } -void IOLoginDataLoad::loadPlayerBestiaryCharms(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerBestiaryCharms(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -452,7 +452,7 @@ void IOLoginDataLoad::loadPlayerBestiaryCharms(std::shared_ptr player, D } } -void IOLoginDataLoad::loadPlayerInstantSpellList(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerInstantSpellList(const std::shared_ptr & player, DBResult_ptr result) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -468,7 +468,7 @@ void IOLoginDataLoad::loadPlayerInstantSpellList(std::shared_ptr player, } } -void IOLoginDataLoad::loadPlayerInventoryItems(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerInventoryItems(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -546,7 +546,7 @@ void IOLoginDataLoad::loadPlayerInventoryItems(std::shared_ptr player, D } } -void IOLoginDataLoad::loadPlayerStoreInbox(std::shared_ptr player) { +void IOLoginDataLoad::loadPlayerStoreInbox(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -557,7 +557,7 @@ void IOLoginDataLoad::loadPlayerStoreInbox(std::shared_ptr player) { } } -void IOLoginDataLoad::loadRewardItems(std::shared_ptr player) { +void IOLoginDataLoad::loadRewardItems(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -575,7 +575,7 @@ void IOLoginDataLoad::loadRewardItems(std::shared_ptr player) { } } -void IOLoginDataLoad::loadPlayerDepotItems(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerDepotItems(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -615,7 +615,7 @@ void IOLoginDataLoad::loadPlayerDepotItems(std::shared_ptr player, DBRes } } -void IOLoginDataLoad::loadPlayerInboxItems(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerInboxItems(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -652,7 +652,7 @@ void IOLoginDataLoad::loadPlayerInboxItems(std::shared_ptr player, DBRes } } -void IOLoginDataLoad::loadPlayerStorageMap(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerStorageMap(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -668,7 +668,7 @@ void IOLoginDataLoad::loadPlayerStorageMap(std::shared_ptr player, DBRes } } -void IOLoginDataLoad::loadPlayerVip(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerVip(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -684,7 +684,7 @@ void IOLoginDataLoad::loadPlayerVip(std::shared_ptr player, DBResult_ptr } } -void IOLoginDataLoad::loadPlayerPreyClass(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerPreyClass(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -731,7 +731,7 @@ void IOLoginDataLoad::loadPlayerPreyClass(std::shared_ptr player, DBResu } } -void IOLoginDataLoad::loadPlayerTaskHuntingClass(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerTaskHuntingClass(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -781,7 +781,7 @@ void IOLoginDataLoad::loadPlayerTaskHuntingClass(std::shared_ptr player, } } -void IOLoginDataLoad::loadPlayerForgeHistory(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerForgeHistory(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -802,7 +802,7 @@ void IOLoginDataLoad::loadPlayerForgeHistory(std::shared_ptr player, DBR } } -void IOLoginDataLoad::loadPlayerBosstiary(std::shared_ptr player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerBosstiary(const std::shared_ptr & player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -834,7 +834,7 @@ void IOLoginDataLoad::loadPlayerBosstiary(std::shared_ptr player, DBResu } } -void IOLoginDataLoad::bindRewardBag(std::shared_ptr player, ItemsMap &rewardItemsMap) { +void IOLoginDataLoad::bindRewardBag(const std::shared_ptr & player, ItemsMap &rewardItemsMap) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -874,7 +874,7 @@ void IOLoginDataLoad::insertItemsIntoRewardBag(const ItemsMap &rewardItemsMap) { } } -void IOLoginDataLoad::loadPlayerInitializeSystem(std::shared_ptr player) { +void IOLoginDataLoad::loadPlayerInitializeSystem(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -888,7 +888,7 @@ void IOLoginDataLoad::loadPlayerInitializeSystem(std::shared_ptr player) player->initializeTaskHunting(); } -void IOLoginDataLoad::loadPlayerUpdateSystem(std::shared_ptr player) { +void IOLoginDataLoad::loadPlayerUpdateSystem(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; diff --git a/src/io/functions/iologindata_load_player.hpp b/src/io/functions/iologindata_load_player.hpp index e8b0b4094de..f36203961ba 100644 --- a/src/io/functions/iologindata_load_player.hpp +++ b/src/io/functions/iologindata_load_player.hpp @@ -13,37 +13,37 @@ class IOLoginDataLoad : public IOLoginData { public: - static bool loadPlayerFirst(std::shared_ptr player, DBResult_ptr result); - static bool preLoadPlayer(std::shared_ptr player, const std::string &name); - static void loadPlayerExperience(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerBlessings(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerConditions(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerDefaultOutfit(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerSkullSystem(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerSkill(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerKills(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerGuild(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerStashItems(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerBestiaryCharms(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerInstantSpellList(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerInventoryItems(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerStoreInbox(std::shared_ptr player); - static void loadPlayerDepotItems(std::shared_ptr player, DBResult_ptr result); - static void loadRewardItems(std::shared_ptr player); - static void loadPlayerInboxItems(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerStorageMap(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerVip(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerPreyClass(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerTaskHuntingClass(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerForgeHistory(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerBosstiary(std::shared_ptr player, DBResult_ptr result); - static void loadPlayerInitializeSystem(std::shared_ptr player); - static void loadPlayerUpdateSystem(std::shared_ptr player); + static bool loadPlayerFirst(const std::shared_ptr & player, DBResult_ptr result); + static bool preLoadPlayer(const std::shared_ptr & player, const std::string &name); + static void loadPlayerExperience(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerBlessings(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerConditions(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerDefaultOutfit(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerSkullSystem(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerSkill(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerKills(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerGuild(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerStashItems(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerBestiaryCharms(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerInstantSpellList(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerInventoryItems(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerStoreInbox(const std::shared_ptr & player); + static void loadPlayerDepotItems(const std::shared_ptr & player, DBResult_ptr result); + static void loadRewardItems(const std::shared_ptr & player); + static void loadPlayerInboxItems(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerStorageMap(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerVip(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerPreyClass(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerTaskHuntingClass(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerForgeHistory(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerBosstiary(const std::shared_ptr & player, DBResult_ptr result); + static void loadPlayerInitializeSystem(const std::shared_ptr & player); + static void loadPlayerUpdateSystem(const std::shared_ptr & player); private: using ItemsMap = std::map, uint32_t>>; - static void bindRewardBag(std::shared_ptr player, ItemsMap &rewardItemsMap); + static void bindRewardBag(const std::shared_ptr & player, ItemsMap &rewardItemsMap); static void insertItemsIntoRewardBag(const ItemsMap &rewardItemsMap); static void loadItems(ItemsMap &itemsMap, DBResult_ptr result, const std::shared_ptr &player); diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index 877c2483786..7a7b00484fc 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -12,7 +12,7 @@ #include "io/functions/iologindata_save_player.hpp" #include "game/game.hpp" -bool IOLoginDataSave::saveItems(std::shared_ptr player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &propWriteStream) { +bool IOLoginDataSave::saveItems(const std::shared_ptr & player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &propWriteStream) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -148,7 +148,7 @@ bool IOLoginDataSave::saveItems(std::shared_ptr player, const ItemBlockL return true; } -bool IOLoginDataSave::savePlayerFirst(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerFirst(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -313,7 +313,7 @@ bool IOLoginDataSave::savePlayerFirst(std::shared_ptr player) { return true; } -bool IOLoginDataSave::savePlayerStash(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerStash(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -339,7 +339,7 @@ bool IOLoginDataSave::savePlayerStash(std::shared_ptr player) { return true; } -bool IOLoginDataSave::savePlayerSpells(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerSpells(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -368,7 +368,7 @@ bool IOLoginDataSave::savePlayerSpells(std::shared_ptr player) { return true; } -bool IOLoginDataSave::savePlayerKills(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerKills(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -397,7 +397,7 @@ bool IOLoginDataSave::savePlayerKills(std::shared_ptr player) { return true; } -bool IOLoginDataSave::savePlayerBestiarySystem(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerBestiarySystem(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -447,7 +447,7 @@ bool IOLoginDataSave::savePlayerBestiarySystem(std::shared_ptr player) { return true; } -bool IOLoginDataSave::savePlayerItem(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerItem(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -479,7 +479,7 @@ bool IOLoginDataSave::savePlayerItem(std::shared_ptr player) { return true; } -bool IOLoginDataSave::savePlayerDepotItems(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerDepotItems(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -514,7 +514,7 @@ bool IOLoginDataSave::savePlayerDepotItems(std::shared_ptr player) { return true; } -bool IOLoginDataSave::saveRewardItems(std::shared_ptr player) { +bool IOLoginDataSave::saveRewardItems(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -548,7 +548,7 @@ bool IOLoginDataSave::saveRewardItems(std::shared_ptr player) { return true; } -bool IOLoginDataSave::savePlayerInbox(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerInbox(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -576,7 +576,7 @@ bool IOLoginDataSave::savePlayerInbox(std::shared_ptr player) { return true; } -bool IOLoginDataSave::savePlayerPreyClass(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerPreyClass(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -631,7 +631,7 @@ bool IOLoginDataSave::savePlayerPreyClass(std::shared_ptr player) { return true; } -bool IOLoginDataSave::savePlayerTaskHuntingClass(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerTaskHuntingClass(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -684,7 +684,7 @@ bool IOLoginDataSave::savePlayerTaskHuntingClass(std::shared_ptr player) return true; } -bool IOLoginDataSave::savePlayerForgeHistory(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerForgeHistory(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -718,7 +718,7 @@ bool IOLoginDataSave::savePlayerForgeHistory(std::shared_ptr player) { return true; } -bool IOLoginDataSave::savePlayerBosstiary(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerBosstiary(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -762,7 +762,7 @@ bool IOLoginDataSave::savePlayerBosstiary(std::shared_ptr player) { return true; } -bool IOLoginDataSave::savePlayerStorage(std::shared_ptr player) { +bool IOLoginDataSave::savePlayerStorage(const std::shared_ptr & player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; diff --git a/src/io/functions/iologindata_save_player.hpp b/src/io/functions/iologindata_save_player.hpp index 1c3cf89cb9c..c9cb66efa28 100644 --- a/src/io/functions/iologindata_save_player.hpp +++ b/src/io/functions/iologindata_save_player.hpp @@ -13,20 +13,20 @@ class IOLoginDataSave : public IOLoginData { public: - static bool savePlayerFirst(std::shared_ptr player); - static bool savePlayerStash(std::shared_ptr player); - static bool savePlayerSpells(std::shared_ptr player); - static bool savePlayerKills(std::shared_ptr player); - static bool savePlayerBestiarySystem(std::shared_ptr player); - static bool savePlayerItem(std::shared_ptr player); - static bool savePlayerDepotItems(std::shared_ptr player); - static bool saveRewardItems(std::shared_ptr player); - static bool savePlayerInbox(std::shared_ptr player); - static bool savePlayerPreyClass(std::shared_ptr player); - static bool savePlayerTaskHuntingClass(std::shared_ptr player); - static bool savePlayerForgeHistory(std::shared_ptr player); - static bool savePlayerBosstiary(std::shared_ptr player); - static bool savePlayerStorage(std::shared_ptr palyer); + static bool savePlayerFirst(const std::shared_ptr & player); + static bool savePlayerStash(const std::shared_ptr & player); + static bool savePlayerSpells(const std::shared_ptr & player); + static bool savePlayerKills(const std::shared_ptr & player); + static bool savePlayerBestiarySystem(const std::shared_ptr & player); + static bool savePlayerItem(const std::shared_ptr & player); + static bool savePlayerDepotItems(const std::shared_ptr & player); + static bool saveRewardItems(const std::shared_ptr & player); + static bool savePlayerInbox(const std::shared_ptr & player); + static bool savePlayerPreyClass(const std::shared_ptr & player); + static bool savePlayerTaskHuntingClass(const std::shared_ptr & player); + static bool savePlayerForgeHistory(const std::shared_ptr & player); + static bool savePlayerBosstiary(const std::shared_ptr & player); + static bool savePlayerStorage(const std::shared_ptr & palyer); protected: using ItemBlockList = std::list>>; @@ -34,5 +34,5 @@ class IOLoginDataSave : public IOLoginData { using ItemRewardList = std::list>>; using ItemInboxList = std::list>>; - static bool saveItems(std::shared_ptr player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &stream); + static bool saveItems(const std::shared_ptr & player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &stream); }; diff --git a/src/io/io_bosstiary.cpp b/src/io/io_bosstiary.cpp index cda3336af9c..bc5a3563141 100644 --- a/src/io/io_bosstiary.cpp +++ b/src/io/io_bosstiary.cpp @@ -164,7 +164,7 @@ std::shared_ptr IOBosstiary::getMonsterTypeByBossRaceId(uint16_t ra return nullptr; } -void IOBosstiary::addBosstiaryKill(std::shared_ptr player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) const { +void IOBosstiary::addBosstiaryKill(const std::shared_ptr &player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) const { if (!player || !mtype) { return; } @@ -231,7 +231,7 @@ uint32_t IOBosstiary::calculateBossPoints(uint16_t lootBonus) const { return static_cast((2.5 * lootBonus * lootBonus) - (477.5 * lootBonus) + 24000); } -phmap::parallel_flat_hash_set IOBosstiary::getBosstiaryFinished(std::shared_ptr player, uint8_t level /* = 1*/) const { +phmap::parallel_flat_hash_set IOBosstiary::getBosstiaryFinished(const std::shared_ptr &player, uint8_t level /* = 1*/) const { phmap::parallel_flat_hash_set unlockedMonsters; if (!player) { return unlockedMonsters; @@ -265,7 +265,7 @@ phmap::parallel_flat_hash_set IOBosstiary::getBosstiaryFinished(std::s return unlockedMonsters; } -uint8_t IOBosstiary::getBossCurrentLevel(std::shared_ptr player, uint16_t bossId) const { +uint8_t IOBosstiary::getBossCurrentLevel(const std::shared_ptr &player, uint16_t bossId) const { if (bossId == 0 || !player) { return 0; } @@ -300,7 +300,7 @@ uint32_t IOBosstiary::calculteRemoveBoss(uint8_t removeTimes) const { return 300000 * removeTimes - 500000; } -std::vector IOBosstiary::getBosstiaryCooldownRaceId(std::shared_ptr player) const { +std::vector IOBosstiary::getBosstiaryCooldownRaceId(const std::shared_ptr &player) const { std::vector bossesCooldownRaceId; if (!player) { return bossesCooldownRaceId; diff --git a/src/io/io_bosstiary.hpp b/src/io/io_bosstiary.hpp index bbb1367e8b8..a94fd180468 100644 --- a/src/io/io_bosstiary.hpp +++ b/src/io/io_bosstiary.hpp @@ -60,13 +60,13 @@ class IOBosstiary { uint16_t getBoostedBossId() const; std::shared_ptr getMonsterTypeByBossRaceId(uint16_t raceId) const; - void addBosstiaryKill(std::shared_ptr player, const std::shared_ptr mtype, uint32_t amount = 1) const; + void addBosstiaryKill(const std::shared_ptr &player, const std::shared_ptr mtype, uint32_t amount = 1) const; uint16_t calculateLootBonus(uint32_t bossPoints) const; uint32_t calculateBossPoints(uint16_t lootBonus) const; - phmap::parallel_flat_hash_set getBosstiaryFinished(std::shared_ptr player, uint8_t level = 1) const; - uint8_t getBossCurrentLevel(std::shared_ptr player, uint16_t bossId) const; + phmap::parallel_flat_hash_set getBosstiaryFinished(const std::shared_ptr &player, uint8_t level = 1) const; + uint8_t getBossCurrentLevel(const std::shared_ptr &player, uint16_t bossId) const; uint32_t calculteRemoveBoss(uint8_t removeTimes) const; - std::vector getBosstiaryCooldownRaceId(std::shared_ptr player) const; + std::vector getBosstiaryCooldownRaceId(const std::shared_ptr &player) const; const std::vector &getBossRaceKillStages(BosstiaryRarity_t race) const; private: diff --git a/src/io/iobestiary.cpp b/src/io/iobestiary.cpp index 7e5d1c9ad55..6fe8d61053c 100644 --- a/src/io/iobestiary.cpp +++ b/src/io/iobestiary.cpp @@ -17,7 +17,7 @@ SoftSingleton IOBestiary::instanceTracker("IOBestiary"); -bool IOBestiary::parseCharmCombat(const std::shared_ptr charm, std::shared_ptr player, std::shared_ptr target, int32_t realDamage, bool dueToPotion, bool checkArmor) { +bool IOBestiary::parseCharmCombat(const std::shared_ptr charm, const std::shared_ptr & player, std::shared_ptr target, int32_t realDamage, bool dueToPotion, bool checkArmor) { if (!charm || !player || !target) { return false; } @@ -146,7 +146,7 @@ uint8_t IOBestiary::getKillStatus(const std::shared_ptr mtype, uint return 4; } -void IOBestiary::resetCharmRuneCreature(std::shared_ptr player, const std::shared_ptr charm) { +void IOBestiary::resetCharmRuneCreature(const std::shared_ptr & player, const std::shared_ptr charm) { if (!player || !charm) { return; } @@ -156,7 +156,7 @@ void IOBestiary::resetCharmRuneCreature(std::shared_ptr player, const st player->parseRacebyCharm(charm->id, true, 0); } -void IOBestiary::setCharmRuneCreature(std::shared_ptr player, const std::shared_ptr charm, uint16_t raceid) { +void IOBestiary::setCharmRuneCreature(const std::shared_ptr & player, const std::shared_ptr charm, uint16_t raceid) { if (!player || !charm) { return; } @@ -166,7 +166,7 @@ void IOBestiary::setCharmRuneCreature(std::shared_ptr player, const std: player->setUsedRunesBit(Toggle); } -std::list IOBestiary::getCharmUsedRuneBitAll(std::shared_ptr player) { +std::list IOBestiary::getCharmUsedRuneBitAll(const std::shared_ptr & player) { int32_t input = player->getUsedRunesBit(); ; int8_t i = 0; @@ -182,7 +182,7 @@ std::list IOBestiary::getCharmUsedRuneBitAll(std::shared_ptr player, BestiaryType_t race) const { +uint16_t IOBestiary::getBestiaryRaceUnlocked(const std::shared_ptr & player, BestiaryType_t race) const { if (!player) { return 0; } @@ -199,7 +199,7 @@ uint16_t IOBestiary::getBestiaryRaceUnlocked(std::shared_ptr player, Bes return count; } -void IOBestiary::addCharmPoints(std::shared_ptr player, uint16_t amount, bool negative /*= false*/) { +void IOBestiary::addCharmPoints(const std::shared_ptr & player, uint16_t amount, bool negative /*= false*/) { if (!player) { return; } @@ -213,7 +213,7 @@ void IOBestiary::addCharmPoints(std::shared_ptr player, uint16_t amount, player->setCharmPoints(myCharms); } -void IOBestiary::addBestiaryKill(std::shared_ptr player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) { +void IOBestiary::addBestiaryKill(const std::shared_ptr & player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) { uint16_t raceid = mtype->info.raceid; if (raceid == 0 || !player || !mtype) { return; @@ -241,7 +241,7 @@ void IOBestiary::addBestiaryKill(std::shared_ptr player, const std::shar player->refreshCyclopediaMonsterTracker(); } -charmRune_t IOBestiary::getCharmFromTarget(std::shared_ptr player, const std::shared_ptr mtype) { +charmRune_t IOBestiary::getCharmFromTarget(const std::shared_ptr & player, const std::shared_ptr mtype) { if (!player || !mtype) { return CHARM_NONE; } @@ -283,7 +283,7 @@ int32_t IOBestiary::bitToggle(int32_t input, const std::shared_ptr charm, } } -void IOBestiary::sendBuyCharmRune(std::shared_ptr player, charmRune_t runeID, uint8_t action, uint16_t raceid) { +void IOBestiary::sendBuyCharmRune(const std::shared_ptr & player, charmRune_t runeID, uint8_t action, uint16_t raceid) { const auto charm = getBestiaryCharm(runeID); if (!player || !charm) { return; @@ -384,7 +384,7 @@ std::map IOBestiary::getMonsterElements(const std::shared_ptr< return defaultMap; } -std::map IOBestiary::getBestiaryKillCountByMonsterIDs(std::shared_ptr player, std::map mtype_list) const { +std::map IOBestiary::getBestiaryKillCountByMonsterIDs(const std::shared_ptr & player, std::map mtype_list) const { std::map raceMonsters = {}; for (const auto &it : mtype_list) { uint16_t raceid = it.first; @@ -396,7 +396,7 @@ std::map IOBestiary::getBestiaryKillCountByMonsterIDs(std::s return raceMonsters; } -phmap::parallel_flat_hash_set IOBestiary::getBestiaryFinished(std::shared_ptr player) const { +phmap::parallel_flat_hash_set IOBestiary::getBestiaryFinished(const std::shared_ptr & player) const { phmap::parallel_flat_hash_set finishedMonsters; auto bestiaryMap = g_game().getBestiaryList(); diff --git a/src/io/iobestiary.hpp b/src/io/iobestiary.hpp index 26f802dcb5b..5e17223b2af 100644 --- a/src/io/iobestiary.hpp +++ b/src/io/iobestiary.hpp @@ -55,28 +55,28 @@ class IOBestiary { } std::shared_ptr getBestiaryCharm(charmRune_t activeCharm, bool force = false) const; - void addBestiaryKill(std::shared_ptr player, const std::shared_ptr mtype, uint32_t amount = 1); - bool parseCharmCombat(const std::shared_ptr charm, std::shared_ptr player, std::shared_ptr target, int32_t realDamage, bool dueToPotion = false, bool checkArmor = false); - void addCharmPoints(std::shared_ptr player, uint16_t amount, bool negative = false); - void sendBuyCharmRune(std::shared_ptr player, charmRune_t runeID, uint8_t action, uint16_t raceid); - void setCharmRuneCreature(std::shared_ptr player, const std::shared_ptr charm, uint16_t raceid); - void resetCharmRuneCreature(std::shared_ptr player, const std::shared_ptr charm); + void addBestiaryKill(const std::shared_ptr & player, const std::shared_ptr mtype, uint32_t amount = 1); + bool parseCharmCombat(const std::shared_ptr charm, const std::shared_ptr & player, std::shared_ptr target, int32_t realDamage, bool dueToPotion = false, bool checkArmor = false); + void addCharmPoints(const std::shared_ptr & player, uint16_t amount, bool negative = false); + void sendBuyCharmRune(const std::shared_ptr & player, charmRune_t runeID, uint8_t action, uint16_t raceid); + void setCharmRuneCreature(const std::shared_ptr & player, const std::shared_ptr charm, uint16_t raceid); + void resetCharmRuneCreature(const std::shared_ptr & player, const std::shared_ptr charm); int8_t calculateDifficult(uint32_t chance) const; uint8_t getKillStatus(const std::shared_ptr mtype, uint32_t killAmount) const; - uint16_t getBestiaryRaceUnlocked(std::shared_ptr player, BestiaryType_t race) const; + uint16_t getBestiaryRaceUnlocked(const std::shared_ptr & player, BestiaryType_t race) const; int32_t bitToggle(int32_t input, const std::shared_ptr charm, bool on) const; bool hasCharmUnlockedRuneBit(const std::shared_ptr charm, int32_t input) const; - std::list getCharmUsedRuneBitAll(std::shared_ptr player); - phmap::parallel_flat_hash_set getBestiaryFinished(std::shared_ptr player) const; + std::list getCharmUsedRuneBitAll(const std::shared_ptr & player); + phmap::parallel_flat_hash_set getBestiaryFinished(const std::shared_ptr & player) const; - charmRune_t getCharmFromTarget(std::shared_ptr player, const std::shared_ptr mtype); + charmRune_t getCharmFromTarget(const std::shared_ptr & player, const std::shared_ptr mtype); - std::map getBestiaryKillCountByMonsterIDs(std::shared_ptr player, std::map mtype_list) const; + std::map getBestiaryKillCountByMonsterIDs(const std::shared_ptr & player, std::map mtype_list) const; std::map getMonsterElements(const std::shared_ptr mtype) const; std::map findRaceByName(const std::string &race, bool Onlystring = true, BestiaryType_t raceNumber = BESTY_RACE_NONE) const; diff --git a/src/io/iologindata.cpp b/src/io/iologindata.cpp index db32e581ec2..a901fbc9940 100644 --- a/src/io/iologindata.cpp +++ b/src/io/iologindata.cpp @@ -85,21 +85,21 @@ void IOLoginData::updateOnlineStatus(uint32_t guid, bool login) { } // The boolean "disable" will desactivate the loading of information that is not relevant to the preload, for example, forge, bosstiary, etc. None of this we need to access if the player is offline -bool IOLoginData::loadPlayerById(std::shared_ptr player, uint32_t id, bool disable /* = true*/) { +bool IOLoginData::loadPlayerById(const std::shared_ptr & player, uint32_t id, bool disable /* = true*/) { Database &db = Database::getInstance(); std::ostringstream query; query << "SELECT * FROM `players` WHERE `id` = " << id; return loadPlayer(player, db.storeQuery(query.str()), disable); } -bool IOLoginData::loadPlayerByName(std::shared_ptr player, const std::string &name, bool disable /* = true*/) { +bool IOLoginData::loadPlayerByName(const std::shared_ptr & player, const std::string &name, bool disable /* = true*/) { Database &db = Database::getInstance(); std::ostringstream query; query << "SELECT * FROM `players` WHERE `name` = " << db.escapeString(name); return loadPlayer(player, db.storeQuery(query.str()), disable); } -bool IOLoginData::loadPlayer(std::shared_ptr player, DBResult_ptr result, bool disable /* = false*/) { +bool IOLoginData::loadPlayer(const std::shared_ptr & player, DBResult_ptr result, bool disable /* = false*/) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Resultnullptr: {}", __FUNCTION__); return false; @@ -185,7 +185,7 @@ bool IOLoginData::loadPlayer(std::shared_ptr player, DBResult_ptr result } } -bool IOLoginData::savePlayer(std::shared_ptr player) { +bool IOLoginData::savePlayer(const std::shared_ptr & player) { bool success = DBTransaction::executeWithinTransaction([player]() { return savePlayerGuard(player); }); @@ -197,7 +197,7 @@ bool IOLoginData::savePlayer(std::shared_ptr player) { return success; } -bool IOLoginData::savePlayerGuard(std::shared_ptr player) { +bool IOLoginData::savePlayerGuard(const std::shared_ptr & player) { if (!player) { throw DatabaseException("Player nullptr in function: " + std::string(__FUNCTION__)); } diff --git a/src/io/iologindata.hpp b/src/io/iologindata.hpp index 724967d2877..3fb1cefb0ed 100644 --- a/src/io/iologindata.hpp +++ b/src/io/iologindata.hpp @@ -20,10 +20,10 @@ class IOLoginData { static bool gameWorldAuthentication(const std::string &accountDescriptor, const std::string &sessionOrPassword, std::string &characterName, uint32_t &accountId, bool oldProcotol); static account::AccountType getAccountType(uint32_t accountId); static void updateOnlineStatus(uint32_t guid, bool login); - static bool loadPlayerById(std::shared_ptr player, uint32_t id, bool disable = true); - static bool loadPlayerByName(std::shared_ptr player, const std::string &name, bool disable = true); - static bool loadPlayer(std::shared_ptr player, DBResult_ptr result, bool disable = true); - static bool savePlayer(std::shared_ptr player); + static bool loadPlayerById(const std::shared_ptr & player, uint32_t id, bool disable = true); + static bool loadPlayerByName(const std::shared_ptr & player, const std::string &name, bool disable = true); + static bool loadPlayer(const std::shared_ptr & player, DBResult_ptr result, bool disable = true); + static bool savePlayer(const std::shared_ptr & player); static uint32_t getGuidByName(const std::string &name); static bool getGuidByNameEx(uint32_t &guid, bool &specialVip, std::string &name); static std::string getNameByGuid(uint32_t guid); @@ -37,5 +37,5 @@ class IOLoginData { static void removeVIPEntry(uint32_t accountId, uint32_t guid); private: - static bool savePlayerGuard(std::shared_ptr player); + static bool savePlayerGuard(const std::shared_ptr & player); }; diff --git a/src/io/ioprey.cpp b/src/io/ioprey.cpp index 449383a1b87..c7c68cce15d 100644 --- a/src/io/ioprey.cpp +++ b/src/io/ioprey.cpp @@ -246,7 +246,7 @@ void TaskHuntingSlot::reloadReward() { } // Prey/Task hunting global class -void IOPrey::CheckPlayerPreys(std::shared_ptr player, uint8_t amount) const { +void IOPrey::CheckPlayerPreys(const std::shared_ptr & player, uint8_t amount) const { if (!player) { return; } @@ -289,7 +289,7 @@ void IOPrey::CheckPlayerPreys(std::shared_ptr player, uint8_t amount) co } } -void IOPrey::ParsePreyAction(std::shared_ptr player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const { +void IOPrey::ParsePreyAction(const std::shared_ptr & player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const { PreySlot* slot = player->getPreySlotById(slotId); if (!slot || slot->state == PreyDataState_Locked) { player->sendMessageDialog("To unlock this prey slot first you must buy it on store."); @@ -389,7 +389,7 @@ void IOPrey::ParsePreyAction(std::shared_ptr player, PreySlot_t slotId, player->reloadPreySlot(slotId); } -void IOPrey::ParseTaskHuntingAction(std::shared_ptr player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const { +void IOPrey::ParseTaskHuntingAction(const std::shared_ptr & player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const { TaskHuntingSlot* slot = player->getTaskHuntingSlotById(slotId); if (!slot || slot->state == PreyTaskDataState_Locked) { player->sendMessageDialog("To unlock this task hunting slot first you must buy it on store."); diff --git a/src/io/ioprey.hpp b/src/io/ioprey.hpp index 5885615d225..042291fe89a 100644 --- a/src/io/ioprey.hpp +++ b/src/io/ioprey.hpp @@ -217,10 +217,10 @@ class IOPrey { return inject(); } - void CheckPlayerPreys(std::shared_ptr player, uint8_t amount) const; - void ParsePreyAction(std::shared_ptr player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const; + void CheckPlayerPreys(const std::shared_ptr & player, uint8_t amount) const; + void ParsePreyAction(const std::shared_ptr & player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const; - void ParseTaskHuntingAction(std::shared_ptr player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const; + void ParseTaskHuntingAction(const std::shared_ptr & player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const; void InitializeTaskHuntOptions(); TaskHuntingOption* GetTaskRewardOption(const TaskHuntingSlot* slot) const; diff --git a/src/items/bed.cpp b/src/items/bed.cpp index 2f029cb1eea..97fbeca870e 100644 --- a/src/items/bed.cpp +++ b/src/items/bed.cpp @@ -78,7 +78,7 @@ std::shared_ptr BedItem::getNextBedItem() { return tile->getBedItem(); } -bool BedItem::canUse(std::shared_ptr player) { +bool BedItem::canUse(const std::shared_ptr &player) { if ((player == nullptr) || (house == nullptr) || !player->isPremium()) { return false; } @@ -110,7 +110,7 @@ bool BedItem::canUse(std::shared_ptr player) { return true; } -bool BedItem::trySleep(std::shared_ptr player) { +bool BedItem::trySleep(const std::shared_ptr &player) { if (!house || player->isRemoved()) { return false; } @@ -126,7 +126,7 @@ bool BedItem::trySleep(std::shared_ptr player) { return true; } -bool BedItem::sleep(std::shared_ptr player) { +bool BedItem::sleep(const std::shared_ptr &player) { if (house == nullptr) { return false; } @@ -165,7 +165,7 @@ bool BedItem::sleep(std::shared_ptr player) { return true; } -void BedItem::wakeUp(std::shared_ptr player) { +void BedItem::wakeUp(const std::shared_ptr &player) { if (house == nullptr) { return; } @@ -206,7 +206,7 @@ void BedItem::wakeUp(std::shared_ptr player) { } } -void BedItem::regeneratePlayer(std::shared_ptr player) const { +void BedItem::regeneratePlayer(const std::shared_ptr &player) const { const uint32_t sleptTime = time(nullptr) - sleepStart; Condition* condition = player->getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT); @@ -232,7 +232,7 @@ void BedItem::regeneratePlayer(std::shared_ptr player) const { player->changeSoul(soulRegen); } -void BedItem::updateAppearance(std::shared_ptr player) { +void BedItem::updateAppearance(const std::shared_ptr &player) { const ItemType &it = Item::items[id]; if (it.type == ITEM_TYPE_BED) { if ((player != nullptr) && it.transformToOnUse[player->getSex()] != 0) { @@ -249,7 +249,7 @@ void BedItem::updateAppearance(std::shared_ptr player) { } } -void BedItem::internalSetSleeper(std::shared_ptr player) { +void BedItem::internalSetSleeper(const std::shared_ptr &player) { std::string desc_str = player->getName() + " is sleeping there."; sleeperGUID = player->getGUID(); diff --git a/src/items/bed.hpp b/src/items/bed.hpp index bdacbd88204..0849fd48749 100644 --- a/src/items/bed.hpp +++ b/src/items/bed.hpp @@ -37,20 +37,20 @@ class BedItem final : public Item { house = h; } - bool canUse(std::shared_ptr player); + bool canUse(const std::shared_ptr & player); - bool trySleep(std::shared_ptr player); - bool sleep(std::shared_ptr player); - void wakeUp(std::shared_ptr player); + bool trySleep(const std::shared_ptr & player); + bool sleep(const std::shared_ptr & player); + void wakeUp(const std::shared_ptr & player); std::shared_ptr getNextBedItem(); friend class MapCache; private: - void updateAppearance(std::shared_ptr player); - void regeneratePlayer(std::shared_ptr player) const; - void internalSetSleeper(std::shared_ptr player); + void updateAppearance(const std::shared_ptr & player); + void regeneratePlayer(const std::shared_ptr & player) const; + void internalSetSleeper(const std::shared_ptr & player); void internalRemoveSleeper(); House* house = nullptr; diff --git a/src/items/containers/mailbox/mailbox.cpp b/src/items/containers/mailbox/mailbox.cpp index bfc732939e0..8a83d48a49f 100644 --- a/src/items/containers/mailbox/mailbox.cpp +++ b/src/items/containers/mailbox/mailbox.cpp @@ -90,7 +90,7 @@ bool Mailbox::sendItem(std::shared_ptr item) const { } } - std::shared_ptr player = g_game().getPlayerByName(receiver, true); + const auto player = g_game().getPlayerByName(receiver, true); std::string writer; time_t date = time(0); std::string text; diff --git a/src/items/decay/decay.cpp b/src/items/decay/decay.cpp index 25ff2b3003f..c3b8de15fa8 100644 --- a/src/items/decay/decay.cpp +++ b/src/items/decay/decay.cpp @@ -139,7 +139,7 @@ void Decay::checkDecay() { void Decay::internalDecayItem(const std::shared_ptr &item) { const ItemType &it = Item::items[item->getID()]; if (it.decayTo != 0) { - std::shared_ptr player = item->getHoldingPlayer(); + const auto &player = item->getHoldingPlayer(); if (player) { bool needUpdateSkills = false; for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { diff --git a/src/items/item.cpp b/src/items/item.cpp index 0a34f34a255..9e97e6557a7 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -87,7 +87,7 @@ void Item::setImbuement(uint8_t slot, uint16_t imbuementId, uint32_t duration) { } void Item::addImbuement(uint8_t slot, uint16_t imbuementId, uint32_t duration) { - std::shared_ptr player = getHoldingPlayer(); + const auto &player = getHoldingPlayer(); if (!player) { return; } diff --git a/src/items/item.hpp b/src/items/item.hpp index 9febd27a917..98257d90de6 100644 --- a/src/items/item.hpp +++ b/src/items/item.hpp @@ -546,7 +546,7 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { return true; } virtual void onRemoved(); - virtual void onTradeEvent(TradeEvents_t, std::shared_ptr) { } + virtual void onTradeEvent(TradeEvents_t, const std::shared_ptr &) { } virtual void startDecaying(); virtual void stopDecaying(); diff --git a/src/items/tile.cpp b/src/items/tile.cpp index 030ba0ab8c7..b7f61950ab5 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -229,7 +229,7 @@ std::shared_ptr Tile::getBottomCreature() const { std::shared_ptr Tile::getTopVisibleCreature(std::shared_ptr creature) const { if (const CreatureVector* creatures = getCreatures()) { if (creature) { - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player && player->isAccessPlayer()) { return getTopCreature(); } @@ -242,7 +242,7 @@ std::shared_ptr Tile::getTopVisibleCreature(std::shared_ptr } else { for (auto &tileCreature : *creatures) { if (!tileCreature->isInvisible()) { - std::shared_ptr player = tileCreature->getPlayer(); + const auto &player = tileCreature->getPlayer(); if (!player || !player->isInGhostMode()) { return tileCreature; } @@ -256,7 +256,7 @@ std::shared_ptr Tile::getTopVisibleCreature(std::shared_ptr std::shared_ptr Tile::getBottomVisibleCreature(std::shared_ptr creature) const { if (const CreatureVector* creatures = getCreatures()) { if (creature) { - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player && player->isAccessPlayer()) { return getBottomCreature(); } @@ -269,7 +269,7 @@ std::shared_ptr Tile::getBottomVisibleCreature(std::shared_ptrrbegin(), end = creatures->rend(); it != end; ++it) { if (!(*it)->isInvisible()) { - std::shared_ptr player = (*it)->getPlayer(); + const auto &player = (*it)->getPlayer(); if (!player || !player->isInGhostMode()) { return *it; } @@ -357,7 +357,7 @@ void Tile::onAddTileItem(std::shared_ptr item) { // send to client for (std::shared_ptr spectator : spectators) { - if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendAddTileItem(static_self_cast(), cylinderMapPos, item); } } @@ -442,7 +442,7 @@ void Tile::onUpdateTileItem(std::shared_ptr oldItem, const ItemType &oldTy // send to client for (std::shared_ptr spectator : spectators) { - if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendUpdateTileItem(static_self_cast(), cylinderMapPos, newItem); } } @@ -475,7 +475,7 @@ void Tile::onRemoveTileItem(const SpectatorHashSet &spectators, const std::vecto // send to client size_t i = 0; for (std::shared_ptr spectator : spectators) { - if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendRemoveTileThing(cylinderMapPos, oldStackPosVector[i++]); } } @@ -636,7 +636,7 @@ ReturnValue Tile::queryAdd(int32_t, const std::shared_ptr &thing, uint32_ } const CreatureVector* creatures = getCreatures(); - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { if (creatures && !creatures->empty() && !hasBitSet(FLAG_IGNOREBLOCKCREATURE, tileFlags) && !player->isAccessPlayer()) { for (std::shared_ptr tileCreature : *creatures) { if (!player->canWalkthrough(tileCreature)) { @@ -1185,7 +1185,7 @@ void Tile::removeThing(std::shared_ptr thing, uint32_t count) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, getPosition(), true); for (std::shared_ptr spectator : spectators) { - if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { oldStackPosVector.push_back(getStackposOfItem(tmpPlayer, item)); } } @@ -1210,7 +1210,7 @@ void Tile::removeThing(std::shared_ptr thing, uint32_t count) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, getPosition(), true); for (std::shared_ptr spectator : spectators) { - if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { oldStackPosVector.push_back(getStackposOfItem(tmpPlayer, item)); } } @@ -1279,7 +1279,7 @@ int32_t Tile::getThingIndex(std::shared_ptr thing) const { return -1; } -int32_t Tile::getClientIndexOfCreature(std::shared_ptr player, std::shared_ptr creature) const { +int32_t Tile::getClientIndexOfCreature(const std::shared_ptr &player, std::shared_ptr creature) const { int32_t n; if (ground) { n = 1; @@ -1304,7 +1304,7 @@ int32_t Tile::getClientIndexOfCreature(std::shared_ptr player, std::shar return -1; } -int32_t Tile::getStackposOfCreature(std::shared_ptr player, std::shared_ptr creature) const { +int32_t Tile::getStackposOfCreature(const std::shared_ptr &player, std::shared_ptr creature) const { int32_t n; if (ground) { n = 1; @@ -1334,7 +1334,7 @@ int32_t Tile::getStackposOfCreature(std::shared_ptr player, std::shared_ return -1; } -int32_t Tile::getStackposOfItem(std::shared_ptr player, std::shared_ptr item) const { +int32_t Tile::getStackposOfItem(const std::shared_ptr &player, std::shared_ptr item) const { int32_t n = 0; if (ground) { if (ground == item) { diff --git a/src/items/tile.hpp b/src/items/tile.hpp index 7e9c4973c59..d414337c38a 100644 --- a/src/items/tile.hpp +++ b/src/items/tile.hpp @@ -196,9 +196,9 @@ class Tile : public Cylinder, public SharedObject { std::string getDescription(int32_t lookDistance) override final; - int32_t getClientIndexOfCreature(std::shared_ptr player, std::shared_ptr creature) const; - int32_t getStackposOfCreature(std::shared_ptr player, std::shared_ptr creature) const; - int32_t getStackposOfItem(std::shared_ptr player, std::shared_ptr item) const; + int32_t getClientIndexOfCreature(const std::shared_ptr & player, std::shared_ptr creature) const; + int32_t getStackposOfCreature(const std::shared_ptr & player, std::shared_ptr creature) const; + int32_t getStackposOfItem(const std::shared_ptr & player, std::shared_ptr item) const; // cylinder implementations ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; diff --git a/src/items/weapons/weapons.cpp b/src/items/weapons/weapons.cpp index 995b71518c0..7f392c623ad 100644 --- a/src/items/weapons/weapons.cpp +++ b/src/items/weapons/weapons.cpp @@ -57,7 +57,7 @@ void Weapon::configureWeapon(const ItemType &it) { id = it.id; } -int32_t Weapon::playerWeaponCheck(std::shared_ptr player, std::shared_ptr target, uint8_t shootRange) const { +int32_t Weapon::playerWeaponCheck(const std::shared_ptr &player, std::shared_ptr target, uint8_t shootRange) const { const Position &playerPos = player->getPosition(); const Position &targetPos = target->getPosition(); if (playerPos.z != targetPos.z) { @@ -107,7 +107,7 @@ int32_t Weapon::playerWeaponCheck(std::shared_ptr player, std::shared_pt return 100; } -bool Weapon::useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const { +bool Weapon::useWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target) const { int32_t damageModifier = playerWeaponCheck(player, target, item->getShootRange()); if (damageModifier == 0) { return false; @@ -117,7 +117,7 @@ bool Weapon::useWeapon(std::shared_ptr player, std::shared_ptr ite return true; } -CombatDamage Weapon::getCombatDamage(CombatDamage combat, std::shared_ptr player, std::shared_ptr item, int32_t damageModifier) const { +CombatDamage Weapon::getCombatDamage(CombatDamage combat, const std::shared_ptr &player, std::shared_ptr item, int32_t damageModifier) const { // Local variables uint32_t level = player->getLevel(); int16_t elementalAttack = getElementDamageValue(); @@ -140,7 +140,7 @@ CombatDamage Weapon::getCombatDamage(CombatDamage combat, std::shared_ptr player, std::shared_ptr target) { +bool Weapon::useFist(const std::shared_ptr &player, std::shared_ptr target) { if (!Position::areInRange<1, 1>(player->getPosition(), target->getPosition())) { return false; } @@ -170,7 +170,7 @@ bool Weapon::useFist(std::shared_ptr player, std::shared_ptr t return true; } -void Weapon::internalUseWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target, int32_t damageModifier, int32_t cleavePercent) const { +void Weapon::internalUseWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target, int32_t damageModifier, int32_t cleavePercent) const { if (player) { if (params.soundCastEffect == SoundEffect_t::SILENCE) { g_game().sendDoubleSoundEffect(player->getPosition(), player->getHitSoundEffect(), player->getAttackSoundEffect(), player); @@ -225,7 +225,7 @@ void Weapon::internalUseWeapon(std::shared_ptr player, std::shared_ptrgetTile()); } -void Weapon::internalUseWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr tile) const { +void Weapon::internalUseWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr tile) const { if (isLoadedCallback()) { LuaVariant var; var.type = VARIANT_TARGETPOSITION; @@ -239,7 +239,7 @@ void Weapon::internalUseWeapon(std::shared_ptr player, std::shared_ptr player, std::shared_ptr item, std::shared_ptr destTile) const { +void Weapon::onUsedWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr destTile) const { if (!player->hasFlag(PlayerFlags_t::NotGainSkill)) { skills_t skillType; uint32_t skillPoint; @@ -293,7 +293,7 @@ void Weapon::onUsedWeapon(std::shared_ptr player, std::shared_ptr } } -uint32_t Weapon::getManaCost(std::shared_ptr player) const { +uint32_t Weapon::getManaCost(const std::shared_ptr &player) const { if (mana != 0) { return mana; } @@ -305,7 +305,7 @@ uint32_t Weapon::getManaCost(std::shared_ptr player) const { return (player->getMaxMana() * manaPercent) / 100; } -int32_t Weapon::getHealthCost(std::shared_ptr player) const { +int32_t Weapon::getHealthCost(const std::shared_ptr &player) const { if (health != 0) { return health; } @@ -317,7 +317,7 @@ int32_t Weapon::getHealthCost(std::shared_ptr player) const { return (player->getMaxHealth() * healthPercent) / 100; } -bool Weapon::executeUseWeapon(std::shared_ptr player, const LuaVariant &var) const { +bool Weapon::executeUseWeapon(const std::shared_ptr &player, const LuaVariant &var) const { // onUseWeapon(player, var) if (!getScriptInterface()->reserveScriptEnv()) { std::string playerName = player ? player->getName() : "Player nullptr"; @@ -370,7 +370,7 @@ void WeaponMelee::configureWeapon(const ItemType &it) { Weapon::configureWeapon(it); } -bool WeaponMelee::useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const { +bool WeaponMelee::useWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target) const { int32_t damageModifier = playerWeaponCheck(player, target, item->getShootRange()); if (damageModifier == 0) { return false; @@ -430,7 +430,7 @@ bool WeaponMelee::useWeapon(std::shared_ptr player, std::shared_ptr player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const { +bool WeaponMelee::getSkillType(const std::shared_ptr &player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const { if (player->getAddAttackSkill() && player->getLastAttackBlockType() != BLOCK_IMMUNITY) { skillpoint = 1; } else { @@ -460,7 +460,7 @@ bool WeaponMelee::getSkillType(std::shared_ptr player, std::shared_ptr player, std::shared_ptr, std::shared_ptr item) const { +int32_t WeaponMelee::getElementDamage(const std::shared_ptr &player, std::shared_ptr, std::shared_ptr item) const { if (elementType == COMBAT_NONE) { return 0; } @@ -479,7 +479,7 @@ int16_t WeaponMelee::getElementDamageValue() const { return elementDamage; } -int32_t WeaponMelee::getWeaponDamage(std::shared_ptr player, std::shared_ptr, std::shared_ptr item, bool maxDamage /*= false*/) const { +int32_t WeaponMelee::getWeaponDamage(const std::shared_ptr &player, std::shared_ptr, std::shared_ptr item, bool maxDamage /*= false*/) const { using namespace std; int32_t attackSkill = player->getWeaponSkill(item); int32_t attackValue = std::max(0, item->getAttack()); @@ -519,7 +519,7 @@ void WeaponDistance::configureWeapon(const ItemType &it) { Weapon::configureWeapon(it); } -bool WeaponDistance::useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const { +bool WeaponDistance::useWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target) const { int32_t damageModifier; const ItemType &it = Item::items[id]; if (it.weaponType == WEAPON_AMMO) { @@ -695,7 +695,7 @@ bool WeaponDistance::useWeapon(std::shared_ptr player, std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const { +int32_t WeaponDistance::getElementDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item) const { if (elementType == COMBAT_NONE) { return 0; } @@ -730,7 +730,7 @@ int16_t WeaponDistance::getElementDamageValue() const { return elementDamage; } -int32_t WeaponDistance::getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage /*= false*/) const { +int32_t WeaponDistance::getWeaponDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, bool maxDamage /*= false*/) const { int32_t attackValue = item->getAttack(); bool hasElement = false; @@ -772,7 +772,7 @@ int32_t WeaponDistance::getWeaponDamage(std::shared_ptr player, std::sha return -normal_random(minValue, (maxValue * static_cast(player->getVocation()->distDamageMultiplier))); } -bool WeaponDistance::getSkillType(std::shared_ptr player, std::shared_ptr, skills_t &skill, uint32_t &skillpoint) const { +bool WeaponDistance::getSkillType(const std::shared_ptr &player, std::shared_ptr, skills_t &skill, uint32_t &skillpoint) const { skill = SKILL_DISTANCE; if (player->getAddAttackSkill()) { @@ -805,7 +805,7 @@ void WeaponWand::configureWeapon(const ItemType &it) { Weapon::configureWeapon(it); } -int32_t WeaponWand::getWeaponDamage(std::shared_ptr, std::shared_ptr, std::shared_ptr, bool maxDamage /*= false*/) const { +int32_t WeaponWand::getWeaponDamage(const std::shared_ptr &, std::shared_ptr, std::shared_ptr, bool maxDamage /*= false*/) const { if (maxDamage) { return -maxChange; } diff --git a/src/items/weapons/weapons.hpp b/src/items/weapons/weapons.hpp index 90785983e17..fdcbab02d35 100644 --- a/src/items/weapons/weapons.hpp +++ b/src/items/weapons/weapons.hpp @@ -59,15 +59,15 @@ class Weapon : public Script { return false; } - int32_t playerWeaponCheck(std::shared_ptr player, std::shared_ptr target, uint8_t shootRange) const; - static bool useFist(std::shared_ptr player, std::shared_ptr target); - virtual bool useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const; + int32_t playerWeaponCheck(const std::shared_ptr &player, std::shared_ptr target, uint8_t shootRange) const; + static bool useFist(const std::shared_ptr &player, std::shared_ptr target); + virtual bool useWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target) const; - virtual int32_t getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const = 0; - virtual int32_t getElementDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const = 0; + virtual int32_t getWeaponDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const = 0; + virtual int32_t getElementDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item) const = 0; virtual CombatType_t getElementType() const = 0; virtual int16_t getElementDamageValue() const = 0; - virtual CombatDamage getCombatDamage(CombatDamage combat, std::shared_ptr player, std::shared_ptr item, int32_t damageModifier) const; + virtual CombatDamage getCombatDamage(CombatDamage combat, const std::shared_ptr &player, std::shared_ptr item, int32_t damageModifier) const; uint16_t getID() const { return id; } @@ -174,17 +174,17 @@ class Weapon : public Script { } protected: - void internalUseWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target, int32_t damageModifier, int32_t cleavePercent = 0) const; - void internalUseWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr tile) const; + void internalUseWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target, int32_t damageModifier, int32_t cleavePercent = 0) const; + void internalUseWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr tile) const; private: - virtual bool getSkillType(std::shared_ptr, std::shared_ptr, skills_t &, uint32_t &) const { + virtual bool getSkillType(const std::shared_ptr &, std::shared_ptr, skills_t &, uint32_t &) const { return false; } - uint32_t getManaCost(std::shared_ptr player) const; - int32_t getHealthCost(std::shared_ptr player) const; - bool executeUseWeapon(std::shared_ptr player, const LuaVariant &var) const; + uint32_t getManaCost(const std::shared_ptr &player) const; + int32_t getHealthCost(const std::shared_ptr &player) const; + bool executeUseWeapon(const std::shared_ptr &player, const LuaVariant &var) const; uint16_t id = 0; @@ -202,7 +202,7 @@ class Weapon : public Script { bool wieldUnproperly = false; std::string vocationString = ""; - void onUsedWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr destTile) const; + void onUsedWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr destTile) const; static void decrementItemCount(std::shared_ptr item); @@ -228,17 +228,17 @@ class WeaponMelee final : public Weapon { void configureWeapon(const ItemType &it) override; - bool useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const override; + bool useWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target) const override; - int32_t getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; - int32_t getElementDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const override; + int32_t getWeaponDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; + int32_t getElementDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item) const override; CombatType_t getElementType() const override { return elementType; } virtual int16_t getElementDamageValue() const override; private: - bool getSkillType(std::shared_ptr player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const override; + bool getSkillType(const std::shared_ptr &player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const override; uint16_t elementDamage = 0; CombatType_t elementType = COMBAT_NONE; }; @@ -256,17 +256,17 @@ class WeaponDistance final : public Weapon { return true; } - bool useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const override; + bool useWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target) const override; - int32_t getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; - int32_t getElementDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const override; + int32_t getWeaponDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; + int32_t getElementDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item) const override; CombatType_t getElementType() const override { return elementType; } virtual int16_t getElementDamageValue() const override; private: - bool getSkillType(std::shared_ptr player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const override; + bool getSkillType(const std::shared_ptr &player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const override; CombatType_t elementType = COMBAT_NONE; uint16_t elementDamage = 0; @@ -282,8 +282,8 @@ class WeaponWand final : public Weapon { void configureWeapon(const ItemType &it) override; - int32_t getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; - int32_t getElementDamage(std::shared_ptr, std::shared_ptr, std::shared_ptr) const override { + int32_t getWeaponDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; + int32_t getElementDamage(const std::shared_ptr &, std::shared_ptr, std::shared_ptr) const override { return 0; } CombatType_t getElementType() const override { @@ -299,7 +299,7 @@ class WeaponWand final : public Weapon { } private: - bool getSkillType(std::shared_ptr, std::shared_ptr, skills_t &, uint32_t &) const override { + bool getSkillType(const std::shared_ptr &, std::shared_ptr, skills_t &, uint32_t &) const override { return false; } diff --git a/src/kv/README.md b/src/kv/README.md index 6c2349572c7..d54d57e740a 100644 --- a/src/kv/README.md +++ b/src/kv/README.md @@ -2,7 +2,7 @@ ## Overview -The Canary KV Library is designed to offer a simple, efficient, persistent, and thread-safe key-value store. It's an abstraction layer that can support various backends (currently, only MySQL is supported). The library provides features such as scoped access to stored values, LRU caching, and type safety. Additionally, it includes a Lua API for easy integration into Lua-based applications. +The Canary KV Library is designed to offer a simple, efficient, persistent, and thread-safe key-value store. It's an abstraction player that can support various backends (currently, only MySQL is supported). The library provides features such as scoped access to stored values, LRU caching, and type safety. Additionally, it includes a Lua API for easy integration into Lua-based applications. ## Features @@ -61,7 +61,7 @@ int lastOccurrence = scope->get("last-occurrence"); ```cpp // Create a player-scoped KV store -auto player = g_game().getPlayerById(123); +const auto &player = g_game().getPlayerById(123); auto playerKV = player->kv(); playerKV->set("coins", 100); ``` diff --git a/src/lua/callbacks/creaturecallback.cpp b/src/lua/callbacks/creaturecallback.cpp index df5845f46c0..e5b96535c84 100644 --- a/src/lua/callbacks/creaturecallback.cpp +++ b/src/lua/callbacks/creaturecallback.cpp @@ -40,7 +40,7 @@ void CreatureCallback::pushSpecificCreature(std::shared_ptr creature) LuaScriptInterface::pushUserdata(L, npc); } else if (std::shared_ptr monster = creature->getMonster()) { LuaScriptInterface::pushUserdata(L, monster); - } else if (std::shared_ptr player = creature->getPlayer()) { + } else if (const auto &player = creature->getPlayer()) { LuaScriptInterface::pushUserdata(L, player); } else { return; diff --git a/src/lua/callbacks/event_callback.cpp b/src/lua/callbacks/event_callback.cpp index e9ac54f15e6..5f0dc9cc24b 100644 --- a/src/lua/callbacks/event_callback.cpp +++ b/src/lua/callbacks/event_callback.cpp @@ -228,7 +228,7 @@ void EventCallback::creatureOnDrainHealth(std::shared_ptr creature, st } // Party -bool EventCallback::partyOnJoin(Party* party, std::shared_ptr player) const { +bool EventCallback::partyOnJoin(Party* party, const std::shared_ptr &player) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::partyOnJoin - " "Player {}] " @@ -252,7 +252,7 @@ bool EventCallback::partyOnJoin(Party* party, std::shared_ptr player) co return getScriptInterface()->callFunction(2); } -bool EventCallback::partyOnLeave(Party* party, std::shared_ptr player) const { +bool EventCallback::partyOnLeave(Party* party, const std::shared_ptr &player) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::partyOnLeave - " "Player {}] " @@ -324,7 +324,7 @@ void EventCallback::partyOnShareExperience(Party* party, uint64_t &exp) const { } // Player -bool EventCallback::playerOnBrowseField(std::shared_ptr player, const Position &position) const { +bool EventCallback::playerOnBrowseField(const std::shared_ptr &player, const Position &position) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnBrowseField - " "Player {}] " @@ -347,7 +347,7 @@ bool EventCallback::playerOnBrowseField(std::shared_ptr player, const Po return getScriptInterface()->callFunction(2); } -void EventCallback::playerOnLook(std::shared_ptr player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) const { +void EventCallback::playerOnLook(const std::shared_ptr &player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLook - " "Player {}] " @@ -381,7 +381,7 @@ void EventCallback::playerOnLook(std::shared_ptr player, const Position getScriptInterface()->callVoidFunction(4); } -void EventCallback::playerOnLookInBattleList(std::shared_ptr player, std::shared_ptr creature, int32_t lookDistance) const { +void EventCallback::playerOnLookInBattleList(const std::shared_ptr &player, std::shared_ptr creature, int32_t lookDistance) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLookInBattleList - " "Player {}] " @@ -407,7 +407,7 @@ void EventCallback::playerOnLookInBattleList(std::shared_ptr player, std getScriptInterface()->callVoidFunction(3); } -void EventCallback::playerOnLookInTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr item, int32_t lookDistance) const { +void EventCallback::playerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr &partner, std::shared_ptr item, int32_t lookDistance) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLookInTrade - " "Player {}] " @@ -436,7 +436,7 @@ void EventCallback::playerOnLookInTrade(std::shared_ptr player, std::sha getScriptInterface()->callVoidFunction(4); } -bool EventCallback::playerOnLookInShop(std::shared_ptr player, const ItemType* itemType, uint8_t count) const { +bool EventCallback::playerOnLookInShop(const std::shared_ptr &player, const ItemType* itemType, uint8_t count) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLookInShop - " "Player {} itemType {}] " @@ -462,7 +462,7 @@ bool EventCallback::playerOnLookInShop(std::shared_ptr player, const Ite return getScriptInterface()->callFunction(3); } -void EventCallback::playerOnRemoveCount(std::shared_ptr player, std::shared_ptr item) const { +void EventCallback::playerOnRemoveCount(const std::shared_ptr &player, std::shared_ptr item) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnMove - " "Player {} item {}] " @@ -486,7 +486,7 @@ void EventCallback::playerOnRemoveCount(std::shared_ptr player, std::sha getScriptInterface()->callFunction(2); } -bool EventCallback::playerOnMoveItem(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPos, const Position &toPos, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const { +bool EventCallback::playerOnMoveItem(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPos, const Position &toPos, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const { if (!getScriptInterface()) { g_logger().error("script interface nullptr"); return false; @@ -521,7 +521,7 @@ bool EventCallback::playerOnMoveItem(std::shared_ptr player, std::shared return getScriptInterface()->callFunction(7); } -void EventCallback::playerOnItemMoved(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const { +void EventCallback::playerOnItemMoved(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnItemMoved - " "Player {} item {}] " @@ -552,7 +552,7 @@ void EventCallback::playerOnItemMoved(std::shared_ptr player, std::share getScriptInterface()->callVoidFunction(7); } -void EventCallback::playerOnChangeZone(std::shared_ptr player, ZoneType_t zone) const { +void EventCallback::playerOnChangeZone(const std::shared_ptr &player, ZoneType_t zone) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnChangeZone - " "Player {}] " @@ -574,7 +574,7 @@ void EventCallback::playerOnChangeZone(std::shared_ptr player, ZoneType_ getScriptInterface()->callVoidFunction(2); } -bool EventCallback::playerOnMoveCreature(std::shared_ptr player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) const { +bool EventCallback::playerOnMoveCreature(const std::shared_ptr &player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnMoveCreature - " "Player {} creature {}] " @@ -601,7 +601,7 @@ bool EventCallback::playerOnMoveCreature(std::shared_ptr player, std::sh return getScriptInterface()->callFunction(4); } -void EventCallback::playerOnReportRuleViolation(std::shared_ptr player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const { +void EventCallback::playerOnReportRuleViolation(const std::shared_ptr &player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnReportRuleViolation - " "Player {}] " @@ -630,7 +630,7 @@ void EventCallback::playerOnReportRuleViolation(std::shared_ptr player, getScriptInterface()->callVoidFunction(6); } -void EventCallback::playerOnReportBug(std::shared_ptr player, const std::string &message, const Position &position, uint8_t category) const { +void EventCallback::playerOnReportBug(const std::shared_ptr &player, const std::string &message, const Position &position, uint8_t category) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnReportBug - " "Player {}] " @@ -655,7 +655,7 @@ void EventCallback::playerOnReportBug(std::shared_ptr player, const std: getScriptInterface()->callFunction(4); } -bool EventCallback::playerOnTurn(std::shared_ptr player, Direction direction) const { +bool EventCallback::playerOnTurn(const std::shared_ptr &player, Direction direction) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnTurn - " "Player {}] " @@ -678,7 +678,7 @@ bool EventCallback::playerOnTurn(std::shared_ptr player, Direction direc return getScriptInterface()->callFunction(2); } -bool EventCallback::playerOnTradeRequest(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const { +bool EventCallback::playerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnTradeRequest - " "Player {} target {}] " @@ -705,7 +705,7 @@ bool EventCallback::playerOnTradeRequest(std::shared_ptr player, std::sh return getScriptInterface()->callFunction(3); } -bool EventCallback::playerOnTradeAccept(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, std::shared_ptr targetItem) const { +bool EventCallback::playerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item, std::shared_ptr targetItem) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnTradeAccept - " "Player {} target {}] " @@ -735,7 +735,7 @@ bool EventCallback::playerOnTradeAccept(std::shared_ptr player, std::sha return getScriptInterface()->callFunction(4); } -void EventCallback::playerOnGainExperience(std::shared_ptr player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) const { +void EventCallback::playerOnGainExperience(const std::shared_ptr &player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnGainExperience - " "Player {} target {}] " @@ -773,7 +773,7 @@ void EventCallback::playerOnGainExperience(std::shared_ptr player, std:: getScriptInterface()->resetScriptEnv(); } -void EventCallback::playerOnLoseExperience(std::shared_ptr player, uint64_t &exp) const { +void EventCallback::playerOnLoseExperience(const std::shared_ptr &player, uint64_t &exp) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLoseExperience - " "Player {}] " @@ -803,7 +803,7 @@ void EventCallback::playerOnLoseExperience(std::shared_ptr player, uint6 getScriptInterface()->resetScriptEnv(); } -void EventCallback::playerOnGainSkillTries(std::shared_ptr player, skills_t skill, uint64_t &tries) const { +void EventCallback::playerOnGainSkillTries(const std::shared_ptr &player, skills_t skill, uint64_t &tries) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnGainSkillTries - " "Player {} skill {}] " @@ -834,7 +834,7 @@ void EventCallback::playerOnGainSkillTries(std::shared_ptr player, skill getScriptInterface()->resetScriptEnv(); } -void EventCallback::playerOnCombat(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) const { +void EventCallback::playerOnCombat(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnCombat - " "Player {} target {}] " @@ -896,7 +896,7 @@ void EventCallback::playerOnCombat(std::shared_ptr player, std::shared_p getScriptInterface()->resetScriptEnv(); } -void EventCallback::playerOnRequestQuestLog(std::shared_ptr player) const { +void EventCallback::playerOnRequestQuestLog(const std::shared_ptr &player) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnRequestQuestLog - " "Player {}] " @@ -917,7 +917,7 @@ void EventCallback::playerOnRequestQuestLog(std::shared_ptr player) cons getScriptInterface()->callVoidFunction(1); } -void EventCallback::playerOnRequestQuestLine(std::shared_ptr player, uint16_t questId) const { +void EventCallback::playerOnRequestQuestLine(const std::shared_ptr &player, uint16_t questId) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnRequestQuestLine - " "Player {} questId {}] " @@ -940,7 +940,7 @@ void EventCallback::playerOnRequestQuestLine(std::shared_ptr player, uin getScriptInterface()->callVoidFunction(2); } -void EventCallback::playerOnInventoryUpdate(std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool equip) const { +void EventCallback::playerOnInventoryUpdate(const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool equip) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[{}] Call stack overflow", __FUNCTION__); return; @@ -964,7 +964,7 @@ void EventCallback::playerOnInventoryUpdate(std::shared_ptr player, std: getScriptInterface()->callVoidFunction(4); } -bool EventCallback::playerOnRotateItem(std::shared_ptr player, std::shared_ptr item, const Position &position) const { +bool EventCallback::playerOnRotateItem(const std::shared_ptr &player, std::shared_ptr item, const Position &position) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[{}] Call stack overflow", __FUNCTION__); return false; @@ -987,7 +987,7 @@ bool EventCallback::playerOnRotateItem(std::shared_ptr player, std::shar return getScriptInterface()->callFunction(3); } -void EventCallback::playerOnStorageUpdate(std::shared_ptr player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const { +void EventCallback::playerOnStorageUpdate(const std::shared_ptr &player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::eventOnStorageUpdate - " "Player {} key {}] " diff --git a/src/lua/callbacks/event_callback.hpp b/src/lua/callbacks/event_callback.hpp index e5712a06d71..b13c0dcfce6 100644 --- a/src/lua/callbacks/event_callback.hpp +++ b/src/lua/callbacks/event_callback.hpp @@ -86,36 +86,36 @@ class EventCallback : public Script { void creatureOnDrainHealth(std::shared_ptr creature, std::shared_ptr attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) const; // Party - bool partyOnJoin(Party* party, std::shared_ptr player) const; - bool partyOnLeave(Party* party, std::shared_ptr player) const; + bool partyOnJoin(Party* party, const std::shared_ptr & player) const; + bool partyOnLeave(Party* party, const std::shared_ptr & player) const; bool partyOnDisband(Party* party) const; void partyOnShareExperience(Party* party, uint64_t &exp) const; // Player - bool playerOnBrowseField(std::shared_ptr player, const Position &position) const; - void playerOnLook(std::shared_ptr player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) const; - void playerOnLookInBattleList(std::shared_ptr player, std::shared_ptr creature, int32_t lookDistance) const; - void playerOnLookInTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr item, int32_t lookDistance) const; - bool playerOnLookInShop(std::shared_ptr player, const ItemType* itemType, uint8_t count) const; - bool playerOnMoveItem(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; - void playerOnItemMoved(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; - void playerOnChangeZone(std::shared_ptr player, ZoneType_t zone) const; - bool playerOnMoveCreature(std::shared_ptr player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) const; - void playerOnReportRuleViolation(std::shared_ptr player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const; - void playerOnReportBug(std::shared_ptr player, const std::string &message, const Position &position, uint8_t category) const; - bool playerOnTurn(std::shared_ptr player, Direction direction) const; - bool playerOnTradeRequest(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const; - bool playerOnTradeAccept(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, std::shared_ptr targetItem) const; - void playerOnGainExperience(std::shared_ptr player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) const; - void playerOnLoseExperience(std::shared_ptr player, uint64_t &exp) const; - void playerOnGainSkillTries(std::shared_ptr player, skills_t skill, uint64_t &tries) const; - void playerOnRemoveCount(std::shared_ptr player, std::shared_ptr item) const; - void playerOnRequestQuestLog(std::shared_ptr player) const; - void playerOnRequestQuestLine(std::shared_ptr player, uint16_t questId) const; - void playerOnStorageUpdate(std::shared_ptr player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const; - void playerOnCombat(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) const; - void playerOnInventoryUpdate(std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool equip) const; - bool playerOnRotateItem(std::shared_ptr player, std::shared_ptr item, const Position &position) const; + bool playerOnBrowseField(const std::shared_ptr & player, const Position &position) const; + void playerOnLook(const std::shared_ptr & player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) const; + void playerOnLookInBattleList(const std::shared_ptr & player, std::shared_ptr creature, int32_t lookDistance) const; + void playerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr & partner, std::shared_ptr item, int32_t lookDistance) const; + bool playerOnLookInShop(const std::shared_ptr & player, const ItemType* itemType, uint8_t count) const; + bool playerOnMoveItem(const std::shared_ptr & player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; + void playerOnItemMoved(const std::shared_ptr & player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; + void playerOnChangeZone(const std::shared_ptr & player, ZoneType_t zone) const; + bool playerOnMoveCreature(const std::shared_ptr & player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) const; + void playerOnReportRuleViolation(const std::shared_ptr & player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const; + void playerOnReportBug(const std::shared_ptr & player, const std::string &message, const Position &position, uint8_t category) const; + bool playerOnTurn(const std::shared_ptr & player, Direction direction) const; + bool playerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr & target, std::shared_ptr item) const; + bool playerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr & target, std::shared_ptr item, std::shared_ptr targetItem) const; + void playerOnGainExperience(const std::shared_ptr & player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) const; + void playerOnLoseExperience(const std::shared_ptr & player, uint64_t &exp) const; + void playerOnGainSkillTries(const std::shared_ptr & player, skills_t skill, uint64_t &tries) const; + void playerOnRemoveCount(const std::shared_ptr & player, std::shared_ptr item) const; + void playerOnRequestQuestLog(const std::shared_ptr & player) const; + void playerOnRequestQuestLine(const std::shared_ptr & player, uint16_t questId) const; + void playerOnStorageUpdate(const std::shared_ptr & player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const; + void playerOnCombat(const std::shared_ptr & player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) const; + void playerOnInventoryUpdate(const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool equip) const; + bool playerOnRotateItem(const std::shared_ptr & player, std::shared_ptr item, const Position &position) const; // Monster void monsterOnDropLoot(std::shared_ptr monster, std::shared_ptr corpse) const; diff --git a/src/lua/creature/actions.cpp b/src/lua/creature/actions.cpp index 6a79d697eb7..4c2e3948bdb 100644 --- a/src/lua/creature/actions.cpp +++ b/src/lua/creature/actions.cpp @@ -166,7 +166,7 @@ bool Actions::registerLuaEvent(const std::shared_ptr action) { return false; } -ReturnValue Actions::canUse(std::shared_ptr player, const Position &pos) { +ReturnValue Actions::canUse(const std::shared_ptr & player, const Position &pos) { if (pos.x != 0xFFFF) { const Position &playerPos = player->getPosition(); if (playerPos.z != pos.z) { @@ -180,7 +180,7 @@ ReturnValue Actions::canUse(std::shared_ptr player, const Position &pos) return RETURNVALUE_NOERROR; } -ReturnValue Actions::canUse(std::shared_ptr player, const Position &pos, std::shared_ptr item) { +ReturnValue Actions::canUse(const std::shared_ptr & player, const Position &pos, std::shared_ptr item) { const std::shared_ptr action = getAction(item); if (action != nullptr) { return action->canExecuteAction(player, pos); @@ -233,7 +233,7 @@ std::shared_ptr Actions::getAction(std::shared_ptr item) { iteratePositions != actionPositionMap.end()) { if (std::shared_ptr tile = item->getTile(); tile) { - if (std::shared_ptr player = item->getHoldingPlayer(); + if (const auto &player = item->getHoldingPlayer(); player && item->getTopParent() == player) { g_logger().debug("[Actions::getAction] - The position only is valid for use item in the map, player name {}", player->getName()); return nullptr; @@ -247,7 +247,7 @@ std::shared_ptr Actions::getAction(std::shared_ptr item) { return g_spells().getRuneSpell(item->getID()); } -ReturnValue Actions::internalUseItem(std::shared_ptr player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { +ReturnValue Actions::internalUseItem(const std::shared_ptr & player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { if (std::shared_ptr door = item->getDoor()) { if (!door->canUse(player)) { return RETURNVALUE_CANNOTUSETHISOBJECT; @@ -383,7 +383,7 @@ ReturnValue Actions::internalUseItem(std::shared_ptr player, const Posit return RETURNVALUE_CANNOTUSETHISOBJECT; } -bool Actions::useItem(std::shared_ptr player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { +bool Actions::useItem(const std::shared_ptr & player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { const ItemType &it = Item::items[item->getID()]; if (it.isRune() || it.type == ITEM_TYPE_POTION) { if (player->walkExhausted()) { @@ -415,7 +415,7 @@ bool Actions::useItem(std::shared_ptr player, const Position &pos, uint8 return true; } -bool Actions::useItemEx(std::shared_ptr player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature /* = nullptr*/) { +bool Actions::useItemEx(const std::shared_ptr & player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature /* = nullptr*/) { const ItemType &it = Item::items[item->getID()]; if (it.isRune() || it.type == ITEM_TYPE_POTION) { if (player->walkExhausted()) { @@ -467,7 +467,7 @@ bool Actions::useItemEx(std::shared_ptr player, const Position &fromPos, return true; } -void Actions::showUseHotkeyMessage(std::shared_ptr player, std::shared_ptr item, uint32_t count) { +void Actions::showUseHotkeyMessage(const std::shared_ptr & player, std::shared_ptr item, uint32_t count) { std::ostringstream ss; const ItemType &it = Item::items[item->getID()]; @@ -491,7 +491,7 @@ void Actions::showUseHotkeyMessage(std::shared_ptr player, std::shared_p Action::Action(LuaScriptInterface* interface) : Script(interface) { } -ReturnValue Action::canExecuteAction(std::shared_ptr player, const Position &toPos) { +ReturnValue Action::canExecuteAction(const std::shared_ptr & player, const Position &toPos) { if (!allowFarUse) { return g_actions().canUse(player, toPos); } @@ -499,14 +499,14 @@ ReturnValue Action::canExecuteAction(std::shared_ptr player, const Posit return g_actions().canUseFar(player, toPos, checkLineOfSight, checkFloor); } -std::shared_ptr Action::getTarget(std::shared_ptr player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const { +std::shared_ptr Action::getTarget(const std::shared_ptr & player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const { if (targetCreature != nullptr) { return targetCreature; } return g_game().internalGetThing(player, toPosition, toStackPos, 0, STACKPOS_USETARGET); } -bool Action::executeUse(std::shared_ptr player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey) { +bool Action::executeUse(const std::shared_ptr & player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey) { // onUse(player, item, fromPosition, target, toPosition, isHotkey) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[Action::executeUse - Player {}, on item {}] " diff --git a/src/lua/creature/actions.hpp b/src/lua/creature/actions.hpp index c0fb1a27790..2dea104c7f5 100644 --- a/src/lua/creature/actions.hpp +++ b/src/lua/creature/actions.hpp @@ -21,7 +21,7 @@ class Action : public Script { explicit Action(LuaScriptInterface* interface); // Scripting - virtual bool executeUse(std::shared_ptr player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey); + virtual bool executeUse(const std::shared_ptr & player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey); bool getAllowFarUse() const { return allowFarUse; @@ -96,13 +96,13 @@ class Action : public Script { positions.emplace_back(pos); } - virtual ReturnValue canExecuteAction(std::shared_ptr player, const Position &toPos); + virtual ReturnValue canExecuteAction(const std::shared_ptr & player, const Position &toPos); virtual bool hasOwnErrorHandler() { return false; } - virtual std::shared_ptr getTarget(std::shared_ptr player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const; + virtual std::shared_ptr getTarget(const std::shared_ptr & player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const; private: std::string getScriptTypeName() const override { @@ -143,11 +143,11 @@ class Actions final : public Scripts { return inject(); } - bool useItem(std::shared_ptr player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); - bool useItemEx(std::shared_ptr player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature = nullptr); + bool useItem(const std::shared_ptr & player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); + bool useItemEx(const std::shared_ptr & player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature = nullptr); - ReturnValue canUse(std::shared_ptr player, const Position &pos); - ReturnValue canUse(std::shared_ptr player, const Position &pos, std::shared_ptr item); + ReturnValue canUse(const std::shared_ptr & player, const Position &pos); + ReturnValue canUse(const std::shared_ptr & player, const Position &pos, std::shared_ptr item); ReturnValue canUseFar(std::shared_ptr creature, const Position &toPos, bool checkLineOfSight, bool checkFloor); bool registerLuaItemEvent(const std::shared_ptr action); @@ -211,8 +211,8 @@ class Actions final : public Scripts { actionItemMap.try_emplace(actionId, action); } - ReturnValue internalUseItem(std::shared_ptr player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); - static void showUseHotkeyMessage(std::shared_ptr player, std::shared_ptr item, uint32_t count); + ReturnValue internalUseItem(const std::shared_ptr & player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); + static void showUseHotkeyMessage(const std::shared_ptr & player, std::shared_ptr item, uint32_t count); using ActionUseMap = std::map>; ActionUseMap useItemMap; diff --git a/src/lua/creature/creatureevent.cpp b/src/lua/creature/creatureevent.cpp index b1984be2fd6..8484d40ac7e 100644 --- a/src/lua/creature/creatureevent.cpp +++ b/src/lua/creature/creatureevent.cpp @@ -55,7 +55,7 @@ std::shared_ptr CreatureEvents::getEventByName(const std::string return nullptr; } -bool CreatureEvents::playerLogin(std::shared_ptr player) const { +bool CreatureEvents::playerLogin(const std::shared_ptr &player) const { // fire global event if is registered for (const auto &it : creatureEvents) { if (it.second->getEventType() == CREATURE_EVENT_LOGIN) { @@ -67,7 +67,7 @@ bool CreatureEvents::playerLogin(std::shared_ptr player) const { return true; } -bool CreatureEvents::playerLogout(std::shared_ptr player) const { +bool CreatureEvents::playerLogout(const std::shared_ptr &player) const { // fire global event if is registered for (const auto &it : creatureEvents) { if (it.second->getEventType() == CREATURE_EVENT_LOGOUT) { @@ -80,7 +80,7 @@ bool CreatureEvents::playerLogout(std::shared_ptr player) const { } bool CreatureEvents::playerAdvance( - std::shared_ptr player, + const std::shared_ptr &player, skills_t skill, uint32_t oldLevel, uint32_t newLevel @@ -171,7 +171,7 @@ void CreatureEvent::clearEvent() { loaded = false; } -bool CreatureEvent::executeOnLogin(std::shared_ptr player) const { +bool CreatureEvent::executeOnLogin(const std::shared_ptr &player) const { // onLogin(player) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeOnLogin - Player {} event {}]" @@ -191,7 +191,7 @@ bool CreatureEvent::executeOnLogin(std::shared_ptr player) const { return getScriptInterface()->callFunction(1); } -bool CreatureEvent::executeOnLogout(std::shared_ptr player) const { +bool CreatureEvent::executeOnLogout(const std::shared_ptr &player) const { // onLogout(player) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeOnLogout - Player {} event {}] " @@ -302,7 +302,7 @@ bool CreatureEvent::executeOnDeath(std::shared_ptr creature, std::shar return getScriptInterface()->callFunction(6); } -bool CreatureEvent::executeAdvance(std::shared_ptr player, skills_t skill, uint32_t oldLevel, uint32_t newLevel) const { +bool CreatureEvent::executeAdvance(const std::shared_ptr &player, skills_t skill, uint32_t oldLevel, uint32_t newLevel) const { // onAdvance(player, skill, oldLevel, newLevel) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeAdvance - Player {} event {}] " @@ -349,7 +349,7 @@ void CreatureEvent::executeOnKill(std::shared_ptr creature, std::share getScriptInterface()->callVoidFunction(3); } -void CreatureEvent::executeModalWindow(std::shared_ptr player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const { +void CreatureEvent::executeModalWindow(const std::shared_ptr &player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const { // onModalWindow(player, modalWindowId, buttonId, choiceId) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeModalWindow - " @@ -375,7 +375,7 @@ void CreatureEvent::executeModalWindow(std::shared_ptr player, uint32_t getScriptInterface()->callVoidFunction(4); } -bool CreatureEvent::executeTextEdit(std::shared_ptr player, std::shared_ptr item, const std::string &text) const { +bool CreatureEvent::executeTextEdit(const std::shared_ptr &player, std::shared_ptr item, const std::string &text) const { // onTextEdit(player, item, text) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeTextEdit - Player {} event {}] " @@ -484,7 +484,7 @@ void CreatureEvent::executeManaChange(std::shared_ptr creature, std::s getScriptInterface()->resetScriptEnv(); } -void CreatureEvent::executeExtendedOpcode(std::shared_ptr player, uint8_t opcode, const std::string &buffer) const { +void CreatureEvent::executeExtendedOpcode(const std::shared_ptr &player, uint8_t opcode, const std::string &buffer) const { // onExtendedOpcode(player, opcode, buffer) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeExtendedOpcode - " diff --git a/src/lua/creature/creatureevent.hpp b/src/lua/creature/creatureevent.hpp index 24052aa84a2..6817cd37687 100644 --- a/src/lua/creature/creatureevent.hpp +++ b/src/lua/creature/creatureevent.hpp @@ -43,18 +43,18 @@ class CreatureEvent final : public Script { void copyEvent(const std::shared_ptr creatureEvent); // scripting - bool executeOnLogin(std::shared_ptr player) const; - bool executeOnLogout(std::shared_ptr player) const; + bool executeOnLogin(const std::shared_ptr & player) const; + bool executeOnLogout(const std::shared_ptr & player) const; bool executeOnThink(std::shared_ptr creature, uint32_t interval) const; bool executeOnPrepareDeath(std::shared_ptr creature, std::shared_ptr killer) const; bool executeOnDeath(std::shared_ptr creature, std::shared_ptr corpse, std::shared_ptr killer, std::shared_ptr mostDamageKiller, bool lastHitUnjustified, bool mostDamageUnjustified) const; void executeOnKill(std::shared_ptr creature, std::shared_ptr target, bool lastHit) const; - bool executeAdvance(std::shared_ptr player, skills_t, uint32_t, uint32_t) const; - void executeModalWindow(std::shared_ptr player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const; - bool executeTextEdit(std::shared_ptr player, std::shared_ptr item, const std::string &text) const; + bool executeAdvance(const std::shared_ptr & player, skills_t, uint32_t, uint32_t) const; + void executeModalWindow(const std::shared_ptr & player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const; + bool executeTextEdit(const std::shared_ptr & player, std::shared_ptr item, const std::string &text) const; void executeHealthChange(std::shared_ptr creature, std::shared_ptr attacker, CombatDamage &damage) const; void executeManaChange(std::shared_ptr creature, std::shared_ptr attacker, CombatDamage &damage) const; - void executeExtendedOpcode(std::shared_ptr player, uint8_t opcode, const std::string &buffer) const; + void executeExtendedOpcode(const std::shared_ptr & player, uint8_t opcode, const std::string &buffer) const; // private: @@ -78,9 +78,9 @@ class CreatureEvents final : public Scripts { } // global events - bool playerLogin(std::shared_ptr player) const; - bool playerLogout(std::shared_ptr player) const; - bool playerAdvance(std::shared_ptr player, skills_t, uint32_t, uint32_t) const; + bool playerLogin(const std::shared_ptr & player) const; + bool playerLogout(const std::shared_ptr & player) const; + bool playerAdvance(const std::shared_ptr & player, skills_t, uint32_t, uint32_t) const; std::shared_ptr getEventByName(const std::string &name, bool forceLoaded = true); diff --git a/src/lua/creature/events.cpp b/src/lua/creature/events.cpp index 65f9270a58a..c05990f2c07 100644 --- a/src/lua/creature/events.cpp +++ b/src/lua/creature/events.cpp @@ -421,7 +421,7 @@ void Events::eventCreatureOnDrainHealth(std::shared_ptr creature, std: } // Party -bool Events::eventPartyOnJoin(Party* party, std::shared_ptr player) { +bool Events::eventPartyOnJoin(Party* party, const std::shared_ptr & player) { // Party:onJoin(player) or Party.onJoin(self, player) if (info.partyOnJoin == -1) { return true; @@ -450,7 +450,7 @@ bool Events::eventPartyOnJoin(Party* party, std::shared_ptr player) { return scriptInterface.callFunction(2); } -bool Events::eventPartyOnLeave(Party* party, std::shared_ptr player) { +bool Events::eventPartyOnLeave(Party* party, const std::shared_ptr & player) { // Party:onLeave(player) or Party.onLeave(self, player) if (info.partyOnLeave == -1) { return true; @@ -537,7 +537,7 @@ void Events::eventPartyOnShareExperience(Party* party, uint64_t &exp) { } // Player -bool Events::eventPlayerOnBrowseField(std::shared_ptr player, const Position &position) { +bool Events::eventPlayerOnBrowseField(const std::shared_ptr & player, const Position &position) { // Player:onBrowseField(position) or Player.onBrowseField(self, position) if (info.playerOnBrowseField == -1) { return true; @@ -565,7 +565,7 @@ bool Events::eventPlayerOnBrowseField(std::shared_ptr player, const Posi return scriptInterface.callFunction(2); } -void Events::eventPlayerOnLook(std::shared_ptr player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) { +void Events::eventPlayerOnLook(const std::shared_ptr & player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) { // Player:onLook(thing, position, distance) or Player.onLook(self, thing, position, distance) if (info.playerOnLook == -1) { return; @@ -604,7 +604,7 @@ void Events::eventPlayerOnLook(std::shared_ptr player, const Position &p scriptInterface.callVoidFunction(4); } -void Events::eventPlayerOnLookInBattleList(std::shared_ptr player, std::shared_ptr creature, int32_t lookDistance) { +void Events::eventPlayerOnLookInBattleList(const std::shared_ptr & player, std::shared_ptr creature, int32_t lookDistance) { // Player:onLookInBattleList(creature, position, distance) or Player.onLookInBattleList(self, creature, position, distance) if (info.playerOnLookInBattleList == -1) { return; @@ -635,7 +635,7 @@ void Events::eventPlayerOnLookInBattleList(std::shared_ptr player, std:: scriptInterface.callVoidFunction(3); } -void Events::eventPlayerOnLookInTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr item, int32_t lookDistance) { +void Events::eventPlayerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr & partner, std::shared_ptr item, int32_t lookDistance) { // Player:onLookInTrade(partner, item, distance) or Player.onLookInTrade(self, partner, item, distance) if (info.playerOnLookInTrade == -1) { return; @@ -669,7 +669,7 @@ void Events::eventPlayerOnLookInTrade(std::shared_ptr player, std::share scriptInterface.callVoidFunction(4); } -bool Events::eventPlayerOnLookInShop(std::shared_ptr player, const ItemType* itemType, uint8_t count) { +bool Events::eventPlayerOnLookInShop(const std::shared_ptr & player, const ItemType* itemType, uint8_t count) { // Player:onLookInShop(itemType, count) or Player.onLookInShop(self, itemType, count) if (info.playerOnLookInShop == -1) { return true; @@ -700,7 +700,7 @@ bool Events::eventPlayerOnLookInShop(std::shared_ptr player, const ItemT return scriptInterface.callFunction(3); } -bool Events::eventPlayerOnRemoveCount(std::shared_ptr player, std::shared_ptr item) { +bool Events::eventPlayerOnRemoveCount(const std::shared_ptr & player, std::shared_ptr item) { // Player:onMove() if (info.playerOnRemoveCount == -1) { return true; @@ -729,7 +729,7 @@ bool Events::eventPlayerOnRemoveCount(std::shared_ptr player, std::share return scriptInterface.callFunction(2); } -bool Events::eventPlayerOnMoveItem(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { +bool Events::eventPlayerOnMoveItem(const std::shared_ptr & player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { // Player:onMoveItem(item, count, fromPosition, toPosition) or Player.onMoveItem(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder) if (info.playerOnMoveItem == -1) { return true; @@ -765,7 +765,7 @@ bool Events::eventPlayerOnMoveItem(std::shared_ptr player, std::shared_p return scriptInterface.callFunction(7); } -void Events::eventPlayerOnItemMoved(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { +void Events::eventPlayerOnItemMoved(const std::shared_ptr & player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { // Player:onItemMoved(item, count, fromPosition, toPosition) or Player.onItemMoved(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder) if (info.playerOnItemMoved == -1) { return; @@ -801,7 +801,7 @@ void Events::eventPlayerOnItemMoved(std::shared_ptr player, std::shared_ scriptInterface.callVoidFunction(7); } -void Events::eventPlayerOnChangeZone(std::shared_ptr player, ZoneType_t zone) { +void Events::eventPlayerOnChangeZone(const std::shared_ptr & player, ZoneType_t zone) { // Player:onChangeZone(zone) if (info.playerOnChangeZone == -1) { return; @@ -828,7 +828,7 @@ void Events::eventPlayerOnChangeZone(std::shared_ptr player, ZoneType_t scriptInterface.callVoidFunction(2); } -bool Events::eventPlayerOnMoveCreature(std::shared_ptr player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) { +bool Events::eventPlayerOnMoveCreature(const std::shared_ptr & player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) { // Player:onMoveCreature(creature, fromPosition, toPosition) or Player.onMoveCreature(self, creature, fromPosition, toPosition) if (info.playerOnMoveCreature == -1) { return true; @@ -860,7 +860,7 @@ bool Events::eventPlayerOnMoveCreature(std::shared_ptr player, std::shar return scriptInterface.callFunction(4); } -void Events::eventPlayerOnReportRuleViolation(std::shared_ptr player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) { +void Events::eventPlayerOnReportRuleViolation(const std::shared_ptr & player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) { // Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation) if (info.playerOnReportRuleViolation == -1) { return; @@ -894,7 +894,7 @@ void Events::eventPlayerOnReportRuleViolation(std::shared_ptr player, co scriptInterface.callVoidFunction(6); } -bool Events::eventPlayerOnReportBug(std::shared_ptr player, const std::string &message, const Position &position, uint8_t category) { +bool Events::eventPlayerOnReportBug(const std::shared_ptr & player, const std::string &message, const Position &position, uint8_t category) { // Player:onReportBug(message, position, category) if (info.playerOnReportBug == -1) { return true; @@ -924,7 +924,7 @@ bool Events::eventPlayerOnReportBug(std::shared_ptr player, const std::s return scriptInterface.callFunction(4); } -bool Events::eventPlayerOnTurn(std::shared_ptr player, Direction direction) { +bool Events::eventPlayerOnTurn(const std::shared_ptr & player, Direction direction) { // Player:onTurn(direction) or Player.onTurn(self, direction) if (info.playerOnTurn == -1) { return true; @@ -952,7 +952,7 @@ bool Events::eventPlayerOnTurn(std::shared_ptr player, Direction directi return scriptInterface.callFunction(2); } -bool Events::eventPlayerOnTradeRequest(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) { +bool Events::eventPlayerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr & target, std::shared_ptr item) { // Player:onTradeRequest(target, item) if (info.playerOnTradeRequest == -1) { return true; @@ -984,7 +984,7 @@ bool Events::eventPlayerOnTradeRequest(std::shared_ptr player, std::shar return scriptInterface.callFunction(3); } -bool Events::eventPlayerOnTradeAccept(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, std::shared_ptr targetItem) { +bool Events::eventPlayerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr & target, std::shared_ptr item, std::shared_ptr targetItem) { // Player:onTradeAccept(target, item, targetItem) if (info.playerOnTradeAccept == -1) { return true; @@ -1019,7 +1019,7 @@ bool Events::eventPlayerOnTradeAccept(std::shared_ptr player, std::share return scriptInterface.callFunction(4); } -void Events::eventPlayerOnGainExperience(std::shared_ptr player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) { +void Events::eventPlayerOnGainExperience(const std::shared_ptr & player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) { // Player:onGainExperience(target, exp, rawExp) // rawExp gives the original exp which is not multiplied if (info.playerOnGainExperience == -1) { @@ -1063,7 +1063,7 @@ void Events::eventPlayerOnGainExperience(std::shared_ptr player, std::sh scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnLoseExperience(std::shared_ptr player, uint64_t &exp) { +void Events::eventPlayerOnLoseExperience(const std::shared_ptr & player, uint64_t &exp) { // Player:onLoseExperience(exp) if (info.playerOnLoseExperience == -1) { return; @@ -1098,7 +1098,7 @@ void Events::eventPlayerOnLoseExperience(std::shared_ptr player, uint64_ scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnGainSkillTries(std::shared_ptr player, skills_t skill, uint64_t &tries) { +void Events::eventPlayerOnGainSkillTries(const std::shared_ptr & player, skills_t skill, uint64_t &tries) { // Player:onGainSkillTries(skill, tries) if (info.playerOnGainSkillTries == -1) { return; @@ -1134,7 +1134,7 @@ void Events::eventPlayerOnGainSkillTries(std::shared_ptr player, skills_ scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnCombat(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) { +void Events::eventPlayerOnCombat(const std::shared_ptr & player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) { // Player:onCombat(target, item, primaryDamage, primaryType, secondaryDamage, secondaryType) if (info.playerOnCombat == -1) { return; @@ -1191,7 +1191,7 @@ void Events::eventPlayerOnCombat(std::shared_ptr player, std::shared_ptr scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnRequestQuestLog(std::shared_ptr player) { +void Events::eventPlayerOnRequestQuestLog(const std::shared_ptr & player) { // Player:onRequestQuestLog() if (info.playerOnRequestQuestLog == -1) { return; @@ -1217,7 +1217,7 @@ void Events::eventPlayerOnRequestQuestLog(std::shared_ptr player) { scriptInterface.callVoidFunction(1); } -void Events::eventPlayerOnRequestQuestLine(std::shared_ptr player, uint16_t questId) { +void Events::eventPlayerOnRequestQuestLine(const std::shared_ptr & player, uint16_t questId) { // Player::onRequestQuestLine() if (info.playerOnRequestQuestLine == -1) { return; @@ -1245,7 +1245,7 @@ void Events::eventPlayerOnRequestQuestLine(std::shared_ptr player, uint1 scriptInterface.callVoidFunction(2); } -void Events::eventPlayerOnInventoryUpdate(std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool equip) { +void Events::eventPlayerOnInventoryUpdate(const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool equip) { // Player:onInventoryUpdate(item, slot, equip) if (info.playerOnInventoryUpdate == -1) { return; @@ -1274,7 +1274,7 @@ void Events::eventPlayerOnInventoryUpdate(std::shared_ptr player, std::s scriptInterface.callVoidFunction(4); } -void Events::eventOnStorageUpdate(std::shared_ptr player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) { +void Events::eventOnStorageUpdate(const std::shared_ptr & player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) { // Player::onStorageUpdate(key, value, oldValue, currentTime) if (info.playerOnStorageUpdate == -1) { return; diff --git a/src/lua/creature/events.hpp b/src/lua/creature/events.hpp index 172144a6f9a..7efb4b0f068 100644 --- a/src/lua/creature/events.hpp +++ b/src/lua/creature/events.hpp @@ -88,35 +88,35 @@ class Events { void eventCreatureOnDrainHealth(std::shared_ptr creature, std::shared_ptr attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary); // Party - bool eventPartyOnJoin(Party* party, std::shared_ptr player); - bool eventPartyOnLeave(Party* party, std::shared_ptr player); + bool eventPartyOnJoin(Party* party, const std::shared_ptr & player); + bool eventPartyOnLeave(Party* party, const std::shared_ptr & player); bool eventPartyOnDisband(Party* party); void eventPartyOnShareExperience(Party* party, uint64_t &exp); // Player - bool eventPlayerOnBrowseField(std::shared_ptr player, const Position &position); - void eventPlayerOnLook(std::shared_ptr player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance); - void eventPlayerOnLookInBattleList(std::shared_ptr player, std::shared_ptr creature, int32_t lookDistance); - void eventPlayerOnLookInTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr item, int32_t lookDistance); - bool eventPlayerOnLookInShop(std::shared_ptr player, const ItemType* itemType, uint8_t count); - bool eventPlayerOnMoveItem(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); - void eventPlayerOnItemMoved(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); - void eventPlayerOnChangeZone(std::shared_ptr player, ZoneType_t zone); - bool eventPlayerOnMoveCreature(std::shared_ptr player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition); - void eventPlayerOnReportRuleViolation(std::shared_ptr player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation); - bool eventPlayerOnReportBug(std::shared_ptr player, const std::string &message, const Position &position, uint8_t category); - bool eventPlayerOnTurn(std::shared_ptr player, Direction direction); - bool eventPlayerOnTradeRequest(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item); - bool eventPlayerOnTradeAccept(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, std::shared_ptr targetItem); - void eventPlayerOnGainExperience(std::shared_ptr player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp); - void eventPlayerOnLoseExperience(std::shared_ptr player, uint64_t &exp); - void eventPlayerOnGainSkillTries(std::shared_ptr player, skills_t skill, uint64_t &tries); - bool eventPlayerOnRemoveCount(std::shared_ptr player, std::shared_ptr item); - void eventPlayerOnRequestQuestLog(std::shared_ptr player); - void eventPlayerOnRequestQuestLine(std::shared_ptr player, uint16_t questId); - void eventOnStorageUpdate(std::shared_ptr player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime); - void eventPlayerOnCombat(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage); - void eventPlayerOnInventoryUpdate(std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool equip); + bool eventPlayerOnBrowseField(const std::shared_ptr & player, const Position &position); + void eventPlayerOnLook(const std::shared_ptr & player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance); + void eventPlayerOnLookInBattleList(const std::shared_ptr & player, std::shared_ptr creature, int32_t lookDistance); + void eventPlayerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr & partner, std::shared_ptr item, int32_t lookDistance); + bool eventPlayerOnLookInShop(const std::shared_ptr & player, const ItemType* itemType, uint8_t count); + bool eventPlayerOnMoveItem(const std::shared_ptr & player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); + void eventPlayerOnItemMoved(const std::shared_ptr & player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); + void eventPlayerOnChangeZone(const std::shared_ptr & player, ZoneType_t zone); + bool eventPlayerOnMoveCreature(const std::shared_ptr & player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition); + void eventPlayerOnReportRuleViolation(const std::shared_ptr & player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation); + bool eventPlayerOnReportBug(const std::shared_ptr & player, const std::string &message, const Position &position, uint8_t category); + bool eventPlayerOnTurn(const std::shared_ptr & player, Direction direction); + bool eventPlayerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr & target, std::shared_ptr item); + bool eventPlayerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr & target, std::shared_ptr item, std::shared_ptr targetItem); + void eventPlayerOnGainExperience(const std::shared_ptr & player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp); + void eventPlayerOnLoseExperience(const std::shared_ptr & player, uint64_t &exp); + void eventPlayerOnGainSkillTries(const std::shared_ptr & player, skills_t skill, uint64_t &tries); + bool eventPlayerOnRemoveCount(const std::shared_ptr & player, std::shared_ptr item); + void eventPlayerOnRequestQuestLog(const std::shared_ptr & player); + void eventPlayerOnRequestQuestLine(const std::shared_ptr & player, uint16_t questId); + void eventOnStorageUpdate(const std::shared_ptr & player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime); + void eventPlayerOnCombat(const std::shared_ptr & player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage); + void eventPlayerOnInventoryUpdate(const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool equip); // Monster void eventMonsterOnDropLoot(std::shared_ptr monster, std::shared_ptr corpse); diff --git a/src/lua/creature/movement.cpp b/src/lua/creature/movement.cpp index 29ba10f8cce..fb673c628db 100644 --- a/src/lua/creature/movement.cpp +++ b/src/lua/creature/movement.cpp @@ -467,7 +467,7 @@ uint32_t MoveEvent::RemoveItemField(std::shared_ptr, std::shared_ptr return 1; } -uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool isCheck) { +uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool isCheck) { if (player == nullptr) { g_logger().error("[MoveEvent::EquipItem] - Player is nullptr"); return 0; @@ -581,7 +581,7 @@ uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, std::s return 1; } -uint32_t MoveEvent::DeEquipItem(const std::shared_ptr MoveEvent, std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool) { +uint32_t MoveEvent::DeEquipItem(const std::shared_ptr MoveEvent, const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool) { if (player == nullptr) { g_logger().error("[MoveEvent::EquipItem] - Player is nullptr"); return 0; @@ -679,7 +679,7 @@ bool MoveEvent::executeStep(const std::shared_ptr &creature, std::shar // Check if the new position is the same as the old one // If it is, log a warning and either teleport the player to their temple position if item type is an teleport auto fromPosition = creature->getLastPosition(); - if (auto player = creature->getPlayer(); item && fromPosition == pos && getEventType() == MOVE_EVENT_STEP_IN) { + if (const auto &player = creature->getPlayer(); item && fromPosition == pos && getEventType() == MOVE_EVENT_STEP_IN) { if (const ItemType &itemType = Item::items[item->getID()]; player && itemType.isTeleport()) { g_logger().warn("[{}] cannot teleport player: {}, to the same position: {} of fromPosition: {}", __FUNCTION__, player->getName(), pos.toString(), fromPosition.toString()); g_game().internalTeleport(player, player->getTemplePosition()); diff --git a/src/lua/creature/movement.hpp b/src/lua/creature/movement.hpp index d410cf2a03f..61089d95f8d 100644 --- a/src/lua/creature/movement.hpp +++ b/src/lua/creature/movement.hpp @@ -248,8 +248,8 @@ class MoveEvent final : public Script, public SharedObject { static uint32_t AddItemField(std::shared_ptr item, std::shared_ptr tileItem, const Position &pos); static uint32_t RemoveItemField(std::shared_ptr item, std::shared_ptr tileItem, const Position &pos); - static uint32_t EquipItem(const std::shared_ptr moveEvent, std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool boolean); - static uint32_t DeEquipItem(const std::shared_ptr moveEvent, std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool boolean); + static uint32_t EquipItem(const std::shared_ptr moveEvent, const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool boolean); + static uint32_t DeEquipItem(const std::shared_ptr moveEvent, const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool boolean); private: std::string getScriptTypeName() const override; diff --git a/src/lua/creature/talkaction.cpp b/src/lua/creature/talkaction.cpp index 4386f6f9b15..4308640a7f2 100644 --- a/src/lua/creature/talkaction.cpp +++ b/src/lua/creature/talkaction.cpp @@ -25,7 +25,7 @@ bool TalkActions::registerLuaEvent(const TalkAction_ptr &talkAction) { return inserted; } -bool TalkActions::checkWord(std::shared_ptr player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const { +bool TalkActions::checkWord(const std::shared_ptr & player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const { auto spacePos = std::ranges::find_if(words.begin(), words.end(), ::isspace); std::string firstWord = words.substr(0, spacePos - words.begin()); @@ -61,7 +61,7 @@ bool TalkActions::checkWord(std::shared_ptr player, SpeakClasses type, c return talkActionPtr->executeSay(player, words, param, type); } -TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(std::shared_ptr player, SpeakClasses type, const std::string &words) const { +TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(const std::shared_ptr & player, SpeakClasses type, const std::string &words) const { for (const auto &[talkactionWords, talkActionPtr] : talkActions) { if (talkactionWords.find(',') != std::string::npos) { auto wordsList = split(talkactionWords); @@ -79,7 +79,7 @@ TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(std::shared_ptr player, const std::string &words, const std::string ¶m, SpeakClasses type) const { +bool TalkAction::executeSay(const std::shared_ptr & player, const std::string &words, const std::string ¶m, SpeakClasses type) const { // onSay(player, words, param, type) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[TalkAction::executeSay - Player {} words {}] " diff --git a/src/lua/creature/talkaction.hpp b/src/lua/creature/talkaction.hpp index bc078a72d75..702602e474b 100644 --- a/src/lua/creature/talkaction.hpp +++ b/src/lua/creature/talkaction.hpp @@ -44,7 +44,7 @@ class TalkAction : public Script { } // scripting - bool executeSay(std::shared_ptr player, const std::string &words, const std::string ¶m, SpeakClasses type) const; + bool executeSay(const std::shared_ptr & player, const std::string &words, const std::string ¶m, SpeakClasses type) const; // void setGroupType(account::GroupType newGroupType) { @@ -78,8 +78,8 @@ class TalkActions final : public Scripts { return inject(); } - bool checkWord(std::shared_ptr player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const; - TalkActionResult_t checkPlayerCanSayTalkAction(std::shared_ptr player, SpeakClasses type, const std::string &words) const; + bool checkWord(const std::shared_ptr & player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const; + TalkActionResult_t checkPlayerCanSayTalkAction(const std::shared_ptr & player, SpeakClasses type, const std::string &words) const; bool registerLuaEvent(const TalkAction_ptr &talkAction); void clear(); diff --git a/src/lua/functions/core/game/bank_functions.cpp b/src/lua/functions/core/game/bank_functions.cpp index e9451a5a637..96ed1aa756b 100644 --- a/src/lua/functions/core/game/bank_functions.cpp +++ b/src/lua/functions/core/game/bank_functions.cpp @@ -91,7 +91,7 @@ int BankFunctions::luaBankTransferToGuild(lua_State* L) { int BankFunctions::luaBankWithdraw(lua_State* L) { // Bank.withdraw(player, amount[, source = player]) - auto player = getPlayer(L, 1); + const auto &player = getPlayer(L, 1); uint64_t amount = getNumber(L, 2); if (lua_gettop(L) == 2) { if (!player) { @@ -113,7 +113,7 @@ int BankFunctions::luaBankWithdraw(lua_State* L) { int BankFunctions::luaBankDeposit(lua_State* L) { // Bank.deposit(player, amount[, destination = player]) - auto player = getPlayer(L, 1); + const auto &player = getPlayer(L, 1); if (!player) { return 1; } @@ -150,7 +150,7 @@ std::shared_ptr BankFunctions::getBank(lua_State* L, int32_t arg, bool isG } return std::make_shared(guild); } - std::shared_ptr player = getPlayer(L, arg, true); + const auto player = getPlayer(L, arg, true); if (!player) { return nullptr; } diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index 1a23358aaf7..2ca5c1c170d 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -414,7 +414,7 @@ int GameFunctions::luaGameCreateMonster(lua_State* L) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, monster->getPosition(), true); for (std::shared_ptr spectator : spectators) { - if (auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { auto bossesOnTracker = g_ioBosstiary().getBosstiaryCooldownRaceId(tmpPlayer); // If not have boss to update, then kill loop for economize resources if (bossesOnTracker.size() == 0) { @@ -611,7 +611,7 @@ int GameFunctions::luaGameGetOfflinePlayer(lua_State* L) { int GameFunctions::luaGameGetNormalizedPlayerName(lua_State* L) { // Game.getNormalizedPlayerName(name) auto name = getString(L, 1); - std::shared_ptr player = g_game().getPlayerByName(name, true); + const auto player = g_game().getPlayerByName(name, true); if (player) { pushString(L, player->getName()); if (!player->isOnline()) { diff --git a/src/lua/functions/core/game/global_functions.cpp b/src/lua/functions/core/game/global_functions.cpp index a0f283188ae..e159ce4eb62 100644 --- a/src/lua/functions/core/game/global_functions.cpp +++ b/src/lua/functions/core/game/global_functions.cpp @@ -22,7 +22,7 @@ class Creature; int GlobalFunctions::luaDoPlayerAddItem(lua_State* L) { // doPlayerAddItem(cid, itemid, count/subtype, canDropOnMap) // doPlayerAddItem(cid, itemid, count, canDropOnMap, subtype) - std::shared_ptr player = getPlayer(L, 1); + const auto &player = getPlayer(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -303,7 +303,7 @@ int GlobalFunctions::luaDoAreaCombatHealth(lua_State* L) { damage.instantSpellName = getString(L, 9); damage.runeSpellName = getString(L, 10); if (creature) { - if (auto player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { player->wheel()->getCombatDataSpell(damage); } } @@ -347,7 +347,7 @@ int GlobalFunctions::luaDoTargetCombatHealth(lua_State* L) { damage.instantSpellName = getString(L, 9); damage.runeSpellName = getString(L, 10); if (creature) { - if (auto player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { player->wheel()->getCombatDataSpell(damage); } } @@ -385,7 +385,7 @@ int GlobalFunctions::luaDoAreaCombatMana(lua_State* L) { damage.instantSpellName = getString(L, 8); damage.runeSpellName = getString(L, 9); if (creature) { - if (auto player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { player->wheel()->getCombatDataSpell(damage); } } @@ -430,7 +430,7 @@ int GlobalFunctions::luaDoTargetCombatMana(lua_State* L) { damage.instantSpellName = getString(L, 7); damage.runeSpellName = getString(L, 8); if (creature) { - if (auto player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { player->wheel()->getCombatDataSpell(damage); } } @@ -742,14 +742,14 @@ int GlobalFunctions::luaDebugPrint(lua_State* L) { int GlobalFunctions::luaIsInWar(lua_State* L) { // isInWar(cid, target) - std::shared_ptr player = getPlayer(L, 1); + const auto &player = getPlayer(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); return 1; } - std::shared_ptr targetPlayer = getPlayer(L, 2); + const auto &targetPlayer = getPlayer(L, 2); if (!targetPlayer) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/core/game/modal_window_functions.cpp b/src/lua/functions/core/game/modal_window_functions.cpp index a56db5a6b65..e7aa9681c79 100644 --- a/src/lua/functions/core/game/modal_window_functions.cpp +++ b/src/lua/functions/core/game/modal_window_functions.cpp @@ -213,7 +213,7 @@ int ModalWindowFunctions::luaModalWindowSetPriority(lua_State* L) { int ModalWindowFunctions::luaModalWindowSendToPlayer(lua_State* L) { // modalWindow:sendToPlayer(player) - std::shared_ptr player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/core/game/zone_functions.cpp b/src/lua/functions/core/game/zone_functions.cpp index d1b341a1aea..ef12be0d988 100644 --- a/src/lua/functions/core/game/zone_functions.cpp +++ b/src/lua/functions/core/game/zone_functions.cpp @@ -171,7 +171,7 @@ int ZoneFunctions::luaZoneGetPlayers(lua_State* L) { pushBoolean(L, false); return 1; } - auto players = zone->getPlayers(); + const auto &players = zone->getPlayers(); lua_createtable(L, static_cast(players.size()), 0); int index = 0; diff --git a/src/lua/functions/core/network/network_message_functions.cpp b/src/lua/functions/core/network/network_message_functions.cpp index d989df46095..771679a456a 100644 --- a/src/lua/functions/core/network/network_message_functions.cpp +++ b/src/lua/functions/core/network/network_message_functions.cpp @@ -247,7 +247,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddItem(lua_State* L) { return 1; } - std::shared_ptr player = getUserdataShared(L, 3); + const auto &player = getUserdataShared(L, 3); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -297,7 +297,7 @@ int NetworkMessageFunctions::luaNetworkMessageSendToPlayer(lua_State* L) { return 1; } - std::shared_ptr player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (player) { player->sendNetworkMessage(*message); pushBoolean(L, true); diff --git a/src/lua/functions/creatures/combat/combat_functions.cpp b/src/lua/functions/creatures/combat/combat_functions.cpp index 889afefb2b8..c1a5ebf2889 100644 --- a/src/lua/functions/creatures/combat/combat_functions.cpp +++ b/src/lua/functions/creatures/combat/combat_functions.cpp @@ -188,7 +188,7 @@ int CombatFunctions::luaCombatExecute(lua_State* L) { } case VARIANT_STRING: { - std::shared_ptr target = g_game().getPlayerByName(variant.text); + const auto &target = g_game().getPlayerByName(variant.text); if (!target) { pushBoolean(L, false); return 1; diff --git a/src/lua/functions/creatures/creature_functions.cpp b/src/lua/functions/creatures/creature_functions.cpp index 8890ca96708..32f7ef53135 100644 --- a/src/lua/functions/creatures/creature_functions.cpp +++ b/src/lua/functions/creatures/creature_functions.cpp @@ -484,7 +484,7 @@ int CreatureFunctions::luaCreatureSetHealth(lua_State* L) { creature->health = std::min(getNumber(L, 2), creature->healthMax); g_game().addCreatureHealth(creature); - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player) { player->sendStats(); } @@ -536,7 +536,7 @@ int CreatureFunctions::luaCreatureSetMaxHealth(lua_State* L) { creature->health = std::min(creature->health, creature->healthMax); g_game().addCreatureHealth(creature); - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player) { player->sendStats(); } @@ -736,7 +736,7 @@ int CreatureFunctions::luaCreatureRemove(lua_State* L) { } bool forced = getBoolean(L, 2, true); - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { if (forced) { player->removePlayer(true); } else { diff --git a/src/lua/functions/creatures/monster/monster_functions.cpp b/src/lua/functions/creatures/monster/monster_functions.cpp index 14c400fa5ff..01e0ddce3bd 100644 --- a/src/lua/functions/creatures/monster/monster_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_functions.cpp @@ -95,7 +95,7 @@ int MonsterFunctions::luaMonsterSetType(lua_State* L) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, monster->getPosition(), true); for (auto spectator : spectators) { - if (auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendCreatureReload(monster); } } diff --git a/src/lua/functions/creatures/npc/npc_functions.cpp b/src/lua/functions/creatures/npc/npc_functions.cpp index 56d8411d909..9a2b9a0ac45 100644 --- a/src/lua/functions/creatures/npc/npc_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_functions.cpp @@ -346,7 +346,7 @@ int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { return 1; } - std::shared_ptr player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -359,7 +359,7 @@ int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { int NpcFunctions::luaNpcCloseShopWindow(lua_State* L) { // npc:closeShopWindow(player) - std::shared_ptr player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -477,7 +477,7 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { return 1; } - std::shared_ptr player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/creatures/player/guild_functions.cpp b/src/lua/functions/creatures/player/guild_functions.cpp index 7dd23f45844..aa9402eabe8 100644 --- a/src/lua/functions/creatures/player/guild_functions.cpp +++ b/src/lua/functions/creatures/player/guild_functions.cpp @@ -58,7 +58,7 @@ int GuildFunctions::luaGuildGetMembersOnline(lua_State* L) { lua_createtable(L, members.size(), 0); int index = 0; - for (std::shared_ptr player : members) { + for (const std::shared_ptr & player : members) { pushUserdata(L, player); setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); diff --git a/src/lua/functions/creatures/player/party_functions.cpp b/src/lua/functions/creatures/player/party_functions.cpp index e51d231ebf8..db740638bb9 100644 --- a/src/lua/functions/creatures/player/party_functions.cpp +++ b/src/lua/functions/creatures/player/party_functions.cpp @@ -16,7 +16,7 @@ int32_t PartyFunctions::luaPartyCreate(lua_State* L) { // Party(userdata) - std::shared_ptr player = getUserdataShared(L, 2); + const auto &player = getUserdataShared(L, 2); if (!player) { lua_pushnil(L); return 1; @@ -57,7 +57,7 @@ int PartyFunctions::luaPartyGetLeader(lua_State* L) { return 1; } - std::shared_ptr leader = party->getLeader(); + const auto &leader = party->getLeader(); if (leader) { pushUserdata(L, leader); setMetatable(L, -1, "Player"); @@ -69,7 +69,7 @@ int PartyFunctions::luaPartyGetLeader(lua_State* L) { int PartyFunctions::luaPartySetLeader(lua_State* L) { // party:setLeader(player) - std::shared_ptr player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { pushBoolean(L, party->passPartyLeadership(player)); @@ -89,7 +89,7 @@ int PartyFunctions::luaPartyGetMembers(lua_State* L) { int index = 0; lua_createtable(L, party->getMemberCount(), 0); - for (std::shared_ptr player : party->getMembers()) { + for (const std::shared_ptr & player : party->getMembers()) { pushUserdata(L, player); setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); @@ -115,7 +115,7 @@ int PartyFunctions::luaPartyGetInvitees(lua_State* L) { lua_createtable(L, party->getInvitationCount(), 0); int index = 0; - for (std::shared_ptr player : party->getInvitees()) { + for (const std::shared_ptr & player : party->getInvitees()) { pushUserdata(L, player); setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); @@ -139,7 +139,7 @@ int PartyFunctions::luaPartyGetInviteeCount(lua_State* L) { int PartyFunctions::luaPartyAddInvite(lua_State* L) { // party:addInvite(player) - std::shared_ptr player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { pushBoolean(L, party->invitePlayer(player)); @@ -151,7 +151,7 @@ int PartyFunctions::luaPartyAddInvite(lua_State* L) { int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { // party:removeInvite(player) - std::shared_ptr player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { pushBoolean(L, party->removeInvite(player)); @@ -163,7 +163,7 @@ int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { int PartyFunctions::luaPartyAddMember(lua_State* L) { // party:addMember(player) - std::shared_ptr player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { pushBoolean(L, party->joinParty(player)); @@ -175,7 +175,7 @@ int PartyFunctions::luaPartyAddMember(lua_State* L) { int PartyFunctions::luaPartyRemoveMember(lua_State* L) { // party:removeMember(player) - std::shared_ptr player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { pushBoolean(L, party->leaveParty(player)); diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index afb991f816d..6fc333e4f2e 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -22,7 +22,7 @@ int PlayerFunctions::luaPlayerSendInventory(lua_State* L) { // player:sendInventory() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -36,7 +36,7 @@ int PlayerFunctions::luaPlayerSendInventory(lua_State* L) { int PlayerFunctions::luaPlayerSendLootStats(lua_State* L) { // player:sendLootStats(item, count) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -62,7 +62,7 @@ int PlayerFunctions::luaPlayerSendLootStats(lua_State* L) { int PlayerFunctions::luaPlayerUpdateSupplyTracker(lua_State* L) { // player:updateSupplyTracker(item) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -82,7 +82,7 @@ int PlayerFunctions::luaPlayerUpdateSupplyTracker(lua_State* L) { int PlayerFunctions::luaPlayerUpdateKillTracker(lua_State* L) { // player:updateKillTracker(creature, corpse) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -145,7 +145,7 @@ int PlayerFunctions::luaPlayerCreate(lua_State* L) { int PlayerFunctions::luaPlayerResetCharmsMonsters(lua_State* L) { // player:resetCharmsBestiary() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->setCharmPoints(0); player->setCharmExpansion(false); @@ -163,7 +163,7 @@ int PlayerFunctions::luaPlayerResetCharmsMonsters(lua_State* L) { int PlayerFunctions::luaPlayerUnlockAllCharmRunes(lua_State* L) { // player:unlockAllCharmRunes() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { for (int8_t i = CHARM_WOUND; i <= CHARM_LAST; i++) { const auto charm = g_iobestiary().getBestiaryCharm(static_cast(i)); @@ -181,7 +181,7 @@ int PlayerFunctions::luaPlayerUnlockAllCharmRunes(lua_State* L) { int PlayerFunctions::luaPlayeraddCharmPoints(lua_State* L) { // player:addCharmPoints() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { int16_t charms = getNumber(L, 2); if (charms >= 0) { @@ -205,7 +205,7 @@ int PlayerFunctions::luaPlayerIsPlayer(lua_State* L) { int PlayerFunctions::luaPlayerGetGuid(lua_State* L) { // player:getGuid() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getGUID()); } else { @@ -216,7 +216,7 @@ int PlayerFunctions::luaPlayerGetGuid(lua_State* L) { int PlayerFunctions::luaPlayerGetIp(lua_State* L) { // player:getIp() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getIP()); } else { @@ -227,7 +227,7 @@ int PlayerFunctions::luaPlayerGetIp(lua_State* L) { int PlayerFunctions::luaPlayerGetAccountId(lua_State* L) { // player:getAccountId() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player || player->getAccountId() == 0) { lua_pushnil(L); return 1; @@ -240,7 +240,7 @@ int PlayerFunctions::luaPlayerGetAccountId(lua_State* L) { int PlayerFunctions::luaPlayerGetLastLoginSaved(lua_State* L) { // player:getLastLoginSaved() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getLastLoginSaved()); } else { @@ -251,7 +251,7 @@ int PlayerFunctions::luaPlayerGetLastLoginSaved(lua_State* L) { int PlayerFunctions::luaPlayerGetLastLogout(lua_State* L) { // player:getLastLogout() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getLastLogout()); } else { @@ -262,7 +262,7 @@ int PlayerFunctions::luaPlayerGetLastLogout(lua_State* L) { int PlayerFunctions::luaPlayerGetAccountType(lua_State* L) { // player:getAccountType() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getAccountType()); } else { @@ -273,7 +273,7 @@ int PlayerFunctions::luaPlayerGetAccountType(lua_State* L) { int PlayerFunctions::luaPlayerSetAccountType(lua_State* L) { // player:setAccountType(accountType) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { lua_pushnil(L); return 1; @@ -295,7 +295,7 @@ int PlayerFunctions::luaPlayerSetAccountType(lua_State* L) { int PlayerFunctions::luaPlayerAddBestiaryKill(lua_State* L) { // player:addBestiaryKill(name[, amount = 1]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { const auto mtype = g_monsters().getMonsterType(getString(L, 2)); if (mtype) { @@ -312,7 +312,7 @@ int PlayerFunctions::luaPlayerAddBestiaryKill(lua_State* L) { int PlayerFunctions::luaPlayerIsMonsterBestiaryUnlocked(lua_State* L) { // player:isMonsterBestiaryUnlocked(raceId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -340,7 +340,7 @@ int PlayerFunctions::luaPlayerIsMonsterBestiaryUnlocked(lua_State* L) { int PlayerFunctions::luaPlayergetCharmMonsterType(lua_State* L) { // player:getCharmMonsterType(charmRune_t) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { charmRune_t charmid = getNumber(L, 2); uint16_t raceid = player->parseRacebyCharm(charmid, false, 0); @@ -363,7 +363,7 @@ int PlayerFunctions::luaPlayergetCharmMonsterType(lua_State* L) { int PlayerFunctions::luaPlayerRemovePreyStamina(lua_State* L) { // player:removePreyStamina(amount) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { g_ioprey().CheckPlayerPreys(player, getNumber(L, 2, 1)); pushBoolean(L, true); @@ -375,7 +375,7 @@ int PlayerFunctions::luaPlayerRemovePreyStamina(lua_State* L) { int PlayerFunctions::luaPlayerAddPreyCards(lua_State* L) { // player:addPreyCards(amount) - if (std::shared_ptr player = getUserdataShared(L, 1)) { + if (const auto &player = getUserdataShared(L, 1)) { player->addPreyCards(getNumber(L, 2, 0)); pushBoolean(L, true); } else { @@ -386,7 +386,7 @@ int PlayerFunctions::luaPlayerAddPreyCards(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyCards(lua_State* L) { // player:getPreyCards() - if (std::shared_ptr player = getUserdataShared(L, 1)) { + if (const auto &player = getUserdataShared(L, 1)) { lua_pushnumber(L, static_cast(player->getPreyCards())); } else { lua_pushnil(L); @@ -396,7 +396,7 @@ int PlayerFunctions::luaPlayerGetPreyCards(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyExperiencePercentage(lua_State* L) { // player:getPreyExperiencePercentage(raceId) - if (std::shared_ptr player = getUserdataShared(L, 1)) { + if (const auto &player = getUserdataShared(L, 1)) { if (const PreySlot* slot = player->getPreyWithMonster(getNumber(L, 2, 0)); slot && slot->isOccupied() && slot->bonus == PreyBonus_Experience && slot->bonusTimeLeft > 0) { lua_pushnumber(L, static_cast(100 + slot->bonusPercentage)); @@ -411,7 +411,7 @@ int PlayerFunctions::luaPlayerGetPreyExperiencePercentage(lua_State* L) { int PlayerFunctions::luaPlayerRemoveTaskHuntingPoints(lua_State* L) { // player:removeTaskHuntingPoints(amount) - if (std::shared_ptr player = getUserdataShared(L, 1)) { + if (const auto &player = getUserdataShared(L, 1)) { pushBoolean(L, player->useTaskHuntingPoints(getNumber(L, 2, 0))); } else { lua_pushnil(L); @@ -421,7 +421,7 @@ int PlayerFunctions::luaPlayerRemoveTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetTaskHuntingPoints(lua_State* L) { // player:getTaskHuntingPoints() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -434,7 +434,7 @@ int PlayerFunctions::luaPlayerGetTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerAddTaskHuntingPoints(lua_State* L) { // player:addTaskHuntingPoints(amount) - if (std::shared_ptr player = getUserdataShared(L, 1)) { + if (const auto &player = getUserdataShared(L, 1)) { auto points = getNumber(L, 2); player->addTaskHuntingPoints(getNumber(L, 2)); lua_pushnumber(L, static_cast(points)); @@ -446,7 +446,7 @@ int PlayerFunctions::luaPlayerAddTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyLootPercentage(lua_State* L) { // player:getPreyLootPercentage(raceid) - if (std::shared_ptr player = getUserdataShared(L, 1)) { + if (const auto &player = getUserdataShared(L, 1)) { if (const PreySlot* slot = player->getPreyWithMonster(getNumber(L, 2, 0)); slot && slot->isOccupied() && slot->bonus == PreyBonus_Loot) { lua_pushnumber(L, slot->bonusPercentage); @@ -461,7 +461,7 @@ int PlayerFunctions::luaPlayerGetPreyLootPercentage(lua_State* L) { int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { // get: player:preyThirdSlot() set: player:preyThirdSlot(bool) - if (std::shared_ptr player = getUserdataShared(L, 1); + if (const auto &player = getUserdataShared(L, 1); PreySlot* slot = player->getPreySlotById(PreySlot_Three)) { if (lua_gettop(L) == 1) { pushBoolean(L, slot->state != PreyDataState_Locked); @@ -485,7 +485,7 @@ int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { int PlayerFunctions::luaPlayerTaskThirdSlot(lua_State* L) { // get: player:taskHuntingThirdSlot() set: player:taskHuntingThirdSlot(bool) - if (std::shared_ptr player = getUserdataShared(L, 1); + if (const auto &player = getUserdataShared(L, 1); TaskHuntingSlot* slot = player->getTaskHuntingSlotById(PreySlot_Three)) { if (lua_gettop(L) == 1) { pushBoolean(L, slot->state != PreyTaskDataState_Locked); @@ -510,7 +510,7 @@ int PlayerFunctions::luaPlayerTaskThirdSlot(lua_State* L) { int PlayerFunctions::luaPlayercharmExpansion(lua_State* L) { // get: player:charmExpansion() set: player:charmExpansion(bool) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { if (lua_gettop(L) == 1) { pushBoolean(L, player->hasCharmExpansion()); @@ -526,7 +526,7 @@ int PlayerFunctions::luaPlayercharmExpansion(lua_State* L) { int PlayerFunctions::luaPlayerGetCapacity(lua_State* L) { // player:getCapacity() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getCapacity()); } else { @@ -537,7 +537,7 @@ int PlayerFunctions::luaPlayerGetCapacity(lua_State* L) { int PlayerFunctions::luaPlayerSetCapacity(lua_State* L) { // player:setCapacity(capacity) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->capacity = getNumber(L, 2); player->sendStats(); @@ -550,7 +550,7 @@ int PlayerFunctions::luaPlayerSetCapacity(lua_State* L) { int PlayerFunctions::luaPlayerSetTraining(lua_State* L) { // player:setTraining(value) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { bool value = getBoolean(L, 2, false); player->setTraining(value); @@ -563,7 +563,7 @@ int PlayerFunctions::luaPlayerSetTraining(lua_State* L) { int PlayerFunctions::luaPlayerGetIsTraining(lua_State* L) { // player:isTraining() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { pushBoolean(L, false); reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); @@ -576,7 +576,7 @@ int PlayerFunctions::luaPlayerGetIsTraining(lua_State* L) { int PlayerFunctions::luaPlayerGetFreeCapacity(lua_State* L) { // player:getFreeCapacity() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getFreeCapacity()); } else { @@ -587,7 +587,7 @@ int PlayerFunctions::luaPlayerGetFreeCapacity(lua_State* L) { int PlayerFunctions::luaPlayerGetKills(lua_State* L) { // player:getKills() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -611,7 +611,7 @@ int PlayerFunctions::luaPlayerGetKills(lua_State* L) { int PlayerFunctions::luaPlayerSetKills(lua_State* L) { // player:setKills(kills) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -639,7 +639,7 @@ int PlayerFunctions::luaPlayerSetKills(lua_State* L) { int PlayerFunctions::luaPlayerGetReward(lua_State* L) { // player:getReward(rewardId[, autoCreate = false]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -658,7 +658,7 @@ int PlayerFunctions::luaPlayerGetReward(lua_State* L) { int PlayerFunctions::luaPlayerRemoveReward(lua_State* L) { // player:removeReward(rewardId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -672,7 +672,7 @@ int PlayerFunctions::luaPlayerRemoveReward(lua_State* L) { int PlayerFunctions::luaPlayerGetRewardList(lua_State* L) { // player:getRewardList() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -692,7 +692,7 @@ int PlayerFunctions::luaPlayerGetRewardList(lua_State* L) { int PlayerFunctions::luaPlayerSetDailyReward(lua_State* L) { // player:setDailyReward(value) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->setDailyReward(getNumber(L, 2)); pushBoolean(L, true); @@ -704,7 +704,7 @@ int PlayerFunctions::luaPlayerSetDailyReward(lua_State* L) { int PlayerFunctions::luaPlayerGetDepotLocker(lua_State* L) { // player:getDepotLocker(depotId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -724,7 +724,7 @@ int PlayerFunctions::luaPlayerGetDepotLocker(lua_State* L) { int PlayerFunctions::luaPlayerGetStashCounter(lua_State* L) { // player:getStashCount() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint16_t sizeStash = getStashSize(player->getStashItems()); lua_pushnumber(L, sizeStash); @@ -736,7 +736,7 @@ int PlayerFunctions::luaPlayerGetStashCounter(lua_State* L) { int PlayerFunctions::luaPlayerGetDepotChest(lua_State* L) { // player:getDepotChest(depotId[, autoCreate = false]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -757,7 +757,7 @@ int PlayerFunctions::luaPlayerGetDepotChest(lua_State* L) { int PlayerFunctions::luaPlayerGetInbox(lua_State* L) { // player:getInbox() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -775,7 +775,7 @@ int PlayerFunctions::luaPlayerGetInbox(lua_State* L) { int PlayerFunctions::luaPlayerGetSkullTime(lua_State* L) { // player:getSkullTime() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSkullTicks()); } else { @@ -786,7 +786,7 @@ int PlayerFunctions::luaPlayerGetSkullTime(lua_State* L) { int PlayerFunctions::luaPlayerSetSkullTime(lua_State* L) { // player:setSkullTime(skullTime) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->setSkullTicks(getNumber(L, 2)); pushBoolean(L, true); @@ -798,7 +798,7 @@ int PlayerFunctions::luaPlayerSetSkullTime(lua_State* L) { int PlayerFunctions::luaPlayerGetDeathPenalty(lua_State* L) { // player:getDeathPenalty() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, static_cast(player->getLostPercent() * 100)); } else { @@ -809,7 +809,7 @@ int PlayerFunctions::luaPlayerGetDeathPenalty(lua_State* L) { int PlayerFunctions::luaPlayerGetExperience(lua_State* L) { // player:getExperience() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getExperience()); } else { @@ -820,7 +820,7 @@ int PlayerFunctions::luaPlayerGetExperience(lua_State* L) { int PlayerFunctions::luaPlayerAddExperience(lua_State* L) { // player:addExperience(experience[, sendText = false]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { int64_t experience = getNumber(L, 2); bool sendText = getBoolean(L, 3, false); @@ -834,7 +834,7 @@ int PlayerFunctions::luaPlayerAddExperience(lua_State* L) { int PlayerFunctions::luaPlayerRemoveExperience(lua_State* L) { // player:removeExperience(experience[, sendText = false]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { int64_t experience = getNumber(L, 2); bool sendText = getBoolean(L, 3, false); @@ -848,7 +848,7 @@ int PlayerFunctions::luaPlayerRemoveExperience(lua_State* L) { int PlayerFunctions::luaPlayerGetLevel(lua_State* L) { // player:getLevel() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getLevel()); } else { @@ -859,7 +859,7 @@ int PlayerFunctions::luaPlayerGetLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetMagicShieldCapacityFlat(lua_State* L) { // player:getMagicShieldCapacityFlat(useCharges) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMagicShieldCapacityFlat(getBoolean(L, 2, false))); } else { @@ -870,7 +870,7 @@ int PlayerFunctions::luaPlayerGetMagicShieldCapacityFlat(lua_State* L) { int PlayerFunctions::luaPlayerGetMagicShieldCapacityPercent(lua_State* L) { // player:getMagicShieldCapacityPercent(useCharges) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMagicShieldCapacityPercent(getBoolean(L, 2, false))); } else { @@ -881,7 +881,7 @@ int PlayerFunctions::luaPlayerGetMagicShieldCapacityPercent(lua_State* L) { int PlayerFunctions::luaPlayerSendSpellCooldown(lua_State* L) { // player:sendSpellCooldown(spellId, time) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -897,7 +897,7 @@ int PlayerFunctions::luaPlayerSendSpellCooldown(lua_State* L) { int PlayerFunctions::luaPlayerSendSpellGroupCooldown(lua_State* L) { // player:sendSpellGroupCooldown(groupId, time) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -913,7 +913,7 @@ int PlayerFunctions::luaPlayerSendSpellGroupCooldown(lua_State* L) { int PlayerFunctions::luaPlayerGetMagicLevel(lua_State* L) { // player:getMagicLevel() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMagicLevel()); } else { @@ -924,7 +924,7 @@ int PlayerFunctions::luaPlayerGetMagicLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseMagicLevel(lua_State* L) { // player:getBaseMagicLevel() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getBaseMagicLevel()); } else { @@ -935,7 +935,7 @@ int PlayerFunctions::luaPlayerGetBaseMagicLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetMana(lua_State* L) { // player:getMana() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMana()); } else { @@ -946,7 +946,7 @@ int PlayerFunctions::luaPlayerGetMana(lua_State* L) { int PlayerFunctions::luaPlayerAddMana(lua_State* L) { // player:addMana(manaChange[, animationOnLoss = false]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -968,7 +968,7 @@ int PlayerFunctions::luaPlayerAddMana(lua_State* L) { int PlayerFunctions::luaPlayerGetMaxMana(lua_State* L) { // player:getMaxMana() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMaxMana()); } else { @@ -979,7 +979,7 @@ int PlayerFunctions::luaPlayerGetMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerSetMaxMana(lua_State* L) { // player:setMaxMana(maxMana) - std::shared_ptr player = getPlayer(L, 1); + const auto &player = getPlayer(L, 1); if (player) { player->manaMax = getNumber(L, 2); player->mana = std::min(player->mana, player->manaMax); @@ -994,7 +994,7 @@ int PlayerFunctions::luaPlayerSetMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerGetManaSpent(lua_State* L) { // player:getManaSpent() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSpentMana()); } else { @@ -1005,7 +1005,7 @@ int PlayerFunctions::luaPlayerGetManaSpent(lua_State* L) { int PlayerFunctions::luaPlayerAddManaSpent(lua_State* L) { // player:addManaSpent(amount) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->addManaSpent(getNumber(L, 2)); pushBoolean(L, true); @@ -1017,7 +1017,7 @@ int PlayerFunctions::luaPlayerAddManaSpent(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseMaxHealth(lua_State* L) { // player:getBaseMaxHealth() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->healthMax); } else { @@ -1028,7 +1028,7 @@ int PlayerFunctions::luaPlayerGetBaseMaxHealth(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseMaxMana(lua_State* L) { // player:getBaseMaxMana() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->manaMax); } else { @@ -1040,7 +1040,7 @@ int PlayerFunctions::luaPlayerGetBaseMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerGetSkillLevel(lua_State* L) { // player:getSkillLevel(skillType) skills_t skillType = getNumber(L, 2); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->skills[skillType].level); } else { @@ -1052,7 +1052,7 @@ int PlayerFunctions::luaPlayerGetSkillLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetEffectiveSkillLevel(lua_State* L) { // player:getEffectiveSkillLevel(skillType) skills_t skillType = getNumber(L, 2); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->getSkillLevel(skillType)); } else { @@ -1064,7 +1064,7 @@ int PlayerFunctions::luaPlayerGetEffectiveSkillLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetSkillPercent(lua_State* L) { // player:getSkillPercent(skillType) skills_t skillType = getNumber(L, 2); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->skills[skillType].percent); } else { @@ -1076,7 +1076,7 @@ int PlayerFunctions::luaPlayerGetSkillPercent(lua_State* L) { int PlayerFunctions::luaPlayerGetSkillTries(lua_State* L) { // player:getSkillTries(skillType) skills_t skillType = getNumber(L, 2); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->skills[skillType].tries); } else { @@ -1087,7 +1087,7 @@ int PlayerFunctions::luaPlayerGetSkillTries(lua_State* L) { int PlayerFunctions::luaPlayerAddSkillTries(lua_State* L) { // player:addSkillTries(skillType, tries) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { skills_t skillType = getNumber(L, 2); uint64_t tries = getNumber(L, 3); @@ -1101,7 +1101,7 @@ int PlayerFunctions::luaPlayerAddSkillTries(lua_State* L) { int PlayerFunctions::luaPlayerSetLevel(lua_State* L) { // player:setLevel(level) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint16_t level = getNumber(L, 2); player->level = level; @@ -1117,7 +1117,7 @@ int PlayerFunctions::luaPlayerSetLevel(lua_State* L) { int PlayerFunctions::luaPlayerSetMagicLevel(lua_State* L) { // player:setMagicLevel(level[, manaSpent]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint16_t level = getNumber(L, 2); player->magLevel = level; @@ -1141,7 +1141,7 @@ int PlayerFunctions::luaPlayerSetMagicLevel(lua_State* L) { int PlayerFunctions::luaPlayerSetSkillLevel(lua_State* L) { // player:setSkillLevel(skillType, level[, tries]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { skills_t skillType = getNumber(L, 2); uint16_t level = getNumber(L, 3); @@ -1166,7 +1166,7 @@ int PlayerFunctions::luaPlayerSetSkillLevel(lua_State* L) { int PlayerFunctions::luaPlayerAddOfflineTrainingTime(lua_State* L) { // player:addOfflineTrainingTime(time) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { int32_t time = getNumber(L, 2); player->addOfflineTrainingTime(time); @@ -1180,7 +1180,7 @@ int PlayerFunctions::luaPlayerAddOfflineTrainingTime(lua_State* L) { int PlayerFunctions::luaPlayerGetOfflineTrainingTime(lua_State* L) { // player:getOfflineTrainingTime() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getOfflineTrainingTime()); } else { @@ -1191,7 +1191,7 @@ int PlayerFunctions::luaPlayerGetOfflineTrainingTime(lua_State* L) { int PlayerFunctions::luaPlayerRemoveOfflineTrainingTime(lua_State* L) { // player:removeOfflineTrainingTime(time) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { int32_t time = getNumber(L, 2); player->removeOfflineTrainingTime(time); @@ -1205,7 +1205,7 @@ int PlayerFunctions::luaPlayerRemoveOfflineTrainingTime(lua_State* L) { int PlayerFunctions::luaPlayerAddOfflineTrainingTries(lua_State* L) { // player:addOfflineTrainingTries(skillType, tries) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { skills_t skillType = getNumber(L, 2); uint64_t tries = getNumber(L, 3); @@ -1218,7 +1218,7 @@ int PlayerFunctions::luaPlayerAddOfflineTrainingTries(lua_State* L) { int PlayerFunctions::luaPlayerGetOfflineTrainingSkill(lua_State* L) { // player:getOfflineTrainingSkill() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getOfflineTrainingSkill()); } else { @@ -1229,7 +1229,7 @@ int PlayerFunctions::luaPlayerGetOfflineTrainingSkill(lua_State* L) { int PlayerFunctions::luaPlayerSetOfflineTrainingSkill(lua_State* L) { // player:setOfflineTrainingSkill(skillId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { int8_t skillId = getNumber(L, 2); player->setOfflineTrainingSkill(skillId); @@ -1242,7 +1242,7 @@ int PlayerFunctions::luaPlayerSetOfflineTrainingSkill(lua_State* L) { int PlayerFunctions::luaPlayerOpenStash(lua_State* L) { // player:openStash(isNpc) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); bool isNpc = getBoolean(L, 2, false); if (player) { player->sendOpenStash(isNpc); @@ -1256,7 +1256,7 @@ int PlayerFunctions::luaPlayerOpenStash(lua_State* L) { int PlayerFunctions::luaPlayerGetItemCount(lua_State* L) { // player:getItemCount(itemId[, subType = -1]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1280,7 +1280,7 @@ int PlayerFunctions::luaPlayerGetItemCount(lua_State* L) { int PlayerFunctions::luaPlayerGetStashItemCount(lua_State* L) { // player:getStashItemCount(itemId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1309,7 +1309,7 @@ int PlayerFunctions::luaPlayerGetStashItemCount(lua_State* L) { int PlayerFunctions::luaPlayerGetItemById(lua_State* L) { // player:getItemById(itemId, deepSearch[, subType = -1]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1340,7 +1340,7 @@ int PlayerFunctions::luaPlayerGetItemById(lua_State* L) { int PlayerFunctions::luaPlayerGetVocation(lua_State* L) { // player:getVocation() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { pushUserdata(L, player->getVocation()); setMetatable(L, -1, "Vocation"); @@ -1352,7 +1352,7 @@ int PlayerFunctions::luaPlayerGetVocation(lua_State* L) { int PlayerFunctions::luaPlayerSetVocation(lua_State* L) { // player:setVocation(id or name or userdata) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1381,7 +1381,7 @@ int PlayerFunctions::luaPlayerSetVocation(lua_State* L) { int PlayerFunctions::luaPlayerGetSex(lua_State* L) { // player:getSex() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSex()); } else { @@ -1392,7 +1392,7 @@ int PlayerFunctions::luaPlayerGetSex(lua_State* L) { int PlayerFunctions::luaPlayerSetSex(lua_State* L) { // player:setSex(newSex) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { PlayerSex_t newSex = getNumber(L, 2); player->setSex(newSex); @@ -1405,7 +1405,7 @@ int PlayerFunctions::luaPlayerSetSex(lua_State* L) { int PlayerFunctions::luaPlayerGetPronoun(lua_State* L) { // player:getPronoun() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getPronoun()); } else { @@ -1416,7 +1416,7 @@ int PlayerFunctions::luaPlayerGetPronoun(lua_State* L) { int PlayerFunctions::luaPlayerSetPronoun(lua_State* L) { // player:setPronoun(newPronoun) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { PlayerPronoun_t newPronoun = getNumber(L, 2); player->setPronoun(newPronoun); @@ -1429,7 +1429,7 @@ int PlayerFunctions::luaPlayerSetPronoun(lua_State* L) { int PlayerFunctions::luaPlayerGetTown(lua_State* L) { // player:getTown() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { pushUserdata(L, player->getTown()); setMetatable(L, -1, "Town"); @@ -1447,7 +1447,7 @@ int PlayerFunctions::luaPlayerSetTown(lua_State* L) { return 1; } - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->setTown(town); pushBoolean(L, true); @@ -1459,7 +1459,7 @@ int PlayerFunctions::luaPlayerSetTown(lua_State* L) { int PlayerFunctions::luaPlayerGetGuild(lua_State* L) { // player:getGuild() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1478,7 +1478,7 @@ int PlayerFunctions::luaPlayerGetGuild(lua_State* L) { int PlayerFunctions::luaPlayerSetGuild(lua_State* L) { // player:setGuild(guild) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1493,7 +1493,7 @@ int PlayerFunctions::luaPlayerSetGuild(lua_State* L) { int PlayerFunctions::luaPlayerGetGuildLevel(lua_State* L) { // player:getGuildLevel() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player && player->getGuild()) { lua_pushnumber(L, player->getGuildRank()->level); } else { @@ -1505,7 +1505,7 @@ int PlayerFunctions::luaPlayerGetGuildLevel(lua_State* L) { int PlayerFunctions::luaPlayerSetGuildLevel(lua_State* L) { // player:setGuildLevel(level) uint8_t level = getNumber(L, 2); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player || !player->getGuild()) { lua_pushnil(L); return 1; @@ -1524,7 +1524,7 @@ int PlayerFunctions::luaPlayerSetGuildLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetGuildNick(lua_State* L) { // player:getGuildNick() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { pushString(L, player->getGuildNick()); } else { @@ -1536,7 +1536,7 @@ int PlayerFunctions::luaPlayerGetGuildNick(lua_State* L) { int PlayerFunctions::luaPlayerSetGuildNick(lua_State* L) { // player:setGuildNick(nick) const std::string &nick = getString(L, 2); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->setGuildNick(nick); pushBoolean(L, true); @@ -1548,7 +1548,7 @@ int PlayerFunctions::luaPlayerSetGuildNick(lua_State* L) { int PlayerFunctions::luaPlayerGetGroup(lua_State* L) { // player:getGroup() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { pushUserdata(L, player->getGroup()); setMetatable(L, -1, "Group"); @@ -1566,7 +1566,7 @@ int PlayerFunctions::luaPlayerSetGroup(lua_State* L) { return 1; } - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->setGroup(group); pushBoolean(L, true); @@ -1581,7 +1581,7 @@ int PlayerFunctions::luaPlayerSetSpecialContainersAvailable(lua_State* L) { bool supplyStashMenu = getBoolean(L, 2, false); bool marketMenu = getBoolean(L, 3, false); bool depotSearchMenu = getBoolean(L, 4, false); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->setSpecialMenuAvailable(supplyStashMenu, marketMenu, depotSearchMenu); pushBoolean(L, true); @@ -1593,7 +1593,7 @@ int PlayerFunctions::luaPlayerSetSpecialContainersAvailable(lua_State* L) { int PlayerFunctions::luaPlayerGetStamina(lua_State* L) { // player:getStamina() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getStaminaMinutes()); } else { @@ -1605,7 +1605,7 @@ int PlayerFunctions::luaPlayerGetStamina(lua_State* L) { int PlayerFunctions::luaPlayerSetStamina(lua_State* L) { // player:setStamina(stamina) uint16_t stamina = getNumber(L, 2); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->staminaMinutes = std::min(2520, stamina); player->sendStats(); @@ -1617,7 +1617,7 @@ int PlayerFunctions::luaPlayerSetStamina(lua_State* L) { int PlayerFunctions::luaPlayerGetSoul(lua_State* L) { // player:getSoul() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSoul()); } else { @@ -1629,7 +1629,7 @@ int PlayerFunctions::luaPlayerGetSoul(lua_State* L) { int PlayerFunctions::luaPlayerAddSoul(lua_State* L) { // player:addSoul(soulChange) int32_t soulChange = getNumber(L, 2); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->changeSoul(soulChange); pushBoolean(L, true); @@ -1641,7 +1641,7 @@ int PlayerFunctions::luaPlayerAddSoul(lua_State* L) { int PlayerFunctions::luaPlayerGetMaxSoul(lua_State* L) { // player:getMaxSoul() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player && player->vocation) { lua_pushnumber(L, player->vocation->getSoulMax()); } else { @@ -1652,7 +1652,7 @@ int PlayerFunctions::luaPlayerGetMaxSoul(lua_State* L) { int PlayerFunctions::luaPlayerGetBankBalance(lua_State* L) { // player:getBankBalance() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getBankBalance()); } else { @@ -1663,7 +1663,7 @@ int PlayerFunctions::luaPlayerGetBankBalance(lua_State* L) { int PlayerFunctions::luaPlayerSetBankBalance(lua_State* L) { // player:setBankBalance(bankBalance) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1691,7 +1691,7 @@ int PlayerFunctions::luaPlayerSetStorageValue(lua_State* L) { // player:setStorageValue(key, value) int32_t value = getNumber(L, 3); uint32_t key = getNumber(L, 2); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (IS_IN_KEYRANGE(key, RESERVED_RANGE)) { std::ostringstream ss; ss << "Accessing reserved range: " << key; @@ -1711,7 +1711,7 @@ int PlayerFunctions::luaPlayerSetStorageValue(lua_State* L) { int PlayerFunctions::luaPlayerGetStorageValueByName(lua_State* L) { // player:getStorageValueByName(name) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -1725,7 +1725,7 @@ int PlayerFunctions::luaPlayerGetStorageValueByName(lua_State* L) { int PlayerFunctions::luaPlayerSetStorageValueByName(lua_State* L) { // player:setStorageValueByName(storageName, value) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -1742,7 +1742,7 @@ int PlayerFunctions::luaPlayerSetStorageValueByName(lua_State* L) { int PlayerFunctions::luaPlayerAddItem(lua_State* L) { // player:addItem(itemId, count = 1, canDropOnMap = true, subType = 1, slot = CONST_SLOT_WHEREEVER, tier = 0) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { pushBoolean(L, false); return 1; @@ -1840,7 +1840,7 @@ int PlayerFunctions::luaPlayerAddItemEx(lua_State* L) { return 1; } - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1872,7 +1872,7 @@ int PlayerFunctions::luaPlayerAddItemEx(lua_State* L) { int PlayerFunctions::luaPlayerRemoveStashItem(lua_State* L) { // player:removeStashItem(itemId, count) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1902,7 +1902,7 @@ int PlayerFunctions::luaPlayerRemoveStashItem(lua_State* L) { int PlayerFunctions::luaPlayerRemoveItem(lua_State* L) { // player:removeItem(itemId, count[, subType = -1[, ignoreEquipped = false]]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1928,7 +1928,7 @@ int PlayerFunctions::luaPlayerRemoveItem(lua_State* L) { int PlayerFunctions::luaPlayerSendContainer(lua_State* L) { // player:sendContainer(container) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1947,7 +1947,7 @@ int PlayerFunctions::luaPlayerSendContainer(lua_State* L) { int PlayerFunctions::luaPlayerSendUpdateContainer(lua_State* L) { // player:sendUpdateContainer(container) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1966,7 +1966,7 @@ int PlayerFunctions::luaPlayerSendUpdateContainer(lua_State* L) { int PlayerFunctions::luaPlayerGetMoney(lua_State* L) { // player:getMoney() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMoney()); } else { @@ -1978,7 +1978,7 @@ int PlayerFunctions::luaPlayerGetMoney(lua_State* L) { int PlayerFunctions::luaPlayerAddMoney(lua_State* L) { // player:addMoney(money) uint64_t money = getNumber(L, 2); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { g_game().addMoney(player, money); pushBoolean(L, true); @@ -1990,7 +1990,7 @@ int PlayerFunctions::luaPlayerAddMoney(lua_State* L) { int PlayerFunctions::luaPlayerRemoveMoney(lua_State* L) { // player:removeMoney(money[, flags = 0[, useBank = true]]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint64_t money = getNumber(L, 2); int32_t flags = getNumber(L, 3, 0); @@ -2004,7 +2004,7 @@ int PlayerFunctions::luaPlayerRemoveMoney(lua_State* L) { int PlayerFunctions::luaPlayerShowTextDialog(lua_State* L) { // player:showTextDialog(id or name or userdata[, text[, canWrite[, length]]]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2061,7 +2061,7 @@ int PlayerFunctions::luaPlayerSendTextMessage(lua_State* L) { // player:sendTextMessage(type, text[, position, primaryValue = 0, primaryColor = TEXTCOLOR_NONE[, secondaryValue = 0, secondaryColor = TEXTCOLOR_NONE]]) // player:sendTextMessage(type, text, channelId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2099,7 +2099,7 @@ int PlayerFunctions::luaPlayerSendTextMessage(lua_State* L) { int PlayerFunctions::luaPlayerSendChannelMessage(lua_State* L) { // player:sendChannelMessage(author, text, type, channelId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2116,13 +2116,13 @@ int PlayerFunctions::luaPlayerSendChannelMessage(lua_State* L) { int PlayerFunctions::luaPlayerSendPrivateMessage(lua_State* L) { // player:sendPrivateMessage(speaker, text[, type]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - std::shared_ptr speaker = getUserdataShared(L, 2); + const auto &speaker = getUserdataShared(L, 2); const std::string &text = getString(L, 3); SpeakClasses type = getNumber(L, 4, TALKTYPE_PRIVATE_FROM); player->sendPrivateMessage(speaker, type, text); @@ -2132,7 +2132,7 @@ int PlayerFunctions::luaPlayerSendPrivateMessage(lua_State* L) { int PlayerFunctions::luaPlayerChannelSay(lua_State* L) { // player:channelSay(speaker, type, text, channelId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2150,7 +2150,7 @@ int PlayerFunctions::luaPlayerChannelSay(lua_State* L) { int PlayerFunctions::luaPlayerOpenChannel(lua_State* L) { // player:openChannel(channelId) uint16_t channelId = getNumber(L, 2); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { g_game().playerOpenChannel(player->getID(), channelId); pushBoolean(L, true); @@ -2162,7 +2162,7 @@ int PlayerFunctions::luaPlayerOpenChannel(lua_State* L) { int PlayerFunctions::luaPlayerGetSlotItem(lua_State* L) { // player:getSlotItem(slot) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2187,7 +2187,7 @@ int PlayerFunctions::luaPlayerGetSlotItem(lua_State* L) { int PlayerFunctions::luaPlayerGetParty(lua_State* L) { // player:getParty() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2205,7 +2205,7 @@ int PlayerFunctions::luaPlayerGetParty(lua_State* L) { int PlayerFunctions::luaPlayerAddOutfit(lua_State* L) { // player:addOutfit(lookType) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->addOutfit(getNumber(L, 2), 0); pushBoolean(L, true); @@ -2217,7 +2217,7 @@ int PlayerFunctions::luaPlayerAddOutfit(lua_State* L) { int PlayerFunctions::luaPlayerAddOutfitAddon(lua_State* L) { // player:addOutfitAddon(lookType, addon) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); uint8_t addon = getNumber(L, 3); @@ -2231,7 +2231,7 @@ int PlayerFunctions::luaPlayerAddOutfitAddon(lua_State* L) { int PlayerFunctions::luaPlayerRemoveOutfit(lua_State* L) { // player:removeOutfit(lookType) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); pushBoolean(L, player->removeOutfit(lookType)); @@ -2243,7 +2243,7 @@ int PlayerFunctions::luaPlayerRemoveOutfit(lua_State* L) { int PlayerFunctions::luaPlayerRemoveOutfitAddon(lua_State* L) { // player:removeOutfitAddon(lookType, addon) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); uint8_t addon = getNumber(L, 3); @@ -2256,7 +2256,7 @@ int PlayerFunctions::luaPlayerRemoveOutfitAddon(lua_State* L) { int PlayerFunctions::luaPlayerHasOutfit(lua_State* L) { // player:hasOutfit(lookType[, addon = 0]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); uint8_t addon = getNumber(L, 3, 0); @@ -2269,7 +2269,7 @@ int PlayerFunctions::luaPlayerHasOutfit(lua_State* L) { int PlayerFunctions::luaPlayerSendOutfitWindow(lua_State* L) { // player:sendOutfitWindow() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->sendOutfitWindow(); pushBoolean(L, true); @@ -2281,7 +2281,7 @@ int PlayerFunctions::luaPlayerSendOutfitWindow(lua_State* L) { int PlayerFunctions::luaPlayerAddMount(lua_State* L) { // player:addMount(mountId or mountName) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2304,7 +2304,7 @@ int PlayerFunctions::luaPlayerAddMount(lua_State* L) { int PlayerFunctions::luaPlayerRemoveMount(lua_State* L) { // player:removeMount(mountId or mountName) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2327,7 +2327,7 @@ int PlayerFunctions::luaPlayerRemoveMount(lua_State* L) { int PlayerFunctions::luaPlayerHasMount(lua_State* L) { // player:hasMount(mountId or mountName) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2350,7 +2350,7 @@ int PlayerFunctions::luaPlayerHasMount(lua_State* L) { int PlayerFunctions::luaPlayerAddFamiliar(lua_State* L) { // player:addFamiliar(lookType) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->addFamiliar(getNumber(L, 2)); pushBoolean(L, true); @@ -2362,7 +2362,7 @@ int PlayerFunctions::luaPlayerAddFamiliar(lua_State* L) { int PlayerFunctions::luaPlayerRemoveFamiliar(lua_State* L) { // player:removeFamiliar(lookType) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); pushBoolean(L, player->removeFamiliar(lookType)); @@ -2374,7 +2374,7 @@ int PlayerFunctions::luaPlayerRemoveFamiliar(lua_State* L) { int PlayerFunctions::luaPlayerHasFamiliar(lua_State* L) { // player:hasFamiliar(lookType) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); pushBoolean(L, player->canFamiliar(lookType)); @@ -2386,7 +2386,7 @@ int PlayerFunctions::luaPlayerHasFamiliar(lua_State* L) { int PlayerFunctions::luaPlayerSetFamiliarLooktype(lua_State* L) { // player:setFamiliarLooktype(lookType) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->setFamiliarLooktype(getNumber(L, 2)); pushBoolean(L, true); @@ -2398,7 +2398,7 @@ int PlayerFunctions::luaPlayerSetFamiliarLooktype(lua_State* L) { int PlayerFunctions::luaPlayerGetFamiliarLooktype(lua_State* L) { // player:getFamiliarLooktype() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->defaultOutfit.lookFamiliarsType); } else { @@ -2409,7 +2409,7 @@ int PlayerFunctions::luaPlayerGetFamiliarLooktype(lua_State* L) { int PlayerFunctions::luaPlayerGetPremiumDays(lua_State* L) { // player:getPremiumDays() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player && player->getAccount()) { lua_pushnumber(L, player->getAccount()->getPremiumRemainingDays()); } else { @@ -2420,7 +2420,7 @@ int PlayerFunctions::luaPlayerGetPremiumDays(lua_State* L) { int PlayerFunctions::luaPlayerAddPremiumDays(lua_State* L) { // player:addPremiumDays(days) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { lua_pushnil(L); return 1; @@ -2449,7 +2449,7 @@ int PlayerFunctions::luaPlayerAddPremiumDays(lua_State* L) { int PlayerFunctions::luaPlayerRemovePremiumDays(lua_State* L) { // player:removePremiumDays(days) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { lua_pushnil(L); return 1; @@ -2478,7 +2478,7 @@ int PlayerFunctions::luaPlayerRemovePremiumDays(lua_State* L) { int PlayerFunctions::luaPlayerGetTibiaCoins(lua_State* L) { // player:getTibiaCoins() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2496,7 +2496,7 @@ int PlayerFunctions::luaPlayerGetTibiaCoins(lua_State* L) { int PlayerFunctions::luaPlayerAddTibiaCoins(lua_State* L) { // player:addTibiaCoins(coins) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2522,7 +2522,7 @@ int PlayerFunctions::luaPlayerAddTibiaCoins(lua_State* L) { int PlayerFunctions::luaPlayerRemoveTibiaCoins(lua_State* L) { // player:removeTibiaCoins(coins) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2547,7 +2547,7 @@ int PlayerFunctions::luaPlayerRemoveTibiaCoins(lua_State* L) { int PlayerFunctions::luaPlayerGetTransferableCoins(lua_State* L) { // player:getTransferableCoins() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2565,7 +2565,7 @@ int PlayerFunctions::luaPlayerGetTransferableCoins(lua_State* L) { int PlayerFunctions::luaPlayerAddTransferableCoins(lua_State* L) { // player:addTransferableCoins(coins) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2591,7 +2591,7 @@ int PlayerFunctions::luaPlayerAddTransferableCoins(lua_State* L) { int PlayerFunctions::luaPlayerRemoveTransferableCoins(lua_State* L) { // player:removeTransferableCoins(coins) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2618,7 +2618,7 @@ int PlayerFunctions::luaPlayerRemoveTransferableCoins(lua_State* L) { int PlayerFunctions::luaPlayerHasBlessing(lua_State* L) { // player:hasBlessing(blessing) uint8_t blessing = getNumber(L, 2); - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->hasBlessing(blessing)); } else { @@ -2629,7 +2629,7 @@ int PlayerFunctions::luaPlayerHasBlessing(lua_State* L) { int PlayerFunctions::luaPlayerAddBlessing(lua_State* L) { // player:addBlessing(blessing) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2646,7 +2646,7 @@ int PlayerFunctions::luaPlayerAddBlessing(lua_State* L) { int PlayerFunctions::luaPlayerRemoveBlessing(lua_State* L) { // player:removeBlessing(blessing) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2667,7 +2667,7 @@ int PlayerFunctions::luaPlayerRemoveBlessing(lua_State* L) { int PlayerFunctions::luaPlayerGetBlessingCount(lua_State* L) { // player:getBlessingCount(index) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); uint8_t index = getNumber(L, 2); if (index == 0) { index = 1; @@ -2683,7 +2683,7 @@ int PlayerFunctions::luaPlayerGetBlessingCount(lua_State* L) { int PlayerFunctions::luaPlayerCanLearnSpell(lua_State* L) { // player:canLearnSpell(spellName) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2717,7 +2717,7 @@ int PlayerFunctions::luaPlayerCanLearnSpell(lua_State* L) { int PlayerFunctions::luaPlayerLearnSpell(lua_State* L) { // player:learnSpell(spellName) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { const std::string &spellName = getString(L, 2); player->learnInstantSpell(spellName); @@ -2730,7 +2730,7 @@ int PlayerFunctions::luaPlayerLearnSpell(lua_State* L) { int PlayerFunctions::luaPlayerForgetSpell(lua_State* L) { // player:forgetSpell(spellName) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { const std::string &spellName = getString(L, 2); player->forgetInstantSpell(spellName); @@ -2743,7 +2743,7 @@ int PlayerFunctions::luaPlayerForgetSpell(lua_State* L) { int PlayerFunctions::luaPlayerHasLearnedSpell(lua_State* L) { // player:hasLearnedSpell(spellName) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { const std::string &spellName = getString(L, 2); pushBoolean(L, player->hasLearnedInstantSpell(spellName)); @@ -2755,7 +2755,7 @@ int PlayerFunctions::luaPlayerHasLearnedSpell(lua_State* L) { int PlayerFunctions::luaPlayerSendTutorial(lua_State* L) { // player:sendTutorial(tutorialId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint8_t tutorialId = getNumber(L, 2); player->sendTutorial(tutorialId); @@ -2768,7 +2768,7 @@ int PlayerFunctions::luaPlayerSendTutorial(lua_State* L) { int PlayerFunctions::luaPlayerOpenImbuementWindow(lua_State* L) { // player:openImbuementWindow(item) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -2788,7 +2788,7 @@ int PlayerFunctions::luaPlayerOpenImbuementWindow(lua_State* L) { int PlayerFunctions::luaPlayerCloseImbuementWindow(lua_State* L) { // player:closeImbuementWindow() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -2801,7 +2801,7 @@ int PlayerFunctions::luaPlayerCloseImbuementWindow(lua_State* L) { int PlayerFunctions::luaPlayerAddMapMark(lua_State* L) { // player:addMapMark(position, type, description) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { const Position &position = getPosition(L, 2); uint8_t type = getNumber(L, 3); @@ -2816,7 +2816,7 @@ int PlayerFunctions::luaPlayerAddMapMark(lua_State* L) { int PlayerFunctions::luaPlayerSave(lua_State* L) { // player:save() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { if (!player->isOffline()) { player->loginPosition = player->getPosition(); @@ -2833,7 +2833,7 @@ int PlayerFunctions::luaPlayerSave(lua_State* L) { int PlayerFunctions::luaPlayerPopupFYI(lua_State* L) { // player:popupFYI(message) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { const std::string &message = getString(L, 2); player->sendFYIBox(message); @@ -2846,7 +2846,7 @@ int PlayerFunctions::luaPlayerPopupFYI(lua_State* L) { int PlayerFunctions::luaPlayerIsPzLocked(lua_State* L) { // player:isPzLocked() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->isPzLocked()); } else { @@ -2857,7 +2857,7 @@ int PlayerFunctions::luaPlayerIsPzLocked(lua_State* L) { int PlayerFunctions::luaPlayerGetClient(lua_State* L) { // player:getClient() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_createtable(L, 0, 2); setField(L, "version", player->getProtocolVersion()); @@ -2870,7 +2870,7 @@ int PlayerFunctions::luaPlayerGetClient(lua_State* L) { int PlayerFunctions::luaPlayerGetHouse(lua_State* L) { // player:getHouse() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2888,7 +2888,7 @@ int PlayerFunctions::luaPlayerGetHouse(lua_State* L) { int PlayerFunctions::luaPlayerSendHouseWindow(lua_State* L) { // player:sendHouseWindow(house, listId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2908,7 +2908,7 @@ int PlayerFunctions::luaPlayerSendHouseWindow(lua_State* L) { int PlayerFunctions::luaPlayerSetEditHouse(lua_State* L) { // player:setEditHouse(house, listId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2928,7 +2928,7 @@ int PlayerFunctions::luaPlayerSetEditHouse(lua_State* L) { int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { // player:setGhostMode(enabled) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2948,7 +2948,7 @@ int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, position, true, true); for (auto spectator : spectators) { - auto tmpPlayer = spectator->getPlayer(); + const auto &tmpPlayer = spectator->getPlayer(); if (tmpPlayer != player && !tmpPlayer->isAccessPlayer()) { if (enabled) { tmpPlayer->sendRemoveTileThing(position, tile->getStackposOfCreature(tmpPlayer, player)); @@ -2981,7 +2981,7 @@ int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { int PlayerFunctions::luaPlayerGetContainerId(lua_State* L) { // player:getContainerId(container) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2998,7 +2998,7 @@ int PlayerFunctions::luaPlayerGetContainerId(lua_State* L) { int PlayerFunctions::luaPlayerGetContainerById(lua_State* L) { // player:getContainerById(id) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3016,7 +3016,7 @@ int PlayerFunctions::luaPlayerGetContainerById(lua_State* L) { int PlayerFunctions::luaPlayerGetContainerIndex(lua_State* L) { // player:getContainerIndex(id) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getContainerIndex(getNumber(L, 2))); } else { @@ -3027,7 +3027,7 @@ int PlayerFunctions::luaPlayerGetContainerIndex(lua_State* L) { int PlayerFunctions::luaPlayerGetInstantSpells(lua_State* L) { // player:getInstantSpells() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3052,7 +3052,7 @@ int PlayerFunctions::luaPlayerGetInstantSpells(lua_State* L) { int PlayerFunctions::luaPlayerCanCast(lua_State* L) { // player:canCast(spell) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); const auto spell = getUserdataShared(L, 2); if (player && spell) { pushBoolean(L, spell->canCast(player)); @@ -3064,7 +3064,7 @@ int PlayerFunctions::luaPlayerCanCast(lua_State* L) { int PlayerFunctions::luaPlayerHasChaseMode(lua_State* L) { // player:hasChaseMode() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->chaseMode); } else { @@ -3075,7 +3075,7 @@ int PlayerFunctions::luaPlayerHasChaseMode(lua_State* L) { int PlayerFunctions::luaPlayerHasSecureMode(lua_State* L) { // player:hasSecureMode() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->secureMode); } else { @@ -3086,7 +3086,7 @@ int PlayerFunctions::luaPlayerHasSecureMode(lua_State* L) { int PlayerFunctions::luaPlayerGetFightMode(lua_State* L) { // player:getFightMode() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->fightMode); } else { @@ -3097,7 +3097,7 @@ int PlayerFunctions::luaPlayerGetFightMode(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseXpGain(lua_State* L) { // player:getBaseXpGain() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getBaseXpGain()); } else { @@ -3108,7 +3108,7 @@ int PlayerFunctions::luaPlayerGetBaseXpGain(lua_State* L) { int PlayerFunctions::luaPlayerSetBaseXpGain(lua_State* L) { // player:setBaseXpGain(value) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->setBaseXpGain(getNumber(L, 2)); player->sendStats(); @@ -3121,7 +3121,7 @@ int PlayerFunctions::luaPlayerSetBaseXpGain(lua_State* L) { int PlayerFunctions::luaPlayerGetVoucherXpBoost(lua_State* L) { // player:getVoucherXpBoost() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getVoucherXpBoost()); } else { @@ -3132,7 +3132,7 @@ int PlayerFunctions::luaPlayerGetVoucherXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetVoucherXpBoost(lua_State* L) { // player:setVoucherXpBoost(value) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->setVoucherXpBoost(getNumber(L, 2)); player->sendStats(); @@ -3145,7 +3145,7 @@ int PlayerFunctions::luaPlayerSetVoucherXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerGetGrindingXpBoost(lua_State* L) { // player:getGrindingXpBoost() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getGrindingXpBoost()); } else { @@ -3156,7 +3156,7 @@ int PlayerFunctions::luaPlayerGetGrindingXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetGrindingXpBoost(lua_State* L) { // player:setGrindingXpBoost(value) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->setGrindingXpBoost(getNumber(L, 2)); player->sendStats(); @@ -3169,7 +3169,7 @@ int PlayerFunctions::luaPlayerSetGrindingXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerGetStoreXpBoost(lua_State* L) { // player:getStoreXpBoost() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getStoreXpBoost()); } else { @@ -3180,7 +3180,7 @@ int PlayerFunctions::luaPlayerGetStoreXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetStoreXpBoost(lua_State* L) { // player:setStoreXpBoost(value) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint16_t experience = getNumber(L, 2); player->setStoreXpBoost(experience); @@ -3193,7 +3193,7 @@ int PlayerFunctions::luaPlayerSetStoreXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerGetStaminaXpBoost(lua_State* L) { // player:getStaminaXpBoost() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getStaminaXpBoost()); } else { @@ -3204,7 +3204,7 @@ int PlayerFunctions::luaPlayerGetStaminaXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetStaminaXpBoost(lua_State* L) { // player:setStaminaXpBoost(value) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { player->setStaminaXpBoost(getNumber(L, 2)); player->sendStats(); @@ -3217,7 +3217,7 @@ int PlayerFunctions::luaPlayerSetStaminaXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetExpBoostStamina(lua_State* L) { // player:setExpBoostStamina(percent) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { uint16_t stamina = getNumber(L, 2); player->setExpBoostStamina(stamina); @@ -3231,7 +3231,7 @@ int PlayerFunctions::luaPlayerSetExpBoostStamina(lua_State* L) { int PlayerFunctions::luaPlayerGetExpBoostStamina(lua_State* L) { // player:getExpBoostStamina() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getExpBoostStamina()); } else { @@ -3242,7 +3242,7 @@ int PlayerFunctions::luaPlayerGetExpBoostStamina(lua_State* L) { int PlayerFunctions::luaPlayerGetIdleTime(lua_State* L) { // player:getIdleTime() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getIdleTime()); } else { @@ -3253,7 +3253,7 @@ int PlayerFunctions::luaPlayerGetIdleTime(lua_State* L) { int PlayerFunctions::luaPlayerGetFreeBackpackSlots(lua_State* L) { // player:getFreeBackpackSlots() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); } @@ -3263,7 +3263,7 @@ int PlayerFunctions::luaPlayerGetFreeBackpackSlots(lua_State* L) { } int PlayerFunctions::luaPlayerIsOffline(lua_State* L) { - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->isOffline()); } else { @@ -3275,7 +3275,7 @@ int PlayerFunctions::luaPlayerIsOffline(lua_State* L) { int PlayerFunctions::luaPlayerOpenMarket(lua_State* L) { // player:openMarket() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3289,7 +3289,7 @@ int PlayerFunctions::luaPlayerOpenMarket(lua_State* L) { // Forge int PlayerFunctions::luaPlayerOpenForge(lua_State* L) { // player:openForge() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3303,7 +3303,7 @@ int PlayerFunctions::luaPlayerOpenForge(lua_State* L) { int PlayerFunctions::luaPlayerCloseForge(lua_State* L) { // player:closeForge() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3317,7 +3317,7 @@ int PlayerFunctions::luaPlayerCloseForge(lua_State* L) { int PlayerFunctions::luaPlayerAddForgeDusts(lua_State* L) { // player:addForgeDusts(amount) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3331,7 +3331,7 @@ int PlayerFunctions::luaPlayerAddForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerRemoveForgeDusts(lua_State* L) { // player:removeForgeDusts(amount) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3345,7 +3345,7 @@ int PlayerFunctions::luaPlayerRemoveForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeDusts(lua_State* L) { // player:getForgeDusts() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3358,7 +3358,7 @@ int PlayerFunctions::luaPlayerGetForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerSetForgeDusts(lua_State* L) { // player:setForgeDusts() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3372,7 +3372,7 @@ int PlayerFunctions::luaPlayerSetForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerAddForgeDustLevel(lua_State* L) { // player:addForgeDustLevel(amount) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3386,7 +3386,7 @@ int PlayerFunctions::luaPlayerAddForgeDustLevel(lua_State* L) { int PlayerFunctions::luaPlayerRemoveForgeDustLevel(lua_State* L) { // player:removeForgeDustLevel(amount) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3400,7 +3400,7 @@ int PlayerFunctions::luaPlayerRemoveForgeDustLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeDustLevel(lua_State* L) { // player:getForgeDustLevel() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3413,7 +3413,7 @@ int PlayerFunctions::luaPlayerGetForgeDustLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeSlivers(lua_State* L) { // player:getForgeSlivers() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3427,7 +3427,7 @@ int PlayerFunctions::luaPlayerGetForgeSlivers(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeCores(lua_State* L) { // player:getForgeCores() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3441,7 +3441,7 @@ int PlayerFunctions::luaPlayerGetForgeCores(lua_State* L) { int PlayerFunctions::luaPlayerSetFaction(lua_State* L) { // player:setFaction(factionId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3456,7 +3456,7 @@ int PlayerFunctions::luaPlayerSetFaction(lua_State* L) { int PlayerFunctions::luaPlayerGetFaction(lua_State* L) { // player:getFaction() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (player == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3469,7 +3469,7 @@ int PlayerFunctions::luaPlayerGetFaction(lua_State* L) { int PlayerFunctions::luaPlayerIsUIExhausted(lua_State* L) { // player:isUIExhausted() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3483,7 +3483,7 @@ int PlayerFunctions::luaPlayerIsUIExhausted(lua_State* L) { int PlayerFunctions::luaPlayerUpdateUIExhausted(lua_State* L) { // player:updateUIExhausted(exhaustionTime = 250) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3498,7 +3498,7 @@ int PlayerFunctions::luaPlayerUpdateUIExhausted(lua_State* L) { // Bosstiary Cooldown Timer int PlayerFunctions::luaPlayerBosstiaryCooldownTimer(lua_State* L) { // player:sendBosstiaryCooldownTimer() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3512,7 +3512,7 @@ int PlayerFunctions::luaPlayerBosstiaryCooldownTimer(lua_State* L) { int PlayerFunctions::luaPlayerGetBosstiaryLevel(lua_State* L) { // player:getBosstiaryLevel(name) - if (std::shared_ptr player = getUserdataShared(L, 1); + if (const auto &player = getUserdataShared(L, 1); player) { const auto mtype = g_monsters().getMonsterType(getString(L, 2)); if (mtype) { @@ -3534,7 +3534,7 @@ int PlayerFunctions::luaPlayerGetBosstiaryLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetBosstiaryKills(lua_State* L) { // player:getBosstiaryKills(name) - if (std::shared_ptr player = getUserdataShared(L, 1); + if (const auto &player = getUserdataShared(L, 1); player) { const auto mtype = g_monsters().getMonsterType(getString(L, 2)); if (mtype) { @@ -3556,7 +3556,7 @@ int PlayerFunctions::luaPlayerGetBosstiaryKills(lua_State* L) { int PlayerFunctions::luaPlayerAddBosstiaryKill(lua_State* L) { // player:addBosstiaryKill(name[, amount = 1]) - if (std::shared_ptr player = getUserdataShared(L, 1); + if (const auto &player = getUserdataShared(L, 1); player) { const auto mtype = g_monsters().getMonsterType(getString(L, 2)); if (mtype) { @@ -3573,7 +3573,7 @@ int PlayerFunctions::luaPlayerAddBosstiaryKill(lua_State* L) { int PlayerFunctions::luaPlayerSetBossPoints(lua_State* L) { // player:setBossPoints() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3587,7 +3587,7 @@ int PlayerFunctions::luaPlayerSetBossPoints(lua_State* L) { int PlayerFunctions::luaPlayerSetRemoveBossTime(lua_State* L) { // player:setRemoveBossTime() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3601,7 +3601,7 @@ int PlayerFunctions::luaPlayerSetRemoveBossTime(lua_State* L) { int PlayerFunctions::luaPlayerGetSlotBossId(lua_State* L) { // player:getSlotBossId(slotId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3616,7 +3616,7 @@ int PlayerFunctions::luaPlayerGetSlotBossId(lua_State* L) { int PlayerFunctions::luaPlayerGetBossBonus(lua_State* L) { // player:getBossBonus(slotId) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3638,7 +3638,7 @@ int PlayerFunctions::luaPlayerGetBossBonus(lua_State* L) { int PlayerFunctions::luaPlayerSendSingleSoundEffect(lua_State* L) { // player:sendSingleSoundEffect(soundId[, actor = true]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3655,7 +3655,7 @@ int PlayerFunctions::luaPlayerSendSingleSoundEffect(lua_State* L) { int PlayerFunctions::luaPlayerSendDoubleSoundEffect(lua_State* L) { // player:sendDoubleSoundEffect(mainSoundId, secondarySoundId[, actor = true]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3686,7 +3686,7 @@ int PlayerFunctions::luaPlayerGetName(lua_State* L) { int PlayerFunctions::luaPlayerHasGroupFlag(lua_State* L) { // player:hasGroupFlag(flag) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3699,7 +3699,7 @@ int PlayerFunctions::luaPlayerHasGroupFlag(lua_State* L) { int PlayerFunctions::luaPlayerSetGroupFlag(lua_State* L) { // player:setGroupFlag(flag) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3712,7 +3712,7 @@ int PlayerFunctions::luaPlayerSetGroupFlag(lua_State* L) { int PlayerFunctions::luaPlayerRemoveGroupFlag(lua_State* L) { // player:removeGroupFlag(flag) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3726,7 +3726,7 @@ int PlayerFunctions::luaPlayerRemoveGroupFlag(lua_State* L) { // Hazard system int PlayerFunctions::luaPlayerAddHazardSystemPoints(lua_State* L) { // player:setHazardSystemPoints(amount) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { pushBoolean(L, false); reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); @@ -3753,7 +3753,7 @@ int PlayerFunctions::luaPlayerGetHazardSystemPoints(lua_State* L) { int PlayerFunctions::luaPlayerSetLoyaltyBonus(lua_State* L) { // player:setLoyaltyBonus(amount) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3766,7 +3766,7 @@ int PlayerFunctions::luaPlayerSetLoyaltyBonus(lua_State* L) { int PlayerFunctions::luaPlayerGetLoyaltyBonus(lua_State* L) { // player:getLoyaltyBonus() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3790,7 +3790,7 @@ int PlayerFunctions::luaPlayerGetLoyaltyPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetLoyaltyTitle(lua_State* L) { // player:getLoyaltyTitle() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3802,7 +3802,7 @@ int PlayerFunctions::luaPlayerGetLoyaltyTitle(lua_State* L) { int PlayerFunctions::luaPlayerSetLoyaltyTitle(lua_State* L) { // player:setLoyaltyTitle(name) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3816,7 +3816,7 @@ int PlayerFunctions::luaPlayerSetLoyaltyTitle(lua_State* L) { // Wheel of destiny system int PlayerFunctions::luaPlayerInstantSkillWOD(lua_State* L) { // player:instantSkillWOD(name[, value]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3834,7 +3834,7 @@ int PlayerFunctions::luaPlayerInstantSkillWOD(lua_State* L) { int PlayerFunctions::luaPlayerUpgradeSpellWOD(lua_State* L) { // player:upgradeSpellsWOD([name[, add]]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3864,7 +3864,7 @@ int PlayerFunctions::luaPlayerUpgradeSpellWOD(lua_State* L) { int PlayerFunctions::luaPlayerRevelationStageWOD(lua_State* L) { // player:revelationStagesWOD([name[, set]]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3890,7 +3890,7 @@ int PlayerFunctions::luaPlayerRevelationStageWOD(lua_State* L) { int PlayerFunctions::luaPlayerReloadData(lua_State* L) { // player:reloadData() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3907,7 +3907,7 @@ int PlayerFunctions::luaPlayerReloadData(lua_State* L) { int PlayerFunctions::luaPlayerOnThinkWheelOfDestiny(lua_State* L) { // player:onThinkWheelOfDestiny([force = false]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3920,7 +3920,7 @@ int PlayerFunctions::luaPlayerOnThinkWheelOfDestiny(lua_State* L) { int PlayerFunctions::luaPlayerAvatarTimer(lua_State* L) { // player:avatarTimer([value]) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3937,7 +3937,7 @@ int PlayerFunctions::luaPlayerAvatarTimer(lua_State* L) { int PlayerFunctions::luaPlayerGetWheelSpellAdditionalArea(lua_State* L) { // player:getWheelSpellAdditionalArea(spellname) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3964,7 +3964,7 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalArea(lua_State* L) { int PlayerFunctions::luaPlayerGetWheelSpellAdditionalTarget(lua_State* L) { // player:getWheelSpellAdditionalTarget(spellname) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3991,7 +3991,7 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalTarget(lua_State* L) { int PlayerFunctions::luaPlayerGetWheelSpellAdditionalDuration(lua_State* L) { // player:getWheelSpellAdditionalDuration(spellname) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -4018,7 +4018,7 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalDuration(lua_State* L) { int PlayerFunctions::luaPlayerUpdateConcoction(lua_State* L) { // player:updateConcoction(itemid, timeLeft) - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -4030,7 +4030,7 @@ int PlayerFunctions::luaPlayerUpdateConcoction(lua_State* L) { int PlayerFunctions::luaPlayerClearSpellCooldowns(lua_State* L) { // player:clearSpellCooldowns() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -4042,7 +4042,7 @@ int PlayerFunctions::luaPlayerClearSpellCooldowns(lua_State* L) { int PlayerFunctions::luaPlayerIsVip(lua_State* L) { // player:isVip() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -4054,7 +4054,7 @@ int PlayerFunctions::luaPlayerIsVip(lua_State* L) { int PlayerFunctions::luaPlayerGetVipDays(lua_State* L) { // player:getVipDays() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -4067,7 +4067,7 @@ int PlayerFunctions::luaPlayerGetVipDays(lua_State* L) { int PlayerFunctions::luaPlayerGetVipTime(lua_State* L) { // player:getVipTime() - std::shared_ptr player = getUserdataShared(L, 1); + const auto &player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/items/item_functions.cpp b/src/lua/functions/items/item_functions.cpp index 1fb527cd07a..1b89b055818 100644 --- a/src/lua/functions/items/item_functions.cpp +++ b/src/lua/functions/items/item_functions.cpp @@ -707,7 +707,7 @@ int ItemFunctions::luaItemMoveToSlot(lua_State* L) { return 1; } - std::shared_ptr player = getUserdataShared(L, 2); + const auto &player = getUserdataShared(L, 2); if (!player) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/map/house_functions.cpp b/src/lua/functions/map/house_functions.cpp index 18c4d66b0fa..3f6639450e6 100644 --- a/src/lua/functions/map/house_functions.cpp +++ b/src/lua/functions/map/house_functions.cpp @@ -131,8 +131,8 @@ int HouseFunctions::luaHouseSetOwnerGuid(lua_State* L) { int HouseFunctions::luaHouseStartTrade(lua_State* L) { // house:startTrade(player, tradePartner) House* house = getUserdata(L, 1); - std::shared_ptr player = getUserdataShared(L, 2); - std::shared_ptr tradePartner = getUserdataShared(L, 3); + const auto &player = getUserdataShared(L, 2); + const auto &tradePartner = getUserdataShared(L, 3); if (!player || !tradePartner || !house) { lua_pushnil(L); @@ -318,7 +318,7 @@ int HouseFunctions::luaHouseCanEditAccessList(lua_State* L) { } uint32_t listId = getNumber(L, 2); - std::shared_ptr player = getPlayer(L, 3); + const auto &player = getPlayer(L, 3); pushBoolean(L, house->canEditAccessList(listId, player)); return 1; @@ -377,7 +377,7 @@ int HouseFunctions::luaHouseIsInvited(lua_State* L) { return 1; } - std::shared_ptr player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/map/position_functions.cpp b/src/lua/functions/map/position_functions.cpp index ba0633a819e..3916a622bf1 100644 --- a/src/lua/functions/map/position_functions.cpp +++ b/src/lua/functions/map/position_functions.cpp @@ -149,7 +149,7 @@ int PositionFunctions::luaPositionSendMagicEffect(lua_State* L) { // position:sendMagicEffect(magicEffect[, player = nullptr]) SpectatorHashSet spectators; if (lua_gettop(L) >= 3) { - std::shared_ptr player = getPlayer(L, 3); + const auto &player = getPlayer(L, 3); if (player) { spectators.insert(player); } @@ -177,7 +177,7 @@ int PositionFunctions::luaPositionRemoveMagicEffect(lua_State* L) { // position:removeMagicEffect(magicEffect[, player = nullptr]) SpectatorHashSet spectators; if (lua_gettop(L) >= 3) { - std::shared_ptr player = getPlayer(L, 3); + const auto &player = getPlayer(L, 3); if (player) { spectators.insert(player); } @@ -205,7 +205,7 @@ int PositionFunctions::luaPositionSendDistanceEffect(lua_State* L) { // position:sendDistanceEffect(positionEx, distanceEffect[, player = nullptr]) SpectatorHashSet spectators; if (lua_gettop(L) >= 4) { - std::shared_ptr player = getPlayer(L, 4); + const auto &player = getPlayer(L, 4); if (player) { spectators.insert(player); } diff --git a/src/lua/modules/modules.cpp b/src/lua/modules/modules.cpp index 18d1107ff76..9804dc2f7ff 100644 --- a/src/lua/modules/modules.cpp +++ b/src/lua/modules/modules.cpp @@ -78,7 +78,7 @@ Module* Modules::getEventByRecvbyte(uint8_t recvbyte, bool force) { } void Modules::executeOnRecvbyte(uint32_t playerId, NetworkMessage &msg, uint8_t byte) const { - std::shared_ptr player = g_game().getPlayerByID(playerId); + const auto &player = g_game().getPlayerByID(playerId); if (!player) { return; } @@ -152,7 +152,7 @@ void Module::clearEvent() { loaded = false; } -void Module::executeOnRecvbyte(std::shared_ptr player, NetworkMessage &msg) { +void Module::executeOnRecvbyte(const std::shared_ptr & player, NetworkMessage &msg) { // onRecvbyte(player, msg, recvbyte) if (!scriptInterface->reserveScriptEnv()) { g_logger().error("Call stack overflow. Too many lua script calls being nested {}", player->getName()); diff --git a/src/lua/modules/modules.hpp b/src/lua/modules/modules.hpp index f72baf94fe1..2e692e400e4 100644 --- a/src/lua/modules/modules.hpp +++ b/src/lua/modules/modules.hpp @@ -35,7 +35,7 @@ class Module final : public Event { void copyEvent(Module* creatureEvent); // scripting - void executeOnRecvbyte(std::shared_ptr player, NetworkMessage &msg); + void executeOnRecvbyte(const std::shared_ptr & player, NetworkMessage &msg); // uint8_t getRecvbyte() { diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index 4b1864d43f5..6a4fc786071 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -24,7 +24,7 @@ void House::addTile(std::shared_ptr tile) { updateDoorDescription(); } -void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, std::shared_ptr player /* = nullptr*/) { +void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, const std::shared_ptr & player /* = nullptr*/) { if (updateDatabase && owner != guid) { Database &db = Database::getInstance(); @@ -136,7 +136,7 @@ void House::updateDoorDescription() const { } } -AccessHouseLevel_t House::getHouseAccessLevel(std::shared_ptr player) { +AccessHouseLevel_t House::getHouseAccessLevel(const std::shared_ptr & player) { if (!player) { return HOUSE_OWNER; } @@ -166,7 +166,7 @@ AccessHouseLevel_t House::getHouseAccessLevel(std::shared_ptr player) { return HOUSE_NOT_INVITED; } -bool House::kickPlayer(std::shared_ptr player, std::shared_ptr target) { +bool House::kickPlayer(const std::shared_ptr &player, const std::shared_ptr & target) { if (!target) { return false; } @@ -207,7 +207,7 @@ void House::setAccessList(uint32_t listId, const std::string &textlist) { for (std::shared_ptr tile : houseTiles) { if (CreatureVector* creatures = tile->getCreatures()) { for (int32_t i = creatures->size(); --i >= 0;) { - std::shared_ptr player = (*creatures)[i]->getPlayer(); + const auto &player = (*creatures)[i]->getPlayer(); if (player && !isInvited(player)) { kickPlayer(nullptr, player); } @@ -221,11 +221,11 @@ bool House::transferToDepot() const { return false; } - std::shared_ptr player = g_game().getPlayerByGUID(owner); + const auto &player = g_game().getPlayerByGUID(owner); if (player) { transferToDepot(player); } else { - std::shared_ptr tmpPlayer = std::make_shared(nullptr); + const auto &tmpPlayer = std::make_shared(nullptr); if (!IOLoginData::loadPlayerById(tmpPlayer, owner)) { return false; } @@ -236,7 +236,7 @@ bool House::transferToDepot() const { return true; } -bool House::transferToDepot(std::shared_ptr player) const { +bool House::transferToDepot(const std::shared_ptr & player) const { if (townId == 0 || owner == 0) { return false; } @@ -261,7 +261,7 @@ bool House::transferToDepot(std::shared_ptr player) const { return true; } -void House::handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, std::shared_ptr player, std::shared_ptr houseTile) const { +void House::handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, const std::shared_ptr & player, std::shared_ptr houseTile) const { if (item->isWrapContainer()) { handleContainer(moveItemList, item); } @@ -300,7 +300,7 @@ bool House::getAccessList(uint32_t listId, std::string &list) const { return door->getAccessList(list); } -bool House::isInvited(std::shared_ptr player) { +bool House::isInvited(const std::shared_ptr & player) { return getHouseAccessLevel(player) != HOUSE_NOT_INVITED; } @@ -345,7 +345,7 @@ std::shared_ptr House::getDoorByPosition(const Position &pos) { return nullptr; } -bool House::canEditAccessList(uint32_t listId, std::shared_ptr player) { +bool House::canEditAccessList(uint32_t listId, const std::shared_ptr & player) { switch (getHouseAccessLevel(player)) { case HOUSE_OWNER: return true; @@ -388,7 +388,7 @@ std::shared_ptr HouseTransferItem::createHouseTransferItem(Ho return transferItem; } -void HouseTransferItem::onTradeEvent(TradeEvents_t event, std::shared_ptr owner) { +void HouseTransferItem::onTradeEvent(TradeEvents_t event, const std::shared_ptr & owner) { if (event == ON_TRADE_TRANSFER) { if (house) { house->executeTransfer(static_self_cast(), owner); @@ -402,7 +402,7 @@ void HouseTransferItem::onTradeEvent(TradeEvents_t event, std::shared_ptr item, std::shared_ptr newOwner) { +bool House::executeTransfer(std::shared_ptr item, const std::shared_ptr & newOwner) { if (transferItem != item) { return false; } @@ -454,7 +454,7 @@ void AccessList::parseList(const std::string &list) { } void AccessList::addPlayer(const std::string &name) { - std::shared_ptr player = g_game().getPlayerByName(name); + const auto &player = g_game().getPlayerByName(name); if (player) { playerList.insert(player->getGUID()); } else { @@ -502,7 +502,7 @@ void AccessList::addGuildRank(const std::string &name, const std::string &guildN } } -bool AccessList::isInList(std::shared_ptr player) { +bool AccessList::isInList(const std::shared_ptr & player) { if (allowEveryone) { return true; } @@ -548,7 +548,7 @@ void Door::setHouse(House* newHouse) { } } -bool Door::canUse(std::shared_ptr player) { +bool Door::canUse(const std::shared_ptr & player) { if (!house) { return true; } @@ -668,7 +668,7 @@ void Houses::payHouses(RentPeriod_t rentPeriod) const { continue; } - std::shared_ptr player = std::make_shared(nullptr); + const auto &player = std::make_shared(nullptr); if (!IOLoginData::loadPlayerById(player, ownerId)) { // Player doesn't exist, reset house owner house->setOwner(0); diff --git a/src/map/house/house.hpp b/src/map/house/house.hpp index d5331001372..85a5e450669 100644 --- a/src/map/house/house.hpp +++ b/src/map/house/house.hpp @@ -25,7 +25,7 @@ class AccessList { void addGuild(const std::string &name); void addGuildRank(const std::string &name, const std::string &rankName); - bool isInList(std::shared_ptr player); + bool isInList(const std::shared_ptr & player); void getList(std::string &list) const; @@ -63,7 +63,7 @@ class Door final : public Item { return getAttribute(ItemAttribute_t::DOORID); } - bool canUse(std::shared_ptr player); + bool canUse(const std::shared_ptr & player); void setAccessList(const std::string &textlist); bool getAccessList(std::string &list) const; @@ -88,7 +88,7 @@ class HouseTransferItem final : public Item { explicit HouseTransferItem(House* newHouse) : Item(0), house(newHouse) { } - void onTradeEvent(TradeEvents_t event, std::shared_ptr owner) override; + void onTradeEvent(TradeEvents_t event, const std::shared_ptr & owner) override; bool canTransform() const override { return false; } @@ -104,17 +104,17 @@ class House { void addTile(std::shared_ptr tile); void updateDoorDescription() const; - bool canEditAccessList(uint32_t listId, std::shared_ptr player); + bool canEditAccessList(uint32_t listId, const std::shared_ptr & player); // listId special = values: // GUEST_LIST = guest list // SUBOWNER_LIST = subowner list void setAccessList(uint32_t listId, const std::string &textlist); bool getAccessList(uint32_t listId, std::string &list) const; - bool isInvited(std::shared_ptr player); + bool isInvited(const std::shared_ptr & player); - AccessHouseLevel_t getHouseAccessLevel(std::shared_ptr player); - bool kickPlayer(std::shared_ptr player, std::shared_ptr target); + AccessHouseLevel_t getHouseAccessLevel(const std::shared_ptr & player); + bool kickPlayer(const std::shared_ptr &player, const std::shared_ptr & target); void setEntryPos(Position pos) { posEntry = pos; @@ -130,7 +130,7 @@ class House { return houseName; } - void setOwner(uint32_t guid, bool updateDatabase = true, std::shared_ptr player = nullptr); + void setOwner(uint32_t guid, bool updateDatabase = true, const std::shared_ptr & player = nullptr); uint32_t getOwner() const { return owner; } @@ -180,7 +180,7 @@ class House { std::shared_ptr getTransferItem(); void resetTransferItem(); - bool executeTransfer(std::shared_ptr item, std::shared_ptr player); + bool executeTransfer(std::shared_ptr item, const std::shared_ptr & player); const HouseTileList &getTiles() const { return houseTiles; @@ -209,7 +209,7 @@ class House { private: bool transferToDepot() const; - bool transferToDepot(std::shared_ptr player) const; + bool transferToDepot(const std::shared_ptr & player) const; AccessList guestList; AccessList subOwnerList; @@ -242,7 +242,7 @@ class House { bool isLoaded = false; void handleContainer(ItemList &moveItemList, std::shared_ptr item) const; - void handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, std::shared_ptr player, std::shared_ptr houseTile) const; + void handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, const std::shared_ptr & player, std::shared_ptr houseTile) const; }; using HouseMap = std::map; diff --git a/src/map/house/housetile.cpp b/src/map/house/housetile.cpp index 615a7862c8e..7bb08996da9 100644 --- a/src/map/house/housetile.cpp +++ b/src/map/house/housetile.cpp @@ -62,7 +62,7 @@ void HouseTile::updateHouse(std::shared_ptr item) { ReturnValue HouseTile::queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t tileFlags, std::shared_ptr actor /* = nullptr*/) { if (std::shared_ptr creature = thing->getCreature()) { - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { if (!house->isInvited(player)) { return RETURNVALUE_PLAYERISNOTINVITED; } @@ -79,7 +79,7 @@ ReturnValue HouseTile::queryAdd(int32_t index, const std::shared_ptr &thi } } } else if (thing->getItem() && actor) { - std::shared_ptr actorPlayer = actor->getPlayer(); + const auto &actorPlayer = actor->getPlayer(); if (house && (!house->isInvited(actorPlayer) || house->getHouseAccessLevel(actorPlayer) == HOUSE_GUEST) && g_configManager().getBoolean(ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { return RETURNVALUE_CANNOTTHROW; } @@ -89,7 +89,7 @@ ReturnValue HouseTile::queryAdd(int32_t index, const std::shared_ptr &thi std::shared_ptr HouseTile::queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &tileFlags) { if (std::shared_ptr creature = thing->getCreature()) { - if (std::shared_ptr player = creature->getPlayer()) { + if (const auto &player = creature->getPlayer()) { if (!house->isInvited(player)) { const Position &entryPos = house->getEntryPosition(); std::shared_ptr destTile = g_game().map.getTile(entryPos); @@ -121,7 +121,7 @@ ReturnValue HouseTile::queryRemove(const std::shared_ptr &thing, uint32_t } if (actor && g_configManager().getBoolean(ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { - std::shared_ptr actorPlayer = actor->getPlayer(); + const auto &actorPlayer = actor->getPlayer(); if (house && !house->isInvited(actorPlayer)) { return RETURNVALUE_NOTPOSSIBLE; } else if (house && house->getHouseAccessLevel(actorPlayer) == HOUSE_GUEST) { diff --git a/src/map/map.cpp b/src/map/map.cpp index f31bf45f6ff..f04c177184f 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -297,7 +297,7 @@ void Map::moveCreature(const std::shared_ptr &creature, const std::sha std::vector oldStackPosVector; for (std::shared_ptr spectator : spectators) { - if (auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { if (tmpPlayer->canSeeCreature(creature)) { oldStackPosVector.push_back(oldTile->getClientIndexOfCreature(tmpPlayer, creature)); } else { @@ -338,7 +338,7 @@ void Map::moveCreature(const std::shared_ptr &creature, const std::sha // send to client size_t i = 0; for (auto spectator : spectators) { - if (auto tmpPlayer = spectator->getPlayer()) { + if (const auto &tmpPlayer = spectator->getPlayer()) { // Use the correct stackpos int32_t stackpos = oldStackPosVector[i++]; if (stackpos != -1) { diff --git a/src/map/utils/astarnodes.cpp b/src/map/utils/astarnodes.cpp index 36265dd7f12..8d3b09ff8db 100644 --- a/src/map/utils/astarnodes.cpp +++ b/src/map/utils/astarnodes.cpp @@ -120,7 +120,7 @@ int_fast32_t AStarNodes::getTileWalkCost(const std::shared_ptr &creatu /** * Make player try to avoid magic fields, when calculating pathing */ - std::shared_ptr player = creature->getPlayer(); + const auto &player = creature->getPlayer(); if (player && !field->isBlocking() && field->getDamage() != 0) { cost += MAP_NORMALWALKCOST * 18; } diff --git a/src/protobuf/appearances.pb.cc b/src/protobuf/appearances.pb.cc index ced2a617345..7777c15d523 100644 --- a/src/protobuf/appearances.pb.cc +++ b/src/protobuf/appearances.pb.cc @@ -118,7 +118,7 @@ PROTOBUF_CONSTEXPR SpriteInfo::SpriteInfo( , /*decltype(_impl_.pattern_width_)*/0u , /*decltype(_impl_.pattern_height_)*/0u , /*decltype(_impl_.pattern_depth_)*/0u - , /*decltype(_impl_.layers_)*/0u + , /*decltype(_impl_.players_)*/0u , /*decltype(_impl_.bounding_square_)*/0u , /*decltype(_impl_.is_opaque_)*/false} {} struct SpriteInfoDefaultTypeInternal { @@ -576,7 +576,7 @@ const uint32_t TableStruct_appearances_2eproto::offsets[] PROTOBUF_SECTION_VARIA PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.pattern_width_), PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.pattern_height_), PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.pattern_depth_), - PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.layers_), + PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.players_), PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.sprite_id_), PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.bounding_square_), PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.animation_), @@ -989,147 +989,147 @@ const char descriptor_table_protodef_appearances_2eproto[] PROTOBUF_SECTION_VARI "\005 \001(\r\022>\n\014sprite_phase\030\006 \003(\0132(.Canary.pro" "tobuf.appearances.SpritePhase\":\n\003Box\022\t\n\001" "x\030\001 \001(\r\022\t\n\001y\030\002 \001(\r\022\r\n\005width\030\003 \001(\r\022\016\n\006hei" - "ght\030\004 \001(\r\"\250\002\n\nSpriteInfo\022\025\n\rpattern_widt" + "ght\030\004 \001(\r\"\251\002\n\nSpriteInfo\022\025\n\rpattern_widt" "h\030\001 \001(\r\022\026\n\016pattern_height\030\002 \001(\r\022\025\n\rpatte" - "rn_depth\030\003 \001(\r\022\016\n\006layers\030\004 \001(\r\022\021\n\tsprite" - "_id\030\005 \003(\r\022\027\n\017bounding_square\030\007 \001(\r\022\?\n\tan" - "imation\030\006 \001(\0132,.Canary.protobuf.appearan" - "ces.SpriteAnimation\022\021\n\tis_opaque\030\010 \001(\010\022D" - "\n\032bounding_box_per_direction\030\t \003(\0132 .Can" - "ary.protobuf.appearances.Box\"\241\001\n\nFrameGr" - "oup\022I\n\021fixed_frame_group\030\001 \001(\0162..Canary." - "protobuf.appearances.FIXED_FRAME_GROUP\022\n" - "\n\002id\030\002 \001(\r\022<\n\013sprite_info\030\003 \001(\0132\'.Canary" - ".protobuf.appearances.SpriteInfo\"\266\001\n\nApp" - "earance\022\n\n\002id\030\001 \001(\r\022<\n\013frame_group\030\002 \003(\013" - "2\'.Canary.protobuf.appearances.FrameGrou" - "p\022;\n\005flags\030\003 \001(\0132,.Canary.protobuf.appea" - "rances.AppearanceFlags\022\014\n\004name\030\004 \001(\014\022\023\n\013" - "description\030\005 \001(\014\"\256\017\n\017AppearanceFlags\022=\n" - "\004bank\030\001 \001(\0132/.Canary.protobuf.appearance" - "s.AppearanceFlagBank\022\014\n\004clip\030\002 \001(\010\022\016\n\006bo" - "ttom\030\003 \001(\010\022\013\n\003top\030\004 \001(\010\022\021\n\tcontainer\030\005 \001" - "(\010\022\022\n\ncumulative\030\006 \001(\010\022\016\n\006usable\030\007 \001(\010\022\020" - "\n\010forceuse\030\010 \001(\010\022\020\n\010multiuse\030\t \001(\010\022\?\n\005wr" - "ite\030\n \001(\01320.Canary.protobuf.appearances." - "AppearanceFlagWrite\022H\n\nwrite_once\030\013 \001(\0132" - "4.Canary.protobuf.appearances.Appearance" - "FlagWriteOnce\022\022\n\nliquidpool\030\014 \001(\010\022\016\n\006unp" - "ass\030\r \001(\010\022\016\n\006unmove\030\016 \001(\010\022\017\n\007unsight\030\017 \001" - "(\010\022\r\n\005avoid\030\020 \001(\010\022\035\n\025no_movement_animati" - "on\030\021 \001(\010\022\014\n\004take\030\022 \001(\010\022\027\n\017liquidcontaine" - "r\030\023 \001(\010\022\014\n\004hang\030\024 \001(\010\022=\n\004hook\030\025 \001(\0132/.Ca" - "nary.protobuf.appearances.AppearanceFlag" - "Hook\022\016\n\006rotate\030\026 \001(\010\022\?\n\005light\030\027 \001(\01320.Ca" - "nary.protobuf.appearances.AppearanceFlag" - "Light\022\021\n\tdont_hide\030\030 \001(\010\022\023\n\013translucent\030" - "\031 \001(\010\022\?\n\005shift\030\032 \001(\01320.Canary.protobuf.a" - "ppearances.AppearanceFlagShift\022A\n\006height" - "\030\033 \001(\01321.Canary.protobuf.appearances.App" - "earanceFlagHeight\022\024\n\014lying_object\030\034 \001(\010\022" - "\026\n\016animate_always\030\035 \001(\010\022C\n\007automap\030\036 \001(\013" - "22.Canary.protobuf.appearances.Appearanc" - "eFlagAutomap\022E\n\010lenshelp\030\037 \001(\01323.Canary." - "protobuf.appearances.AppearanceFlagLensh" - "elp\022\020\n\010fullbank\030 \001(\010\022\023\n\013ignore_look\030! \001" - "(\010\022C\n\007clothes\030\" \001(\01322.Canary.protobuf.ap" - "pearances.AppearanceFlagClothes\022P\n\016defau" - "lt_action\030# \001(\01328.Canary.protobuf.appear" - "ances.AppearanceFlagDefaultAction\022A\n\006mar" - "ket\030$ \001(\01321.Canary.protobuf.appearances." - "AppearanceFlagMarket\022\014\n\004wrap\030% \001(\010\022\016\n\006un" - "wrap\030& \001(\010\022\021\n\ttopeffect\030\' \001(\010\022C\n\013npcsale" - "data\030( \003(\0132..Canary.protobuf.appearances" - ".AppearanceFlagNPC\022S\n\017changedtoexpire\030) " - "\001(\0132:.Canary.protobuf.appearances.Appear" - "anceFlagChangedToExpire\022\016\n\006corpse\030* \001(\010\022" - "\025\n\rplayer_corpse\030+ \001(\010\022M\n\016cyclopediaitem" - "\030, \001(\01325.Canary.protobuf.appearances.App" - "earanceFlagCyclopedia\022\014\n\004ammo\030- \001(\010\022\027\n\017s" - "how_off_socket\030. \001(\010\022\022\n\nreportable\030/ \001(\010" - "\022_\n\025upgradeclassification\0300 \001(\0132@.Canary" - ".protobuf.appearances.AppearanceFlagUpgr" - "adeClassification\022\033\n\023reverse_addons_east" - "\0301 \001(\010\022\033\n\023reverse_addons_west\0302 \001(\010\022\034\n\024r" - "everse_addons_south\0303 \001(\010\022\034\n\024reverse_add" - "ons_north\0304 \001(\010\022\017\n\007wearout\0305 \001(\010\022\023\n\013cloc" - "kexpire\0306 \001(\010\022\016\n\006expire\0307 \001(\010\022\022\n\nexpires" - "top\0308 \001(\010\022\017\n\007wrapkit\0309 \001(\010\"E\n#Appearance" - "FlagUpgradeClassification\022\036\n\026upgrade_cla" - "ssification\030\001 \001(\r\"\'\n\022AppearanceFlagBank\022" - "\021\n\twaypoints\030\001 \001(\r\".\n\023AppearanceFlagWrit" - "e\022\027\n\017max_text_length\030\001 \001(\r\"7\n\027Appearance" - "FlagWriteOnce\022\034\n\024max_text_length_once\030\001 " - "\001(\r\"8\n\023AppearanceFlagLight\022\022\n\nbrightness" - "\030\001 \001(\r\022\r\n\005color\030\002 \001(\r\")\n\024AppearanceFlagH" - "eight\022\021\n\televation\030\001 \001(\r\"+\n\023AppearanceFl" - "agShift\022\t\n\001x\030\001 \001(\r\022\t\n\001y\030\002 \001(\r\"%\n\025Appeara" - "nceFlagClothes\022\014\n\004slot\030\001 \001(\r\"Y\n\033Appearan" - "ceFlagDefaultAction\022:\n\006action\030\001 \001(\0162*.Ca" - "nary.protobuf.appearances.PLAYER_ACTION\"" - "\362\001\n\024AppearanceFlagMarket\022<\n\010category\030\001 \001" - "(\0162*.Canary.protobuf.appearances.ITEM_CA" - "TEGORY\022\032\n\022trade_as_object_id\030\002 \001(\r\022\031\n\021sh" - "ow_as_object_id\030\003 \001(\r\022N\n\026restrict_to_pro" - "fession\030\005 \003(\0162..Canary.protobuf.appearan" - "ces.PLAYER_PROFESSION\022\025\n\rminimum_level\030\006" - " \001(\r\"\245\001\n\021AppearanceFlagNPC\022\014\n\004name\030\001 \001(\014" - "\022\020\n\010location\030\002 \001(\014\022\022\n\nsale_price\030\003 \001(\r\022\021" - "\n\tbuy_price\030\004 \001(\r\022\037\n\027currency_object_typ" - "e_id\030\005 \001(\r\022(\n currency_quest_flag_displa" - "y_name\030\006 \001(\014\"&\n\025AppearanceFlagAutomap\022\r\n" - "\005color\030\001 \001(\r\"O\n\022AppearanceFlagHook\0229\n\tdi" - "rection\030\001 \001(\0162&.Canary.protobuf.appearan" - "ces.HOOK_TYPE\"$\n\026AppearanceFlagLenshelp\022" - "\n\n\002id\030\001 \001(\r\"=\n\035AppearanceFlagChangedToEx" - "pire\022\034\n\024former_object_typeid\030\001 \001(\r\"3\n\030Ap" - "pearanceFlagCyclopedia\022\027\n\017cyclopedia_typ" - "e\030\001 \001(\r\"\312\001\n\033SpecialMeaningAppearanceIds\022" - "\024\n\014gold_coin_id\030\001 \001(\r\022\030\n\020platinum_coin_i" - "d\030\002 \001(\r\022\027\n\017crystal_coin_id\030\003 \001(\r\022\025\n\rtibi" - "a_coin_id\030\004 \001(\r\022\031\n\021stamped_letter_id\030\005 \001" - "(\r\022\027\n\017supply_stash_id\030\006 \001(\r\022\027\n\017reward_ch" - "est_id\030\007 \001(\r*\224\001\n\rPLAYER_ACTION\022\026\n\022PLAYER" - "_ACTION_NONE\020\000\022\026\n\022PLAYER_ACTION_LOOK\020\001\022\025" - "\n\021PLAYER_ACTION_USE\020\002\022\026\n\022PLAYER_ACTION_O" - "PEN\020\003\022$\n PLAYER_ACTION_AUTOWALK_HIGHLIGH" - "T\020\004*\315\005\n\rITEM_CATEGORY\022\030\n\024ITEM_CATEGORY_A" - "RMORS\020\001\022\031\n\025ITEM_CATEGORY_AMULETS\020\002\022\027\n\023IT" - "EM_CATEGORY_BOOTS\020\003\022\034\n\030ITEM_CATEGORY_CON" - "TAINERS\020\004\022\034\n\030ITEM_CATEGORY_DECORATION\020\005\022" - "\026\n\022ITEM_CATEGORY_FOOD\020\006\022\036\n\032ITEM_CATEGORY" - "_HELMETS_HATS\020\007\022\026\n\022ITEM_CATEGORY_LEGS\020\010\022" - "\030\n\024ITEM_CATEGORY_OTHERS\020\t\022\031\n\025ITEM_CATEGO" - "RY_POTIONS\020\n\022\027\n\023ITEM_CATEGORY_RINGS\020\013\022\027\n" - "\023ITEM_CATEGORY_RUNES\020\014\022\031\n\025ITEM_CATEGORY_" - "SHIELDS\020\r\022\027\n\023ITEM_CATEGORY_TOOLS\020\016\022\033\n\027IT" - "EM_CATEGORY_VALUABLES\020\017\022\034\n\030ITEM_CATEGORY" - "_AMMUNITION\020\020\022\026\n\022ITEM_CATEGORY_AXES\020\021\022\027\n" - "\023ITEM_CATEGORY_CLUBS\020\022\022\"\n\036ITEM_CATEGORY_" - "DISTANCE_WEAPONS\020\023\022\030\n\024ITEM_CATEGORY_SWOR" - "DS\020\024\022\034\n\030ITEM_CATEGORY_WANDS_RODS\020\025\022!\n\035IT" - "EM_CATEGORY_PREMIUM_SCROLLS\020\026\022\035\n\031ITEM_CA" - "TEGORY_TIBIA_COINS\020\027\022#\n\037ITEM_CATEGORY_CR" - "EATURE_PRODUCTS\020\030\022\030\n\024ITEM_CATEGORY_QUIVE" - "R\020\031*\355\001\n\021PLAYER_PROFESSION\022\"\n\025PLAYER_PROF" - "ESSION_ANY\020\377\377\377\377\377\377\377\377\377\001\022\032\n\026PLAYER_PROFESSI" - "ON_NONE\020\000\022\034\n\030PLAYER_PROFESSION_KNIGHT\020\001\022" - "\035\n\031PLAYER_PROFESSION_PALADIN\020\002\022\036\n\032PLAYER" - "_PROFESSION_SORCERER\020\003\022\033\n\027PLAYER_PROFESS" - "ION_DRUID\020\004\022\036\n\032PLAYER_PROFESSION_PROMOTE" - "D\020\n*\203\001\n\023ANIMATION_LOOP_TYPE\022)\n\034ANIMATION" - "_LOOP_TYPE_PINGPONG\020\377\377\377\377\377\377\377\377\377\001\022 \n\034ANIMAT" - "ION_LOOP_TYPE_INFINITE\020\000\022\037\n\033ANIMATION_LO" - "OP_TYPE_COUNTED\020\001*4\n\tHOOK_TYPE\022\023\n\017HOOK_T" - "YPE_SOUTH\020\001\022\022\n\016HOOK_TYPE_EAST\020\002*\201\001\n\021FIXE" - "D_FRAME_GROUP\022!\n\035FIXED_FRAME_GROUP_OUTFI" - "T_IDLE\020\000\022#\n\037FIXED_FRAME_GROUP_OUTFIT_MOV" - "ING\020\001\022$\n FIXED_FRAME_GROUP_OBJECT_INITIA" - "L\020\002" + "rn_depth\030\003 \001(\r\022\017\n\007players\030\004 \001(\r\022\021\n\tsprit" + "e_id\030\005 \003(\r\022\027\n\017bounding_square\030\007 \001(\r\022\?\n\ta" + "nimation\030\006 \001(\0132,.Canary.protobuf.appeara" + "nces.SpriteAnimation\022\021\n\tis_opaque\030\010 \001(\010\022" + "D\n\032bounding_box_per_direction\030\t \003(\0132 .Ca" + "nary.protobuf.appearances.Box\"\241\001\n\nFrameG" + "roup\022I\n\021fixed_frame_group\030\001 \001(\0162..Canary" + ".protobuf.appearances.FIXED_FRAME_GROUP\022" + "\n\n\002id\030\002 \001(\r\022<\n\013sprite_info\030\003 \001(\0132\'.Canar" + "y.protobuf.appearances.SpriteInfo\"\266\001\n\nAp" + "pearance\022\n\n\002id\030\001 \001(\r\022<\n\013frame_group\030\002 \003(" + "\0132\'.Canary.protobuf.appearances.FrameGro" + "up\022;\n\005flags\030\003 \001(\0132,.Canary.protobuf.appe" + "arances.AppearanceFlags\022\014\n\004name\030\004 \001(\014\022\023\n" + "\013description\030\005 \001(\014\"\256\017\n\017AppearanceFlags\022=" + "\n\004bank\030\001 \001(\0132/.Canary.protobuf.appearanc" + "es.AppearanceFlagBank\022\014\n\004clip\030\002 \001(\010\022\016\n\006b" + "ottom\030\003 \001(\010\022\013\n\003top\030\004 \001(\010\022\021\n\tcontainer\030\005 " + "\001(\010\022\022\n\ncumulative\030\006 \001(\010\022\016\n\006usable\030\007 \001(\010\022" + "\020\n\010forceuse\030\010 \001(\010\022\020\n\010multiuse\030\t \001(\010\022\?\n\005w" + "rite\030\n \001(\01320.Canary.protobuf.appearances" + ".AppearanceFlagWrite\022H\n\nwrite_once\030\013 \001(\013" + "24.Canary.protobuf.appearances.Appearanc" + "eFlagWriteOnce\022\022\n\nliquidpool\030\014 \001(\010\022\016\n\006un" + "pass\030\r \001(\010\022\016\n\006unmove\030\016 \001(\010\022\017\n\007unsight\030\017 " + "\001(\010\022\r\n\005avoid\030\020 \001(\010\022\035\n\025no_movement_animat" + "ion\030\021 \001(\010\022\014\n\004take\030\022 \001(\010\022\027\n\017liquidcontain" + "er\030\023 \001(\010\022\014\n\004hang\030\024 \001(\010\022=\n\004hook\030\025 \001(\0132/.C" + "anary.protobuf.appearances.AppearanceFla" + "gHook\022\016\n\006rotate\030\026 \001(\010\022\?\n\005light\030\027 \001(\01320.C" + "anary.protobuf.appearances.AppearanceFla" + "gLight\022\021\n\tdont_hide\030\030 \001(\010\022\023\n\013translucent" + "\030\031 \001(\010\022\?\n\005shift\030\032 \001(\01320.Canary.protobuf." + "appearances.AppearanceFlagShift\022A\n\006heigh" + "t\030\033 \001(\01321.Canary.protobuf.appearances.Ap" + "pearanceFlagHeight\022\024\n\014lying_object\030\034 \001(\010" + "\022\026\n\016animate_always\030\035 \001(\010\022C\n\007automap\030\036 \001(" + "\01322.Canary.protobuf.appearances.Appearan" + "ceFlagAutomap\022E\n\010lenshelp\030\037 \001(\01323.Canary" + ".protobuf.appearances.AppearanceFlagLens" + "help\022\020\n\010fullbank\030 \001(\010\022\023\n\013ignore_look\030! " + "\001(\010\022C\n\007clothes\030\" \001(\01322.Canary.protobuf.a" + "ppearances.AppearanceFlagClothes\022P\n\016defa" + "ult_action\030# \001(\01328.Canary.protobuf.appea" + "rances.AppearanceFlagDefaultAction\022A\n\006ma" + "rket\030$ \001(\01321.Canary.protobuf.appearances" + ".AppearanceFlagMarket\022\014\n\004wrap\030% \001(\010\022\016\n\006u" + "nwrap\030& \001(\010\022\021\n\ttopeffect\030\' \001(\010\022C\n\013npcsal" + "edata\030( \003(\0132..Canary.protobuf.appearance" + "s.AppearanceFlagNPC\022S\n\017changedtoexpire\030)" + " \001(\0132:.Canary.protobuf.appearances.Appea" + "ranceFlagChangedToExpire\022\016\n\006corpse\030* \001(\010" + "\022\025\n\rplayer_corpse\030+ \001(\010\022M\n\016cyclopediaite" + "m\030, \001(\01325.Canary.protobuf.appearances.Ap" + "pearanceFlagCyclopedia\022\014\n\004ammo\030- \001(\010\022\027\n\017" + "show_off_socket\030. \001(\010\022\022\n\nreportable\030/ \001(" + "\010\022_\n\025upgradeclassification\0300 \001(\0132@.Canar" + "y.protobuf.appearances.AppearanceFlagUpg" + "radeClassification\022\033\n\023reverse_addons_eas" + "t\0301 \001(\010\022\033\n\023reverse_addons_west\0302 \001(\010\022\034\n\024" + "reverse_addons_south\0303 \001(\010\022\034\n\024reverse_ad" + "dons_north\0304 \001(\010\022\017\n\007wearout\0305 \001(\010\022\023\n\013clo" + "ckexpire\0306 \001(\010\022\016\n\006expire\0307 \001(\010\022\022\n\nexpire" + "stop\0308 \001(\010\022\017\n\007wrapkit\0309 \001(\010\"E\n#Appearanc" + "eFlagUpgradeClassification\022\036\n\026upgrade_cl" + "assification\030\001 \001(\r\"\'\n\022AppearanceFlagBank" + "\022\021\n\twaypoints\030\001 \001(\r\".\n\023AppearanceFlagWri" + "te\022\027\n\017max_text_length\030\001 \001(\r\"7\n\027Appearanc" + "eFlagWriteOnce\022\034\n\024max_text_length_once\030\001" + " \001(\r\"8\n\023AppearanceFlagLight\022\022\n\nbrightnes" + "s\030\001 \001(\r\022\r\n\005color\030\002 \001(\r\")\n\024AppearanceFlag" + "Height\022\021\n\televation\030\001 \001(\r\"+\n\023AppearanceF" + "lagShift\022\t\n\001x\030\001 \001(\r\022\t\n\001y\030\002 \001(\r\"%\n\025Appear" + "anceFlagClothes\022\014\n\004slot\030\001 \001(\r\"Y\n\033Appeara" + "nceFlagDefaultAction\022:\n\006action\030\001 \001(\0162*.C" + "anary.protobuf.appearances.PLAYER_ACTION" + "\"\362\001\n\024AppearanceFlagMarket\022<\n\010category\030\001 " + "\001(\0162*.Canary.protobuf.appearances.ITEM_C" + "ATEGORY\022\032\n\022trade_as_object_id\030\002 \001(\r\022\031\n\021s" + "how_as_object_id\030\003 \001(\r\022N\n\026restrict_to_pr" + "ofession\030\005 \003(\0162..Canary.protobuf.appeara" + "nces.PLAYER_PROFESSION\022\025\n\rminimum_level\030" + "\006 \001(\r\"\245\001\n\021AppearanceFlagNPC\022\014\n\004name\030\001 \001(" + "\014\022\020\n\010location\030\002 \001(\014\022\022\n\nsale_price\030\003 \001(\r\022" + "\021\n\tbuy_price\030\004 \001(\r\022\037\n\027currency_object_ty" + "pe_id\030\005 \001(\r\022(\n currency_quest_flag_displ" + "ay_name\030\006 \001(\014\"&\n\025AppearanceFlagAutomap\022\r" + "\n\005color\030\001 \001(\r\"O\n\022AppearanceFlagHook\0229\n\td" + "irection\030\001 \001(\0162&.Canary.protobuf.appeara" + "nces.HOOK_TYPE\"$\n\026AppearanceFlagLenshelp" + "\022\n\n\002id\030\001 \001(\r\"=\n\035AppearanceFlagChangedToE" + "xpire\022\034\n\024former_object_typeid\030\001 \001(\r\"3\n\030A" + "ppearanceFlagCyclopedia\022\027\n\017cyclopedia_ty" + "pe\030\001 \001(\r\"\312\001\n\033SpecialMeaningAppearanceIds" + "\022\024\n\014gold_coin_id\030\001 \001(\r\022\030\n\020platinum_coin_" + "id\030\002 \001(\r\022\027\n\017crystal_coin_id\030\003 \001(\r\022\025\n\rtib" + "ia_coin_id\030\004 \001(\r\022\031\n\021stamped_letter_id\030\005 " + "\001(\r\022\027\n\017supply_stash_id\030\006 \001(\r\022\027\n\017reward_c" + "hest_id\030\007 \001(\r*\224\001\n\rPLAYER_ACTION\022\026\n\022PLAYE" + "R_ACTION_NONE\020\000\022\026\n\022PLAYER_ACTION_LOOK\020\001\022" + "\025\n\021PLAYER_ACTION_USE\020\002\022\026\n\022PLAYER_ACTION_" + "OPEN\020\003\022$\n PLAYER_ACTION_AUTOWALK_HIGHLIG" + "HT\020\004*\315\005\n\rITEM_CATEGORY\022\030\n\024ITEM_CATEGORY_" + "ARMORS\020\001\022\031\n\025ITEM_CATEGORY_AMULETS\020\002\022\027\n\023I" + "TEM_CATEGORY_BOOTS\020\003\022\034\n\030ITEM_CATEGORY_CO" + "NTAINERS\020\004\022\034\n\030ITEM_CATEGORY_DECORATION\020\005" + "\022\026\n\022ITEM_CATEGORY_FOOD\020\006\022\036\n\032ITEM_CATEGOR" + "Y_HELMETS_HATS\020\007\022\026\n\022ITEM_CATEGORY_LEGS\020\010" + "\022\030\n\024ITEM_CATEGORY_OTHERS\020\t\022\031\n\025ITEM_CATEG" + "ORY_POTIONS\020\n\022\027\n\023ITEM_CATEGORY_RINGS\020\013\022\027" + "\n\023ITEM_CATEGORY_RUNES\020\014\022\031\n\025ITEM_CATEGORY" + "_SHIELDS\020\r\022\027\n\023ITEM_CATEGORY_TOOLS\020\016\022\033\n\027I" + "TEM_CATEGORY_VALUABLES\020\017\022\034\n\030ITEM_CATEGOR" + "Y_AMMUNITION\020\020\022\026\n\022ITEM_CATEGORY_AXES\020\021\022\027" + "\n\023ITEM_CATEGORY_CLUBS\020\022\022\"\n\036ITEM_CATEGORY" + "_DISTANCE_WEAPONS\020\023\022\030\n\024ITEM_CATEGORY_SWO" + "RDS\020\024\022\034\n\030ITEM_CATEGORY_WANDS_RODS\020\025\022!\n\035I" + "TEM_CATEGORY_PREMIUM_SCROLLS\020\026\022\035\n\031ITEM_C" + "ATEGORY_TIBIA_COINS\020\027\022#\n\037ITEM_CATEGORY_C" + "REATURE_PRODUCTS\020\030\022\030\n\024ITEM_CATEGORY_QUIV" + "ER\020\031*\355\001\n\021PLAYER_PROFESSION\022\"\n\025PLAYER_PRO" + "FESSION_ANY\020\377\377\377\377\377\377\377\377\377\001\022\032\n\026PLAYER_PROFESS" + "ION_NONE\020\000\022\034\n\030PLAYER_PROFESSION_KNIGHT\020\001" + "\022\035\n\031PLAYER_PROFESSION_PALADIN\020\002\022\036\n\032PLAYE" + "R_PROFESSION_SORCERER\020\003\022\033\n\027PLAYER_PROFES" + "SION_DRUID\020\004\022\036\n\032PLAYER_PROFESSION_PROMOT" + "ED\020\n*\203\001\n\023ANIMATION_LOOP_TYPE\022)\n\034ANIMATIO" + "N_LOOP_TYPE_PINGPONG\020\377\377\377\377\377\377\377\377\377\001\022 \n\034ANIMA" + "TION_LOOP_TYPE_INFINITE\020\000\022\037\n\033ANIMATION_L" + "OOP_TYPE_COUNTED\020\001*4\n\tHOOK_TYPE\022\023\n\017HOOK_" + "TYPE_SOUTH\020\001\022\022\n\016HOOK_TYPE_EAST\020\002*\201\001\n\021FIX" + "ED_FRAME_GROUP\022!\n\035FIXED_FRAME_GROUP_OUTF" + "IT_IDLE\020\000\022#\n\037FIXED_FRAME_GROUP_OUTFIT_MO" + "VING\020\001\022$\n FIXED_FRAME_GROUP_OBJECT_INITI" + "AL\020\002" ; static ::_pbi::once_flag descriptor_table_appearances_2eproto_once; const ::_pbi::DescriptorTable descriptor_table_appearances_2eproto = { - false, false, 6243, descriptor_table_protodef_appearances_2eproto, + false, false, 6244, descriptor_table_protodef_appearances_2eproto, "appearances.proto", &descriptor_table_appearances_2eproto_once, nullptr, 0, 26, schemas, file_default_instances, TableStruct_appearances_2eproto::offsets, @@ -2777,7 +2777,7 @@ class SpriteInfo::_Internal { static void set_has_pattern_depth(HasBits* has_bits) { (*has_bits)[0] |= 8u; } - static void set_has_layers(HasBits* has_bits) { + static void set_has_players(HasBits* has_bits) { (*has_bits)[0] |= 16u; } static void set_has_bounding_square(HasBits* has_bits) { @@ -2814,7 +2814,7 @@ SpriteInfo::SpriteInfo(const SpriteInfo& from) , decltype(_impl_.pattern_width_){} , decltype(_impl_.pattern_height_){} , decltype(_impl_.pattern_depth_){} - , decltype(_impl_.layers_){} + , decltype(_impl_.players_){} , decltype(_impl_.bounding_square_){} , decltype(_impl_.is_opaque_){}}; @@ -2841,7 +2841,7 @@ inline void SpriteInfo::SharedCtor( , decltype(_impl_.pattern_width_){0u} , decltype(_impl_.pattern_height_){0u} , decltype(_impl_.pattern_depth_){0u} - , decltype(_impl_.layers_){0u} + , decltype(_impl_.players_){0u} , decltype(_impl_.bounding_square_){0u} , decltype(_impl_.is_opaque_){false} }; @@ -2923,11 +2923,11 @@ const char* SpriteInfo::_InternalParse(const char* ptr, ::_pbi::ParseContext* ct } else goto handle_unusual; continue; - // optional uint32 layers = 4; + // optional uint32 players = 4; case 4: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 32)) { - _Internal::set_has_layers(&has_bits); - _impl_.layers_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + _Internal::set_has_players(&has_bits); + _impl_.players_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); } else goto handle_unusual; @@ -3036,10 +3036,10 @@ uint8_t* SpriteInfo::_InternalSerialize( target = ::_pbi::WireFormatLite::WriteUInt32ToArray(3, this->_internal_pattern_depth(), target); } - // optional uint32 layers = 4; + // optional uint32 players = 4; if (cached_has_bits & 0x00000010u) { target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteUInt32ToArray(4, this->_internal_layers(), target); + target = ::_pbi::WireFormatLite::WriteUInt32ToArray(4, this->_internal_players(), target); } // repeated uint32 sprite_id = 5; @@ -3131,9 +3131,9 @@ size_t SpriteInfo::ByteSizeLong() const { total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_pattern_depth()); } - // optional uint32 layers = 4; + // optional uint32 players = 4; if (cached_has_bits & 0x00000010u) { - total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_layers()); + total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_players()); } // optional uint32 bounding_square = 7; @@ -3183,7 +3183,7 @@ void SpriteInfo::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PRO _this->_impl_.pattern_depth_ = from._impl_.pattern_depth_; } if (cached_has_bits & 0x00000010u) { - _this->_impl_.layers_ = from._impl_.layers_; + _this->_impl_.players_ = from._impl_.players_; } if (cached_has_bits & 0x00000020u) { _this->_impl_.bounding_square_ = from._impl_.bounding_square_; diff --git a/src/protobuf/appearances.pb.h b/src/protobuf/appearances.pb.h index 65bc2c7e9cc..67ec22d8b24 100644 --- a/src/protobuf/appearances.pb.h +++ b/src/protobuf/appearances.pb.h @@ -1523,7 +1523,7 @@ class SpriteInfo final : kPatternWidthFieldNumber = 1, kPatternHeightFieldNumber = 2, kPatternDepthFieldNumber = 3, - kLayersFieldNumber = 4, + kPlayersFieldNumber = 4, kBoundingSquareFieldNumber = 7, kIsOpaqueFieldNumber = 8, }; @@ -1624,17 +1624,17 @@ class SpriteInfo final : void _internal_set_pattern_depth(uint32_t value); public: - // optional uint32 layers = 4; - bool has_layers() const; + // optional uint32 players = 4; + bool has_players() const; private: - bool _internal_has_layers() const; + bool _internal_has_players() const; public: - void clear_layers(); - uint32_t layers() const; - void set_layers(uint32_t value); + void clear_players(); + uint32_t players() const; + void set_players(uint32_t value); private: - uint32_t _internal_layers() const; - void _internal_set_layers(uint32_t value); + uint32_t _internal_players() const; + void _internal_set_players(uint32_t value); public: // optional uint32 bounding_square = 7; @@ -1679,7 +1679,7 @@ class SpriteInfo final : uint32_t pattern_width_; uint32_t pattern_height_; uint32_t pattern_depth_; - uint32_t layers_; + uint32_t players_; uint32_t bounding_square_; bool is_opaque_; }; @@ -6993,32 +6993,32 @@ inline void SpriteInfo::set_pattern_depth(uint32_t value) { // @@protoc_insertion_point(field_set:Canary.protobuf.appearances.SpriteInfo.pattern_depth) } -// optional uint32 layers = 4; -inline bool SpriteInfo::_internal_has_layers() const { +// optional uint32 players = 4; +inline bool SpriteInfo::_internal_has_players() const { bool value = (_impl_._has_bits_[0] & 0x00000010u) != 0; return value; } -inline bool SpriteInfo::has_layers() const { - return _internal_has_layers(); +inline bool SpriteInfo::has_players() const { + return _internal_has_players(); } -inline void SpriteInfo::clear_layers() { - _impl_.layers_ = 0u; +inline void SpriteInfo::clear_players() { + _impl_.players_ = 0u; _impl_._has_bits_[0] &= ~0x00000010u; } -inline uint32_t SpriteInfo::_internal_layers() const { - return _impl_.layers_; +inline uint32_t SpriteInfo::_internal_players() const { + return _impl_.players_; } -inline uint32_t SpriteInfo::layers() const { - // @@protoc_insertion_point(field_get:Canary.protobuf.appearances.SpriteInfo.layers) - return _internal_layers(); +inline uint32_t SpriteInfo::players() const { + // @@protoc_insertion_point(field_get:Canary.protobuf.appearances.SpriteInfo.players) + return _internal_players(); } -inline void SpriteInfo::_internal_set_layers(uint32_t value) { +inline void SpriteInfo::_internal_set_players(uint32_t value) { _impl_._has_bits_[0] |= 0x00000010u; - _impl_.layers_ = value; + _impl_.players_ = value; } -inline void SpriteInfo::set_layers(uint32_t value) { - _internal_set_layers(value); - // @@protoc_insertion_point(field_set:Canary.protobuf.appearances.SpriteInfo.layers) +inline void SpriteInfo::set_players(uint32_t value) { + _internal_set_players(value); + // @@protoc_insertion_point(field_set:Canary.protobuf.appearances.SpriteInfo.players) } // repeated uint32 sprite_id = 5; diff --git a/src/protobuf/appearances.proto b/src/protobuf/appearances.proto index ed924febfc4..b4ee4178a29 100644 --- a/src/protobuf/appearances.proto +++ b/src/protobuf/appearances.proto @@ -98,7 +98,7 @@ message SpriteInfo { optional uint32 pattern_width = 1; optional uint32 pattern_height = 2; optional uint32 pattern_depth = 3; - optional uint32 layers = 4; + optional uint32 players = 4; repeated uint32 sprite_id = 5; optional uint32 bounding_square = 7; optional SpriteAnimation animation = 6; diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 576ce8ae777..795d0fecb66 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -106,7 +106,7 @@ namespace { * @param msg The network message to which the imbuement damage should be added. * @param player Pointer to the player for whom the imbuement damage should be handled. */ - void handleImbuementDamage(NetworkMessage &msg, std::shared_ptr player) { + void handleImbuementDamage(NetworkMessage &msg, const std::shared_ptr &player) { bool imbueDmg = false; std::shared_ptr weapon = player->getWeapon(); if (weapon) { @@ -144,7 +144,7 @@ namespace { * * @param[in] player The pointer to the player whose equipped items are considered. */ - void calculateAbsorbValues(std::shared_ptr player, NetworkMessage &msg, uint8_t &combats) { + void calculateAbsorbValues(const std::shared_ptr &player, NetworkMessage &msg, uint8_t &combats) { alignas(16) uint16_t damageReduction[COMBAT_COUNT] = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }; for (int32_t slot = CONST_SLOT_FIRST; slot <= CONST_SLOT_LAST; ++slot) { @@ -472,7 +472,7 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS } // dispatcher thread - std::shared_ptr foundPlayer = g_game().getPlayerUniqueLogin(name); + const auto &foundPlayer = g_game().getPlayerUniqueLogin(name); if (!foundPlayer) { player = std::make_shared(getThis()); player->setName(name); @@ -598,7 +598,7 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS void ProtocolGame::connect(const std::string &playerName, OperatingSystem_t operatingSystem) { eventConnect = 0; - std::shared_ptr foundPlayer = g_game().getPlayerUniqueLogin(playerName); + const auto &foundPlayer = g_game().getPlayerUniqueLogin(playerName); if (!foundPlayer) { disconnectClient("You are already logged in."); return; @@ -730,7 +730,7 @@ void ProtocolGame::onRecvFirstMessage(NetworkMessage &msg) { std::string characterName = msg.getString(); - std::shared_ptr foundPlayer = g_game().getPlayerUniqueLogin(characterName); + const auto &foundPlayer = g_game().getPlayerUniqueLogin(characterName); if (foundPlayer && foundPlayer->client) { foundPlayer->client->disconnectClient("You are already connected through another client. Please use only one client at a time!"); } @@ -2395,7 +2395,7 @@ void ProtocolGame::sendTeamFinderList() { std::map teamFinder = g_game().getTeamFinderList(); msg.add(teamFinder.size()); for (auto it : teamFinder) { - std::shared_ptr leader = g_game().getPlayerByGUID(it.first); + const auto &leader = g_game().getPlayerByGUID(it.first); if (!leader) { return; } @@ -2414,7 +2414,7 @@ void ProtocolGame::sendTeamFinderList() { msg.addByte(teamAssemble->vocationIDs); msg.add(teamAssemble->teamSlots); for (auto itt : teamAssemble->membersMap) { - std::shared_ptr member = g_game().getPlayerByGUID(it.first); + const auto &member = g_game().getPlayerByGUID(it.first); if (member) { if (itt.first == player->getGUID()) { status = itt.second; @@ -2506,14 +2506,14 @@ void ProtocolGame::sendLeaderTeamFinder(bool reset) { uint16_t membersSize = 1; for (auto memberPair : teamAssemble->membersMap) { - std::shared_ptr member = g_game().getPlayerByGUID(memberPair.first); + const auto &member = g_game().getPlayerByGUID(memberPair.first); if (member) { membersSize += 1; } } msg.add(membersSize); - std::shared_ptr leader = g_game().getPlayerByGUID(teamAssemble->leaderGuid); + const auto &leader = g_game().getPlayerByGUID(teamAssemble->leaderGuid); if (!leader) { return; } @@ -2525,7 +2525,7 @@ void ProtocolGame::sendLeaderTeamFinder(bool reset) { msg.addByte(3); for (auto memberPair : teamAssemble->membersMap) { - std::shared_ptr member = g_game().getPlayerByGUID(memberPair.first); + const auto &member = g_game().getPlayerByGUID(memberPair.first); if (!member) { continue; } @@ -2598,7 +2598,7 @@ void ProtocolGame::createLeaderTeamFinder(NetworkMessage &msg) { teamAssemble->leaderGuid = player->getGUID(); if (teamAssemble->partyBool && player->getParty()) { - for (std::shared_ptr member : player->getParty()->getMembers()) { + for (const std::shared_ptr &member : player->getParty()->getMembers()) { if (member && member->getGUID() != player->getGUID()) { members.insert({ member->getGUID(), 3 }); } @@ -2655,7 +2655,7 @@ void ProtocolGame::parseLeaderFinderWindow(NetworkMessage &msg) { } case 2: { uint32_t memberID = msg.get(); - std::shared_ptr member = g_game().getPlayerByGUID(memberID); + const auto &member = g_game().getPlayerByGUID(memberID); if (!member) { return; } @@ -2719,7 +2719,7 @@ void ProtocolGame::parseMemberFinderWindow(NetworkMessage &msg) { player->sendTeamFinderList(); } else { uint32_t leaderID = msg.get(); - std::shared_ptr leader = g_game().getPlayerByGUID(leaderID); + const auto &leader = g_game().getPlayerByGUID(leaderID); if (!leader) { return; } @@ -3872,7 +3872,7 @@ void ProtocolGame::sendCyclopediaCharacterBadges() { msg.addByte(0x01); // if ShowAccountInformation show IsOnline, IsPremium, character title, badges // IsOnline - const auto loggedPlayer = g_game().getPlayerUniqueLogin(player->getName()); + const auto &loggedPlayer = g_game().getPlayerUniqueLogin(player->getName()); msg.addByte(loggedPlayer ? 0x01 : 0x00); // IsPremium (GOD has always 'Premium') msg.addByte(player->isPremium() ? 0x01 : 0x00); @@ -4599,7 +4599,7 @@ void ProtocolGame::updateCoinBalance() { g_dispatcher().addTask( std::bind( [](uint32_t playerId) { - auto threadPlayer = g_game().getPlayerByID(playerId); + const auto &threadPlayer = g_game().getPlayerByID(playerId); if (threadPlayer && threadPlayer->getAccount()) { auto [coins, errCoin] = threadPlayer->getAccount()->getCoins(account::CoinType::COIN); auto [transferCoins, errTCoin] = threadPlayer->getAccount()->getCoins(account::CoinType::TRANSFERABLE); @@ -5582,7 +5582,7 @@ void ProtocolGame::sendCreatureSay(std::shared_ptr creature, SpeakClas } // Add level only for players - if (std::shared_ptr speaker = creature->getPlayer()) { + if (const auto &speaker = creature->getPlayer()) { msg.add(speaker->getLevel()); } else { msg.add(0x00); @@ -5628,7 +5628,7 @@ void ProtocolGame::sendToChannel(std::shared_ptr creature, SpeakClasse } // Add level only for players - if (std::shared_ptr speaker = creature->getPlayer()) { + if (const auto &speaker = creature->getPlayer()) { msg.add(speaker->getLevel()); } else { msg.add(0x00); @@ -5646,7 +5646,7 @@ void ProtocolGame::sendToChannel(std::shared_ptr creature, SpeakClasse writeToOutputBuffer(msg); } -void ProtocolGame::sendPrivateMessage(std::shared_ptr speaker, SpeakClasses type, const std::string &text) { +void ProtocolGame::sendPrivateMessage(const std::shared_ptr &speaker, SpeakClasses type, const std::string &text) { NetworkMessage msg; msg.addByte(0xAA); static uint32_t statementId = 0; @@ -5896,7 +5896,7 @@ void ProtocolGame::sendPartyCreatureHealth(std::shared_ptr target, uin writeToOutputBuffer(msg); } -void ProtocolGame::sendPartyPlayerMana(std::shared_ptr target, uint8_t manaPercent) { +void ProtocolGame::sendPartyPlayerMana(const std::shared_ptr &target, uint8_t manaPercent) { uint32_t cid = target->getID(); if (knownCreatureSet.find(cid) == knownCreatureSet.end()) { sendPartyCreatureUpdate(target); @@ -5932,7 +5932,7 @@ void ProtocolGame::sendPartyCreatureShowStatus(std::shared_ptr target, writeToOutputBuffer(msg); } -void ProtocolGame::sendPartyPlayerVocation(std::shared_ptr target) { +void ProtocolGame::sendPartyPlayerVocation(const std::shared_ptr &target) { uint32_t cid = target->getID(); if (knownCreatureSet.find(cid) == knownCreatureSet.end()) { sendPartyCreatureUpdate(target); @@ -5951,7 +5951,7 @@ void ProtocolGame::sendPartyPlayerVocation(std::shared_ptr target) { writeToOutputBuffer(msg); } -void ProtocolGame::sendPlayerVocation(std::shared_ptr target) { +void ProtocolGame::sendPlayerVocation(const std::shared_ptr &target) { if (!player || oldProtocol) { return; } @@ -6100,7 +6100,7 @@ void ProtocolGame::sendAddCreature(std::shared_ptr creature, const Pos writeToOutputBuffer(msg); if (isLogin) { - if (std::shared_ptr creaturePlayer = creature->getPlayer()) { + if (const auto &creaturePlayer = creature->getPlayer()) { if (!creaturePlayer->isAccessPlayer() || creaturePlayer->getAccountType() == account::ACCOUNT_TYPE_NORMAL) { sendMagicEffect(pos, CONST_ME_TELEPORT); } @@ -6182,7 +6182,7 @@ void ProtocolGame::sendAddCreature(std::shared_ptr creature, const Pos for (const VIPEntry &entry : vipEntries) { VipStatus_t vipStatus; - std::shared_ptr vipPlayer = g_game().getPlayerByGUID(entry.guid); + const auto &vipPlayer = g_game().getPlayerByGUID(entry.guid); if (!vipPlayer) { vipStatus = VIPSTATUS_OFFLINE; } else { @@ -6195,7 +6195,7 @@ void ProtocolGame::sendAddCreature(std::shared_ptr creature, const Pos for (const VIPEntry &entry : vipEntries) { VipStatus_t vipStatus; - std::shared_ptr vipPlayer = g_game().getPlayerByGUID(entry.guid); + const auto &vipPlayer = g_game().getPlayerByGUID(entry.guid); if (!vipPlayer || vipPlayer->isInGhostMode()) { vipStatus = VIPSTATUS_OFFLINE; } else { @@ -6989,7 +6989,7 @@ void ProtocolGame::sendModalWindow(const ModalWindow &modalWindow) { ////////////// Add common messages void ProtocolGame::AddCreature(NetworkMessage &msg, std::shared_ptr creature, bool known, uint32_t remove) { CreatureType_t creatureType = creature->getType(); - std::shared_ptr otherPlayer = creature->getPlayer(); + const auto &otherPlayer = creature->getPlayer(); if (known) { msg.add(0x62); @@ -7058,7 +7058,7 @@ void ProtocolGame::AddCreature(NetworkMessage &msg, std::shared_ptr cr if (!oldProtocol && creatureType == CREATURETYPE_MONSTER) { if (std::shared_ptr master = creature->getMaster()) { - if (std::shared_ptr masterPlayer = master->getPlayer()) { + if (const auto &masterPlayer = master->getPlayer()) { creatureType = CREATURETYPE_SUMMON_PLAYER; } } @@ -7079,7 +7079,7 @@ void ProtocolGame::AddCreature(NetworkMessage &msg, std::shared_ptr cr } if (!oldProtocol && creatureType == CREATURETYPE_PLAYER) { - if (std::shared_ptr otherCreature = creature->getPlayer()) { + if (const auto &otherCreature = creature->getPlayer()) { msg.addByte(otherCreature->getVocation()->getClientId()); } else { msg.addByte(0); @@ -7371,7 +7371,7 @@ void ProtocolGame::updatePartyTrackerAnalyzer(const Party* party) { msg.addByte(static_cast(party->membersData.size())); for (const PartyAnalyzer* analyzer : party->membersData) { msg.add(analyzer->id); - if (std::shared_ptr member = g_game().getPlayerByID(analyzer->id); + if (const auto &member = g_game().getPlayerByID(analyzer->id); !member || !member->getParty() || member->getParty() != party) { msg.addByte(0); } else { @@ -7512,14 +7512,14 @@ void ProtocolGame::sendTaskHuntingData(const TaskHuntingSlot* slot) { } else if (slot->state == PreyTaskDataState_Inactive) { // Empty } else if (slot->state == PreyTaskDataState_Selection) { - std::shared_ptr user = player; + const auto &user = player; msg.add(static_cast(slot->raceIdList.size())); std::for_each(slot->raceIdList.begin(), slot->raceIdList.end(), [&msg, user](uint16_t raceid) { msg.add(raceid); msg.addByte(user->isCreatureUnlockedOnTaskHunting(g_monsters().getMonsterTypeByRaceId(raceid)) ? 0x01 : 0x00); }); } else if (slot->state == PreyTaskDataState_ListSelection) { - std::shared_ptr user = player; + const auto &user = player; const std::map bestiaryList = g_game().getBestiaryList(); msg.add(static_cast(bestiaryList.size())); std::for_each(bestiaryList.begin(), bestiaryList.end(), [&msg, user](auto mType) { diff --git a/src/server/network/protocol/protocolgame.hpp b/src/server/network/protocol/protocolgame.hpp index a167ab9559e..1d1a3eef644 100644 --- a/src/server/network/protocol/protocolgame.hpp +++ b/src/server/network/protocol/protocolgame.hpp @@ -233,7 +233,7 @@ class ProtocolGame final : public Protocol { void sendOpenPrivateChannel(const std::string &receiver); void sendExperienceTracker(int64_t rawExp, int64_t finalExp); void sendToChannel(std::shared_ptr creature, SpeakClasses type, const std::string &text, uint16_t channelId); - void sendPrivateMessage(std::shared_ptr speaker, SpeakClasses type, const std::string &text); + void sendPrivateMessage(const std::shared_ptr & speaker, SpeakClasses type, const std::string &text); void sendIcons(uint32_t icons); void sendFYIBox(const std::string &message); @@ -281,10 +281,10 @@ class ProtocolGame final : public Protocol { void sendPartyCreatureShield(std::shared_ptr target); void sendPartyCreatureSkull(std::shared_ptr target); void sendPartyCreatureHealth(std::shared_ptr target, uint8_t healthPercent); - void sendPartyPlayerMana(std::shared_ptr target, uint8_t manaPercent); + void sendPartyPlayerMana(const std::shared_ptr & target, uint8_t manaPercent); void sendPartyCreatureShowStatus(std::shared_ptr target, bool showStatus); - void sendPartyPlayerVocation(std::shared_ptr target); - void sendPlayerVocation(std::shared_ptr target); + void sendPartyPlayerVocation(const std::shared_ptr & target); + void sendPlayerVocation(const std::shared_ptr & target); void sendSkills(); void sendPing(); void sendPingBack(); From b882ae7c55945aff268aaa4210f3ac9fc758c16a Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sun, 17 Sep 2023 22:19:15 +0000 Subject: [PATCH 24/67] Code format - (Clang-format) --- src/creatures/combat/condition.hpp | 8 +-- src/creatures/players/grouping/party.hpp | 38 ++++++------- src/creatures/players/management/waitlist.hpp | 6 +-- src/io/functions/iologindata_load_player.cpp | 54 +++++++++---------- src/io/functions/iologindata_load_player.hpp | 54 +++++++++---------- src/io/functions/iologindata_save_player.cpp | 30 +++++------ src/io/functions/iologindata_save_player.hpp | 30 +++++------ src/io/iobestiary.cpp | 22 ++++---- src/io/iobestiary.hpp | 22 ++++---- src/io/iologindata.cpp | 10 ++-- src/io/iologindata.hpp | 10 ++-- src/io/ioprey.cpp | 6 +-- src/io/ioprey.hpp | 6 +-- src/items/bed.hpp | 14 ++--- src/items/tile.hpp | 6 +-- src/lua/callbacks/event_callback.hpp | 52 +++++++++--------- src/lua/creature/actions.cpp | 18 +++---- src/lua/creature/actions.hpp | 18 +++---- src/lua/creature/creatureevent.hpp | 18 +++---- src/lua/creature/events.cpp | 50 ++++++++--------- src/lua/creature/events.hpp | 50 ++++++++--------- src/lua/creature/movement.cpp | 4 +- src/lua/creature/movement.hpp | 4 +- src/lua/creature/talkaction.cpp | 6 +-- src/lua/creature/talkaction.hpp | 6 +-- .../creatures/player/guild_functions.cpp | 2 +- .../creatures/player/party_functions.cpp | 4 +- src/lua/modules/modules.cpp | 2 +- src/lua/modules/modules.hpp | 2 +- src/map/house/house.cpp | 22 ++++---- src/map/house/house.hpp | 22 ++++---- src/server/network/protocol/protocolgame.hpp | 8 +-- 32 files changed, 302 insertions(+), 302 deletions(-) diff --git a/src/creatures/combat/condition.hpp b/src/creatures/combat/condition.hpp index a99e0721f66..82450648c17 100644 --- a/src/creatures/combat/condition.hpp +++ b/src/creatures/combat/condition.hpp @@ -150,10 +150,10 @@ class ConditionAttributes final : public ConditionGeneric { bool disableDefense = false; - void updatePercentStats(const std::shared_ptr & player); - void updateStats(const std::shared_ptr & player); - void updatePercentSkills(const std::shared_ptr & player); - void updateSkills(const std::shared_ptr & player); + void updatePercentStats(const std::shared_ptr &player); + void updateStats(const std::shared_ptr &player); + void updatePercentSkills(const std::shared_ptr &player); + void updateSkills(const std::shared_ptr &player); void updateBuffs(std::shared_ptr creature); // 12.72 mechanics diff --git a/src/creatures/players/grouping/party.hpp b/src/creatures/players/grouping/party.hpp index 3d8ecfe343f..6cc90d49044 100644 --- a/src/creatures/players/grouping/party.hpp +++ b/src/creatures/players/grouping/party.hpp @@ -26,7 +26,7 @@ class Party; class Party { public: - explicit Party(const std::shared_ptr & leader); + explicit Party(const std::shared_ptr &leader); std::shared_ptr getLeader() const { return m_leader.lock(); @@ -48,8 +48,8 @@ class Party { bool invitePlayer(const std::shared_ptr &player); bool joinParty(const std::shared_ptr &player); void revokeInvitation(const std::shared_ptr &player); - bool passPartyLeadership(const std::shared_ptr & player); - bool leaveParty(const std::shared_ptr & player); + bool passPartyLeadership(const std::shared_ptr &player); + bool leaveParty(const std::shared_ptr &player); bool removeInvite(const std::shared_ptr &player, bool removeFromPlayer = true); @@ -62,32 +62,32 @@ class Party { bool canOpenCorpse(uint32_t ownerId) const; void shareExperience(uint64_t experience, std::shared_ptr target = nullptr); - bool setSharedExperience(const std::shared_ptr & player, bool sharedExpActive, bool silent = false); + bool setSharedExperience(const std::shared_ptr &player, bool sharedExpActive, bool silent = false); bool isSharedExperienceActive() const { return sharedExpActive; } bool isSharedExperienceEnabled() const { return sharedExpEnabled; } - bool canUseSharedExperience(const std::shared_ptr & player); - SharedExpStatus_t getMemberSharedExperienceStatus(const std::shared_ptr & player); + bool canUseSharedExperience(const std::shared_ptr &player); + SharedExpStatus_t getMemberSharedExperienceStatus(const std::shared_ptr &player); void updateSharedExperience(); - void updatePlayerTicks(const std::shared_ptr & player, uint32_t points); - void clearPlayerPoints(const std::shared_ptr & player); + void updatePlayerTicks(const std::shared_ptr &player, uint32_t points); + void clearPlayerPoints(const std::shared_ptr &player); - void showPlayerStatus(const std::shared_ptr & player, const std::shared_ptr & member, bool showStatus); - void updatePlayerStatus(const std::shared_ptr & player); - void updatePlayerStatus(const std::shared_ptr & player, const Position &oldPos, const Position &newPos); - void updatePlayerHealth(const std::shared_ptr & player, std::shared_ptr target, uint8_t healthPercent); - void updatePlayerMana(const std::shared_ptr & player, uint8_t manaPercent); - void updatePlayerVocation(const std::shared_ptr & player); + void showPlayerStatus(const std::shared_ptr &player, const std::shared_ptr &member, bool showStatus); + void updatePlayerStatus(const std::shared_ptr &player); + void updatePlayerStatus(const std::shared_ptr &player, const Position &oldPos, const Position &newPos); + void updatePlayerHealth(const std::shared_ptr &player, std::shared_ptr target, uint8_t healthPercent); + void updatePlayerMana(const std::shared_ptr &player, uint8_t manaPercent); + void updatePlayerVocation(const std::shared_ptr &player); void updateTrackerAnalyzer(); - void addPlayerLoot(const std::shared_ptr & player, std::shared_ptr item); - void addPlayerSupply(const std::shared_ptr & player, std::shared_ptr item); - void addPlayerDamage(const std::shared_ptr & player, uint64_t amount); - void addPlayerHealing(const std::shared_ptr & player, uint64_t amount); + void addPlayerLoot(const std::shared_ptr &player, std::shared_ptr item); + void addPlayerSupply(const std::shared_ptr &player, std::shared_ptr item); + void addPlayerDamage(const std::shared_ptr &player, uint64_t amount); + void addPlayerHealing(const std::shared_ptr &player, uint64_t amount); void switchAnalyzerPriceType(); void resetAnalyzer(); void reloadPrices(); @@ -115,7 +115,7 @@ class Party { private: const char* getSharedExpReturnMessage(SharedExpStatus_t value); - bool isPlayerActive(const std::shared_ptr & player); + bool isPlayerActive(const std::shared_ptr &player); SharedExpStatus_t getSharedExperienceStatus(); uint32_t getHighestLevel(); uint32_t getLowestLevel(); diff --git a/src/creatures/players/management/waitlist.hpp b/src/creatures/players/management/waitlist.hpp index 5a659100d43..11e1e3d64a7 100644 --- a/src/creatures/players/management/waitlist.hpp +++ b/src/creatures/players/management/waitlist.hpp @@ -34,13 +34,13 @@ class WaitingList { public: WaitingList(); static WaitingList &getInstance(); - bool clientLogin(const std::shared_ptr & player); - std::size_t getClientSlot(const std::shared_ptr & player); + bool clientLogin(const std::shared_ptr &player); + std::size_t getClientSlot(const std::shared_ptr &player); static std::size_t getTime(std::size_t slot); private: void cleanupList(WaitList &list); std::size_t getTimeout(std::size_t slot); - void addPlayerToList(const std::shared_ptr & player); + void addPlayerToList(const std::shared_ptr &player); std::unique_ptr info; }; diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index f5e601e38c6..5278435d5cd 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -49,7 +49,7 @@ void IOLoginDataLoad::loadItems(ItemsMap &itemsMap, DBResult_ptr result, const s } } -bool IOLoginDataLoad::preLoadPlayer(const std::shared_ptr & player, const std::string &name) { +bool IOLoginDataLoad::preLoadPlayer(const std::shared_ptr &player, const std::string &name) { Database &db = Database::getInstance(); std::ostringstream query; @@ -103,7 +103,7 @@ bool IOLoginDataLoad::preLoadPlayer(const std::shared_ptr & player, cons return true; } -bool IOLoginDataLoad::loadPlayerFirst(const std::shared_ptr & player, DBResult_ptr result) { +bool IOLoginDataLoad::loadPlayerFirst(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return false; @@ -183,7 +183,7 @@ bool IOLoginDataLoad::loadPlayerFirst(const std::shared_ptr & player, DB return true; } -void IOLoginDataLoad::loadPlayerExperience(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerExperience(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -206,7 +206,7 @@ void IOLoginDataLoad::loadPlayerExperience(const std::shared_ptr & playe } } -void IOLoginDataLoad::loadPlayerBlessings(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerBlessings(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -219,7 +219,7 @@ void IOLoginDataLoad::loadPlayerBlessings(const std::shared_ptr & player } } -void IOLoginDataLoad::loadPlayerConditions(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerConditions(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -239,7 +239,7 @@ void IOLoginDataLoad::loadPlayerConditions(const std::shared_ptr & playe } } -void IOLoginDataLoad::loadPlayerDefaultOutfit(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerDefaultOutfit(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -270,7 +270,7 @@ void IOLoginDataLoad::loadPlayerDefaultOutfit(const std::shared_ptr & pl player->currentOutfit = player->defaultOutfit; } -void IOLoginDataLoad::loadPlayerSkullSystem(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerSkullSystem(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -292,7 +292,7 @@ void IOLoginDataLoad::loadPlayerSkullSystem(const std::shared_ptr & play } } -void IOLoginDataLoad::loadPlayerSkill(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerSkill(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -314,7 +314,7 @@ void IOLoginDataLoad::loadPlayerSkill(const std::shared_ptr & player, DB } } -void IOLoginDataLoad::loadPlayerKills(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerKills(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -333,7 +333,7 @@ void IOLoginDataLoad::loadPlayerKills(const std::shared_ptr & player, DB } } -void IOLoginDataLoad::loadPlayerGuild(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerGuild(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -383,7 +383,7 @@ void IOLoginDataLoad::loadPlayerGuild(const std::shared_ptr & player, DB } } -void IOLoginDataLoad::loadPlayerStashItems(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerStashItems(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -399,7 +399,7 @@ void IOLoginDataLoad::loadPlayerStashItems(const std::shared_ptr & playe } } -void IOLoginDataLoad::loadPlayerBestiaryCharms(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerBestiaryCharms(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -452,7 +452,7 @@ void IOLoginDataLoad::loadPlayerBestiaryCharms(const std::shared_ptr & p } } -void IOLoginDataLoad::loadPlayerInstantSpellList(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerInstantSpellList(const std::shared_ptr &player, DBResult_ptr result) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -468,7 +468,7 @@ void IOLoginDataLoad::loadPlayerInstantSpellList(const std::shared_ptr & } } -void IOLoginDataLoad::loadPlayerInventoryItems(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerInventoryItems(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -546,7 +546,7 @@ void IOLoginDataLoad::loadPlayerInventoryItems(const std::shared_ptr & p } } -void IOLoginDataLoad::loadPlayerStoreInbox(const std::shared_ptr & player) { +void IOLoginDataLoad::loadPlayerStoreInbox(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -557,7 +557,7 @@ void IOLoginDataLoad::loadPlayerStoreInbox(const std::shared_ptr & playe } } -void IOLoginDataLoad::loadRewardItems(const std::shared_ptr & player) { +void IOLoginDataLoad::loadRewardItems(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -575,7 +575,7 @@ void IOLoginDataLoad::loadRewardItems(const std::shared_ptr & player) { } } -void IOLoginDataLoad::loadPlayerDepotItems(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerDepotItems(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -615,7 +615,7 @@ void IOLoginDataLoad::loadPlayerDepotItems(const std::shared_ptr & playe } } -void IOLoginDataLoad::loadPlayerInboxItems(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerInboxItems(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -652,7 +652,7 @@ void IOLoginDataLoad::loadPlayerInboxItems(const std::shared_ptr & playe } } -void IOLoginDataLoad::loadPlayerStorageMap(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerStorageMap(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -668,7 +668,7 @@ void IOLoginDataLoad::loadPlayerStorageMap(const std::shared_ptr & playe } } -void IOLoginDataLoad::loadPlayerVip(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerVip(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -684,7 +684,7 @@ void IOLoginDataLoad::loadPlayerVip(const std::shared_ptr & player, DBRe } } -void IOLoginDataLoad::loadPlayerPreyClass(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerPreyClass(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -731,7 +731,7 @@ void IOLoginDataLoad::loadPlayerPreyClass(const std::shared_ptr & player } } -void IOLoginDataLoad::loadPlayerTaskHuntingClass(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerTaskHuntingClass(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -781,7 +781,7 @@ void IOLoginDataLoad::loadPlayerTaskHuntingClass(const std::shared_ptr & } } -void IOLoginDataLoad::loadPlayerForgeHistory(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerForgeHistory(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -802,7 +802,7 @@ void IOLoginDataLoad::loadPlayerForgeHistory(const std::shared_ptr & pla } } -void IOLoginDataLoad::loadPlayerBosstiary(const std::shared_ptr & player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerBosstiary(const std::shared_ptr &player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -834,7 +834,7 @@ void IOLoginDataLoad::loadPlayerBosstiary(const std::shared_ptr & player } } -void IOLoginDataLoad::bindRewardBag(const std::shared_ptr & player, ItemsMap &rewardItemsMap) { +void IOLoginDataLoad::bindRewardBag(const std::shared_ptr &player, ItemsMap &rewardItemsMap) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -874,7 +874,7 @@ void IOLoginDataLoad::insertItemsIntoRewardBag(const ItemsMap &rewardItemsMap) { } } -void IOLoginDataLoad::loadPlayerInitializeSystem(const std::shared_ptr & player) { +void IOLoginDataLoad::loadPlayerInitializeSystem(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -888,7 +888,7 @@ void IOLoginDataLoad::loadPlayerInitializeSystem(const std::shared_ptr & player->initializeTaskHunting(); } -void IOLoginDataLoad::loadPlayerUpdateSystem(const std::shared_ptr & player) { +void IOLoginDataLoad::loadPlayerUpdateSystem(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; diff --git a/src/io/functions/iologindata_load_player.hpp b/src/io/functions/iologindata_load_player.hpp index f36203961ba..3fd45f2465d 100644 --- a/src/io/functions/iologindata_load_player.hpp +++ b/src/io/functions/iologindata_load_player.hpp @@ -13,37 +13,37 @@ class IOLoginDataLoad : public IOLoginData { public: - static bool loadPlayerFirst(const std::shared_ptr & player, DBResult_ptr result); - static bool preLoadPlayer(const std::shared_ptr & player, const std::string &name); - static void loadPlayerExperience(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerBlessings(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerConditions(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerDefaultOutfit(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerSkullSystem(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerSkill(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerKills(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerGuild(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerStashItems(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerBestiaryCharms(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerInstantSpellList(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerInventoryItems(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerStoreInbox(const std::shared_ptr & player); - static void loadPlayerDepotItems(const std::shared_ptr & player, DBResult_ptr result); - static void loadRewardItems(const std::shared_ptr & player); - static void loadPlayerInboxItems(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerStorageMap(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerVip(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerPreyClass(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerTaskHuntingClass(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerForgeHistory(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerBosstiary(const std::shared_ptr & player, DBResult_ptr result); - static void loadPlayerInitializeSystem(const std::shared_ptr & player); - static void loadPlayerUpdateSystem(const std::shared_ptr & player); + static bool loadPlayerFirst(const std::shared_ptr &player, DBResult_ptr result); + static bool preLoadPlayer(const std::shared_ptr &player, const std::string &name); + static void loadPlayerExperience(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerBlessings(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerConditions(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerDefaultOutfit(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerSkullSystem(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerSkill(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerKills(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerGuild(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerStashItems(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerBestiaryCharms(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerInstantSpellList(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerInventoryItems(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerStoreInbox(const std::shared_ptr &player); + static void loadPlayerDepotItems(const std::shared_ptr &player, DBResult_ptr result); + static void loadRewardItems(const std::shared_ptr &player); + static void loadPlayerInboxItems(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerStorageMap(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerVip(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerPreyClass(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerTaskHuntingClass(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerForgeHistory(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerBosstiary(const std::shared_ptr &player, DBResult_ptr result); + static void loadPlayerInitializeSystem(const std::shared_ptr &player); + static void loadPlayerUpdateSystem(const std::shared_ptr &player); private: using ItemsMap = std::map, uint32_t>>; - static void bindRewardBag(const std::shared_ptr & player, ItemsMap &rewardItemsMap); + static void bindRewardBag(const std::shared_ptr &player, ItemsMap &rewardItemsMap); static void insertItemsIntoRewardBag(const ItemsMap &rewardItemsMap); static void loadItems(ItemsMap &itemsMap, DBResult_ptr result, const std::shared_ptr &player); diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index 7a7b00484fc..6cea5af4dae 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -12,7 +12,7 @@ #include "io/functions/iologindata_save_player.hpp" #include "game/game.hpp" -bool IOLoginDataSave::saveItems(const std::shared_ptr & player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &propWriteStream) { +bool IOLoginDataSave::saveItems(const std::shared_ptr &player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &propWriteStream) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -148,7 +148,7 @@ bool IOLoginDataSave::saveItems(const std::shared_ptr & player, const It return true; } -bool IOLoginDataSave::savePlayerFirst(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerFirst(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -313,7 +313,7 @@ bool IOLoginDataSave::savePlayerFirst(const std::shared_ptr & player) { return true; } -bool IOLoginDataSave::savePlayerStash(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerStash(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -339,7 +339,7 @@ bool IOLoginDataSave::savePlayerStash(const std::shared_ptr & player) { return true; } -bool IOLoginDataSave::savePlayerSpells(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerSpells(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -368,7 +368,7 @@ bool IOLoginDataSave::savePlayerSpells(const std::shared_ptr & player) { return true; } -bool IOLoginDataSave::savePlayerKills(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerKills(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -397,7 +397,7 @@ bool IOLoginDataSave::savePlayerKills(const std::shared_ptr & player) { return true; } -bool IOLoginDataSave::savePlayerBestiarySystem(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerBestiarySystem(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -447,7 +447,7 @@ bool IOLoginDataSave::savePlayerBestiarySystem(const std::shared_ptr & p return true; } -bool IOLoginDataSave::savePlayerItem(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerItem(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -479,7 +479,7 @@ bool IOLoginDataSave::savePlayerItem(const std::shared_ptr & player) { return true; } -bool IOLoginDataSave::savePlayerDepotItems(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerDepotItems(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -514,7 +514,7 @@ bool IOLoginDataSave::savePlayerDepotItems(const std::shared_ptr & playe return true; } -bool IOLoginDataSave::saveRewardItems(const std::shared_ptr & player) { +bool IOLoginDataSave::saveRewardItems(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -548,7 +548,7 @@ bool IOLoginDataSave::saveRewardItems(const std::shared_ptr & player) { return true; } -bool IOLoginDataSave::savePlayerInbox(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerInbox(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -576,7 +576,7 @@ bool IOLoginDataSave::savePlayerInbox(const std::shared_ptr & player) { return true; } -bool IOLoginDataSave::savePlayerPreyClass(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerPreyClass(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -631,7 +631,7 @@ bool IOLoginDataSave::savePlayerPreyClass(const std::shared_ptr & player return true; } -bool IOLoginDataSave::savePlayerTaskHuntingClass(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerTaskHuntingClass(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -684,7 +684,7 @@ bool IOLoginDataSave::savePlayerTaskHuntingClass(const std::shared_ptr & return true; } -bool IOLoginDataSave::savePlayerForgeHistory(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerForgeHistory(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -718,7 +718,7 @@ bool IOLoginDataSave::savePlayerForgeHistory(const std::shared_ptr & pla return true; } -bool IOLoginDataSave::savePlayerBosstiary(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerBosstiary(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -762,7 +762,7 @@ bool IOLoginDataSave::savePlayerBosstiary(const std::shared_ptr & player return true; } -bool IOLoginDataSave::savePlayerStorage(const std::shared_ptr & player) { +bool IOLoginDataSave::savePlayerStorage(const std::shared_ptr &player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; diff --git a/src/io/functions/iologindata_save_player.hpp b/src/io/functions/iologindata_save_player.hpp index c9cb66efa28..5d6c9cac612 100644 --- a/src/io/functions/iologindata_save_player.hpp +++ b/src/io/functions/iologindata_save_player.hpp @@ -13,20 +13,20 @@ class IOLoginDataSave : public IOLoginData { public: - static bool savePlayerFirst(const std::shared_ptr & player); - static bool savePlayerStash(const std::shared_ptr & player); - static bool savePlayerSpells(const std::shared_ptr & player); - static bool savePlayerKills(const std::shared_ptr & player); - static bool savePlayerBestiarySystem(const std::shared_ptr & player); - static bool savePlayerItem(const std::shared_ptr & player); - static bool savePlayerDepotItems(const std::shared_ptr & player); - static bool saveRewardItems(const std::shared_ptr & player); - static bool savePlayerInbox(const std::shared_ptr & player); - static bool savePlayerPreyClass(const std::shared_ptr & player); - static bool savePlayerTaskHuntingClass(const std::shared_ptr & player); - static bool savePlayerForgeHistory(const std::shared_ptr & player); - static bool savePlayerBosstiary(const std::shared_ptr & player); - static bool savePlayerStorage(const std::shared_ptr & palyer); + static bool savePlayerFirst(const std::shared_ptr &player); + static bool savePlayerStash(const std::shared_ptr &player); + static bool savePlayerSpells(const std::shared_ptr &player); + static bool savePlayerKills(const std::shared_ptr &player); + static bool savePlayerBestiarySystem(const std::shared_ptr &player); + static bool savePlayerItem(const std::shared_ptr &player); + static bool savePlayerDepotItems(const std::shared_ptr &player); + static bool saveRewardItems(const std::shared_ptr &player); + static bool savePlayerInbox(const std::shared_ptr &player); + static bool savePlayerPreyClass(const std::shared_ptr &player); + static bool savePlayerTaskHuntingClass(const std::shared_ptr &player); + static bool savePlayerForgeHistory(const std::shared_ptr &player); + static bool savePlayerBosstiary(const std::shared_ptr &player); + static bool savePlayerStorage(const std::shared_ptr &palyer); protected: using ItemBlockList = std::list>>; @@ -34,5 +34,5 @@ class IOLoginDataSave : public IOLoginData { using ItemRewardList = std::list>>; using ItemInboxList = std::list>>; - static bool saveItems(const std::shared_ptr & player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &stream); + static bool saveItems(const std::shared_ptr &player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &stream); }; diff --git a/src/io/iobestiary.cpp b/src/io/iobestiary.cpp index 6fe8d61053c..77727188a27 100644 --- a/src/io/iobestiary.cpp +++ b/src/io/iobestiary.cpp @@ -17,7 +17,7 @@ SoftSingleton IOBestiary::instanceTracker("IOBestiary"); -bool IOBestiary::parseCharmCombat(const std::shared_ptr charm, const std::shared_ptr & player, std::shared_ptr target, int32_t realDamage, bool dueToPotion, bool checkArmor) { +bool IOBestiary::parseCharmCombat(const std::shared_ptr charm, const std::shared_ptr &player, std::shared_ptr target, int32_t realDamage, bool dueToPotion, bool checkArmor) { if (!charm || !player || !target) { return false; } @@ -146,7 +146,7 @@ uint8_t IOBestiary::getKillStatus(const std::shared_ptr mtype, uint return 4; } -void IOBestiary::resetCharmRuneCreature(const std::shared_ptr & player, const std::shared_ptr charm) { +void IOBestiary::resetCharmRuneCreature(const std::shared_ptr &player, const std::shared_ptr charm) { if (!player || !charm) { return; } @@ -156,7 +156,7 @@ void IOBestiary::resetCharmRuneCreature(const std::shared_ptr & player, player->parseRacebyCharm(charm->id, true, 0); } -void IOBestiary::setCharmRuneCreature(const std::shared_ptr & player, const std::shared_ptr charm, uint16_t raceid) { +void IOBestiary::setCharmRuneCreature(const std::shared_ptr &player, const std::shared_ptr charm, uint16_t raceid) { if (!player || !charm) { return; } @@ -166,7 +166,7 @@ void IOBestiary::setCharmRuneCreature(const std::shared_ptr & player, co player->setUsedRunesBit(Toggle); } -std::list IOBestiary::getCharmUsedRuneBitAll(const std::shared_ptr & player) { +std::list IOBestiary::getCharmUsedRuneBitAll(const std::shared_ptr &player) { int32_t input = player->getUsedRunesBit(); ; int8_t i = 0; @@ -182,7 +182,7 @@ std::list IOBestiary::getCharmUsedRuneBitAll(const std::shared_ptr< return rtn; } -uint16_t IOBestiary::getBestiaryRaceUnlocked(const std::shared_ptr & player, BestiaryType_t race) const { +uint16_t IOBestiary::getBestiaryRaceUnlocked(const std::shared_ptr &player, BestiaryType_t race) const { if (!player) { return 0; } @@ -199,7 +199,7 @@ uint16_t IOBestiary::getBestiaryRaceUnlocked(const std::shared_ptr & pla return count; } -void IOBestiary::addCharmPoints(const std::shared_ptr & player, uint16_t amount, bool negative /*= false*/) { +void IOBestiary::addCharmPoints(const std::shared_ptr &player, uint16_t amount, bool negative /*= false*/) { if (!player) { return; } @@ -213,7 +213,7 @@ void IOBestiary::addCharmPoints(const std::shared_ptr & player, uint16_t player->setCharmPoints(myCharms); } -void IOBestiary::addBestiaryKill(const std::shared_ptr & player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) { +void IOBestiary::addBestiaryKill(const std::shared_ptr &player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) { uint16_t raceid = mtype->info.raceid; if (raceid == 0 || !player || !mtype) { return; @@ -241,7 +241,7 @@ void IOBestiary::addBestiaryKill(const std::shared_ptr & player, const s player->refreshCyclopediaMonsterTracker(); } -charmRune_t IOBestiary::getCharmFromTarget(const std::shared_ptr & player, const std::shared_ptr mtype) { +charmRune_t IOBestiary::getCharmFromTarget(const std::shared_ptr &player, const std::shared_ptr mtype) { if (!player || !mtype) { return CHARM_NONE; } @@ -283,7 +283,7 @@ int32_t IOBestiary::bitToggle(int32_t input, const std::shared_ptr charm, } } -void IOBestiary::sendBuyCharmRune(const std::shared_ptr & player, charmRune_t runeID, uint8_t action, uint16_t raceid) { +void IOBestiary::sendBuyCharmRune(const std::shared_ptr &player, charmRune_t runeID, uint8_t action, uint16_t raceid) { const auto charm = getBestiaryCharm(runeID); if (!player || !charm) { return; @@ -384,7 +384,7 @@ std::map IOBestiary::getMonsterElements(const std::shared_ptr< return defaultMap; } -std::map IOBestiary::getBestiaryKillCountByMonsterIDs(const std::shared_ptr & player, std::map mtype_list) const { +std::map IOBestiary::getBestiaryKillCountByMonsterIDs(const std::shared_ptr &player, std::map mtype_list) const { std::map raceMonsters = {}; for (const auto &it : mtype_list) { uint16_t raceid = it.first; @@ -396,7 +396,7 @@ std::map IOBestiary::getBestiaryKillCountByMonsterIDs(const return raceMonsters; } -phmap::parallel_flat_hash_set IOBestiary::getBestiaryFinished(const std::shared_ptr & player) const { +phmap::parallel_flat_hash_set IOBestiary::getBestiaryFinished(const std::shared_ptr &player) const { phmap::parallel_flat_hash_set finishedMonsters; auto bestiaryMap = g_game().getBestiaryList(); diff --git a/src/io/iobestiary.hpp b/src/io/iobestiary.hpp index 5e17223b2af..eaaacd6cb69 100644 --- a/src/io/iobestiary.hpp +++ b/src/io/iobestiary.hpp @@ -55,28 +55,28 @@ class IOBestiary { } std::shared_ptr getBestiaryCharm(charmRune_t activeCharm, bool force = false) const; - void addBestiaryKill(const std::shared_ptr & player, const std::shared_ptr mtype, uint32_t amount = 1); - bool parseCharmCombat(const std::shared_ptr charm, const std::shared_ptr & player, std::shared_ptr target, int32_t realDamage, bool dueToPotion = false, bool checkArmor = false); - void addCharmPoints(const std::shared_ptr & player, uint16_t amount, bool negative = false); - void sendBuyCharmRune(const std::shared_ptr & player, charmRune_t runeID, uint8_t action, uint16_t raceid); - void setCharmRuneCreature(const std::shared_ptr & player, const std::shared_ptr charm, uint16_t raceid); - void resetCharmRuneCreature(const std::shared_ptr & player, const std::shared_ptr charm); + void addBestiaryKill(const std::shared_ptr &player, const std::shared_ptr mtype, uint32_t amount = 1); + bool parseCharmCombat(const std::shared_ptr charm, const std::shared_ptr &player, std::shared_ptr target, int32_t realDamage, bool dueToPotion = false, bool checkArmor = false); + void addCharmPoints(const std::shared_ptr &player, uint16_t amount, bool negative = false); + void sendBuyCharmRune(const std::shared_ptr &player, charmRune_t runeID, uint8_t action, uint16_t raceid); + void setCharmRuneCreature(const std::shared_ptr &player, const std::shared_ptr charm, uint16_t raceid); + void resetCharmRuneCreature(const std::shared_ptr &player, const std::shared_ptr charm); int8_t calculateDifficult(uint32_t chance) const; uint8_t getKillStatus(const std::shared_ptr mtype, uint32_t killAmount) const; - uint16_t getBestiaryRaceUnlocked(const std::shared_ptr & player, BestiaryType_t race) const; + uint16_t getBestiaryRaceUnlocked(const std::shared_ptr &player, BestiaryType_t race) const; int32_t bitToggle(int32_t input, const std::shared_ptr charm, bool on) const; bool hasCharmUnlockedRuneBit(const std::shared_ptr charm, int32_t input) const; - std::list getCharmUsedRuneBitAll(const std::shared_ptr & player); - phmap::parallel_flat_hash_set getBestiaryFinished(const std::shared_ptr & player) const; + std::list getCharmUsedRuneBitAll(const std::shared_ptr &player); + phmap::parallel_flat_hash_set getBestiaryFinished(const std::shared_ptr &player) const; - charmRune_t getCharmFromTarget(const std::shared_ptr & player, const std::shared_ptr mtype); + charmRune_t getCharmFromTarget(const std::shared_ptr &player, const std::shared_ptr mtype); - std::map getBestiaryKillCountByMonsterIDs(const std::shared_ptr & player, std::map mtype_list) const; + std::map getBestiaryKillCountByMonsterIDs(const std::shared_ptr &player, std::map mtype_list) const; std::map getMonsterElements(const std::shared_ptr mtype) const; std::map findRaceByName(const std::string &race, bool Onlystring = true, BestiaryType_t raceNumber = BESTY_RACE_NONE) const; diff --git a/src/io/iologindata.cpp b/src/io/iologindata.cpp index a901fbc9940..dab83adc60e 100644 --- a/src/io/iologindata.cpp +++ b/src/io/iologindata.cpp @@ -85,21 +85,21 @@ void IOLoginData::updateOnlineStatus(uint32_t guid, bool login) { } // The boolean "disable" will desactivate the loading of information that is not relevant to the preload, for example, forge, bosstiary, etc. None of this we need to access if the player is offline -bool IOLoginData::loadPlayerById(const std::shared_ptr & player, uint32_t id, bool disable /* = true*/) { +bool IOLoginData::loadPlayerById(const std::shared_ptr &player, uint32_t id, bool disable /* = true*/) { Database &db = Database::getInstance(); std::ostringstream query; query << "SELECT * FROM `players` WHERE `id` = " << id; return loadPlayer(player, db.storeQuery(query.str()), disable); } -bool IOLoginData::loadPlayerByName(const std::shared_ptr & player, const std::string &name, bool disable /* = true*/) { +bool IOLoginData::loadPlayerByName(const std::shared_ptr &player, const std::string &name, bool disable /* = true*/) { Database &db = Database::getInstance(); std::ostringstream query; query << "SELECT * FROM `players` WHERE `name` = " << db.escapeString(name); return loadPlayer(player, db.storeQuery(query.str()), disable); } -bool IOLoginData::loadPlayer(const std::shared_ptr & player, DBResult_ptr result, bool disable /* = false*/) { +bool IOLoginData::loadPlayer(const std::shared_ptr &player, DBResult_ptr result, bool disable /* = false*/) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Resultnullptr: {}", __FUNCTION__); return false; @@ -185,7 +185,7 @@ bool IOLoginData::loadPlayer(const std::shared_ptr & player, DBResult_pt } } -bool IOLoginData::savePlayer(const std::shared_ptr & player) { +bool IOLoginData::savePlayer(const std::shared_ptr &player) { bool success = DBTransaction::executeWithinTransaction([player]() { return savePlayerGuard(player); }); @@ -197,7 +197,7 @@ bool IOLoginData::savePlayer(const std::shared_ptr & player) { return success; } -bool IOLoginData::savePlayerGuard(const std::shared_ptr & player) { +bool IOLoginData::savePlayerGuard(const std::shared_ptr &player) { if (!player) { throw DatabaseException("Player nullptr in function: " + std::string(__FUNCTION__)); } diff --git a/src/io/iologindata.hpp b/src/io/iologindata.hpp index 3fb1cefb0ed..8cf44133c1c 100644 --- a/src/io/iologindata.hpp +++ b/src/io/iologindata.hpp @@ -20,10 +20,10 @@ class IOLoginData { static bool gameWorldAuthentication(const std::string &accountDescriptor, const std::string &sessionOrPassword, std::string &characterName, uint32_t &accountId, bool oldProcotol); static account::AccountType getAccountType(uint32_t accountId); static void updateOnlineStatus(uint32_t guid, bool login); - static bool loadPlayerById(const std::shared_ptr & player, uint32_t id, bool disable = true); - static bool loadPlayerByName(const std::shared_ptr & player, const std::string &name, bool disable = true); - static bool loadPlayer(const std::shared_ptr & player, DBResult_ptr result, bool disable = true); - static bool savePlayer(const std::shared_ptr & player); + static bool loadPlayerById(const std::shared_ptr &player, uint32_t id, bool disable = true); + static bool loadPlayerByName(const std::shared_ptr &player, const std::string &name, bool disable = true); + static bool loadPlayer(const std::shared_ptr &player, DBResult_ptr result, bool disable = true); + static bool savePlayer(const std::shared_ptr &player); static uint32_t getGuidByName(const std::string &name); static bool getGuidByNameEx(uint32_t &guid, bool &specialVip, std::string &name); static std::string getNameByGuid(uint32_t guid); @@ -37,5 +37,5 @@ class IOLoginData { static void removeVIPEntry(uint32_t accountId, uint32_t guid); private: - static bool savePlayerGuard(const std::shared_ptr & player); + static bool savePlayerGuard(const std::shared_ptr &player); }; diff --git a/src/io/ioprey.cpp b/src/io/ioprey.cpp index c7c68cce15d..6876311e9f7 100644 --- a/src/io/ioprey.cpp +++ b/src/io/ioprey.cpp @@ -246,7 +246,7 @@ void TaskHuntingSlot::reloadReward() { } // Prey/Task hunting global class -void IOPrey::CheckPlayerPreys(const std::shared_ptr & player, uint8_t amount) const { +void IOPrey::CheckPlayerPreys(const std::shared_ptr &player, uint8_t amount) const { if (!player) { return; } @@ -289,7 +289,7 @@ void IOPrey::CheckPlayerPreys(const std::shared_ptr & player, uint8_t am } } -void IOPrey::ParsePreyAction(const std::shared_ptr & player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const { +void IOPrey::ParsePreyAction(const std::shared_ptr &player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const { PreySlot* slot = player->getPreySlotById(slotId); if (!slot || slot->state == PreyDataState_Locked) { player->sendMessageDialog("To unlock this prey slot first you must buy it on store."); @@ -389,7 +389,7 @@ void IOPrey::ParsePreyAction(const std::shared_ptr & player, PreySlot_t player->reloadPreySlot(slotId); } -void IOPrey::ParseTaskHuntingAction(const std::shared_ptr & player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const { +void IOPrey::ParseTaskHuntingAction(const std::shared_ptr &player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const { TaskHuntingSlot* slot = player->getTaskHuntingSlotById(slotId); if (!slot || slot->state == PreyTaskDataState_Locked) { player->sendMessageDialog("To unlock this task hunting slot first you must buy it on store."); diff --git a/src/io/ioprey.hpp b/src/io/ioprey.hpp index 042291fe89a..16e734bbb0a 100644 --- a/src/io/ioprey.hpp +++ b/src/io/ioprey.hpp @@ -217,10 +217,10 @@ class IOPrey { return inject(); } - void CheckPlayerPreys(const std::shared_ptr & player, uint8_t amount) const; - void ParsePreyAction(const std::shared_ptr & player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const; + void CheckPlayerPreys(const std::shared_ptr &player, uint8_t amount) const; + void ParsePreyAction(const std::shared_ptr &player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const; - void ParseTaskHuntingAction(const std::shared_ptr & player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const; + void ParseTaskHuntingAction(const std::shared_ptr &player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const; void InitializeTaskHuntOptions(); TaskHuntingOption* GetTaskRewardOption(const TaskHuntingSlot* slot) const; diff --git a/src/items/bed.hpp b/src/items/bed.hpp index 0849fd48749..ebd91e29817 100644 --- a/src/items/bed.hpp +++ b/src/items/bed.hpp @@ -37,20 +37,20 @@ class BedItem final : public Item { house = h; } - bool canUse(const std::shared_ptr & player); + bool canUse(const std::shared_ptr &player); - bool trySleep(const std::shared_ptr & player); - bool sleep(const std::shared_ptr & player); - void wakeUp(const std::shared_ptr & player); + bool trySleep(const std::shared_ptr &player); + bool sleep(const std::shared_ptr &player); + void wakeUp(const std::shared_ptr &player); std::shared_ptr getNextBedItem(); friend class MapCache; private: - void updateAppearance(const std::shared_ptr & player); - void regeneratePlayer(const std::shared_ptr & player) const; - void internalSetSleeper(const std::shared_ptr & player); + void updateAppearance(const std::shared_ptr &player); + void regeneratePlayer(const std::shared_ptr &player) const; + void internalSetSleeper(const std::shared_ptr &player); void internalRemoveSleeper(); House* house = nullptr; diff --git a/src/items/tile.hpp b/src/items/tile.hpp index d414337c38a..a94f6c08fad 100644 --- a/src/items/tile.hpp +++ b/src/items/tile.hpp @@ -196,9 +196,9 @@ class Tile : public Cylinder, public SharedObject { std::string getDescription(int32_t lookDistance) override final; - int32_t getClientIndexOfCreature(const std::shared_ptr & player, std::shared_ptr creature) const; - int32_t getStackposOfCreature(const std::shared_ptr & player, std::shared_ptr creature) const; - int32_t getStackposOfItem(const std::shared_ptr & player, std::shared_ptr item) const; + int32_t getClientIndexOfCreature(const std::shared_ptr &player, std::shared_ptr creature) const; + int32_t getStackposOfCreature(const std::shared_ptr &player, std::shared_ptr creature) const; + int32_t getStackposOfItem(const std::shared_ptr &player, std::shared_ptr item) const; // cylinder implementations ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; diff --git a/src/lua/callbacks/event_callback.hpp b/src/lua/callbacks/event_callback.hpp index b13c0dcfce6..976d171f61a 100644 --- a/src/lua/callbacks/event_callback.hpp +++ b/src/lua/callbacks/event_callback.hpp @@ -86,36 +86,36 @@ class EventCallback : public Script { void creatureOnDrainHealth(std::shared_ptr creature, std::shared_ptr attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) const; // Party - bool partyOnJoin(Party* party, const std::shared_ptr & player) const; - bool partyOnLeave(Party* party, const std::shared_ptr & player) const; + bool partyOnJoin(Party* party, const std::shared_ptr &player) const; + bool partyOnLeave(Party* party, const std::shared_ptr &player) const; bool partyOnDisband(Party* party) const; void partyOnShareExperience(Party* party, uint64_t &exp) const; // Player - bool playerOnBrowseField(const std::shared_ptr & player, const Position &position) const; - void playerOnLook(const std::shared_ptr & player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) const; - void playerOnLookInBattleList(const std::shared_ptr & player, std::shared_ptr creature, int32_t lookDistance) const; - void playerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr & partner, std::shared_ptr item, int32_t lookDistance) const; - bool playerOnLookInShop(const std::shared_ptr & player, const ItemType* itemType, uint8_t count) const; - bool playerOnMoveItem(const std::shared_ptr & player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; - void playerOnItemMoved(const std::shared_ptr & player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; - void playerOnChangeZone(const std::shared_ptr & player, ZoneType_t zone) const; - bool playerOnMoveCreature(const std::shared_ptr & player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) const; - void playerOnReportRuleViolation(const std::shared_ptr & player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const; - void playerOnReportBug(const std::shared_ptr & player, const std::string &message, const Position &position, uint8_t category) const; - bool playerOnTurn(const std::shared_ptr & player, Direction direction) const; - bool playerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr & target, std::shared_ptr item) const; - bool playerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr & target, std::shared_ptr item, std::shared_ptr targetItem) const; - void playerOnGainExperience(const std::shared_ptr & player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) const; - void playerOnLoseExperience(const std::shared_ptr & player, uint64_t &exp) const; - void playerOnGainSkillTries(const std::shared_ptr & player, skills_t skill, uint64_t &tries) const; - void playerOnRemoveCount(const std::shared_ptr & player, std::shared_ptr item) const; - void playerOnRequestQuestLog(const std::shared_ptr & player) const; - void playerOnRequestQuestLine(const std::shared_ptr & player, uint16_t questId) const; - void playerOnStorageUpdate(const std::shared_ptr & player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const; - void playerOnCombat(const std::shared_ptr & player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) const; - void playerOnInventoryUpdate(const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool equip) const; - bool playerOnRotateItem(const std::shared_ptr & player, std::shared_ptr item, const Position &position) const; + bool playerOnBrowseField(const std::shared_ptr &player, const Position &position) const; + void playerOnLook(const std::shared_ptr &player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) const; + void playerOnLookInBattleList(const std::shared_ptr &player, std::shared_ptr creature, int32_t lookDistance) const; + void playerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr &partner, std::shared_ptr item, int32_t lookDistance) const; + bool playerOnLookInShop(const std::shared_ptr &player, const ItemType* itemType, uint8_t count) const; + bool playerOnMoveItem(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; + void playerOnItemMoved(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; + void playerOnChangeZone(const std::shared_ptr &player, ZoneType_t zone) const; + bool playerOnMoveCreature(const std::shared_ptr &player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) const; + void playerOnReportRuleViolation(const std::shared_ptr &player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const; + void playerOnReportBug(const std::shared_ptr &player, const std::string &message, const Position &position, uint8_t category) const; + bool playerOnTurn(const std::shared_ptr &player, Direction direction) const; + bool playerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item) const; + bool playerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item, std::shared_ptr targetItem) const; + void playerOnGainExperience(const std::shared_ptr &player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) const; + void playerOnLoseExperience(const std::shared_ptr &player, uint64_t &exp) const; + void playerOnGainSkillTries(const std::shared_ptr &player, skills_t skill, uint64_t &tries) const; + void playerOnRemoveCount(const std::shared_ptr &player, std::shared_ptr item) const; + void playerOnRequestQuestLog(const std::shared_ptr &player) const; + void playerOnRequestQuestLine(const std::shared_ptr &player, uint16_t questId) const; + void playerOnStorageUpdate(const std::shared_ptr &player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const; + void playerOnCombat(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) const; + void playerOnInventoryUpdate(const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool equip) const; + bool playerOnRotateItem(const std::shared_ptr &player, std::shared_ptr item, const Position &position) const; // Monster void monsterOnDropLoot(std::shared_ptr monster, std::shared_ptr corpse) const; diff --git a/src/lua/creature/actions.cpp b/src/lua/creature/actions.cpp index 4c2e3948bdb..69a924d585e 100644 --- a/src/lua/creature/actions.cpp +++ b/src/lua/creature/actions.cpp @@ -166,7 +166,7 @@ bool Actions::registerLuaEvent(const std::shared_ptr action) { return false; } -ReturnValue Actions::canUse(const std::shared_ptr & player, const Position &pos) { +ReturnValue Actions::canUse(const std::shared_ptr &player, const Position &pos) { if (pos.x != 0xFFFF) { const Position &playerPos = player->getPosition(); if (playerPos.z != pos.z) { @@ -180,7 +180,7 @@ ReturnValue Actions::canUse(const std::shared_ptr & player, const Positi return RETURNVALUE_NOERROR; } -ReturnValue Actions::canUse(const std::shared_ptr & player, const Position &pos, std::shared_ptr item) { +ReturnValue Actions::canUse(const std::shared_ptr &player, const Position &pos, std::shared_ptr item) { const std::shared_ptr action = getAction(item); if (action != nullptr) { return action->canExecuteAction(player, pos); @@ -247,7 +247,7 @@ std::shared_ptr Actions::getAction(std::shared_ptr item) { return g_spells().getRuneSpell(item->getID()); } -ReturnValue Actions::internalUseItem(const std::shared_ptr & player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { +ReturnValue Actions::internalUseItem(const std::shared_ptr &player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { if (std::shared_ptr door = item->getDoor()) { if (!door->canUse(player)) { return RETURNVALUE_CANNOTUSETHISOBJECT; @@ -383,7 +383,7 @@ ReturnValue Actions::internalUseItem(const std::shared_ptr & player, con return RETURNVALUE_CANNOTUSETHISOBJECT; } -bool Actions::useItem(const std::shared_ptr & player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { +bool Actions::useItem(const std::shared_ptr &player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { const ItemType &it = Item::items[item->getID()]; if (it.isRune() || it.type == ITEM_TYPE_POTION) { if (player->walkExhausted()) { @@ -415,7 +415,7 @@ bool Actions::useItem(const std::shared_ptr & player, const Position &po return true; } -bool Actions::useItemEx(const std::shared_ptr & player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature /* = nullptr*/) { +bool Actions::useItemEx(const std::shared_ptr &player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature /* = nullptr*/) { const ItemType &it = Item::items[item->getID()]; if (it.isRune() || it.type == ITEM_TYPE_POTION) { if (player->walkExhausted()) { @@ -467,7 +467,7 @@ bool Actions::useItemEx(const std::shared_ptr & player, const Position & return true; } -void Actions::showUseHotkeyMessage(const std::shared_ptr & player, std::shared_ptr item, uint32_t count) { +void Actions::showUseHotkeyMessage(const std::shared_ptr &player, std::shared_ptr item, uint32_t count) { std::ostringstream ss; const ItemType &it = Item::items[item->getID()]; @@ -491,7 +491,7 @@ void Actions::showUseHotkeyMessage(const std::shared_ptr & player, std:: Action::Action(LuaScriptInterface* interface) : Script(interface) { } -ReturnValue Action::canExecuteAction(const std::shared_ptr & player, const Position &toPos) { +ReturnValue Action::canExecuteAction(const std::shared_ptr &player, const Position &toPos) { if (!allowFarUse) { return g_actions().canUse(player, toPos); } @@ -499,14 +499,14 @@ ReturnValue Action::canExecuteAction(const std::shared_ptr & player, con return g_actions().canUseFar(player, toPos, checkLineOfSight, checkFloor); } -std::shared_ptr Action::getTarget(const std::shared_ptr & player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const { +std::shared_ptr Action::getTarget(const std::shared_ptr &player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const { if (targetCreature != nullptr) { return targetCreature; } return g_game().internalGetThing(player, toPosition, toStackPos, 0, STACKPOS_USETARGET); } -bool Action::executeUse(const std::shared_ptr & player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey) { +bool Action::executeUse(const std::shared_ptr &player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey) { // onUse(player, item, fromPosition, target, toPosition, isHotkey) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[Action::executeUse - Player {}, on item {}] " diff --git a/src/lua/creature/actions.hpp b/src/lua/creature/actions.hpp index 2dea104c7f5..9be4d9ff39e 100644 --- a/src/lua/creature/actions.hpp +++ b/src/lua/creature/actions.hpp @@ -21,7 +21,7 @@ class Action : public Script { explicit Action(LuaScriptInterface* interface); // Scripting - virtual bool executeUse(const std::shared_ptr & player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey); + virtual bool executeUse(const std::shared_ptr &player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey); bool getAllowFarUse() const { return allowFarUse; @@ -96,13 +96,13 @@ class Action : public Script { positions.emplace_back(pos); } - virtual ReturnValue canExecuteAction(const std::shared_ptr & player, const Position &toPos); + virtual ReturnValue canExecuteAction(const std::shared_ptr &player, const Position &toPos); virtual bool hasOwnErrorHandler() { return false; } - virtual std::shared_ptr getTarget(const std::shared_ptr & player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const; + virtual std::shared_ptr getTarget(const std::shared_ptr &player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const; private: std::string getScriptTypeName() const override { @@ -143,11 +143,11 @@ class Actions final : public Scripts { return inject(); } - bool useItem(const std::shared_ptr & player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); - bool useItemEx(const std::shared_ptr & player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature = nullptr); + bool useItem(const std::shared_ptr &player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); + bool useItemEx(const std::shared_ptr &player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature = nullptr); - ReturnValue canUse(const std::shared_ptr & player, const Position &pos); - ReturnValue canUse(const std::shared_ptr & player, const Position &pos, std::shared_ptr item); + ReturnValue canUse(const std::shared_ptr &player, const Position &pos); + ReturnValue canUse(const std::shared_ptr &player, const Position &pos, std::shared_ptr item); ReturnValue canUseFar(std::shared_ptr creature, const Position &toPos, bool checkLineOfSight, bool checkFloor); bool registerLuaItemEvent(const std::shared_ptr action); @@ -211,8 +211,8 @@ class Actions final : public Scripts { actionItemMap.try_emplace(actionId, action); } - ReturnValue internalUseItem(const std::shared_ptr & player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); - static void showUseHotkeyMessage(const std::shared_ptr & player, std::shared_ptr item, uint32_t count); + ReturnValue internalUseItem(const std::shared_ptr &player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); + static void showUseHotkeyMessage(const std::shared_ptr &player, std::shared_ptr item, uint32_t count); using ActionUseMap = std::map>; ActionUseMap useItemMap; diff --git a/src/lua/creature/creatureevent.hpp b/src/lua/creature/creatureevent.hpp index 6817cd37687..29c958f9b0c 100644 --- a/src/lua/creature/creatureevent.hpp +++ b/src/lua/creature/creatureevent.hpp @@ -43,18 +43,18 @@ class CreatureEvent final : public Script { void copyEvent(const std::shared_ptr creatureEvent); // scripting - bool executeOnLogin(const std::shared_ptr & player) const; - bool executeOnLogout(const std::shared_ptr & player) const; + bool executeOnLogin(const std::shared_ptr &player) const; + bool executeOnLogout(const std::shared_ptr &player) const; bool executeOnThink(std::shared_ptr creature, uint32_t interval) const; bool executeOnPrepareDeath(std::shared_ptr creature, std::shared_ptr killer) const; bool executeOnDeath(std::shared_ptr creature, std::shared_ptr corpse, std::shared_ptr killer, std::shared_ptr mostDamageKiller, bool lastHitUnjustified, bool mostDamageUnjustified) const; void executeOnKill(std::shared_ptr creature, std::shared_ptr target, bool lastHit) const; - bool executeAdvance(const std::shared_ptr & player, skills_t, uint32_t, uint32_t) const; - void executeModalWindow(const std::shared_ptr & player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const; - bool executeTextEdit(const std::shared_ptr & player, std::shared_ptr item, const std::string &text) const; + bool executeAdvance(const std::shared_ptr &player, skills_t, uint32_t, uint32_t) const; + void executeModalWindow(const std::shared_ptr &player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const; + bool executeTextEdit(const std::shared_ptr &player, std::shared_ptr item, const std::string &text) const; void executeHealthChange(std::shared_ptr creature, std::shared_ptr attacker, CombatDamage &damage) const; void executeManaChange(std::shared_ptr creature, std::shared_ptr attacker, CombatDamage &damage) const; - void executeExtendedOpcode(const std::shared_ptr & player, uint8_t opcode, const std::string &buffer) const; + void executeExtendedOpcode(const std::shared_ptr &player, uint8_t opcode, const std::string &buffer) const; // private: @@ -78,9 +78,9 @@ class CreatureEvents final : public Scripts { } // global events - bool playerLogin(const std::shared_ptr & player) const; - bool playerLogout(const std::shared_ptr & player) const; - bool playerAdvance(const std::shared_ptr & player, skills_t, uint32_t, uint32_t) const; + bool playerLogin(const std::shared_ptr &player) const; + bool playerLogout(const std::shared_ptr &player) const; + bool playerAdvance(const std::shared_ptr &player, skills_t, uint32_t, uint32_t) const; std::shared_ptr getEventByName(const std::string &name, bool forceLoaded = true); diff --git a/src/lua/creature/events.cpp b/src/lua/creature/events.cpp index c05990f2c07..5352d126e3e 100644 --- a/src/lua/creature/events.cpp +++ b/src/lua/creature/events.cpp @@ -421,7 +421,7 @@ void Events::eventCreatureOnDrainHealth(std::shared_ptr creature, std: } // Party -bool Events::eventPartyOnJoin(Party* party, const std::shared_ptr & player) { +bool Events::eventPartyOnJoin(Party* party, const std::shared_ptr &player) { // Party:onJoin(player) or Party.onJoin(self, player) if (info.partyOnJoin == -1) { return true; @@ -450,7 +450,7 @@ bool Events::eventPartyOnJoin(Party* party, const std::shared_ptr & play return scriptInterface.callFunction(2); } -bool Events::eventPartyOnLeave(Party* party, const std::shared_ptr & player) { +bool Events::eventPartyOnLeave(Party* party, const std::shared_ptr &player) { // Party:onLeave(player) or Party.onLeave(self, player) if (info.partyOnLeave == -1) { return true; @@ -537,7 +537,7 @@ void Events::eventPartyOnShareExperience(Party* party, uint64_t &exp) { } // Player -bool Events::eventPlayerOnBrowseField(const std::shared_ptr & player, const Position &position) { +bool Events::eventPlayerOnBrowseField(const std::shared_ptr &player, const Position &position) { // Player:onBrowseField(position) or Player.onBrowseField(self, position) if (info.playerOnBrowseField == -1) { return true; @@ -565,7 +565,7 @@ bool Events::eventPlayerOnBrowseField(const std::shared_ptr & player, co return scriptInterface.callFunction(2); } -void Events::eventPlayerOnLook(const std::shared_ptr & player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) { +void Events::eventPlayerOnLook(const std::shared_ptr &player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) { // Player:onLook(thing, position, distance) or Player.onLook(self, thing, position, distance) if (info.playerOnLook == -1) { return; @@ -604,7 +604,7 @@ void Events::eventPlayerOnLook(const std::shared_ptr & player, const Pos scriptInterface.callVoidFunction(4); } -void Events::eventPlayerOnLookInBattleList(const std::shared_ptr & player, std::shared_ptr creature, int32_t lookDistance) { +void Events::eventPlayerOnLookInBattleList(const std::shared_ptr &player, std::shared_ptr creature, int32_t lookDistance) { // Player:onLookInBattleList(creature, position, distance) or Player.onLookInBattleList(self, creature, position, distance) if (info.playerOnLookInBattleList == -1) { return; @@ -635,7 +635,7 @@ void Events::eventPlayerOnLookInBattleList(const std::shared_ptr & playe scriptInterface.callVoidFunction(3); } -void Events::eventPlayerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr & partner, std::shared_ptr item, int32_t lookDistance) { +void Events::eventPlayerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr &partner, std::shared_ptr item, int32_t lookDistance) { // Player:onLookInTrade(partner, item, distance) or Player.onLookInTrade(self, partner, item, distance) if (info.playerOnLookInTrade == -1) { return; @@ -669,7 +669,7 @@ void Events::eventPlayerOnLookInTrade(const std::shared_ptr &player, con scriptInterface.callVoidFunction(4); } -bool Events::eventPlayerOnLookInShop(const std::shared_ptr & player, const ItemType* itemType, uint8_t count) { +bool Events::eventPlayerOnLookInShop(const std::shared_ptr &player, const ItemType* itemType, uint8_t count) { // Player:onLookInShop(itemType, count) or Player.onLookInShop(self, itemType, count) if (info.playerOnLookInShop == -1) { return true; @@ -700,7 +700,7 @@ bool Events::eventPlayerOnLookInShop(const std::shared_ptr & player, con return scriptInterface.callFunction(3); } -bool Events::eventPlayerOnRemoveCount(const std::shared_ptr & player, std::shared_ptr item) { +bool Events::eventPlayerOnRemoveCount(const std::shared_ptr &player, std::shared_ptr item) { // Player:onMove() if (info.playerOnRemoveCount == -1) { return true; @@ -729,7 +729,7 @@ bool Events::eventPlayerOnRemoveCount(const std::shared_ptr & player, st return scriptInterface.callFunction(2); } -bool Events::eventPlayerOnMoveItem(const std::shared_ptr & player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { +bool Events::eventPlayerOnMoveItem(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { // Player:onMoveItem(item, count, fromPosition, toPosition) or Player.onMoveItem(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder) if (info.playerOnMoveItem == -1) { return true; @@ -765,7 +765,7 @@ bool Events::eventPlayerOnMoveItem(const std::shared_ptr & player, std:: return scriptInterface.callFunction(7); } -void Events::eventPlayerOnItemMoved(const std::shared_ptr & player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { +void Events::eventPlayerOnItemMoved(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { // Player:onItemMoved(item, count, fromPosition, toPosition) or Player.onItemMoved(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder) if (info.playerOnItemMoved == -1) { return; @@ -801,7 +801,7 @@ void Events::eventPlayerOnItemMoved(const std::shared_ptr & player, std: scriptInterface.callVoidFunction(7); } -void Events::eventPlayerOnChangeZone(const std::shared_ptr & player, ZoneType_t zone) { +void Events::eventPlayerOnChangeZone(const std::shared_ptr &player, ZoneType_t zone) { // Player:onChangeZone(zone) if (info.playerOnChangeZone == -1) { return; @@ -828,7 +828,7 @@ void Events::eventPlayerOnChangeZone(const std::shared_ptr & player, Zon scriptInterface.callVoidFunction(2); } -bool Events::eventPlayerOnMoveCreature(const std::shared_ptr & player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) { +bool Events::eventPlayerOnMoveCreature(const std::shared_ptr &player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) { // Player:onMoveCreature(creature, fromPosition, toPosition) or Player.onMoveCreature(self, creature, fromPosition, toPosition) if (info.playerOnMoveCreature == -1) { return true; @@ -860,7 +860,7 @@ bool Events::eventPlayerOnMoveCreature(const std::shared_ptr & player, s return scriptInterface.callFunction(4); } -void Events::eventPlayerOnReportRuleViolation(const std::shared_ptr & player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) { +void Events::eventPlayerOnReportRuleViolation(const std::shared_ptr &player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) { // Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation) if (info.playerOnReportRuleViolation == -1) { return; @@ -894,7 +894,7 @@ void Events::eventPlayerOnReportRuleViolation(const std::shared_ptr & pl scriptInterface.callVoidFunction(6); } -bool Events::eventPlayerOnReportBug(const std::shared_ptr & player, const std::string &message, const Position &position, uint8_t category) { +bool Events::eventPlayerOnReportBug(const std::shared_ptr &player, const std::string &message, const Position &position, uint8_t category) { // Player:onReportBug(message, position, category) if (info.playerOnReportBug == -1) { return true; @@ -924,7 +924,7 @@ bool Events::eventPlayerOnReportBug(const std::shared_ptr & player, cons return scriptInterface.callFunction(4); } -bool Events::eventPlayerOnTurn(const std::shared_ptr & player, Direction direction) { +bool Events::eventPlayerOnTurn(const std::shared_ptr &player, Direction direction) { // Player:onTurn(direction) or Player.onTurn(self, direction) if (info.playerOnTurn == -1) { return true; @@ -952,7 +952,7 @@ bool Events::eventPlayerOnTurn(const std::shared_ptr & player, Direction return scriptInterface.callFunction(2); } -bool Events::eventPlayerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr & target, std::shared_ptr item) { +bool Events::eventPlayerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item) { // Player:onTradeRequest(target, item) if (info.playerOnTradeRequest == -1) { return true; @@ -984,7 +984,7 @@ bool Events::eventPlayerOnTradeRequest(const std::shared_ptr &player, co return scriptInterface.callFunction(3); } -bool Events::eventPlayerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr & target, std::shared_ptr item, std::shared_ptr targetItem) { +bool Events::eventPlayerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item, std::shared_ptr targetItem) { // Player:onTradeAccept(target, item, targetItem) if (info.playerOnTradeAccept == -1) { return true; @@ -1019,7 +1019,7 @@ bool Events::eventPlayerOnTradeAccept(const std::shared_ptr &player, con return scriptInterface.callFunction(4); } -void Events::eventPlayerOnGainExperience(const std::shared_ptr & player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) { +void Events::eventPlayerOnGainExperience(const std::shared_ptr &player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) { // Player:onGainExperience(target, exp, rawExp) // rawExp gives the original exp which is not multiplied if (info.playerOnGainExperience == -1) { @@ -1063,7 +1063,7 @@ void Events::eventPlayerOnGainExperience(const std::shared_ptr & player, scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnLoseExperience(const std::shared_ptr & player, uint64_t &exp) { +void Events::eventPlayerOnLoseExperience(const std::shared_ptr &player, uint64_t &exp) { // Player:onLoseExperience(exp) if (info.playerOnLoseExperience == -1) { return; @@ -1098,7 +1098,7 @@ void Events::eventPlayerOnLoseExperience(const std::shared_ptr & player, scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnGainSkillTries(const std::shared_ptr & player, skills_t skill, uint64_t &tries) { +void Events::eventPlayerOnGainSkillTries(const std::shared_ptr &player, skills_t skill, uint64_t &tries) { // Player:onGainSkillTries(skill, tries) if (info.playerOnGainSkillTries == -1) { return; @@ -1134,7 +1134,7 @@ void Events::eventPlayerOnGainSkillTries(const std::shared_ptr & player, scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnCombat(const std::shared_ptr & player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) { +void Events::eventPlayerOnCombat(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) { // Player:onCombat(target, item, primaryDamage, primaryType, secondaryDamage, secondaryType) if (info.playerOnCombat == -1) { return; @@ -1191,7 +1191,7 @@ void Events::eventPlayerOnCombat(const std::shared_ptr & player, std::sh scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnRequestQuestLog(const std::shared_ptr & player) { +void Events::eventPlayerOnRequestQuestLog(const std::shared_ptr &player) { // Player:onRequestQuestLog() if (info.playerOnRequestQuestLog == -1) { return; @@ -1217,7 +1217,7 @@ void Events::eventPlayerOnRequestQuestLog(const std::shared_ptr & player scriptInterface.callVoidFunction(1); } -void Events::eventPlayerOnRequestQuestLine(const std::shared_ptr & player, uint16_t questId) { +void Events::eventPlayerOnRequestQuestLine(const std::shared_ptr &player, uint16_t questId) { // Player::onRequestQuestLine() if (info.playerOnRequestQuestLine == -1) { return; @@ -1245,7 +1245,7 @@ void Events::eventPlayerOnRequestQuestLine(const std::shared_ptr & playe scriptInterface.callVoidFunction(2); } -void Events::eventPlayerOnInventoryUpdate(const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool equip) { +void Events::eventPlayerOnInventoryUpdate(const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool equip) { // Player:onInventoryUpdate(item, slot, equip) if (info.playerOnInventoryUpdate == -1) { return; @@ -1274,7 +1274,7 @@ void Events::eventPlayerOnInventoryUpdate(const std::shared_ptr & player scriptInterface.callVoidFunction(4); } -void Events::eventOnStorageUpdate(const std::shared_ptr & player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) { +void Events::eventOnStorageUpdate(const std::shared_ptr &player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) { // Player::onStorageUpdate(key, value, oldValue, currentTime) if (info.playerOnStorageUpdate == -1) { return; diff --git a/src/lua/creature/events.hpp b/src/lua/creature/events.hpp index 7efb4b0f068..918aa9a3b84 100644 --- a/src/lua/creature/events.hpp +++ b/src/lua/creature/events.hpp @@ -88,35 +88,35 @@ class Events { void eventCreatureOnDrainHealth(std::shared_ptr creature, std::shared_ptr attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary); // Party - bool eventPartyOnJoin(Party* party, const std::shared_ptr & player); - bool eventPartyOnLeave(Party* party, const std::shared_ptr & player); + bool eventPartyOnJoin(Party* party, const std::shared_ptr &player); + bool eventPartyOnLeave(Party* party, const std::shared_ptr &player); bool eventPartyOnDisband(Party* party); void eventPartyOnShareExperience(Party* party, uint64_t &exp); // Player - bool eventPlayerOnBrowseField(const std::shared_ptr & player, const Position &position); - void eventPlayerOnLook(const std::shared_ptr & player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance); - void eventPlayerOnLookInBattleList(const std::shared_ptr & player, std::shared_ptr creature, int32_t lookDistance); - void eventPlayerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr & partner, std::shared_ptr item, int32_t lookDistance); - bool eventPlayerOnLookInShop(const std::shared_ptr & player, const ItemType* itemType, uint8_t count); - bool eventPlayerOnMoveItem(const std::shared_ptr & player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); - void eventPlayerOnItemMoved(const std::shared_ptr & player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); - void eventPlayerOnChangeZone(const std::shared_ptr & player, ZoneType_t zone); - bool eventPlayerOnMoveCreature(const std::shared_ptr & player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition); - void eventPlayerOnReportRuleViolation(const std::shared_ptr & player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation); - bool eventPlayerOnReportBug(const std::shared_ptr & player, const std::string &message, const Position &position, uint8_t category); - bool eventPlayerOnTurn(const std::shared_ptr & player, Direction direction); - bool eventPlayerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr & target, std::shared_ptr item); - bool eventPlayerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr & target, std::shared_ptr item, std::shared_ptr targetItem); - void eventPlayerOnGainExperience(const std::shared_ptr & player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp); - void eventPlayerOnLoseExperience(const std::shared_ptr & player, uint64_t &exp); - void eventPlayerOnGainSkillTries(const std::shared_ptr & player, skills_t skill, uint64_t &tries); - bool eventPlayerOnRemoveCount(const std::shared_ptr & player, std::shared_ptr item); - void eventPlayerOnRequestQuestLog(const std::shared_ptr & player); - void eventPlayerOnRequestQuestLine(const std::shared_ptr & player, uint16_t questId); - void eventOnStorageUpdate(const std::shared_ptr & player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime); - void eventPlayerOnCombat(const std::shared_ptr & player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage); - void eventPlayerOnInventoryUpdate(const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool equip); + bool eventPlayerOnBrowseField(const std::shared_ptr &player, const Position &position); + void eventPlayerOnLook(const std::shared_ptr &player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance); + void eventPlayerOnLookInBattleList(const std::shared_ptr &player, std::shared_ptr creature, int32_t lookDistance); + void eventPlayerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr &partner, std::shared_ptr item, int32_t lookDistance); + bool eventPlayerOnLookInShop(const std::shared_ptr &player, const ItemType* itemType, uint8_t count); + bool eventPlayerOnMoveItem(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); + void eventPlayerOnItemMoved(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); + void eventPlayerOnChangeZone(const std::shared_ptr &player, ZoneType_t zone); + bool eventPlayerOnMoveCreature(const std::shared_ptr &player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition); + void eventPlayerOnReportRuleViolation(const std::shared_ptr &player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation); + bool eventPlayerOnReportBug(const std::shared_ptr &player, const std::string &message, const Position &position, uint8_t category); + bool eventPlayerOnTurn(const std::shared_ptr &player, Direction direction); + bool eventPlayerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item); + bool eventPlayerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item, std::shared_ptr targetItem); + void eventPlayerOnGainExperience(const std::shared_ptr &player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp); + void eventPlayerOnLoseExperience(const std::shared_ptr &player, uint64_t &exp); + void eventPlayerOnGainSkillTries(const std::shared_ptr &player, skills_t skill, uint64_t &tries); + bool eventPlayerOnRemoveCount(const std::shared_ptr &player, std::shared_ptr item); + void eventPlayerOnRequestQuestLog(const std::shared_ptr &player); + void eventPlayerOnRequestQuestLine(const std::shared_ptr &player, uint16_t questId); + void eventOnStorageUpdate(const std::shared_ptr &player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime); + void eventPlayerOnCombat(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage); + void eventPlayerOnInventoryUpdate(const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool equip); // Monster void eventMonsterOnDropLoot(std::shared_ptr monster, std::shared_ptr corpse); diff --git a/src/lua/creature/movement.cpp b/src/lua/creature/movement.cpp index fb673c628db..d242c25c964 100644 --- a/src/lua/creature/movement.cpp +++ b/src/lua/creature/movement.cpp @@ -467,7 +467,7 @@ uint32_t MoveEvent::RemoveItemField(std::shared_ptr, std::shared_ptr return 1; } -uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool isCheck) { +uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool isCheck) { if (player == nullptr) { g_logger().error("[MoveEvent::EquipItem] - Player is nullptr"); return 0; @@ -581,7 +581,7 @@ uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, const return 1; } -uint32_t MoveEvent::DeEquipItem(const std::shared_ptr MoveEvent, const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool) { +uint32_t MoveEvent::DeEquipItem(const std::shared_ptr MoveEvent, const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool) { if (player == nullptr) { g_logger().error("[MoveEvent::EquipItem] - Player is nullptr"); return 0; diff --git a/src/lua/creature/movement.hpp b/src/lua/creature/movement.hpp index 61089d95f8d..7657bfebfcc 100644 --- a/src/lua/creature/movement.hpp +++ b/src/lua/creature/movement.hpp @@ -248,8 +248,8 @@ class MoveEvent final : public Script, public SharedObject { static uint32_t AddItemField(std::shared_ptr item, std::shared_ptr tileItem, const Position &pos); static uint32_t RemoveItemField(std::shared_ptr item, std::shared_ptr tileItem, const Position &pos); - static uint32_t EquipItem(const std::shared_ptr moveEvent, const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool boolean); - static uint32_t DeEquipItem(const std::shared_ptr moveEvent, const std::shared_ptr & player, std::shared_ptr item, Slots_t slot, bool boolean); + static uint32_t EquipItem(const std::shared_ptr moveEvent, const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool boolean); + static uint32_t DeEquipItem(const std::shared_ptr moveEvent, const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool boolean); private: std::string getScriptTypeName() const override; diff --git a/src/lua/creature/talkaction.cpp b/src/lua/creature/talkaction.cpp index 4308640a7f2..084bccd8f54 100644 --- a/src/lua/creature/talkaction.cpp +++ b/src/lua/creature/talkaction.cpp @@ -25,7 +25,7 @@ bool TalkActions::registerLuaEvent(const TalkAction_ptr &talkAction) { return inserted; } -bool TalkActions::checkWord(const std::shared_ptr & player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const { +bool TalkActions::checkWord(const std::shared_ptr &player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const { auto spacePos = std::ranges::find_if(words.begin(), words.end(), ::isspace); std::string firstWord = words.substr(0, spacePos - words.begin()); @@ -61,7 +61,7 @@ bool TalkActions::checkWord(const std::shared_ptr & player, SpeakClasses return talkActionPtr->executeSay(player, words, param, type); } -TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(const std::shared_ptr & player, SpeakClasses type, const std::string &words) const { +TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(const std::shared_ptr &player, SpeakClasses type, const std::string &words) const { for (const auto &[talkactionWords, talkActionPtr] : talkActions) { if (talkactionWords.find(',') != std::string::npos) { auto wordsList = split(talkactionWords); @@ -79,7 +79,7 @@ TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(const std::shared_pt return TALKACTION_CONTINUE; } -bool TalkAction::executeSay(const std::shared_ptr & player, const std::string &words, const std::string ¶m, SpeakClasses type) const { +bool TalkAction::executeSay(const std::shared_ptr &player, const std::string &words, const std::string ¶m, SpeakClasses type) const { // onSay(player, words, param, type) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[TalkAction::executeSay - Player {} words {}] " diff --git a/src/lua/creature/talkaction.hpp b/src/lua/creature/talkaction.hpp index 702602e474b..e5b21db5416 100644 --- a/src/lua/creature/talkaction.hpp +++ b/src/lua/creature/talkaction.hpp @@ -44,7 +44,7 @@ class TalkAction : public Script { } // scripting - bool executeSay(const std::shared_ptr & player, const std::string &words, const std::string ¶m, SpeakClasses type) const; + bool executeSay(const std::shared_ptr &player, const std::string &words, const std::string ¶m, SpeakClasses type) const; // void setGroupType(account::GroupType newGroupType) { @@ -78,8 +78,8 @@ class TalkActions final : public Scripts { return inject(); } - bool checkWord(const std::shared_ptr & player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const; - TalkActionResult_t checkPlayerCanSayTalkAction(const std::shared_ptr & player, SpeakClasses type, const std::string &words) const; + bool checkWord(const std::shared_ptr &player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const; + TalkActionResult_t checkPlayerCanSayTalkAction(const std::shared_ptr &player, SpeakClasses type, const std::string &words) const; bool registerLuaEvent(const TalkAction_ptr &talkAction); void clear(); diff --git a/src/lua/functions/creatures/player/guild_functions.cpp b/src/lua/functions/creatures/player/guild_functions.cpp index aa9402eabe8..6bb600fa97a 100644 --- a/src/lua/functions/creatures/player/guild_functions.cpp +++ b/src/lua/functions/creatures/player/guild_functions.cpp @@ -58,7 +58,7 @@ int GuildFunctions::luaGuildGetMembersOnline(lua_State* L) { lua_createtable(L, members.size(), 0); int index = 0; - for (const std::shared_ptr & player : members) { + for (const std::shared_ptr &player : members) { pushUserdata(L, player); setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); diff --git a/src/lua/functions/creatures/player/party_functions.cpp b/src/lua/functions/creatures/player/party_functions.cpp index db740638bb9..c5495b1f017 100644 --- a/src/lua/functions/creatures/player/party_functions.cpp +++ b/src/lua/functions/creatures/player/party_functions.cpp @@ -89,7 +89,7 @@ int PartyFunctions::luaPartyGetMembers(lua_State* L) { int index = 0; lua_createtable(L, party->getMemberCount(), 0); - for (const std::shared_ptr & player : party->getMembers()) { + for (const std::shared_ptr &player : party->getMembers()) { pushUserdata(L, player); setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); @@ -115,7 +115,7 @@ int PartyFunctions::luaPartyGetInvitees(lua_State* L) { lua_createtable(L, party->getInvitationCount(), 0); int index = 0; - for (const std::shared_ptr & player : party->getInvitees()) { + for (const std::shared_ptr &player : party->getInvitees()) { pushUserdata(L, player); setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); diff --git a/src/lua/modules/modules.cpp b/src/lua/modules/modules.cpp index 9804dc2f7ff..bda2c157570 100644 --- a/src/lua/modules/modules.cpp +++ b/src/lua/modules/modules.cpp @@ -152,7 +152,7 @@ void Module::clearEvent() { loaded = false; } -void Module::executeOnRecvbyte(const std::shared_ptr & player, NetworkMessage &msg) { +void Module::executeOnRecvbyte(const std::shared_ptr &player, NetworkMessage &msg) { // onRecvbyte(player, msg, recvbyte) if (!scriptInterface->reserveScriptEnv()) { g_logger().error("Call stack overflow. Too many lua script calls being nested {}", player->getName()); diff --git a/src/lua/modules/modules.hpp b/src/lua/modules/modules.hpp index 2e692e400e4..3470df890c8 100644 --- a/src/lua/modules/modules.hpp +++ b/src/lua/modules/modules.hpp @@ -35,7 +35,7 @@ class Module final : public Event { void copyEvent(Module* creatureEvent); // scripting - void executeOnRecvbyte(const std::shared_ptr & player, NetworkMessage &msg); + void executeOnRecvbyte(const std::shared_ptr &player, NetworkMessage &msg); // uint8_t getRecvbyte() { diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index 6a4fc786071..f89c4c2a232 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -24,7 +24,7 @@ void House::addTile(std::shared_ptr tile) { updateDoorDescription(); } -void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, const std::shared_ptr & player /* = nullptr*/) { +void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, const std::shared_ptr &player /* = nullptr*/) { if (updateDatabase && owner != guid) { Database &db = Database::getInstance(); @@ -136,7 +136,7 @@ void House::updateDoorDescription() const { } } -AccessHouseLevel_t House::getHouseAccessLevel(const std::shared_ptr & player) { +AccessHouseLevel_t House::getHouseAccessLevel(const std::shared_ptr &player) { if (!player) { return HOUSE_OWNER; } @@ -166,7 +166,7 @@ AccessHouseLevel_t House::getHouseAccessLevel(const std::shared_ptr & pl return HOUSE_NOT_INVITED; } -bool House::kickPlayer(const std::shared_ptr &player, const std::shared_ptr & target) { +bool House::kickPlayer(const std::shared_ptr &player, const std::shared_ptr &target) { if (!target) { return false; } @@ -236,7 +236,7 @@ bool House::transferToDepot() const { return true; } -bool House::transferToDepot(const std::shared_ptr & player) const { +bool House::transferToDepot(const std::shared_ptr &player) const { if (townId == 0 || owner == 0) { return false; } @@ -261,7 +261,7 @@ bool House::transferToDepot(const std::shared_ptr & player) const { return true; } -void House::handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, const std::shared_ptr & player, std::shared_ptr houseTile) const { +void House::handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, const std::shared_ptr &player, std::shared_ptr houseTile) const { if (item->isWrapContainer()) { handleContainer(moveItemList, item); } @@ -300,7 +300,7 @@ bool House::getAccessList(uint32_t listId, std::string &list) const { return door->getAccessList(list); } -bool House::isInvited(const std::shared_ptr & player) { +bool House::isInvited(const std::shared_ptr &player) { return getHouseAccessLevel(player) != HOUSE_NOT_INVITED; } @@ -345,7 +345,7 @@ std::shared_ptr House::getDoorByPosition(const Position &pos) { return nullptr; } -bool House::canEditAccessList(uint32_t listId, const std::shared_ptr & player) { +bool House::canEditAccessList(uint32_t listId, const std::shared_ptr &player) { switch (getHouseAccessLevel(player)) { case HOUSE_OWNER: return true; @@ -388,7 +388,7 @@ std::shared_ptr HouseTransferItem::createHouseTransferItem(Ho return transferItem; } -void HouseTransferItem::onTradeEvent(TradeEvents_t event, const std::shared_ptr & owner) { +void HouseTransferItem::onTradeEvent(TradeEvents_t event, const std::shared_ptr &owner) { if (event == ON_TRADE_TRANSFER) { if (house) { house->executeTransfer(static_self_cast(), owner); @@ -402,7 +402,7 @@ void HouseTransferItem::onTradeEvent(TradeEvents_t event, const std::shared_ptr< } } -bool House::executeTransfer(std::shared_ptr item, const std::shared_ptr & newOwner) { +bool House::executeTransfer(std::shared_ptr item, const std::shared_ptr &newOwner) { if (transferItem != item) { return false; } @@ -502,7 +502,7 @@ void AccessList::addGuildRank(const std::string &name, const std::string &guildN } } -bool AccessList::isInList(const std::shared_ptr & player) { +bool AccessList::isInList(const std::shared_ptr &player) { if (allowEveryone) { return true; } @@ -548,7 +548,7 @@ void Door::setHouse(House* newHouse) { } } -bool Door::canUse(const std::shared_ptr & player) { +bool Door::canUse(const std::shared_ptr &player) { if (!house) { return true; } diff --git a/src/map/house/house.hpp b/src/map/house/house.hpp index 85a5e450669..e0febc918ae 100644 --- a/src/map/house/house.hpp +++ b/src/map/house/house.hpp @@ -25,7 +25,7 @@ class AccessList { void addGuild(const std::string &name); void addGuildRank(const std::string &name, const std::string &rankName); - bool isInList(const std::shared_ptr & player); + bool isInList(const std::shared_ptr &player); void getList(std::string &list) const; @@ -63,7 +63,7 @@ class Door final : public Item { return getAttribute(ItemAttribute_t::DOORID); } - bool canUse(const std::shared_ptr & player); + bool canUse(const std::shared_ptr &player); void setAccessList(const std::string &textlist); bool getAccessList(std::string &list) const; @@ -88,7 +88,7 @@ class HouseTransferItem final : public Item { explicit HouseTransferItem(House* newHouse) : Item(0), house(newHouse) { } - void onTradeEvent(TradeEvents_t event, const std::shared_ptr & owner) override; + void onTradeEvent(TradeEvents_t event, const std::shared_ptr &owner) override; bool canTransform() const override { return false; } @@ -104,17 +104,17 @@ class House { void addTile(std::shared_ptr tile); void updateDoorDescription() const; - bool canEditAccessList(uint32_t listId, const std::shared_ptr & player); + bool canEditAccessList(uint32_t listId, const std::shared_ptr &player); // listId special = values: // GUEST_LIST = guest list // SUBOWNER_LIST = subowner list void setAccessList(uint32_t listId, const std::string &textlist); bool getAccessList(uint32_t listId, std::string &list) const; - bool isInvited(const std::shared_ptr & player); + bool isInvited(const std::shared_ptr &player); - AccessHouseLevel_t getHouseAccessLevel(const std::shared_ptr & player); - bool kickPlayer(const std::shared_ptr &player, const std::shared_ptr & target); + AccessHouseLevel_t getHouseAccessLevel(const std::shared_ptr &player); + bool kickPlayer(const std::shared_ptr &player, const std::shared_ptr &target); void setEntryPos(Position pos) { posEntry = pos; @@ -130,7 +130,7 @@ class House { return houseName; } - void setOwner(uint32_t guid, bool updateDatabase = true, const std::shared_ptr & player = nullptr); + void setOwner(uint32_t guid, bool updateDatabase = true, const std::shared_ptr &player = nullptr); uint32_t getOwner() const { return owner; } @@ -180,7 +180,7 @@ class House { std::shared_ptr getTransferItem(); void resetTransferItem(); - bool executeTransfer(std::shared_ptr item, const std::shared_ptr & player); + bool executeTransfer(std::shared_ptr item, const std::shared_ptr &player); const HouseTileList &getTiles() const { return houseTiles; @@ -209,7 +209,7 @@ class House { private: bool transferToDepot() const; - bool transferToDepot(const std::shared_ptr & player) const; + bool transferToDepot(const std::shared_ptr &player) const; AccessList guestList; AccessList subOwnerList; @@ -242,7 +242,7 @@ class House { bool isLoaded = false; void handleContainer(ItemList &moveItemList, std::shared_ptr item) const; - void handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, const std::shared_ptr & player, std::shared_ptr houseTile) const; + void handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, const std::shared_ptr &player, std::shared_ptr houseTile) const; }; using HouseMap = std::map; diff --git a/src/server/network/protocol/protocolgame.hpp b/src/server/network/protocol/protocolgame.hpp index 1d1a3eef644..4689a7a0ce4 100644 --- a/src/server/network/protocol/protocolgame.hpp +++ b/src/server/network/protocol/protocolgame.hpp @@ -233,7 +233,7 @@ class ProtocolGame final : public Protocol { void sendOpenPrivateChannel(const std::string &receiver); void sendExperienceTracker(int64_t rawExp, int64_t finalExp); void sendToChannel(std::shared_ptr creature, SpeakClasses type, const std::string &text, uint16_t channelId); - void sendPrivateMessage(const std::shared_ptr & speaker, SpeakClasses type, const std::string &text); + void sendPrivateMessage(const std::shared_ptr &speaker, SpeakClasses type, const std::string &text); void sendIcons(uint32_t icons); void sendFYIBox(const std::string &message); @@ -281,10 +281,10 @@ class ProtocolGame final : public Protocol { void sendPartyCreatureShield(std::shared_ptr target); void sendPartyCreatureSkull(std::shared_ptr target); void sendPartyCreatureHealth(std::shared_ptr target, uint8_t healthPercent); - void sendPartyPlayerMana(const std::shared_ptr & target, uint8_t manaPercent); + void sendPartyPlayerMana(const std::shared_ptr &target, uint8_t manaPercent); void sendPartyCreatureShowStatus(std::shared_ptr target, bool showStatus); - void sendPartyPlayerVocation(const std::shared_ptr & target); - void sendPlayerVocation(const std::shared_ptr & target); + void sendPartyPlayerVocation(const std::shared_ptr &target); + void sendPlayerVocation(const std::shared_ptr &target); void sendSkills(); void sendPing(); void sendPingBack(); From 499c7a2dd9451ef6c746cb9d72936b908e7a3aaa Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sun, 17 Sep 2023 16:52:10 -0700 Subject: [PATCH 25/67] fix: check if summon exists --- src/creatures/creature.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index a81b6da7f7b..1cce98986af 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -336,6 +336,9 @@ class Creature : virtual public Thing, public SharedObject { } const std::shared_ptr &getSummon(uint32_t creatureId) { + if (!m_summons.contains(creatureId)) { + return nullptr; + } return m_summons.at(creatureId); } From 239a7c8fcdc6539dcefa3522a7791d6aef942a3d Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sun, 17 Sep 2023 16:52:10 -0700 Subject: [PATCH 26/67] fix: check if summon exists --- src/creatures/creature.cpp | 2 +- src/creatures/creature.hpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index e8d7a7b9efc..2865c371992 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -1238,7 +1238,7 @@ bool Creature::setMaster(std::shared_ptr newMaster, bool reloadCreatur m_master = newMaster; if (oldMaster) { - auto summon = getSummon(getID()); + auto summon = oldMaster->getSummon(getID()); if (summon) { oldMaster->removeSummon(summon); } diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index 1cce98986af..d83132d883c 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -335,11 +335,11 @@ class Creature : virtual public Thing, public SharedObject { return m_summons; } - const std::shared_ptr &getSummon(uint32_t creatureId) { - if (!m_summons.contains(creatureId)) { - return nullptr; + std::shared_ptr getSummon(uint32_t creatureId) { + if (m_summons.contains(creatureId)) { + return m_summons.at(creatureId); } - return m_summons.at(creatureId); + return nullptr; } void removeSummon(const std::shared_ptr &summon) { From 1496737467db27bded3d6c54f8b518df068087f2 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sun, 17 Sep 2023 21:52:12 -0700 Subject: [PATCH 27/67] fix: decay semantics --- src/items/decay/decay.cpp | 156 +++++++++++++++++++------------------- src/items/decay/decay.hpp | 7 +- 2 files changed, 80 insertions(+), 83 deletions(-) diff --git a/src/items/decay/decay.cpp b/src/items/decay/decay.cpp index c3b8de15fa8..5542a85ab7d 100644 --- a/src/items/decay/decay.cpp +++ b/src/items/decay/decay.cpp @@ -13,8 +13,8 @@ #include "game/game.hpp" #include "game/scheduling/scheduler.hpp" -void Decay::startDecay(const std::shared_ptr &item) { - if (!item) { +void Decay::startDecay(std::shared_ptr item) { + if (!item || !item->canDecay() || item->getDecaying() == DECAYING_TRUE) { return; } @@ -24,10 +24,6 @@ void Decay::startDecay(const std::shared_ptr &item) { return; } - if (!item->canDecay() || decayState == DECAYING_TRUE) { - return; - } - const auto duration = item->getAttribute(ItemAttribute_t::DURATION); if (duration <= 0 && item->hasAttribute(ItemAttribute_t::DURATION)) { internalDecayItem(item); @@ -55,55 +51,57 @@ void Decay::startDecay(const std::shared_ptr &item) { } } -void Decay::stopDecay(const std::shared_ptr &item) { - if (item->hasAttribute(ItemAttribute_t::DECAYSTATE)) { +void Decay::stopDecay(std::shared_ptr item) { + if (!item->hasAttribute(ItemAttribute_t::DECAYSTATE)) { + return; + } + + if (item->hasAttribute(ItemAttribute_t::DURATION_TIMESTAMP)) { auto timestamp = item->getAttribute(ItemAttribute_t::DURATION_TIMESTAMP); - if (item->hasAttribute(ItemAttribute_t::DURATION_TIMESTAMP)) { - auto it = decayMap.find(timestamp); - if (it != decayMap.end()) { - auto &decayItems = it->second; - - size_t i = 0, end = decayItems.size(); - auto decayItem = decayItems[i]; - if (end == 1) { - if (item == decayItem) { - if (item->hasAttribute(ItemAttribute_t::DURATION)) { - // Incase we removed duration attribute don't assign new duration - item->setDuration(item->getDuration()); - } - item->removeAttribute(ItemAttribute_t::DECAYSTATE); - - decayMap.erase(it); + auto it = decayMap.find(timestamp); + if (it != decayMap.end()) { + auto &decayItems = it->second; + + size_t i = 0, end = decayItems.size(); + auto decayItem = decayItems[i]; + if (end == 1) { + if (item == decayItem) { + if (item->hasAttribute(ItemAttribute_t::DURATION)) { + // Incase we removed duration attribute don't assign new duration + item->setDuration(item->getDuration()); } - return; + item->removeAttribute(ItemAttribute_t::DECAYSTATE); + + decayMap.erase(it); } - while (i < end) { - decayItem = decayItems[i]; - if (item == decayItem) { - if (item->hasAttribute(ItemAttribute_t::DURATION)) { - // Incase we removed duration attribute don't assign new duration - item->setDuration(item->getDuration()); - } - item->removeAttribute(ItemAttribute_t::DECAYSTATE); - - decayItems[i] = decayItems.back(); - decayItems.pop_back(); - return; + return; + } + while (i < end) { + decayItem = decayItems[i]; + if (item == decayItem) { + if (item->hasAttribute(ItemAttribute_t::DURATION)) { + // Incase we removed duration attribute don't assign new duration + item->setDuration(item->getDuration()); } - ++i; + item->removeAttribute(ItemAttribute_t::DECAYSTATE); + + decayItems[i] = decayItems.back(); + decayItems.pop_back(); + return; } + ++i; } - item->removeAttribute(ItemAttribute_t::DURATION_TIMESTAMP); - } else { - item->removeAttribute(ItemAttribute_t::DECAYSTATE); } + item->removeAttribute(ItemAttribute_t::DURATION_TIMESTAMP); + } else { + item->removeAttribute(ItemAttribute_t::DECAYSTATE); } } void Decay::checkDecay() { int64_t timestamp = OTSYS_TIME(); - std::vector> tempItems; + tempItems.reserve(32); // Small preallocation auto it = decayMap.begin(), end = decayMap.end(); @@ -138,53 +136,51 @@ void Decay::checkDecay() { void Decay::internalDecayItem(const std::shared_ptr &item) { const ItemType &it = Item::items[item->getID()]; - if (it.decayTo != 0) { - const auto &player = item->getHoldingPlayer(); - if (player) { - bool needUpdateSkills = false; - for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { - if (it.abilities && it.abilities->skills[i] != 0) { - needUpdateSkills = true; - player->setVarSkill(static_cast(i), -it.abilities->skills[i]); - } - } - if (needUpdateSkills) { - player->sendSkills(); - } + if (it.decayTo == 0 && !item->isLoadedFromMap()) { + ReturnValue ret = g_game().internalRemoveItem(item); + if (ret != RETURNVALUE_NOERROR) { + g_logger().error("[Decay::internalDecayItem] - internalDecayItem failed, " + "error code: {}, item id: {}", + static_cast(ret), item->getID()); + } + return; + } - bool needUpdateStats = false; - for (int32_t s = STAT_FIRST; s <= STAT_LAST; ++s) { - if (it.abilities && it.abilities->stats[s] != 0) { - needUpdateStats = true; - needUpdateSkills = true; - player->setVarStats(static_cast(s), -it.abilities->stats[s]); - } - if (it.abilities && it.abilities->statsPercent[s] != 0) { - needUpdateStats = true; - player->setVarStats(static_cast(s), -static_cast(player->getDefaultStats(static_cast(s)) * ((it.abilities->statsPercent[s] - 100) / 100.f))); - } + const auto &player = item->getHoldingPlayer(); + if (player) { + bool needUpdateSkills = false; + for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { + if (it.abilities && it.abilities->skills[i] != 0) { + needUpdateSkills = true; + player->setVarSkill(static_cast(i), -it.abilities->skills[i]); } + } - if (needUpdateStats) { - player->sendStats(); - } + if (needUpdateSkills) { + player->sendSkills(); + } - if (needUpdateSkills) { - player->sendSkills(); + bool needUpdateStats = false; + for (int32_t s = STAT_FIRST; s <= STAT_LAST; ++s) { + if (it.abilities && it.abilities->stats[s] != 0) { + needUpdateStats = true; + needUpdateSkills = true; + player->setVarStats(static_cast(s), -it.abilities->stats[s]); + } + if (it.abilities && it.abilities->statsPercent[s] != 0) { + needUpdateStats = true; + player->setVarStats(static_cast(s), -static_cast(player->getDefaultStats(static_cast(s)) * ((it.abilities->statsPercent[s] - 100) / 100.f))); } } - g_game().transformItem(item, static_cast(it.decayTo)); - } else { - if (item->isLoadedFromMap()) { - return; + + if (needUpdateStats) { + player->sendStats(); } - ReturnValue ret = g_game().internalRemoveItem(item); - if (ret != RETURNVALUE_NOERROR) { - g_logger().error("[Decay::internalDecayItem] - internalDecayItem failed, " - "error code: {}, item id: {}", - static_cast(ret), item->getID()); + if (needUpdateSkills) { + player->sendSkills(); } } + g_game().transformItem(item, static_cast(it.decayTo)); } diff --git a/src/items/decay/decay.hpp b/src/items/decay/decay.hpp index 481be26c610..d4230b8a0ba 100644 --- a/src/items/decay/decay.hpp +++ b/src/items/decay/decay.hpp @@ -22,15 +22,16 @@ class Decay { return inject(); } - void startDecay(const std::shared_ptr &item); - void stopDecay(const std::shared_ptr &item); + void startDecay(std::shared_ptr item); + void stopDecay(std::shared_ptr item); private: void checkDecay(); void internalDecayItem(const std::shared_ptr &item); uint32_t eventId { 0 }; - phmap::flat_hash_map>> decayMap; + // order is important, so we use an std::map + std::map>> decayMap; }; constexpr auto g_decay = Decay::getInstance; From 474903d3c1590d32bf21f3f416dbf675b71b4ffb Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Mon, 18 Sep 2023 17:09:49 -0700 Subject: [PATCH 28/67] fix: cancel decay properly --- src/items/decay/decay.cpp | 7 ++++++- src/items/item.cpp | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/items/decay/decay.cpp b/src/items/decay/decay.cpp index 5542a85ab7d..23759e5dc24 100644 --- a/src/items/decay/decay.cpp +++ b/src/items/decay/decay.cpp @@ -14,7 +14,7 @@ #include "game/scheduling/scheduler.hpp" void Decay::startDecay(std::shared_ptr item) { - if (!item || !item->canDecay() || item->getDecaying() == DECAYING_TRUE) { + if (!item) { return; } @@ -24,6 +24,10 @@ void Decay::startDecay(std::shared_ptr item) { return; } + if (!item->canDecay() || decayState == DECAYING_TRUE) { + return; + } + const auto duration = item->getAttribute(ItemAttribute_t::DURATION); if (duration <= 0 && item->hasAttribute(ItemAttribute_t::DURATION)) { internalDecayItem(item); @@ -52,6 +56,7 @@ void Decay::startDecay(std::shared_ptr item) { } void Decay::stopDecay(std::shared_ptr item) { + g_logger().debug("[Decay::stopDecay] - Stopping decay for item id: {}", item->getID()); if (!item->hasAttribute(ItemAttribute_t::DECAYSTATE)) { return; } diff --git a/src/items/item.cpp b/src/items/item.cpp index 9e97e6557a7..6913f0b72ee 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -281,6 +281,7 @@ void Item::onRemoved() { } void Item::setID(uint16_t newid) { + g_logger().debug("[Item::setID] - Setting item id from {} to {}", id, newid); const ItemType &prevIt = Item::items[id]; id = newid; @@ -3082,6 +3083,7 @@ void Item::startDecaying() { } void Item::stopDecaying() { + g_logger().debug("Item::stopDecaying"); g_decay().stopDecay(static_self_cast()); } From 16295ee1c7bcf578eac468f4f903cc41739b8a7d Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Mon, 18 Sep 2023 17:28:44 -0700 Subject: [PATCH 29/67] fix: track summons properly --- src/creatures/creature.cpp | 16 +++++++--------- src/creatures/creature.hpp | 17 ++--------------- src/creatures/monsters/monster.cpp | 4 ++-- src/creatures/players/grouping/party.cpp | 8 ++++---- src/game/game.cpp | 2 +- .../functions/creatures/creature_functions.cpp | 2 +- 6 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 2865c371992..2d1695ffbc0 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -26,7 +26,7 @@ Creature::Creature() { } Creature::~Creature() { - for (auto &[_, summon] : m_summons) { + for (const auto &summon : m_summons) { summon->setAttackedCreature(nullptr); summon->removeMaster(); } @@ -425,7 +425,7 @@ void Creature::onAttackedCreatureChangeZone(ZoneType_t zone) { void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) { if (hasSummons()) { std::vector> despawnMonsterList; - for (auto &[_, summon] : getSummons()) { + for (const auto &summon : getSummons()) { const Position &pos = summon->getPosition(); std::shared_ptr monster = summon->getMonster(); auto tile = getTile(); @@ -945,7 +945,7 @@ bool Creature::setAttackedCreature(std::shared_ptr creature) { m_attackedCreature.reset(); } - for (auto &[_, summon] : m_summons) { + for (const auto &summon : m_summons) { summon->setAttackedCreature(creature); } return true; @@ -1223,25 +1223,23 @@ bool Creature::setMaster(std::shared_ptr newMaster, bool reloadCreatur if (!newMaster && !oldMaster) { return false; } + const auto &self = getCreature(); // Reloading summon icon/knownCreature and reset informations (follow/dropLoot/skillLoss) if (reloadCreature) { setFollowCreature(nullptr); setDropLoot(false); setSkillLoss(false); - g_game().reloadCreature(static_self_cast()); + g_game().reloadCreature(self); } if (newMaster) { - newMaster->m_summons.try_emplace(getID(), static_self_cast()); + newMaster->m_summons.insert(self); } m_master = newMaster; if (oldMaster) { - auto summon = oldMaster->getSummon(getID()); - if (summon) { - oldMaster->removeSummon(summon); - } + oldMaster->m_summons.erase(self); } return true; } diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index d83132d883c..a1b7bd386b4 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -331,23 +331,10 @@ class Creature : virtual public Thing, public SharedObject { return m_master.lock(); } - const phmap::flat_hash_map> &getSummons() const { + const phmap::flat_hash_set> &getSummons() const { return m_summons; } - std::shared_ptr getSummon(uint32_t creatureId) { - if (m_summons.contains(creatureId)) { - return m_summons.at(creatureId); - } - return nullptr; - } - - void removeSummon(const std::shared_ptr &summon) { - if (summon) { - m_summons.erase(summon->getID()); - } - } - virtual int32_t getArmor() const { return 0; } @@ -668,7 +655,7 @@ class Creature : virtual public Thing, public SharedObject { CountMap damageMap; - phmap::flat_hash_map> m_summons; + phmap::flat_hash_set> m_summons; CreatureEventList eventsList; ConditionList conditions; diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index ee929e6f986..69f282af754 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -1013,7 +1013,7 @@ void Monster::onThinkDefense(uint32_t interval) { } uint32_t summonCount = 0; - for (auto &[_, summon] : m_summons) { + for (const auto &summon : m_summons) { if (summon && summon->getName() == summonBlock.name) { ++summonCount; } @@ -1852,7 +1852,7 @@ void Monster::death(std::shared_ptr) { } setAttackedCreature(nullptr); - for (auto &[_, summon] : m_summons) { + for (const auto &summon : m_summons) { if (!summon) { continue; } diff --git a/src/creatures/players/grouping/party.cpp b/src/creatures/players/grouping/party.cpp index 56d34a4a0dd..c057431ab16 100644 --- a/src/creatures/players/grouping/party.cpp +++ b/src/creatures/players/grouping/party.cpp @@ -587,11 +587,11 @@ void Party::showPlayerStatus(const std::shared_ptr &player, const std::s player->sendPartyCreatureShowStatus(member, showStatus); member->sendPartyCreatureShowStatus(player, showStatus); if (showStatus) { - for (auto &[_, summon] : member->getSummons()) { + for (const auto &summon : member->getSummons()) { player->sendPartyCreatureShowStatus(summon, showStatus); player->sendPartyCreatureHealth(summon, std::ceil((static_cast(summon->getHealth()) / std::max(summon->getMaxHealth(), 1)) * 100)); } - for (auto &[_, summon] : player->getSummons()) { + for (const auto &summon : player->getSummons()) { member->sendPartyCreatureShowStatus(summon, showStatus); member->sendPartyCreatureHealth(summon, std::ceil((static_cast(summon->getHealth()) / std::max(summon->getMaxHealth(), 1)) * 100)); } @@ -600,10 +600,10 @@ void Party::showPlayerStatus(const std::shared_ptr &player, const std::s player->sendPartyPlayerMana(member, std::ceil((static_cast(member->getMana()) / std::max(member->getMaxMana(), 1)) * 100)); member->sendPartyPlayerMana(player, std::ceil((static_cast(player->getMana()) / std::max(player->getMaxMana(), 1)) * 100)); } else { - for (auto &[_, summon] : player->getSummons()) { + for (const auto &summon : player->getSummons()) { member->sendPartyCreatureShowStatus(summon, showStatus); } - for (auto &[_, summon] : member->getSummons()) { + for (const auto &summon : member->getSummons()) { player->sendPartyCreatureShowStatus(summon, showStatus); } } diff --git a/src/game/game.cpp b/src/game/game.cpp index cfc52afa117..7bd6c196e88 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -945,7 +945,7 @@ bool Game::removeCreature(std::shared_ptr creature, bool isLogout /* = removeCreatureCheck(creature); - for (auto &[_, summon] : creature->m_summons) { + for (const auto &summon : creature->m_summons) { summon->setSkillLoss(false); removeCreature(summon); } diff --git a/src/lua/functions/creatures/creature_functions.cpp b/src/lua/functions/creatures/creature_functions.cpp index 32f7ef53135..40d46dcdbf0 100644 --- a/src/lua/functions/creatures/creature_functions.cpp +++ b/src/lua/functions/creatures/creature_functions.cpp @@ -859,7 +859,7 @@ int CreatureFunctions::luaCreatureGetSummons(lua_State* L) { lua_createtable(L, creature->getSummonCount(), 0); int index = 0; - for (auto &[_, summon] : creature->getSummons()) { + for (const auto &summon : creature->getSummons()) { if (summon) { pushUserdata(L, summon); setCreatureMetatable(L, -1, summon); From 760fb2df59619d7d6fccf5914555dc3c32de0289 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Mon, 18 Sep 2023 21:51:17 -0700 Subject: [PATCH 30/67] Revert "improve: use const refs for player where appropriate" This reverts commit 5bebe3ddd20f95dc66921b70d2fcec8e96b1f0df. --- src/creatures/combat/combat.cpp | 51 +- src/creatures/combat/combat.hpp | 14 +- src/creatures/combat/condition.cpp | 56 +- src/creatures/combat/condition.hpp | 8 +- src/creatures/combat/spells.cpp | 53 +- src/creatures/combat/spells.hpp | 28 +- src/creatures/creature.cpp | 10 +- src/creatures/monsters/monster.cpp | 6 +- src/creatures/npcs/npc.cpp | 26 +- src/creatures/npcs/npc.hpp | 16 +- src/creatures/players/grouping/party.cpp | 40 +- src/creatures/players/grouping/party.hpp | 38 +- .../players/imbuements/imbuements.cpp | 2 +- .../players/imbuements/imbuements.hpp | 2 +- src/creatures/players/management/waitlist.cpp | 6 +- src/creatures/players/management/waitlist.hpp | 6 +- src/creatures/players/player.cpp | 58 +-- src/creatures/players/player.hpp | 34 +- src/creatures/players/wheel/player_wheel.cpp | 14 +- src/game/bank/bank.cpp | 8 +- src/game/bank/bank.hpp | 6 +- src/game/game.cpp | 469 +++++++++-------- src/game/game.hpp | 92 ++-- src/io/functions/iologindata_load_player.cpp | 54 +- src/io/functions/iologindata_load_player.hpp | 54 +- src/io/functions/iologindata_save_player.cpp | 30 +- src/io/functions/iologindata_save_player.hpp | 30 +- src/io/io_bosstiary.cpp | 8 +- src/io/io_bosstiary.hpp | 8 +- src/io/iobestiary.cpp | 22 +- src/io/iobestiary.hpp | 22 +- src/io/iologindata.cpp | 10 +- src/io/iologindata.hpp | 10 +- src/io/ioprey.cpp | 6 +- src/io/ioprey.hpp | 6 +- src/items/bed.cpp | 14 +- src/items/bed.hpp | 14 +- src/items/containers/mailbox/mailbox.cpp | 2 +- src/items/decay/decay.cpp | 149 +++--- src/items/decay/decay.hpp | 2 +- src/items/item.cpp | 2 +- src/items/item.hpp | 2 +- src/items/tile.cpp | 26 +- src/items/tile.hpp | 6 +- src/items/weapons/weapons.cpp | 38 +- src/items/weapons/weapons.hpp | 48 +- src/kv/README.md | 4 +- src/lua/callbacks/creaturecallback.cpp | 2 +- src/lua/callbacks/event_callback.cpp | 52 +- src/lua/callbacks/event_callback.hpp | 52 +- src/lua/creature/actions.cpp | 20 +- src/lua/creature/actions.hpp | 18 +- src/lua/creature/creatureevent.cpp | 18 +- src/lua/creature/creatureevent.hpp | 18 +- src/lua/creature/events.cpp | 50 +- src/lua/creature/events.hpp | 50 +- src/lua/creature/movement.cpp | 6 +- src/lua/creature/movement.hpp | 4 +- src/lua/creature/talkaction.cpp | 6 +- src/lua/creature/talkaction.hpp | 6 +- .../functions/core/game/bank_functions.cpp | 6 +- .../functions/core/game/game_functions.cpp | 4 +- .../functions/core/game/global_functions.cpp | 14 +- .../core/game/modal_window_functions.cpp | 2 +- .../functions/core/game/zone_functions.cpp | 2 +- .../network/network_message_functions.cpp | 4 +- .../creatures/combat/combat_functions.cpp | 2 +- .../creatures/creature_functions.cpp | 6 +- .../creatures/monster/monster_functions.cpp | 2 +- .../functions/creatures/npc/npc_functions.cpp | 6 +- .../creatures/player/guild_functions.cpp | 2 +- .../creatures/player/party_functions.cpp | 18 +- .../creatures/player/player_functions.cpp | 484 +++++++++--------- src/lua/functions/items/item_functions.cpp | 2 +- src/lua/functions/map/house_functions.cpp | 8 +- src/lua/functions/map/position_functions.cpp | 6 +- src/lua/modules/modules.cpp | 4 +- src/lua/modules/modules.hpp | 2 +- src/map/house/house.cpp | 32 +- src/map/house/house.hpp | 22 +- src/map/house/housetile.cpp | 8 +- src/map/map.cpp | 4 +- src/map/utils/astarnodes.cpp | 2 +- src/protobuf/appearances.pb.cc | 300 +++++------ src/protobuf/appearances.pb.h | 52 +- src/protobuf/appearances.proto | 2 +- src/server/network/protocol/protocolgame.cpp | 60 +-- src/server/network/protocol/protocolgame.hpp | 8 +- 88 files changed, 1465 insertions(+), 1511 deletions(-) diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index 36cdbbb3716..10c7b2ee67d 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -19,7 +19,7 @@ #include "creatures/monsters/monsters.hpp" #include "items/weapons/weapons.hpp" -int32_t Combat::getLevelFormula(const std::shared_ptr &player, const std::shared_ptr &wheelSpell, const CombatDamage &damage) const { +int32_t Combat::getLevelFormula(std::shared_ptr player, const std::shared_ptr wheelSpell, const CombatDamage &damage) const { if (!player) { return 0; } @@ -47,7 +47,7 @@ CombatDamage Combat::getCombatDamage(std::shared_ptr creature, std::sh damage.runeSpellName = runeSpellName; // Wheel of destiny std::shared_ptr wheelSpell = nullptr; - const std::shared_ptr &attackerPlayer = creature ? creature->getPlayer() : nullptr; + std::shared_ptr attackerPlayer = creature ? creature->getPlayer() : nullptr; if (attackerPlayer) { wheelSpell = attackerPlayer->wheel()->getCombatDataSpell(damage); } @@ -61,7 +61,7 @@ CombatDamage Combat::getCombatDamage(std::shared_ptr creature, std::sh int32_t min, max; if (creature->getCombatValues(min, max)) { damage.primary.value = normal_random(min, max); - } else if (const auto &player = creature->getPlayer()) { + } else if (std::shared_ptr player = creature->getPlayer()) { if (params.valueCallback) { params.valueCallback->getMinMaxValues(player, damage, params.useCharges); } else if (formulaType == COMBAT_FORMULA_LEVELMAGIC) { @@ -187,8 +187,8 @@ bool Combat::isPlayerCombat(std::shared_ptr target) { return false; } -ReturnValue Combat::canTargetCreature(const std::shared_ptr &player, const std::shared_ptr &target) { - if (!player || !target || player == target) { +ReturnValue Combat::canTargetCreature(std::shared_ptr player, std::shared_ptr target) { + if (player == target) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } @@ -260,7 +260,7 @@ ReturnValue Combat::canDoCombat(std::shared_ptr caster, std::shared_pt return RETURNVALUE_FIRSTGOUPSTAIRS; } - if (const auto &player = caster->getPlayer()) { + if (std::shared_ptr player = caster->getPlayer()) { if (player->hasFlag(PlayerFlags_t::IgnoreProtectionZone)) { return RETURNVALUE_NOERROR; } @@ -274,11 +274,7 @@ bool Combat::isInPvpZone(std::shared_ptr attacker, std::shared_ptrgetZoneType() == ZONE_PVP && target->getZoneType() == ZONE_PVP; } -bool Combat::isProtected(const std::shared_ptr &attacker, const std::shared_ptr &target) { - if (!attacker || !target) { - return true; - } - +bool Combat::isProtected(std::shared_ptr attacker, std::shared_ptr target) { uint32_t protectionLevel = g_configManager().getNumber(PROTECTION_LEVEL); if (target->getLevel() < protectionLevel || attacker->getLevel() < protectionLevel) { return true; @@ -312,7 +308,7 @@ ReturnValue Combat::canDoCombat(std::shared_ptr attacker, std::shared_ if (attacker) { const std::shared_ptr attackerMaster = attacker->getMaster(); - const auto &targetPlayer = target ? target->getPlayer() : nullptr; + auto targetPlayer = target ? target->getPlayer() : nullptr; if (targetPlayer) { if (targetPlayer->hasFlag(PlayerFlags_t::CannotBeAttacked)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; @@ -320,7 +316,7 @@ ReturnValue Combat::canDoCombat(std::shared_ptr attacker, std::shared_ const std::shared_ptr targetPlayerTile = targetPlayer->getTile(); - if (const auto &attackerPlayer = attacker->getPlayer()) { + if (const std::shared_ptr attackerPlayer = attacker->getPlayer()) { if (attackerPlayer->hasFlag(PlayerFlags_t::CannotAttackPlayer)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } @@ -343,7 +339,7 @@ ReturnValue Combat::canDoCombat(std::shared_ptr attacker, std::shared_ } if (attackerMaster) { - if (const auto &masterAttackerPlayer = attackerMaster->getPlayer()) { + if (const std::shared_ptr masterAttackerPlayer = attackerMaster->getPlayer()) { if (masterAttackerPlayer->hasFlag(PlayerFlags_t::CannotAttackPlayer)) { return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER; } @@ -368,7 +364,7 @@ ReturnValue Combat::canDoCombat(std::shared_ptr attacker, std::shared_ return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE; } - if (const auto &attackerPlayer = attacker->getPlayer()) { + if (const std::shared_ptr attackerPlayer = attacker->getPlayer()) { if (attackerPlayer->hasFlag(PlayerFlags_t::CannotAttackMonster)) { return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE; } @@ -614,10 +610,7 @@ void Combat::CombatHealthFunc(std::shared_ptr caster, std::shared_ptr< } } -CombatDamage Combat::applyImbuementElementalDamage(const std::shared_ptr &attackerPlayer, std::shared_ptr item, CombatDamage damage) { - if (!attackerPlayer) { - return damage; - } +CombatDamage Combat::applyImbuementElementalDamage(std::shared_ptr attackerPlayer, std::shared_ptr item, CombatDamage damage) { if (!item) { return damage; } @@ -669,8 +662,8 @@ void Combat::CombatManaFunc(std::shared_ptr caster, std::shared_ptr &player) { - if (!player || player->isImmuneFear()) { +bool Combat::checkFearConditionAffected(std::shared_ptr player) { + if (player->isImmuneFear()) { return false; } @@ -868,7 +861,7 @@ void Combat::addDistanceEffect(std::shared_ptr caster, const Position return; } - const auto &player = caster->getPlayer(); + std::shared_ptr player = caster->getPlayer(); if (!player) { return; } @@ -1078,7 +1071,7 @@ void Combat::CombatFunc(std::shared_ptr caster, const Position &origin } // Wheel of destiny get beam affected total - const auto &casterPlayer = caster ? caster->getPlayer() : nullptr; + std::shared_ptr casterPlayer = caster ? caster->getPlayer() : nullptr; uint8_t beamAffectedTotal = casterPlayer ? casterPlayer->wheel()->getBeamAffectedTotal(tmpDamage) : 0; uint8_t beamAffectedCurrent = 0; @@ -1170,7 +1163,7 @@ void Combat::doCombatHealth(std::shared_ptr caster, std::shared_ptrgetPlayer()->getInventoryItem(CONST_SLOT_LEFT); + if (auto playerWeapon = caster->getPlayer()->getInventoryItem(CONST_SLOT_LEFT); playerWeapon != nullptr && playerWeapon->getTier()) { double_t fatalChance = playerWeapon->getFatalChance(); double_t randomChance = uniform_random(0, 10000) / 100; @@ -1211,7 +1204,7 @@ void Combat::doCombatHealth(std::shared_ptr caster, const Position &po } // Fatal hit (onslaught) - if (const auto &playerWeapon = caster->getPlayer()->getInventoryItem(CONST_SLOT_LEFT); + if (auto playerWeapon = caster->getPlayer()->getInventoryItem(CONST_SLOT_LEFT); playerWeapon != nullptr && playerWeapon->getTier() > 0) { double_t fatalChance = playerWeapon->getFatalChance(); double_t randomChance = uniform_random(0, 10000) / 100; @@ -1464,7 +1457,7 @@ bool Combat::isValidChainTarget(std::shared_ptr caster, std::shared_pt //**********************************************************// -uint32_t ValueCallback::getMagicLevelSkill(const std::shared_ptr &player, const CombatDamage &damage) const { +uint32_t ValueCallback::getMagicLevelSkill(std::shared_ptr player, const CombatDamage &damage) const { if (!player) { return 0; } @@ -1484,7 +1477,7 @@ uint32_t ValueCallback::getMagicLevelSkill(const std::shared_ptr &player return magicLevelSkill + player->getSpecializedMagicLevel(damage.primary.type, true); } -void ValueCallback::getMinMaxValues(const std::shared_ptr &player, CombatDamage &damage, bool useCharges) const { +void ValueCallback::getMinMaxValues(std::shared_ptr player, CombatDamage &damage, bool useCharges) const { // onGetPlayerMinMaxValues(...) if (!scriptInterface->reserveScriptEnv()) { g_logger().error("[ValueCallback::getMinMaxValues - Player {} formula {}] " @@ -2075,9 +2068,9 @@ void MagicField::onStepInField(const std::shared_ptr &creature) { } } - const auto &targetPlayer = creature->getPlayer(); + std::shared_ptr targetPlayer = creature->getPlayer(); if (targetPlayer) { - const auto &attackerPlayer = g_game().getPlayerByID(ownerId); + const std::shared_ptr attackerPlayer = g_game().getPlayerByID(ownerId); if (attackerPlayer) { if (Combat::isProtected(attackerPlayer, targetPlayer)) { harmfulField = false; diff --git a/src/creatures/combat/combat.hpp b/src/creatures/combat/combat.hpp index 604f293d3f2..780b1b5eb2c 100644 --- a/src/creatures/combat/combat.hpp +++ b/src/creatures/combat/combat.hpp @@ -33,8 +33,8 @@ class ValueCallback final : public CallBack { * @param damage The combat damage information. * @return The magic level skill of the player. */ - uint32_t getMagicLevelSkill(const std::shared_ptr &player, const CombatDamage &damage) const; - void getMinMaxValues(const std::shared_ptr &player, CombatDamage &damage, bool useCharges) const; + uint32_t getMagicLevelSkill(std::shared_ptr player, const CombatDamage &damage) const; + void getMinMaxValues(std::shared_ptr player, CombatDamage &damage, bool useCharges) const; private: formulaType_t type; @@ -271,11 +271,11 @@ class Combat { static void getCombatArea(const Position ¢erPos, const Position &targetPos, const AreaCombat* area, std::forward_list> &list); static bool isInPvpZone(std::shared_ptr attacker, std::shared_ptr target); - static bool isProtected(const std::shared_ptr &attacker, const std::shared_ptr &target); + static bool isProtected(std::shared_ptr attacker, std::shared_ptr target); static bool isPlayerCombat(std::shared_ptr target); static CombatType_t ConditionToDamageType(ConditionType_t type); static ConditionType_t DamageToConditionType(CombatType_t type); - static ReturnValue canTargetCreature(const std::shared_ptr &attacker, const std::shared_ptr &target); + static ReturnValue canTargetCreature(std::shared_ptr attacker, std::shared_ptr target); static ReturnValue canDoCombat(std::shared_ptr caster, std::shared_ptr tile, bool aggressive); static ReturnValue canDoCombat(std::shared_ptr attacker, std::shared_ptr target, bool aggressive); static void postCombatEffects(std::shared_ptr caster, const Position &origin, const Position &pos, const CombatParams ¶ms); @@ -336,7 +336,7 @@ class Combat { static void CombatFunc(std::shared_ptr caster, const Position &origin, const Position &pos, const AreaCombat* area, const CombatParams ¶ms, CombatFunction func, CombatDamage* data); static void CombatHealthFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); - static CombatDamage applyImbuementElementalDamage(const std::shared_ptr &attackerPlayer, std::shared_ptr item, CombatDamage damage); + static CombatDamage applyImbuementElementalDamage(std::shared_ptr attackerPlayer, std::shared_ptr item, CombatDamage damage); static void CombatManaFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* damage); /** * @brief Checks if a fear condition can be applied to a player. @@ -352,7 +352,7 @@ class Combat { * @param player Pointer to the Player object to be checked. * @return true if the fear condition can be applied, false otherwise. */ - static bool checkFearConditionAffected(const std::shared_ptr &player); + static bool checkFearConditionAffected(std::shared_ptr player); static void CombatConditionFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); static void CombatDispelFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); static void CombatNullFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); @@ -367,7 +367,7 @@ class Combat { * @param damage The combat damage. * @return The calculated level formula. */ - int32_t getLevelFormula(const std::shared_ptr &player, const std::shared_ptr &wheelSpell, const CombatDamage &damage) const; + int32_t getLevelFormula(std::shared_ptr player, const std::shared_ptr wheelSpell, const CombatDamage &damage) const; CombatDamage getCombatDamage(std::shared_ptr creature, std::shared_ptr target) const; bool doCombatChain(std::shared_ptr caster, std::shared_ptr target, bool aggressive) const; diff --git a/src/creatures/combat/condition.cpp b/src/creatures/combat/condition.cpp index 68802f378bc..b4e09da0d58 100644 --- a/src/creatures/combat/condition.cpp +++ b/src/creatures/combat/condition.cpp @@ -437,7 +437,7 @@ void ConditionAttributes::addCondition(std::shared_ptr creature, const updateCharmChanceModifier(creature); disableDefense = conditionAttrs.disableDefense; - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { updatePercentSkills(player); updateSkills(player); updatePercentStats(player); @@ -541,7 +541,7 @@ bool ConditionAttributes::startCondition(std::shared_ptr creature) { updatePercentIncreases(creature); updateIncreases(creature); updateCharmChanceModifier(creature); - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { updatePercentSkills(player); updateSkills(player); updatePercentStats(player); @@ -551,10 +551,7 @@ bool ConditionAttributes::startCondition(std::shared_ptr creature) { return true; } -void ConditionAttributes::updatePercentStats(const std::shared_ptr &player) { - if (!player) { - return; - } +void ConditionAttributes::updatePercentStats(std::shared_ptr player) { for (int32_t i = STAT_FIRST; i <= STAT_LAST; ++i) { if (statsPercent[i] == 0) { continue; @@ -580,10 +577,7 @@ void ConditionAttributes::updatePercentStats(const std::shared_ptr &play } } -void ConditionAttributes::updateStats(const std::shared_ptr &player) { - if (!player) { - return; - } +void ConditionAttributes::updateStats(std::shared_ptr player) { bool needUpdate = false; for (int32_t i = STAT_FIRST; i <= STAT_LAST; ++i) { @@ -599,10 +593,7 @@ void ConditionAttributes::updateStats(const std::shared_ptr &player) { } } -void ConditionAttributes::updatePercentSkills(const std::shared_ptr &player) { - if (!player) { - return; - } +void ConditionAttributes::updatePercentSkills(std::shared_ptr player) { for (uint8_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { skills_t skill = static_cast(i); if (skillsPercent[skill] == 0) { @@ -614,10 +605,7 @@ void ConditionAttributes::updatePercentSkills(const std::shared_ptr &pla } } -void ConditionAttributes::updateSkills(const std::shared_ptr &player) { - if (!player) { - return; - } +void ConditionAttributes::updateSkills(std::shared_ptr player) { bool needUpdateSkills = false; for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { @@ -706,7 +694,7 @@ bool ConditionAttributes::executeCondition(std::shared_ptr creature, i } void ConditionAttributes::endCondition(std::shared_ptr creature) { - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { bool needUpdate = false; @@ -1113,14 +1101,14 @@ bool ConditionRegeneration::startCondition(std::shared_ptr creature) { return false; } - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->sendStats(); } return true; } void ConditionRegeneration::endCondition(std::shared_ptr creature) { - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->sendStats(); } } @@ -1138,7 +1126,7 @@ void ConditionRegeneration::addCondition(std::shared_ptr creature, con manaGain = conditionRegen.manaGain; } - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->sendStats(); } } @@ -1175,7 +1163,7 @@ void ConditionRegeneration::serialize(PropWriteStream &propWriteStream) { bool ConditionRegeneration::executeCondition(std::shared_ptr creature, int32_t interval) { internalHealthTicks += interval; internalManaTicks += interval; - const auto &player = creature->getPlayer(); + auto player = creature->getPlayer(); int32_t PlayerdailyStreak = 0; if (player) { PlayerdailyStreak = player->getStorageValue(STORAGEVALUE_DAILYREWARD); @@ -1257,7 +1245,7 @@ bool ConditionRegeneration::setParam(ConditionParam_t param, int32_t value) { } uint32_t ConditionRegeneration::getHealthTicks(std::shared_ptr creature) const { - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player != nullptr && isBuff) { return healthTicks / g_configManager().getFloat(RATE_SPELL_COOLDOWN); @@ -1267,7 +1255,7 @@ uint32_t ConditionRegeneration::getHealthTicks(std::shared_ptr creatur } uint32_t ConditionRegeneration::getManaTicks(std::shared_ptr creature) const { - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player != nullptr && isBuff) { return manaTicks / g_configManager().getFloat(RATE_SPELL_COOLDOWN); @@ -1288,7 +1276,7 @@ bool ConditionManaShield::startCondition(std::shared_ptr creature) { creature->setManaShield(manaShield); creature->setMaxManaShield(manaShield); - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->sendStats(); } @@ -1298,7 +1286,7 @@ bool ConditionManaShield::startCondition(std::shared_ptr creature) { void ConditionManaShield::endCondition(std::shared_ptr creature) { creature->setManaShield(0); creature->setMaxManaShield(0); - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->sendStats(); } } @@ -1313,7 +1301,7 @@ void ConditionManaShield::addCondition(std::shared_ptr creature, const creature->setManaShield(manaShield); creature->setMaxManaShield(manaShield); - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->sendStats(); } } @@ -1391,7 +1379,7 @@ void ConditionSoul::serialize(PropWriteStream &propWriteStream) { bool ConditionSoul::executeCondition(std::shared_ptr creature, int32_t interval) { internalSoulTicks += interval; - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { if (player->getZoneType() != ZONE_PROTECTION) { if (internalSoulTicks >= soulTicks) { internalSoulTicks = 0; @@ -2065,7 +2053,7 @@ void ConditionFeared::endCondition(std::shared_ptr creature) { /* * After a player is feared there's a 10 seconds before he can feared again. */ - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->setImmuneFear(); } @@ -2451,7 +2439,7 @@ void ConditionSpellCooldown::addCondition(std::shared_ptr creature, co setTicks(addCondition->getTicks()); if (subId != 0 && ticks > 0) { - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->sendSpellCooldown(subId, ticks); } @@ -2465,7 +2453,7 @@ bool ConditionSpellCooldown::startCondition(std::shared_ptr creature) } if (subId != 0 && ticks > 0) { - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->sendSpellCooldown(subId, ticks); } @@ -2482,7 +2470,7 @@ void ConditionSpellGroupCooldown::addCondition(std::shared_ptr creatur setTicks(addCondition->getTicks()); if (subId != 0 && ticks > 0) { - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->sendSpellGroupCooldown(static_cast(subId), ticks); } @@ -2496,7 +2484,7 @@ bool ConditionSpellGroupCooldown::startCondition(std::shared_ptr creat } if (subId != 0 && ticks > 0) { - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->sendSpellGroupCooldown(static_cast(subId), ticks); } diff --git a/src/creatures/combat/condition.hpp b/src/creatures/combat/condition.hpp index 82450648c17..d2704c4c49d 100644 --- a/src/creatures/combat/condition.hpp +++ b/src/creatures/combat/condition.hpp @@ -150,10 +150,10 @@ class ConditionAttributes final : public ConditionGeneric { bool disableDefense = false; - void updatePercentStats(const std::shared_ptr &player); - void updateStats(const std::shared_ptr &player); - void updatePercentSkills(const std::shared_ptr &player); - void updateSkills(const std::shared_ptr &player); + void updatePercentStats(std::shared_ptr player); + void updateStats(std::shared_ptr player); + void updatePercentSkills(std::shared_ptr player); + void updateSkills(std::shared_ptr player); void updateBuffs(std::shared_ptr creature); // 12.72 mechanics diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 255e16a8a73..46c5ba8f604 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -19,10 +19,7 @@ Spells::Spells() = default; Spells::~Spells() = default; -TalkActionResult_t Spells::playerSaySpell(const std::shared_ptr &player, std::string &words) { - if (!player) { - return TALKACTION_FAILED; - } +TalkActionResult_t Spells::playerSaySpell(std::shared_ptr player, std::string &words) { std::string str_words = words; if (player->hasCondition(CONDITION_FEARED)) { @@ -360,8 +357,8 @@ bool CombatSpell::executeCastSpell(std::shared_ptr creature, const Lua return getScriptInterface()->callFunction(2); } -bool Spell::playerSpellCheck(const std::shared_ptr &player) const { - if (!player || player->hasFlag(PlayerFlags_t::CannotUseSpells)) { +bool Spell::playerSpellCheck(std::shared_ptr player) const { + if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) { return false; } @@ -464,10 +461,7 @@ bool Spell::playerSpellCheck(const std::shared_ptr &player) const { return true; } -bool Spell::playerInstantSpellCheck(const std::shared_ptr &player, const Position &toPos) const { - if (!player) { - return false; - } +bool Spell::playerInstantSpellCheck(std::shared_ptr player, const Position &toPos) const { if (toPos.x == 0xFFFF) { return true; } @@ -507,7 +501,7 @@ bool Spell::playerInstantSpellCheck(const std::shared_ptr &player, const return true; } -bool Spell::playerRuneSpellCheck(const std::shared_ptr &player, const Position &toPos) { +bool Spell::playerRuneSpellCheck(std::shared_ptr player, const Position &toPos) { if (!playerSpellCheck(player)) { return false; } @@ -565,7 +559,7 @@ bool Spell::playerRuneSpellCheck(const std::shared_ptr &player, const Po } if (aggressive && needTarget && topVisibleCreature && player->hasSecureMode()) { - const auto &targetPlayer = topVisibleCreature->getPlayer(); + const std::shared_ptr targetPlayer = topVisibleCreature->getPlayer(); if (targetPlayer && targetPlayer != player && player->getSkullClient(targetPlayer) == SKULL_NONE && !Combat::isInPvpZone(player, targetPlayer)) { player->sendCancelMessage(RETURNVALUE_TURNSECUREMODETOATTACKUNMARKEDPLAYERS); g_game().addMagicEffect(player->getPosition(), CONST_ME_POFF); @@ -612,10 +606,7 @@ void Spell::setWheelOfDestinyBoost(WheelSpellBoost_t boost, WheelSpellGrade_t gr } } -void Spell::applyCooldownConditions(const std::shared_ptr &player) const { - if (!player) { - return; - } +void Spell::applyCooldownConditions(std::shared_ptr player) const { WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0; auto rate_cooldown = (int32_t)g_configManager().getFloat(RATE_SPELL_COOLDOWN); @@ -653,10 +644,7 @@ void Spell::applyCooldownConditions(const std::shared_ptr &player) const } } -void Spell::postCastSpell(const std::shared_ptr &player, bool finishedCast /*= true*/, bool payCost /*= true*/) const { - if (!player) { - return; - } +void Spell::postCastSpell(std::shared_ptr player, bool finishedCast /*= true*/, bool payCost /*= true*/) const { if (finishedCast) { if (!player->hasFlag(PlayerFlags_t::HasNoExhaustion)) { applyCooldownConditions(player); @@ -676,10 +664,7 @@ void Spell::postCastSpell(const std::shared_ptr &player, bool finishedCa } } -void Spell::postCastSpell(const std::shared_ptr &player, uint32_t manaCost, uint32_t soulCost) { - if (!player) { - return; - } +void Spell::postCastSpell(std::shared_ptr player, uint32_t manaCost, uint32_t soulCost) { if (manaCost > 0) { player->addManaSpent(manaCost); player->changeMana(-static_cast(manaCost)); @@ -692,10 +677,7 @@ void Spell::postCastSpell(const std::shared_ptr &player, uint32_t manaCo } } -uint32_t Spell::getManaCost(const std::shared_ptr &player) const { - if (!player) { - return 0; - } +uint32_t Spell::getManaCost(std::shared_ptr player) const { if (mana != 0) { WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); if (getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0) { @@ -725,7 +707,7 @@ uint32_t Spell::getManaCost(const std::shared_ptr &player) const { return 0; } -bool InstantSpell::playerCastInstant(const std::shared_ptr &player, std::string ¶m) { +bool InstantSpell::playerCastInstant(std::shared_ptr player, std::string ¶m) { if (!playerSpellCheck(player)) { return false; } @@ -919,11 +901,7 @@ bool InstantSpell::executeCastSpell(std::shared_ptr creature, const Lu return getScriptInterface()->callFunction(2); } -bool InstantSpell::canCast(const std::shared_ptr &player) const { - if (!player) { - return false; - } - +bool InstantSpell::canCast(std::shared_ptr player) const { if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) { return false; } @@ -945,10 +923,7 @@ bool InstantSpell::canCast(const std::shared_ptr &player) const { return false; } -ReturnValue RuneSpell::canExecuteAction(const std::shared_ptr &player, const Position &toPos) { - if (!player) { - return RETURNVALUE_NOTPOSSIBLE; - } +ReturnValue RuneSpell::canExecuteAction(std::shared_ptr player, const Position &toPos) { if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) { return RETURNVALUE_CANNOTUSETHISOBJECT; } @@ -969,7 +944,7 @@ ReturnValue RuneSpell::canExecuteAction(const std::shared_ptr &player, c return RETURNVALUE_NOERROR; } -bool RuneSpell::executeUse(const std::shared_ptr &player, std::shared_ptr item, const Position &, std::shared_ptr target, const Position &toPosition, bool isHotkey) { +bool RuneSpell::executeUse(std::shared_ptr player, std::shared_ptr item, const Position &, std::shared_ptr target, const Position &toPosition, bool isHotkey) { if (!playerRuneSpellCheck(player, toPosition)) { return false; } diff --git a/src/creatures/combat/spells.hpp b/src/creatures/combat/spells.hpp index 90dd57f5f45..f95f8aa40b3 100644 --- a/src/creatures/combat/spells.hpp +++ b/src/creatures/combat/spells.hpp @@ -44,7 +44,7 @@ class Spells final : public Scripts { std::shared_ptr getInstantSpellById(uint16_t spellId); - TalkActionResult_t playerSaySpell(const std::shared_ptr &player, std::string &words); + TalkActionResult_t playerSaySpell(std::shared_ptr player, std::string &words); static Position getCasterPosition(std::shared_ptr creature, Direction dir); @@ -73,7 +73,7 @@ class Spells final : public Scripts { constexpr auto g_spells = Spells::getInstance; -using RuneSpellFunction = std::function spell, const std::shared_ptr &player, const Position &posTo)>; +using RuneSpellFunction = std::function spell, std::shared_ptr player, const Position &posTo)>; class BaseSpell { public: @@ -135,14 +135,14 @@ class Spell : public BaseSpell { spellId = id; } - void postCastSpell(const std::shared_ptr &player, bool finishedCast = true, bool payCost = true) const; - static void postCastSpell(const std::shared_ptr &player, uint32_t manaCost, uint32_t soulCost); + void postCastSpell(std::shared_ptr player, bool finishedCast = true, bool payCost = true) const; + static void postCastSpell(std::shared_ptr player, uint32_t manaCost, uint32_t soulCost); [[nodiscard]] virtual bool isInstant() const = 0; [[nodiscard]] bool isLearnable() const { return learnable; } - uint32_t getManaCost(const std::shared_ptr &player) const; + uint32_t getManaCost(std::shared_ptr player) const; [[nodiscard]] uint32_t getSoulCost() const { return soul; } @@ -338,10 +338,10 @@ class Spell : public BaseSpell { } protected: - void applyCooldownConditions(const std::shared_ptr &player) const; - bool playerSpellCheck(const std::shared_ptr &player) const; - bool playerInstantSpellCheck(const std::shared_ptr &player, const Position &toPos) const; - bool playerRuneSpellCheck(const std::shared_ptr &player, const Position &toPos); + void applyCooldownConditions(std::shared_ptr player) const; + bool playerSpellCheck(std::shared_ptr player) const; + bool playerInstantSpellCheck(std::shared_ptr player, const Position &toPos) const; + bool playerRuneSpellCheck(std::shared_ptr player, const Position &toPos); VocSpellMap vocSpellMap; @@ -388,7 +388,7 @@ class InstantSpell final : public Script, public Spell { public: using Script::Script; - virtual bool playerCastInstant(const std::shared_ptr &player, std::string ¶m); + virtual bool playerCastInstant(std::shared_ptr player, std::string ¶m); bool castSpell(std::shared_ptr creature) override; bool castSpell(std::shared_ptr creature, std::shared_ptr target) override; @@ -429,7 +429,7 @@ class InstantSpell final : public Script, public Spell { void setBlockWalls(bool w) { checkLineOfSight = w; } - bool canCast(const std::shared_ptr &player) const; + bool canCast(std::shared_ptr player) const; bool canThrowSpell(std::shared_ptr creature, std::shared_ptr target) const; private: @@ -448,15 +448,15 @@ class RuneSpell final : public Action, public Spell { public: using Action::Action; - ReturnValue canExecuteAction(const std::shared_ptr &player, const Position &toPos) override; + ReturnValue canExecuteAction(std::shared_ptr player, const Position &toPos) override; bool hasOwnErrorHandler() override { return true; } - std::shared_ptr getTarget(const std::shared_ptr &, std::shared_ptr targetCreature, const Position &, uint8_t) const override { + std::shared_ptr getTarget(std::shared_ptr, std::shared_ptr targetCreature, const Position &, uint8_t) const override { return targetCreature; } - bool executeUse(const std::shared_ptr &player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey) override; + bool executeUse(std::shared_ptr player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey) override; bool castSpell(std::shared_ptr creature) override; bool castSpell(std::shared_ptr creature, std::shared_ptr target) override; diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 2d1695ffbc0..af985316dbe 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -173,7 +173,7 @@ void Creature::onCreatureWalk() { if (getNextStep(dir, flags)) { ReturnValue ret = g_game().internalMoveCreature(static_self_cast(), dir, flags); if (ret != RETURNVALUE_NOERROR) { - if (const auto &player = getPlayer()) { + if (std::shared_ptr player = getPlayer()) { player->sendCancelMessage(ret); player->sendCancelWalk(); } @@ -487,7 +487,7 @@ void Creature::onCreatureMove(std::shared_ptr creature, std::shared_pt handleLostSummon(configTeleportSummons); } - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { if (player->isExerciseTraining()) { player->setTraining(false); } @@ -650,7 +650,7 @@ void Creature::onDeath() { if (attacker != getCreature()) { uint64_t gainExp = getGainedExperience(attacker); - if (const auto &attackerPlayer = attacker->getPlayer()) { + if (std::shared_ptr attackerPlayer = attacker->getPlayer()) { attackerPlayer->removeAttacked(getPlayer()); Party* party = attackerPlayer->getParty(); @@ -739,7 +739,7 @@ bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared corpse->startDecaying(); bool corpses = corpse->isRewardCorpse() || (corpse->getID() == ITEM_MALE_CORPSE || corpse->getID() == ITEM_FEMALE_CORPSE); if (corpse->getContainer() && mostDamageCreature && mostDamageCreature->getPlayer() && !corpses) { - const auto &player = mostDamageCreature->getPlayer(); + auto player = mostDamageCreature->getPlayer(); std::ostringstream lootMessage; lootMessage << "Loot of " << getNameDescription() << ": " << corpse->getContainer()->getContentDescription(player->getProtocolVersion() < 1200); auto suffix = corpse->getContainer()->getAttribute(ItemAttribute_t::LOOTMESSAGE_SUFFIX); @@ -1804,7 +1804,7 @@ void Creature::iconChanged() { continue; } - const auto &player = spectator->getPlayer(); + auto player = spectator->getPlayer(); if (player) { player->sendCreatureIcon(getCreature()); } diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 69f282af754..037a8b4c651 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -386,7 +386,7 @@ void Monster::onCreatureEnter(std::shared_ptr creature) { bool Monster::isFriend(std::shared_ptr creature) const { if (isSummon() && getMaster()->getPlayer()) { - const auto &masterPlayer = getMaster()->getPlayer(); + std::shared_ptr masterPlayer = getMaster()->getPlayer(); std::shared_ptr tmpPlayer = nullptr; if (creature->getPlayer()) { @@ -620,7 +620,7 @@ BlockType_t Monster::blockHit(std::shared_ptr attacker, CombatType_t c } // Wheel of destiny - const auto &player = attacker ? attacker->getPlayer() : nullptr; + std::shared_ptr player = attacker ? attacker->getPlayer() : nullptr; if (player && player->wheel()->getInstant("Ballistic Mastery")) { elementMod -= player->wheel()->checkElementSensitiveReduction(combatType); } @@ -2048,7 +2048,7 @@ bool Monster::challengeCreature(std::shared_ptr creature, int targetCh challengeFocusDuration = targetChangeCooldown; targetChangeTicks = 0; // Wheel of destiny - const auto &player = creature ? creature->getPlayer() : nullptr; + std::shared_ptr player = creature ? creature->getPlayer() : nullptr; if (player && !player->isRemoved()) { player->wheel()->healIfBattleHealingActive(); } diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index e38d999688b..b8775ee148a 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -72,7 +72,7 @@ bool Npc::canInteract(const Position &pos, uint32_t range /* = 4 */) { void Npc::onCreatureAppear(std::shared_ptr creature, bool isLogin) { Creature::onCreatureAppear(creature, isLogin); - if (const auto &player = creature->getPlayer()) { + if (auto player = creature->getPlayer()) { onPlayerAppear(player); } @@ -102,7 +102,7 @@ void Npc::onRemoveCreature(std::shared_ptr creature, bool isLogout) { return; } - if (const auto &player = creature->getPlayer()) { + if (auto player = creature->getPlayer()) { onPlayerDisappear(player); } @@ -134,7 +134,7 @@ void Npc::onCreatureMove(std::shared_ptr creature, std::shared_ptrgetPlayer()) { + if (auto player = creature->getPlayer()) { handlePlayerMove(player, newPos); } } @@ -147,7 +147,7 @@ void Npc::manageIdle() { } } -void Npc::onPlayerAppear(const std::shared_ptr &player) { +void Npc::onPlayerAppear(std::shared_ptr player) { if (player->hasFlag(PlayerFlags_t::IgnoredByNpcs) || playerSpectators.contains(player)) { return; } @@ -155,7 +155,7 @@ void Npc::onPlayerAppear(const std::shared_ptr &player) { manageIdle(); } -void Npc::onPlayerDisappear(const std::shared_ptr &player) { +void Npc::onPlayerDisappear(std::shared_ptr player) { removePlayerInteraction(player); if (!player->hasFlag(PlayerFlags_t::IgnoredByNpcs) && playerSpectators.contains(player)) { playerSpectators.erase(player); @@ -231,7 +231,7 @@ void Npc::onThink(uint32_t interval) { } } -void Npc::onPlayerBuyItem(const std::shared_ptr &player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore, bool inBackpacks) { +void Npc::onPlayerBuyItem(std::shared_ptr player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore, bool inBackpacks) { if (player == nullptr) { g_logger().error("[Npc::onPlayerBuyItem] - Player is nullptr"); return; @@ -304,13 +304,13 @@ void Npc::onPlayerBuyItem(const std::shared_ptr &player, uint16_t itemId } } -void Npc::onPlayerSellItem(const std::shared_ptr &player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore) { +void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore) { uint64_t totalPrice = 0; onPlayerSellItem(player, itemId, subType, amount, ignore, totalPrice); } void Npc::onPlayerSellAllLoot(uint32_t playerId, uint16_t itemId, bool ignore, uint64_t totalPrice) { - const auto &player = g_game().getPlayerByID(playerId); + std::shared_ptr player = g_game().getPlayerByID(playerId); if (!player) { return; } @@ -359,7 +359,7 @@ void Npc::onPlayerSellAllLoot(uint32_t playerId, uint16_t itemId, bool ignore, u } } -void Npc::onPlayerSellItem(const std::shared_ptr &player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore, uint64_t &totalPrice, std::shared_ptr parent /*= nullptr*/) { +void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore, uint64_t &totalPrice, std::shared_ptr parent /*= nullptr*/) { if (!player) { return; } @@ -441,7 +441,7 @@ void Npc::onPlayerSellItem(const std::shared_ptr &player, uint16_t itemI } } -void Npc::onPlayerCheckItem(const std::shared_ptr &player, uint16_t itemId, uint8_t subType) { +void Npc::onPlayerCheckItem(std::shared_ptr player, uint16_t itemId, uint8_t subType) { if (!player) { return; } @@ -462,7 +462,7 @@ void Npc::onPlayerCheckItem(const std::shared_ptr &player, uint16_t item } void Npc::onPlayerCloseChannel(std::shared_ptr creature) { - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (!player) { return; } @@ -583,7 +583,7 @@ void Npc::setPlayerInteraction(uint32_t playerId, uint16_t topicId /*= 0*/) { playerInteractions[playerId] = topicId; } -void Npc::removePlayerInteraction(const std::shared_ptr &player) { +void Npc::removePlayerInteraction(std::shared_ptr player) { if (playerInteractions.contains(player->getID())) { playerInteractions.erase(player->getID()); player->closeShopWindow(true); @@ -667,7 +667,7 @@ void Npc::closeAllShopWindows() { shopPlayerMap.clear(); } -void Npc::handlePlayerMove(const std::shared_ptr &player, const Position &newPos) { +void Npc::handlePlayerMove(std::shared_ptr player, const Position &newPos) { if (!canInteract(newPos)) { removePlayerInteraction(player); } diff --git a/src/creatures/npcs/npc.hpp b/src/creatures/npcs/npc.hpp index 91544b4a31f..3af93863fc3 100644 --- a/src/creatures/npcs/npc.hpp +++ b/src/creatures/npcs/npc.hpp @@ -117,7 +117,7 @@ class Npc final : public Creature { } void setPlayerInteraction(uint32_t playerId, uint16_t topicId = 0); - void removePlayerInteraction(const std::shared_ptr &player); + void removePlayerInteraction(std::shared_ptr player); void resetPlayerInteractions(); bool isInteractingWithPlayer(uint32_t playerId) { @@ -140,11 +140,11 @@ class Npc final : public Creature { void onCreatureMove(std::shared_ptr creature, std::shared_ptr newTile, const Position &newPos, std::shared_ptr oldTile, const Position &oldPos, bool teleport) override; void onCreatureSay(std::shared_ptr creature, SpeakClasses type, const std::string &text) override; void onThink(uint32_t interval) override; - void onPlayerBuyItem(const std::shared_ptr &player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore, bool inBackpacks); + void onPlayerBuyItem(std::shared_ptr player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore, bool inBackpacks); void onPlayerSellAllLoot(uint32_t playerId, uint16_t itemid, bool ignore, uint64_t totalPrice); - void onPlayerSellItem(const std::shared_ptr &player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore); - void onPlayerSellItem(const std::shared_ptr &player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore, uint64_t &totalPrice, std::shared_ptr parent = nullptr); - void onPlayerCheckItem(const std::shared_ptr &player, uint16_t itemid, uint8_t count); + void onPlayerSellItem(std::shared_ptr player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore); + void onPlayerSellItem(std::shared_ptr player, uint16_t itemid, uint8_t count, uint16_t amount, bool ignore, uint64_t &totalPrice, std::shared_ptr parent = nullptr); + void onPlayerCheckItem(std::shared_ptr player, uint16_t itemid, uint8_t count); void onPlayerCloseChannel(std::shared_ptr creature); void onPlacedCreature() override; @@ -194,10 +194,10 @@ class Npc final : public Creature { friend class LuaScriptInterface; friend class Map; - void onPlayerAppear(const std::shared_ptr &player); - void onPlayerDisappear(const std::shared_ptr &player); + void onPlayerAppear(std::shared_ptr player); + void onPlayerDisappear(std::shared_ptr player); void manageIdle(); - void handlePlayerMove(const std::shared_ptr &player, const Position &newPos); + void handlePlayerMove(std::shared_ptr player, const Position &newPos); void loadPlayerSpectators(); }; diff --git a/src/creatures/players/grouping/party.cpp b/src/creatures/players/grouping/party.cpp index c057431ab16..5701adb6708 100644 --- a/src/creatures/players/grouping/party.cpp +++ b/src/creatures/players/grouping/party.cpp @@ -15,7 +15,7 @@ #include "lua/callbacks/event_callback.hpp" #include "lua/callbacks/events_callbacks.hpp" -Party::Party(const std::shared_ptr &initLeader) : +Party::Party(std::shared_ptr initLeader) : m_leader(initLeader) { initLeader->setParty(this); if (g_configManager().getBoolean(PARTY_AUTO_SHARE_EXPERIENCE)) { @@ -76,7 +76,7 @@ void Party::disband() { membersData.clear(); } -bool Party::leaveParty(const std::shared_ptr &player) { +bool Party::leaveParty(std::shared_ptr player) { if (!player) { return false; } @@ -162,7 +162,7 @@ bool Party::leaveParty(const std::shared_ptr &player) { return true; } -bool Party::passPartyLeadership(const std::shared_ptr &player) { +bool Party::passPartyLeadership(std::shared_ptr player) { auto leader = getLeader(); if (!leader || !player || leader == player || player->getParty() != this) { return false; @@ -415,7 +415,7 @@ const char* Party::getSharedExpReturnMessage(SharedExpStatus_t value) { } } -bool Party::setSharedExperience(const std::shared_ptr &player, bool newSharedExpActive, bool silent /*= false*/) { +bool Party::setSharedExperience(std::shared_ptr player, bool newSharedExpActive, bool silent /*= false*/) { auto leader = getLeader(); if (!player || leader != player) { return false; @@ -459,11 +459,11 @@ void Party::shareExperience(uint64_t experience, std::shared_ptr targe leader->onGainSharedExperience(shareExperience, target); } -bool Party::canUseSharedExperience(const std::shared_ptr &player) { +bool Party::canUseSharedExperience(std::shared_ptr player) { return getMemberSharedExperienceStatus(player) == SHAREDEXP_OK; } -SharedExpStatus_t Party::getMemberSharedExperienceStatus(const std::shared_ptr &player) { +SharedExpStatus_t Party::getMemberSharedExperienceStatus(std::shared_ptr player) { auto leader = getLeader(); if (!leader) { return SHAREDEXP_EMPTYPARTY; @@ -527,7 +527,7 @@ uint32_t Party::getMaxLevel() { return static_cast(std::floor((static_cast(getLowestLevel()) * 3) / 2)); } -bool Party::isPlayerActive(const std::shared_ptr &player) { +bool Party::isPlayerActive(std::shared_ptr player) { auto it = ticksMap.find(player->getID()); if (it == ticksMap.end()) { return false; @@ -556,14 +556,14 @@ SharedExpStatus_t Party::getSharedExperienceStatus() { return SHAREDEXP_OK; } -void Party::updatePlayerTicks(const std::shared_ptr &player, uint32_t points) { +void Party::updatePlayerTicks(std::shared_ptr player, uint32_t points) { if (points != 0 && !player->hasFlag(PlayerFlags_t::NotGainInFight)) { ticksMap[player->getID()] = OTSYS_TIME(); updateSharedExperience(); } } -void Party::clearPlayerPoints(const std::shared_ptr &player) { +void Party::clearPlayerPoints(std::shared_ptr player) { auto it = ticksMap.find(player->getID()); if (it != ticksMap.end()) { ticksMap.erase(it); @@ -577,13 +577,13 @@ bool Party::canOpenCorpse(uint32_t ownerId) const { return false; } - if (const auto &player = g_game().getPlayerByID(ownerId)) { + if (std::shared_ptr player = g_game().getPlayerByID(ownerId)) { return leader->getID() == ownerId || player->getParty() == this; } return false; } -void Party::showPlayerStatus(const std::shared_ptr &player, const std::shared_ptr &member, bool showStatus) { +void Party::showPlayerStatus(std::shared_ptr player, std::shared_ptr member, bool showStatus) { player->sendPartyCreatureShowStatus(member, showStatus); member->sendPartyCreatureShowStatus(player, showStatus); if (showStatus) { @@ -609,7 +609,7 @@ void Party::showPlayerStatus(const std::shared_ptr &player, const std::s } } -void Party::updatePlayerStatus(const std::shared_ptr &player) { +void Party::updatePlayerStatus(std::shared_ptr player) { auto leader = getLeader(); if (!leader) { return; @@ -632,7 +632,7 @@ void Party::updatePlayerStatus(const std::shared_ptr &player) { } } -void Party::updatePlayerStatus(const std::shared_ptr &player, const Position &oldPos, const Position &newPos) { +void Party::updatePlayerStatus(std::shared_ptr player, const Position &oldPos, const Position &newPos) { auto leader = getLeader(); if (!leader) { return; @@ -660,7 +660,7 @@ void Party::updatePlayerStatus(const std::shared_ptr &player, const Posi } } -void Party::updatePlayerHealth(const std::shared_ptr &player, std::shared_ptr target, uint8_t healthPercent) { +void Party::updatePlayerHealth(std::shared_ptr player, std::shared_ptr target, uint8_t healthPercent) { auto leader = getLeader(); if (!leader) { return; @@ -682,7 +682,7 @@ void Party::updatePlayerHealth(const std::shared_ptr &player, std::share } } -void Party::updatePlayerMana(const std::shared_ptr &player, uint8_t manaPercent) { +void Party::updatePlayerMana(std::shared_ptr player, uint8_t manaPercent) { auto leader = getLeader(); if (!leader) { return; @@ -701,7 +701,7 @@ void Party::updatePlayerMana(const std::shared_ptr &player, uint8_t mana } } -void Party::updatePlayerVocation(const std::shared_ptr &player) { +void Party::updatePlayerVocation(std::shared_ptr player) { auto leader = getLeader(); if (!leader) { return; @@ -733,7 +733,7 @@ void Party::updateTrackerAnalyzer() { leader->updatePartyTrackerAnalyzer(); } -void Party::addPlayerLoot(const std::shared_ptr &player, std::shared_ptr item) { +void Party::addPlayerLoot(std::shared_ptr player, std::shared_ptr item) { auto leader = getLeader(); if (!leader) { return; @@ -761,7 +761,7 @@ void Party::addPlayerLoot(const std::shared_ptr &player, std::shared_ptr updateTrackerAnalyzer(); } -void Party::addPlayerSupply(const std::shared_ptr &player, std::shared_ptr item) { +void Party::addPlayerSupply(std::shared_ptr player, std::shared_ptr item) { auto leader = getLeader(); if (!leader) { return; @@ -788,7 +788,7 @@ void Party::addPlayerSupply(const std::shared_ptr &player, std::shared_p updateTrackerAnalyzer(); } -void Party::addPlayerDamage(const std::shared_ptr &player, uint64_t amount) { +void Party::addPlayerDamage(std::shared_ptr player, uint64_t amount) { PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); @@ -799,7 +799,7 @@ void Party::addPlayerDamage(const std::shared_ptr &player, uint64_t amou updateTrackerAnalyzer(); } -void Party::addPlayerHealing(const std::shared_ptr &player, uint64_t amount) { +void Party::addPlayerHealing(std::shared_ptr player, uint64_t amount) { PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); diff --git a/src/creatures/players/grouping/party.hpp b/src/creatures/players/grouping/party.hpp index 6cc90d49044..d6c0e9ea6bc 100644 --- a/src/creatures/players/grouping/party.hpp +++ b/src/creatures/players/grouping/party.hpp @@ -26,7 +26,7 @@ class Party; class Party { public: - explicit Party(const std::shared_ptr &leader); + explicit Party(std::shared_ptr leader); std::shared_ptr getLeader() const { return m_leader.lock(); @@ -48,8 +48,8 @@ class Party { bool invitePlayer(const std::shared_ptr &player); bool joinParty(const std::shared_ptr &player); void revokeInvitation(const std::shared_ptr &player); - bool passPartyLeadership(const std::shared_ptr &player); - bool leaveParty(const std::shared_ptr &player); + bool passPartyLeadership(std::shared_ptr player); + bool leaveParty(std::shared_ptr player); bool removeInvite(const std::shared_ptr &player, bool removeFromPlayer = true); @@ -62,32 +62,32 @@ class Party { bool canOpenCorpse(uint32_t ownerId) const; void shareExperience(uint64_t experience, std::shared_ptr target = nullptr); - bool setSharedExperience(const std::shared_ptr &player, bool sharedExpActive, bool silent = false); + bool setSharedExperience(std::shared_ptr player, bool sharedExpActive, bool silent = false); bool isSharedExperienceActive() const { return sharedExpActive; } bool isSharedExperienceEnabled() const { return sharedExpEnabled; } - bool canUseSharedExperience(const std::shared_ptr &player); - SharedExpStatus_t getMemberSharedExperienceStatus(const std::shared_ptr &player); + bool canUseSharedExperience(std::shared_ptr player); + SharedExpStatus_t getMemberSharedExperienceStatus(std::shared_ptr player); void updateSharedExperience(); - void updatePlayerTicks(const std::shared_ptr &player, uint32_t points); - void clearPlayerPoints(const std::shared_ptr &player); + void updatePlayerTicks(std::shared_ptr player, uint32_t points); + void clearPlayerPoints(std::shared_ptr player); - void showPlayerStatus(const std::shared_ptr &player, const std::shared_ptr &member, bool showStatus); - void updatePlayerStatus(const std::shared_ptr &player); - void updatePlayerStatus(const std::shared_ptr &player, const Position &oldPos, const Position &newPos); - void updatePlayerHealth(const std::shared_ptr &player, std::shared_ptr target, uint8_t healthPercent); - void updatePlayerMana(const std::shared_ptr &player, uint8_t manaPercent); - void updatePlayerVocation(const std::shared_ptr &player); + void showPlayerStatus(std::shared_ptr player, std::shared_ptr member, bool showStatus); + void updatePlayerStatus(std::shared_ptr player); + void updatePlayerStatus(std::shared_ptr player, const Position &oldPos, const Position &newPos); + void updatePlayerHealth(std::shared_ptr player, std::shared_ptr target, uint8_t healthPercent); + void updatePlayerMana(std::shared_ptr player, uint8_t manaPercent); + void updatePlayerVocation(std::shared_ptr player); void updateTrackerAnalyzer(); - void addPlayerLoot(const std::shared_ptr &player, std::shared_ptr item); - void addPlayerSupply(const std::shared_ptr &player, std::shared_ptr item); - void addPlayerDamage(const std::shared_ptr &player, uint64_t amount); - void addPlayerHealing(const std::shared_ptr &player, uint64_t amount); + void addPlayerLoot(std::shared_ptr player, std::shared_ptr item); + void addPlayerSupply(std::shared_ptr player, std::shared_ptr item); + void addPlayerDamage(std::shared_ptr player, uint64_t amount); + void addPlayerHealing(std::shared_ptr player, uint64_t amount); void switchAnalyzerPriceType(); void resetAnalyzer(); void reloadPrices(); @@ -115,7 +115,7 @@ class Party { private: const char* getSharedExpReturnMessage(SharedExpStatus_t value); - bool isPlayerActive(const std::shared_ptr &player); + bool isPlayerActive(std::shared_ptr player); SharedExpStatus_t getSharedExperienceStatus(); uint32_t getHighestLevel(); uint32_t getLowestLevel(); diff --git a/src/creatures/players/imbuements/imbuements.cpp b/src/creatures/players/imbuements/imbuements.cpp index 1c2d1c00ea9..2d27d15bb3a 100644 --- a/src/creatures/players/imbuements/imbuements.cpp +++ b/src/creatures/players/imbuements/imbuements.cpp @@ -336,7 +336,7 @@ CategoryImbuement* Imbuements::getCategoryByID(uint16_t id) { return categoryImbuements != categoriesImbuement.end() ? &*categoryImbuements : nullptr; } -std::vector Imbuements::getImbuements(const std::shared_ptr &player, std::shared_ptr item) { +std::vector Imbuements::getImbuements(std::shared_ptr player, std::shared_ptr item) { std::vector imbuements; for (auto &[key, value] : imbuementMap) { diff --git a/src/creatures/players/imbuements/imbuements.hpp b/src/creatures/players/imbuements/imbuements.hpp index ee9bd3d7db3..69c5219a0d8 100644 --- a/src/creatures/players/imbuements/imbuements.hpp +++ b/src/creatures/players/imbuements/imbuements.hpp @@ -60,7 +60,7 @@ class Imbuements { BaseImbuement* getBaseByID(uint16_t id); CategoryImbuement* getCategoryByID(uint16_t id); - std::vector getImbuements(const std::shared_ptr &player, std::shared_ptr item); + std::vector getImbuements(std::shared_ptr player, std::shared_ptr item); protected: friend class Imbuement; diff --git a/src/creatures/players/management/waitlist.cpp b/src/creatures/players/management/waitlist.cpp index ab4e4d80d80..ff1ad2b00bd 100644 --- a/src/creatures/players/management/waitlist.cpp +++ b/src/creatures/players/management/waitlist.cpp @@ -59,7 +59,7 @@ std::size_t WaitingList::getTime(std::size_t slot) { } } -bool WaitingList::clientLogin(const std::shared_ptr &player) { +bool WaitingList::clientLogin(std::shared_ptr player) { if (player->hasFlag(PlayerFlags_t::CanAlwaysLogin) || player->getAccountType() >= account::ACCOUNT_TYPE_GAMEMASTER) { return true; } @@ -85,7 +85,7 @@ bool WaitingList::clientLogin(const std::shared_ptr &player) { return false; } -void WaitingList::addPlayerToList(const std::shared_ptr &player) { +void WaitingList::addPlayerToList(std::shared_ptr player) { auto it = info->playerReferences.find(player->getGUID()); if (it != info->playerReferences.end()) { std::size_t slot; @@ -111,7 +111,7 @@ void WaitingList::addPlayerToList(const std::shared_ptr &player) { } } -std::size_t WaitingList::getClientSlot(const std::shared_ptr &player) { +std::size_t WaitingList::getClientSlot(std::shared_ptr player) { auto it = info->playerReferences.find(player->getGUID()); if (it == info->playerReferences.end()) { return 0; diff --git a/src/creatures/players/management/waitlist.hpp b/src/creatures/players/management/waitlist.hpp index 11e1e3d64a7..28b65c7cad0 100644 --- a/src/creatures/players/management/waitlist.hpp +++ b/src/creatures/players/management/waitlist.hpp @@ -34,13 +34,13 @@ class WaitingList { public: WaitingList(); static WaitingList &getInstance(); - bool clientLogin(const std::shared_ptr &player); - std::size_t getClientSlot(const std::shared_ptr &player); + bool clientLogin(std::shared_ptr player); + std::size_t getClientSlot(std::shared_ptr player); static std::size_t getTime(std::size_t slot); private: void cleanupList(WaitList &list); std::size_t getTimeout(std::size_t slot); - void addPlayerToList(const std::shared_ptr &player); + void addPlayerToList(std::shared_ptr player); std::unique_ptr info; }; diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 2fe1ebcdc6e..aa9180921f7 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -917,7 +917,7 @@ bool Player::canWalkthrough(std::shared_ptr creature) { return true; } - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); std::shared_ptr monster = creature->getMonster(); std::shared_ptr npc = creature->getNpc(); if (monster) { @@ -938,7 +938,7 @@ bool Player::canWalkthrough(std::shared_ptr creature) { return false; } - const auto &thisPlayer = getPlayer(); + std::shared_ptr thisPlayer = getPlayer(); if ((OTSYS_TIME() - lastWalkthroughAttempt) > 2000) { thisPlayer->setLastWalkthroughAttempt(OTSYS_TIME()); return false; @@ -973,7 +973,7 @@ bool Player::canWalkthroughEx(std::shared_ptr creature) { return true; } - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); std::shared_ptr npc = creature->getNpc(); if (player) { std::shared_ptr playerTile = player->getTile(); @@ -2539,7 +2539,7 @@ void Player::death(std::shared_ptr lastHitCreature) { for (const auto &it : damageMap) { CountBlock_t cb = it.second; if ((OTSYS_TIME() - cb.ticks) <= inFightTicks) { - const auto &damageDealer = g_game().getPlayerByID(it.first); + std::shared_ptr damageDealer = g_game().getPlayerByID(it.first); if (damageDealer) { playerDmg += cb.total; sumLevels += damageDealer->getLevel(); @@ -2764,7 +2764,7 @@ bool Player::spawn() { continue; } - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendCreatureAppear(static_self_cast(), pos, true); } @@ -2808,10 +2808,10 @@ void Player::despawn() { continue; } - if (const auto &player = spectator->getPlayer()) { + if (const auto player = spectator->getPlayer()) { oldStackPosVector.push_back(player->canSeeCreature(static_self_cast()) ? tile->getStackposOfCreature(player, getPlayer()) : -1); } - if (const auto &player = spectator->getPlayer()) { + if (auto player = spectator->getPlayer()) { player->sendRemoveTileThing(tile->getPosition(), oldStackPosVector[i++]); } @@ -2901,7 +2901,7 @@ void Player::removePlayer(bool displayEffect, bool forced /*= true*/) { } } -void Player::notifyStatusChange(const std::shared_ptr &loginPlayer, VipStatus_t status, bool message) { +void Player::notifyStatusChange(std::shared_ptr loginPlayer, VipStatus_t status, bool message) { if (!client) { return; } @@ -4253,7 +4253,7 @@ void Player::doAttacking(uint32_t) { uint64_t Player::getGainedExperience(std::shared_ptr attacker) const { if (g_configManager().getBoolean(EXPERIENCE_FROM_PLAYERS)) { - const auto &attackerPlayer = attacker->getPlayer(); + auto attackerPlayer = attacker->getPlayer(); if (attackerPlayer && attackerPlayer.get() != this && skillLoss && std::abs(static_cast(attackerPlayer->getLevel() - level)) <= g_configManager().getNumber(EXP_FROM_PLAYERS_LEVEL_RANGE)) { return std::max(0, std::floor(getLostExperience() * getDamageRatio(attacker) * 0.75)); } @@ -4469,7 +4469,7 @@ void Player::onAttackedCreature(std::shared_ptr target) { return; } - const auto &targetPlayer = target->getPlayer(); + auto targetPlayer = target->getPlayer(); if (targetPlayer && !isPartner(targetPlayer) && !isGuildMate(targetPlayer)) { if (!pzLocked && g_game().getWorldType() == WORLD_TYPE_PVP_ENFORCED) { pzLocked = true; @@ -4546,7 +4546,7 @@ void Player::onTargetCreatureGainHealth(std::shared_ptr target, int32_ if (isPartner(tmpPlayer) && (tmpPlayer != getPlayer())) { tmpPlayer = target->getPlayer(); } else if (std::shared_ptr targetMaster = target->getMaster()) { - if (const auto &targetMasterPlayer = targetMaster->getPlayer()) { + if (std::shared_ptr targetMasterPlayer = targetMaster->getPlayer()) { tmpPlayer = targetMasterPlayer; } } @@ -4566,7 +4566,7 @@ bool Player::onKilledCreature(std::shared_ptr target, bool lastHit /* Creature::onKilledCreature(target, lastHit); - if (const auto &targetPlayer = target->getPlayer()) { + if (auto targetPlayer = target->getPlayer()) { if (targetPlayer && targetPlayer->getZoneType() == ZONE_PVP) { targetPlayer->setDropLoot(false); targetPlayer->setSkillLoss(false); @@ -4576,7 +4576,7 @@ bool Player::onKilledCreature(std::shared_ptr target, bool lastHit /* for (auto &kill : targetPlayer->unjustifiedKills) { if (kill.target == getGUID() && kill.unavenged) { kill.unavenged = false; - const auto &it = attackedSet.find(targetPlayer->guid); + auto it = attackedSet.find(targetPlayer->guid); attackedSet.erase(it); break; } @@ -4596,7 +4596,7 @@ bool Player::onKilledCreature(std::shared_ptr target, bool lastHit /* } else if (std::shared_ptr monster = target->getMonster()) { // Access to the monster's map damage to check if the player attacked it for (auto [playerId, damage] : monster->getDamageMap()) { - const auto &damagePlayer = g_game().getPlayerByID(playerId); + auto damagePlayer = g_game().getPlayerByID(playerId); if (!damagePlayer) { continue; } @@ -4924,7 +4924,7 @@ Skulls_t Player::getSkullClient(std::shared_ptr creature) { return SKULL_NONE; } - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player && player->getSkull() == SKULL_NONE) { if (player.get() == this) { for (const auto &kill : unjustifiedKills) { @@ -4949,7 +4949,7 @@ Skulls_t Player::getSkullClient(std::shared_ptr creature) { return Creature::getSkullClient(creature); } -bool Player::hasKilled(const std::shared_ptr &player) const { +bool Player::hasKilled(std::shared_ptr player) const { for (const auto &kill : unjustifiedKills) { if (kill.target == player->getGUID() && (time(nullptr) - kill.time) < g_configManager().getNumber(ORANGE_SKULL_DURATION) * 24 * 60 * 60 && kill.unavenged) { return true; @@ -4959,7 +4959,7 @@ bool Player::hasKilled(const std::shared_ptr &player) const { return false; } -bool Player::hasAttacked(const std::shared_ptr &attacked) const { +bool Player::hasAttacked(std::shared_ptr attacked) const { if (hasFlag(PlayerFlags_t::NotGainInFight) || !attacked) { return false; } @@ -4967,7 +4967,7 @@ bool Player::hasAttacked(const std::shared_ptr &attacked) const { return attackedSet.find(attacked->guid) != attackedSet.end(); } -void Player::addAttacked(const std::shared_ptr &attacked) { +void Player::addAttacked(std::shared_ptr attacked) { if (hasFlag(PlayerFlags_t::NotGainInFight) || !attacked || attacked == getPlayer()) { return; } @@ -4975,7 +4975,7 @@ void Player::addAttacked(const std::shared_ptr &attacked) { attackedSet.insert(attacked->guid); } -void Player::removeAttacked(const std::shared_ptr &attacked) { +void Player::removeAttacked(std::shared_ptr attacked) { if (!attacked || attacked == getPlayer()) { return; } @@ -4990,7 +4990,7 @@ void Player::clearAttacked() { attackedSet.clear(); } -void Player::addUnjustifiedDead(const std::shared_ptr &attacked) { +void Player::addUnjustifiedDead(std::shared_ptr attacked) { if (hasFlag(PlayerFlags_t::NotGainInFight) || attacked == getPlayer() || g_game().getWorldType() == WORLD_TYPE_PVP_ENFORCED) { return; } @@ -5112,7 +5112,7 @@ bool Player::hasLearnedInstantSpell(const std::string &spellName) const { return false; } -bool Player::isInWar(const std::shared_ptr &player) const { +bool Player::isInWar(std::shared_ptr player) const { if (!player || !guild) { return false; } @@ -5391,7 +5391,7 @@ void Player::setTransferableTibiaCoins(int32_t v) { coinTransferableBalance = v; } -PartyShields_t Player::getPartyShield(const std::shared_ptr &player) { +PartyShields_t Player::getPartyShield(std::shared_ptr player) { if (!player) { return SHIELD_NONE; } @@ -5445,28 +5445,28 @@ PartyShields_t Player::getPartyShield(const std::shared_ptr &player) { return SHIELD_NONE; } -bool Player::isInviting(const std::shared_ptr &player) const { +bool Player::isInviting(std::shared_ptr player) const { if (!player || !party || party->getLeader().get() != this) { return false; } return party->isPlayerInvited(player); } -bool Player::isPartner(const std::shared_ptr &player) const { +bool Player::isPartner(std::shared_ptr player) const { if (!player || !party || player.get() == this) { return false; } return party == player->party; } -bool Player::isGuildMate(const std::shared_ptr &player) const { +bool Player::isGuildMate(std::shared_ptr player) const { if (!player || !guild) { return false; } return guild == player->guild; } -void Player::sendPlayerPartyIcons(const std::shared_ptr &player) { +void Player::sendPlayerPartyIcons(std::shared_ptr player) { sendPartyCreatureShield(player); sendPartyCreatureSkull(player); } @@ -5492,7 +5492,7 @@ void Player::clearPartyInvitations() { invitePartyList.clear(); } -GuildEmblems_t Player::getGuildEmblem(const std::shared_ptr &player) const { +GuildEmblems_t Player::getGuildEmblem(std::shared_ptr player) const { if (!player) { return GUILDEMBLEM_NONE; } @@ -6798,7 +6798,7 @@ bool Player::saySpell( int32_t valueEmote = 0; // Send to client for (std::shared_ptr spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { valueEmote = tmpPlayer->getStorageValue(STORAGEVALUE_EMOTE); if (!ghostMode || tmpPlayer->canSeeCreature(static_self_cast())) { if (valueEmote == 1) { @@ -6812,7 +6812,7 @@ bool Player::saySpell( // Execute lua event method for (std::shared_ptr spectator : spectators) { - const auto &tmpPlayer = spectator->getPlayer(); + auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; } diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 4daadb070fb..7ff7e02a505 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -257,7 +257,7 @@ class Player final : public Creature, public Cylinder, public Bankable { guildRank = newGuildRank; } - bool isGuildMate(const std::shared_ptr &player) const; + bool isGuildMate(std::shared_ptr player) const; [[nodiscard]] const std::string &getGuildNick() const { return guildNick; @@ -266,7 +266,7 @@ class Player final : public Creature, public Cylinder, public Bankable { guildNick = nick; } - bool isInWar(const std::shared_ptr &player) const; + bool isInWar(std::shared_ptr player) const; bool isInWarList(uint32_t guild_id) const; void setLastWalkthroughAttempt(int64_t walkthroughAttempt) { @@ -383,17 +383,17 @@ class Player final : public Creature, public Cylinder, public Bankable { int32_t getReflectFlat(CombatType_t combat, bool useCharges = false) const override; - PartyShields_t getPartyShield(const std::shared_ptr &player); - bool isInviting(const std::shared_ptr &player) const; - bool isPartner(const std::shared_ptr &player) const; - void sendPlayerPartyIcons(const std::shared_ptr &player); + PartyShields_t getPartyShield(std::shared_ptr player); + bool isInviting(std::shared_ptr player) const; + bool isPartner(std::shared_ptr player) const; + void sendPlayerPartyIcons(std::shared_ptr player); bool addPartyInvitation(Party* party); void removePartyInvitation(Party* party); void clearPartyInvitations(); void sendUnjustifiedPoints(); - GuildEmblems_t getGuildEmblem(const std::shared_ptr &player) const; + GuildEmblems_t getGuildEmblem(std::shared_ptr player) const; uint64_t getSpentMana() const { return manaSpent; @@ -787,7 +787,7 @@ class Player final : public Creature, public Cylinder, public Bankable { } // V.I.P. functions - void notifyStatusChange(const std::shared_ptr &player, VipStatus_t status, bool message = true); + void notifyStatusChange(std::shared_ptr player, VipStatus_t status, bool message = true); bool removeVIP(uint32_t vipGuid); bool addVIP(uint32_t vipGuid, const std::string &vipName, VipStatus_t status); bool addVIPInternal(uint32_t vipGuid); @@ -919,11 +919,11 @@ class Player final : public Creature, public Cylinder, public Bankable { skullTicks = ticks; } - bool hasAttacked(const std::shared_ptr &attacked) const; - void addAttacked(const std::shared_ptr &attacked); - void removeAttacked(const std::shared_ptr &attacked); + bool hasAttacked(std::shared_ptr attacked) const; + void addAttacked(std::shared_ptr attacked); + void removeAttacked(std::shared_ptr attacked); void clearAttacked(); - void addUnjustifiedDead(const std::shared_ptr &attacked); + void addUnjustifiedDead(std::shared_ptr attacked); void sendCreatureEmblem(std::shared_ptr creature) const { if (client) { client->sendCreatureEmblem(creature); @@ -952,7 +952,7 @@ class Player final : public Creature, public Cylinder, public Bankable { bool canLogout(); - bool hasKilled(const std::shared_ptr &player) const; + bool hasKilled(std::shared_ptr player) const; size_t getMaxVIPEntries() const; size_t getMaxDepotItems() const; @@ -1042,7 +1042,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->reloadCreature(creature); } } - void sendPrivateMessage(const std::shared_ptr &speaker, SpeakClasses type, const std::string &text) { + void sendPrivateMessage(std::shared_ptr speaker, SpeakClasses type, const std::string &text) { if (client) { client->sendPrivateMessage(speaker, type, text); } @@ -1277,7 +1277,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendPartyCreatureHealth(creature, healthPercent); } } - void sendPartyPlayerMana(const std::shared_ptr &player, uint8_t manaPercent) const { + void sendPartyPlayerMana(std::shared_ptr player, uint8_t manaPercent) const { if (client) { client->sendPartyPlayerMana(player, manaPercent); } @@ -1287,12 +1287,12 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendPartyCreatureShowStatus(creature, showStatus); } } - void sendPartyPlayerVocation(const std::shared_ptr &player) const { + void sendPartyPlayerVocation(std::shared_ptr player) const { if (client) { client->sendPartyPlayerVocation(player); } } - void sendPlayerVocation(const std::shared_ptr &player) const { + void sendPlayerVocation(std::shared_ptr player) const { if (client) { client->sendPlayerVocation(player); } diff --git a/src/creatures/players/wheel/player_wheel.cpp b/src/creatures/players/wheel/player_wheel.cpp index 08b050d0911..bdf64fc63b0 100644 --- a/src/creatures/players/wheel/player_wheel.cpp +++ b/src/creatures/players/wheel/player_wheel.cpp @@ -632,7 +632,7 @@ bool PlayerWheel::getSpellAdditionalArea(const std::string &spellName) const { return false; } - const auto &vocationEnum = getPlayerVocationEnum(); + auto vocationEnum = getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { return checkSpellArea(g_game().getIOWheel()->getWheelBonusData().spells.knight, spellName, stage); } else if (vocationEnum == Vocation_t::VOCATION_PALADIN_CIP) { @@ -652,7 +652,7 @@ int PlayerWheel::getSpellAdditionalTarget(const std::string &spellName) const { return 0; } - const auto &vocationEnum = getPlayerVocationEnum(); + auto vocationEnum = getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { return checkSpellAdditionalTarget(g_game().getIOWheel()->getWheelBonusData().spells.knight, spellName, stage); } else if (vocationEnum == Vocation_t::VOCATION_PALADIN_CIP) { @@ -672,7 +672,7 @@ int PlayerWheel::getSpellAdditionalDuration(const std::string &spellName) const return 0; } - const auto &vocationEnum = getPlayerVocationEnum(); + auto vocationEnum = getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { return checkSpellAdditionalDuration(g_game().getIOWheel()->getWheelBonusData().spells.knight, spellName, stage); } else if (vocationEnum == Vocation_t::VOCATION_PALADIN_CIP) { @@ -1376,7 +1376,7 @@ void PlayerWheel::printPlayerWheelMethodsBonusData(const PlayerWheelMethodsBonus void PlayerWheel::loadDedicationAndConvictionPerks() { using VocationBonusFunction = std::function &, uint16_t, uint8_t, PlayerWheelMethodsBonusData &)>; auto &wheelFunctions = g_game().getIOWheel()->getWheelMapFunctions(); - const auto &vocationCipId = getPlayerVocationEnum(); + auto vocationCipId = getPlayerVocationEnum(); if (vocationCipId < VOCATION_KNIGHT_CIP || vocationCipId > VOCATION_DRUID_CIP) { return; } @@ -1421,7 +1421,7 @@ void PlayerWheel::loadRevelationPerks() { m_playerBonusData.stats.healing += statsHealing; auto redStageValue = static_cast(redStageEnum); - const auto &vocationEnum = getPlayerVocationEnum(); + auto vocationEnum = getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_DRUID_CIP) { m_playerBonusData.stages.blessingOfTheGrove = redStageValue; } else if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { @@ -1448,7 +1448,7 @@ void PlayerWheel::loadRevelationPerks() { m_playerBonusData.stats.healing += statsHealing; auto purpleStage = static_cast(purpleStageEnum); - const auto &vocationEnum = getPlayerVocationEnum(); + auto vocationEnum = getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { m_playerBonusData.avatar.steel = purpleStage; for (uint8_t i = 0; i < purpleStage; ++i) { @@ -1479,7 +1479,7 @@ void PlayerWheel::loadRevelationPerks() { m_playerBonusData.stats.healing += statsHealing; auto blueStage = static_cast(blueStageEnum); - const auto &vocationEnum = getPlayerVocationEnum(); + auto vocationEnum = getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { m_playerBonusData.stages.combatMastery = blueStage; } else if (vocationEnum == Vocation_t::VOCATION_SORCERER_CIP) { diff --git a/src/game/bank/bank.cpp b/src/game/bank/bank.cpp index d7b3d67b224..56e06150bdb 100644 --- a/src/game/bank/bank.cpp +++ b/src/game/bank/bank.cpp @@ -23,7 +23,7 @@ Bank::~Bank() { if (bankable == nullptr || bankable->isOnline()) { return; } - const auto &player = bankable->getPlayer(); + std::shared_ptr player = bankable->getPlayer(); if (player && !player->isOnline()) { IOLoginData::savePlayer(player); @@ -93,7 +93,7 @@ bool Bank::transferTo(const std::shared_ptr destination, uint64_t amount) return false; } if (destinationBankable->getPlayer() != nullptr) { - const auto &player = bankable->getPlayer(); + auto player = bankable->getPlayer(); auto name = asLowerCaseString(player->getName()); replaceString(name, " ", ""); if (deniedNames.contains(name)) { @@ -111,7 +111,7 @@ bool Bank::transferTo(const std::shared_ptr destination, uint64_t amount) return debit(amount) && destination->credit(amount); } -bool Bank::withdraw(const std::shared_ptr &player, uint64_t amount) { +bool Bank::withdraw(std::shared_ptr player, uint64_t amount) { if (!debit(amount)) { return false; } @@ -127,7 +127,7 @@ bool Bank::deposit(const std::shared_ptr destination) { if (bankable->getPlayer() == nullptr) { return false; } - const auto &amount = bankable->getPlayer()->getMoney(); + auto amount = bankable->getPlayer()->getMoney(); return deposit(destination, amount); } diff --git a/src/game/bank/bank.hpp b/src/game/bank/bank.hpp index 792e5cc6dbb..b04a02a9998 100644 --- a/src/game/bank/bank.hpp +++ b/src/game/bank/bank.hpp @@ -43,13 +43,13 @@ class Bank : public SharedObject { uint64_t balance(); bool hasBalance(uint64_t amount); bool transferTo(const std::shared_ptr destination, uint64_t amount); - bool withdraw(const std::shared_ptr &player, uint64_t amount); + bool withdraw(std::shared_ptr player, uint64_t amount); bool deposit(const std::shared_ptr destination); bool deposit(const std::shared_ptr destination, uint64_t amount); private: std::shared_ptr getBankable() const { - return m_bankable; + return m_bankable.lock(); } - std::shared_ptr m_bankable; + std::weak_ptr m_bankable; }; diff --git a/src/game/game.cpp b/src/game/game.cpp index 7bd6c196e88..1b84a7ffc3f 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -91,7 +91,7 @@ namespace InternalGame { } } - bool playerCanUseItemOnHouseTile(const std::shared_ptr &player, std::shared_ptr item) { + bool playerCanUseItemOnHouseTile(std::shared_ptr player, std::shared_ptr item) { if (!player || !item) { return false; } @@ -124,7 +124,7 @@ namespace InternalGame { return true; } - bool playerCanUseItemWithOnHouseTile(const std::shared_ptr &player, std::shared_ptr item, const Position &toPos, int toStackPos, int toItemId) { + bool playerCanUseItemWithOnHouseTile(std::shared_ptr player, std::shared_ptr item, const Position &toPos, int toStackPos, int toItemId) { if (!player || !item) { return false; } @@ -499,7 +499,7 @@ void Game::loadMap(const std::string &path, const Position &pos) { map.loadMap(path, false, false, false, false, pos); } -std::shared_ptr Game::internalGetCylinder(const std::shared_ptr &player, const Position &pos) { +std::shared_ptr Game::internalGetCylinder(std::shared_ptr player, const Position &pos) { if (pos.x != 0xFFFF) { return map.getTile(pos); } @@ -514,7 +514,7 @@ std::shared_ptr Game::internalGetCylinder(const std::shared_ptr Game::internalGetThing(const std::shared_ptr &player, const Position &pos, int32_t index, uint32_t itemId, StackPosType_t type) { +std::shared_ptr Game::internalGetThing(std::shared_ptr player, const Position &pos, int32_t index, uint32_t itemId, StackPosType_t type) { if (pos.x != 0xFFFF) { std::shared_ptr tile = map.getTile(pos); if (!tile) { @@ -661,7 +661,7 @@ void Game::internalGetPosition(std::shared_ptr item, Position &pos, uint8_ std::shared_ptr topParent = item->getTopParent(); if (topParent) { - if (const auto &player = std::dynamic_pointer_cast(topParent)) { + if (std::shared_ptr player = std::dynamic_pointer_cast(topParent)) { pos.x = 0xFFFF; std::shared_ptr container = std::dynamic_pointer_cast(item->getParent()); @@ -783,7 +783,7 @@ std::shared_ptr Game::getPlayerByName(const std::string &s, bool loadTmp if (!loadTmp) { return nullptr; } - const auto &tmpPlayer = std::make_shared(nullptr); + std::shared_ptr tmpPlayer = std::make_shared(nullptr); if (!IOLoginData::loadPlayerByName(tmpPlayer, s)) { return nullptr; @@ -794,7 +794,7 @@ std::shared_ptr Game::getPlayerByName(const std::string &s, bool loadTmp return it->second.lock(); } -std::shared_ptr Game::getPlayerByGUID(const uint32_t &guid, bool loadTmp /* = false */) { +std::shared_ptr Game::getPlayerByGUID(const uint32_t &guid) { if (guid == 0) { return nullptr; } @@ -803,16 +803,7 @@ std::shared_ptr Game::getPlayerByGUID(const uint32_t &guid, bool loadTmp return it.second; } } - if (!loadTmp) { - return nullptr; - } - - const auto &tmpPlayer = std::make_shared(nullptr); - if (!IOLoginData::loadPlayerById(tmpPlayer, guid)) { - return nullptr; - } - tmpPlayer->setOnline(false); - return tmpPlayer; + return nullptr; } ReturnValue Game::getPlayerByNameWildcard(const std::string &s, std::shared_ptr &player) { @@ -883,7 +874,7 @@ bool Game::placeCreature(std::shared_ptr creature, const Position &pos SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true); for (std::shared_ptr spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendCreatureAppear(creature, creature->getPosition(), true); hasPlayerSpectators = true; } @@ -911,7 +902,7 @@ bool Game::removeCreature(std::shared_ptr creature, bool isLogout /* = SpectatorHashSet spectators; map.getSpectators(spectators, tile->getPosition(), true); for (auto spectator : spectators) { - if (const auto &player = spectator->getPlayer()) { + if (auto player = spectator->getPlayer()) { oldStackPosVector.push_back(player->canSeeCreature(creature) ? tile->getStackposOfCreature(player, creature) : -1); } } @@ -923,7 +914,7 @@ bool Game::removeCreature(std::shared_ptr creature, bool isLogout /* = // send to client size_t i = 0; for (auto spectator : spectators) { - if (const auto &player = spectator->getPlayer()) { + if (auto player = spectator->getPlayer()) { player->sendRemoveTileThing(tilePosition, oldStackPosVector[i++]); } } @@ -951,7 +942,7 @@ bool Game::removeCreature(std::shared_ptr creature, bool isLogout /* = } if (creature->getPlayer() && isLogout) { - const auto &it = teamFinderMap.find(creature->getPlayer()->getGUID()); + auto it = teamFinderMap.find(creature->getPlayer()->getGUID()); if (it != teamFinderMap.end()) { teamFinderMap.erase(it); } @@ -969,7 +960,7 @@ void Game::executeDeath(uint32_t creatureId) { } void Game::playerTeleport(uint32_t playerId, const Position &newPosition) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->hasFlag(PlayerFlags_t::CanMapClickTeleport)) { return; } @@ -980,7 +971,7 @@ void Game::playerTeleport(uint32_t playerId, const Position &newPosition) { } } -void Game::playerInspectItem(const std::shared_ptr &player, const Position &pos) { +void Game::playerInspectItem(std::shared_ptr player, const Position &pos) { std::shared_ptr thing = internalGetThing(player, pos, 0, 0, STACKPOS_TOPDOWN_ITEM); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); @@ -996,7 +987,7 @@ void Game::playerInspectItem(const std::shared_ptr &player, const Positi player->sendItemInspection(item->getID(), static_cast(item->getItemCount()), item, false); } -void Game::playerInspectItem(const std::shared_ptr &player, uint16_t itemId, uint8_t itemCount, bool cyclopedia) { +void Game::playerInspectItem(std::shared_ptr player, uint16_t itemId, uint8_t itemCount, bool cyclopedia) { player->sendItemInspection(itemId, itemCount, nullptr, cyclopedia); } @@ -1050,7 +1041,7 @@ FILELOADER_ERRORS Game::loadAppearanceProtobuf(const std::string &file) { } void Game::playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -1112,7 +1103,7 @@ void Game::playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t } void Game::playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, const Position &movingCreatureOrigPos, const Position &toPos) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -1131,7 +1122,7 @@ void Game::playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, playerMoveCreature(player, movingCreature, movingCreatureOrigPos, toTile); } -void Game::playerMoveCreature(const std::shared_ptr &player, std::shared_ptr movingCreature, const Position &movingCreatureOrigPos, std::shared_ptr toTile) { +void Game::playerMoveCreature(std::shared_ptr player, std::shared_ptr movingCreature, const Position &movingCreatureOrigPos, std::shared_ptr toTile) { if (!player->canDoAction()) { uint32_t delay = 600; std::shared_ptr task = createPlayerTask(delay, std::bind(&Game::playerMoveCreatureByID, this, player->getID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()), "Game::playerMoveCreatureByID"); @@ -1228,7 +1219,7 @@ ReturnValue Game::internalMoveCreature(std::shared_ptr creature, Direc creature->setLastPosition(creature->getPosition()); const Position ¤tPos = creature->getPosition(); Position destPos = getNextPosition(direction, currentPos); - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); bool diagonalMovement = (direction & DIRECTION_DIAGONAL_MASK) != 0; if (player && !diagonalMovement) { @@ -1338,14 +1329,14 @@ ReturnValue Game::internalMoveCreature(const std::shared_ptr &creature } void Game::playerMoveItemByPlayerID(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } playerMoveItem(player, fromPos, itemId, fromStackPos, toPos, count, nullptr, nullptr); } -void Game::playerMoveItem(const std::shared_ptr &player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder) { +void Game::playerMoveItem(std::shared_ptr player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder) { if (!player->canDoAction()) { uint32_t delay = player->getNextActionTime(); std::shared_ptr task = createPlayerTask(delay, std::bind(&Game::playerMoveItemByPlayerID, this, player->getID(), fromPos, itemId, fromStackPos, toPos, count), "Game::playerMoveItemByPlayerID"); @@ -1565,7 +1556,7 @@ bool Game::isTryingToStow(const Position &toPos, std::shared_ptr toCyl return toCylinder->getContainer() && toCylinder->getItem()->getID() == ITEM_LOCKER && toPos.getZ() == ITEM_SUPPLY_STASH_INDEX; } -ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr &player, std::shared_ptr fromCylinder, std::shared_ptr toCylinder, std::shared_ptr item, Position toPos) { +ReturnValue Game::checkMoveItemToCylinder(std::shared_ptr player, std::shared_ptr fromCylinder, std::shared_ptr toCylinder, std::shared_ptr item, Position toPos) { if (!player || !toCylinder || !item) { return RETURNVALUE_NOTPOSSIBLE; } @@ -1871,7 +1862,7 @@ ReturnValue Game::internalMoveItem(std::shared_ptr fromCylinder, std:: auto fromContainer = fromCylinder ? fromCylinder->getContainer() : nullptr; auto toContainer = toCylinder ? toCylinder->getContainer() : nullptr; - const auto &player = actor ? actor->getPlayer() : nullptr; + auto player = actor ? actor->getPlayer() : nullptr; if (player) { // Update containers player->onSendContainer(toContainer); @@ -1884,7 +1875,7 @@ ReturnValue Game::internalMoveItem(std::shared_ptr fromCylinder, std:: return ret; } - if (const auto &player = actor->getPlayer()) { + if (std::shared_ptr player = actor->getPlayer()) { // Refresh depot search window if necessary if (player->isDepotSearchOpenOnItem(item->getID()) && ((fromCylinder->getItem() && fromCylinder->getItem()->isInsideDepot(true)) || (toCylinder->getItem() && toCylinder->getItem()->isInsideDepot(true)))) { player->requestDepotSearchItem(item->getID(), item->getTier()); @@ -2055,7 +2046,7 @@ ReturnValue Game::internalRemoveItem(std::shared_ptr item, int32_t count / return RETURNVALUE_NOERROR; } -ReturnValue Game::internalPlayerAddItem(const std::shared_ptr &player, std::shared_ptr item, bool dropOnMap /*= true*/, Slots_t slot /*= CONST_SLOT_WHEREEVER*/) { +ReturnValue Game::internalPlayerAddItem(std::shared_ptr player, std::shared_ptr item, bool dropOnMap /*= true*/, Slots_t slot /*= CONST_SLOT_WHEREEVER*/) { uint32_t remainderCount = 0; ReturnValue ret = internalAddItem(player, item, static_cast(slot), 0, false, remainderCount); if (remainderCount != 0) { @@ -2172,7 +2163,7 @@ bool Game::removeMoney(std::shared_ptr cylinder, uint64_t money, uint3 } } - const auto &player = useBalance ? std::dynamic_pointer_cast(cylinder) : nullptr; + std::shared_ptr player = useBalance ? std::dynamic_pointer_cast(cylinder) : nullptr; uint64_t balance = 0; if (useBalance && player) { balance = player->getBankBalance(); @@ -2414,7 +2405,7 @@ ReturnValue Game::internalTeleport(std::shared_ptr thing, const Position return RETURNVALUE_NOTPOSSIBLE; } -void Game::internalQuickLootCorpse(const std::shared_ptr &player, std::shared_ptr corpse) { +void Game::internalQuickLootCorpse(std::shared_ptr player, std::shared_ptr corpse) { if (!player || !corpse) { return; } @@ -2557,7 +2548,7 @@ void Game::internalQuickLootCorpse(const std::shared_ptr &player, std::s player->lastQuickLootNotification = OTSYS_TIME(); } -std::shared_ptr Game::findLootContainer(const std::shared_ptr &player, bool &fallbackConsumed, ObjectCategory_t category) { +std::shared_ptr Game::findLootContainer(std::shared_ptr player, bool &fallbackConsumed, ObjectCategory_t category) { auto lootContainer = player->getLootContainer(category); if (!lootContainer && player->quickLootFallbackToMainContainer && !fallbackConsumed) { auto fallbackItem = player->getInventoryItem(CONST_SLOT_BACKPACK); @@ -2598,7 +2589,7 @@ std::shared_ptr Game::findNextAvailableContainer(ContainerIterator &c return nullptr; } -bool Game::handleFallbackLogic(const std::shared_ptr &player, std::shared_ptr &lootContainer, ContainerIterator &containerIterator, const bool &fallbackConsumed) { +bool Game::handleFallbackLogic(std::shared_ptr player, std::shared_ptr &lootContainer, ContainerIterator &containerIterator, const bool &fallbackConsumed) { if (fallbackConsumed || !player->quickLootFallbackToMainContainer) { return false; } @@ -2614,7 +2605,7 @@ bool Game::handleFallbackLogic(const std::shared_ptr &player, std::share return true; } -ReturnValue Game::processMoveOrAddItemToLootContainer(std::shared_ptr item, std::shared_ptr lootContainer, uint32_t &remainderCount, const std::shared_ptr &player) { +ReturnValue Game::processMoveOrAddItemToLootContainer(std::shared_ptr item, std::shared_ptr lootContainer, uint32_t &remainderCount, std::shared_ptr player) { std::shared_ptr moveItem = nullptr; ReturnValue ret; if (item->getParent()) { @@ -2628,7 +2619,7 @@ ReturnValue Game::processMoveOrAddItemToLootContainer(std::shared_ptr item return ret; } -ReturnValue Game::processLootItems(const std::shared_ptr &player, std::shared_ptr lootContainer, std::shared_ptr item, bool &fallbackConsumed) { +ReturnValue Game::processLootItems(std::shared_ptr player, std::shared_ptr lootContainer, std::shared_ptr item, bool &fallbackConsumed) { std::shared_ptr lastSubContainer = nullptr; uint32_t remainderCount = item->getItemCount(); ContainerIterator containerIterator = lootContainer->iterator(); @@ -2650,7 +2641,7 @@ ReturnValue Game::processLootItems(const std::shared_ptr &player, std::s return ret; } -ReturnValue Game::internalCollectLootItems(const std::shared_ptr &player, std::shared_ptr item, ObjectCategory_t category /* = OBJECTCATEGORY_DEFAULT*/) { +ReturnValue Game::internalCollectLootItems(std::shared_ptr player, std::shared_ptr item, ObjectCategory_t category /* = OBJECTCATEGORY_DEFAULT*/) { if (!player || !item) { return RETURNVALUE_NOTPOSSIBLE; } @@ -2687,7 +2678,7 @@ ReturnValue Game::internalCollectLootItems(const std::shared_ptr &player return processLootItems(player, lootContainer, item, fallbackConsumed); } -ReturnValue Game::collectRewardChestItems(const std::shared_ptr &player, uint32_t maxMoveItems /* = 0*/) { +ReturnValue Game::collectRewardChestItems(std::shared_ptr player, uint32_t maxMoveItems /* = 0*/) { // Check if have item on player reward chest std::shared_ptr rewardChest = player->getRewardChest(); if (rewardChest->empty()) { @@ -2863,7 +2854,7 @@ Slots_t getSlotType(const ItemType &it) { // Implementation of player invoked events void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = false*/, uint8_t tier /* = 0*/) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -2907,7 +2898,7 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = } void Game::playerMove(uint32_t playerId, Direction direction) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -2920,7 +2911,7 @@ void Game::playerMove(uint32_t playerId, Direction direction) { } void Game::forcePlayerMove(uint32_t playerId, Direction direction) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -2932,7 +2923,7 @@ void Game::forcePlayerMove(uint32_t playerId, Direction direction) { player->startAutoWalk(std::forward_list { direction }, true); } -bool Game::playerBroadcastMessage(const std::shared_ptr &player, const std::string &text) const { +bool Game::playerBroadcastMessage(std::shared_ptr player, const std::string &text) const { if (!player->hasFlag(PlayerFlags_t::CanBroadcast)) { return false; } @@ -2947,7 +2938,7 @@ bool Game::playerBroadcastMessage(const std::shared_ptr &player, const s } void Game::playerCreatePrivateChannel(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->isPremium()) { return; } @@ -2961,7 +2952,7 @@ void Game::playerCreatePrivateChannel(uint32_t playerId) { } void Game::playerChannelInvite(uint32_t playerId, const std::string &name) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -2971,7 +2962,7 @@ void Game::playerChannelInvite(uint32_t playerId, const std::string &name) { return; } - const auto &invitePlayer = getPlayerByName(name); + std::shared_ptr invitePlayer = getPlayerByName(name); if (!invitePlayer) { return; } @@ -2984,7 +2975,7 @@ void Game::playerChannelInvite(uint32_t playerId, const std::string &name) { } void Game::playerChannelExclude(uint32_t playerId, const std::string &name) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -2994,7 +2985,7 @@ void Game::playerChannelExclude(uint32_t playerId, const std::string &name) { return; } - const auto &excludePlayer = getPlayerByName(name); + std::shared_ptr excludePlayer = getPlayerByName(name); if (!excludePlayer) { return; } @@ -3007,7 +2998,7 @@ void Game::playerChannelExclude(uint32_t playerId, const std::string &name) { } void Game::playerRequestChannels(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3016,7 +3007,7 @@ void Game::playerRequestChannels(uint32_t playerId) { } void Game::playerOpenChannel(uint32_t playerId, uint16_t channelId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3038,7 +3029,7 @@ void Game::playerOpenChannel(uint32_t playerId, uint16_t channelId) { } void Game::playerCloseChannel(uint32_t playerId, uint16_t channelId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3047,7 +3038,7 @@ void Game::playerCloseChannel(uint32_t playerId, uint16_t channelId) { } void Game::playerOpenPrivateChannel(uint32_t playerId, std::string &receiver) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3066,7 +3057,7 @@ void Game::playerOpenPrivateChannel(uint32_t playerId, std::string &receiver) { } void Game::playerCloseNpcChannel(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3081,7 +3072,7 @@ void Game::playerCloseNpcChannel(uint32_t playerId) { } void Game::playerReceivePing(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3090,7 +3081,7 @@ void Game::playerReceivePing(uint32_t playerId) { } void Game::playerReceivePingBack(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3099,7 +3090,7 @@ void Game::playerReceivePingBack(uint32_t playerId) { } void Game::playerAutoWalk(uint32_t playerId, const std::forward_list &listDir) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3110,7 +3101,7 @@ void Game::playerAutoWalk(uint32_t playerId, const std::forward_list } void Game::forcePlayerAutoWalk(uint32_t playerId, const std::forward_list &listDir) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3127,7 +3118,7 @@ void Game::forcePlayerAutoWalk(uint32_t playerId, const std::forward_list player = getPlayerByID(playerId); if (!player) { return; } @@ -3136,7 +3127,7 @@ void Game::playerStopAutoWalk(uint32_t playerId) { } void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t fromStackPos, uint16_t fromItemId, const Position &toPos, uint8_t toStackPos, uint16_t toItemId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3265,7 +3256,7 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f } void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPos, uint8_t index, uint16_t itemId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3359,7 +3350,7 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo } void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uint8_t fromStackPos, uint32_t creatureId, uint16_t itemId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3488,7 +3479,7 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin } void Game::playerCloseContainer(uint32_t playerId, uint8_t cid) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3498,7 +3489,7 @@ void Game::playerCloseContainer(uint32_t playerId, uint8_t cid) { } void Game::playerMoveUpContainer(uint32_t playerId, uint8_t cid) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3545,7 +3536,7 @@ void Game::playerMoveUpContainer(uint32_t playerId, uint8_t cid) { } void Game::playerUpdateContainer(uint32_t playerId, uint8_t cid) { - const auto &player = getPlayerByGUID(playerId); + std::shared_ptr player = getPlayerByGUID(playerId); if (!player) { return; } @@ -3559,7 +3550,7 @@ void Game::playerUpdateContainer(uint32_t playerId, uint8_t cid) { } void Game::playerRotateItem(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3599,7 +3590,7 @@ void Game::playerRotateItem(uint32_t playerId, const Position &pos, uint8_t stac } void Game::playerConfigureShowOffSocket(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || pos.x == 0xFFFF) { return; } @@ -3641,7 +3632,7 @@ void Game::playerConfigureShowOffSocket(uint32_t playerId, const Position &pos, } void Game::playerSetShowOffSocket(uint32_t playerId, Outfit_t &outfit, const Position &pos, uint8_t stackPos, const uint16_t itemId, uint8_t podiumVisible, uint8_t direction) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || pos.x == 0xFFFF) { return; } @@ -3757,14 +3748,14 @@ void Game::playerSetShowOffSocket(uint32_t playerId, Outfit_t &outfit, const Pos // Send to client for (auto spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendUpdateTileItem(tile, pos, item); } } } void Game::playerWrapableItem(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3870,7 +3861,7 @@ std::shared_ptr Game::wrapItem(std::shared_ptr item, House* house) { return newItem; } -void Game::unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* house, const std::shared_ptr &player) { +void Game::unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* house, std::shared_ptr player) { auto hiddenCharges = item->getAttribute(DATE); const ItemType &newiType = Item::items.getItemType(unWrapId); if (player != nullptr && house != nullptr && newiType.isBed() && house->getMaxBeds() > -1 && house->getBedCount() >= house->getMaxBeds()) { @@ -3896,7 +3887,7 @@ void Game::unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* hous } void Game::playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std::string &text) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -3916,7 +3907,7 @@ void Game::playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std:: std::shared_ptr topParent = writeItem->getTopParent(); - const auto &owner = std::dynamic_pointer_cast(topParent); + std::shared_ptr owner = std::dynamic_pointer_cast(topParent); if (owner && owner != player) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; @@ -3955,7 +3946,7 @@ void Game::playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std:: } void Game::playerBrowseField(uint32_t playerId, const Position &pos) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4013,7 +4004,7 @@ void Game::playerBrowseField(uint32_t playerId, const Position &pos) { } void Game::playerStowItem(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackpos, uint8_t count, bool allItems) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4049,7 +4040,7 @@ void Game::playerStowItem(uint32_t playerId, const Position &pos, uint16_t itemI } void Game::playerStashWithdraw(uint32_t playerId, uint16_t itemId, uint32_t count, uint8_t) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4122,7 +4113,7 @@ void Game::playerStashWithdraw(uint32_t playerId, uint16_t itemId, uint32_t coun } void Game::playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_t index, uint8_t containerCategory) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4147,7 +4138,7 @@ void Game::playerSeekInContainer(uint32_t playerId, uint8_t containerId, uint16_ } void Game::playerUpdateHouseWindow(uint32_t playerId, uint8_t listId, uint32_t windowTextId, const std::string &text) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4164,12 +4155,12 @@ void Game::playerUpdateHouseWindow(uint32_t playerId, uint8_t listId, uint32_t w } void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t stackPos, uint32_t tradePlayerId, uint16_t itemId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - const auto &tradePartner = getPlayerByID(tradePlayerId); + std::shared_ptr tradePartner = getPlayerByID(tradePlayerId); if (!tradePartner || tradePartner == player) { player->sendTextMessage(MESSAGE_FAILURE, "Sorry, not possible."); return; @@ -4296,7 +4287,7 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st internalStartTrade(player, tradePartner, tradeItem); } -bool Game::internalStartTrade(const std::shared_ptr &player, const std::shared_ptr &tradePartner, std::shared_ptr tradeItem) { +bool Game::internalStartTrade(std::shared_ptr player, std::shared_ptr tradePartner, std::shared_ptr tradeItem) { if (player->tradeState != TRADE_NONE && !(player->tradeState == TRADE_ACKNOWLEDGE && player->tradePartner == tradePartner)) { player->sendCancelMessage(RETURNVALUE_YOUAREALREADYTRADING); return false; @@ -4328,7 +4319,7 @@ bool Game::internalStartTrade(const std::shared_ptr &player, const std:: } void Game::playerAcceptTrade(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4337,7 +4328,7 @@ void Game::playerAcceptTrade(uint32_t playerId) { return; } - const auto &tradePartner = player->tradePartner; + std::shared_ptr tradePartner = player->tradePartner; if (!tradePartner) { return; } @@ -4461,12 +4452,12 @@ std::string Game::getTradeErrorDescription(ReturnValue ret, std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - const auto &tradePartner = player->tradePartner; + std::shared_ptr tradePartner = player->tradePartner; if (!tradePartner) { return; } @@ -4520,7 +4511,7 @@ void Game::playerLookInTrade(uint32_t playerId, bool lookAtCounterOffer, uint8_t } void Game::playerCloseTrade(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4528,8 +4519,8 @@ void Game::playerCloseTrade(uint32_t playerId) { internalCloseTrade(player); } -void Game::internalCloseTrade(const std::shared_ptr &player) { - const auto &tradePartner = player->tradePartner; +void Game::internalCloseTrade(std::shared_ptr player) { + std::shared_ptr tradePartner = player->tradePartner; if ((tradePartner && tradePartner->getTradeState() == TRADE_TRANSFER) || player->getTradeState() == TRADE_TRANSFER) { return; } @@ -4574,7 +4565,7 @@ void Game::playerBuyItem(uint32_t playerId, uint16_t itemId, uint8_t count, uint return; } - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4612,7 +4603,7 @@ void Game::playerSellItem(uint32_t playerId, uint16_t itemId, uint8_t count, uin return; } - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4642,7 +4633,7 @@ void Game::playerSellItem(uint32_t playerId, uint16_t itemId, uint8_t count, uin } void Game::playerCloseShop(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4651,7 +4642,7 @@ void Game::playerCloseShop(uint32_t playerId) { } void Game::playerLookInShop(uint32_t playerId, uint16_t itemId, uint8_t count) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4681,7 +4672,7 @@ void Game::playerLookInShop(uint32_t playerId, uint16_t itemId, uint8_t count) { } void Game::playerLookAt(uint32_t playerId, uint16_t itemId, const Position &pos, uint8_t stackPos) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4716,7 +4707,7 @@ void Game::playerLookAt(uint32_t playerId, uint16_t itemId, const Position &pos, } void Game::playerLookInBattleList(uint32_t playerId, uint32_t creatureId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4751,7 +4742,7 @@ void Game::playerLookInBattleList(uint32_t playerId, uint32_t creatureId) { } void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, std::shared_ptr defaultItem, bool lootAllCorpses, bool autoLoot) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4881,7 +4872,7 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item } } -void Game::playerLootAllCorpses(const std::shared_ptr &player, const Position &pos, bool lootAllCorpses) { +void Game::playerLootAllCorpses(std::shared_ptr player, const Position &pos, bool lootAllCorpses) { if (lootAllCorpses) { std::shared_ptr tile = g_game().map.getTile(pos.x, pos.y, pos.z); if (!tile) { @@ -4931,7 +4922,7 @@ void Game::playerLootAllCorpses(const std::shared_ptr &player, const Pos } void Game::playerSetLootContainer(uint32_t playerId, ObjectCategory_t category, const Position &pos, uint16_t itemId, uint8_t stackPos) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || pos.x != 0xffff) { return; } @@ -4970,7 +4961,7 @@ void Game::playerSetLootContainer(uint32_t playerId, ObjectCategory_t category, } void Game::playerClearLootContainer(uint32_t playerId, ObjectCategory_t category) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -4987,7 +4978,7 @@ void Game::playerClearLootContainer(uint32_t playerId, ObjectCategory_t category } void Game::playerOpenLootContainer(uint32_t playerId, ObjectCategory_t category) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5001,7 +4992,7 @@ void Game::playerOpenLootContainer(uint32_t playerId, ObjectCategory_t category) } void Game::playerSetQuickLootFallback(uint32_t playerId, bool fallback) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5010,7 +5001,7 @@ void Game::playerSetQuickLootFallback(uint32_t playerId, bool fallback) { } void Game::playerQuickLootBlackWhitelist(uint32_t playerId, QuickLootFilter_t filter, const std::vector itemIds) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5023,7 +5014,7 @@ void Game::playerQuickLootBlackWhitelist(uint32_t playerId, QuickLootFilter_t fi * Depot search system ******************************************************************************/ void Game::playerRequestDepotItems(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->isDepotSearchAvailable()) { return; } @@ -5038,7 +5029,7 @@ void Game::playerRequestDepotItems(uint32_t playerId) { } void Game::playerRequestCloseDepotSearch(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->isDepotSearchOpen()) { return; } @@ -5048,7 +5039,7 @@ void Game::playerRequestCloseDepotSearch(uint32_t playerId) { } void Game::playerRequestDepotSearchItem(uint32_t playerId, uint16_t itemId, uint8_t tier) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->isDepotSearchOpen()) { return; } @@ -5063,7 +5054,7 @@ void Game::playerRequestDepotSearchItem(uint32_t playerId, uint16_t itemId, uint } void Game::playerRequestDepotSearchRetrieve(uint32_t playerId, uint16_t itemId, uint8_t tier, uint8_t type) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->isDepotSearchOpenOnItem(itemId)) { return; } @@ -5078,7 +5069,7 @@ void Game::playerRequestDepotSearchRetrieve(uint32_t playerId, uint16_t itemId, } void Game::playerRequestOpenContainerFromDepotSearch(uint32_t playerId, const Position &pos) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->isDepotSearchOpen()) { return; } @@ -5093,7 +5084,7 @@ void Game::playerRequestOpenContainerFromDepotSearch(uint32_t playerId, const Po } void Game::playerCancelAttackAndFollow(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5104,7 +5095,7 @@ void Game::playerCancelAttackAndFollow(uint32_t playerId) { } void Game::playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5135,7 +5126,7 @@ void Game::playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId) { } void Game::playerFollowCreature(uint32_t playerId, uint32_t creatureId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5146,7 +5137,7 @@ void Game::playerFollowCreature(uint32_t playerId, uint32_t creatureId) { } void Game::playerSetFightModes(uint32_t playerId, FightMode_t fightMode, bool chaseMode, bool secureMode) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5161,12 +5152,12 @@ void Game::playerRequestAddVip(uint32_t playerId, const std::string &name) { return; } - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - const auto &vipPlayer = getPlayerByName(name); + std::shared_ptr vipPlayer = getPlayerByName(name); if (!vipPlayer) { uint32_t guid; bool specialVip; @@ -5197,7 +5188,7 @@ void Game::playerRequestAddVip(uint32_t playerId, const std::string &name) { } void Game::playerRequestRemoveVip(uint32_t playerId, uint32_t guid) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5206,7 +5197,7 @@ void Game::playerRequestRemoveVip(uint32_t playerId, uint32_t guid) { } void Game::playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::string &description, uint32_t icon, bool notify) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5215,7 +5206,7 @@ void Game::playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::str } void Game::playerApplyImbuement(uint32_t playerId, uint16_t imbuementid, uint8_t slot, bool protectionCharm) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5244,7 +5235,7 @@ void Game::playerApplyImbuement(uint32_t playerId, uint16_t imbuementid, uint8_t } void Game::playerClearImbuement(uint32_t playerid, uint8_t slot) { - const auto &player = getPlayerByID(playerid); + std::shared_ptr player = getPlayerByID(playerid); if (!player) { return; } @@ -5262,7 +5253,7 @@ void Game::playerClearImbuement(uint32_t playerid, uint8_t slot) { } void Game::playerCloseImbuementWindow(uint32_t playerid) { - const auto &player = getPlayerByID(playerid); + std::shared_ptr player = getPlayerByID(playerid); if (!player) { return; } @@ -5272,7 +5263,7 @@ void Game::playerCloseImbuementWindow(uint32_t playerid) { } void Game::playerTurn(uint32_t playerId, Direction dir) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5294,7 +5285,7 @@ void Game::playerRequestOutfit(uint32_t playerId) { return; } - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5303,7 +5294,7 @@ void Game::playerRequestOutfit(uint32_t playerId) { } void Game::playerToggleMount(uint32_t playerId, bool mount) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5316,7 +5307,7 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, uint8_t isMoun return; } - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5378,7 +5369,7 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, uint8_t isMoun } void Game::playerShowQuestLog(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5388,7 +5379,7 @@ void Game::playerShowQuestLog(uint32_t playerId) { } void Game::playerShowQuestLine(uint32_t playerId, uint16_t questId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5398,7 +5389,7 @@ void Game::playerShowQuestLine(uint32_t playerId, uint16_t questId) { } void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, const std::string &receiver, const std::string &text) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -5462,7 +5453,7 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, c } } -bool Game::playerSaySpell(const std::shared_ptr &player, SpeakClasses type, const std::string &text) { +bool Game::playerSaySpell(std::shared_ptr player, SpeakClasses type, const std::string &text) { if (player->walkExhausted()) { return true; } @@ -5491,13 +5482,13 @@ bool Game::playerSaySpell(const std::shared_ptr &player, SpeakClasses ty return false; } -void Game::playerWhisper(const std::shared_ptr &player, const std::string &text) { +void Game::playerWhisper(std::shared_ptr player, const std::string &text) { SpectatorHashSet spectators; map.getSpectators(spectators, player->getPosition(), false, false, MAP_MAX_CLIENT_VIEW_PORT_X, MAP_MAX_CLIENT_VIEW_PORT_X, MAP_MAX_CLIENT_VIEW_PORT_Y, MAP_MAX_CLIENT_VIEW_PORT_Y); // send to client for (auto spectator : spectators) { - if (const auto &spectatorPlayer = spectator->getPlayer()) { + if (auto spectatorPlayer = spectator->getPlayer()) { if (!Position::areInRange<1, 1>(player->getPosition(), spectatorPlayer->getPosition())) { spectatorPlayer->sendCreatureSay(player, TALKTYPE_WHISPER, "pspsps"); } else { @@ -5512,7 +5503,7 @@ void Game::playerWhisper(const std::shared_ptr &player, const std::strin } } -bool Game::playerYell(const std::shared_ptr &player, const std::string &text) { +bool Game::playerYell(std::shared_ptr player, const std::string &text) { if (player->getLevel() == 1) { player->sendTextMessage(MESSAGE_FAILURE, "You may not yell as long as you are on level 1."); return false; @@ -5532,8 +5523,8 @@ bool Game::playerYell(const std::shared_ptr &player, const std::string & return true; } -bool Game::playerSpeakTo(const std::shared_ptr &player, SpeakClasses type, const std::string &receiver, const std::string &text) { - const auto &toPlayer = getPlayerByName(receiver); +bool Game::playerSpeakTo(std::shared_ptr player, SpeakClasses type, const std::string &receiver, const std::string &text) { + std::shared_ptr toPlayer = getPlayerByName(receiver); if (!toPlayer) { player->sendTextMessage(MESSAGE_FAILURE, "A player with this name is not online."); return false; @@ -5558,7 +5549,7 @@ bool Game::playerSpeakTo(const std::shared_ptr &player, SpeakClasses typ return true; } -void Game::playerSpeakToNpc(const std::shared_ptr &player, const std::string &text) { +void Game::playerSpeakToNpc(std::shared_ptr player, const std::string &text) { if (player == nullptr) { g_logger().error("[Game::playerSpeakToNpc] - Player is nullptr"); return; @@ -5599,7 +5590,7 @@ bool Game::internalCreatureTurn(std::shared_ptr creature, Direction di return false; } - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { player->cancelPush(); } creature->setDirection(dir); @@ -5608,7 +5599,7 @@ bool Game::internalCreatureTurn(std::shared_ptr creature, Direction di SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); for (auto spectator : spectators) { - const auto &tmpPlayer = spectator->getPlayer(); + auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; } @@ -5644,7 +5635,7 @@ bool Game::internalCreatureSay(std::shared_ptr creature, SpeakClasses // send to client for (auto spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (auto tmpPlayer = spectator->getPlayer()) { if (!ghostMode || tmpPlayer->canSeeCreature(creature)) { tmpPlayer->sendCreatureSay(creature, type, text, pos); } @@ -5769,7 +5760,7 @@ void Game::changePlayerSpeed(const std::shared_ptr &player, int32_t varS continue; } - const auto &playerSpectator = creatureSpectator->getPlayer(); + std::shared_ptr playerSpectator = creatureSpectator->getPlayer(); if (playerSpectator == nullptr) { g_logger().error("[Game::changePlayerSpeed] - Player spectator is nullptr"); continue; @@ -5838,7 +5829,7 @@ void Game::reloadCreature(std::shared_ptr creature) { SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), false, true); for (auto spectator : spectators) { - const auto &tmpPlayer = spectator->getPlayer(); + auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; } @@ -5854,7 +5845,7 @@ void Game::sendSingleSoundEffect(const Position &pos, SoundEffect_t soundId, std SpectatorHashSet spectators; map.getSpectators(spectators, pos, false, true); for (auto spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (auto tmpPlayer = spectator->getPlayer()) { SourceEffect_t source = SourceEffect_t::CREATURES; if (!actor || actor->getNpc()) { source = SourceEffect_t::GLOBAL; @@ -5878,7 +5869,7 @@ void Game::sendDoubleSoundEffect(const Position &pos, SoundEffect_t mainSoundEff SpectatorHashSet spectators; map.getSpectators(spectators, pos, false, true); for (auto spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (auto tmpPlayer = spectator->getPlayer()) { SourceEffect_t source = SourceEffect_t::CREATURES; if (!actor || actor->getNpc()) { source = SourceEffect_t::GLOBAL; @@ -5907,8 +5898,8 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr attack } // Skill dodge (ruse) - if (const auto &targetPlayer = target->getPlayer()) { - if (const auto &playerArmor = targetPlayer->getInventoryItem(CONST_SLOT_ARMOR); + if (std::shared_ptr targetPlayer = target->getPlayer()) { + if (auto playerArmor = targetPlayer->getInventoryItem(CONST_SLOT_ARMOR); playerArmor != nullptr && playerArmor->getTier()) { double_t chance = playerArmor->getDodgeChance(); double_t randomChance = uniform_random(0, 10000) / 100; @@ -5932,7 +5923,7 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr attack CombatParams damageReflectedParams; BlockType_t primaryBlockType, secondaryBlockType; - const auto &targetPlayer = target->getPlayer(); + std::shared_ptr targetPlayer = target->getPlayer(); if (damage.primary.type != COMBAT_NONE) { // Damage reflection primary @@ -6189,7 +6180,7 @@ void Game::combatGetTypeInfo(CombatType_t combatType, std::shared_ptr } // Hazard combat helpers -void Game::handleHazardSystemAttack(CombatDamage &damage, const std::shared_ptr &player, std::shared_ptr monster, bool isPlayerAttacker) { +void Game::handleHazardSystemAttack(CombatDamage &damage, std::shared_ptr player, std::shared_ptr monster, bool isPlayerAttacker) { if (damage.primary.value != 0 && monster->getHazard()) { if (isPlayerAttacker) { player->parseAttackDealtHazardSystem(damage, monster); @@ -6199,14 +6190,14 @@ void Game::handleHazardSystemAttack(CombatDamage &damage, const std::shared_ptr< } } -void Game::notifySpectators(const SpectatorHashSet &spectators, const Position &targetPos, const std::shared_ptr &attackerPlayer, std::shared_ptr targetMonster) { +void Game::notifySpectators(const SpectatorHashSet &spectators, const Position &targetPos, std::shared_ptr attackerPlayer, std::shared_ptr targetMonster) { if (!spectators.empty()) { for (auto spectator : spectators) { if (!spectator) { continue; } - const auto &tmpPlayer = spectator->getPlayer(); + const auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer || tmpPlayer->getPosition().z != targetPos.z) { continue; } @@ -6228,7 +6219,7 @@ void Game::notifySpectators(const SpectatorHashSet &spectators, const Position & } // Wheel of destiny combat helpers -void Game::applyWheelOfDestinyHealing(CombatDamage &damage, const std::shared_ptr &attackerPlayer, std::shared_ptr target) { +void Game::applyWheelOfDestinyHealing(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr target) { damage.primary.value += (damage.primary.value * damage.healingMultiplier) / 100.; if (attackerPlayer) { @@ -6251,7 +6242,7 @@ void Game::applyWheelOfDestinyHealing(CombatDamage &damage, const std::shared_pt } } -void Game::applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, const std::shared_ptr &attackerPlayer, std::shared_ptr target) const { +void Game::applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr target) const { // If damage is 0, it means the target is immune to the damage type, or that we missed. if (damage.primary.value == 0 && damage.secondary.value == 0) { return; @@ -6288,7 +6279,7 @@ int32_t Game::applyHealthChange(CombatDamage &damage, std::shared_ptr int32_t targetHealth = target->getHealth(); // Wheel of destiny (Gift of Life) - if (const auto &targetPlayer = target->getPlayer()) { + if (std::shared_ptr targetPlayer = target->getPlayer()) { if (targetPlayer->wheel()->getInstant("Gift of Life") && targetPlayer->wheel()->getGiftOfCooldown() == 0 && (damage.primary.value + damage.secondary.value) >= targetHealth) { int32_t overkillMultiplier = (damage.primary.value + damage.secondary.value) - targetHealth; overkillMultiplier = (overkillMultiplier * 100) / targetPlayer->getMaxHealth(); @@ -6324,7 +6315,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt attackerPlayer = nullptr; } - const auto &targetPlayer = target->getPlayer(); + auto targetPlayer = target->getPlayer(); if (attackerPlayer && targetPlayer && attackerPlayer->getSkull() == SKULL_BLACK && attackerPlayer->getSkullClient(targetPlayer) == SKULL_NONE) { return false; } @@ -6372,7 +6363,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt SpectatorHashSet spectators; map.getSpectators(spectators, targetPos, false, true); for (auto spectator : spectators) { - const auto &tmpPlayer = spectator->getPlayer(); + auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; @@ -6432,7 +6423,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt attackerPlayer = nullptr; } - const auto &targetPlayer = target->getPlayer(); + auto targetPlayer = target->getPlayer(); if (attackerPlayer && targetPlayer && attackerPlayer->getSkull() == SKULL_BLACK && attackerPlayer->getSkullClient(targetPlayer) == SKULL_NONE) { return false; } @@ -6593,7 +6584,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt continue; } - const auto &tmpPlayer = spectator->getPlayer(); + std::shared_ptr tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; } @@ -6730,7 +6721,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt return true; } -void Game::updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, const std::shared_ptr &player) const { +void Game::updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, std::shared_ptr player) const { if (!player) { return; } @@ -6796,7 +6787,7 @@ void Game::sendMessages( std::string spectatorMessage; for (std::shared_ptr spectator : spectators) { - const auto &tmpPlayer = spectator->getPlayer(); + std::shared_ptr tmpPlayer = spectator->getPlayer(); if (tmpPlayer->getPosition().z != targetPos.z) { continue; } @@ -6901,7 +6892,7 @@ void Game::sendEffects( } void Game::applyCharmRune( - std::shared_ptr targetMonster, const std::shared_ptr &attackerPlayer, std::shared_ptr target, const int32_t &realDamage + std::shared_ptr targetMonster, std::shared_ptr attackerPlayer, std::shared_ptr target, const int32_t &realDamage ) const { if (!targetMonster || !attackerPlayer) { return; @@ -6997,7 +6988,7 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< attackerPlayer = nullptr; } - const auto &targetPlayer = target->getPlayer(); + auto targetPlayer = target->getPlayer(); if (attackerPlayer && targetPlayer && attackerPlayer->getSkull() == SKULL_BLACK && attackerPlayer->getSkullClient(targetPlayer) == SKULL_NONE) { return false; } @@ -7043,7 +7034,7 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< SpectatorHashSet spectators; map.getSpectators(spectators, targetPos, false, true); for (auto spectator : spectators) { - const auto &tmpPlayer = spectator->getPlayer(); + auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; @@ -7083,7 +7074,7 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< attackerPlayer = nullptr; } - const auto &targetPlayer = target->getPlayer(); + auto targetPlayer = target->getPlayer(); if (attackerPlayer && targetPlayer && attackerPlayer->getSkull() == SKULL_BLACK && attackerPlayer->getSkullClient(targetPlayer) == SKULL_NONE) { return false; } @@ -7143,7 +7134,7 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< SpectatorHashSet spectators; map.getSpectators(spectators, targetPos, false, true); for (auto spectator : spectators) { - const auto &tmpPlayer = spectator->getPlayer(); + auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; @@ -7199,32 +7190,32 @@ void Game::addCreatureHealth(std::shared_ptr target) { void Game::addCreatureHealth(const SpectatorHashSet &spectators, std::shared_ptr target) { uint8_t healthPercent = std::ceil((static_cast(target->getHealth()) / std::max(target->getMaxHealth(), 1)) * 100); - if (const auto &targetPlayer = target->getPlayer()) { + if (std::shared_ptr targetPlayer = target->getPlayer()) { if (Party* party = targetPlayer->getParty()) { party->updatePlayerHealth(targetPlayer, target, healthPercent); } } else if (std::shared_ptr master = target->getMaster()) { - if (const auto &masterPlayer = master->getPlayer()) { + if (std::shared_ptr masterPlayer = master->getPlayer()) { if (Party* party = masterPlayer->getParty()) { party->updatePlayerHealth(masterPlayer, target, healthPercent); } } } for (std::shared_ptr spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendCreatureHealth(target); } } } -void Game::addPlayerMana(const std::shared_ptr &target) { +void Game::addPlayerMana(std::shared_ptr target) { if (Party* party = target->getParty()) { uint8_t manaPercent = std::ceil((static_cast(target->getMana()) / std::max(target->getMaxMana(), 1)) * 100); party->updatePlayerMana(target, manaPercent); } } -void Game::addPlayerVocation(const std::shared_ptr &target) { +void Game::addPlayerVocation(std::shared_ptr target) { if (Party* party = target->getParty()) { party->updatePlayerVocation(target); } @@ -7233,7 +7224,7 @@ void Game::addPlayerVocation(const std::shared_ptr &target) { map.getSpectators(spectators, target->getPosition(), true, true); for (auto spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendPlayerVocation(target); } } @@ -7247,7 +7238,7 @@ void Game::addMagicEffect(const Position &pos, uint16_t effect) { void Game::addMagicEffect(const SpectatorHashSet &spectators, const Position &pos, uint16_t effect) { for (auto spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendMagicEffect(pos, effect); } } @@ -7261,7 +7252,7 @@ void Game::removeMagicEffect(const Position &pos, uint16_t effect) { void Game::removeMagicEffect(const SpectatorHashSet &spectators, const Position &pos, uint16_t effect) { for (auto spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (const auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->removeMagicEffect(pos, effect); } } @@ -7276,7 +7267,7 @@ void Game::addDistanceEffect(const Position &fromPos, const Position &toPos, uin void Game::addDistanceEffect(const SpectatorHashSet &spectators, const Position &fromPos, const Position &toPos, uint16_t effect) { for (auto spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendDistanceShoot(fromPos, toPos, effect); } } @@ -7426,7 +7417,7 @@ void Game::updateCreatureWalkthrough(std::shared_ptr creature) { SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); for (auto spectator : spectators) { - const auto &tmpPlayer = spectator->getPlayer(); + auto tmpPlayer = spectator->getPlayer(); tmpPlayer->sendCreatureWalkthrough(creature, tmpPlayer->canWalkthroughEx(creature)); } } @@ -7443,7 +7434,7 @@ void Game::updateCreatureSkull(std::shared_ptr creature) { } } -void Game::updatePlayerShield(const std::shared_ptr &player) { +void Game::updatePlayerShield(std::shared_ptr player) { SpectatorHashSet spectators; map.getSpectators(spectators, player->getPosition(), true, true); for (auto spectator : spectators) { @@ -7476,7 +7467,7 @@ void Game::updateCreatureType(std::shared_ptr creature) { map.getSpectators(spectators, creature->getPosition(), true, true); if (creatureType == CREATURETYPE_SUMMON_OTHERS) { for (auto spectator : spectators) { - const auto &player = spectator->getPlayer(); + auto player = spectator->getPlayer(); if (!player) { continue; } @@ -7489,7 +7480,7 @@ void Game::updateCreatureType(std::shared_ptr creature) { } } else { for (auto spectator : spectators) { - if (const auto &player = spectator->getPlayer()) { + if (auto player = spectator->getPlayer()) { player->sendCreatureType(creature, creatureType); } } @@ -7567,12 +7558,12 @@ void Game::playerInviteToParty(uint32_t playerId, uint32_t invitedId) { return; } - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - const auto &invitedPlayer = getPlayerByID(invitedId); + std::shared_ptr invitedPlayer = getPlayerByID(invitedId); if (!invitedPlayer || invitedPlayer->isInviting(player)) { return; } @@ -7594,7 +7585,7 @@ void Game::playerInviteToParty(uint32_t playerId, uint32_t invitedId) { party->invitePlayer(invitedPlayer); } -void Game::updatePlayerHelpers(const std::shared_ptr &player) { +void Game::updatePlayerHelpers(std::shared_ptr player) { if (!player) { return; } @@ -7613,12 +7604,12 @@ void Game::updatePlayerHelpers(const std::shared_ptr &player) { } void Game::playerJoinParty(uint32_t playerId, uint32_t leaderId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } - const auto &leader = getPlayerByID(leaderId); + std::shared_ptr leader = getPlayerByID(leaderId); if (!leader || !leader->isInviting(player)) { return; } @@ -7637,7 +7628,7 @@ void Game::playerJoinParty(uint32_t playerId, uint32_t leaderId) { } void Game::playerRevokePartyInvitation(uint32_t playerId, uint32_t invitedId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -7647,7 +7638,7 @@ void Game::playerRevokePartyInvitation(uint32_t playerId, uint32_t invitedId) { return; } - const auto &invitedPlayer = getPlayerByID(invitedId); + std::shared_ptr invitedPlayer = getPlayerByID(invitedId); if (!invitedPlayer || !player->isInviting(invitedPlayer)) { return; } @@ -7656,7 +7647,7 @@ void Game::playerRevokePartyInvitation(uint32_t playerId, uint32_t invitedId) { } void Game::playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -7666,7 +7657,7 @@ void Game::playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId) { return; } - const auto &newLeader = getPlayerByID(newLeaderId); + std::shared_ptr newLeader = getPlayerByID(newLeaderId); if (!newLeader || !player->isPartner(newLeader)) { return; } @@ -7675,7 +7666,7 @@ void Game::playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId) { } void Game::playerLeaveParty(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -7689,7 +7680,7 @@ void Game::playerLeaveParty(uint32_t playerId) { } void Game::playerEnableSharedPartyExperience(uint32_t playerId, bool sharedExpActive) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -7704,7 +7695,7 @@ void Game::playerEnableSharedPartyExperience(uint32_t playerId, bool sharedExpAc } void Game::sendGuildMotd(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -7716,7 +7707,7 @@ void Game::sendGuildMotd(uint32_t playerId) { } void Game::kickPlayer(uint32_t playerId, bool displayEffect) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -7724,7 +7715,7 @@ void Game::kickPlayer(uint32_t playerId, bool displayEffect) { player->removePlayer(displayEffect); } -void Game::playerCyclopediaCharacterInfo(const std::shared_ptr &player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page) { +void Game::playerCyclopediaCharacterInfo(std::shared_ptr player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page) { uint32_t playerGUID = player->getGUID(); if (characterID != playerGUID) { // For now allow viewing only our character since we don't have tournaments supported @@ -7749,7 +7740,7 @@ void Game::playerCyclopediaCharacterInfo(const std::shared_ptr &player, uint32_t playerID = player->getID(); std::function callback = [playerID, page, entriesPerPage](DBResult_ptr result, bool) { - const auto &player = g_game().getPlayerByID(playerID); + std::shared_ptr player = g_game().getPlayerByID(playerID); if (!player) { return; } @@ -7814,7 +7805,7 @@ void Game::playerCyclopediaCharacterInfo(const std::shared_ptr &player, uint32_t playerID = player->getID(); std::function callback = [playerID, page, entriesPerPage](DBResult_ptr result, bool) { - const auto &player = g_game().getPlayerByID(playerID); + std::shared_ptr player = g_game().getPlayerByID(playerID); if (!player) { return; } @@ -7884,7 +7875,7 @@ void Game::playerCyclopediaCharacterInfo(const std::shared_ptr &player, } } -void Game::playerHighscores(const std::shared_ptr &player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &, uint16_t page, uint8_t entriesPerPage) { +void Game::playerHighscores(std::shared_ptr player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &, uint16_t page, uint8_t entriesPerPage) { if (player->hasAsyncOngoingTask(PlayerAsyncTask_Highscore)) { return; } @@ -7968,7 +7959,7 @@ void Game::playerHighscores(const std::shared_ptr &player, HighscoreType uint32_t playerID = player->getID(); std::function callback = [playerID, category, vocation, entriesPerPage](DBResult_ptr result, bool) { - const auto &player = g_game().getPlayerByID(playerID); + std::shared_ptr player = g_game().getPlayerByID(playerID); if (!player) { return; } @@ -8003,7 +7994,7 @@ void Game::playerHighscores(const std::shared_ptr &player, HighscoreType } void Game::playerReportRuleViolationReport(uint32_t playerId, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8013,7 +8004,7 @@ void Game::playerReportRuleViolationReport(uint32_t playerId, const std::string } void Game::playerReportBug(uint32_t playerId, const std::string &message, const Position &position, uint8_t category) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8023,7 +8014,7 @@ void Game::playerReportBug(uint32_t playerId, const std::string &message, const } void Game::playerDebugAssert(uint32_t playerId, const std::string &assertLine, const std::string &date, const std::string &description, const std::string &comment) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8038,7 +8029,7 @@ void Game::playerDebugAssert(uint32_t playerId, const std::string &assertLine, c } void Game::playerPreyAction(uint32_t playerId, uint8_t slot, uint8_t action, uint8_t option, int8_t index, uint16_t raceId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8047,7 +8038,7 @@ void Game::playerPreyAction(uint32_t playerId, uint8_t slot, uint8_t action, uin } void Game::playerTaskHuntingAction(uint32_t playerId, uint8_t slot, uint8_t action, bool upgrade, uint16_t raceId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8056,7 +8047,7 @@ void Game::playerTaskHuntingAction(uint32_t playerId, uint8_t slot, uint8_t acti } void Game::playerNpcGreet(uint32_t playerId, uint32_t npcId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8080,7 +8071,7 @@ void Game::playerNpcGreet(uint32_t playerId, uint32_t npcId) { } void Game::playerLeaveMarket(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8089,7 +8080,7 @@ void Game::playerLeaveMarket(uint32_t playerId) { } void Game::playerBrowseMarket(uint32_t playerId, uint16_t itemId, uint8_t tier) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8114,7 +8105,7 @@ void Game::playerBrowseMarket(uint32_t playerId, uint16_t itemId, uint8_t tier) } void Game::playerBrowseMarketOwnOffers(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8129,7 +8120,7 @@ void Game::playerBrowseMarketOwnOffers(uint32_t playerId) { } void Game::playerBrowseMarketOwnHistory(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8215,7 +8206,7 @@ namespace { } } // namespace -bool checkCanInitCreateMarketOffer(const std::shared_ptr &player, uint8_t type, const ItemType &it, uint16_t amount, uint64_t price, std::ostringstream &offerStatus) { +bool checkCanInitCreateMarketOffer(std::shared_ptr player, uint8_t type, const ItemType &it, uint16_t amount, uint64_t price, std::ostringstream &offerStatus) { if (!player) { offerStatus << "Failed to load player"; return false; @@ -8281,7 +8272,7 @@ void Game::playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t ite // Initialize variables // Before creating the offer we will compare it with the RETURN VALUE ERROR std::ostringstream offerStatus; - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); const ItemType &it = Item::items[itemId]; // Make sure everything is ok before the create market offer starts @@ -8373,7 +8364,7 @@ void Game::playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t ite } void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->getAccount()) { return; } @@ -8457,7 +8448,7 @@ void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter, uint16_t amount) { std::ostringstream offerStatus; - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || !player->getAccount()) { offerStatus << "Failed to load player"; return; @@ -8501,10 +8492,14 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 return; } - const auto buyerPlayer = getPlayerByGUID(offer.playerId, true); + std::shared_ptr buyerPlayer = getPlayerByGUID(offer.playerId); if (!buyerPlayer) { - offerStatus << "Failed to load buyer player " << player->getName(); - return; + buyerPlayer = std::make_shared(nullptr); + if (!IOLoginData::loadPlayerById(buyerPlayer, offer.playerId)) { + + offerStatus << "Failed to load buyer player " << player->getName(); + return; + } } if (!buyerPlayer->getAccount()) { @@ -8602,10 +8597,14 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 IOLoginData::savePlayer(buyerPlayer); } } else if (offer.type == MARKETACTION_SELL) { - const auto sellerPlayer = getPlayerByGUID(offer.playerId, true); + std::shared_ptr sellerPlayer = getPlayerByGUID(offer.playerId); if (!sellerPlayer) { - offerStatus << "Failed to load seller player"; - return; + sellerPlayer = std::make_shared(nullptr); + if (!IOLoginData::loadPlayerById(sellerPlayer, offer.playerId)) { + offerStatus << "Failed to load seller player"; + + return; + } } if (player == sellerPlayer || player->getAccount() == sellerPlayer->getAccount()) { @@ -8724,7 +8723,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 } void Game::parsePlayerExtendedOpcode(uint32_t playerId, uint8_t opcode, const std::string &buffer) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8743,7 +8742,7 @@ void Game::forceRemoveCondition(uint32_t creatureId, ConditionType_t conditionTy creature->removeCondition(conditionType, conditionId, true); } -void Game::sendOfflineTrainingDialog(const std::shared_ptr &player) { +void Game::sendOfflineTrainingDialog(std::shared_ptr player) { if (!player) { return; } @@ -8754,7 +8753,7 @@ void Game::sendOfflineTrainingDialog(const std::shared_ptr &player) { } void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, uint8_t button, uint8_t choice) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8788,7 +8787,7 @@ void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, ui } void Game::playerForgeFuseItems(uint32_t playerId, uint16_t itemId, uint8_t tier, bool usedCore, bool reduceTierLoss) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8813,7 +8812,7 @@ void Game::playerForgeFuseItems(uint32_t playerId, uint16_t itemId, uint8_t tier } void Game::playerForgeTransferItemTier(uint32_t playerId, uint16_t donorItemId, uint8_t tier, uint16_t receiveItemId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8822,7 +8821,7 @@ void Game::playerForgeTransferItemTier(uint32_t playerId, uint16_t donorItemId, } void Game::playerForgeResourceConversion(uint32_t playerId, uint8_t action) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8837,7 +8836,7 @@ void Game::playerForgeResourceConversion(uint32_t playerId, uint8_t action) { } void Game::playerBrowseForgeHistory(uint32_t playerId, uint8_t page) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8852,7 +8851,7 @@ void Game::playerBrowseForgeHistory(uint32_t playerId, uint8_t page) { } void Game::playerBosstiarySlot(uint32_t playerId, uint8_t slotId, uint32_t selectedBossId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -8878,7 +8877,7 @@ void Game::playerBosstiarySlot(uint32_t playerId, uint8_t slotId, uint32_t selec } void Game::playerSetMonsterPodium(uint32_t playerId, uint32_t monsterRaceId, const Position &pos, uint8_t stackPos, const uint16_t itemId, uint8_t direction, const std::pair &podiumAndMonsterVisible) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || pos.x == 0xFFFF) { return; } @@ -8974,14 +8973,14 @@ void Game::playerSetMonsterPodium(uint32_t playerId, uint32_t monsterRaceId, con // Send to client for (auto spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendUpdateTileItem(tile, pos, item); } } } void Game::playerRotatePodium(uint32_t playerId, const Position &pos, uint8_t stackPos, const uint16_t itemId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -9066,7 +9065,7 @@ void Game::playerRotatePodium(uint32_t playerId, const Position &pos, uint8_t st } void Game::playerRequestInventoryImbuements(uint32_t playerId, bool isTrackerOpen) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player || player->isRemoved()) { return; } @@ -9098,7 +9097,7 @@ void Game::playerRequestInventoryImbuements(uint32_t playerId, bool isTrackerOpe } void Game::playerOpenWheel(uint32_t playerId, uint32_t ownerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -9118,7 +9117,7 @@ void Game::playerOpenWheel(uint32_t playerId, uint32_t ownerId) { } void Game::playerSaveWheel(uint32_t playerId, NetworkMessage &msg) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -9136,7 +9135,7 @@ void Game::playerSaveWheel(uint32_t playerId, NetworkMessage &msg) { ********************/ void Game::updatePlayerSaleItems(uint32_t playerId) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -9146,14 +9145,14 @@ void Game::updatePlayerSaleItems(uint32_t playerId) { player->setScheduledSaleUpdate(false); } -void Game::addPlayer(const std::shared_ptr &player) { +void Game::addPlayer(std::shared_ptr player) { const std::string &lowercase_name = asLowerCaseString(player->getName()); mappedPlayerNames[lowercase_name] = player; wildcardTree.insert(lowercase_name); players[player->getID()] = player; } -void Game::removePlayer(const std::shared_ptr &player) { +void Game::removePlayer(std::shared_ptr player) { const std::string &lowercase_name = asLowerCaseString(player->getName()); mappedPlayerNames.erase(lowercase_name); wildcardTree.remove(lowercase_name); @@ -9329,7 +9328,7 @@ void Game::sendUpdateCreature(std::shared_ptr creature) { SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true); for (auto spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (const auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendUpdateCreature(creature); } } @@ -9641,7 +9640,7 @@ bool Game::addInfluencedMonster(std::shared_ptr monster) { return false; } -bool Game::addItemStoreInbox(const std::shared_ptr &player, uint32_t itemId) { +bool Game::addItemStoreInbox(std::shared_ptr player, uint32_t itemId) { std::shared_ptr decoKit = Item::CreateItem(ITEM_DECORATION_KIT, 1); if (!decoKit) { return false; @@ -9673,7 +9672,7 @@ bool Game::addItemStoreInbox(const std::shared_ptr &player, uint32_t ite return true; } -void Game::addPlayerUniqueLogin(const std::shared_ptr &player) { +void Game::addPlayerUniqueLogin(std::shared_ptr player) { if (!player) { g_logger().error("Attempted to add null player to unique player names list"); return; @@ -9703,7 +9702,7 @@ void Game::removePlayerUniqueLogin(const std::string &playerName) { m_uniqueLoginPlayerNames.erase(lowercase_name); } -void Game::removePlayerUniqueLogin(const std::shared_ptr &player) { +void Game::removePlayerUniqueLogin(std::shared_ptr player) { if (!player) { g_logger().error("Attempted to remove null player from unique player names list."); return; @@ -9714,7 +9713,7 @@ void Game::removePlayerUniqueLogin(const std::shared_ptr &player) { } void Game::playerCheckActivity(const std::string &playerName, int interval) { - const auto &player = getPlayerUniqueLogin(playerName); + std::shared_ptr player = getPlayerUniqueLogin(playerName); if (!player) { return; } @@ -9747,7 +9746,7 @@ void Game::playerCheckActivity(const std::string &playerName, int interval) { } void Game::playerRewardChestCollect(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, uint32_t maxMoveItems /* = 0*/) { - const auto &player = getPlayerByID(playerId); + std::shared_ptr player = getPlayerByID(playerId); if (!player) { return; } @@ -9789,7 +9788,7 @@ void Game::playerRewardChestCollect(uint32_t playerId, const Position &pos, uint } } -bool Game::tryRetrieveStashItems(const std::shared_ptr &player, std::shared_ptr item) { +bool Game::tryRetrieveStashItems(std::shared_ptr player, std::shared_ptr item) { return internalCollectLootItems(player, item, OBJECTCATEGORY_STASHRETRIEVE) == RETURNVALUE_NOERROR; } diff --git a/src/game/game.hpp b/src/game/game.hpp index 0858546d946..eb6de64001a 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -98,8 +98,8 @@ class Game { teamFinderMap.erase(leaderGuid); } - std::shared_ptr internalGetCylinder(const std::shared_ptr &player, const Position &pos); - std::shared_ptr internalGetThing(const std::shared_ptr &player, const Position &pos, int32_t index, uint32_t itemId, StackPosType_t type); + std::shared_ptr internalGetCylinder(std::shared_ptr player, const Position &pos); + std::shared_ptr internalGetThing(std::shared_ptr player, const Position &pos, int32_t index, uint32_t itemId, StackPosType_t type); static void internalGetPosition(std::shared_ptr item, Position &pos, uint8_t &stackpos); static std::string getTradeErrorDescription(ReturnValue ret, std::shared_ptr item); @@ -118,7 +118,7 @@ class Game { std::shared_ptr getPlayerByName(const std::string &s, bool allowOffline = false); - std::shared_ptr getPlayerByGUID(const uint32_t &guid, bool allowOffline = false); + std::shared_ptr getPlayerByGUID(const uint32_t &guid); ReturnValue getPlayerByNameWildcard(const std::string &s, std::shared_ptr &player); @@ -176,14 +176,14 @@ class Game { ReturnValue internalMoveCreature(std::shared_ptr creature, Direction direction, uint32_t flags = 0); ReturnValue internalMoveCreature(const std::shared_ptr &creature, const std::shared_ptr &toTile, uint32_t flags = 0); - ReturnValue checkMoveItemToCylinder(const std::shared_ptr &player, std::shared_ptr fromCylinder, std::shared_ptr toCylinder, std::shared_ptr item, Position toPos); + ReturnValue checkMoveItemToCylinder(std::shared_ptr player, std::shared_ptr fromCylinder, std::shared_ptr toCylinder, std::shared_ptr item, Position toPos); ReturnValue internalMoveItem(std::shared_ptr fromCylinder, std::shared_ptr toCylinder, int32_t index, std::shared_ptr item, uint32_t count, std::shared_ptr* movedItem, uint32_t flags = 0, std::shared_ptr actor = nullptr, std::shared_ptr tradeItem = nullptr, bool checkTile = true); ReturnValue internalAddItem(std::shared_ptr toCylinder, std::shared_ptr item, int32_t index = INDEX_WHEREEVER, uint32_t flags = 0, bool test = false); ReturnValue internalAddItem(std::shared_ptr toCylinder, std::shared_ptr item, int32_t index, uint32_t flags, bool test, uint32_t &remainderCount); ReturnValue internalRemoveItem(std::shared_ptr item, int32_t count = -1, bool test = false, uint32_t flags = 0, bool force = false); - ReturnValue internalPlayerAddItem(const std::shared_ptr &player, std::shared_ptr item, bool dropOnMap = true, Slots_t slot = CONST_SLOT_WHEREEVER); + ReturnValue internalPlayerAddItem(std::shared_ptr player, std::shared_ptr item, bool dropOnMap = true, Slots_t slot = CONST_SLOT_WHEREEVER); std::shared_ptr findItemOfType(std::shared_ptr cylinder, uint16_t itemId, bool depthSearch = true, int32_t subType = -1) const; @@ -241,30 +241,30 @@ class Game { void playerRequestInventoryImbuements(uint32_t playerId, bool isTrackerOpen); - bool addItemStoreInbox(const std::shared_ptr &player, uint32_t itemId); + bool addItemStoreInbox(std::shared_ptr player, uint32_t itemId); void playerRewardChestCollect(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, uint32_t maxMoveItems = 0); void playerReportRuleViolationReport(uint32_t playerId, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation); - void playerCyclopediaCharacterInfo(const std::shared_ptr &player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page); + void playerCyclopediaCharacterInfo(std::shared_ptr player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page); - void playerHighscores(const std::shared_ptr &player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &worldName, uint16_t page, uint8_t entriesPerPage); + void playerHighscores(std::shared_ptr player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &worldName, uint16_t page, uint8_t entriesPerPage); void updatePlayerSaleItems(uint32_t playerId); - bool internalStartTrade(const std::shared_ptr &player, const std::shared_ptr &partner, std::shared_ptr tradeItem); - void internalCloseTrade(const std::shared_ptr &player); - bool playerBroadcastMessage(const std::shared_ptr &player, const std::string &text) const; + bool internalStartTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr tradeItem); + void internalCloseTrade(std::shared_ptr player); + bool playerBroadcastMessage(std::shared_ptr player, const std::string &text) const; void broadcastMessage(const std::string &text, MessageClasses type) const; // Implementation of player invoked events void playerTeleport(uint32_t playerId, const Position &pos); void playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count); void playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, const Position &movingCreatureOrigPos, const Position &toPos); - void playerMoveCreature(const std::shared_ptr &playerId, std::shared_ptr movingCreature, const Position &movingCreatureOrigPos, std::shared_ptr toTile); + void playerMoveCreature(std::shared_ptr playerId, std::shared_ptr movingCreature, const Position &movingCreatureOrigPos, std::shared_ptr toTile); void playerMoveItemByPlayerID(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count); - void playerMoveItem(const std::shared_ptr &player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder); + void playerMoveItem(std::shared_ptr player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder); void playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier = false, uint8_t tier = 0); void playerMove(uint32_t playerId, Direction direction); void forcePlayerMove(uint32_t playerId, Direction direction); @@ -312,7 +312,7 @@ class Game { void playerLookAt(uint32_t playerId, uint16_t itemId, const Position &pos, uint8_t stackPos); void playerLookInBattleList(uint32_t playerId, uint32_t creatureId); void playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, std::shared_ptr defaultItem = nullptr, bool lootAllCorpses = false, bool autoLoot = false); - void playerLootAllCorpses(const std::shared_ptr &player, const Position &pos, bool lootAllCorpses); + void playerLootAllCorpses(std::shared_ptr player, const Position &pos, bool lootAllCorpses); void playerSetLootContainer(uint32_t playerId, ObjectCategory_t category, const Position &pos, uint16_t itemId, uint8_t stackPos); void playerClearLootContainer(uint32_t playerId, ObjectCategory_t category); ; @@ -325,7 +325,7 @@ class Game { void playerRequestDepotSearchItem(uint32_t playerId, uint16_t itemId, uint8_t tier); void playerRequestDepotSearchRetrieve(uint32_t playerId, uint16_t itemId, uint8_t tier, uint8_t type); void playerRequestOpenContainerFromDepotSearch(uint32_t playerId, const Position &pos); - void playerMoveThingFromDepotSearch(const std::shared_ptr &player, uint16_t itemId, uint8_t tier, uint8_t count, const Position &fromPos, const Position &toPos, bool allItems = false); + void playerMoveThingFromDepotSearch(std::shared_ptr player, uint16_t itemId, uint8_t tier, uint8_t count, const Position &fromPos, const Position &toPos, bool allItems = false); void playerRequestAddVip(uint32_t playerId, const std::string &name); void playerRequestRemoveVip(uint32_t playerId, uint32_t guid); @@ -359,7 +359,7 @@ class Game { void playerOpenWheel(uint32_t playerId, uint32_t ownerId); void playerSaveWheel(uint32_t playerId, NetworkMessage &msg); - void updatePlayerHelpers(const std::shared_ptr &player); + void updatePlayerHelpers(std::shared_ptr player); void cleanup(); void shutdown(); @@ -390,7 +390,7 @@ class Game { void updateCreatureIcon(const std::shared_ptr creature); void reloadCreature(const std::shared_ptr creature); void updateCreatureSkull(std::shared_ptr player); - void updatePlayerShield(const std::shared_ptr &player); + void updatePlayerShield(std::shared_ptr player); void updateCreatureType(std::shared_ptr creature); void updateCreatureWalkthrough(const std::shared_ptr creature); @@ -410,16 +410,16 @@ class Game { void combatGetTypeInfo(CombatType_t combatType, std::shared_ptr target, TextColor_t &color, uint16_t &effect); // Hazard combat helpers - void handleHazardSystemAttack(CombatDamage &damage, const std::shared_ptr &player, const std::shared_ptr monster, bool isPlayerAttacker); - void notifySpectators(const SpectatorHashSet &spectators, const Position &targetPos, const std::shared_ptr &attackerPlayer, std::shared_ptr targetMonster); + void handleHazardSystemAttack(CombatDamage &damage, std::shared_ptr player, const std::shared_ptr monster, bool isPlayerAttacker); + void notifySpectators(const SpectatorHashSet &spectators, const Position &targetPos, std::shared_ptr attackerPlayer, std::shared_ptr targetMonster); // Wheel of destiny combat helpers - void applyWheelOfDestinyHealing(CombatDamage &damage, const std::shared_ptr &attackerPlayer, std::shared_ptr target); - void applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, const std::shared_ptr &attackerPlayer, std::shared_ptr target) const; + void applyWheelOfDestinyHealing(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr target); + void applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, std::shared_ptr attackerPlayer, std::shared_ptr target) const; int32_t applyHealthChange(CombatDamage &damage, std::shared_ptr target) const; bool combatChangeHealth(std::shared_ptr attacker, std::shared_ptr target, CombatDamage &damage, bool isEvent = false); - void applyCharmRune(std::shared_ptr targetMonster, const std::shared_ptr &attackerPlayer, std::shared_ptr target, const int32_t &realDamage) const; + void applyCharmRune(std::shared_ptr targetMonster, std::shared_ptr attackerPlayer, std::shared_ptr target, const int32_t &realDamage) const; void applyManaLeech( std::shared_ptr attackerPlayer, std::shared_ptr targetMonster, std::shared_ptr target, const CombatDamage &damage, const int32_t &realDamage @@ -434,8 +434,8 @@ class Game { // Animation help functions void addCreatureHealth(const std::shared_ptr target); static void addCreatureHealth(const SpectatorHashSet &spectators, const std::shared_ptr target); - void addPlayerMana(const std::shared_ptr &target); - void addPlayerVocation(const std::shared_ptr &target); + void addPlayerMana(const std::shared_ptr target); + void addPlayerVocation(const std::shared_ptr target); void addMagicEffect(const Position &pos, uint16_t effect); static void addMagicEffect(const SpectatorHashSet &spectators, const Position &pos, uint16_t effect); void removeMagicEffect(const Position &pos, uint16_t effect); @@ -461,7 +461,7 @@ class Game { motdNum++; } - void sendOfflineTrainingDialog(const std::shared_ptr &player); + void sendOfflineTrainingDialog(std::shared_ptr player); const std::map> &getItemsPrice() const { return itemsPriceMap; @@ -480,8 +480,8 @@ class Game { return itemsClassifications; } - void addPlayer(const std::shared_ptr &player); - void removePlayer(const std::shared_ptr &player); + void addPlayer(std::shared_ptr player); + void removePlayer(std::shared_ptr player); void addNpc(std::shared_ptr npc); void removeNpc(std::shared_ptr npc); @@ -528,8 +528,8 @@ class Game { tilesToClean.clear(); } - void playerInspectItem(const std::shared_ptr &player, const Position &pos); - void playerInspectItem(const std::shared_ptr &player, uint16_t itemId, uint8_t itemCount, bool cyclopedia); + void playerInspectItem(std::shared_ptr player, const Position &pos); + void playerInspectItem(std::shared_ptr player, uint16_t itemId, uint8_t itemCount, bool cyclopedia); void addCharmRune(const std::shared_ptr charm) { CharmList.push_back(charm); @@ -587,7 +587,7 @@ class Game { * * @param player A pointer to the Player object to add. */ - void addPlayerUniqueLogin(const std::shared_ptr &player); + void addPlayerUniqueLogin(std::shared_ptr player); /** * @brief Gets a player from the unique login map using their name. @@ -616,7 +616,7 @@ class Game { * * @param player A pointer to the Player object to remove. */ - void removePlayerUniqueLogin(const std::shared_ptr &player); + void removePlayerUniqueLogin(std::shared_ptr player); void playerCheckActivity(const std::string &playerName, int interval); /** @@ -629,7 +629,7 @@ class Game { * @param item Pointer to the item to be checked. * @return True if stash items can be retrieved, false otherwise. */ - bool tryRetrieveStashItems(const std::shared_ptr &player, std::shared_ptr item); + bool tryRetrieveStashItems(std::shared_ptr player, std::shared_ptr item); ReturnValue beforeCreatureZoneChange(std::shared_ptr creature, const phmap::parallel_flat_hash_set> &fromZones, const phmap::parallel_flat_hash_set> &toZones, bool force = false) const; void afterCreatureZoneChange(std::shared_ptr creature, const phmap::parallel_flat_hash_set> &fromZones, const phmap::parallel_flat_hash_set> &toZones) const; @@ -642,11 +642,11 @@ class Game { std::set fiendishMonsters; std::set influencedMonsters; void checkImbuements(); - bool playerSaySpell(const std::shared_ptr &player, SpeakClasses type, const std::string &text); - void playerWhisper(const std::shared_ptr &player, const std::string &text); - bool playerYell(const std::shared_ptr &player, const std::string &text); - bool playerSpeakTo(const std::shared_ptr &player, SpeakClasses type, const std::string &receiver, const std::string &text); - void playerSpeakToNpc(const std::shared_ptr &player, const std::string &text); + bool playerSaySpell(std::shared_ptr player, SpeakClasses type, const std::string &text); + void playerWhisper(std::shared_ptr player, const std::string &text); + bool playerYell(std::shared_ptr player, const std::string &text); + bool playerSpeakTo(std::shared_ptr player, SpeakClasses type, const std::string &receiver, const std::string &text); + void playerSpeakToNpc(std::shared_ptr player, const std::string &text); std::shared_ptr createPlayerTask(uint32_t delay, std::function f, std::string context) const; /** @@ -654,7 +654,7 @@ class Game { * \param player Player pointer * \param corpse Container pointer to be looted */ - void internalQuickLootCorpse(const std::shared_ptr &player, std::shared_ptr corpse); + void internalQuickLootCorpse(std::shared_ptr player, std::shared_ptr corpse); /** * @brief Finds the container for loot based on the given parameters. @@ -668,7 +668,7 @@ class Game { * * @return Pointer to the loot container or nullptr if not found. */ - std::shared_ptr findLootContainer(const std::shared_ptr &player, bool &fallbackConsumed, ObjectCategory_t category); + std::shared_ptr findLootContainer(std::shared_ptr player, bool &fallbackConsumed, ObjectCategory_t category); /** * @brief Finds the next available sub-container within a container. @@ -689,7 +689,7 @@ class Game { * @param fallbackConsumed Reference to a boolean flag indicating whether a fallback has been consumed. * @return True if fallback logic was handled, false otherwise. */ - bool handleFallbackLogic(const std::shared_ptr &player, std::shared_ptr &lootContainer, ContainerIterator &containerIterator, const bool &fallbackConsumed); + bool handleFallbackLogic(std::shared_ptr player, std::shared_ptr &lootContainer, ContainerIterator &containerIterator, const bool &fallbackConsumed); /** * @brief Processes the movement or addition of an item to a loot container. @@ -700,7 +700,7 @@ class Game { * @param player Pointer to the player object. * @return Return value indicating success or error. */ - ReturnValue processMoveOrAddItemToLootContainer(std::shared_ptr item, std::shared_ptr lootContainer, uint32_t &remainderCount, const std::shared_ptr &player); + ReturnValue processMoveOrAddItemToLootContainer(std::shared_ptr item, std::shared_ptr lootContainer, uint32_t &remainderCount, std::shared_ptr player); /** * @brief Processes loot items and places them into the appropriate containers. @@ -711,7 +711,7 @@ class Game { * @param fallbackConsumed Reference to a boolean flag indicating whether a fallback has been consumed. * @return Return value indicating success or error. */ - ReturnValue processLootItems(const std::shared_ptr &player, std::shared_ptr lootContainer, std::shared_ptr item, bool &fallbackConsumed); + ReturnValue processLootItems(std::shared_ptr player, std::shared_ptr lootContainer, std::shared_ptr item, bool &fallbackConsumed); /** * @brief Internally collects loot items from a given item and places them into the loot container. @@ -721,7 +721,7 @@ class Game { * @param category Category of the item (default is OBJECTCATEGORY_DEFAULT). * @return Return value indicating success or error. */ - ReturnValue internalCollectLootItems(const std::shared_ptr &player, std::shared_ptr item, ObjectCategory_t category = OBJECTCATEGORY_DEFAULT); + ReturnValue internalCollectLootItems(std::shared_ptr player, std::shared_ptr item, ObjectCategory_t category = OBJECTCATEGORY_DEFAULT); /** * @brief Collects items from the reward chest. @@ -730,7 +730,7 @@ class Game { * @param maxMoveItems Maximum number of items to move (default is 0, which means no limit). * @return Return value indicating success or error. */ - ReturnValue collectRewardChestItems(const std::shared_ptr &player, uint32_t maxMoveItems = 0); + ReturnValue collectRewardChestItems(std::shared_ptr player, uint32_t maxMoveItems = 0); phmap::flat_hash_map> m_uniqueLoginPlayerNames; phmap::flat_hash_map> players; @@ -816,7 +816,7 @@ class Game { const SpectatorHashSet &spectators, int32_t realDamage ); - void updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, const std::shared_ptr &player) const; + void updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, std::shared_ptr player) const; void sendEffects( std::shared_ptr target, const CombatDamage &damage, const Position &targetPos, @@ -848,7 +848,7 @@ class Game { const std::string &damageString, std::string &spectatorMessage ) const; - void unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* house, const std::shared_ptr &player); + void unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* house, std::shared_ptr player); // Variable members (m_) std::unique_ptr m_IOWheel; diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index 5278435d5cd..b89c7257c63 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -49,7 +49,7 @@ void IOLoginDataLoad::loadItems(ItemsMap &itemsMap, DBResult_ptr result, const s } } -bool IOLoginDataLoad::preLoadPlayer(const std::shared_ptr &player, const std::string &name) { +bool IOLoginDataLoad::preLoadPlayer(std::shared_ptr player, const std::string &name) { Database &db = Database::getInstance(); std::ostringstream query; @@ -103,7 +103,7 @@ bool IOLoginDataLoad::preLoadPlayer(const std::shared_ptr &player, const return true; } -bool IOLoginDataLoad::loadPlayerFirst(const std::shared_ptr &player, DBResult_ptr result) { +bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return false; @@ -183,7 +183,7 @@ bool IOLoginDataLoad::loadPlayerFirst(const std::shared_ptr &player, DBR return true; } -void IOLoginDataLoad::loadPlayerExperience(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerExperience(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -206,7 +206,7 @@ void IOLoginDataLoad::loadPlayerExperience(const std::shared_ptr &player } } -void IOLoginDataLoad::loadPlayerBlessings(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerBlessings(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -219,7 +219,7 @@ void IOLoginDataLoad::loadPlayerBlessings(const std::shared_ptr &player, } } -void IOLoginDataLoad::loadPlayerConditions(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerConditions(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -239,7 +239,7 @@ void IOLoginDataLoad::loadPlayerConditions(const std::shared_ptr &player } } -void IOLoginDataLoad::loadPlayerDefaultOutfit(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerDefaultOutfit(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -270,7 +270,7 @@ void IOLoginDataLoad::loadPlayerDefaultOutfit(const std::shared_ptr &pla player->currentOutfit = player->defaultOutfit; } -void IOLoginDataLoad::loadPlayerSkullSystem(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerSkullSystem(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -292,7 +292,7 @@ void IOLoginDataLoad::loadPlayerSkullSystem(const std::shared_ptr &playe } } -void IOLoginDataLoad::loadPlayerSkill(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerSkill(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -314,7 +314,7 @@ void IOLoginDataLoad::loadPlayerSkill(const std::shared_ptr &player, DBR } } -void IOLoginDataLoad::loadPlayerKills(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerKills(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -333,7 +333,7 @@ void IOLoginDataLoad::loadPlayerKills(const std::shared_ptr &player, DBR } } -void IOLoginDataLoad::loadPlayerGuild(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerGuild(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -383,7 +383,7 @@ void IOLoginDataLoad::loadPlayerGuild(const std::shared_ptr &player, DBR } } -void IOLoginDataLoad::loadPlayerStashItems(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerStashItems(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -399,7 +399,7 @@ void IOLoginDataLoad::loadPlayerStashItems(const std::shared_ptr &player } } -void IOLoginDataLoad::loadPlayerBestiaryCharms(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerBestiaryCharms(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -452,7 +452,7 @@ void IOLoginDataLoad::loadPlayerBestiaryCharms(const std::shared_ptr &pl } } -void IOLoginDataLoad::loadPlayerInstantSpellList(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerInstantSpellList(std::shared_ptr player, DBResult_ptr result) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -468,7 +468,7 @@ void IOLoginDataLoad::loadPlayerInstantSpellList(const std::shared_ptr & } } -void IOLoginDataLoad::loadPlayerInventoryItems(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerInventoryItems(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -546,7 +546,7 @@ void IOLoginDataLoad::loadPlayerInventoryItems(const std::shared_ptr &pl } } -void IOLoginDataLoad::loadPlayerStoreInbox(const std::shared_ptr &player) { +void IOLoginDataLoad::loadPlayerStoreInbox(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -557,7 +557,7 @@ void IOLoginDataLoad::loadPlayerStoreInbox(const std::shared_ptr &player } } -void IOLoginDataLoad::loadRewardItems(const std::shared_ptr &player) { +void IOLoginDataLoad::loadRewardItems(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -575,7 +575,7 @@ void IOLoginDataLoad::loadRewardItems(const std::shared_ptr &player) { } } -void IOLoginDataLoad::loadPlayerDepotItems(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerDepotItems(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -615,7 +615,7 @@ void IOLoginDataLoad::loadPlayerDepotItems(const std::shared_ptr &player } } -void IOLoginDataLoad::loadPlayerInboxItems(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerInboxItems(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -652,7 +652,7 @@ void IOLoginDataLoad::loadPlayerInboxItems(const std::shared_ptr &player } } -void IOLoginDataLoad::loadPlayerStorageMap(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerStorageMap(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -668,7 +668,7 @@ void IOLoginDataLoad::loadPlayerStorageMap(const std::shared_ptr &player } } -void IOLoginDataLoad::loadPlayerVip(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerVip(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -684,7 +684,7 @@ void IOLoginDataLoad::loadPlayerVip(const std::shared_ptr &player, DBRes } } -void IOLoginDataLoad::loadPlayerPreyClass(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerPreyClass(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -731,7 +731,7 @@ void IOLoginDataLoad::loadPlayerPreyClass(const std::shared_ptr &player, } } -void IOLoginDataLoad::loadPlayerTaskHuntingClass(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerTaskHuntingClass(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -781,7 +781,7 @@ void IOLoginDataLoad::loadPlayerTaskHuntingClass(const std::shared_ptr & } } -void IOLoginDataLoad::loadPlayerForgeHistory(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerForgeHistory(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -802,7 +802,7 @@ void IOLoginDataLoad::loadPlayerForgeHistory(const std::shared_ptr &play } } -void IOLoginDataLoad::loadPlayerBosstiary(const std::shared_ptr &player, DBResult_ptr result) { +void IOLoginDataLoad::loadPlayerBosstiary(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); return; @@ -834,7 +834,7 @@ void IOLoginDataLoad::loadPlayerBosstiary(const std::shared_ptr &player, } } -void IOLoginDataLoad::bindRewardBag(const std::shared_ptr &player, ItemsMap &rewardItemsMap) { +void IOLoginDataLoad::bindRewardBag(std::shared_ptr player, ItemsMap &rewardItemsMap) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -874,7 +874,7 @@ void IOLoginDataLoad::insertItemsIntoRewardBag(const ItemsMap &rewardItemsMap) { } } -void IOLoginDataLoad::loadPlayerInitializeSystem(const std::shared_ptr &player) { +void IOLoginDataLoad::loadPlayerInitializeSystem(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; @@ -888,7 +888,7 @@ void IOLoginDataLoad::loadPlayerInitializeSystem(const std::shared_ptr & player->initializeTaskHunting(); } -void IOLoginDataLoad::loadPlayerUpdateSystem(const std::shared_ptr &player) { +void IOLoginDataLoad::loadPlayerUpdateSystem(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); return; diff --git a/src/io/functions/iologindata_load_player.hpp b/src/io/functions/iologindata_load_player.hpp index 3fd45f2465d..e8b0b4094de 100644 --- a/src/io/functions/iologindata_load_player.hpp +++ b/src/io/functions/iologindata_load_player.hpp @@ -13,37 +13,37 @@ class IOLoginDataLoad : public IOLoginData { public: - static bool loadPlayerFirst(const std::shared_ptr &player, DBResult_ptr result); - static bool preLoadPlayer(const std::shared_ptr &player, const std::string &name); - static void loadPlayerExperience(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerBlessings(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerConditions(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerDefaultOutfit(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerSkullSystem(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerSkill(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerKills(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerGuild(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerStashItems(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerBestiaryCharms(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerInstantSpellList(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerInventoryItems(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerStoreInbox(const std::shared_ptr &player); - static void loadPlayerDepotItems(const std::shared_ptr &player, DBResult_ptr result); - static void loadRewardItems(const std::shared_ptr &player); - static void loadPlayerInboxItems(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerStorageMap(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerVip(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerPreyClass(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerTaskHuntingClass(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerForgeHistory(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerBosstiary(const std::shared_ptr &player, DBResult_ptr result); - static void loadPlayerInitializeSystem(const std::shared_ptr &player); - static void loadPlayerUpdateSystem(const std::shared_ptr &player); + static bool loadPlayerFirst(std::shared_ptr player, DBResult_ptr result); + static bool preLoadPlayer(std::shared_ptr player, const std::string &name); + static void loadPlayerExperience(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerBlessings(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerConditions(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerDefaultOutfit(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerSkullSystem(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerSkill(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerKills(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerGuild(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerStashItems(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerBestiaryCharms(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerInstantSpellList(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerInventoryItems(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerStoreInbox(std::shared_ptr player); + static void loadPlayerDepotItems(std::shared_ptr player, DBResult_ptr result); + static void loadRewardItems(std::shared_ptr player); + static void loadPlayerInboxItems(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerStorageMap(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerVip(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerPreyClass(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerTaskHuntingClass(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerForgeHistory(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerBosstiary(std::shared_ptr player, DBResult_ptr result); + static void loadPlayerInitializeSystem(std::shared_ptr player); + static void loadPlayerUpdateSystem(std::shared_ptr player); private: using ItemsMap = std::map, uint32_t>>; - static void bindRewardBag(const std::shared_ptr &player, ItemsMap &rewardItemsMap); + static void bindRewardBag(std::shared_ptr player, ItemsMap &rewardItemsMap); static void insertItemsIntoRewardBag(const ItemsMap &rewardItemsMap); static void loadItems(ItemsMap &itemsMap, DBResult_ptr result, const std::shared_ptr &player); diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index 6cea5af4dae..877c2483786 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -12,7 +12,7 @@ #include "io/functions/iologindata_save_player.hpp" #include "game/game.hpp" -bool IOLoginDataSave::saveItems(const std::shared_ptr &player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &propWriteStream) { +bool IOLoginDataSave::saveItems(std::shared_ptr player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &propWriteStream) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -148,7 +148,7 @@ bool IOLoginDataSave::saveItems(const std::shared_ptr &player, const Ite return true; } -bool IOLoginDataSave::savePlayerFirst(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerFirst(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -313,7 +313,7 @@ bool IOLoginDataSave::savePlayerFirst(const std::shared_ptr &player) { return true; } -bool IOLoginDataSave::savePlayerStash(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerStash(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -339,7 +339,7 @@ bool IOLoginDataSave::savePlayerStash(const std::shared_ptr &player) { return true; } -bool IOLoginDataSave::savePlayerSpells(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerSpells(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -368,7 +368,7 @@ bool IOLoginDataSave::savePlayerSpells(const std::shared_ptr &player) { return true; } -bool IOLoginDataSave::savePlayerKills(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerKills(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -397,7 +397,7 @@ bool IOLoginDataSave::savePlayerKills(const std::shared_ptr &player) { return true; } -bool IOLoginDataSave::savePlayerBestiarySystem(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerBestiarySystem(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -447,7 +447,7 @@ bool IOLoginDataSave::savePlayerBestiarySystem(const std::shared_ptr &pl return true; } -bool IOLoginDataSave::savePlayerItem(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerItem(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -479,7 +479,7 @@ bool IOLoginDataSave::savePlayerItem(const std::shared_ptr &player) { return true; } -bool IOLoginDataSave::savePlayerDepotItems(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerDepotItems(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -514,7 +514,7 @@ bool IOLoginDataSave::savePlayerDepotItems(const std::shared_ptr &player return true; } -bool IOLoginDataSave::saveRewardItems(const std::shared_ptr &player) { +bool IOLoginDataSave::saveRewardItems(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -548,7 +548,7 @@ bool IOLoginDataSave::saveRewardItems(const std::shared_ptr &player) { return true; } -bool IOLoginDataSave::savePlayerInbox(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerInbox(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -576,7 +576,7 @@ bool IOLoginDataSave::savePlayerInbox(const std::shared_ptr &player) { return true; } -bool IOLoginDataSave::savePlayerPreyClass(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerPreyClass(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -631,7 +631,7 @@ bool IOLoginDataSave::savePlayerPreyClass(const std::shared_ptr &player) return true; } -bool IOLoginDataSave::savePlayerTaskHuntingClass(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerTaskHuntingClass(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -684,7 +684,7 @@ bool IOLoginDataSave::savePlayerTaskHuntingClass(const std::shared_ptr & return true; } -bool IOLoginDataSave::savePlayerForgeHistory(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerForgeHistory(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -718,7 +718,7 @@ bool IOLoginDataSave::savePlayerForgeHistory(const std::shared_ptr &play return true; } -bool IOLoginDataSave::savePlayerBosstiary(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerBosstiary(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; @@ -762,7 +762,7 @@ bool IOLoginDataSave::savePlayerBosstiary(const std::shared_ptr &player) return true; } -bool IOLoginDataSave::savePlayerStorage(const std::shared_ptr &player) { +bool IOLoginDataSave::savePlayerStorage(std::shared_ptr player) { if (!player) { g_logger().warn("[IOLoginData::savePlayer] - Player nullptr: {}", __FUNCTION__); return false; diff --git a/src/io/functions/iologindata_save_player.hpp b/src/io/functions/iologindata_save_player.hpp index 5d6c9cac612..1c3cf89cb9c 100644 --- a/src/io/functions/iologindata_save_player.hpp +++ b/src/io/functions/iologindata_save_player.hpp @@ -13,20 +13,20 @@ class IOLoginDataSave : public IOLoginData { public: - static bool savePlayerFirst(const std::shared_ptr &player); - static bool savePlayerStash(const std::shared_ptr &player); - static bool savePlayerSpells(const std::shared_ptr &player); - static bool savePlayerKills(const std::shared_ptr &player); - static bool savePlayerBestiarySystem(const std::shared_ptr &player); - static bool savePlayerItem(const std::shared_ptr &player); - static bool savePlayerDepotItems(const std::shared_ptr &player); - static bool saveRewardItems(const std::shared_ptr &player); - static bool savePlayerInbox(const std::shared_ptr &player); - static bool savePlayerPreyClass(const std::shared_ptr &player); - static bool savePlayerTaskHuntingClass(const std::shared_ptr &player); - static bool savePlayerForgeHistory(const std::shared_ptr &player); - static bool savePlayerBosstiary(const std::shared_ptr &player); - static bool savePlayerStorage(const std::shared_ptr &palyer); + static bool savePlayerFirst(std::shared_ptr player); + static bool savePlayerStash(std::shared_ptr player); + static bool savePlayerSpells(std::shared_ptr player); + static bool savePlayerKills(std::shared_ptr player); + static bool savePlayerBestiarySystem(std::shared_ptr player); + static bool savePlayerItem(std::shared_ptr player); + static bool savePlayerDepotItems(std::shared_ptr player); + static bool saveRewardItems(std::shared_ptr player); + static bool savePlayerInbox(std::shared_ptr player); + static bool savePlayerPreyClass(std::shared_ptr player); + static bool savePlayerTaskHuntingClass(std::shared_ptr player); + static bool savePlayerForgeHistory(std::shared_ptr player); + static bool savePlayerBosstiary(std::shared_ptr player); + static bool savePlayerStorage(std::shared_ptr palyer); protected: using ItemBlockList = std::list>>; @@ -34,5 +34,5 @@ class IOLoginDataSave : public IOLoginData { using ItemRewardList = std::list>>; using ItemInboxList = std::list>>; - static bool saveItems(const std::shared_ptr &player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &stream); + static bool saveItems(std::shared_ptr player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &stream); }; diff --git a/src/io/io_bosstiary.cpp b/src/io/io_bosstiary.cpp index bc5a3563141..cda3336af9c 100644 --- a/src/io/io_bosstiary.cpp +++ b/src/io/io_bosstiary.cpp @@ -164,7 +164,7 @@ std::shared_ptr IOBosstiary::getMonsterTypeByBossRaceId(uint16_t ra return nullptr; } -void IOBosstiary::addBosstiaryKill(const std::shared_ptr &player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) const { +void IOBosstiary::addBosstiaryKill(std::shared_ptr player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) const { if (!player || !mtype) { return; } @@ -231,7 +231,7 @@ uint32_t IOBosstiary::calculateBossPoints(uint16_t lootBonus) const { return static_cast((2.5 * lootBonus * lootBonus) - (477.5 * lootBonus) + 24000); } -phmap::parallel_flat_hash_set IOBosstiary::getBosstiaryFinished(const std::shared_ptr &player, uint8_t level /* = 1*/) const { +phmap::parallel_flat_hash_set IOBosstiary::getBosstiaryFinished(std::shared_ptr player, uint8_t level /* = 1*/) const { phmap::parallel_flat_hash_set unlockedMonsters; if (!player) { return unlockedMonsters; @@ -265,7 +265,7 @@ phmap::parallel_flat_hash_set IOBosstiary::getBosstiaryFinished(const return unlockedMonsters; } -uint8_t IOBosstiary::getBossCurrentLevel(const std::shared_ptr &player, uint16_t bossId) const { +uint8_t IOBosstiary::getBossCurrentLevel(std::shared_ptr player, uint16_t bossId) const { if (bossId == 0 || !player) { return 0; } @@ -300,7 +300,7 @@ uint32_t IOBosstiary::calculteRemoveBoss(uint8_t removeTimes) const { return 300000 * removeTimes - 500000; } -std::vector IOBosstiary::getBosstiaryCooldownRaceId(const std::shared_ptr &player) const { +std::vector IOBosstiary::getBosstiaryCooldownRaceId(std::shared_ptr player) const { std::vector bossesCooldownRaceId; if (!player) { return bossesCooldownRaceId; diff --git a/src/io/io_bosstiary.hpp b/src/io/io_bosstiary.hpp index a94fd180468..bbb1367e8b8 100644 --- a/src/io/io_bosstiary.hpp +++ b/src/io/io_bosstiary.hpp @@ -60,13 +60,13 @@ class IOBosstiary { uint16_t getBoostedBossId() const; std::shared_ptr getMonsterTypeByBossRaceId(uint16_t raceId) const; - void addBosstiaryKill(const std::shared_ptr &player, const std::shared_ptr mtype, uint32_t amount = 1) const; + void addBosstiaryKill(std::shared_ptr player, const std::shared_ptr mtype, uint32_t amount = 1) const; uint16_t calculateLootBonus(uint32_t bossPoints) const; uint32_t calculateBossPoints(uint16_t lootBonus) const; - phmap::parallel_flat_hash_set getBosstiaryFinished(const std::shared_ptr &player, uint8_t level = 1) const; - uint8_t getBossCurrentLevel(const std::shared_ptr &player, uint16_t bossId) const; + phmap::parallel_flat_hash_set getBosstiaryFinished(std::shared_ptr player, uint8_t level = 1) const; + uint8_t getBossCurrentLevel(std::shared_ptr player, uint16_t bossId) const; uint32_t calculteRemoveBoss(uint8_t removeTimes) const; - std::vector getBosstiaryCooldownRaceId(const std::shared_ptr &player) const; + std::vector getBosstiaryCooldownRaceId(std::shared_ptr player) const; const std::vector &getBossRaceKillStages(BosstiaryRarity_t race) const; private: diff --git a/src/io/iobestiary.cpp b/src/io/iobestiary.cpp index 77727188a27..7e5d1c9ad55 100644 --- a/src/io/iobestiary.cpp +++ b/src/io/iobestiary.cpp @@ -17,7 +17,7 @@ SoftSingleton IOBestiary::instanceTracker("IOBestiary"); -bool IOBestiary::parseCharmCombat(const std::shared_ptr charm, const std::shared_ptr &player, std::shared_ptr target, int32_t realDamage, bool dueToPotion, bool checkArmor) { +bool IOBestiary::parseCharmCombat(const std::shared_ptr charm, std::shared_ptr player, std::shared_ptr target, int32_t realDamage, bool dueToPotion, bool checkArmor) { if (!charm || !player || !target) { return false; } @@ -146,7 +146,7 @@ uint8_t IOBestiary::getKillStatus(const std::shared_ptr mtype, uint return 4; } -void IOBestiary::resetCharmRuneCreature(const std::shared_ptr &player, const std::shared_ptr charm) { +void IOBestiary::resetCharmRuneCreature(std::shared_ptr player, const std::shared_ptr charm) { if (!player || !charm) { return; } @@ -156,7 +156,7 @@ void IOBestiary::resetCharmRuneCreature(const std::shared_ptr &player, c player->parseRacebyCharm(charm->id, true, 0); } -void IOBestiary::setCharmRuneCreature(const std::shared_ptr &player, const std::shared_ptr charm, uint16_t raceid) { +void IOBestiary::setCharmRuneCreature(std::shared_ptr player, const std::shared_ptr charm, uint16_t raceid) { if (!player || !charm) { return; } @@ -166,7 +166,7 @@ void IOBestiary::setCharmRuneCreature(const std::shared_ptr &player, con player->setUsedRunesBit(Toggle); } -std::list IOBestiary::getCharmUsedRuneBitAll(const std::shared_ptr &player) { +std::list IOBestiary::getCharmUsedRuneBitAll(std::shared_ptr player) { int32_t input = player->getUsedRunesBit(); ; int8_t i = 0; @@ -182,7 +182,7 @@ std::list IOBestiary::getCharmUsedRuneBitAll(const std::shared_ptr< return rtn; } -uint16_t IOBestiary::getBestiaryRaceUnlocked(const std::shared_ptr &player, BestiaryType_t race) const { +uint16_t IOBestiary::getBestiaryRaceUnlocked(std::shared_ptr player, BestiaryType_t race) const { if (!player) { return 0; } @@ -199,7 +199,7 @@ uint16_t IOBestiary::getBestiaryRaceUnlocked(const std::shared_ptr &play return count; } -void IOBestiary::addCharmPoints(const std::shared_ptr &player, uint16_t amount, bool negative /*= false*/) { +void IOBestiary::addCharmPoints(std::shared_ptr player, uint16_t amount, bool negative /*= false*/) { if (!player) { return; } @@ -213,7 +213,7 @@ void IOBestiary::addCharmPoints(const std::shared_ptr &player, uint16_t player->setCharmPoints(myCharms); } -void IOBestiary::addBestiaryKill(const std::shared_ptr &player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) { +void IOBestiary::addBestiaryKill(std::shared_ptr player, const std::shared_ptr mtype, uint32_t amount /*= 1*/) { uint16_t raceid = mtype->info.raceid; if (raceid == 0 || !player || !mtype) { return; @@ -241,7 +241,7 @@ void IOBestiary::addBestiaryKill(const std::shared_ptr &player, const st player->refreshCyclopediaMonsterTracker(); } -charmRune_t IOBestiary::getCharmFromTarget(const std::shared_ptr &player, const std::shared_ptr mtype) { +charmRune_t IOBestiary::getCharmFromTarget(std::shared_ptr player, const std::shared_ptr mtype) { if (!player || !mtype) { return CHARM_NONE; } @@ -283,7 +283,7 @@ int32_t IOBestiary::bitToggle(int32_t input, const std::shared_ptr charm, } } -void IOBestiary::sendBuyCharmRune(const std::shared_ptr &player, charmRune_t runeID, uint8_t action, uint16_t raceid) { +void IOBestiary::sendBuyCharmRune(std::shared_ptr player, charmRune_t runeID, uint8_t action, uint16_t raceid) { const auto charm = getBestiaryCharm(runeID); if (!player || !charm) { return; @@ -384,7 +384,7 @@ std::map IOBestiary::getMonsterElements(const std::shared_ptr< return defaultMap; } -std::map IOBestiary::getBestiaryKillCountByMonsterIDs(const std::shared_ptr &player, std::map mtype_list) const { +std::map IOBestiary::getBestiaryKillCountByMonsterIDs(std::shared_ptr player, std::map mtype_list) const { std::map raceMonsters = {}; for (const auto &it : mtype_list) { uint16_t raceid = it.first; @@ -396,7 +396,7 @@ std::map IOBestiary::getBestiaryKillCountByMonsterIDs(const return raceMonsters; } -phmap::parallel_flat_hash_set IOBestiary::getBestiaryFinished(const std::shared_ptr &player) const { +phmap::parallel_flat_hash_set IOBestiary::getBestiaryFinished(std::shared_ptr player) const { phmap::parallel_flat_hash_set finishedMonsters; auto bestiaryMap = g_game().getBestiaryList(); diff --git a/src/io/iobestiary.hpp b/src/io/iobestiary.hpp index eaaacd6cb69..26f802dcb5b 100644 --- a/src/io/iobestiary.hpp +++ b/src/io/iobestiary.hpp @@ -55,28 +55,28 @@ class IOBestiary { } std::shared_ptr getBestiaryCharm(charmRune_t activeCharm, bool force = false) const; - void addBestiaryKill(const std::shared_ptr &player, const std::shared_ptr mtype, uint32_t amount = 1); - bool parseCharmCombat(const std::shared_ptr charm, const std::shared_ptr &player, std::shared_ptr target, int32_t realDamage, bool dueToPotion = false, bool checkArmor = false); - void addCharmPoints(const std::shared_ptr &player, uint16_t amount, bool negative = false); - void sendBuyCharmRune(const std::shared_ptr &player, charmRune_t runeID, uint8_t action, uint16_t raceid); - void setCharmRuneCreature(const std::shared_ptr &player, const std::shared_ptr charm, uint16_t raceid); - void resetCharmRuneCreature(const std::shared_ptr &player, const std::shared_ptr charm); + void addBestiaryKill(std::shared_ptr player, const std::shared_ptr mtype, uint32_t amount = 1); + bool parseCharmCombat(const std::shared_ptr charm, std::shared_ptr player, std::shared_ptr target, int32_t realDamage, bool dueToPotion = false, bool checkArmor = false); + void addCharmPoints(std::shared_ptr player, uint16_t amount, bool negative = false); + void sendBuyCharmRune(std::shared_ptr player, charmRune_t runeID, uint8_t action, uint16_t raceid); + void setCharmRuneCreature(std::shared_ptr player, const std::shared_ptr charm, uint16_t raceid); + void resetCharmRuneCreature(std::shared_ptr player, const std::shared_ptr charm); int8_t calculateDifficult(uint32_t chance) const; uint8_t getKillStatus(const std::shared_ptr mtype, uint32_t killAmount) const; - uint16_t getBestiaryRaceUnlocked(const std::shared_ptr &player, BestiaryType_t race) const; + uint16_t getBestiaryRaceUnlocked(std::shared_ptr player, BestiaryType_t race) const; int32_t bitToggle(int32_t input, const std::shared_ptr charm, bool on) const; bool hasCharmUnlockedRuneBit(const std::shared_ptr charm, int32_t input) const; - std::list getCharmUsedRuneBitAll(const std::shared_ptr &player); - phmap::parallel_flat_hash_set getBestiaryFinished(const std::shared_ptr &player) const; + std::list getCharmUsedRuneBitAll(std::shared_ptr player); + phmap::parallel_flat_hash_set getBestiaryFinished(std::shared_ptr player) const; - charmRune_t getCharmFromTarget(const std::shared_ptr &player, const std::shared_ptr mtype); + charmRune_t getCharmFromTarget(std::shared_ptr player, const std::shared_ptr mtype); - std::map getBestiaryKillCountByMonsterIDs(const std::shared_ptr &player, std::map mtype_list) const; + std::map getBestiaryKillCountByMonsterIDs(std::shared_ptr player, std::map mtype_list) const; std::map getMonsterElements(const std::shared_ptr mtype) const; std::map findRaceByName(const std::string &race, bool Onlystring = true, BestiaryType_t raceNumber = BESTY_RACE_NONE) const; diff --git a/src/io/iologindata.cpp b/src/io/iologindata.cpp index dab83adc60e..db32e581ec2 100644 --- a/src/io/iologindata.cpp +++ b/src/io/iologindata.cpp @@ -85,21 +85,21 @@ void IOLoginData::updateOnlineStatus(uint32_t guid, bool login) { } // The boolean "disable" will desactivate the loading of information that is not relevant to the preload, for example, forge, bosstiary, etc. None of this we need to access if the player is offline -bool IOLoginData::loadPlayerById(const std::shared_ptr &player, uint32_t id, bool disable /* = true*/) { +bool IOLoginData::loadPlayerById(std::shared_ptr player, uint32_t id, bool disable /* = true*/) { Database &db = Database::getInstance(); std::ostringstream query; query << "SELECT * FROM `players` WHERE `id` = " << id; return loadPlayer(player, db.storeQuery(query.str()), disable); } -bool IOLoginData::loadPlayerByName(const std::shared_ptr &player, const std::string &name, bool disable /* = true*/) { +bool IOLoginData::loadPlayerByName(std::shared_ptr player, const std::string &name, bool disable /* = true*/) { Database &db = Database::getInstance(); std::ostringstream query; query << "SELECT * FROM `players` WHERE `name` = " << db.escapeString(name); return loadPlayer(player, db.storeQuery(query.str()), disable); } -bool IOLoginData::loadPlayer(const std::shared_ptr &player, DBResult_ptr result, bool disable /* = false*/) { +bool IOLoginData::loadPlayer(std::shared_ptr player, DBResult_ptr result, bool disable /* = false*/) { if (!result || !player) { g_logger().warn("[IOLoginData::loadPlayer] - Player or Resultnullptr: {}", __FUNCTION__); return false; @@ -185,7 +185,7 @@ bool IOLoginData::loadPlayer(const std::shared_ptr &player, DBResult_ptr } } -bool IOLoginData::savePlayer(const std::shared_ptr &player) { +bool IOLoginData::savePlayer(std::shared_ptr player) { bool success = DBTransaction::executeWithinTransaction([player]() { return savePlayerGuard(player); }); @@ -197,7 +197,7 @@ bool IOLoginData::savePlayer(const std::shared_ptr &player) { return success; } -bool IOLoginData::savePlayerGuard(const std::shared_ptr &player) { +bool IOLoginData::savePlayerGuard(std::shared_ptr player) { if (!player) { throw DatabaseException("Player nullptr in function: " + std::string(__FUNCTION__)); } diff --git a/src/io/iologindata.hpp b/src/io/iologindata.hpp index 8cf44133c1c..724967d2877 100644 --- a/src/io/iologindata.hpp +++ b/src/io/iologindata.hpp @@ -20,10 +20,10 @@ class IOLoginData { static bool gameWorldAuthentication(const std::string &accountDescriptor, const std::string &sessionOrPassword, std::string &characterName, uint32_t &accountId, bool oldProcotol); static account::AccountType getAccountType(uint32_t accountId); static void updateOnlineStatus(uint32_t guid, bool login); - static bool loadPlayerById(const std::shared_ptr &player, uint32_t id, bool disable = true); - static bool loadPlayerByName(const std::shared_ptr &player, const std::string &name, bool disable = true); - static bool loadPlayer(const std::shared_ptr &player, DBResult_ptr result, bool disable = true); - static bool savePlayer(const std::shared_ptr &player); + static bool loadPlayerById(std::shared_ptr player, uint32_t id, bool disable = true); + static bool loadPlayerByName(std::shared_ptr player, const std::string &name, bool disable = true); + static bool loadPlayer(std::shared_ptr player, DBResult_ptr result, bool disable = true); + static bool savePlayer(std::shared_ptr player); static uint32_t getGuidByName(const std::string &name); static bool getGuidByNameEx(uint32_t &guid, bool &specialVip, std::string &name); static std::string getNameByGuid(uint32_t guid); @@ -37,5 +37,5 @@ class IOLoginData { static void removeVIPEntry(uint32_t accountId, uint32_t guid); private: - static bool savePlayerGuard(const std::shared_ptr &player); + static bool savePlayerGuard(std::shared_ptr player); }; diff --git a/src/io/ioprey.cpp b/src/io/ioprey.cpp index 6876311e9f7..449383a1b87 100644 --- a/src/io/ioprey.cpp +++ b/src/io/ioprey.cpp @@ -246,7 +246,7 @@ void TaskHuntingSlot::reloadReward() { } // Prey/Task hunting global class -void IOPrey::CheckPlayerPreys(const std::shared_ptr &player, uint8_t amount) const { +void IOPrey::CheckPlayerPreys(std::shared_ptr player, uint8_t amount) const { if (!player) { return; } @@ -289,7 +289,7 @@ void IOPrey::CheckPlayerPreys(const std::shared_ptr &player, uint8_t amo } } -void IOPrey::ParsePreyAction(const std::shared_ptr &player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const { +void IOPrey::ParsePreyAction(std::shared_ptr player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const { PreySlot* slot = player->getPreySlotById(slotId); if (!slot || slot->state == PreyDataState_Locked) { player->sendMessageDialog("To unlock this prey slot first you must buy it on store."); @@ -389,7 +389,7 @@ void IOPrey::ParsePreyAction(const std::shared_ptr &player, PreySlot_t s player->reloadPreySlot(slotId); } -void IOPrey::ParseTaskHuntingAction(const std::shared_ptr &player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const { +void IOPrey::ParseTaskHuntingAction(std::shared_ptr player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const { TaskHuntingSlot* slot = player->getTaskHuntingSlotById(slotId); if (!slot || slot->state == PreyTaskDataState_Locked) { player->sendMessageDialog("To unlock this task hunting slot first you must buy it on store."); diff --git a/src/io/ioprey.hpp b/src/io/ioprey.hpp index 16e734bbb0a..5885615d225 100644 --- a/src/io/ioprey.hpp +++ b/src/io/ioprey.hpp @@ -217,10 +217,10 @@ class IOPrey { return inject(); } - void CheckPlayerPreys(const std::shared_ptr &player, uint8_t amount) const; - void ParsePreyAction(const std::shared_ptr &player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const; + void CheckPlayerPreys(std::shared_ptr player, uint8_t amount) const; + void ParsePreyAction(std::shared_ptr player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const; - void ParseTaskHuntingAction(const std::shared_ptr &player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const; + void ParseTaskHuntingAction(std::shared_ptr player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const; void InitializeTaskHuntOptions(); TaskHuntingOption* GetTaskRewardOption(const TaskHuntingSlot* slot) const; diff --git a/src/items/bed.cpp b/src/items/bed.cpp index 97fbeca870e..2f029cb1eea 100644 --- a/src/items/bed.cpp +++ b/src/items/bed.cpp @@ -78,7 +78,7 @@ std::shared_ptr BedItem::getNextBedItem() { return tile->getBedItem(); } -bool BedItem::canUse(const std::shared_ptr &player) { +bool BedItem::canUse(std::shared_ptr player) { if ((player == nullptr) || (house == nullptr) || !player->isPremium()) { return false; } @@ -110,7 +110,7 @@ bool BedItem::canUse(const std::shared_ptr &player) { return true; } -bool BedItem::trySleep(const std::shared_ptr &player) { +bool BedItem::trySleep(std::shared_ptr player) { if (!house || player->isRemoved()) { return false; } @@ -126,7 +126,7 @@ bool BedItem::trySleep(const std::shared_ptr &player) { return true; } -bool BedItem::sleep(const std::shared_ptr &player) { +bool BedItem::sleep(std::shared_ptr player) { if (house == nullptr) { return false; } @@ -165,7 +165,7 @@ bool BedItem::sleep(const std::shared_ptr &player) { return true; } -void BedItem::wakeUp(const std::shared_ptr &player) { +void BedItem::wakeUp(std::shared_ptr player) { if (house == nullptr) { return; } @@ -206,7 +206,7 @@ void BedItem::wakeUp(const std::shared_ptr &player) { } } -void BedItem::regeneratePlayer(const std::shared_ptr &player) const { +void BedItem::regeneratePlayer(std::shared_ptr player) const { const uint32_t sleptTime = time(nullptr) - sleepStart; Condition* condition = player->getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT); @@ -232,7 +232,7 @@ void BedItem::regeneratePlayer(const std::shared_ptr &player) const { player->changeSoul(soulRegen); } -void BedItem::updateAppearance(const std::shared_ptr &player) { +void BedItem::updateAppearance(std::shared_ptr player) { const ItemType &it = Item::items[id]; if (it.type == ITEM_TYPE_BED) { if ((player != nullptr) && it.transformToOnUse[player->getSex()] != 0) { @@ -249,7 +249,7 @@ void BedItem::updateAppearance(const std::shared_ptr &player) { } } -void BedItem::internalSetSleeper(const std::shared_ptr &player) { +void BedItem::internalSetSleeper(std::shared_ptr player) { std::string desc_str = player->getName() + " is sleeping there."; sleeperGUID = player->getGUID(); diff --git a/src/items/bed.hpp b/src/items/bed.hpp index ebd91e29817..bdacbd88204 100644 --- a/src/items/bed.hpp +++ b/src/items/bed.hpp @@ -37,20 +37,20 @@ class BedItem final : public Item { house = h; } - bool canUse(const std::shared_ptr &player); + bool canUse(std::shared_ptr player); - bool trySleep(const std::shared_ptr &player); - bool sleep(const std::shared_ptr &player); - void wakeUp(const std::shared_ptr &player); + bool trySleep(std::shared_ptr player); + bool sleep(std::shared_ptr player); + void wakeUp(std::shared_ptr player); std::shared_ptr getNextBedItem(); friend class MapCache; private: - void updateAppearance(const std::shared_ptr &player); - void regeneratePlayer(const std::shared_ptr &player) const; - void internalSetSleeper(const std::shared_ptr &player); + void updateAppearance(std::shared_ptr player); + void regeneratePlayer(std::shared_ptr player) const; + void internalSetSleeper(std::shared_ptr player); void internalRemoveSleeper(); House* house = nullptr; diff --git a/src/items/containers/mailbox/mailbox.cpp b/src/items/containers/mailbox/mailbox.cpp index 8a83d48a49f..bfc732939e0 100644 --- a/src/items/containers/mailbox/mailbox.cpp +++ b/src/items/containers/mailbox/mailbox.cpp @@ -90,7 +90,7 @@ bool Mailbox::sendItem(std::shared_ptr item) const { } } - const auto player = g_game().getPlayerByName(receiver, true); + std::shared_ptr player = g_game().getPlayerByName(receiver, true); std::string writer; time_t date = time(0); std::string text; diff --git a/src/items/decay/decay.cpp b/src/items/decay/decay.cpp index 23759e5dc24..77c7eb9f3f1 100644 --- a/src/items/decay/decay.cpp +++ b/src/items/decay/decay.cpp @@ -56,57 +56,54 @@ void Decay::startDecay(std::shared_ptr item) { } void Decay::stopDecay(std::shared_ptr item) { - g_logger().debug("[Decay::stopDecay] - Stopping decay for item id: {}", item->getID()); - if (!item->hasAttribute(ItemAttribute_t::DECAYSTATE)) { - return; - } - - if (item->hasAttribute(ItemAttribute_t::DURATION_TIMESTAMP)) { + if (item->hasAttribute(ItemAttribute_t::DECAYSTATE)) { auto timestamp = item->getAttribute(ItemAttribute_t::DURATION_TIMESTAMP); - auto it = decayMap.find(timestamp); - if (it != decayMap.end()) { - auto &decayItems = it->second; - - size_t i = 0, end = decayItems.size(); - auto decayItem = decayItems[i]; - if (end == 1) { - if (item == decayItem) { - if (item->hasAttribute(ItemAttribute_t::DURATION)) { - // Incase we removed duration attribute don't assign new duration - item->setDuration(item->getDuration()); + if (item->hasAttribute(ItemAttribute_t::DURATION_TIMESTAMP)) { + auto it = decayMap.find(timestamp); + if (it != decayMap.end()) { + auto &decayItems = it->second; + + size_t i = 0, end = decayItems.size(); + auto decayItem = decayItems[i]; + if (end == 1) { + if (item == decayItem) { + if (item->hasAttribute(ItemAttribute_t::DURATION)) { + // Incase we removed duration attribute don't assign new duration + item->setDuration(item->getDuration()); + } + item->removeAttribute(ItemAttribute_t::DECAYSTATE); + + decayMap.erase(it); } - item->removeAttribute(ItemAttribute_t::DECAYSTATE); - - decayMap.erase(it); + return; } - return; - } - while (i < end) { - decayItem = decayItems[i]; - if (item == decayItem) { - if (item->hasAttribute(ItemAttribute_t::DURATION)) { - // Incase we removed duration attribute don't assign new duration - item->setDuration(item->getDuration()); + while (i < end) { + decayItem = decayItems[i]; + if (item == decayItem) { + if (item->hasAttribute(ItemAttribute_t::DURATION)) { + // Incase we removed duration attribute don't assign new duration + item->setDuration(item->getDuration()); + } + item->removeAttribute(ItemAttribute_t::DECAYSTATE); + + decayItems[i] = decayItems.back(); + decayItems.pop_back(); + return; } - item->removeAttribute(ItemAttribute_t::DECAYSTATE); - - decayItems[i] = decayItems.back(); - decayItems.pop_back(); - return; + ++i; } - ++i; } + item->removeAttribute(ItemAttribute_t::DURATION_TIMESTAMP); + } else { + item->removeAttribute(ItemAttribute_t::DECAYSTATE); } - item->removeAttribute(ItemAttribute_t::DURATION_TIMESTAMP); - } else { - item->removeAttribute(ItemAttribute_t::DECAYSTATE); } } void Decay::checkDecay() { int64_t timestamp = OTSYS_TIME(); - std::vector> tempItems; + std::vector> tempItems; tempItems.reserve(32); // Small preallocation auto it = decayMap.begin(), end = decayMap.end(); @@ -139,53 +136,55 @@ void Decay::checkDecay() { } } -void Decay::internalDecayItem(const std::shared_ptr &item) { +void Decay::internalDecayItem(std::shared_ptr item) { const ItemType &it = Item::items[item->getID()]; + if (it.decayTo != 0) { + std::shared_ptr player = item->getHoldingPlayer(); + if (player) { + bool needUpdateSkills = false; + for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { + if (it.abilities && it.abilities->skills[i] != 0) { + needUpdateSkills = true; + player->setVarSkill(static_cast(i), -it.abilities->skills[i]); + } + } - if (it.decayTo == 0 && !item->isLoadedFromMap()) { - ReturnValue ret = g_game().internalRemoveItem(item); - if (ret != RETURNVALUE_NOERROR) { - g_logger().error("[Decay::internalDecayItem] - internalDecayItem failed, " - "error code: {}, item id: {}", - static_cast(ret), item->getID()); - } - return; - } - - const auto &player = item->getHoldingPlayer(); - if (player) { - bool needUpdateSkills = false; - for (int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { - if (it.abilities && it.abilities->skills[i] != 0) { - needUpdateSkills = true; - player->setVarSkill(static_cast(i), -it.abilities->skills[i]); + if (needUpdateSkills) { + player->sendSkills(); } - } - if (needUpdateSkills) { - player->sendSkills(); - } + bool needUpdateStats = false; + for (int32_t s = STAT_FIRST; s <= STAT_LAST; ++s) { + if (it.abilities && it.abilities->stats[s] != 0) { + needUpdateStats = true; + needUpdateSkills = true; + player->setVarStats(static_cast(s), -it.abilities->stats[s]); + } + if (it.abilities && it.abilities->statsPercent[s] != 0) { + needUpdateStats = true; + player->setVarStats(static_cast(s), -static_cast(player->getDefaultStats(static_cast(s)) * ((it.abilities->statsPercent[s] - 100) / 100.f))); + } + } - bool needUpdateStats = false; - for (int32_t s = STAT_FIRST; s <= STAT_LAST; ++s) { - if (it.abilities && it.abilities->stats[s] != 0) { - needUpdateStats = true; - needUpdateSkills = true; - player->setVarStats(static_cast(s), -it.abilities->stats[s]); + if (needUpdateStats) { + player->sendStats(); } - if (it.abilities && it.abilities->statsPercent[s] != 0) { - needUpdateStats = true; - player->setVarStats(static_cast(s), -static_cast(player->getDefaultStats(static_cast(s)) * ((it.abilities->statsPercent[s] - 100) / 100.f))); + + if (needUpdateSkills) { + player->sendSkills(); } } - - if (needUpdateStats) { - player->sendStats(); + g_game().transformItem(item, static_cast(it.decayTo)); + } else { + if (item->isLoadedFromMap()) { + return; } - if (needUpdateSkills) { - player->sendSkills(); + ReturnValue ret = g_game().internalRemoveItem(item); + if (ret != RETURNVALUE_NOERROR) { + g_logger().error("[Decay::internalDecayItem] - internalDecayItem failed, " + "error code: {}, item id: {}", + static_cast(ret), item->getID()); } } - g_game().transformItem(item, static_cast(it.decayTo)); } diff --git a/src/items/decay/decay.hpp b/src/items/decay/decay.hpp index d4230b8a0ba..4447da2a0d0 100644 --- a/src/items/decay/decay.hpp +++ b/src/items/decay/decay.hpp @@ -27,7 +27,7 @@ class Decay { private: void checkDecay(); - void internalDecayItem(const std::shared_ptr &item); + void internalDecayItem(std::shared_ptr item); uint32_t eventId { 0 }; // order is important, so we use an std::map diff --git a/src/items/item.cpp b/src/items/item.cpp index 6913f0b72ee..66170747b07 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -87,7 +87,7 @@ void Item::setImbuement(uint8_t slot, uint16_t imbuementId, uint32_t duration) { } void Item::addImbuement(uint8_t slot, uint16_t imbuementId, uint32_t duration) { - const auto &player = getHoldingPlayer(); + std::shared_ptr player = getHoldingPlayer(); if (!player) { return; } diff --git a/src/items/item.hpp b/src/items/item.hpp index 98257d90de6..9febd27a917 100644 --- a/src/items/item.hpp +++ b/src/items/item.hpp @@ -546,7 +546,7 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { return true; } virtual void onRemoved(); - virtual void onTradeEvent(TradeEvents_t, const std::shared_ptr &) { } + virtual void onTradeEvent(TradeEvents_t, std::shared_ptr) { } virtual void startDecaying(); virtual void stopDecaying(); diff --git a/src/items/tile.cpp b/src/items/tile.cpp index b7f61950ab5..030ba0ab8c7 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -229,7 +229,7 @@ std::shared_ptr Tile::getBottomCreature() const { std::shared_ptr Tile::getTopVisibleCreature(std::shared_ptr creature) const { if (const CreatureVector* creatures = getCreatures()) { if (creature) { - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player && player->isAccessPlayer()) { return getTopCreature(); } @@ -242,7 +242,7 @@ std::shared_ptr Tile::getTopVisibleCreature(std::shared_ptr } else { for (auto &tileCreature : *creatures) { if (!tileCreature->isInvisible()) { - const auto &player = tileCreature->getPlayer(); + std::shared_ptr player = tileCreature->getPlayer(); if (!player || !player->isInGhostMode()) { return tileCreature; } @@ -256,7 +256,7 @@ std::shared_ptr Tile::getTopVisibleCreature(std::shared_ptr std::shared_ptr Tile::getBottomVisibleCreature(std::shared_ptr creature) const { if (const CreatureVector* creatures = getCreatures()) { if (creature) { - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player && player->isAccessPlayer()) { return getBottomCreature(); } @@ -269,7 +269,7 @@ std::shared_ptr Tile::getBottomVisibleCreature(std::shared_ptrrbegin(), end = creatures->rend(); it != end; ++it) { if (!(*it)->isInvisible()) { - const auto &player = (*it)->getPlayer(); + std::shared_ptr player = (*it)->getPlayer(); if (!player || !player->isInGhostMode()) { return *it; } @@ -357,7 +357,7 @@ void Tile::onAddTileItem(std::shared_ptr item) { // send to client for (std::shared_ptr spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendAddTileItem(static_self_cast(), cylinderMapPos, item); } } @@ -442,7 +442,7 @@ void Tile::onUpdateTileItem(std::shared_ptr oldItem, const ItemType &oldTy // send to client for (std::shared_ptr spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendUpdateTileItem(static_self_cast(), cylinderMapPos, newItem); } } @@ -475,7 +475,7 @@ void Tile::onRemoveTileItem(const SpectatorHashSet &spectators, const std::vecto // send to client size_t i = 0; for (std::shared_ptr spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendRemoveTileThing(cylinderMapPos, oldStackPosVector[i++]); } } @@ -636,7 +636,7 @@ ReturnValue Tile::queryAdd(int32_t, const std::shared_ptr &thing, uint32_ } const CreatureVector* creatures = getCreatures(); - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { if (creatures && !creatures->empty() && !hasBitSet(FLAG_IGNOREBLOCKCREATURE, tileFlags) && !player->isAccessPlayer()) { for (std::shared_ptr tileCreature : *creatures) { if (!player->canWalkthrough(tileCreature)) { @@ -1185,7 +1185,7 @@ void Tile::removeThing(std::shared_ptr thing, uint32_t count) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, getPosition(), true); for (std::shared_ptr spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { oldStackPosVector.push_back(getStackposOfItem(tmpPlayer, item)); } } @@ -1210,7 +1210,7 @@ void Tile::removeThing(std::shared_ptr thing, uint32_t count) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, getPosition(), true); for (std::shared_ptr spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (std::shared_ptr tmpPlayer = spectator->getPlayer()) { oldStackPosVector.push_back(getStackposOfItem(tmpPlayer, item)); } } @@ -1279,7 +1279,7 @@ int32_t Tile::getThingIndex(std::shared_ptr thing) const { return -1; } -int32_t Tile::getClientIndexOfCreature(const std::shared_ptr &player, std::shared_ptr creature) const { +int32_t Tile::getClientIndexOfCreature(std::shared_ptr player, std::shared_ptr creature) const { int32_t n; if (ground) { n = 1; @@ -1304,7 +1304,7 @@ int32_t Tile::getClientIndexOfCreature(const std::shared_ptr &player, st return -1; } -int32_t Tile::getStackposOfCreature(const std::shared_ptr &player, std::shared_ptr creature) const { +int32_t Tile::getStackposOfCreature(std::shared_ptr player, std::shared_ptr creature) const { int32_t n; if (ground) { n = 1; @@ -1334,7 +1334,7 @@ int32_t Tile::getStackposOfCreature(const std::shared_ptr &player, std:: return -1; } -int32_t Tile::getStackposOfItem(const std::shared_ptr &player, std::shared_ptr item) const { +int32_t Tile::getStackposOfItem(std::shared_ptr player, std::shared_ptr item) const { int32_t n = 0; if (ground) { if (ground == item) { diff --git a/src/items/tile.hpp b/src/items/tile.hpp index a94f6c08fad..7e9c4973c59 100644 --- a/src/items/tile.hpp +++ b/src/items/tile.hpp @@ -196,9 +196,9 @@ class Tile : public Cylinder, public SharedObject { std::string getDescription(int32_t lookDistance) override final; - int32_t getClientIndexOfCreature(const std::shared_ptr &player, std::shared_ptr creature) const; - int32_t getStackposOfCreature(const std::shared_ptr &player, std::shared_ptr creature) const; - int32_t getStackposOfItem(const std::shared_ptr &player, std::shared_ptr item) const; + int32_t getClientIndexOfCreature(std::shared_ptr player, std::shared_ptr creature) const; + int32_t getStackposOfCreature(std::shared_ptr player, std::shared_ptr creature) const; + int32_t getStackposOfItem(std::shared_ptr player, std::shared_ptr item) const; // cylinder implementations ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; diff --git a/src/items/weapons/weapons.cpp b/src/items/weapons/weapons.cpp index 7f392c623ad..995b71518c0 100644 --- a/src/items/weapons/weapons.cpp +++ b/src/items/weapons/weapons.cpp @@ -57,7 +57,7 @@ void Weapon::configureWeapon(const ItemType &it) { id = it.id; } -int32_t Weapon::playerWeaponCheck(const std::shared_ptr &player, std::shared_ptr target, uint8_t shootRange) const { +int32_t Weapon::playerWeaponCheck(std::shared_ptr player, std::shared_ptr target, uint8_t shootRange) const { const Position &playerPos = player->getPosition(); const Position &targetPos = target->getPosition(); if (playerPos.z != targetPos.z) { @@ -107,7 +107,7 @@ int32_t Weapon::playerWeaponCheck(const std::shared_ptr &player, std::sh return 100; } -bool Weapon::useWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target) const { +bool Weapon::useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const { int32_t damageModifier = playerWeaponCheck(player, target, item->getShootRange()); if (damageModifier == 0) { return false; @@ -117,7 +117,7 @@ bool Weapon::useWeapon(const std::shared_ptr &player, std::shared_ptr &player, std::shared_ptr item, int32_t damageModifier) const { +CombatDamage Weapon::getCombatDamage(CombatDamage combat, std::shared_ptr player, std::shared_ptr item, int32_t damageModifier) const { // Local variables uint32_t level = player->getLevel(); int16_t elementalAttack = getElementDamageValue(); @@ -140,7 +140,7 @@ CombatDamage Weapon::getCombatDamage(CombatDamage combat, const std::shared_ptr< return combat; } -bool Weapon::useFist(const std::shared_ptr &player, std::shared_ptr target) { +bool Weapon::useFist(std::shared_ptr player, std::shared_ptr target) { if (!Position::areInRange<1, 1>(player->getPosition(), target->getPosition())) { return false; } @@ -170,7 +170,7 @@ bool Weapon::useFist(const std::shared_ptr &player, std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target, int32_t damageModifier, int32_t cleavePercent) const { +void Weapon::internalUseWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target, int32_t damageModifier, int32_t cleavePercent) const { if (player) { if (params.soundCastEffect == SoundEffect_t::SILENCE) { g_game().sendDoubleSoundEffect(player->getPosition(), player->getHitSoundEffect(), player->getAttackSoundEffect(), player); @@ -225,7 +225,7 @@ void Weapon::internalUseWeapon(const std::shared_ptr &player, std::share onUsedWeapon(player, item, target->getTile()); } -void Weapon::internalUseWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr tile) const { +void Weapon::internalUseWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr tile) const { if (isLoadedCallback()) { LuaVariant var; var.type = VARIANT_TARGETPOSITION; @@ -239,7 +239,7 @@ void Weapon::internalUseWeapon(const std::shared_ptr &player, std::share onUsedWeapon(player, item, tile); } -void Weapon::onUsedWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr destTile) const { +void Weapon::onUsedWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr destTile) const { if (!player->hasFlag(PlayerFlags_t::NotGainSkill)) { skills_t skillType; uint32_t skillPoint; @@ -293,7 +293,7 @@ void Weapon::onUsedWeapon(const std::shared_ptr &player, std::shared_ptr } } -uint32_t Weapon::getManaCost(const std::shared_ptr &player) const { +uint32_t Weapon::getManaCost(std::shared_ptr player) const { if (mana != 0) { return mana; } @@ -305,7 +305,7 @@ uint32_t Weapon::getManaCost(const std::shared_ptr &player) const { return (player->getMaxMana() * manaPercent) / 100; } -int32_t Weapon::getHealthCost(const std::shared_ptr &player) const { +int32_t Weapon::getHealthCost(std::shared_ptr player) const { if (health != 0) { return health; } @@ -317,7 +317,7 @@ int32_t Weapon::getHealthCost(const std::shared_ptr &player) const { return (player->getMaxHealth() * healthPercent) / 100; } -bool Weapon::executeUseWeapon(const std::shared_ptr &player, const LuaVariant &var) const { +bool Weapon::executeUseWeapon(std::shared_ptr player, const LuaVariant &var) const { // onUseWeapon(player, var) if (!getScriptInterface()->reserveScriptEnv()) { std::string playerName = player ? player->getName() : "Player nullptr"; @@ -370,7 +370,7 @@ void WeaponMelee::configureWeapon(const ItemType &it) { Weapon::configureWeapon(it); } -bool WeaponMelee::useWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target) const { +bool WeaponMelee::useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const { int32_t damageModifier = playerWeaponCheck(player, target, item->getShootRange()); if (damageModifier == 0) { return false; @@ -430,7 +430,7 @@ bool WeaponMelee::useWeapon(const std::shared_ptr &player, std::shared_p return true; } -bool WeaponMelee::getSkillType(const std::shared_ptr &player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const { +bool WeaponMelee::getSkillType(std::shared_ptr player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const { if (player->getAddAttackSkill() && player->getLastAttackBlockType() != BLOCK_IMMUNITY) { skillpoint = 1; } else { @@ -460,7 +460,7 @@ bool WeaponMelee::getSkillType(const std::shared_ptr &player, std::share return false; } -int32_t WeaponMelee::getElementDamage(const std::shared_ptr &player, std::shared_ptr, std::shared_ptr item) const { +int32_t WeaponMelee::getElementDamage(std::shared_ptr player, std::shared_ptr, std::shared_ptr item) const { if (elementType == COMBAT_NONE) { return 0; } @@ -479,7 +479,7 @@ int16_t WeaponMelee::getElementDamageValue() const { return elementDamage; } -int32_t WeaponMelee::getWeaponDamage(const std::shared_ptr &player, std::shared_ptr, std::shared_ptr item, bool maxDamage /*= false*/) const { +int32_t WeaponMelee::getWeaponDamage(std::shared_ptr player, std::shared_ptr, std::shared_ptr item, bool maxDamage /*= false*/) const { using namespace std; int32_t attackSkill = player->getWeaponSkill(item); int32_t attackValue = std::max(0, item->getAttack()); @@ -519,7 +519,7 @@ void WeaponDistance::configureWeapon(const ItemType &it) { Weapon::configureWeapon(it); } -bool WeaponDistance::useWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target) const { +bool WeaponDistance::useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const { int32_t damageModifier; const ItemType &it = Item::items[id]; if (it.weaponType == WEAPON_AMMO) { @@ -695,7 +695,7 @@ bool WeaponDistance::useWeapon(const std::shared_ptr &player, std::share return true; } -int32_t WeaponDistance::getElementDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item) const { +int32_t WeaponDistance::getElementDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const { if (elementType == COMBAT_NONE) { return 0; } @@ -730,7 +730,7 @@ int16_t WeaponDistance::getElementDamageValue() const { return elementDamage; } -int32_t WeaponDistance::getWeaponDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, bool maxDamage /*= false*/) const { +int32_t WeaponDistance::getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage /*= false*/) const { int32_t attackValue = item->getAttack(); bool hasElement = false; @@ -772,7 +772,7 @@ int32_t WeaponDistance::getWeaponDamage(const std::shared_ptr &player, s return -normal_random(minValue, (maxValue * static_cast(player->getVocation()->distDamageMultiplier))); } -bool WeaponDistance::getSkillType(const std::shared_ptr &player, std::shared_ptr, skills_t &skill, uint32_t &skillpoint) const { +bool WeaponDistance::getSkillType(std::shared_ptr player, std::shared_ptr, skills_t &skill, uint32_t &skillpoint) const { skill = SKILL_DISTANCE; if (player->getAddAttackSkill()) { @@ -805,7 +805,7 @@ void WeaponWand::configureWeapon(const ItemType &it) { Weapon::configureWeapon(it); } -int32_t WeaponWand::getWeaponDamage(const std::shared_ptr &, std::shared_ptr, std::shared_ptr, bool maxDamage /*= false*/) const { +int32_t WeaponWand::getWeaponDamage(std::shared_ptr, std::shared_ptr, std::shared_ptr, bool maxDamage /*= false*/) const { if (maxDamage) { return -maxChange; } diff --git a/src/items/weapons/weapons.hpp b/src/items/weapons/weapons.hpp index fdcbab02d35..90785983e17 100644 --- a/src/items/weapons/weapons.hpp +++ b/src/items/weapons/weapons.hpp @@ -59,15 +59,15 @@ class Weapon : public Script { return false; } - int32_t playerWeaponCheck(const std::shared_ptr &player, std::shared_ptr target, uint8_t shootRange) const; - static bool useFist(const std::shared_ptr &player, std::shared_ptr target); - virtual bool useWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target) const; + int32_t playerWeaponCheck(std::shared_ptr player, std::shared_ptr target, uint8_t shootRange) const; + static bool useFist(std::shared_ptr player, std::shared_ptr target); + virtual bool useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const; - virtual int32_t getWeaponDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const = 0; - virtual int32_t getElementDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item) const = 0; + virtual int32_t getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const = 0; + virtual int32_t getElementDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const = 0; virtual CombatType_t getElementType() const = 0; virtual int16_t getElementDamageValue() const = 0; - virtual CombatDamage getCombatDamage(CombatDamage combat, const std::shared_ptr &player, std::shared_ptr item, int32_t damageModifier) const; + virtual CombatDamage getCombatDamage(CombatDamage combat, std::shared_ptr player, std::shared_ptr item, int32_t damageModifier) const; uint16_t getID() const { return id; } @@ -174,17 +174,17 @@ class Weapon : public Script { } protected: - void internalUseWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target, int32_t damageModifier, int32_t cleavePercent = 0) const; - void internalUseWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr tile) const; + void internalUseWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target, int32_t damageModifier, int32_t cleavePercent = 0) const; + void internalUseWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr tile) const; private: - virtual bool getSkillType(const std::shared_ptr &, std::shared_ptr, skills_t &, uint32_t &) const { + virtual bool getSkillType(std::shared_ptr, std::shared_ptr, skills_t &, uint32_t &) const { return false; } - uint32_t getManaCost(const std::shared_ptr &player) const; - int32_t getHealthCost(const std::shared_ptr &player) const; - bool executeUseWeapon(const std::shared_ptr &player, const LuaVariant &var) const; + uint32_t getManaCost(std::shared_ptr player) const; + int32_t getHealthCost(std::shared_ptr player) const; + bool executeUseWeapon(std::shared_ptr player, const LuaVariant &var) const; uint16_t id = 0; @@ -202,7 +202,7 @@ class Weapon : public Script { bool wieldUnproperly = false; std::string vocationString = ""; - void onUsedWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr destTile) const; + void onUsedWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr destTile) const; static void decrementItemCount(std::shared_ptr item); @@ -228,17 +228,17 @@ class WeaponMelee final : public Weapon { void configureWeapon(const ItemType &it) override; - bool useWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target) const override; + bool useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const override; - int32_t getWeaponDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; - int32_t getElementDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item) const override; + int32_t getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; + int32_t getElementDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const override; CombatType_t getElementType() const override { return elementType; } virtual int16_t getElementDamageValue() const override; private: - bool getSkillType(const std::shared_ptr &player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const override; + bool getSkillType(std::shared_ptr player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const override; uint16_t elementDamage = 0; CombatType_t elementType = COMBAT_NONE; }; @@ -256,17 +256,17 @@ class WeaponDistance final : public Weapon { return true; } - bool useWeapon(const std::shared_ptr &player, std::shared_ptr item, std::shared_ptr target) const override; + bool useWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr target) const override; - int32_t getWeaponDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; - int32_t getElementDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item) const override; + int32_t getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; + int32_t getElementDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const override; CombatType_t getElementType() const override { return elementType; } virtual int16_t getElementDamageValue() const override; private: - bool getSkillType(const std::shared_ptr &player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const override; + bool getSkillType(std::shared_ptr player, std::shared_ptr item, skills_t &skill, uint32_t &skillpoint) const override; CombatType_t elementType = COMBAT_NONE; uint16_t elementDamage = 0; @@ -282,8 +282,8 @@ class WeaponWand final : public Weapon { void configureWeapon(const ItemType &it) override; - int32_t getWeaponDamage(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; - int32_t getElementDamage(const std::shared_ptr &, std::shared_ptr, std::shared_ptr) const override { + int32_t getWeaponDamage(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, bool maxDamage = false) const override; + int32_t getElementDamage(std::shared_ptr, std::shared_ptr, std::shared_ptr) const override { return 0; } CombatType_t getElementType() const override { @@ -299,7 +299,7 @@ class WeaponWand final : public Weapon { } private: - bool getSkillType(const std::shared_ptr &, std::shared_ptr, skills_t &, uint32_t &) const override { + bool getSkillType(std::shared_ptr, std::shared_ptr, skills_t &, uint32_t &) const override { return false; } diff --git a/src/kv/README.md b/src/kv/README.md index d54d57e740a..6c2349572c7 100644 --- a/src/kv/README.md +++ b/src/kv/README.md @@ -2,7 +2,7 @@ ## Overview -The Canary KV Library is designed to offer a simple, efficient, persistent, and thread-safe key-value store. It's an abstraction player that can support various backends (currently, only MySQL is supported). The library provides features such as scoped access to stored values, LRU caching, and type safety. Additionally, it includes a Lua API for easy integration into Lua-based applications. +The Canary KV Library is designed to offer a simple, efficient, persistent, and thread-safe key-value store. It's an abstraction layer that can support various backends (currently, only MySQL is supported). The library provides features such as scoped access to stored values, LRU caching, and type safety. Additionally, it includes a Lua API for easy integration into Lua-based applications. ## Features @@ -61,7 +61,7 @@ int lastOccurrence = scope->get("last-occurrence"); ```cpp // Create a player-scoped KV store -const auto &player = g_game().getPlayerById(123); +auto player = g_game().getPlayerById(123); auto playerKV = player->kv(); playerKV->set("coins", 100); ``` diff --git a/src/lua/callbacks/creaturecallback.cpp b/src/lua/callbacks/creaturecallback.cpp index e5b96535c84..df5845f46c0 100644 --- a/src/lua/callbacks/creaturecallback.cpp +++ b/src/lua/callbacks/creaturecallback.cpp @@ -40,7 +40,7 @@ void CreatureCallback::pushSpecificCreature(std::shared_ptr creature) LuaScriptInterface::pushUserdata(L, npc); } else if (std::shared_ptr monster = creature->getMonster()) { LuaScriptInterface::pushUserdata(L, monster); - } else if (const auto &player = creature->getPlayer()) { + } else if (std::shared_ptr player = creature->getPlayer()) { LuaScriptInterface::pushUserdata(L, player); } else { return; diff --git a/src/lua/callbacks/event_callback.cpp b/src/lua/callbacks/event_callback.cpp index 5f0dc9cc24b..e9ac54f15e6 100644 --- a/src/lua/callbacks/event_callback.cpp +++ b/src/lua/callbacks/event_callback.cpp @@ -228,7 +228,7 @@ void EventCallback::creatureOnDrainHealth(std::shared_ptr creature, st } // Party -bool EventCallback::partyOnJoin(Party* party, const std::shared_ptr &player) const { +bool EventCallback::partyOnJoin(Party* party, std::shared_ptr player) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::partyOnJoin - " "Player {}] " @@ -252,7 +252,7 @@ bool EventCallback::partyOnJoin(Party* party, const std::shared_ptr &pla return getScriptInterface()->callFunction(2); } -bool EventCallback::partyOnLeave(Party* party, const std::shared_ptr &player) const { +bool EventCallback::partyOnLeave(Party* party, std::shared_ptr player) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::partyOnLeave - " "Player {}] " @@ -324,7 +324,7 @@ void EventCallback::partyOnShareExperience(Party* party, uint64_t &exp) const { } // Player -bool EventCallback::playerOnBrowseField(const std::shared_ptr &player, const Position &position) const { +bool EventCallback::playerOnBrowseField(std::shared_ptr player, const Position &position) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnBrowseField - " "Player {}] " @@ -347,7 +347,7 @@ bool EventCallback::playerOnBrowseField(const std::shared_ptr &player, c return getScriptInterface()->callFunction(2); } -void EventCallback::playerOnLook(const std::shared_ptr &player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) const { +void EventCallback::playerOnLook(std::shared_ptr player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLook - " "Player {}] " @@ -381,7 +381,7 @@ void EventCallback::playerOnLook(const std::shared_ptr &player, const Po getScriptInterface()->callVoidFunction(4); } -void EventCallback::playerOnLookInBattleList(const std::shared_ptr &player, std::shared_ptr creature, int32_t lookDistance) const { +void EventCallback::playerOnLookInBattleList(std::shared_ptr player, std::shared_ptr creature, int32_t lookDistance) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLookInBattleList - " "Player {}] " @@ -407,7 +407,7 @@ void EventCallback::playerOnLookInBattleList(const std::shared_ptr &play getScriptInterface()->callVoidFunction(3); } -void EventCallback::playerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr &partner, std::shared_ptr item, int32_t lookDistance) const { +void EventCallback::playerOnLookInTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr item, int32_t lookDistance) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLookInTrade - " "Player {}] " @@ -436,7 +436,7 @@ void EventCallback::playerOnLookInTrade(const std::shared_ptr &player, c getScriptInterface()->callVoidFunction(4); } -bool EventCallback::playerOnLookInShop(const std::shared_ptr &player, const ItemType* itemType, uint8_t count) const { +bool EventCallback::playerOnLookInShop(std::shared_ptr player, const ItemType* itemType, uint8_t count) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLookInShop - " "Player {} itemType {}] " @@ -462,7 +462,7 @@ bool EventCallback::playerOnLookInShop(const std::shared_ptr &player, co return getScriptInterface()->callFunction(3); } -void EventCallback::playerOnRemoveCount(const std::shared_ptr &player, std::shared_ptr item) const { +void EventCallback::playerOnRemoveCount(std::shared_ptr player, std::shared_ptr item) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnMove - " "Player {} item {}] " @@ -486,7 +486,7 @@ void EventCallback::playerOnRemoveCount(const std::shared_ptr &player, s getScriptInterface()->callFunction(2); } -bool EventCallback::playerOnMoveItem(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPos, const Position &toPos, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const { +bool EventCallback::playerOnMoveItem(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPos, const Position &toPos, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const { if (!getScriptInterface()) { g_logger().error("script interface nullptr"); return false; @@ -521,7 +521,7 @@ bool EventCallback::playerOnMoveItem(const std::shared_ptr &player, std: return getScriptInterface()->callFunction(7); } -void EventCallback::playerOnItemMoved(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const { +void EventCallback::playerOnItemMoved(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnItemMoved - " "Player {} item {}] " @@ -552,7 +552,7 @@ void EventCallback::playerOnItemMoved(const std::shared_ptr &player, std getScriptInterface()->callVoidFunction(7); } -void EventCallback::playerOnChangeZone(const std::shared_ptr &player, ZoneType_t zone) const { +void EventCallback::playerOnChangeZone(std::shared_ptr player, ZoneType_t zone) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnChangeZone - " "Player {}] " @@ -574,7 +574,7 @@ void EventCallback::playerOnChangeZone(const std::shared_ptr &player, Zo getScriptInterface()->callVoidFunction(2); } -bool EventCallback::playerOnMoveCreature(const std::shared_ptr &player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) const { +bool EventCallback::playerOnMoveCreature(std::shared_ptr player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnMoveCreature - " "Player {} creature {}] " @@ -601,7 +601,7 @@ bool EventCallback::playerOnMoveCreature(const std::shared_ptr &player, return getScriptInterface()->callFunction(4); } -void EventCallback::playerOnReportRuleViolation(const std::shared_ptr &player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const { +void EventCallback::playerOnReportRuleViolation(std::shared_ptr player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnReportRuleViolation - " "Player {}] " @@ -630,7 +630,7 @@ void EventCallback::playerOnReportRuleViolation(const std::shared_ptr &p getScriptInterface()->callVoidFunction(6); } -void EventCallback::playerOnReportBug(const std::shared_ptr &player, const std::string &message, const Position &position, uint8_t category) const { +void EventCallback::playerOnReportBug(std::shared_ptr player, const std::string &message, const Position &position, uint8_t category) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnReportBug - " "Player {}] " @@ -655,7 +655,7 @@ void EventCallback::playerOnReportBug(const std::shared_ptr &player, con getScriptInterface()->callFunction(4); } -bool EventCallback::playerOnTurn(const std::shared_ptr &player, Direction direction) const { +bool EventCallback::playerOnTurn(std::shared_ptr player, Direction direction) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnTurn - " "Player {}] " @@ -678,7 +678,7 @@ bool EventCallback::playerOnTurn(const std::shared_ptr &player, Directio return getScriptInterface()->callFunction(2); } -bool EventCallback::playerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item) const { +bool EventCallback::playerOnTradeRequest(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnTradeRequest - " "Player {} target {}] " @@ -705,7 +705,7 @@ bool EventCallback::playerOnTradeRequest(const std::shared_ptr &player, return getScriptInterface()->callFunction(3); } -bool EventCallback::playerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item, std::shared_ptr targetItem) const { +bool EventCallback::playerOnTradeAccept(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, std::shared_ptr targetItem) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnTradeAccept - " "Player {} target {}] " @@ -735,7 +735,7 @@ bool EventCallback::playerOnTradeAccept(const std::shared_ptr &player, c return getScriptInterface()->callFunction(4); } -void EventCallback::playerOnGainExperience(const std::shared_ptr &player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) const { +void EventCallback::playerOnGainExperience(std::shared_ptr player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnGainExperience - " "Player {} target {}] " @@ -773,7 +773,7 @@ void EventCallback::playerOnGainExperience(const std::shared_ptr &player getScriptInterface()->resetScriptEnv(); } -void EventCallback::playerOnLoseExperience(const std::shared_ptr &player, uint64_t &exp) const { +void EventCallback::playerOnLoseExperience(std::shared_ptr player, uint64_t &exp) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnLoseExperience - " "Player {}] " @@ -803,7 +803,7 @@ void EventCallback::playerOnLoseExperience(const std::shared_ptr &player getScriptInterface()->resetScriptEnv(); } -void EventCallback::playerOnGainSkillTries(const std::shared_ptr &player, skills_t skill, uint64_t &tries) const { +void EventCallback::playerOnGainSkillTries(std::shared_ptr player, skills_t skill, uint64_t &tries) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnGainSkillTries - " "Player {} skill {}] " @@ -834,7 +834,7 @@ void EventCallback::playerOnGainSkillTries(const std::shared_ptr &player getScriptInterface()->resetScriptEnv(); } -void EventCallback::playerOnCombat(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) const { +void EventCallback::playerOnCombat(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnCombat - " "Player {} target {}] " @@ -896,7 +896,7 @@ void EventCallback::playerOnCombat(const std::shared_ptr &player, std::s getScriptInterface()->resetScriptEnv(); } -void EventCallback::playerOnRequestQuestLog(const std::shared_ptr &player) const { +void EventCallback::playerOnRequestQuestLog(std::shared_ptr player) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnRequestQuestLog - " "Player {}] " @@ -917,7 +917,7 @@ void EventCallback::playerOnRequestQuestLog(const std::shared_ptr &playe getScriptInterface()->callVoidFunction(1); } -void EventCallback::playerOnRequestQuestLine(const std::shared_ptr &player, uint16_t questId) const { +void EventCallback::playerOnRequestQuestLine(std::shared_ptr player, uint16_t questId) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::playerOnRequestQuestLine - " "Player {} questId {}] " @@ -940,7 +940,7 @@ void EventCallback::playerOnRequestQuestLine(const std::shared_ptr &play getScriptInterface()->callVoidFunction(2); } -void EventCallback::playerOnInventoryUpdate(const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool equip) const { +void EventCallback::playerOnInventoryUpdate(std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool equip) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[{}] Call stack overflow", __FUNCTION__); return; @@ -964,7 +964,7 @@ void EventCallback::playerOnInventoryUpdate(const std::shared_ptr &playe getScriptInterface()->callVoidFunction(4); } -bool EventCallback::playerOnRotateItem(const std::shared_ptr &player, std::shared_ptr item, const Position &position) const { +bool EventCallback::playerOnRotateItem(std::shared_ptr player, std::shared_ptr item, const Position &position) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[{}] Call stack overflow", __FUNCTION__); return false; @@ -987,7 +987,7 @@ bool EventCallback::playerOnRotateItem(const std::shared_ptr &player, st return getScriptInterface()->callFunction(3); } -void EventCallback::playerOnStorageUpdate(const std::shared_ptr &player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const { +void EventCallback::playerOnStorageUpdate(std::shared_ptr player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::eventOnStorageUpdate - " "Player {} key {}] " diff --git a/src/lua/callbacks/event_callback.hpp b/src/lua/callbacks/event_callback.hpp index 976d171f61a..e5712a06d71 100644 --- a/src/lua/callbacks/event_callback.hpp +++ b/src/lua/callbacks/event_callback.hpp @@ -86,36 +86,36 @@ class EventCallback : public Script { void creatureOnDrainHealth(std::shared_ptr creature, std::shared_ptr attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) const; // Party - bool partyOnJoin(Party* party, const std::shared_ptr &player) const; - bool partyOnLeave(Party* party, const std::shared_ptr &player) const; + bool partyOnJoin(Party* party, std::shared_ptr player) const; + bool partyOnLeave(Party* party, std::shared_ptr player) const; bool partyOnDisband(Party* party) const; void partyOnShareExperience(Party* party, uint64_t &exp) const; // Player - bool playerOnBrowseField(const std::shared_ptr &player, const Position &position) const; - void playerOnLook(const std::shared_ptr &player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) const; - void playerOnLookInBattleList(const std::shared_ptr &player, std::shared_ptr creature, int32_t lookDistance) const; - void playerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr &partner, std::shared_ptr item, int32_t lookDistance) const; - bool playerOnLookInShop(const std::shared_ptr &player, const ItemType* itemType, uint8_t count) const; - bool playerOnMoveItem(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; - void playerOnItemMoved(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; - void playerOnChangeZone(const std::shared_ptr &player, ZoneType_t zone) const; - bool playerOnMoveCreature(const std::shared_ptr &player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) const; - void playerOnReportRuleViolation(const std::shared_ptr &player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const; - void playerOnReportBug(const std::shared_ptr &player, const std::string &message, const Position &position, uint8_t category) const; - bool playerOnTurn(const std::shared_ptr &player, Direction direction) const; - bool playerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item) const; - bool playerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item, std::shared_ptr targetItem) const; - void playerOnGainExperience(const std::shared_ptr &player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) const; - void playerOnLoseExperience(const std::shared_ptr &player, uint64_t &exp) const; - void playerOnGainSkillTries(const std::shared_ptr &player, skills_t skill, uint64_t &tries) const; - void playerOnRemoveCount(const std::shared_ptr &player, std::shared_ptr item) const; - void playerOnRequestQuestLog(const std::shared_ptr &player) const; - void playerOnRequestQuestLine(const std::shared_ptr &player, uint16_t questId) const; - void playerOnStorageUpdate(const std::shared_ptr &player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const; - void playerOnCombat(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) const; - void playerOnInventoryUpdate(const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool equip) const; - bool playerOnRotateItem(const std::shared_ptr &player, std::shared_ptr item, const Position &position) const; + bool playerOnBrowseField(std::shared_ptr player, const Position &position) const; + void playerOnLook(std::shared_ptr player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) const; + void playerOnLookInBattleList(std::shared_ptr player, std::shared_ptr creature, int32_t lookDistance) const; + void playerOnLookInTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr item, int32_t lookDistance) const; + bool playerOnLookInShop(std::shared_ptr player, const ItemType* itemType, uint8_t count) const; + bool playerOnMoveItem(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; + void playerOnItemMoved(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) const; + void playerOnChangeZone(std::shared_ptr player, ZoneType_t zone) const; + bool playerOnMoveCreature(std::shared_ptr player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) const; + void playerOnReportRuleViolation(std::shared_ptr player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) const; + void playerOnReportBug(std::shared_ptr player, const std::string &message, const Position &position, uint8_t category) const; + bool playerOnTurn(std::shared_ptr player, Direction direction) const; + bool playerOnTradeRequest(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) const; + bool playerOnTradeAccept(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, std::shared_ptr targetItem) const; + void playerOnGainExperience(std::shared_ptr player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) const; + void playerOnLoseExperience(std::shared_ptr player, uint64_t &exp) const; + void playerOnGainSkillTries(std::shared_ptr player, skills_t skill, uint64_t &tries) const; + void playerOnRemoveCount(std::shared_ptr player, std::shared_ptr item) const; + void playerOnRequestQuestLog(std::shared_ptr player) const; + void playerOnRequestQuestLine(std::shared_ptr player, uint16_t questId) const; + void playerOnStorageUpdate(std::shared_ptr player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const; + void playerOnCombat(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) const; + void playerOnInventoryUpdate(std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool equip) const; + bool playerOnRotateItem(std::shared_ptr player, std::shared_ptr item, const Position &position) const; // Monster void monsterOnDropLoot(std::shared_ptr monster, std::shared_ptr corpse) const; diff --git a/src/lua/creature/actions.cpp b/src/lua/creature/actions.cpp index 69a924d585e..6a79d697eb7 100644 --- a/src/lua/creature/actions.cpp +++ b/src/lua/creature/actions.cpp @@ -166,7 +166,7 @@ bool Actions::registerLuaEvent(const std::shared_ptr action) { return false; } -ReturnValue Actions::canUse(const std::shared_ptr &player, const Position &pos) { +ReturnValue Actions::canUse(std::shared_ptr player, const Position &pos) { if (pos.x != 0xFFFF) { const Position &playerPos = player->getPosition(); if (playerPos.z != pos.z) { @@ -180,7 +180,7 @@ ReturnValue Actions::canUse(const std::shared_ptr &player, const Positio return RETURNVALUE_NOERROR; } -ReturnValue Actions::canUse(const std::shared_ptr &player, const Position &pos, std::shared_ptr item) { +ReturnValue Actions::canUse(std::shared_ptr player, const Position &pos, std::shared_ptr item) { const std::shared_ptr action = getAction(item); if (action != nullptr) { return action->canExecuteAction(player, pos); @@ -233,7 +233,7 @@ std::shared_ptr Actions::getAction(std::shared_ptr item) { iteratePositions != actionPositionMap.end()) { if (std::shared_ptr tile = item->getTile(); tile) { - if (const auto &player = item->getHoldingPlayer(); + if (std::shared_ptr player = item->getHoldingPlayer(); player && item->getTopParent() == player) { g_logger().debug("[Actions::getAction] - The position only is valid for use item in the map, player name {}", player->getName()); return nullptr; @@ -247,7 +247,7 @@ std::shared_ptr Actions::getAction(std::shared_ptr item) { return g_spells().getRuneSpell(item->getID()); } -ReturnValue Actions::internalUseItem(const std::shared_ptr &player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { +ReturnValue Actions::internalUseItem(std::shared_ptr player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { if (std::shared_ptr door = item->getDoor()) { if (!door->canUse(player)) { return RETURNVALUE_CANNOTUSETHISOBJECT; @@ -383,7 +383,7 @@ ReturnValue Actions::internalUseItem(const std::shared_ptr &player, cons return RETURNVALUE_CANNOTUSETHISOBJECT; } -bool Actions::useItem(const std::shared_ptr &player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { +bool Actions::useItem(std::shared_ptr player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey) { const ItemType &it = Item::items[item->getID()]; if (it.isRune() || it.type == ITEM_TYPE_POTION) { if (player->walkExhausted()) { @@ -415,7 +415,7 @@ bool Actions::useItem(const std::shared_ptr &player, const Position &pos return true; } -bool Actions::useItemEx(const std::shared_ptr &player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature /* = nullptr*/) { +bool Actions::useItemEx(std::shared_ptr player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature /* = nullptr*/) { const ItemType &it = Item::items[item->getID()]; if (it.isRune() || it.type == ITEM_TYPE_POTION) { if (player->walkExhausted()) { @@ -467,7 +467,7 @@ bool Actions::useItemEx(const std::shared_ptr &player, const Position &f return true; } -void Actions::showUseHotkeyMessage(const std::shared_ptr &player, std::shared_ptr item, uint32_t count) { +void Actions::showUseHotkeyMessage(std::shared_ptr player, std::shared_ptr item, uint32_t count) { std::ostringstream ss; const ItemType &it = Item::items[item->getID()]; @@ -491,7 +491,7 @@ void Actions::showUseHotkeyMessage(const std::shared_ptr &player, std::s Action::Action(LuaScriptInterface* interface) : Script(interface) { } -ReturnValue Action::canExecuteAction(const std::shared_ptr &player, const Position &toPos) { +ReturnValue Action::canExecuteAction(std::shared_ptr player, const Position &toPos) { if (!allowFarUse) { return g_actions().canUse(player, toPos); } @@ -499,14 +499,14 @@ ReturnValue Action::canExecuteAction(const std::shared_ptr &player, cons return g_actions().canUseFar(player, toPos, checkLineOfSight, checkFloor); } -std::shared_ptr Action::getTarget(const std::shared_ptr &player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const { +std::shared_ptr Action::getTarget(std::shared_ptr player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const { if (targetCreature != nullptr) { return targetCreature; } return g_game().internalGetThing(player, toPosition, toStackPos, 0, STACKPOS_USETARGET); } -bool Action::executeUse(const std::shared_ptr &player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey) { +bool Action::executeUse(std::shared_ptr player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey) { // onUse(player, item, fromPosition, target, toPosition, isHotkey) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[Action::executeUse - Player {}, on item {}] " diff --git a/src/lua/creature/actions.hpp b/src/lua/creature/actions.hpp index 9be4d9ff39e..c0fb1a27790 100644 --- a/src/lua/creature/actions.hpp +++ b/src/lua/creature/actions.hpp @@ -21,7 +21,7 @@ class Action : public Script { explicit Action(LuaScriptInterface* interface); // Scripting - virtual bool executeUse(const std::shared_ptr &player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey); + virtual bool executeUse(std::shared_ptr player, std::shared_ptr item, const Position &fromPosition, std::shared_ptr target, const Position &toPosition, bool isHotkey); bool getAllowFarUse() const { return allowFarUse; @@ -96,13 +96,13 @@ class Action : public Script { positions.emplace_back(pos); } - virtual ReturnValue canExecuteAction(const std::shared_ptr &player, const Position &toPos); + virtual ReturnValue canExecuteAction(std::shared_ptr player, const Position &toPos); virtual bool hasOwnErrorHandler() { return false; } - virtual std::shared_ptr getTarget(const std::shared_ptr &player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const; + virtual std::shared_ptr getTarget(std::shared_ptr player, std::shared_ptr targetCreature, const Position &toPosition, uint8_t toStackPos) const; private: std::string getScriptTypeName() const override { @@ -143,11 +143,11 @@ class Actions final : public Scripts { return inject(); } - bool useItem(const std::shared_ptr &player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); - bool useItemEx(const std::shared_ptr &player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature = nullptr); + bool useItem(std::shared_ptr player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); + bool useItemEx(std::shared_ptr player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, std::shared_ptr item, bool isHotkey, std::shared_ptr creature = nullptr); - ReturnValue canUse(const std::shared_ptr &player, const Position &pos); - ReturnValue canUse(const std::shared_ptr &player, const Position &pos, std::shared_ptr item); + ReturnValue canUse(std::shared_ptr player, const Position &pos); + ReturnValue canUse(std::shared_ptr player, const Position &pos, std::shared_ptr item); ReturnValue canUseFar(std::shared_ptr creature, const Position &toPos, bool checkLineOfSight, bool checkFloor); bool registerLuaItemEvent(const std::shared_ptr action); @@ -211,8 +211,8 @@ class Actions final : public Scripts { actionItemMap.try_emplace(actionId, action); } - ReturnValue internalUseItem(const std::shared_ptr &player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); - static void showUseHotkeyMessage(const std::shared_ptr &player, std::shared_ptr item, uint32_t count); + ReturnValue internalUseItem(std::shared_ptr player, const Position &pos, uint8_t index, std::shared_ptr item, bool isHotkey); + static void showUseHotkeyMessage(std::shared_ptr player, std::shared_ptr item, uint32_t count); using ActionUseMap = std::map>; ActionUseMap useItemMap; diff --git a/src/lua/creature/creatureevent.cpp b/src/lua/creature/creatureevent.cpp index 8484d40ac7e..b1984be2fd6 100644 --- a/src/lua/creature/creatureevent.cpp +++ b/src/lua/creature/creatureevent.cpp @@ -55,7 +55,7 @@ std::shared_ptr CreatureEvents::getEventByName(const std::string return nullptr; } -bool CreatureEvents::playerLogin(const std::shared_ptr &player) const { +bool CreatureEvents::playerLogin(std::shared_ptr player) const { // fire global event if is registered for (const auto &it : creatureEvents) { if (it.second->getEventType() == CREATURE_EVENT_LOGIN) { @@ -67,7 +67,7 @@ bool CreatureEvents::playerLogin(const std::shared_ptr &player) const { return true; } -bool CreatureEvents::playerLogout(const std::shared_ptr &player) const { +bool CreatureEvents::playerLogout(std::shared_ptr player) const { // fire global event if is registered for (const auto &it : creatureEvents) { if (it.second->getEventType() == CREATURE_EVENT_LOGOUT) { @@ -80,7 +80,7 @@ bool CreatureEvents::playerLogout(const std::shared_ptr &player) const { } bool CreatureEvents::playerAdvance( - const std::shared_ptr &player, + std::shared_ptr player, skills_t skill, uint32_t oldLevel, uint32_t newLevel @@ -171,7 +171,7 @@ void CreatureEvent::clearEvent() { loaded = false; } -bool CreatureEvent::executeOnLogin(const std::shared_ptr &player) const { +bool CreatureEvent::executeOnLogin(std::shared_ptr player) const { // onLogin(player) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeOnLogin - Player {} event {}]" @@ -191,7 +191,7 @@ bool CreatureEvent::executeOnLogin(const std::shared_ptr &player) const return getScriptInterface()->callFunction(1); } -bool CreatureEvent::executeOnLogout(const std::shared_ptr &player) const { +bool CreatureEvent::executeOnLogout(std::shared_ptr player) const { // onLogout(player) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeOnLogout - Player {} event {}] " @@ -302,7 +302,7 @@ bool CreatureEvent::executeOnDeath(std::shared_ptr creature, std::shar return getScriptInterface()->callFunction(6); } -bool CreatureEvent::executeAdvance(const std::shared_ptr &player, skills_t skill, uint32_t oldLevel, uint32_t newLevel) const { +bool CreatureEvent::executeAdvance(std::shared_ptr player, skills_t skill, uint32_t oldLevel, uint32_t newLevel) const { // onAdvance(player, skill, oldLevel, newLevel) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeAdvance - Player {} event {}] " @@ -349,7 +349,7 @@ void CreatureEvent::executeOnKill(std::shared_ptr creature, std::share getScriptInterface()->callVoidFunction(3); } -void CreatureEvent::executeModalWindow(const std::shared_ptr &player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const { +void CreatureEvent::executeModalWindow(std::shared_ptr player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const { // onModalWindow(player, modalWindowId, buttonId, choiceId) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeModalWindow - " @@ -375,7 +375,7 @@ void CreatureEvent::executeModalWindow(const std::shared_ptr &player, ui getScriptInterface()->callVoidFunction(4); } -bool CreatureEvent::executeTextEdit(const std::shared_ptr &player, std::shared_ptr item, const std::string &text) const { +bool CreatureEvent::executeTextEdit(std::shared_ptr player, std::shared_ptr item, const std::string &text) const { // onTextEdit(player, item, text) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeTextEdit - Player {} event {}] " @@ -484,7 +484,7 @@ void CreatureEvent::executeManaChange(std::shared_ptr creature, std::s getScriptInterface()->resetScriptEnv(); } -void CreatureEvent::executeExtendedOpcode(const std::shared_ptr &player, uint8_t opcode, const std::string &buffer) const { +void CreatureEvent::executeExtendedOpcode(std::shared_ptr player, uint8_t opcode, const std::string &buffer) const { // onExtendedOpcode(player, opcode, buffer) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[CreatureEvent::executeExtendedOpcode - " diff --git a/src/lua/creature/creatureevent.hpp b/src/lua/creature/creatureevent.hpp index 29c958f9b0c..24052aa84a2 100644 --- a/src/lua/creature/creatureevent.hpp +++ b/src/lua/creature/creatureevent.hpp @@ -43,18 +43,18 @@ class CreatureEvent final : public Script { void copyEvent(const std::shared_ptr creatureEvent); // scripting - bool executeOnLogin(const std::shared_ptr &player) const; - bool executeOnLogout(const std::shared_ptr &player) const; + bool executeOnLogin(std::shared_ptr player) const; + bool executeOnLogout(std::shared_ptr player) const; bool executeOnThink(std::shared_ptr creature, uint32_t interval) const; bool executeOnPrepareDeath(std::shared_ptr creature, std::shared_ptr killer) const; bool executeOnDeath(std::shared_ptr creature, std::shared_ptr corpse, std::shared_ptr killer, std::shared_ptr mostDamageKiller, bool lastHitUnjustified, bool mostDamageUnjustified) const; void executeOnKill(std::shared_ptr creature, std::shared_ptr target, bool lastHit) const; - bool executeAdvance(const std::shared_ptr &player, skills_t, uint32_t, uint32_t) const; - void executeModalWindow(const std::shared_ptr &player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const; - bool executeTextEdit(const std::shared_ptr &player, std::shared_ptr item, const std::string &text) const; + bool executeAdvance(std::shared_ptr player, skills_t, uint32_t, uint32_t) const; + void executeModalWindow(std::shared_ptr player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId) const; + bool executeTextEdit(std::shared_ptr player, std::shared_ptr item, const std::string &text) const; void executeHealthChange(std::shared_ptr creature, std::shared_ptr attacker, CombatDamage &damage) const; void executeManaChange(std::shared_ptr creature, std::shared_ptr attacker, CombatDamage &damage) const; - void executeExtendedOpcode(const std::shared_ptr &player, uint8_t opcode, const std::string &buffer) const; + void executeExtendedOpcode(std::shared_ptr player, uint8_t opcode, const std::string &buffer) const; // private: @@ -78,9 +78,9 @@ class CreatureEvents final : public Scripts { } // global events - bool playerLogin(const std::shared_ptr &player) const; - bool playerLogout(const std::shared_ptr &player) const; - bool playerAdvance(const std::shared_ptr &player, skills_t, uint32_t, uint32_t) const; + bool playerLogin(std::shared_ptr player) const; + bool playerLogout(std::shared_ptr player) const; + bool playerAdvance(std::shared_ptr player, skills_t, uint32_t, uint32_t) const; std::shared_ptr getEventByName(const std::string &name, bool forceLoaded = true); diff --git a/src/lua/creature/events.cpp b/src/lua/creature/events.cpp index 5352d126e3e..65f9270a58a 100644 --- a/src/lua/creature/events.cpp +++ b/src/lua/creature/events.cpp @@ -421,7 +421,7 @@ void Events::eventCreatureOnDrainHealth(std::shared_ptr creature, std: } // Party -bool Events::eventPartyOnJoin(Party* party, const std::shared_ptr &player) { +bool Events::eventPartyOnJoin(Party* party, std::shared_ptr player) { // Party:onJoin(player) or Party.onJoin(self, player) if (info.partyOnJoin == -1) { return true; @@ -450,7 +450,7 @@ bool Events::eventPartyOnJoin(Party* party, const std::shared_ptr &playe return scriptInterface.callFunction(2); } -bool Events::eventPartyOnLeave(Party* party, const std::shared_ptr &player) { +bool Events::eventPartyOnLeave(Party* party, std::shared_ptr player) { // Party:onLeave(player) or Party.onLeave(self, player) if (info.partyOnLeave == -1) { return true; @@ -537,7 +537,7 @@ void Events::eventPartyOnShareExperience(Party* party, uint64_t &exp) { } // Player -bool Events::eventPlayerOnBrowseField(const std::shared_ptr &player, const Position &position) { +bool Events::eventPlayerOnBrowseField(std::shared_ptr player, const Position &position) { // Player:onBrowseField(position) or Player.onBrowseField(self, position) if (info.playerOnBrowseField == -1) { return true; @@ -565,7 +565,7 @@ bool Events::eventPlayerOnBrowseField(const std::shared_ptr &player, con return scriptInterface.callFunction(2); } -void Events::eventPlayerOnLook(const std::shared_ptr &player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) { +void Events::eventPlayerOnLook(std::shared_ptr player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance) { // Player:onLook(thing, position, distance) or Player.onLook(self, thing, position, distance) if (info.playerOnLook == -1) { return; @@ -604,7 +604,7 @@ void Events::eventPlayerOnLook(const std::shared_ptr &player, const Posi scriptInterface.callVoidFunction(4); } -void Events::eventPlayerOnLookInBattleList(const std::shared_ptr &player, std::shared_ptr creature, int32_t lookDistance) { +void Events::eventPlayerOnLookInBattleList(std::shared_ptr player, std::shared_ptr creature, int32_t lookDistance) { // Player:onLookInBattleList(creature, position, distance) or Player.onLookInBattleList(self, creature, position, distance) if (info.playerOnLookInBattleList == -1) { return; @@ -635,7 +635,7 @@ void Events::eventPlayerOnLookInBattleList(const std::shared_ptr &player scriptInterface.callVoidFunction(3); } -void Events::eventPlayerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr &partner, std::shared_ptr item, int32_t lookDistance) { +void Events::eventPlayerOnLookInTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr item, int32_t lookDistance) { // Player:onLookInTrade(partner, item, distance) or Player.onLookInTrade(self, partner, item, distance) if (info.playerOnLookInTrade == -1) { return; @@ -669,7 +669,7 @@ void Events::eventPlayerOnLookInTrade(const std::shared_ptr &player, con scriptInterface.callVoidFunction(4); } -bool Events::eventPlayerOnLookInShop(const std::shared_ptr &player, const ItemType* itemType, uint8_t count) { +bool Events::eventPlayerOnLookInShop(std::shared_ptr player, const ItemType* itemType, uint8_t count) { // Player:onLookInShop(itemType, count) or Player.onLookInShop(self, itemType, count) if (info.playerOnLookInShop == -1) { return true; @@ -700,7 +700,7 @@ bool Events::eventPlayerOnLookInShop(const std::shared_ptr &player, cons return scriptInterface.callFunction(3); } -bool Events::eventPlayerOnRemoveCount(const std::shared_ptr &player, std::shared_ptr item) { +bool Events::eventPlayerOnRemoveCount(std::shared_ptr player, std::shared_ptr item) { // Player:onMove() if (info.playerOnRemoveCount == -1) { return true; @@ -729,7 +729,7 @@ bool Events::eventPlayerOnRemoveCount(const std::shared_ptr &player, std return scriptInterface.callFunction(2); } -bool Events::eventPlayerOnMoveItem(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { +bool Events::eventPlayerOnMoveItem(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { // Player:onMoveItem(item, count, fromPosition, toPosition) or Player.onMoveItem(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder) if (info.playerOnMoveItem == -1) { return true; @@ -765,7 +765,7 @@ bool Events::eventPlayerOnMoveItem(const std::shared_ptr &player, std::s return scriptInterface.callFunction(7); } -void Events::eventPlayerOnItemMoved(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { +void Events::eventPlayerOnItemMoved(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder) { // Player:onItemMoved(item, count, fromPosition, toPosition) or Player.onItemMoved(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder) if (info.playerOnItemMoved == -1) { return; @@ -801,7 +801,7 @@ void Events::eventPlayerOnItemMoved(const std::shared_ptr &player, std:: scriptInterface.callVoidFunction(7); } -void Events::eventPlayerOnChangeZone(const std::shared_ptr &player, ZoneType_t zone) { +void Events::eventPlayerOnChangeZone(std::shared_ptr player, ZoneType_t zone) { // Player:onChangeZone(zone) if (info.playerOnChangeZone == -1) { return; @@ -828,7 +828,7 @@ void Events::eventPlayerOnChangeZone(const std::shared_ptr &player, Zone scriptInterface.callVoidFunction(2); } -bool Events::eventPlayerOnMoveCreature(const std::shared_ptr &player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) { +bool Events::eventPlayerOnMoveCreature(std::shared_ptr player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition) { // Player:onMoveCreature(creature, fromPosition, toPosition) or Player.onMoveCreature(self, creature, fromPosition, toPosition) if (info.playerOnMoveCreature == -1) { return true; @@ -860,7 +860,7 @@ bool Events::eventPlayerOnMoveCreature(const std::shared_ptr &player, st return scriptInterface.callFunction(4); } -void Events::eventPlayerOnReportRuleViolation(const std::shared_ptr &player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) { +void Events::eventPlayerOnReportRuleViolation(std::shared_ptr player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) { // Player:onReportRuleViolation(targetName, reportType, reportReason, comment, translation) if (info.playerOnReportRuleViolation == -1) { return; @@ -894,7 +894,7 @@ void Events::eventPlayerOnReportRuleViolation(const std::shared_ptr &pla scriptInterface.callVoidFunction(6); } -bool Events::eventPlayerOnReportBug(const std::shared_ptr &player, const std::string &message, const Position &position, uint8_t category) { +bool Events::eventPlayerOnReportBug(std::shared_ptr player, const std::string &message, const Position &position, uint8_t category) { // Player:onReportBug(message, position, category) if (info.playerOnReportBug == -1) { return true; @@ -924,7 +924,7 @@ bool Events::eventPlayerOnReportBug(const std::shared_ptr &player, const return scriptInterface.callFunction(4); } -bool Events::eventPlayerOnTurn(const std::shared_ptr &player, Direction direction) { +bool Events::eventPlayerOnTurn(std::shared_ptr player, Direction direction) { // Player:onTurn(direction) or Player.onTurn(self, direction) if (info.playerOnTurn == -1) { return true; @@ -952,7 +952,7 @@ bool Events::eventPlayerOnTurn(const std::shared_ptr &player, Direction return scriptInterface.callFunction(2); } -bool Events::eventPlayerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item) { +bool Events::eventPlayerOnTradeRequest(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item) { // Player:onTradeRequest(target, item) if (info.playerOnTradeRequest == -1) { return true; @@ -984,7 +984,7 @@ bool Events::eventPlayerOnTradeRequest(const std::shared_ptr &player, co return scriptInterface.callFunction(3); } -bool Events::eventPlayerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item, std::shared_ptr targetItem) { +bool Events::eventPlayerOnTradeAccept(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, std::shared_ptr targetItem) { // Player:onTradeAccept(target, item, targetItem) if (info.playerOnTradeAccept == -1) { return true; @@ -1019,7 +1019,7 @@ bool Events::eventPlayerOnTradeAccept(const std::shared_ptr &player, con return scriptInterface.callFunction(4); } -void Events::eventPlayerOnGainExperience(const std::shared_ptr &player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) { +void Events::eventPlayerOnGainExperience(std::shared_ptr player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp) { // Player:onGainExperience(target, exp, rawExp) // rawExp gives the original exp which is not multiplied if (info.playerOnGainExperience == -1) { @@ -1063,7 +1063,7 @@ void Events::eventPlayerOnGainExperience(const std::shared_ptr &player, scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnLoseExperience(const std::shared_ptr &player, uint64_t &exp) { +void Events::eventPlayerOnLoseExperience(std::shared_ptr player, uint64_t &exp) { // Player:onLoseExperience(exp) if (info.playerOnLoseExperience == -1) { return; @@ -1098,7 +1098,7 @@ void Events::eventPlayerOnLoseExperience(const std::shared_ptr &player, scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnGainSkillTries(const std::shared_ptr &player, skills_t skill, uint64_t &tries) { +void Events::eventPlayerOnGainSkillTries(std::shared_ptr player, skills_t skill, uint64_t &tries) { // Player:onGainSkillTries(skill, tries) if (info.playerOnGainSkillTries == -1) { return; @@ -1134,7 +1134,7 @@ void Events::eventPlayerOnGainSkillTries(const std::shared_ptr &player, scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnCombat(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) { +void Events::eventPlayerOnCombat(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage) { // Player:onCombat(target, item, primaryDamage, primaryType, secondaryDamage, secondaryType) if (info.playerOnCombat == -1) { return; @@ -1191,7 +1191,7 @@ void Events::eventPlayerOnCombat(const std::shared_ptr &player, std::sha scriptInterface.resetScriptEnv(); } -void Events::eventPlayerOnRequestQuestLog(const std::shared_ptr &player) { +void Events::eventPlayerOnRequestQuestLog(std::shared_ptr player) { // Player:onRequestQuestLog() if (info.playerOnRequestQuestLog == -1) { return; @@ -1217,7 +1217,7 @@ void Events::eventPlayerOnRequestQuestLog(const std::shared_ptr &player) scriptInterface.callVoidFunction(1); } -void Events::eventPlayerOnRequestQuestLine(const std::shared_ptr &player, uint16_t questId) { +void Events::eventPlayerOnRequestQuestLine(std::shared_ptr player, uint16_t questId) { // Player::onRequestQuestLine() if (info.playerOnRequestQuestLine == -1) { return; @@ -1245,7 +1245,7 @@ void Events::eventPlayerOnRequestQuestLine(const std::shared_ptr &player scriptInterface.callVoidFunction(2); } -void Events::eventPlayerOnInventoryUpdate(const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool equip) { +void Events::eventPlayerOnInventoryUpdate(std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool equip) { // Player:onInventoryUpdate(item, slot, equip) if (info.playerOnInventoryUpdate == -1) { return; @@ -1274,7 +1274,7 @@ void Events::eventPlayerOnInventoryUpdate(const std::shared_ptr &player, scriptInterface.callVoidFunction(4); } -void Events::eventOnStorageUpdate(const std::shared_ptr &player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) { +void Events::eventOnStorageUpdate(std::shared_ptr player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) { // Player::onStorageUpdate(key, value, oldValue, currentTime) if (info.playerOnStorageUpdate == -1) { return; diff --git a/src/lua/creature/events.hpp b/src/lua/creature/events.hpp index 918aa9a3b84..172144a6f9a 100644 --- a/src/lua/creature/events.hpp +++ b/src/lua/creature/events.hpp @@ -88,35 +88,35 @@ class Events { void eventCreatureOnDrainHealth(std::shared_ptr creature, std::shared_ptr attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary); // Party - bool eventPartyOnJoin(Party* party, const std::shared_ptr &player); - bool eventPartyOnLeave(Party* party, const std::shared_ptr &player); + bool eventPartyOnJoin(Party* party, std::shared_ptr player); + bool eventPartyOnLeave(Party* party, std::shared_ptr player); bool eventPartyOnDisband(Party* party); void eventPartyOnShareExperience(Party* party, uint64_t &exp); // Player - bool eventPlayerOnBrowseField(const std::shared_ptr &player, const Position &position); - void eventPlayerOnLook(const std::shared_ptr &player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance); - void eventPlayerOnLookInBattleList(const std::shared_ptr &player, std::shared_ptr creature, int32_t lookDistance); - void eventPlayerOnLookInTrade(const std::shared_ptr &player, const std::shared_ptr &partner, std::shared_ptr item, int32_t lookDistance); - bool eventPlayerOnLookInShop(const std::shared_ptr &player, const ItemType* itemType, uint8_t count); - bool eventPlayerOnMoveItem(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); - void eventPlayerOnItemMoved(const std::shared_ptr &player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); - void eventPlayerOnChangeZone(const std::shared_ptr &player, ZoneType_t zone); - bool eventPlayerOnMoveCreature(const std::shared_ptr &player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition); - void eventPlayerOnReportRuleViolation(const std::shared_ptr &player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation); - bool eventPlayerOnReportBug(const std::shared_ptr &player, const std::string &message, const Position &position, uint8_t category); - bool eventPlayerOnTurn(const std::shared_ptr &player, Direction direction); - bool eventPlayerOnTradeRequest(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item); - bool eventPlayerOnTradeAccept(const std::shared_ptr &player, const std::shared_ptr &target, std::shared_ptr item, std::shared_ptr targetItem); - void eventPlayerOnGainExperience(const std::shared_ptr &player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp); - void eventPlayerOnLoseExperience(const std::shared_ptr &player, uint64_t &exp); - void eventPlayerOnGainSkillTries(const std::shared_ptr &player, skills_t skill, uint64_t &tries); - bool eventPlayerOnRemoveCount(const std::shared_ptr &player, std::shared_ptr item); - void eventPlayerOnRequestQuestLog(const std::shared_ptr &player); - void eventPlayerOnRequestQuestLine(const std::shared_ptr &player, uint16_t questId); - void eventOnStorageUpdate(const std::shared_ptr &player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime); - void eventPlayerOnCombat(const std::shared_ptr &player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage); - void eventPlayerOnInventoryUpdate(const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool equip); + bool eventPlayerOnBrowseField(std::shared_ptr player, const Position &position); + void eventPlayerOnLook(std::shared_ptr player, const Position &position, std::shared_ptr thing, uint8_t stackpos, int32_t lookDistance); + void eventPlayerOnLookInBattleList(std::shared_ptr player, std::shared_ptr creature, int32_t lookDistance); + void eventPlayerOnLookInTrade(std::shared_ptr player, std::shared_ptr partner, std::shared_ptr item, int32_t lookDistance); + bool eventPlayerOnLookInShop(std::shared_ptr player, const ItemType* itemType, uint8_t count); + bool eventPlayerOnMoveItem(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); + void eventPlayerOnItemMoved(std::shared_ptr player, std::shared_ptr item, uint16_t count, const Position &fromPosition, const Position &toPosition, std::shared_ptr fromCylinder, std::shared_ptr toCylinder); + void eventPlayerOnChangeZone(std::shared_ptr player, ZoneType_t zone); + bool eventPlayerOnMoveCreature(std::shared_ptr player, std::shared_ptr creature, const Position &fromPosition, const Position &toPosition); + void eventPlayerOnReportRuleViolation(std::shared_ptr player, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation); + bool eventPlayerOnReportBug(std::shared_ptr player, const std::string &message, const Position &position, uint8_t category); + bool eventPlayerOnTurn(std::shared_ptr player, Direction direction); + bool eventPlayerOnTradeRequest(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item); + bool eventPlayerOnTradeAccept(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, std::shared_ptr targetItem); + void eventPlayerOnGainExperience(std::shared_ptr player, std::shared_ptr target, uint64_t &exp, uint64_t rawExp); + void eventPlayerOnLoseExperience(std::shared_ptr player, uint64_t &exp); + void eventPlayerOnGainSkillTries(std::shared_ptr player, skills_t skill, uint64_t &tries); + bool eventPlayerOnRemoveCount(std::shared_ptr player, std::shared_ptr item); + void eventPlayerOnRequestQuestLog(std::shared_ptr player); + void eventPlayerOnRequestQuestLine(std::shared_ptr player, uint16_t questId); + void eventOnStorageUpdate(std::shared_ptr player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime); + void eventPlayerOnCombat(std::shared_ptr player, std::shared_ptr target, std::shared_ptr item, CombatDamage &damage); + void eventPlayerOnInventoryUpdate(std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool equip); // Monster void eventMonsterOnDropLoot(std::shared_ptr monster, std::shared_ptr corpse); diff --git a/src/lua/creature/movement.cpp b/src/lua/creature/movement.cpp index d242c25c964..29ba10f8cce 100644 --- a/src/lua/creature/movement.cpp +++ b/src/lua/creature/movement.cpp @@ -467,7 +467,7 @@ uint32_t MoveEvent::RemoveItemField(std::shared_ptr, std::shared_ptr return 1; } -uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool isCheck) { +uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool isCheck) { if (player == nullptr) { g_logger().error("[MoveEvent::EquipItem] - Player is nullptr"); return 0; @@ -581,7 +581,7 @@ uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, const return 1; } -uint32_t MoveEvent::DeEquipItem(const std::shared_ptr MoveEvent, const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool) { +uint32_t MoveEvent::DeEquipItem(const std::shared_ptr MoveEvent, std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool) { if (player == nullptr) { g_logger().error("[MoveEvent::EquipItem] - Player is nullptr"); return 0; @@ -679,7 +679,7 @@ bool MoveEvent::executeStep(const std::shared_ptr &creature, std::shar // Check if the new position is the same as the old one // If it is, log a warning and either teleport the player to their temple position if item type is an teleport auto fromPosition = creature->getLastPosition(); - if (const auto &player = creature->getPlayer(); item && fromPosition == pos && getEventType() == MOVE_EVENT_STEP_IN) { + if (auto player = creature->getPlayer(); item && fromPosition == pos && getEventType() == MOVE_EVENT_STEP_IN) { if (const ItemType &itemType = Item::items[item->getID()]; player && itemType.isTeleport()) { g_logger().warn("[{}] cannot teleport player: {}, to the same position: {} of fromPosition: {}", __FUNCTION__, player->getName(), pos.toString(), fromPosition.toString()); g_game().internalTeleport(player, player->getTemplePosition()); diff --git a/src/lua/creature/movement.hpp b/src/lua/creature/movement.hpp index 7657bfebfcc..d410cf2a03f 100644 --- a/src/lua/creature/movement.hpp +++ b/src/lua/creature/movement.hpp @@ -248,8 +248,8 @@ class MoveEvent final : public Script, public SharedObject { static uint32_t AddItemField(std::shared_ptr item, std::shared_ptr tileItem, const Position &pos); static uint32_t RemoveItemField(std::shared_ptr item, std::shared_ptr tileItem, const Position &pos); - static uint32_t EquipItem(const std::shared_ptr moveEvent, const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool boolean); - static uint32_t DeEquipItem(const std::shared_ptr moveEvent, const std::shared_ptr &player, std::shared_ptr item, Slots_t slot, bool boolean); + static uint32_t EquipItem(const std::shared_ptr moveEvent, std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool boolean); + static uint32_t DeEquipItem(const std::shared_ptr moveEvent, std::shared_ptr player, std::shared_ptr item, Slots_t slot, bool boolean); private: std::string getScriptTypeName() const override; diff --git a/src/lua/creature/talkaction.cpp b/src/lua/creature/talkaction.cpp index 084bccd8f54..4386f6f9b15 100644 --- a/src/lua/creature/talkaction.cpp +++ b/src/lua/creature/talkaction.cpp @@ -25,7 +25,7 @@ bool TalkActions::registerLuaEvent(const TalkAction_ptr &talkAction) { return inserted; } -bool TalkActions::checkWord(const std::shared_ptr &player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const { +bool TalkActions::checkWord(std::shared_ptr player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const { auto spacePos = std::ranges::find_if(words.begin(), words.end(), ::isspace); std::string firstWord = words.substr(0, spacePos - words.begin()); @@ -61,7 +61,7 @@ bool TalkActions::checkWord(const std::shared_ptr &player, SpeakClasses return talkActionPtr->executeSay(player, words, param, type); } -TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(const std::shared_ptr &player, SpeakClasses type, const std::string &words) const { +TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(std::shared_ptr player, SpeakClasses type, const std::string &words) const { for (const auto &[talkactionWords, talkActionPtr] : talkActions) { if (talkactionWords.find(',') != std::string::npos) { auto wordsList = split(talkactionWords); @@ -79,7 +79,7 @@ TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(const std::shared_pt return TALKACTION_CONTINUE; } -bool TalkAction::executeSay(const std::shared_ptr &player, const std::string &words, const std::string ¶m, SpeakClasses type) const { +bool TalkAction::executeSay(std::shared_ptr player, const std::string &words, const std::string ¶m, SpeakClasses type) const { // onSay(player, words, param, type) if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[TalkAction::executeSay - Player {} words {}] " diff --git a/src/lua/creature/talkaction.hpp b/src/lua/creature/talkaction.hpp index e5b21db5416..bc078a72d75 100644 --- a/src/lua/creature/talkaction.hpp +++ b/src/lua/creature/talkaction.hpp @@ -44,7 +44,7 @@ class TalkAction : public Script { } // scripting - bool executeSay(const std::shared_ptr &player, const std::string &words, const std::string ¶m, SpeakClasses type) const; + bool executeSay(std::shared_ptr player, const std::string &words, const std::string ¶m, SpeakClasses type) const; // void setGroupType(account::GroupType newGroupType) { @@ -78,8 +78,8 @@ class TalkActions final : public Scripts { return inject(); } - bool checkWord(const std::shared_ptr &player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const; - TalkActionResult_t checkPlayerCanSayTalkAction(const std::shared_ptr &player, SpeakClasses type, const std::string &words) const; + bool checkWord(std::shared_ptr player, SpeakClasses type, const std::string &words, const std::string_view &word, const TalkAction_ptr &talkActionPtr) const; + TalkActionResult_t checkPlayerCanSayTalkAction(std::shared_ptr player, SpeakClasses type, const std::string &words) const; bool registerLuaEvent(const TalkAction_ptr &talkAction); void clear(); diff --git a/src/lua/functions/core/game/bank_functions.cpp b/src/lua/functions/core/game/bank_functions.cpp index 96ed1aa756b..e9451a5a637 100644 --- a/src/lua/functions/core/game/bank_functions.cpp +++ b/src/lua/functions/core/game/bank_functions.cpp @@ -91,7 +91,7 @@ int BankFunctions::luaBankTransferToGuild(lua_State* L) { int BankFunctions::luaBankWithdraw(lua_State* L) { // Bank.withdraw(player, amount[, source = player]) - const auto &player = getPlayer(L, 1); + auto player = getPlayer(L, 1); uint64_t amount = getNumber(L, 2); if (lua_gettop(L) == 2) { if (!player) { @@ -113,7 +113,7 @@ int BankFunctions::luaBankWithdraw(lua_State* L) { int BankFunctions::luaBankDeposit(lua_State* L) { // Bank.deposit(player, amount[, destination = player]) - const auto &player = getPlayer(L, 1); + auto player = getPlayer(L, 1); if (!player) { return 1; } @@ -150,7 +150,7 @@ std::shared_ptr BankFunctions::getBank(lua_State* L, int32_t arg, bool isG } return std::make_shared(guild); } - const auto player = getPlayer(L, arg, true); + std::shared_ptr player = getPlayer(L, arg, true); if (!player) { return nullptr; } diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index 2ca5c1c170d..1a23358aaf7 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -414,7 +414,7 @@ int GameFunctions::luaGameCreateMonster(lua_State* L) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, monster->getPosition(), true); for (std::shared_ptr spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (auto tmpPlayer = spectator->getPlayer()) { auto bossesOnTracker = g_ioBosstiary().getBosstiaryCooldownRaceId(tmpPlayer); // If not have boss to update, then kill loop for economize resources if (bossesOnTracker.size() == 0) { @@ -611,7 +611,7 @@ int GameFunctions::luaGameGetOfflinePlayer(lua_State* L) { int GameFunctions::luaGameGetNormalizedPlayerName(lua_State* L) { // Game.getNormalizedPlayerName(name) auto name = getString(L, 1); - const auto player = g_game().getPlayerByName(name, true); + std::shared_ptr player = g_game().getPlayerByName(name, true); if (player) { pushString(L, player->getName()); if (!player->isOnline()) { diff --git a/src/lua/functions/core/game/global_functions.cpp b/src/lua/functions/core/game/global_functions.cpp index e159ce4eb62..a0f283188ae 100644 --- a/src/lua/functions/core/game/global_functions.cpp +++ b/src/lua/functions/core/game/global_functions.cpp @@ -22,7 +22,7 @@ class Creature; int GlobalFunctions::luaDoPlayerAddItem(lua_State* L) { // doPlayerAddItem(cid, itemid, count/subtype, canDropOnMap) // doPlayerAddItem(cid, itemid, count, canDropOnMap, subtype) - const auto &player = getPlayer(L, 1); + std::shared_ptr player = getPlayer(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -303,7 +303,7 @@ int GlobalFunctions::luaDoAreaCombatHealth(lua_State* L) { damage.instantSpellName = getString(L, 9); damage.runeSpellName = getString(L, 10); if (creature) { - if (const auto &player = creature->getPlayer()) { + if (auto player = creature->getPlayer()) { player->wheel()->getCombatDataSpell(damage); } } @@ -347,7 +347,7 @@ int GlobalFunctions::luaDoTargetCombatHealth(lua_State* L) { damage.instantSpellName = getString(L, 9); damage.runeSpellName = getString(L, 10); if (creature) { - if (const auto &player = creature->getPlayer()) { + if (auto player = creature->getPlayer()) { player->wheel()->getCombatDataSpell(damage); } } @@ -385,7 +385,7 @@ int GlobalFunctions::luaDoAreaCombatMana(lua_State* L) { damage.instantSpellName = getString(L, 8); damage.runeSpellName = getString(L, 9); if (creature) { - if (const auto &player = creature->getPlayer()) { + if (auto player = creature->getPlayer()) { player->wheel()->getCombatDataSpell(damage); } } @@ -430,7 +430,7 @@ int GlobalFunctions::luaDoTargetCombatMana(lua_State* L) { damage.instantSpellName = getString(L, 7); damage.runeSpellName = getString(L, 8); if (creature) { - if (const auto &player = creature->getPlayer()) { + if (auto player = creature->getPlayer()) { player->wheel()->getCombatDataSpell(damage); } } @@ -742,14 +742,14 @@ int GlobalFunctions::luaDebugPrint(lua_State* L) { int GlobalFunctions::luaIsInWar(lua_State* L) { // isInWar(cid, target) - const auto &player = getPlayer(L, 1); + std::shared_ptr player = getPlayer(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); return 1; } - const auto &targetPlayer = getPlayer(L, 2); + std::shared_ptr targetPlayer = getPlayer(L, 2); if (!targetPlayer) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/core/game/modal_window_functions.cpp b/src/lua/functions/core/game/modal_window_functions.cpp index e7aa9681c79..a56db5a6b65 100644 --- a/src/lua/functions/core/game/modal_window_functions.cpp +++ b/src/lua/functions/core/game/modal_window_functions.cpp @@ -213,7 +213,7 @@ int ModalWindowFunctions::luaModalWindowSetPriority(lua_State* L) { int ModalWindowFunctions::luaModalWindowSendToPlayer(lua_State* L) { // modalWindow:sendToPlayer(player) - const auto &player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); if (!player) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/core/game/zone_functions.cpp b/src/lua/functions/core/game/zone_functions.cpp index ef12be0d988..d1b341a1aea 100644 --- a/src/lua/functions/core/game/zone_functions.cpp +++ b/src/lua/functions/core/game/zone_functions.cpp @@ -171,7 +171,7 @@ int ZoneFunctions::luaZoneGetPlayers(lua_State* L) { pushBoolean(L, false); return 1; } - const auto &players = zone->getPlayers(); + auto players = zone->getPlayers(); lua_createtable(L, static_cast(players.size()), 0); int index = 0; diff --git a/src/lua/functions/core/network/network_message_functions.cpp b/src/lua/functions/core/network/network_message_functions.cpp index 771679a456a..d989df46095 100644 --- a/src/lua/functions/core/network/network_message_functions.cpp +++ b/src/lua/functions/core/network/network_message_functions.cpp @@ -247,7 +247,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddItem(lua_State* L) { return 1; } - const auto &player = getUserdataShared(L, 3); + std::shared_ptr player = getUserdataShared(L, 3); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -297,7 +297,7 @@ int NetworkMessageFunctions::luaNetworkMessageSendToPlayer(lua_State* L) { return 1; } - const auto &player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); if (player) { player->sendNetworkMessage(*message); pushBoolean(L, true); diff --git a/src/lua/functions/creatures/combat/combat_functions.cpp b/src/lua/functions/creatures/combat/combat_functions.cpp index c1a5ebf2889..889afefb2b8 100644 --- a/src/lua/functions/creatures/combat/combat_functions.cpp +++ b/src/lua/functions/creatures/combat/combat_functions.cpp @@ -188,7 +188,7 @@ int CombatFunctions::luaCombatExecute(lua_State* L) { } case VARIANT_STRING: { - const auto &target = g_game().getPlayerByName(variant.text); + std::shared_ptr target = g_game().getPlayerByName(variant.text); if (!target) { pushBoolean(L, false); return 1; diff --git a/src/lua/functions/creatures/creature_functions.cpp b/src/lua/functions/creatures/creature_functions.cpp index 40d46dcdbf0..897ee2b9638 100644 --- a/src/lua/functions/creatures/creature_functions.cpp +++ b/src/lua/functions/creatures/creature_functions.cpp @@ -484,7 +484,7 @@ int CreatureFunctions::luaCreatureSetHealth(lua_State* L) { creature->health = std::min(getNumber(L, 2), creature->healthMax); g_game().addCreatureHealth(creature); - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->sendStats(); } @@ -536,7 +536,7 @@ int CreatureFunctions::luaCreatureSetMaxHealth(lua_State* L) { creature->health = std::min(creature->health, creature->healthMax); g_game().addCreatureHealth(creature); - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player) { player->sendStats(); } @@ -736,7 +736,7 @@ int CreatureFunctions::luaCreatureRemove(lua_State* L) { } bool forced = getBoolean(L, 2, true); - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { if (forced) { player->removePlayer(true); } else { diff --git a/src/lua/functions/creatures/monster/monster_functions.cpp b/src/lua/functions/creatures/monster/monster_functions.cpp index 01e0ddce3bd..14c400fa5ff 100644 --- a/src/lua/functions/creatures/monster/monster_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_functions.cpp @@ -95,7 +95,7 @@ int MonsterFunctions::luaMonsterSetType(lua_State* L) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, monster->getPosition(), true); for (auto spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (auto tmpPlayer = spectator->getPlayer()) { tmpPlayer->sendCreatureReload(monster); } } diff --git a/src/lua/functions/creatures/npc/npc_functions.cpp b/src/lua/functions/creatures/npc/npc_functions.cpp index 9a2b9a0ac45..56d8411d909 100644 --- a/src/lua/functions/creatures/npc/npc_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_functions.cpp @@ -346,7 +346,7 @@ int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { return 1; } - const auto &player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -359,7 +359,7 @@ int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { int NpcFunctions::luaNpcCloseShopWindow(lua_State* L) { // npc:closeShopWindow(player) - const auto &player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -477,7 +477,7 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { return 1; } - const auto &player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/creatures/player/guild_functions.cpp b/src/lua/functions/creatures/player/guild_functions.cpp index 6bb600fa97a..7dd23f45844 100644 --- a/src/lua/functions/creatures/player/guild_functions.cpp +++ b/src/lua/functions/creatures/player/guild_functions.cpp @@ -58,7 +58,7 @@ int GuildFunctions::luaGuildGetMembersOnline(lua_State* L) { lua_createtable(L, members.size(), 0); int index = 0; - for (const std::shared_ptr &player : members) { + for (std::shared_ptr player : members) { pushUserdata(L, player); setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); diff --git a/src/lua/functions/creatures/player/party_functions.cpp b/src/lua/functions/creatures/player/party_functions.cpp index c5495b1f017..e51d231ebf8 100644 --- a/src/lua/functions/creatures/player/party_functions.cpp +++ b/src/lua/functions/creatures/player/party_functions.cpp @@ -16,7 +16,7 @@ int32_t PartyFunctions::luaPartyCreate(lua_State* L) { // Party(userdata) - const auto &player = getUserdataShared(L, 2); + std::shared_ptr player = getUserdataShared(L, 2); if (!player) { lua_pushnil(L); return 1; @@ -57,7 +57,7 @@ int PartyFunctions::luaPartyGetLeader(lua_State* L) { return 1; } - const auto &leader = party->getLeader(); + std::shared_ptr leader = party->getLeader(); if (leader) { pushUserdata(L, leader); setMetatable(L, -1, "Player"); @@ -69,7 +69,7 @@ int PartyFunctions::luaPartyGetLeader(lua_State* L) { int PartyFunctions::luaPartySetLeader(lua_State* L) { // party:setLeader(player) - const auto &player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { pushBoolean(L, party->passPartyLeadership(player)); @@ -89,7 +89,7 @@ int PartyFunctions::luaPartyGetMembers(lua_State* L) { int index = 0; lua_createtable(L, party->getMemberCount(), 0); - for (const std::shared_ptr &player : party->getMembers()) { + for (std::shared_ptr player : party->getMembers()) { pushUserdata(L, player); setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); @@ -115,7 +115,7 @@ int PartyFunctions::luaPartyGetInvitees(lua_State* L) { lua_createtable(L, party->getInvitationCount(), 0); int index = 0; - for (const std::shared_ptr &player : party->getInvitees()) { + for (std::shared_ptr player : party->getInvitees()) { pushUserdata(L, player); setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); @@ -139,7 +139,7 @@ int PartyFunctions::luaPartyGetInviteeCount(lua_State* L) { int PartyFunctions::luaPartyAddInvite(lua_State* L) { // party:addInvite(player) - const auto &player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { pushBoolean(L, party->invitePlayer(player)); @@ -151,7 +151,7 @@ int PartyFunctions::luaPartyAddInvite(lua_State* L) { int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { // party:removeInvite(player) - const auto &player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { pushBoolean(L, party->removeInvite(player)); @@ -163,7 +163,7 @@ int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { int PartyFunctions::luaPartyAddMember(lua_State* L) { // party:addMember(player) - const auto &player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { pushBoolean(L, party->joinParty(player)); @@ -175,7 +175,7 @@ int PartyFunctions::luaPartyAddMember(lua_State* L) { int PartyFunctions::luaPartyRemoveMember(lua_State* L) { // party:removeMember(player) - const auto &player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); Party* party = getUserdata(L, 1); if (party && player) { pushBoolean(L, party->leaveParty(player)); diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 6fc333e4f2e..afb991f816d 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -22,7 +22,7 @@ int PlayerFunctions::luaPlayerSendInventory(lua_State* L) { // player:sendInventory() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -36,7 +36,7 @@ int PlayerFunctions::luaPlayerSendInventory(lua_State* L) { int PlayerFunctions::luaPlayerSendLootStats(lua_State* L) { // player:sendLootStats(item, count) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -62,7 +62,7 @@ int PlayerFunctions::luaPlayerSendLootStats(lua_State* L) { int PlayerFunctions::luaPlayerUpdateSupplyTracker(lua_State* L) { // player:updateSupplyTracker(item) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -82,7 +82,7 @@ int PlayerFunctions::luaPlayerUpdateSupplyTracker(lua_State* L) { int PlayerFunctions::luaPlayerUpdateKillTracker(lua_State* L) { // player:updateKillTracker(creature, corpse) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -145,7 +145,7 @@ int PlayerFunctions::luaPlayerCreate(lua_State* L) { int PlayerFunctions::luaPlayerResetCharmsMonsters(lua_State* L) { // player:resetCharmsBestiary() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setCharmPoints(0); player->setCharmExpansion(false); @@ -163,7 +163,7 @@ int PlayerFunctions::luaPlayerResetCharmsMonsters(lua_State* L) { int PlayerFunctions::luaPlayerUnlockAllCharmRunes(lua_State* L) { // player:unlockAllCharmRunes() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { for (int8_t i = CHARM_WOUND; i <= CHARM_LAST; i++) { const auto charm = g_iobestiary().getBestiaryCharm(static_cast(i)); @@ -181,7 +181,7 @@ int PlayerFunctions::luaPlayerUnlockAllCharmRunes(lua_State* L) { int PlayerFunctions::luaPlayeraddCharmPoints(lua_State* L) { // player:addCharmPoints() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { int16_t charms = getNumber(L, 2); if (charms >= 0) { @@ -205,7 +205,7 @@ int PlayerFunctions::luaPlayerIsPlayer(lua_State* L) { int PlayerFunctions::luaPlayerGetGuid(lua_State* L) { // player:getGuid() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getGUID()); } else { @@ -216,7 +216,7 @@ int PlayerFunctions::luaPlayerGetGuid(lua_State* L) { int PlayerFunctions::luaPlayerGetIp(lua_State* L) { // player:getIp() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getIP()); } else { @@ -227,7 +227,7 @@ int PlayerFunctions::luaPlayerGetIp(lua_State* L) { int PlayerFunctions::luaPlayerGetAccountId(lua_State* L) { // player:getAccountId() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || player->getAccountId() == 0) { lua_pushnil(L); return 1; @@ -240,7 +240,7 @@ int PlayerFunctions::luaPlayerGetAccountId(lua_State* L) { int PlayerFunctions::luaPlayerGetLastLoginSaved(lua_State* L) { // player:getLastLoginSaved() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getLastLoginSaved()); } else { @@ -251,7 +251,7 @@ int PlayerFunctions::luaPlayerGetLastLoginSaved(lua_State* L) { int PlayerFunctions::luaPlayerGetLastLogout(lua_State* L) { // player:getLastLogout() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getLastLogout()); } else { @@ -262,7 +262,7 @@ int PlayerFunctions::luaPlayerGetLastLogout(lua_State* L) { int PlayerFunctions::luaPlayerGetAccountType(lua_State* L) { // player:getAccountType() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getAccountType()); } else { @@ -273,7 +273,7 @@ int PlayerFunctions::luaPlayerGetAccountType(lua_State* L) { int PlayerFunctions::luaPlayerSetAccountType(lua_State* L) { // player:setAccountType(accountType) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { lua_pushnil(L); return 1; @@ -295,7 +295,7 @@ int PlayerFunctions::luaPlayerSetAccountType(lua_State* L) { int PlayerFunctions::luaPlayerAddBestiaryKill(lua_State* L) { // player:addBestiaryKill(name[, amount = 1]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { const auto mtype = g_monsters().getMonsterType(getString(L, 2)); if (mtype) { @@ -312,7 +312,7 @@ int PlayerFunctions::luaPlayerAddBestiaryKill(lua_State* L) { int PlayerFunctions::luaPlayerIsMonsterBestiaryUnlocked(lua_State* L) { // player:isMonsterBestiaryUnlocked(raceId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -340,7 +340,7 @@ int PlayerFunctions::luaPlayerIsMonsterBestiaryUnlocked(lua_State* L) { int PlayerFunctions::luaPlayergetCharmMonsterType(lua_State* L) { // player:getCharmMonsterType(charmRune_t) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { charmRune_t charmid = getNumber(L, 2); uint16_t raceid = player->parseRacebyCharm(charmid, false, 0); @@ -363,7 +363,7 @@ int PlayerFunctions::luaPlayergetCharmMonsterType(lua_State* L) { int PlayerFunctions::luaPlayerRemovePreyStamina(lua_State* L) { // player:removePreyStamina(amount) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { g_ioprey().CheckPlayerPreys(player, getNumber(L, 2, 1)); pushBoolean(L, true); @@ -375,7 +375,7 @@ int PlayerFunctions::luaPlayerRemovePreyStamina(lua_State* L) { int PlayerFunctions::luaPlayerAddPreyCards(lua_State* L) { // player:addPreyCards(amount) - if (const auto &player = getUserdataShared(L, 1)) { + if (std::shared_ptr player = getUserdataShared(L, 1)) { player->addPreyCards(getNumber(L, 2, 0)); pushBoolean(L, true); } else { @@ -386,7 +386,7 @@ int PlayerFunctions::luaPlayerAddPreyCards(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyCards(lua_State* L) { // player:getPreyCards() - if (const auto &player = getUserdataShared(L, 1)) { + if (std::shared_ptr player = getUserdataShared(L, 1)) { lua_pushnumber(L, static_cast(player->getPreyCards())); } else { lua_pushnil(L); @@ -396,7 +396,7 @@ int PlayerFunctions::luaPlayerGetPreyCards(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyExperiencePercentage(lua_State* L) { // player:getPreyExperiencePercentage(raceId) - if (const auto &player = getUserdataShared(L, 1)) { + if (std::shared_ptr player = getUserdataShared(L, 1)) { if (const PreySlot* slot = player->getPreyWithMonster(getNumber(L, 2, 0)); slot && slot->isOccupied() && slot->bonus == PreyBonus_Experience && slot->bonusTimeLeft > 0) { lua_pushnumber(L, static_cast(100 + slot->bonusPercentage)); @@ -411,7 +411,7 @@ int PlayerFunctions::luaPlayerGetPreyExperiencePercentage(lua_State* L) { int PlayerFunctions::luaPlayerRemoveTaskHuntingPoints(lua_State* L) { // player:removeTaskHuntingPoints(amount) - if (const auto &player = getUserdataShared(L, 1)) { + if (std::shared_ptr player = getUserdataShared(L, 1)) { pushBoolean(L, player->useTaskHuntingPoints(getNumber(L, 2, 0))); } else { lua_pushnil(L); @@ -421,7 +421,7 @@ int PlayerFunctions::luaPlayerRemoveTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetTaskHuntingPoints(lua_State* L) { // player:getTaskHuntingPoints() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -434,7 +434,7 @@ int PlayerFunctions::luaPlayerGetTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerAddTaskHuntingPoints(lua_State* L) { // player:addTaskHuntingPoints(amount) - if (const auto &player = getUserdataShared(L, 1)) { + if (std::shared_ptr player = getUserdataShared(L, 1)) { auto points = getNumber(L, 2); player->addTaskHuntingPoints(getNumber(L, 2)); lua_pushnumber(L, static_cast(points)); @@ -446,7 +446,7 @@ int PlayerFunctions::luaPlayerAddTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyLootPercentage(lua_State* L) { // player:getPreyLootPercentage(raceid) - if (const auto &player = getUserdataShared(L, 1)) { + if (std::shared_ptr player = getUserdataShared(L, 1)) { if (const PreySlot* slot = player->getPreyWithMonster(getNumber(L, 2, 0)); slot && slot->isOccupied() && slot->bonus == PreyBonus_Loot) { lua_pushnumber(L, slot->bonusPercentage); @@ -461,7 +461,7 @@ int PlayerFunctions::luaPlayerGetPreyLootPercentage(lua_State* L) { int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { // get: player:preyThirdSlot() set: player:preyThirdSlot(bool) - if (const auto &player = getUserdataShared(L, 1); + if (std::shared_ptr player = getUserdataShared(L, 1); PreySlot* slot = player->getPreySlotById(PreySlot_Three)) { if (lua_gettop(L) == 1) { pushBoolean(L, slot->state != PreyDataState_Locked); @@ -485,7 +485,7 @@ int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { int PlayerFunctions::luaPlayerTaskThirdSlot(lua_State* L) { // get: player:taskHuntingThirdSlot() set: player:taskHuntingThirdSlot(bool) - if (const auto &player = getUserdataShared(L, 1); + if (std::shared_ptr player = getUserdataShared(L, 1); TaskHuntingSlot* slot = player->getTaskHuntingSlotById(PreySlot_Three)) { if (lua_gettop(L) == 1) { pushBoolean(L, slot->state != PreyTaskDataState_Locked); @@ -510,7 +510,7 @@ int PlayerFunctions::luaPlayerTaskThirdSlot(lua_State* L) { int PlayerFunctions::luaPlayercharmExpansion(lua_State* L) { // get: player:charmExpansion() set: player:charmExpansion(bool) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { if (lua_gettop(L) == 1) { pushBoolean(L, player->hasCharmExpansion()); @@ -526,7 +526,7 @@ int PlayerFunctions::luaPlayercharmExpansion(lua_State* L) { int PlayerFunctions::luaPlayerGetCapacity(lua_State* L) { // player:getCapacity() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getCapacity()); } else { @@ -537,7 +537,7 @@ int PlayerFunctions::luaPlayerGetCapacity(lua_State* L) { int PlayerFunctions::luaPlayerSetCapacity(lua_State* L) { // player:setCapacity(capacity) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->capacity = getNumber(L, 2); player->sendStats(); @@ -550,7 +550,7 @@ int PlayerFunctions::luaPlayerSetCapacity(lua_State* L) { int PlayerFunctions::luaPlayerSetTraining(lua_State* L) { // player:setTraining(value) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { bool value = getBoolean(L, 2, false); player->setTraining(value); @@ -563,7 +563,7 @@ int PlayerFunctions::luaPlayerSetTraining(lua_State* L) { int PlayerFunctions::luaPlayerGetIsTraining(lua_State* L) { // player:isTraining() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { pushBoolean(L, false); reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); @@ -576,7 +576,7 @@ int PlayerFunctions::luaPlayerGetIsTraining(lua_State* L) { int PlayerFunctions::luaPlayerGetFreeCapacity(lua_State* L) { // player:getFreeCapacity() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getFreeCapacity()); } else { @@ -587,7 +587,7 @@ int PlayerFunctions::luaPlayerGetFreeCapacity(lua_State* L) { int PlayerFunctions::luaPlayerGetKills(lua_State* L) { // player:getKills() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -611,7 +611,7 @@ int PlayerFunctions::luaPlayerGetKills(lua_State* L) { int PlayerFunctions::luaPlayerSetKills(lua_State* L) { // player:setKills(kills) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -639,7 +639,7 @@ int PlayerFunctions::luaPlayerSetKills(lua_State* L) { int PlayerFunctions::luaPlayerGetReward(lua_State* L) { // player:getReward(rewardId[, autoCreate = false]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -658,7 +658,7 @@ int PlayerFunctions::luaPlayerGetReward(lua_State* L) { int PlayerFunctions::luaPlayerRemoveReward(lua_State* L) { // player:removeReward(rewardId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -672,7 +672,7 @@ int PlayerFunctions::luaPlayerRemoveReward(lua_State* L) { int PlayerFunctions::luaPlayerGetRewardList(lua_State* L) { // player:getRewardList() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -692,7 +692,7 @@ int PlayerFunctions::luaPlayerGetRewardList(lua_State* L) { int PlayerFunctions::luaPlayerSetDailyReward(lua_State* L) { // player:setDailyReward(value) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setDailyReward(getNumber(L, 2)); pushBoolean(L, true); @@ -704,7 +704,7 @@ int PlayerFunctions::luaPlayerSetDailyReward(lua_State* L) { int PlayerFunctions::luaPlayerGetDepotLocker(lua_State* L) { // player:getDepotLocker(depotId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -724,7 +724,7 @@ int PlayerFunctions::luaPlayerGetDepotLocker(lua_State* L) { int PlayerFunctions::luaPlayerGetStashCounter(lua_State* L) { // player:getStashCount() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t sizeStash = getStashSize(player->getStashItems()); lua_pushnumber(L, sizeStash); @@ -736,7 +736,7 @@ int PlayerFunctions::luaPlayerGetStashCounter(lua_State* L) { int PlayerFunctions::luaPlayerGetDepotChest(lua_State* L) { // player:getDepotChest(depotId[, autoCreate = false]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -757,7 +757,7 @@ int PlayerFunctions::luaPlayerGetDepotChest(lua_State* L) { int PlayerFunctions::luaPlayerGetInbox(lua_State* L) { // player:getInbox() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -775,7 +775,7 @@ int PlayerFunctions::luaPlayerGetInbox(lua_State* L) { int PlayerFunctions::luaPlayerGetSkullTime(lua_State* L) { // player:getSkullTime() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSkullTicks()); } else { @@ -786,7 +786,7 @@ int PlayerFunctions::luaPlayerGetSkullTime(lua_State* L) { int PlayerFunctions::luaPlayerSetSkullTime(lua_State* L) { // player:setSkullTime(skullTime) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setSkullTicks(getNumber(L, 2)); pushBoolean(L, true); @@ -798,7 +798,7 @@ int PlayerFunctions::luaPlayerSetSkullTime(lua_State* L) { int PlayerFunctions::luaPlayerGetDeathPenalty(lua_State* L) { // player:getDeathPenalty() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, static_cast(player->getLostPercent() * 100)); } else { @@ -809,7 +809,7 @@ int PlayerFunctions::luaPlayerGetDeathPenalty(lua_State* L) { int PlayerFunctions::luaPlayerGetExperience(lua_State* L) { // player:getExperience() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getExperience()); } else { @@ -820,7 +820,7 @@ int PlayerFunctions::luaPlayerGetExperience(lua_State* L) { int PlayerFunctions::luaPlayerAddExperience(lua_State* L) { // player:addExperience(experience[, sendText = false]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { int64_t experience = getNumber(L, 2); bool sendText = getBoolean(L, 3, false); @@ -834,7 +834,7 @@ int PlayerFunctions::luaPlayerAddExperience(lua_State* L) { int PlayerFunctions::luaPlayerRemoveExperience(lua_State* L) { // player:removeExperience(experience[, sendText = false]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { int64_t experience = getNumber(L, 2); bool sendText = getBoolean(L, 3, false); @@ -848,7 +848,7 @@ int PlayerFunctions::luaPlayerRemoveExperience(lua_State* L) { int PlayerFunctions::luaPlayerGetLevel(lua_State* L) { // player:getLevel() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getLevel()); } else { @@ -859,7 +859,7 @@ int PlayerFunctions::luaPlayerGetLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetMagicShieldCapacityFlat(lua_State* L) { // player:getMagicShieldCapacityFlat(useCharges) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMagicShieldCapacityFlat(getBoolean(L, 2, false))); } else { @@ -870,7 +870,7 @@ int PlayerFunctions::luaPlayerGetMagicShieldCapacityFlat(lua_State* L) { int PlayerFunctions::luaPlayerGetMagicShieldCapacityPercent(lua_State* L) { // player:getMagicShieldCapacityPercent(useCharges) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMagicShieldCapacityPercent(getBoolean(L, 2, false))); } else { @@ -881,7 +881,7 @@ int PlayerFunctions::luaPlayerGetMagicShieldCapacityPercent(lua_State* L) { int PlayerFunctions::luaPlayerSendSpellCooldown(lua_State* L) { // player:sendSpellCooldown(spellId, time) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -897,7 +897,7 @@ int PlayerFunctions::luaPlayerSendSpellCooldown(lua_State* L) { int PlayerFunctions::luaPlayerSendSpellGroupCooldown(lua_State* L) { // player:sendSpellGroupCooldown(groupId, time) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -913,7 +913,7 @@ int PlayerFunctions::luaPlayerSendSpellGroupCooldown(lua_State* L) { int PlayerFunctions::luaPlayerGetMagicLevel(lua_State* L) { // player:getMagicLevel() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMagicLevel()); } else { @@ -924,7 +924,7 @@ int PlayerFunctions::luaPlayerGetMagicLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseMagicLevel(lua_State* L) { // player:getBaseMagicLevel() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getBaseMagicLevel()); } else { @@ -935,7 +935,7 @@ int PlayerFunctions::luaPlayerGetBaseMagicLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetMana(lua_State* L) { // player:getMana() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMana()); } else { @@ -946,7 +946,7 @@ int PlayerFunctions::luaPlayerGetMana(lua_State* L) { int PlayerFunctions::luaPlayerAddMana(lua_State* L) { // player:addMana(manaChange[, animationOnLoss = false]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -968,7 +968,7 @@ int PlayerFunctions::luaPlayerAddMana(lua_State* L) { int PlayerFunctions::luaPlayerGetMaxMana(lua_State* L) { // player:getMaxMana() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMaxMana()); } else { @@ -979,7 +979,7 @@ int PlayerFunctions::luaPlayerGetMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerSetMaxMana(lua_State* L) { // player:setMaxMana(maxMana) - const auto &player = getPlayer(L, 1); + std::shared_ptr player = getPlayer(L, 1); if (player) { player->manaMax = getNumber(L, 2); player->mana = std::min(player->mana, player->manaMax); @@ -994,7 +994,7 @@ int PlayerFunctions::luaPlayerSetMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerGetManaSpent(lua_State* L) { // player:getManaSpent() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSpentMana()); } else { @@ -1005,7 +1005,7 @@ int PlayerFunctions::luaPlayerGetManaSpent(lua_State* L) { int PlayerFunctions::luaPlayerAddManaSpent(lua_State* L) { // player:addManaSpent(amount) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->addManaSpent(getNumber(L, 2)); pushBoolean(L, true); @@ -1017,7 +1017,7 @@ int PlayerFunctions::luaPlayerAddManaSpent(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseMaxHealth(lua_State* L) { // player:getBaseMaxHealth() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->healthMax); } else { @@ -1028,7 +1028,7 @@ int PlayerFunctions::luaPlayerGetBaseMaxHealth(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseMaxMana(lua_State* L) { // player:getBaseMaxMana() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->manaMax); } else { @@ -1040,7 +1040,7 @@ int PlayerFunctions::luaPlayerGetBaseMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerGetSkillLevel(lua_State* L) { // player:getSkillLevel(skillType) skills_t skillType = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->skills[skillType].level); } else { @@ -1052,7 +1052,7 @@ int PlayerFunctions::luaPlayerGetSkillLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetEffectiveSkillLevel(lua_State* L) { // player:getEffectiveSkillLevel(skillType) skills_t skillType = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->getSkillLevel(skillType)); } else { @@ -1064,7 +1064,7 @@ int PlayerFunctions::luaPlayerGetEffectiveSkillLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetSkillPercent(lua_State* L) { // player:getSkillPercent(skillType) skills_t skillType = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->skills[skillType].percent); } else { @@ -1076,7 +1076,7 @@ int PlayerFunctions::luaPlayerGetSkillPercent(lua_State* L) { int PlayerFunctions::luaPlayerGetSkillTries(lua_State* L) { // player:getSkillTries(skillType) skills_t skillType = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->skills[skillType].tries); } else { @@ -1087,7 +1087,7 @@ int PlayerFunctions::luaPlayerGetSkillTries(lua_State* L) { int PlayerFunctions::luaPlayerAddSkillTries(lua_State* L) { // player:addSkillTries(skillType, tries) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { skills_t skillType = getNumber(L, 2); uint64_t tries = getNumber(L, 3); @@ -1101,7 +1101,7 @@ int PlayerFunctions::luaPlayerAddSkillTries(lua_State* L) { int PlayerFunctions::luaPlayerSetLevel(lua_State* L) { // player:setLevel(level) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t level = getNumber(L, 2); player->level = level; @@ -1117,7 +1117,7 @@ int PlayerFunctions::luaPlayerSetLevel(lua_State* L) { int PlayerFunctions::luaPlayerSetMagicLevel(lua_State* L) { // player:setMagicLevel(level[, manaSpent]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t level = getNumber(L, 2); player->magLevel = level; @@ -1141,7 +1141,7 @@ int PlayerFunctions::luaPlayerSetMagicLevel(lua_State* L) { int PlayerFunctions::luaPlayerSetSkillLevel(lua_State* L) { // player:setSkillLevel(skillType, level[, tries]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { skills_t skillType = getNumber(L, 2); uint16_t level = getNumber(L, 3); @@ -1166,7 +1166,7 @@ int PlayerFunctions::luaPlayerSetSkillLevel(lua_State* L) { int PlayerFunctions::luaPlayerAddOfflineTrainingTime(lua_State* L) { // player:addOfflineTrainingTime(time) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { int32_t time = getNumber(L, 2); player->addOfflineTrainingTime(time); @@ -1180,7 +1180,7 @@ int PlayerFunctions::luaPlayerAddOfflineTrainingTime(lua_State* L) { int PlayerFunctions::luaPlayerGetOfflineTrainingTime(lua_State* L) { // player:getOfflineTrainingTime() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getOfflineTrainingTime()); } else { @@ -1191,7 +1191,7 @@ int PlayerFunctions::luaPlayerGetOfflineTrainingTime(lua_State* L) { int PlayerFunctions::luaPlayerRemoveOfflineTrainingTime(lua_State* L) { // player:removeOfflineTrainingTime(time) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { int32_t time = getNumber(L, 2); player->removeOfflineTrainingTime(time); @@ -1205,7 +1205,7 @@ int PlayerFunctions::luaPlayerRemoveOfflineTrainingTime(lua_State* L) { int PlayerFunctions::luaPlayerAddOfflineTrainingTries(lua_State* L) { // player:addOfflineTrainingTries(skillType, tries) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { skills_t skillType = getNumber(L, 2); uint64_t tries = getNumber(L, 3); @@ -1218,7 +1218,7 @@ int PlayerFunctions::luaPlayerAddOfflineTrainingTries(lua_State* L) { int PlayerFunctions::luaPlayerGetOfflineTrainingSkill(lua_State* L) { // player:getOfflineTrainingSkill() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getOfflineTrainingSkill()); } else { @@ -1229,7 +1229,7 @@ int PlayerFunctions::luaPlayerGetOfflineTrainingSkill(lua_State* L) { int PlayerFunctions::luaPlayerSetOfflineTrainingSkill(lua_State* L) { // player:setOfflineTrainingSkill(skillId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { int8_t skillId = getNumber(L, 2); player->setOfflineTrainingSkill(skillId); @@ -1242,7 +1242,7 @@ int PlayerFunctions::luaPlayerSetOfflineTrainingSkill(lua_State* L) { int PlayerFunctions::luaPlayerOpenStash(lua_State* L) { // player:openStash(isNpc) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); bool isNpc = getBoolean(L, 2, false); if (player) { player->sendOpenStash(isNpc); @@ -1256,7 +1256,7 @@ int PlayerFunctions::luaPlayerOpenStash(lua_State* L) { int PlayerFunctions::luaPlayerGetItemCount(lua_State* L) { // player:getItemCount(itemId[, subType = -1]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1280,7 +1280,7 @@ int PlayerFunctions::luaPlayerGetItemCount(lua_State* L) { int PlayerFunctions::luaPlayerGetStashItemCount(lua_State* L) { // player:getStashItemCount(itemId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1309,7 +1309,7 @@ int PlayerFunctions::luaPlayerGetStashItemCount(lua_State* L) { int PlayerFunctions::luaPlayerGetItemById(lua_State* L) { // player:getItemById(itemId, deepSearch[, subType = -1]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1340,7 +1340,7 @@ int PlayerFunctions::luaPlayerGetItemById(lua_State* L) { int PlayerFunctions::luaPlayerGetVocation(lua_State* L) { // player:getVocation() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushUserdata(L, player->getVocation()); setMetatable(L, -1, "Vocation"); @@ -1352,7 +1352,7 @@ int PlayerFunctions::luaPlayerGetVocation(lua_State* L) { int PlayerFunctions::luaPlayerSetVocation(lua_State* L) { // player:setVocation(id or name or userdata) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1381,7 +1381,7 @@ int PlayerFunctions::luaPlayerSetVocation(lua_State* L) { int PlayerFunctions::luaPlayerGetSex(lua_State* L) { // player:getSex() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSex()); } else { @@ -1392,7 +1392,7 @@ int PlayerFunctions::luaPlayerGetSex(lua_State* L) { int PlayerFunctions::luaPlayerSetSex(lua_State* L) { // player:setSex(newSex) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { PlayerSex_t newSex = getNumber(L, 2); player->setSex(newSex); @@ -1405,7 +1405,7 @@ int PlayerFunctions::luaPlayerSetSex(lua_State* L) { int PlayerFunctions::luaPlayerGetPronoun(lua_State* L) { // player:getPronoun() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getPronoun()); } else { @@ -1416,7 +1416,7 @@ int PlayerFunctions::luaPlayerGetPronoun(lua_State* L) { int PlayerFunctions::luaPlayerSetPronoun(lua_State* L) { // player:setPronoun(newPronoun) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { PlayerPronoun_t newPronoun = getNumber(L, 2); player->setPronoun(newPronoun); @@ -1429,7 +1429,7 @@ int PlayerFunctions::luaPlayerSetPronoun(lua_State* L) { int PlayerFunctions::luaPlayerGetTown(lua_State* L) { // player:getTown() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushUserdata(L, player->getTown()); setMetatable(L, -1, "Town"); @@ -1447,7 +1447,7 @@ int PlayerFunctions::luaPlayerSetTown(lua_State* L) { return 1; } - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setTown(town); pushBoolean(L, true); @@ -1459,7 +1459,7 @@ int PlayerFunctions::luaPlayerSetTown(lua_State* L) { int PlayerFunctions::luaPlayerGetGuild(lua_State* L) { // player:getGuild() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1478,7 +1478,7 @@ int PlayerFunctions::luaPlayerGetGuild(lua_State* L) { int PlayerFunctions::luaPlayerSetGuild(lua_State* L) { // player:setGuild(guild) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1493,7 +1493,7 @@ int PlayerFunctions::luaPlayerSetGuild(lua_State* L) { int PlayerFunctions::luaPlayerGetGuildLevel(lua_State* L) { // player:getGuildLevel() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && player->getGuild()) { lua_pushnumber(L, player->getGuildRank()->level); } else { @@ -1505,7 +1505,7 @@ int PlayerFunctions::luaPlayerGetGuildLevel(lua_State* L) { int PlayerFunctions::luaPlayerSetGuildLevel(lua_State* L) { // player:setGuildLevel(level) uint8_t level = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getGuild()) { lua_pushnil(L); return 1; @@ -1524,7 +1524,7 @@ int PlayerFunctions::luaPlayerSetGuildLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetGuildNick(lua_State* L) { // player:getGuildNick() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushString(L, player->getGuildNick()); } else { @@ -1536,7 +1536,7 @@ int PlayerFunctions::luaPlayerGetGuildNick(lua_State* L) { int PlayerFunctions::luaPlayerSetGuildNick(lua_State* L) { // player:setGuildNick(nick) const std::string &nick = getString(L, 2); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setGuildNick(nick); pushBoolean(L, true); @@ -1548,7 +1548,7 @@ int PlayerFunctions::luaPlayerSetGuildNick(lua_State* L) { int PlayerFunctions::luaPlayerGetGroup(lua_State* L) { // player:getGroup() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushUserdata(L, player->getGroup()); setMetatable(L, -1, "Group"); @@ -1566,7 +1566,7 @@ int PlayerFunctions::luaPlayerSetGroup(lua_State* L) { return 1; } - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setGroup(group); pushBoolean(L, true); @@ -1581,7 +1581,7 @@ int PlayerFunctions::luaPlayerSetSpecialContainersAvailable(lua_State* L) { bool supplyStashMenu = getBoolean(L, 2, false); bool marketMenu = getBoolean(L, 3, false); bool depotSearchMenu = getBoolean(L, 4, false); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setSpecialMenuAvailable(supplyStashMenu, marketMenu, depotSearchMenu); pushBoolean(L, true); @@ -1593,7 +1593,7 @@ int PlayerFunctions::luaPlayerSetSpecialContainersAvailable(lua_State* L) { int PlayerFunctions::luaPlayerGetStamina(lua_State* L) { // player:getStamina() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getStaminaMinutes()); } else { @@ -1605,7 +1605,7 @@ int PlayerFunctions::luaPlayerGetStamina(lua_State* L) { int PlayerFunctions::luaPlayerSetStamina(lua_State* L) { // player:setStamina(stamina) uint16_t stamina = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->staminaMinutes = std::min(2520, stamina); player->sendStats(); @@ -1617,7 +1617,7 @@ int PlayerFunctions::luaPlayerSetStamina(lua_State* L) { int PlayerFunctions::luaPlayerGetSoul(lua_State* L) { // player:getSoul() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSoul()); } else { @@ -1629,7 +1629,7 @@ int PlayerFunctions::luaPlayerGetSoul(lua_State* L) { int PlayerFunctions::luaPlayerAddSoul(lua_State* L) { // player:addSoul(soulChange) int32_t soulChange = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->changeSoul(soulChange); pushBoolean(L, true); @@ -1641,7 +1641,7 @@ int PlayerFunctions::luaPlayerAddSoul(lua_State* L) { int PlayerFunctions::luaPlayerGetMaxSoul(lua_State* L) { // player:getMaxSoul() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && player->vocation) { lua_pushnumber(L, player->vocation->getSoulMax()); } else { @@ -1652,7 +1652,7 @@ int PlayerFunctions::luaPlayerGetMaxSoul(lua_State* L) { int PlayerFunctions::luaPlayerGetBankBalance(lua_State* L) { // player:getBankBalance() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getBankBalance()); } else { @@ -1663,7 +1663,7 @@ int PlayerFunctions::luaPlayerGetBankBalance(lua_State* L) { int PlayerFunctions::luaPlayerSetBankBalance(lua_State* L) { // player:setBankBalance(bankBalance) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1691,7 +1691,7 @@ int PlayerFunctions::luaPlayerSetStorageValue(lua_State* L) { // player:setStorageValue(key, value) int32_t value = getNumber(L, 3); uint32_t key = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (IS_IN_KEYRANGE(key, RESERVED_RANGE)) { std::ostringstream ss; ss << "Accessing reserved range: " << key; @@ -1711,7 +1711,7 @@ int PlayerFunctions::luaPlayerSetStorageValue(lua_State* L) { int PlayerFunctions::luaPlayerGetStorageValueByName(lua_State* L) { // player:getStorageValueByName(name) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -1725,7 +1725,7 @@ int PlayerFunctions::luaPlayerGetStorageValueByName(lua_State* L) { int PlayerFunctions::luaPlayerSetStorageValueByName(lua_State* L) { // player:setStorageValueByName(storageName, value) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -1742,7 +1742,7 @@ int PlayerFunctions::luaPlayerSetStorageValueByName(lua_State* L) { int PlayerFunctions::luaPlayerAddItem(lua_State* L) { // player:addItem(itemId, count = 1, canDropOnMap = true, subType = 1, slot = CONST_SLOT_WHEREEVER, tier = 0) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { pushBoolean(L, false); return 1; @@ -1840,7 +1840,7 @@ int PlayerFunctions::luaPlayerAddItemEx(lua_State* L) { return 1; } - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1872,7 +1872,7 @@ int PlayerFunctions::luaPlayerAddItemEx(lua_State* L) { int PlayerFunctions::luaPlayerRemoveStashItem(lua_State* L) { // player:removeStashItem(itemId, count) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1902,7 +1902,7 @@ int PlayerFunctions::luaPlayerRemoveStashItem(lua_State* L) { int PlayerFunctions::luaPlayerRemoveItem(lua_State* L) { // player:removeItem(itemId, count[, subType = -1[, ignoreEquipped = false]]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1928,7 +1928,7 @@ int PlayerFunctions::luaPlayerRemoveItem(lua_State* L) { int PlayerFunctions::luaPlayerSendContainer(lua_State* L) { // player:sendContainer(container) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1947,7 +1947,7 @@ int PlayerFunctions::luaPlayerSendContainer(lua_State* L) { int PlayerFunctions::luaPlayerSendUpdateContainer(lua_State* L) { // player:sendUpdateContainer(container) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1966,7 +1966,7 @@ int PlayerFunctions::luaPlayerSendUpdateContainer(lua_State* L) { int PlayerFunctions::luaPlayerGetMoney(lua_State* L) { // player:getMoney() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMoney()); } else { @@ -1978,7 +1978,7 @@ int PlayerFunctions::luaPlayerGetMoney(lua_State* L) { int PlayerFunctions::luaPlayerAddMoney(lua_State* L) { // player:addMoney(money) uint64_t money = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { g_game().addMoney(player, money); pushBoolean(L, true); @@ -1990,7 +1990,7 @@ int PlayerFunctions::luaPlayerAddMoney(lua_State* L) { int PlayerFunctions::luaPlayerRemoveMoney(lua_State* L) { // player:removeMoney(money[, flags = 0[, useBank = true]]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint64_t money = getNumber(L, 2); int32_t flags = getNumber(L, 3, 0); @@ -2004,7 +2004,7 @@ int PlayerFunctions::luaPlayerRemoveMoney(lua_State* L) { int PlayerFunctions::luaPlayerShowTextDialog(lua_State* L) { // player:showTextDialog(id or name or userdata[, text[, canWrite[, length]]]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2061,7 +2061,7 @@ int PlayerFunctions::luaPlayerSendTextMessage(lua_State* L) { // player:sendTextMessage(type, text[, position, primaryValue = 0, primaryColor = TEXTCOLOR_NONE[, secondaryValue = 0, secondaryColor = TEXTCOLOR_NONE]]) // player:sendTextMessage(type, text, channelId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2099,7 +2099,7 @@ int PlayerFunctions::luaPlayerSendTextMessage(lua_State* L) { int PlayerFunctions::luaPlayerSendChannelMessage(lua_State* L) { // player:sendChannelMessage(author, text, type, channelId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2116,13 +2116,13 @@ int PlayerFunctions::luaPlayerSendChannelMessage(lua_State* L) { int PlayerFunctions::luaPlayerSendPrivateMessage(lua_State* L) { // player:sendPrivateMessage(speaker, text[, type]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &speaker = getUserdataShared(L, 2); + std::shared_ptr speaker = getUserdataShared(L, 2); const std::string &text = getString(L, 3); SpeakClasses type = getNumber(L, 4, TALKTYPE_PRIVATE_FROM); player->sendPrivateMessage(speaker, type, text); @@ -2132,7 +2132,7 @@ int PlayerFunctions::luaPlayerSendPrivateMessage(lua_State* L) { int PlayerFunctions::luaPlayerChannelSay(lua_State* L) { // player:channelSay(speaker, type, text, channelId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2150,7 +2150,7 @@ int PlayerFunctions::luaPlayerChannelSay(lua_State* L) { int PlayerFunctions::luaPlayerOpenChannel(lua_State* L) { // player:openChannel(channelId) uint16_t channelId = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { g_game().playerOpenChannel(player->getID(), channelId); pushBoolean(L, true); @@ -2162,7 +2162,7 @@ int PlayerFunctions::luaPlayerOpenChannel(lua_State* L) { int PlayerFunctions::luaPlayerGetSlotItem(lua_State* L) { // player:getSlotItem(slot) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2187,7 +2187,7 @@ int PlayerFunctions::luaPlayerGetSlotItem(lua_State* L) { int PlayerFunctions::luaPlayerGetParty(lua_State* L) { // player:getParty() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2205,7 +2205,7 @@ int PlayerFunctions::luaPlayerGetParty(lua_State* L) { int PlayerFunctions::luaPlayerAddOutfit(lua_State* L) { // player:addOutfit(lookType) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->addOutfit(getNumber(L, 2), 0); pushBoolean(L, true); @@ -2217,7 +2217,7 @@ int PlayerFunctions::luaPlayerAddOutfit(lua_State* L) { int PlayerFunctions::luaPlayerAddOutfitAddon(lua_State* L) { // player:addOutfitAddon(lookType, addon) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); uint8_t addon = getNumber(L, 3); @@ -2231,7 +2231,7 @@ int PlayerFunctions::luaPlayerAddOutfitAddon(lua_State* L) { int PlayerFunctions::luaPlayerRemoveOutfit(lua_State* L) { // player:removeOutfit(lookType) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); pushBoolean(L, player->removeOutfit(lookType)); @@ -2243,7 +2243,7 @@ int PlayerFunctions::luaPlayerRemoveOutfit(lua_State* L) { int PlayerFunctions::luaPlayerRemoveOutfitAddon(lua_State* L) { // player:removeOutfitAddon(lookType, addon) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); uint8_t addon = getNumber(L, 3); @@ -2256,7 +2256,7 @@ int PlayerFunctions::luaPlayerRemoveOutfitAddon(lua_State* L) { int PlayerFunctions::luaPlayerHasOutfit(lua_State* L) { // player:hasOutfit(lookType[, addon = 0]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); uint8_t addon = getNumber(L, 3, 0); @@ -2269,7 +2269,7 @@ int PlayerFunctions::luaPlayerHasOutfit(lua_State* L) { int PlayerFunctions::luaPlayerSendOutfitWindow(lua_State* L) { // player:sendOutfitWindow() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->sendOutfitWindow(); pushBoolean(L, true); @@ -2281,7 +2281,7 @@ int PlayerFunctions::luaPlayerSendOutfitWindow(lua_State* L) { int PlayerFunctions::luaPlayerAddMount(lua_State* L) { // player:addMount(mountId or mountName) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2304,7 +2304,7 @@ int PlayerFunctions::luaPlayerAddMount(lua_State* L) { int PlayerFunctions::luaPlayerRemoveMount(lua_State* L) { // player:removeMount(mountId or mountName) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2327,7 +2327,7 @@ int PlayerFunctions::luaPlayerRemoveMount(lua_State* L) { int PlayerFunctions::luaPlayerHasMount(lua_State* L) { // player:hasMount(mountId or mountName) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2350,7 +2350,7 @@ int PlayerFunctions::luaPlayerHasMount(lua_State* L) { int PlayerFunctions::luaPlayerAddFamiliar(lua_State* L) { // player:addFamiliar(lookType) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->addFamiliar(getNumber(L, 2)); pushBoolean(L, true); @@ -2362,7 +2362,7 @@ int PlayerFunctions::luaPlayerAddFamiliar(lua_State* L) { int PlayerFunctions::luaPlayerRemoveFamiliar(lua_State* L) { // player:removeFamiliar(lookType) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); pushBoolean(L, player->removeFamiliar(lookType)); @@ -2374,7 +2374,7 @@ int PlayerFunctions::luaPlayerRemoveFamiliar(lua_State* L) { int PlayerFunctions::luaPlayerHasFamiliar(lua_State* L) { // player:hasFamiliar(lookType) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t lookType = getNumber(L, 2); pushBoolean(L, player->canFamiliar(lookType)); @@ -2386,7 +2386,7 @@ int PlayerFunctions::luaPlayerHasFamiliar(lua_State* L) { int PlayerFunctions::luaPlayerSetFamiliarLooktype(lua_State* L) { // player:setFamiliarLooktype(lookType) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setFamiliarLooktype(getNumber(L, 2)); pushBoolean(L, true); @@ -2398,7 +2398,7 @@ int PlayerFunctions::luaPlayerSetFamiliarLooktype(lua_State* L) { int PlayerFunctions::luaPlayerGetFamiliarLooktype(lua_State* L) { // player:getFamiliarLooktype() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->defaultOutfit.lookFamiliarsType); } else { @@ -2409,7 +2409,7 @@ int PlayerFunctions::luaPlayerGetFamiliarLooktype(lua_State* L) { int PlayerFunctions::luaPlayerGetPremiumDays(lua_State* L) { // player:getPremiumDays() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player && player->getAccount()) { lua_pushnumber(L, player->getAccount()->getPremiumRemainingDays()); } else { @@ -2420,7 +2420,7 @@ int PlayerFunctions::luaPlayerGetPremiumDays(lua_State* L) { int PlayerFunctions::luaPlayerAddPremiumDays(lua_State* L) { // player:addPremiumDays(days) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { lua_pushnil(L); return 1; @@ -2449,7 +2449,7 @@ int PlayerFunctions::luaPlayerAddPremiumDays(lua_State* L) { int PlayerFunctions::luaPlayerRemovePremiumDays(lua_State* L) { // player:removePremiumDays(days) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { lua_pushnil(L); return 1; @@ -2478,7 +2478,7 @@ int PlayerFunctions::luaPlayerRemovePremiumDays(lua_State* L) { int PlayerFunctions::luaPlayerGetTibiaCoins(lua_State* L) { // player:getTibiaCoins() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2496,7 +2496,7 @@ int PlayerFunctions::luaPlayerGetTibiaCoins(lua_State* L) { int PlayerFunctions::luaPlayerAddTibiaCoins(lua_State* L) { // player:addTibiaCoins(coins) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2522,7 +2522,7 @@ int PlayerFunctions::luaPlayerAddTibiaCoins(lua_State* L) { int PlayerFunctions::luaPlayerRemoveTibiaCoins(lua_State* L) { // player:removeTibiaCoins(coins) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2547,7 +2547,7 @@ int PlayerFunctions::luaPlayerRemoveTibiaCoins(lua_State* L) { int PlayerFunctions::luaPlayerGetTransferableCoins(lua_State* L) { // player:getTransferableCoins() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2565,7 +2565,7 @@ int PlayerFunctions::luaPlayerGetTransferableCoins(lua_State* L) { int PlayerFunctions::luaPlayerAddTransferableCoins(lua_State* L) { // player:addTransferableCoins(coins) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2591,7 +2591,7 @@ int PlayerFunctions::luaPlayerAddTransferableCoins(lua_State* L) { int PlayerFunctions::luaPlayerRemoveTransferableCoins(lua_State* L) { // player:removeTransferableCoins(coins) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player || !player->getAccount()) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); @@ -2618,7 +2618,7 @@ int PlayerFunctions::luaPlayerRemoveTransferableCoins(lua_State* L) { int PlayerFunctions::luaPlayerHasBlessing(lua_State* L) { // player:hasBlessing(blessing) uint8_t blessing = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->hasBlessing(blessing)); } else { @@ -2629,7 +2629,7 @@ int PlayerFunctions::luaPlayerHasBlessing(lua_State* L) { int PlayerFunctions::luaPlayerAddBlessing(lua_State* L) { // player:addBlessing(blessing) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2646,7 +2646,7 @@ int PlayerFunctions::luaPlayerAddBlessing(lua_State* L) { int PlayerFunctions::luaPlayerRemoveBlessing(lua_State* L) { // player:removeBlessing(blessing) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2667,7 +2667,7 @@ int PlayerFunctions::luaPlayerRemoveBlessing(lua_State* L) { int PlayerFunctions::luaPlayerGetBlessingCount(lua_State* L) { // player:getBlessingCount(index) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); uint8_t index = getNumber(L, 2); if (index == 0) { index = 1; @@ -2683,7 +2683,7 @@ int PlayerFunctions::luaPlayerGetBlessingCount(lua_State* L) { int PlayerFunctions::luaPlayerCanLearnSpell(lua_State* L) { // player:canLearnSpell(spellName) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2717,7 +2717,7 @@ int PlayerFunctions::luaPlayerCanLearnSpell(lua_State* L) { int PlayerFunctions::luaPlayerLearnSpell(lua_State* L) { // player:learnSpell(spellName) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { const std::string &spellName = getString(L, 2); player->learnInstantSpell(spellName); @@ -2730,7 +2730,7 @@ int PlayerFunctions::luaPlayerLearnSpell(lua_State* L) { int PlayerFunctions::luaPlayerForgetSpell(lua_State* L) { // player:forgetSpell(spellName) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { const std::string &spellName = getString(L, 2); player->forgetInstantSpell(spellName); @@ -2743,7 +2743,7 @@ int PlayerFunctions::luaPlayerForgetSpell(lua_State* L) { int PlayerFunctions::luaPlayerHasLearnedSpell(lua_State* L) { // player:hasLearnedSpell(spellName) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { const std::string &spellName = getString(L, 2); pushBoolean(L, player->hasLearnedInstantSpell(spellName)); @@ -2755,7 +2755,7 @@ int PlayerFunctions::luaPlayerHasLearnedSpell(lua_State* L) { int PlayerFunctions::luaPlayerSendTutorial(lua_State* L) { // player:sendTutorial(tutorialId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint8_t tutorialId = getNumber(L, 2); player->sendTutorial(tutorialId); @@ -2768,7 +2768,7 @@ int PlayerFunctions::luaPlayerSendTutorial(lua_State* L) { int PlayerFunctions::luaPlayerOpenImbuementWindow(lua_State* L) { // player:openImbuementWindow(item) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -2788,7 +2788,7 @@ int PlayerFunctions::luaPlayerOpenImbuementWindow(lua_State* L) { int PlayerFunctions::luaPlayerCloseImbuementWindow(lua_State* L) { // player:closeImbuementWindow() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -2801,7 +2801,7 @@ int PlayerFunctions::luaPlayerCloseImbuementWindow(lua_State* L) { int PlayerFunctions::luaPlayerAddMapMark(lua_State* L) { // player:addMapMark(position, type, description) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { const Position &position = getPosition(L, 2); uint8_t type = getNumber(L, 3); @@ -2816,7 +2816,7 @@ int PlayerFunctions::luaPlayerAddMapMark(lua_State* L) { int PlayerFunctions::luaPlayerSave(lua_State* L) { // player:save() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { if (!player->isOffline()) { player->loginPosition = player->getPosition(); @@ -2833,7 +2833,7 @@ int PlayerFunctions::luaPlayerSave(lua_State* L) { int PlayerFunctions::luaPlayerPopupFYI(lua_State* L) { // player:popupFYI(message) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { const std::string &message = getString(L, 2); player->sendFYIBox(message); @@ -2846,7 +2846,7 @@ int PlayerFunctions::luaPlayerPopupFYI(lua_State* L) { int PlayerFunctions::luaPlayerIsPzLocked(lua_State* L) { // player:isPzLocked() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->isPzLocked()); } else { @@ -2857,7 +2857,7 @@ int PlayerFunctions::luaPlayerIsPzLocked(lua_State* L) { int PlayerFunctions::luaPlayerGetClient(lua_State* L) { // player:getClient() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_createtable(L, 0, 2); setField(L, "version", player->getProtocolVersion()); @@ -2870,7 +2870,7 @@ int PlayerFunctions::luaPlayerGetClient(lua_State* L) { int PlayerFunctions::luaPlayerGetHouse(lua_State* L) { // player:getHouse() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2888,7 +2888,7 @@ int PlayerFunctions::luaPlayerGetHouse(lua_State* L) { int PlayerFunctions::luaPlayerSendHouseWindow(lua_State* L) { // player:sendHouseWindow(house, listId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2908,7 +2908,7 @@ int PlayerFunctions::luaPlayerSendHouseWindow(lua_State* L) { int PlayerFunctions::luaPlayerSetEditHouse(lua_State* L) { // player:setEditHouse(house, listId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2928,7 +2928,7 @@ int PlayerFunctions::luaPlayerSetEditHouse(lua_State* L) { int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { // player:setGhostMode(enabled) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2948,7 +2948,7 @@ int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { SpectatorHashSet spectators; g_game().map.getSpectators(spectators, position, true, true); for (auto spectator : spectators) { - const auto &tmpPlayer = spectator->getPlayer(); + auto tmpPlayer = spectator->getPlayer(); if (tmpPlayer != player && !tmpPlayer->isAccessPlayer()) { if (enabled) { tmpPlayer->sendRemoveTileThing(position, tile->getStackposOfCreature(tmpPlayer, player)); @@ -2981,7 +2981,7 @@ int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { int PlayerFunctions::luaPlayerGetContainerId(lua_State* L) { // player:getContainerId(container) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2998,7 +2998,7 @@ int PlayerFunctions::luaPlayerGetContainerId(lua_State* L) { int PlayerFunctions::luaPlayerGetContainerById(lua_State* L) { // player:getContainerById(id) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3016,7 +3016,7 @@ int PlayerFunctions::luaPlayerGetContainerById(lua_State* L) { int PlayerFunctions::luaPlayerGetContainerIndex(lua_State* L) { // player:getContainerIndex(id) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getContainerIndex(getNumber(L, 2))); } else { @@ -3027,7 +3027,7 @@ int PlayerFunctions::luaPlayerGetContainerIndex(lua_State* L) { int PlayerFunctions::luaPlayerGetInstantSpells(lua_State* L) { // player:getInstantSpells() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3052,7 +3052,7 @@ int PlayerFunctions::luaPlayerGetInstantSpells(lua_State* L) { int PlayerFunctions::luaPlayerCanCast(lua_State* L) { // player:canCast(spell) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); const auto spell = getUserdataShared(L, 2); if (player && spell) { pushBoolean(L, spell->canCast(player)); @@ -3064,7 +3064,7 @@ int PlayerFunctions::luaPlayerCanCast(lua_State* L) { int PlayerFunctions::luaPlayerHasChaseMode(lua_State* L) { // player:hasChaseMode() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->chaseMode); } else { @@ -3075,7 +3075,7 @@ int PlayerFunctions::luaPlayerHasChaseMode(lua_State* L) { int PlayerFunctions::luaPlayerHasSecureMode(lua_State* L) { // player:hasSecureMode() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->secureMode); } else { @@ -3086,7 +3086,7 @@ int PlayerFunctions::luaPlayerHasSecureMode(lua_State* L) { int PlayerFunctions::luaPlayerGetFightMode(lua_State* L) { // player:getFightMode() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->fightMode); } else { @@ -3097,7 +3097,7 @@ int PlayerFunctions::luaPlayerGetFightMode(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseXpGain(lua_State* L) { // player:getBaseXpGain() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getBaseXpGain()); } else { @@ -3108,7 +3108,7 @@ int PlayerFunctions::luaPlayerGetBaseXpGain(lua_State* L) { int PlayerFunctions::luaPlayerSetBaseXpGain(lua_State* L) { // player:setBaseXpGain(value) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setBaseXpGain(getNumber(L, 2)); player->sendStats(); @@ -3121,7 +3121,7 @@ int PlayerFunctions::luaPlayerSetBaseXpGain(lua_State* L) { int PlayerFunctions::luaPlayerGetVoucherXpBoost(lua_State* L) { // player:getVoucherXpBoost() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getVoucherXpBoost()); } else { @@ -3132,7 +3132,7 @@ int PlayerFunctions::luaPlayerGetVoucherXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetVoucherXpBoost(lua_State* L) { // player:setVoucherXpBoost(value) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setVoucherXpBoost(getNumber(L, 2)); player->sendStats(); @@ -3145,7 +3145,7 @@ int PlayerFunctions::luaPlayerSetVoucherXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerGetGrindingXpBoost(lua_State* L) { // player:getGrindingXpBoost() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getGrindingXpBoost()); } else { @@ -3156,7 +3156,7 @@ int PlayerFunctions::luaPlayerGetGrindingXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetGrindingXpBoost(lua_State* L) { // player:setGrindingXpBoost(value) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setGrindingXpBoost(getNumber(L, 2)); player->sendStats(); @@ -3169,7 +3169,7 @@ int PlayerFunctions::luaPlayerSetGrindingXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerGetStoreXpBoost(lua_State* L) { // player:getStoreXpBoost() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getStoreXpBoost()); } else { @@ -3180,7 +3180,7 @@ int PlayerFunctions::luaPlayerGetStoreXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetStoreXpBoost(lua_State* L) { // player:setStoreXpBoost(value) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t experience = getNumber(L, 2); player->setStoreXpBoost(experience); @@ -3193,7 +3193,7 @@ int PlayerFunctions::luaPlayerSetStoreXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerGetStaminaXpBoost(lua_State* L) { // player:getStaminaXpBoost() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getStaminaXpBoost()); } else { @@ -3204,7 +3204,7 @@ int PlayerFunctions::luaPlayerGetStaminaXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetStaminaXpBoost(lua_State* L) { // player:setStaminaXpBoost(value) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { player->setStaminaXpBoost(getNumber(L, 2)); player->sendStats(); @@ -3217,7 +3217,7 @@ int PlayerFunctions::luaPlayerSetStaminaXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetExpBoostStamina(lua_State* L) { // player:setExpBoostStamina(percent) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { uint16_t stamina = getNumber(L, 2); player->setExpBoostStamina(stamina); @@ -3231,7 +3231,7 @@ int PlayerFunctions::luaPlayerSetExpBoostStamina(lua_State* L) { int PlayerFunctions::luaPlayerGetExpBoostStamina(lua_State* L) { // player:getExpBoostStamina() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getExpBoostStamina()); } else { @@ -3242,7 +3242,7 @@ int PlayerFunctions::luaPlayerGetExpBoostStamina(lua_State* L) { int PlayerFunctions::luaPlayerGetIdleTime(lua_State* L) { // player:getIdleTime() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getIdleTime()); } else { @@ -3253,7 +3253,7 @@ int PlayerFunctions::luaPlayerGetIdleTime(lua_State* L) { int PlayerFunctions::luaPlayerGetFreeBackpackSlots(lua_State* L) { // player:getFreeBackpackSlots() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); } @@ -3263,7 +3263,7 @@ int PlayerFunctions::luaPlayerGetFreeBackpackSlots(lua_State* L) { } int PlayerFunctions::luaPlayerIsOffline(lua_State* L) { - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player) { pushBoolean(L, player->isOffline()); } else { @@ -3275,7 +3275,7 @@ int PlayerFunctions::luaPlayerIsOffline(lua_State* L) { int PlayerFunctions::luaPlayerOpenMarket(lua_State* L) { // player:openMarket() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3289,7 +3289,7 @@ int PlayerFunctions::luaPlayerOpenMarket(lua_State* L) { // Forge int PlayerFunctions::luaPlayerOpenForge(lua_State* L) { // player:openForge() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3303,7 +3303,7 @@ int PlayerFunctions::luaPlayerOpenForge(lua_State* L) { int PlayerFunctions::luaPlayerCloseForge(lua_State* L) { // player:closeForge() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3317,7 +3317,7 @@ int PlayerFunctions::luaPlayerCloseForge(lua_State* L) { int PlayerFunctions::luaPlayerAddForgeDusts(lua_State* L) { // player:addForgeDusts(amount) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3331,7 +3331,7 @@ int PlayerFunctions::luaPlayerAddForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerRemoveForgeDusts(lua_State* L) { // player:removeForgeDusts(amount) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3345,7 +3345,7 @@ int PlayerFunctions::luaPlayerRemoveForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeDusts(lua_State* L) { // player:getForgeDusts() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3358,7 +3358,7 @@ int PlayerFunctions::luaPlayerGetForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerSetForgeDusts(lua_State* L) { // player:setForgeDusts() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3372,7 +3372,7 @@ int PlayerFunctions::luaPlayerSetForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerAddForgeDustLevel(lua_State* L) { // player:addForgeDustLevel(amount) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3386,7 +3386,7 @@ int PlayerFunctions::luaPlayerAddForgeDustLevel(lua_State* L) { int PlayerFunctions::luaPlayerRemoveForgeDustLevel(lua_State* L) { // player:removeForgeDustLevel(amount) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3400,7 +3400,7 @@ int PlayerFunctions::luaPlayerRemoveForgeDustLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeDustLevel(lua_State* L) { // player:getForgeDustLevel() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3413,7 +3413,7 @@ int PlayerFunctions::luaPlayerGetForgeDustLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeSlivers(lua_State* L) { // player:getForgeSlivers() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3427,7 +3427,7 @@ int PlayerFunctions::luaPlayerGetForgeSlivers(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeCores(lua_State* L) { // player:getForgeCores() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3441,7 +3441,7 @@ int PlayerFunctions::luaPlayerGetForgeCores(lua_State* L) { int PlayerFunctions::luaPlayerSetFaction(lua_State* L) { // player:setFaction(factionId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3456,7 +3456,7 @@ int PlayerFunctions::luaPlayerSetFaction(lua_State* L) { int PlayerFunctions::luaPlayerGetFaction(lua_State* L) { // player:getFaction() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (player == nullptr) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3469,7 +3469,7 @@ int PlayerFunctions::luaPlayerGetFaction(lua_State* L) { int PlayerFunctions::luaPlayerIsUIExhausted(lua_State* L) { // player:isUIExhausted() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3483,7 +3483,7 @@ int PlayerFunctions::luaPlayerIsUIExhausted(lua_State* L) { int PlayerFunctions::luaPlayerUpdateUIExhausted(lua_State* L) { // player:updateUIExhausted(exhaustionTime = 250) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3498,7 +3498,7 @@ int PlayerFunctions::luaPlayerUpdateUIExhausted(lua_State* L) { // Bosstiary Cooldown Timer int PlayerFunctions::luaPlayerBosstiaryCooldownTimer(lua_State* L) { // player:sendBosstiaryCooldownTimer() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3512,7 +3512,7 @@ int PlayerFunctions::luaPlayerBosstiaryCooldownTimer(lua_State* L) { int PlayerFunctions::luaPlayerGetBosstiaryLevel(lua_State* L) { // player:getBosstiaryLevel(name) - if (const auto &player = getUserdataShared(L, 1); + if (std::shared_ptr player = getUserdataShared(L, 1); player) { const auto mtype = g_monsters().getMonsterType(getString(L, 2)); if (mtype) { @@ -3534,7 +3534,7 @@ int PlayerFunctions::luaPlayerGetBosstiaryLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetBosstiaryKills(lua_State* L) { // player:getBosstiaryKills(name) - if (const auto &player = getUserdataShared(L, 1); + if (std::shared_ptr player = getUserdataShared(L, 1); player) { const auto mtype = g_monsters().getMonsterType(getString(L, 2)); if (mtype) { @@ -3556,7 +3556,7 @@ int PlayerFunctions::luaPlayerGetBosstiaryKills(lua_State* L) { int PlayerFunctions::luaPlayerAddBosstiaryKill(lua_State* L) { // player:addBosstiaryKill(name[, amount = 1]) - if (const auto &player = getUserdataShared(L, 1); + if (std::shared_ptr player = getUserdataShared(L, 1); player) { const auto mtype = g_monsters().getMonsterType(getString(L, 2)); if (mtype) { @@ -3573,7 +3573,7 @@ int PlayerFunctions::luaPlayerAddBosstiaryKill(lua_State* L) { int PlayerFunctions::luaPlayerSetBossPoints(lua_State* L) { // player:setBossPoints() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3587,7 +3587,7 @@ int PlayerFunctions::luaPlayerSetBossPoints(lua_State* L) { int PlayerFunctions::luaPlayerSetRemoveBossTime(lua_State* L) { // player:setRemoveBossTime() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3601,7 +3601,7 @@ int PlayerFunctions::luaPlayerSetRemoveBossTime(lua_State* L) { int PlayerFunctions::luaPlayerGetSlotBossId(lua_State* L) { // player:getSlotBossId(slotId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3616,7 +3616,7 @@ int PlayerFunctions::luaPlayerGetSlotBossId(lua_State* L) { int PlayerFunctions::luaPlayerGetBossBonus(lua_State* L) { // player:getBossBonus(slotId) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3638,7 +3638,7 @@ int PlayerFunctions::luaPlayerGetBossBonus(lua_State* L) { int PlayerFunctions::luaPlayerSendSingleSoundEffect(lua_State* L) { // player:sendSingleSoundEffect(soundId[, actor = true]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3655,7 +3655,7 @@ int PlayerFunctions::luaPlayerSendSingleSoundEffect(lua_State* L) { int PlayerFunctions::luaPlayerSendDoubleSoundEffect(lua_State* L) { // player:sendDoubleSoundEffect(mainSoundId, secondarySoundId[, actor = true]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3686,7 +3686,7 @@ int PlayerFunctions::luaPlayerGetName(lua_State* L) { int PlayerFunctions::luaPlayerHasGroupFlag(lua_State* L) { // player:hasGroupFlag(flag) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3699,7 +3699,7 @@ int PlayerFunctions::luaPlayerHasGroupFlag(lua_State* L) { int PlayerFunctions::luaPlayerSetGroupFlag(lua_State* L) { // player:setGroupFlag(flag) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3712,7 +3712,7 @@ int PlayerFunctions::luaPlayerSetGroupFlag(lua_State* L) { int PlayerFunctions::luaPlayerRemoveGroupFlag(lua_State* L) { // player:removeGroupFlag(flag) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3726,7 +3726,7 @@ int PlayerFunctions::luaPlayerRemoveGroupFlag(lua_State* L) { // Hazard system int PlayerFunctions::luaPlayerAddHazardSystemPoints(lua_State* L) { // player:setHazardSystemPoints(amount) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { pushBoolean(L, false); reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); @@ -3753,7 +3753,7 @@ int PlayerFunctions::luaPlayerGetHazardSystemPoints(lua_State* L) { int PlayerFunctions::luaPlayerSetLoyaltyBonus(lua_State* L) { // player:setLoyaltyBonus(amount) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3766,7 +3766,7 @@ int PlayerFunctions::luaPlayerSetLoyaltyBonus(lua_State* L) { int PlayerFunctions::luaPlayerGetLoyaltyBonus(lua_State* L) { // player:getLoyaltyBonus() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3790,7 +3790,7 @@ int PlayerFunctions::luaPlayerGetLoyaltyPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetLoyaltyTitle(lua_State* L) { // player:getLoyaltyTitle() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3802,7 +3802,7 @@ int PlayerFunctions::luaPlayerGetLoyaltyTitle(lua_State* L) { int PlayerFunctions::luaPlayerSetLoyaltyTitle(lua_State* L) { // player:setLoyaltyTitle(name) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3816,7 +3816,7 @@ int PlayerFunctions::luaPlayerSetLoyaltyTitle(lua_State* L) { // Wheel of destiny system int PlayerFunctions::luaPlayerInstantSkillWOD(lua_State* L) { // player:instantSkillWOD(name[, value]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3834,7 +3834,7 @@ int PlayerFunctions::luaPlayerInstantSkillWOD(lua_State* L) { int PlayerFunctions::luaPlayerUpgradeSpellWOD(lua_State* L) { // player:upgradeSpellsWOD([name[, add]]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3864,7 +3864,7 @@ int PlayerFunctions::luaPlayerUpgradeSpellWOD(lua_State* L) { int PlayerFunctions::luaPlayerRevelationStageWOD(lua_State* L) { // player:revelationStagesWOD([name[, set]]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3890,7 +3890,7 @@ int PlayerFunctions::luaPlayerRevelationStageWOD(lua_State* L) { int PlayerFunctions::luaPlayerReloadData(lua_State* L) { // player:reloadData() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3907,7 +3907,7 @@ int PlayerFunctions::luaPlayerReloadData(lua_State* L) { int PlayerFunctions::luaPlayerOnThinkWheelOfDestiny(lua_State* L) { // player:onThinkWheelOfDestiny([force = false]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3920,7 +3920,7 @@ int PlayerFunctions::luaPlayerOnThinkWheelOfDestiny(lua_State* L) { int PlayerFunctions::luaPlayerAvatarTimer(lua_State* L) { // player:avatarTimer([value]) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3937,7 +3937,7 @@ int PlayerFunctions::luaPlayerAvatarTimer(lua_State* L) { int PlayerFunctions::luaPlayerGetWheelSpellAdditionalArea(lua_State* L) { // player:getWheelSpellAdditionalArea(spellname) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3964,7 +3964,7 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalArea(lua_State* L) { int PlayerFunctions::luaPlayerGetWheelSpellAdditionalTarget(lua_State* L) { // player:getWheelSpellAdditionalTarget(spellname) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -3991,7 +3991,7 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalTarget(lua_State* L) { int PlayerFunctions::luaPlayerGetWheelSpellAdditionalDuration(lua_State* L) { // player:getWheelSpellAdditionalDuration(spellname) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -4018,7 +4018,7 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalDuration(lua_State* L) { int PlayerFunctions::luaPlayerUpdateConcoction(lua_State* L) { // player:updateConcoction(itemid, timeLeft) - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -4030,7 +4030,7 @@ int PlayerFunctions::luaPlayerUpdateConcoction(lua_State* L) { int PlayerFunctions::luaPlayerClearSpellCooldowns(lua_State* L) { // player:clearSpellCooldowns() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -4042,7 +4042,7 @@ int PlayerFunctions::luaPlayerClearSpellCooldowns(lua_State* L) { int PlayerFunctions::luaPlayerIsVip(lua_State* L) { // player:isVip() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -4054,7 +4054,7 @@ int PlayerFunctions::luaPlayerIsVip(lua_State* L) { int PlayerFunctions::luaPlayerGetVipDays(lua_State* L) { // player:getVipDays() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -4067,7 +4067,7 @@ int PlayerFunctions::luaPlayerGetVipDays(lua_State* L) { int PlayerFunctions::luaPlayerGetVipTime(lua_State* L) { // player:getVipTime() - const auto &player = getUserdataShared(L, 1); + std::shared_ptr player = getUserdataShared(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/items/item_functions.cpp b/src/lua/functions/items/item_functions.cpp index 1b89b055818..1fb527cd07a 100644 --- a/src/lua/functions/items/item_functions.cpp +++ b/src/lua/functions/items/item_functions.cpp @@ -707,7 +707,7 @@ int ItemFunctions::luaItemMoveToSlot(lua_State* L) { return 1; } - const auto &player = getUserdataShared(L, 2); + std::shared_ptr player = getUserdataShared(L, 2); if (!player) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/map/house_functions.cpp b/src/lua/functions/map/house_functions.cpp index 3f6639450e6..18c4d66b0fa 100644 --- a/src/lua/functions/map/house_functions.cpp +++ b/src/lua/functions/map/house_functions.cpp @@ -131,8 +131,8 @@ int HouseFunctions::luaHouseSetOwnerGuid(lua_State* L) { int HouseFunctions::luaHouseStartTrade(lua_State* L) { // house:startTrade(player, tradePartner) House* house = getUserdata(L, 1); - const auto &player = getUserdataShared(L, 2); - const auto &tradePartner = getUserdataShared(L, 3); + std::shared_ptr player = getUserdataShared(L, 2); + std::shared_ptr tradePartner = getUserdataShared(L, 3); if (!player || !tradePartner || !house) { lua_pushnil(L); @@ -318,7 +318,7 @@ int HouseFunctions::luaHouseCanEditAccessList(lua_State* L) { } uint32_t listId = getNumber(L, 2); - const auto &player = getPlayer(L, 3); + std::shared_ptr player = getPlayer(L, 3); pushBoolean(L, house->canEditAccessList(listId, player)); return 1; @@ -377,7 +377,7 @@ int HouseFunctions::luaHouseIsInvited(lua_State* L) { return 1; } - const auto &player = getPlayer(L, 2); + std::shared_ptr player = getPlayer(L, 2); if (!player) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/map/position_functions.cpp b/src/lua/functions/map/position_functions.cpp index 3916a622bf1..ba0633a819e 100644 --- a/src/lua/functions/map/position_functions.cpp +++ b/src/lua/functions/map/position_functions.cpp @@ -149,7 +149,7 @@ int PositionFunctions::luaPositionSendMagicEffect(lua_State* L) { // position:sendMagicEffect(magicEffect[, player = nullptr]) SpectatorHashSet spectators; if (lua_gettop(L) >= 3) { - const auto &player = getPlayer(L, 3); + std::shared_ptr player = getPlayer(L, 3); if (player) { spectators.insert(player); } @@ -177,7 +177,7 @@ int PositionFunctions::luaPositionRemoveMagicEffect(lua_State* L) { // position:removeMagicEffect(magicEffect[, player = nullptr]) SpectatorHashSet spectators; if (lua_gettop(L) >= 3) { - const auto &player = getPlayer(L, 3); + std::shared_ptr player = getPlayer(L, 3); if (player) { spectators.insert(player); } @@ -205,7 +205,7 @@ int PositionFunctions::luaPositionSendDistanceEffect(lua_State* L) { // position:sendDistanceEffect(positionEx, distanceEffect[, player = nullptr]) SpectatorHashSet spectators; if (lua_gettop(L) >= 4) { - const auto &player = getPlayer(L, 4); + std::shared_ptr player = getPlayer(L, 4); if (player) { spectators.insert(player); } diff --git a/src/lua/modules/modules.cpp b/src/lua/modules/modules.cpp index bda2c157570..18d1107ff76 100644 --- a/src/lua/modules/modules.cpp +++ b/src/lua/modules/modules.cpp @@ -78,7 +78,7 @@ Module* Modules::getEventByRecvbyte(uint8_t recvbyte, bool force) { } void Modules::executeOnRecvbyte(uint32_t playerId, NetworkMessage &msg, uint8_t byte) const { - const auto &player = g_game().getPlayerByID(playerId); + std::shared_ptr player = g_game().getPlayerByID(playerId); if (!player) { return; } @@ -152,7 +152,7 @@ void Module::clearEvent() { loaded = false; } -void Module::executeOnRecvbyte(const std::shared_ptr &player, NetworkMessage &msg) { +void Module::executeOnRecvbyte(std::shared_ptr player, NetworkMessage &msg) { // onRecvbyte(player, msg, recvbyte) if (!scriptInterface->reserveScriptEnv()) { g_logger().error("Call stack overflow. Too many lua script calls being nested {}", player->getName()); diff --git a/src/lua/modules/modules.hpp b/src/lua/modules/modules.hpp index 3470df890c8..f72baf94fe1 100644 --- a/src/lua/modules/modules.hpp +++ b/src/lua/modules/modules.hpp @@ -35,7 +35,7 @@ class Module final : public Event { void copyEvent(Module* creatureEvent); // scripting - void executeOnRecvbyte(const std::shared_ptr &player, NetworkMessage &msg); + void executeOnRecvbyte(std::shared_ptr player, NetworkMessage &msg); // uint8_t getRecvbyte() { diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index f89c4c2a232..4b1864d43f5 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -24,7 +24,7 @@ void House::addTile(std::shared_ptr tile) { updateDoorDescription(); } -void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, const std::shared_ptr &player /* = nullptr*/) { +void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, std::shared_ptr player /* = nullptr*/) { if (updateDatabase && owner != guid) { Database &db = Database::getInstance(); @@ -136,7 +136,7 @@ void House::updateDoorDescription() const { } } -AccessHouseLevel_t House::getHouseAccessLevel(const std::shared_ptr &player) { +AccessHouseLevel_t House::getHouseAccessLevel(std::shared_ptr player) { if (!player) { return HOUSE_OWNER; } @@ -166,7 +166,7 @@ AccessHouseLevel_t House::getHouseAccessLevel(const std::shared_ptr &pla return HOUSE_NOT_INVITED; } -bool House::kickPlayer(const std::shared_ptr &player, const std::shared_ptr &target) { +bool House::kickPlayer(std::shared_ptr player, std::shared_ptr target) { if (!target) { return false; } @@ -207,7 +207,7 @@ void House::setAccessList(uint32_t listId, const std::string &textlist) { for (std::shared_ptr tile : houseTiles) { if (CreatureVector* creatures = tile->getCreatures()) { for (int32_t i = creatures->size(); --i >= 0;) { - const auto &player = (*creatures)[i]->getPlayer(); + std::shared_ptr player = (*creatures)[i]->getPlayer(); if (player && !isInvited(player)) { kickPlayer(nullptr, player); } @@ -221,11 +221,11 @@ bool House::transferToDepot() const { return false; } - const auto &player = g_game().getPlayerByGUID(owner); + std::shared_ptr player = g_game().getPlayerByGUID(owner); if (player) { transferToDepot(player); } else { - const auto &tmpPlayer = std::make_shared(nullptr); + std::shared_ptr tmpPlayer = std::make_shared(nullptr); if (!IOLoginData::loadPlayerById(tmpPlayer, owner)) { return false; } @@ -236,7 +236,7 @@ bool House::transferToDepot() const { return true; } -bool House::transferToDepot(const std::shared_ptr &player) const { +bool House::transferToDepot(std::shared_ptr player) const { if (townId == 0 || owner == 0) { return false; } @@ -261,7 +261,7 @@ bool House::transferToDepot(const std::shared_ptr &player) const { return true; } -void House::handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, const std::shared_ptr &player, std::shared_ptr houseTile) const { +void House::handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, std::shared_ptr player, std::shared_ptr houseTile) const { if (item->isWrapContainer()) { handleContainer(moveItemList, item); } @@ -300,7 +300,7 @@ bool House::getAccessList(uint32_t listId, std::string &list) const { return door->getAccessList(list); } -bool House::isInvited(const std::shared_ptr &player) { +bool House::isInvited(std::shared_ptr player) { return getHouseAccessLevel(player) != HOUSE_NOT_INVITED; } @@ -345,7 +345,7 @@ std::shared_ptr House::getDoorByPosition(const Position &pos) { return nullptr; } -bool House::canEditAccessList(uint32_t listId, const std::shared_ptr &player) { +bool House::canEditAccessList(uint32_t listId, std::shared_ptr player) { switch (getHouseAccessLevel(player)) { case HOUSE_OWNER: return true; @@ -388,7 +388,7 @@ std::shared_ptr HouseTransferItem::createHouseTransferItem(Ho return transferItem; } -void HouseTransferItem::onTradeEvent(TradeEvents_t event, const std::shared_ptr &owner) { +void HouseTransferItem::onTradeEvent(TradeEvents_t event, std::shared_ptr owner) { if (event == ON_TRADE_TRANSFER) { if (house) { house->executeTransfer(static_self_cast(), owner); @@ -402,7 +402,7 @@ void HouseTransferItem::onTradeEvent(TradeEvents_t event, const std::shared_ptr< } } -bool House::executeTransfer(std::shared_ptr item, const std::shared_ptr &newOwner) { +bool House::executeTransfer(std::shared_ptr item, std::shared_ptr newOwner) { if (transferItem != item) { return false; } @@ -454,7 +454,7 @@ void AccessList::parseList(const std::string &list) { } void AccessList::addPlayer(const std::string &name) { - const auto &player = g_game().getPlayerByName(name); + std::shared_ptr player = g_game().getPlayerByName(name); if (player) { playerList.insert(player->getGUID()); } else { @@ -502,7 +502,7 @@ void AccessList::addGuildRank(const std::string &name, const std::string &guildN } } -bool AccessList::isInList(const std::shared_ptr &player) { +bool AccessList::isInList(std::shared_ptr player) { if (allowEveryone) { return true; } @@ -548,7 +548,7 @@ void Door::setHouse(House* newHouse) { } } -bool Door::canUse(const std::shared_ptr &player) { +bool Door::canUse(std::shared_ptr player) { if (!house) { return true; } @@ -668,7 +668,7 @@ void Houses::payHouses(RentPeriod_t rentPeriod) const { continue; } - const auto &player = std::make_shared(nullptr); + std::shared_ptr player = std::make_shared(nullptr); if (!IOLoginData::loadPlayerById(player, ownerId)) { // Player doesn't exist, reset house owner house->setOwner(0); diff --git a/src/map/house/house.hpp b/src/map/house/house.hpp index e0febc918ae..d5331001372 100644 --- a/src/map/house/house.hpp +++ b/src/map/house/house.hpp @@ -25,7 +25,7 @@ class AccessList { void addGuild(const std::string &name); void addGuildRank(const std::string &name, const std::string &rankName); - bool isInList(const std::shared_ptr &player); + bool isInList(std::shared_ptr player); void getList(std::string &list) const; @@ -63,7 +63,7 @@ class Door final : public Item { return getAttribute(ItemAttribute_t::DOORID); } - bool canUse(const std::shared_ptr &player); + bool canUse(std::shared_ptr player); void setAccessList(const std::string &textlist); bool getAccessList(std::string &list) const; @@ -88,7 +88,7 @@ class HouseTransferItem final : public Item { explicit HouseTransferItem(House* newHouse) : Item(0), house(newHouse) { } - void onTradeEvent(TradeEvents_t event, const std::shared_ptr &owner) override; + void onTradeEvent(TradeEvents_t event, std::shared_ptr owner) override; bool canTransform() const override { return false; } @@ -104,17 +104,17 @@ class House { void addTile(std::shared_ptr tile); void updateDoorDescription() const; - bool canEditAccessList(uint32_t listId, const std::shared_ptr &player); + bool canEditAccessList(uint32_t listId, std::shared_ptr player); // listId special = values: // GUEST_LIST = guest list // SUBOWNER_LIST = subowner list void setAccessList(uint32_t listId, const std::string &textlist); bool getAccessList(uint32_t listId, std::string &list) const; - bool isInvited(const std::shared_ptr &player); + bool isInvited(std::shared_ptr player); - AccessHouseLevel_t getHouseAccessLevel(const std::shared_ptr &player); - bool kickPlayer(const std::shared_ptr &player, const std::shared_ptr &target); + AccessHouseLevel_t getHouseAccessLevel(std::shared_ptr player); + bool kickPlayer(std::shared_ptr player, std::shared_ptr target); void setEntryPos(Position pos) { posEntry = pos; @@ -130,7 +130,7 @@ class House { return houseName; } - void setOwner(uint32_t guid, bool updateDatabase = true, const std::shared_ptr &player = nullptr); + void setOwner(uint32_t guid, bool updateDatabase = true, std::shared_ptr player = nullptr); uint32_t getOwner() const { return owner; } @@ -180,7 +180,7 @@ class House { std::shared_ptr getTransferItem(); void resetTransferItem(); - bool executeTransfer(std::shared_ptr item, const std::shared_ptr &player); + bool executeTransfer(std::shared_ptr item, std::shared_ptr player); const HouseTileList &getTiles() const { return houseTiles; @@ -209,7 +209,7 @@ class House { private: bool transferToDepot() const; - bool transferToDepot(const std::shared_ptr &player) const; + bool transferToDepot(std::shared_ptr player) const; AccessList guestList; AccessList subOwnerList; @@ -242,7 +242,7 @@ class House { bool isLoaded = false; void handleContainer(ItemList &moveItemList, std::shared_ptr item) const; - void handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, const std::shared_ptr &player, std::shared_ptr houseTile) const; + void handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, std::shared_ptr player, std::shared_ptr houseTile) const; }; using HouseMap = std::map; diff --git a/src/map/house/housetile.cpp b/src/map/house/housetile.cpp index 7bb08996da9..615a7862c8e 100644 --- a/src/map/house/housetile.cpp +++ b/src/map/house/housetile.cpp @@ -62,7 +62,7 @@ void HouseTile::updateHouse(std::shared_ptr item) { ReturnValue HouseTile::queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t tileFlags, std::shared_ptr actor /* = nullptr*/) { if (std::shared_ptr creature = thing->getCreature()) { - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { if (!house->isInvited(player)) { return RETURNVALUE_PLAYERISNOTINVITED; } @@ -79,7 +79,7 @@ ReturnValue HouseTile::queryAdd(int32_t index, const std::shared_ptr &thi } } } else if (thing->getItem() && actor) { - const auto &actorPlayer = actor->getPlayer(); + std::shared_ptr actorPlayer = actor->getPlayer(); if (house && (!house->isInvited(actorPlayer) || house->getHouseAccessLevel(actorPlayer) == HOUSE_GUEST) && g_configManager().getBoolean(ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { return RETURNVALUE_CANNOTTHROW; } @@ -89,7 +89,7 @@ ReturnValue HouseTile::queryAdd(int32_t index, const std::shared_ptr &thi std::shared_ptr HouseTile::queryDestination(int32_t &index, const std::shared_ptr &thing, std::shared_ptr* destItem, uint32_t &tileFlags) { if (std::shared_ptr creature = thing->getCreature()) { - if (const auto &player = creature->getPlayer()) { + if (std::shared_ptr player = creature->getPlayer()) { if (!house->isInvited(player)) { const Position &entryPos = house->getEntryPosition(); std::shared_ptr destTile = g_game().map.getTile(entryPos); @@ -121,7 +121,7 @@ ReturnValue HouseTile::queryRemove(const std::shared_ptr &thing, uint32_t } if (actor && g_configManager().getBoolean(ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { - const auto &actorPlayer = actor->getPlayer(); + std::shared_ptr actorPlayer = actor->getPlayer(); if (house && !house->isInvited(actorPlayer)) { return RETURNVALUE_NOTPOSSIBLE; } else if (house && house->getHouseAccessLevel(actorPlayer) == HOUSE_GUEST) { diff --git a/src/map/map.cpp b/src/map/map.cpp index f04c177184f..f31bf45f6ff 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -297,7 +297,7 @@ void Map::moveCreature(const std::shared_ptr &creature, const std::sha std::vector oldStackPosVector; for (std::shared_ptr spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (auto tmpPlayer = spectator->getPlayer()) { if (tmpPlayer->canSeeCreature(creature)) { oldStackPosVector.push_back(oldTile->getClientIndexOfCreature(tmpPlayer, creature)); } else { @@ -338,7 +338,7 @@ void Map::moveCreature(const std::shared_ptr &creature, const std::sha // send to client size_t i = 0; for (auto spectator : spectators) { - if (const auto &tmpPlayer = spectator->getPlayer()) { + if (auto tmpPlayer = spectator->getPlayer()) { // Use the correct stackpos int32_t stackpos = oldStackPosVector[i++]; if (stackpos != -1) { diff --git a/src/map/utils/astarnodes.cpp b/src/map/utils/astarnodes.cpp index 8d3b09ff8db..36265dd7f12 100644 --- a/src/map/utils/astarnodes.cpp +++ b/src/map/utils/astarnodes.cpp @@ -120,7 +120,7 @@ int_fast32_t AStarNodes::getTileWalkCost(const std::shared_ptr &creatu /** * Make player try to avoid magic fields, when calculating pathing */ - const auto &player = creature->getPlayer(); + std::shared_ptr player = creature->getPlayer(); if (player && !field->isBlocking() && field->getDamage() != 0) { cost += MAP_NORMALWALKCOST * 18; } diff --git a/src/protobuf/appearances.pb.cc b/src/protobuf/appearances.pb.cc index 7777c15d523..ced2a617345 100644 --- a/src/protobuf/appearances.pb.cc +++ b/src/protobuf/appearances.pb.cc @@ -118,7 +118,7 @@ PROTOBUF_CONSTEXPR SpriteInfo::SpriteInfo( , /*decltype(_impl_.pattern_width_)*/0u , /*decltype(_impl_.pattern_height_)*/0u , /*decltype(_impl_.pattern_depth_)*/0u - , /*decltype(_impl_.players_)*/0u + , /*decltype(_impl_.layers_)*/0u , /*decltype(_impl_.bounding_square_)*/0u , /*decltype(_impl_.is_opaque_)*/false} {} struct SpriteInfoDefaultTypeInternal { @@ -576,7 +576,7 @@ const uint32_t TableStruct_appearances_2eproto::offsets[] PROTOBUF_SECTION_VARIA PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.pattern_width_), PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.pattern_height_), PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.pattern_depth_), - PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.players_), + PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.layers_), PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.sprite_id_), PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.bounding_square_), PROTOBUF_FIELD_OFFSET(::Canary::protobuf::appearances::SpriteInfo, _impl_.animation_), @@ -989,147 +989,147 @@ const char descriptor_table_protodef_appearances_2eproto[] PROTOBUF_SECTION_VARI "\005 \001(\r\022>\n\014sprite_phase\030\006 \003(\0132(.Canary.pro" "tobuf.appearances.SpritePhase\":\n\003Box\022\t\n\001" "x\030\001 \001(\r\022\t\n\001y\030\002 \001(\r\022\r\n\005width\030\003 \001(\r\022\016\n\006hei" - "ght\030\004 \001(\r\"\251\002\n\nSpriteInfo\022\025\n\rpattern_widt" + "ght\030\004 \001(\r\"\250\002\n\nSpriteInfo\022\025\n\rpattern_widt" "h\030\001 \001(\r\022\026\n\016pattern_height\030\002 \001(\r\022\025\n\rpatte" - "rn_depth\030\003 \001(\r\022\017\n\007players\030\004 \001(\r\022\021\n\tsprit" - "e_id\030\005 \003(\r\022\027\n\017bounding_square\030\007 \001(\r\022\?\n\ta" - "nimation\030\006 \001(\0132,.Canary.protobuf.appeara" - "nces.SpriteAnimation\022\021\n\tis_opaque\030\010 \001(\010\022" - "D\n\032bounding_box_per_direction\030\t \003(\0132 .Ca" - "nary.protobuf.appearances.Box\"\241\001\n\nFrameG" - "roup\022I\n\021fixed_frame_group\030\001 \001(\0162..Canary" - ".protobuf.appearances.FIXED_FRAME_GROUP\022" - "\n\n\002id\030\002 \001(\r\022<\n\013sprite_info\030\003 \001(\0132\'.Canar" - "y.protobuf.appearances.SpriteInfo\"\266\001\n\nAp" - "pearance\022\n\n\002id\030\001 \001(\r\022<\n\013frame_group\030\002 \003(" - "\0132\'.Canary.protobuf.appearances.FrameGro" - "up\022;\n\005flags\030\003 \001(\0132,.Canary.protobuf.appe" - "arances.AppearanceFlags\022\014\n\004name\030\004 \001(\014\022\023\n" - "\013description\030\005 \001(\014\"\256\017\n\017AppearanceFlags\022=" - "\n\004bank\030\001 \001(\0132/.Canary.protobuf.appearanc" - "es.AppearanceFlagBank\022\014\n\004clip\030\002 \001(\010\022\016\n\006b" - "ottom\030\003 \001(\010\022\013\n\003top\030\004 \001(\010\022\021\n\tcontainer\030\005 " - "\001(\010\022\022\n\ncumulative\030\006 \001(\010\022\016\n\006usable\030\007 \001(\010\022" - "\020\n\010forceuse\030\010 \001(\010\022\020\n\010multiuse\030\t \001(\010\022\?\n\005w" - "rite\030\n \001(\01320.Canary.protobuf.appearances" - ".AppearanceFlagWrite\022H\n\nwrite_once\030\013 \001(\013" - "24.Canary.protobuf.appearances.Appearanc" - "eFlagWriteOnce\022\022\n\nliquidpool\030\014 \001(\010\022\016\n\006un" - "pass\030\r \001(\010\022\016\n\006unmove\030\016 \001(\010\022\017\n\007unsight\030\017 " - "\001(\010\022\r\n\005avoid\030\020 \001(\010\022\035\n\025no_movement_animat" - "ion\030\021 \001(\010\022\014\n\004take\030\022 \001(\010\022\027\n\017liquidcontain" - "er\030\023 \001(\010\022\014\n\004hang\030\024 \001(\010\022=\n\004hook\030\025 \001(\0132/.C" - "anary.protobuf.appearances.AppearanceFla" - "gHook\022\016\n\006rotate\030\026 \001(\010\022\?\n\005light\030\027 \001(\01320.C" - "anary.protobuf.appearances.AppearanceFla" - "gLight\022\021\n\tdont_hide\030\030 \001(\010\022\023\n\013translucent" - "\030\031 \001(\010\022\?\n\005shift\030\032 \001(\01320.Canary.protobuf." - "appearances.AppearanceFlagShift\022A\n\006heigh" - "t\030\033 \001(\01321.Canary.protobuf.appearances.Ap" - "pearanceFlagHeight\022\024\n\014lying_object\030\034 \001(\010" - "\022\026\n\016animate_always\030\035 \001(\010\022C\n\007automap\030\036 \001(" - "\01322.Canary.protobuf.appearances.Appearan" - "ceFlagAutomap\022E\n\010lenshelp\030\037 \001(\01323.Canary" - ".protobuf.appearances.AppearanceFlagLens" - "help\022\020\n\010fullbank\030 \001(\010\022\023\n\013ignore_look\030! " - "\001(\010\022C\n\007clothes\030\" \001(\01322.Canary.protobuf.a" - "ppearances.AppearanceFlagClothes\022P\n\016defa" - "ult_action\030# \001(\01328.Canary.protobuf.appea" - "rances.AppearanceFlagDefaultAction\022A\n\006ma" - "rket\030$ \001(\01321.Canary.protobuf.appearances" - ".AppearanceFlagMarket\022\014\n\004wrap\030% \001(\010\022\016\n\006u" - "nwrap\030& \001(\010\022\021\n\ttopeffect\030\' \001(\010\022C\n\013npcsal" - "edata\030( \003(\0132..Canary.protobuf.appearance" - "s.AppearanceFlagNPC\022S\n\017changedtoexpire\030)" - " \001(\0132:.Canary.protobuf.appearances.Appea" - "ranceFlagChangedToExpire\022\016\n\006corpse\030* \001(\010" - "\022\025\n\rplayer_corpse\030+ \001(\010\022M\n\016cyclopediaite" - "m\030, \001(\01325.Canary.protobuf.appearances.Ap" - "pearanceFlagCyclopedia\022\014\n\004ammo\030- \001(\010\022\027\n\017" - "show_off_socket\030. \001(\010\022\022\n\nreportable\030/ \001(" - "\010\022_\n\025upgradeclassification\0300 \001(\0132@.Canar" - "y.protobuf.appearances.AppearanceFlagUpg" - "radeClassification\022\033\n\023reverse_addons_eas" - "t\0301 \001(\010\022\033\n\023reverse_addons_west\0302 \001(\010\022\034\n\024" - "reverse_addons_south\0303 \001(\010\022\034\n\024reverse_ad" - "dons_north\0304 \001(\010\022\017\n\007wearout\0305 \001(\010\022\023\n\013clo" - "ckexpire\0306 \001(\010\022\016\n\006expire\0307 \001(\010\022\022\n\nexpire" - "stop\0308 \001(\010\022\017\n\007wrapkit\0309 \001(\010\"E\n#Appearanc" - "eFlagUpgradeClassification\022\036\n\026upgrade_cl" - "assification\030\001 \001(\r\"\'\n\022AppearanceFlagBank" - "\022\021\n\twaypoints\030\001 \001(\r\".\n\023AppearanceFlagWri" - "te\022\027\n\017max_text_length\030\001 \001(\r\"7\n\027Appearanc" - "eFlagWriteOnce\022\034\n\024max_text_length_once\030\001" - " \001(\r\"8\n\023AppearanceFlagLight\022\022\n\nbrightnes" - "s\030\001 \001(\r\022\r\n\005color\030\002 \001(\r\")\n\024AppearanceFlag" - "Height\022\021\n\televation\030\001 \001(\r\"+\n\023AppearanceF" - "lagShift\022\t\n\001x\030\001 \001(\r\022\t\n\001y\030\002 \001(\r\"%\n\025Appear" - "anceFlagClothes\022\014\n\004slot\030\001 \001(\r\"Y\n\033Appeara" - "nceFlagDefaultAction\022:\n\006action\030\001 \001(\0162*.C" - "anary.protobuf.appearances.PLAYER_ACTION" - "\"\362\001\n\024AppearanceFlagMarket\022<\n\010category\030\001 " - "\001(\0162*.Canary.protobuf.appearances.ITEM_C" - "ATEGORY\022\032\n\022trade_as_object_id\030\002 \001(\r\022\031\n\021s" - "how_as_object_id\030\003 \001(\r\022N\n\026restrict_to_pr" - "ofession\030\005 \003(\0162..Canary.protobuf.appeara" - "nces.PLAYER_PROFESSION\022\025\n\rminimum_level\030" - "\006 \001(\r\"\245\001\n\021AppearanceFlagNPC\022\014\n\004name\030\001 \001(" - "\014\022\020\n\010location\030\002 \001(\014\022\022\n\nsale_price\030\003 \001(\r\022" - "\021\n\tbuy_price\030\004 \001(\r\022\037\n\027currency_object_ty" - "pe_id\030\005 \001(\r\022(\n currency_quest_flag_displ" - "ay_name\030\006 \001(\014\"&\n\025AppearanceFlagAutomap\022\r" - "\n\005color\030\001 \001(\r\"O\n\022AppearanceFlagHook\0229\n\td" - "irection\030\001 \001(\0162&.Canary.protobuf.appeara" - "nces.HOOK_TYPE\"$\n\026AppearanceFlagLenshelp" - "\022\n\n\002id\030\001 \001(\r\"=\n\035AppearanceFlagChangedToE" - "xpire\022\034\n\024former_object_typeid\030\001 \001(\r\"3\n\030A" - "ppearanceFlagCyclopedia\022\027\n\017cyclopedia_ty" - "pe\030\001 \001(\r\"\312\001\n\033SpecialMeaningAppearanceIds" - "\022\024\n\014gold_coin_id\030\001 \001(\r\022\030\n\020platinum_coin_" - "id\030\002 \001(\r\022\027\n\017crystal_coin_id\030\003 \001(\r\022\025\n\rtib" - "ia_coin_id\030\004 \001(\r\022\031\n\021stamped_letter_id\030\005 " - "\001(\r\022\027\n\017supply_stash_id\030\006 \001(\r\022\027\n\017reward_c" - "hest_id\030\007 \001(\r*\224\001\n\rPLAYER_ACTION\022\026\n\022PLAYE" - "R_ACTION_NONE\020\000\022\026\n\022PLAYER_ACTION_LOOK\020\001\022" - "\025\n\021PLAYER_ACTION_USE\020\002\022\026\n\022PLAYER_ACTION_" - "OPEN\020\003\022$\n PLAYER_ACTION_AUTOWALK_HIGHLIG" - "HT\020\004*\315\005\n\rITEM_CATEGORY\022\030\n\024ITEM_CATEGORY_" - "ARMORS\020\001\022\031\n\025ITEM_CATEGORY_AMULETS\020\002\022\027\n\023I" - "TEM_CATEGORY_BOOTS\020\003\022\034\n\030ITEM_CATEGORY_CO" - "NTAINERS\020\004\022\034\n\030ITEM_CATEGORY_DECORATION\020\005" - "\022\026\n\022ITEM_CATEGORY_FOOD\020\006\022\036\n\032ITEM_CATEGOR" - "Y_HELMETS_HATS\020\007\022\026\n\022ITEM_CATEGORY_LEGS\020\010" - "\022\030\n\024ITEM_CATEGORY_OTHERS\020\t\022\031\n\025ITEM_CATEG" - "ORY_POTIONS\020\n\022\027\n\023ITEM_CATEGORY_RINGS\020\013\022\027" - "\n\023ITEM_CATEGORY_RUNES\020\014\022\031\n\025ITEM_CATEGORY" - "_SHIELDS\020\r\022\027\n\023ITEM_CATEGORY_TOOLS\020\016\022\033\n\027I" - "TEM_CATEGORY_VALUABLES\020\017\022\034\n\030ITEM_CATEGOR" - "Y_AMMUNITION\020\020\022\026\n\022ITEM_CATEGORY_AXES\020\021\022\027" - "\n\023ITEM_CATEGORY_CLUBS\020\022\022\"\n\036ITEM_CATEGORY" - "_DISTANCE_WEAPONS\020\023\022\030\n\024ITEM_CATEGORY_SWO" - "RDS\020\024\022\034\n\030ITEM_CATEGORY_WANDS_RODS\020\025\022!\n\035I" - "TEM_CATEGORY_PREMIUM_SCROLLS\020\026\022\035\n\031ITEM_C" - "ATEGORY_TIBIA_COINS\020\027\022#\n\037ITEM_CATEGORY_C" - "REATURE_PRODUCTS\020\030\022\030\n\024ITEM_CATEGORY_QUIV" - "ER\020\031*\355\001\n\021PLAYER_PROFESSION\022\"\n\025PLAYER_PRO" - "FESSION_ANY\020\377\377\377\377\377\377\377\377\377\001\022\032\n\026PLAYER_PROFESS" - "ION_NONE\020\000\022\034\n\030PLAYER_PROFESSION_KNIGHT\020\001" - "\022\035\n\031PLAYER_PROFESSION_PALADIN\020\002\022\036\n\032PLAYE" - "R_PROFESSION_SORCERER\020\003\022\033\n\027PLAYER_PROFES" - "SION_DRUID\020\004\022\036\n\032PLAYER_PROFESSION_PROMOT" - "ED\020\n*\203\001\n\023ANIMATION_LOOP_TYPE\022)\n\034ANIMATIO" - "N_LOOP_TYPE_PINGPONG\020\377\377\377\377\377\377\377\377\377\001\022 \n\034ANIMA" - "TION_LOOP_TYPE_INFINITE\020\000\022\037\n\033ANIMATION_L" - "OOP_TYPE_COUNTED\020\001*4\n\tHOOK_TYPE\022\023\n\017HOOK_" - "TYPE_SOUTH\020\001\022\022\n\016HOOK_TYPE_EAST\020\002*\201\001\n\021FIX" - "ED_FRAME_GROUP\022!\n\035FIXED_FRAME_GROUP_OUTF" - "IT_IDLE\020\000\022#\n\037FIXED_FRAME_GROUP_OUTFIT_MO" - "VING\020\001\022$\n FIXED_FRAME_GROUP_OBJECT_INITI" - "AL\020\002" + "rn_depth\030\003 \001(\r\022\016\n\006layers\030\004 \001(\r\022\021\n\tsprite" + "_id\030\005 \003(\r\022\027\n\017bounding_square\030\007 \001(\r\022\?\n\tan" + "imation\030\006 \001(\0132,.Canary.protobuf.appearan" + "ces.SpriteAnimation\022\021\n\tis_opaque\030\010 \001(\010\022D" + "\n\032bounding_box_per_direction\030\t \003(\0132 .Can" + "ary.protobuf.appearances.Box\"\241\001\n\nFrameGr" + "oup\022I\n\021fixed_frame_group\030\001 \001(\0162..Canary." + "protobuf.appearances.FIXED_FRAME_GROUP\022\n" + "\n\002id\030\002 \001(\r\022<\n\013sprite_info\030\003 \001(\0132\'.Canary" + ".protobuf.appearances.SpriteInfo\"\266\001\n\nApp" + "earance\022\n\n\002id\030\001 \001(\r\022<\n\013frame_group\030\002 \003(\013" + "2\'.Canary.protobuf.appearances.FrameGrou" + "p\022;\n\005flags\030\003 \001(\0132,.Canary.protobuf.appea" + "rances.AppearanceFlags\022\014\n\004name\030\004 \001(\014\022\023\n\013" + "description\030\005 \001(\014\"\256\017\n\017AppearanceFlags\022=\n" + "\004bank\030\001 \001(\0132/.Canary.protobuf.appearance" + "s.AppearanceFlagBank\022\014\n\004clip\030\002 \001(\010\022\016\n\006bo" + "ttom\030\003 \001(\010\022\013\n\003top\030\004 \001(\010\022\021\n\tcontainer\030\005 \001" + "(\010\022\022\n\ncumulative\030\006 \001(\010\022\016\n\006usable\030\007 \001(\010\022\020" + "\n\010forceuse\030\010 \001(\010\022\020\n\010multiuse\030\t \001(\010\022\?\n\005wr" + "ite\030\n \001(\01320.Canary.protobuf.appearances." + "AppearanceFlagWrite\022H\n\nwrite_once\030\013 \001(\0132" + "4.Canary.protobuf.appearances.Appearance" + "FlagWriteOnce\022\022\n\nliquidpool\030\014 \001(\010\022\016\n\006unp" + "ass\030\r \001(\010\022\016\n\006unmove\030\016 \001(\010\022\017\n\007unsight\030\017 \001" + "(\010\022\r\n\005avoid\030\020 \001(\010\022\035\n\025no_movement_animati" + "on\030\021 \001(\010\022\014\n\004take\030\022 \001(\010\022\027\n\017liquidcontaine" + "r\030\023 \001(\010\022\014\n\004hang\030\024 \001(\010\022=\n\004hook\030\025 \001(\0132/.Ca" + "nary.protobuf.appearances.AppearanceFlag" + "Hook\022\016\n\006rotate\030\026 \001(\010\022\?\n\005light\030\027 \001(\01320.Ca" + "nary.protobuf.appearances.AppearanceFlag" + "Light\022\021\n\tdont_hide\030\030 \001(\010\022\023\n\013translucent\030" + "\031 \001(\010\022\?\n\005shift\030\032 \001(\01320.Canary.protobuf.a" + "ppearances.AppearanceFlagShift\022A\n\006height" + "\030\033 \001(\01321.Canary.protobuf.appearances.App" + "earanceFlagHeight\022\024\n\014lying_object\030\034 \001(\010\022" + "\026\n\016animate_always\030\035 \001(\010\022C\n\007automap\030\036 \001(\013" + "22.Canary.protobuf.appearances.Appearanc" + "eFlagAutomap\022E\n\010lenshelp\030\037 \001(\01323.Canary." + "protobuf.appearances.AppearanceFlagLensh" + "elp\022\020\n\010fullbank\030 \001(\010\022\023\n\013ignore_look\030! \001" + "(\010\022C\n\007clothes\030\" \001(\01322.Canary.protobuf.ap" + "pearances.AppearanceFlagClothes\022P\n\016defau" + "lt_action\030# \001(\01328.Canary.protobuf.appear" + "ances.AppearanceFlagDefaultAction\022A\n\006mar" + "ket\030$ \001(\01321.Canary.protobuf.appearances." + "AppearanceFlagMarket\022\014\n\004wrap\030% \001(\010\022\016\n\006un" + "wrap\030& \001(\010\022\021\n\ttopeffect\030\' \001(\010\022C\n\013npcsale" + "data\030( \003(\0132..Canary.protobuf.appearances" + ".AppearanceFlagNPC\022S\n\017changedtoexpire\030) " + "\001(\0132:.Canary.protobuf.appearances.Appear" + "anceFlagChangedToExpire\022\016\n\006corpse\030* \001(\010\022" + "\025\n\rplayer_corpse\030+ \001(\010\022M\n\016cyclopediaitem" + "\030, \001(\01325.Canary.protobuf.appearances.App" + "earanceFlagCyclopedia\022\014\n\004ammo\030- \001(\010\022\027\n\017s" + "how_off_socket\030. \001(\010\022\022\n\nreportable\030/ \001(\010" + "\022_\n\025upgradeclassification\0300 \001(\0132@.Canary" + ".protobuf.appearances.AppearanceFlagUpgr" + "adeClassification\022\033\n\023reverse_addons_east" + "\0301 \001(\010\022\033\n\023reverse_addons_west\0302 \001(\010\022\034\n\024r" + "everse_addons_south\0303 \001(\010\022\034\n\024reverse_add" + "ons_north\0304 \001(\010\022\017\n\007wearout\0305 \001(\010\022\023\n\013cloc" + "kexpire\0306 \001(\010\022\016\n\006expire\0307 \001(\010\022\022\n\nexpires" + "top\0308 \001(\010\022\017\n\007wrapkit\0309 \001(\010\"E\n#Appearance" + "FlagUpgradeClassification\022\036\n\026upgrade_cla" + "ssification\030\001 \001(\r\"\'\n\022AppearanceFlagBank\022" + "\021\n\twaypoints\030\001 \001(\r\".\n\023AppearanceFlagWrit" + "e\022\027\n\017max_text_length\030\001 \001(\r\"7\n\027Appearance" + "FlagWriteOnce\022\034\n\024max_text_length_once\030\001 " + "\001(\r\"8\n\023AppearanceFlagLight\022\022\n\nbrightness" + "\030\001 \001(\r\022\r\n\005color\030\002 \001(\r\")\n\024AppearanceFlagH" + "eight\022\021\n\televation\030\001 \001(\r\"+\n\023AppearanceFl" + "agShift\022\t\n\001x\030\001 \001(\r\022\t\n\001y\030\002 \001(\r\"%\n\025Appeara" + "nceFlagClothes\022\014\n\004slot\030\001 \001(\r\"Y\n\033Appearan" + "ceFlagDefaultAction\022:\n\006action\030\001 \001(\0162*.Ca" + "nary.protobuf.appearances.PLAYER_ACTION\"" + "\362\001\n\024AppearanceFlagMarket\022<\n\010category\030\001 \001" + "(\0162*.Canary.protobuf.appearances.ITEM_CA" + "TEGORY\022\032\n\022trade_as_object_id\030\002 \001(\r\022\031\n\021sh" + "ow_as_object_id\030\003 \001(\r\022N\n\026restrict_to_pro" + "fession\030\005 \003(\0162..Canary.protobuf.appearan" + "ces.PLAYER_PROFESSION\022\025\n\rminimum_level\030\006" + " \001(\r\"\245\001\n\021AppearanceFlagNPC\022\014\n\004name\030\001 \001(\014" + "\022\020\n\010location\030\002 \001(\014\022\022\n\nsale_price\030\003 \001(\r\022\021" + "\n\tbuy_price\030\004 \001(\r\022\037\n\027currency_object_typ" + "e_id\030\005 \001(\r\022(\n currency_quest_flag_displa" + "y_name\030\006 \001(\014\"&\n\025AppearanceFlagAutomap\022\r\n" + "\005color\030\001 \001(\r\"O\n\022AppearanceFlagHook\0229\n\tdi" + "rection\030\001 \001(\0162&.Canary.protobuf.appearan" + "ces.HOOK_TYPE\"$\n\026AppearanceFlagLenshelp\022" + "\n\n\002id\030\001 \001(\r\"=\n\035AppearanceFlagChangedToEx" + "pire\022\034\n\024former_object_typeid\030\001 \001(\r\"3\n\030Ap" + "pearanceFlagCyclopedia\022\027\n\017cyclopedia_typ" + "e\030\001 \001(\r\"\312\001\n\033SpecialMeaningAppearanceIds\022" + "\024\n\014gold_coin_id\030\001 \001(\r\022\030\n\020platinum_coin_i" + "d\030\002 \001(\r\022\027\n\017crystal_coin_id\030\003 \001(\r\022\025\n\rtibi" + "a_coin_id\030\004 \001(\r\022\031\n\021stamped_letter_id\030\005 \001" + "(\r\022\027\n\017supply_stash_id\030\006 \001(\r\022\027\n\017reward_ch" + "est_id\030\007 \001(\r*\224\001\n\rPLAYER_ACTION\022\026\n\022PLAYER" + "_ACTION_NONE\020\000\022\026\n\022PLAYER_ACTION_LOOK\020\001\022\025" + "\n\021PLAYER_ACTION_USE\020\002\022\026\n\022PLAYER_ACTION_O" + "PEN\020\003\022$\n PLAYER_ACTION_AUTOWALK_HIGHLIGH" + "T\020\004*\315\005\n\rITEM_CATEGORY\022\030\n\024ITEM_CATEGORY_A" + "RMORS\020\001\022\031\n\025ITEM_CATEGORY_AMULETS\020\002\022\027\n\023IT" + "EM_CATEGORY_BOOTS\020\003\022\034\n\030ITEM_CATEGORY_CON" + "TAINERS\020\004\022\034\n\030ITEM_CATEGORY_DECORATION\020\005\022" + "\026\n\022ITEM_CATEGORY_FOOD\020\006\022\036\n\032ITEM_CATEGORY" + "_HELMETS_HATS\020\007\022\026\n\022ITEM_CATEGORY_LEGS\020\010\022" + "\030\n\024ITEM_CATEGORY_OTHERS\020\t\022\031\n\025ITEM_CATEGO" + "RY_POTIONS\020\n\022\027\n\023ITEM_CATEGORY_RINGS\020\013\022\027\n" + "\023ITEM_CATEGORY_RUNES\020\014\022\031\n\025ITEM_CATEGORY_" + "SHIELDS\020\r\022\027\n\023ITEM_CATEGORY_TOOLS\020\016\022\033\n\027IT" + "EM_CATEGORY_VALUABLES\020\017\022\034\n\030ITEM_CATEGORY" + "_AMMUNITION\020\020\022\026\n\022ITEM_CATEGORY_AXES\020\021\022\027\n" + "\023ITEM_CATEGORY_CLUBS\020\022\022\"\n\036ITEM_CATEGORY_" + "DISTANCE_WEAPONS\020\023\022\030\n\024ITEM_CATEGORY_SWOR" + "DS\020\024\022\034\n\030ITEM_CATEGORY_WANDS_RODS\020\025\022!\n\035IT" + "EM_CATEGORY_PREMIUM_SCROLLS\020\026\022\035\n\031ITEM_CA" + "TEGORY_TIBIA_COINS\020\027\022#\n\037ITEM_CATEGORY_CR" + "EATURE_PRODUCTS\020\030\022\030\n\024ITEM_CATEGORY_QUIVE" + "R\020\031*\355\001\n\021PLAYER_PROFESSION\022\"\n\025PLAYER_PROF" + "ESSION_ANY\020\377\377\377\377\377\377\377\377\377\001\022\032\n\026PLAYER_PROFESSI" + "ON_NONE\020\000\022\034\n\030PLAYER_PROFESSION_KNIGHT\020\001\022" + "\035\n\031PLAYER_PROFESSION_PALADIN\020\002\022\036\n\032PLAYER" + "_PROFESSION_SORCERER\020\003\022\033\n\027PLAYER_PROFESS" + "ION_DRUID\020\004\022\036\n\032PLAYER_PROFESSION_PROMOTE" + "D\020\n*\203\001\n\023ANIMATION_LOOP_TYPE\022)\n\034ANIMATION" + "_LOOP_TYPE_PINGPONG\020\377\377\377\377\377\377\377\377\377\001\022 \n\034ANIMAT" + "ION_LOOP_TYPE_INFINITE\020\000\022\037\n\033ANIMATION_LO" + "OP_TYPE_COUNTED\020\001*4\n\tHOOK_TYPE\022\023\n\017HOOK_T" + "YPE_SOUTH\020\001\022\022\n\016HOOK_TYPE_EAST\020\002*\201\001\n\021FIXE" + "D_FRAME_GROUP\022!\n\035FIXED_FRAME_GROUP_OUTFI" + "T_IDLE\020\000\022#\n\037FIXED_FRAME_GROUP_OUTFIT_MOV" + "ING\020\001\022$\n FIXED_FRAME_GROUP_OBJECT_INITIA" + "L\020\002" ; static ::_pbi::once_flag descriptor_table_appearances_2eproto_once; const ::_pbi::DescriptorTable descriptor_table_appearances_2eproto = { - false, false, 6244, descriptor_table_protodef_appearances_2eproto, + false, false, 6243, descriptor_table_protodef_appearances_2eproto, "appearances.proto", &descriptor_table_appearances_2eproto_once, nullptr, 0, 26, schemas, file_default_instances, TableStruct_appearances_2eproto::offsets, @@ -2777,7 +2777,7 @@ class SpriteInfo::_Internal { static void set_has_pattern_depth(HasBits* has_bits) { (*has_bits)[0] |= 8u; } - static void set_has_players(HasBits* has_bits) { + static void set_has_layers(HasBits* has_bits) { (*has_bits)[0] |= 16u; } static void set_has_bounding_square(HasBits* has_bits) { @@ -2814,7 +2814,7 @@ SpriteInfo::SpriteInfo(const SpriteInfo& from) , decltype(_impl_.pattern_width_){} , decltype(_impl_.pattern_height_){} , decltype(_impl_.pattern_depth_){} - , decltype(_impl_.players_){} + , decltype(_impl_.layers_){} , decltype(_impl_.bounding_square_){} , decltype(_impl_.is_opaque_){}}; @@ -2841,7 +2841,7 @@ inline void SpriteInfo::SharedCtor( , decltype(_impl_.pattern_width_){0u} , decltype(_impl_.pattern_height_){0u} , decltype(_impl_.pattern_depth_){0u} - , decltype(_impl_.players_){0u} + , decltype(_impl_.layers_){0u} , decltype(_impl_.bounding_square_){0u} , decltype(_impl_.is_opaque_){false} }; @@ -2923,11 +2923,11 @@ const char* SpriteInfo::_InternalParse(const char* ptr, ::_pbi::ParseContext* ct } else goto handle_unusual; continue; - // optional uint32 players = 4; + // optional uint32 layers = 4; case 4: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 32)) { - _Internal::set_has_players(&has_bits); - _impl_.players_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + _Internal::set_has_layers(&has_bits); + _impl_.layers_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); CHK_(ptr); } else goto handle_unusual; @@ -3036,10 +3036,10 @@ uint8_t* SpriteInfo::_InternalSerialize( target = ::_pbi::WireFormatLite::WriteUInt32ToArray(3, this->_internal_pattern_depth(), target); } - // optional uint32 players = 4; + // optional uint32 layers = 4; if (cached_has_bits & 0x00000010u) { target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteUInt32ToArray(4, this->_internal_players(), target); + target = ::_pbi::WireFormatLite::WriteUInt32ToArray(4, this->_internal_layers(), target); } // repeated uint32 sprite_id = 5; @@ -3131,9 +3131,9 @@ size_t SpriteInfo::ByteSizeLong() const { total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_pattern_depth()); } - // optional uint32 players = 4; + // optional uint32 layers = 4; if (cached_has_bits & 0x00000010u) { - total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_players()); + total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_layers()); } // optional uint32 bounding_square = 7; @@ -3183,7 +3183,7 @@ void SpriteInfo::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PRO _this->_impl_.pattern_depth_ = from._impl_.pattern_depth_; } if (cached_has_bits & 0x00000010u) { - _this->_impl_.players_ = from._impl_.players_; + _this->_impl_.layers_ = from._impl_.layers_; } if (cached_has_bits & 0x00000020u) { _this->_impl_.bounding_square_ = from._impl_.bounding_square_; diff --git a/src/protobuf/appearances.pb.h b/src/protobuf/appearances.pb.h index 67ec22d8b24..65bc2c7e9cc 100644 --- a/src/protobuf/appearances.pb.h +++ b/src/protobuf/appearances.pb.h @@ -1523,7 +1523,7 @@ class SpriteInfo final : kPatternWidthFieldNumber = 1, kPatternHeightFieldNumber = 2, kPatternDepthFieldNumber = 3, - kPlayersFieldNumber = 4, + kLayersFieldNumber = 4, kBoundingSquareFieldNumber = 7, kIsOpaqueFieldNumber = 8, }; @@ -1624,17 +1624,17 @@ class SpriteInfo final : void _internal_set_pattern_depth(uint32_t value); public: - // optional uint32 players = 4; - bool has_players() const; + // optional uint32 layers = 4; + bool has_layers() const; private: - bool _internal_has_players() const; + bool _internal_has_layers() const; public: - void clear_players(); - uint32_t players() const; - void set_players(uint32_t value); + void clear_layers(); + uint32_t layers() const; + void set_layers(uint32_t value); private: - uint32_t _internal_players() const; - void _internal_set_players(uint32_t value); + uint32_t _internal_layers() const; + void _internal_set_layers(uint32_t value); public: // optional uint32 bounding_square = 7; @@ -1679,7 +1679,7 @@ class SpriteInfo final : uint32_t pattern_width_; uint32_t pattern_height_; uint32_t pattern_depth_; - uint32_t players_; + uint32_t layers_; uint32_t bounding_square_; bool is_opaque_; }; @@ -6993,32 +6993,32 @@ inline void SpriteInfo::set_pattern_depth(uint32_t value) { // @@protoc_insertion_point(field_set:Canary.protobuf.appearances.SpriteInfo.pattern_depth) } -// optional uint32 players = 4; -inline bool SpriteInfo::_internal_has_players() const { +// optional uint32 layers = 4; +inline bool SpriteInfo::_internal_has_layers() const { bool value = (_impl_._has_bits_[0] & 0x00000010u) != 0; return value; } -inline bool SpriteInfo::has_players() const { - return _internal_has_players(); +inline bool SpriteInfo::has_layers() const { + return _internal_has_layers(); } -inline void SpriteInfo::clear_players() { - _impl_.players_ = 0u; +inline void SpriteInfo::clear_layers() { + _impl_.layers_ = 0u; _impl_._has_bits_[0] &= ~0x00000010u; } -inline uint32_t SpriteInfo::_internal_players() const { - return _impl_.players_; +inline uint32_t SpriteInfo::_internal_layers() const { + return _impl_.layers_; } -inline uint32_t SpriteInfo::players() const { - // @@protoc_insertion_point(field_get:Canary.protobuf.appearances.SpriteInfo.players) - return _internal_players(); +inline uint32_t SpriteInfo::layers() const { + // @@protoc_insertion_point(field_get:Canary.protobuf.appearances.SpriteInfo.layers) + return _internal_layers(); } -inline void SpriteInfo::_internal_set_players(uint32_t value) { +inline void SpriteInfo::_internal_set_layers(uint32_t value) { _impl_._has_bits_[0] |= 0x00000010u; - _impl_.players_ = value; + _impl_.layers_ = value; } -inline void SpriteInfo::set_players(uint32_t value) { - _internal_set_players(value); - // @@protoc_insertion_point(field_set:Canary.protobuf.appearances.SpriteInfo.players) +inline void SpriteInfo::set_layers(uint32_t value) { + _internal_set_layers(value); + // @@protoc_insertion_point(field_set:Canary.protobuf.appearances.SpriteInfo.layers) } // repeated uint32 sprite_id = 5; diff --git a/src/protobuf/appearances.proto b/src/protobuf/appearances.proto index b4ee4178a29..ed924febfc4 100644 --- a/src/protobuf/appearances.proto +++ b/src/protobuf/appearances.proto @@ -98,7 +98,7 @@ message SpriteInfo { optional uint32 pattern_width = 1; optional uint32 pattern_height = 2; optional uint32 pattern_depth = 3; - optional uint32 players = 4; + optional uint32 layers = 4; repeated uint32 sprite_id = 5; optional uint32 bounding_square = 7; optional SpriteAnimation animation = 6; diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 795d0fecb66..576ce8ae777 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -106,7 +106,7 @@ namespace { * @param msg The network message to which the imbuement damage should be added. * @param player Pointer to the player for whom the imbuement damage should be handled. */ - void handleImbuementDamage(NetworkMessage &msg, const std::shared_ptr &player) { + void handleImbuementDamage(NetworkMessage &msg, std::shared_ptr player) { bool imbueDmg = false; std::shared_ptr weapon = player->getWeapon(); if (weapon) { @@ -144,7 +144,7 @@ namespace { * * @param[in] player The pointer to the player whose equipped items are considered. */ - void calculateAbsorbValues(const std::shared_ptr &player, NetworkMessage &msg, uint8_t &combats) { + void calculateAbsorbValues(std::shared_ptr player, NetworkMessage &msg, uint8_t &combats) { alignas(16) uint16_t damageReduction[COMBAT_COUNT] = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }; for (int32_t slot = CONST_SLOT_FIRST; slot <= CONST_SLOT_LAST; ++slot) { @@ -472,7 +472,7 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS } // dispatcher thread - const auto &foundPlayer = g_game().getPlayerUniqueLogin(name); + std::shared_ptr foundPlayer = g_game().getPlayerUniqueLogin(name); if (!foundPlayer) { player = std::make_shared(getThis()); player->setName(name); @@ -598,7 +598,7 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS void ProtocolGame::connect(const std::string &playerName, OperatingSystem_t operatingSystem) { eventConnect = 0; - const auto &foundPlayer = g_game().getPlayerUniqueLogin(playerName); + std::shared_ptr foundPlayer = g_game().getPlayerUniqueLogin(playerName); if (!foundPlayer) { disconnectClient("You are already logged in."); return; @@ -730,7 +730,7 @@ void ProtocolGame::onRecvFirstMessage(NetworkMessage &msg) { std::string characterName = msg.getString(); - const auto &foundPlayer = g_game().getPlayerUniqueLogin(characterName); + std::shared_ptr foundPlayer = g_game().getPlayerUniqueLogin(characterName); if (foundPlayer && foundPlayer->client) { foundPlayer->client->disconnectClient("You are already connected through another client. Please use only one client at a time!"); } @@ -2395,7 +2395,7 @@ void ProtocolGame::sendTeamFinderList() { std::map teamFinder = g_game().getTeamFinderList(); msg.add(teamFinder.size()); for (auto it : teamFinder) { - const auto &leader = g_game().getPlayerByGUID(it.first); + std::shared_ptr leader = g_game().getPlayerByGUID(it.first); if (!leader) { return; } @@ -2414,7 +2414,7 @@ void ProtocolGame::sendTeamFinderList() { msg.addByte(teamAssemble->vocationIDs); msg.add(teamAssemble->teamSlots); for (auto itt : teamAssemble->membersMap) { - const auto &member = g_game().getPlayerByGUID(it.first); + std::shared_ptr member = g_game().getPlayerByGUID(it.first); if (member) { if (itt.first == player->getGUID()) { status = itt.second; @@ -2506,14 +2506,14 @@ void ProtocolGame::sendLeaderTeamFinder(bool reset) { uint16_t membersSize = 1; for (auto memberPair : teamAssemble->membersMap) { - const auto &member = g_game().getPlayerByGUID(memberPair.first); + std::shared_ptr member = g_game().getPlayerByGUID(memberPair.first); if (member) { membersSize += 1; } } msg.add(membersSize); - const auto &leader = g_game().getPlayerByGUID(teamAssemble->leaderGuid); + std::shared_ptr leader = g_game().getPlayerByGUID(teamAssemble->leaderGuid); if (!leader) { return; } @@ -2525,7 +2525,7 @@ void ProtocolGame::sendLeaderTeamFinder(bool reset) { msg.addByte(3); for (auto memberPair : teamAssemble->membersMap) { - const auto &member = g_game().getPlayerByGUID(memberPair.first); + std::shared_ptr member = g_game().getPlayerByGUID(memberPair.first); if (!member) { continue; } @@ -2598,7 +2598,7 @@ void ProtocolGame::createLeaderTeamFinder(NetworkMessage &msg) { teamAssemble->leaderGuid = player->getGUID(); if (teamAssemble->partyBool && player->getParty()) { - for (const std::shared_ptr &member : player->getParty()->getMembers()) { + for (std::shared_ptr member : player->getParty()->getMembers()) { if (member && member->getGUID() != player->getGUID()) { members.insert({ member->getGUID(), 3 }); } @@ -2655,7 +2655,7 @@ void ProtocolGame::parseLeaderFinderWindow(NetworkMessage &msg) { } case 2: { uint32_t memberID = msg.get(); - const auto &member = g_game().getPlayerByGUID(memberID); + std::shared_ptr member = g_game().getPlayerByGUID(memberID); if (!member) { return; } @@ -2719,7 +2719,7 @@ void ProtocolGame::parseMemberFinderWindow(NetworkMessage &msg) { player->sendTeamFinderList(); } else { uint32_t leaderID = msg.get(); - const auto &leader = g_game().getPlayerByGUID(leaderID); + std::shared_ptr leader = g_game().getPlayerByGUID(leaderID); if (!leader) { return; } @@ -3872,7 +3872,7 @@ void ProtocolGame::sendCyclopediaCharacterBadges() { msg.addByte(0x01); // if ShowAccountInformation show IsOnline, IsPremium, character title, badges // IsOnline - const auto &loggedPlayer = g_game().getPlayerUniqueLogin(player->getName()); + const auto loggedPlayer = g_game().getPlayerUniqueLogin(player->getName()); msg.addByte(loggedPlayer ? 0x01 : 0x00); // IsPremium (GOD has always 'Premium') msg.addByte(player->isPremium() ? 0x01 : 0x00); @@ -4599,7 +4599,7 @@ void ProtocolGame::updateCoinBalance() { g_dispatcher().addTask( std::bind( [](uint32_t playerId) { - const auto &threadPlayer = g_game().getPlayerByID(playerId); + auto threadPlayer = g_game().getPlayerByID(playerId); if (threadPlayer && threadPlayer->getAccount()) { auto [coins, errCoin] = threadPlayer->getAccount()->getCoins(account::CoinType::COIN); auto [transferCoins, errTCoin] = threadPlayer->getAccount()->getCoins(account::CoinType::TRANSFERABLE); @@ -5582,7 +5582,7 @@ void ProtocolGame::sendCreatureSay(std::shared_ptr creature, SpeakClas } // Add level only for players - if (const auto &speaker = creature->getPlayer()) { + if (std::shared_ptr speaker = creature->getPlayer()) { msg.add(speaker->getLevel()); } else { msg.add(0x00); @@ -5628,7 +5628,7 @@ void ProtocolGame::sendToChannel(std::shared_ptr creature, SpeakClasse } // Add level only for players - if (const auto &speaker = creature->getPlayer()) { + if (std::shared_ptr speaker = creature->getPlayer()) { msg.add(speaker->getLevel()); } else { msg.add(0x00); @@ -5646,7 +5646,7 @@ void ProtocolGame::sendToChannel(std::shared_ptr creature, SpeakClasse writeToOutputBuffer(msg); } -void ProtocolGame::sendPrivateMessage(const std::shared_ptr &speaker, SpeakClasses type, const std::string &text) { +void ProtocolGame::sendPrivateMessage(std::shared_ptr speaker, SpeakClasses type, const std::string &text) { NetworkMessage msg; msg.addByte(0xAA); static uint32_t statementId = 0; @@ -5896,7 +5896,7 @@ void ProtocolGame::sendPartyCreatureHealth(std::shared_ptr target, uin writeToOutputBuffer(msg); } -void ProtocolGame::sendPartyPlayerMana(const std::shared_ptr &target, uint8_t manaPercent) { +void ProtocolGame::sendPartyPlayerMana(std::shared_ptr target, uint8_t manaPercent) { uint32_t cid = target->getID(); if (knownCreatureSet.find(cid) == knownCreatureSet.end()) { sendPartyCreatureUpdate(target); @@ -5932,7 +5932,7 @@ void ProtocolGame::sendPartyCreatureShowStatus(std::shared_ptr target, writeToOutputBuffer(msg); } -void ProtocolGame::sendPartyPlayerVocation(const std::shared_ptr &target) { +void ProtocolGame::sendPartyPlayerVocation(std::shared_ptr target) { uint32_t cid = target->getID(); if (knownCreatureSet.find(cid) == knownCreatureSet.end()) { sendPartyCreatureUpdate(target); @@ -5951,7 +5951,7 @@ void ProtocolGame::sendPartyPlayerVocation(const std::shared_ptr &target writeToOutputBuffer(msg); } -void ProtocolGame::sendPlayerVocation(const std::shared_ptr &target) { +void ProtocolGame::sendPlayerVocation(std::shared_ptr target) { if (!player || oldProtocol) { return; } @@ -6100,7 +6100,7 @@ void ProtocolGame::sendAddCreature(std::shared_ptr creature, const Pos writeToOutputBuffer(msg); if (isLogin) { - if (const auto &creaturePlayer = creature->getPlayer()) { + if (std::shared_ptr creaturePlayer = creature->getPlayer()) { if (!creaturePlayer->isAccessPlayer() || creaturePlayer->getAccountType() == account::ACCOUNT_TYPE_NORMAL) { sendMagicEffect(pos, CONST_ME_TELEPORT); } @@ -6182,7 +6182,7 @@ void ProtocolGame::sendAddCreature(std::shared_ptr creature, const Pos for (const VIPEntry &entry : vipEntries) { VipStatus_t vipStatus; - const auto &vipPlayer = g_game().getPlayerByGUID(entry.guid); + std::shared_ptr vipPlayer = g_game().getPlayerByGUID(entry.guid); if (!vipPlayer) { vipStatus = VIPSTATUS_OFFLINE; } else { @@ -6195,7 +6195,7 @@ void ProtocolGame::sendAddCreature(std::shared_ptr creature, const Pos for (const VIPEntry &entry : vipEntries) { VipStatus_t vipStatus; - const auto &vipPlayer = g_game().getPlayerByGUID(entry.guid); + std::shared_ptr vipPlayer = g_game().getPlayerByGUID(entry.guid); if (!vipPlayer || vipPlayer->isInGhostMode()) { vipStatus = VIPSTATUS_OFFLINE; } else { @@ -6989,7 +6989,7 @@ void ProtocolGame::sendModalWindow(const ModalWindow &modalWindow) { ////////////// Add common messages void ProtocolGame::AddCreature(NetworkMessage &msg, std::shared_ptr creature, bool known, uint32_t remove) { CreatureType_t creatureType = creature->getType(); - const auto &otherPlayer = creature->getPlayer(); + std::shared_ptr otherPlayer = creature->getPlayer(); if (known) { msg.add(0x62); @@ -7058,7 +7058,7 @@ void ProtocolGame::AddCreature(NetworkMessage &msg, std::shared_ptr cr if (!oldProtocol && creatureType == CREATURETYPE_MONSTER) { if (std::shared_ptr master = creature->getMaster()) { - if (const auto &masterPlayer = master->getPlayer()) { + if (std::shared_ptr masterPlayer = master->getPlayer()) { creatureType = CREATURETYPE_SUMMON_PLAYER; } } @@ -7079,7 +7079,7 @@ void ProtocolGame::AddCreature(NetworkMessage &msg, std::shared_ptr cr } if (!oldProtocol && creatureType == CREATURETYPE_PLAYER) { - if (const auto &otherCreature = creature->getPlayer()) { + if (std::shared_ptr otherCreature = creature->getPlayer()) { msg.addByte(otherCreature->getVocation()->getClientId()); } else { msg.addByte(0); @@ -7371,7 +7371,7 @@ void ProtocolGame::updatePartyTrackerAnalyzer(const Party* party) { msg.addByte(static_cast(party->membersData.size())); for (const PartyAnalyzer* analyzer : party->membersData) { msg.add(analyzer->id); - if (const auto &member = g_game().getPlayerByID(analyzer->id); + if (std::shared_ptr member = g_game().getPlayerByID(analyzer->id); !member || !member->getParty() || member->getParty() != party) { msg.addByte(0); } else { @@ -7512,14 +7512,14 @@ void ProtocolGame::sendTaskHuntingData(const TaskHuntingSlot* slot) { } else if (slot->state == PreyTaskDataState_Inactive) { // Empty } else if (slot->state == PreyTaskDataState_Selection) { - const auto &user = player; + std::shared_ptr user = player; msg.add(static_cast(slot->raceIdList.size())); std::for_each(slot->raceIdList.begin(), slot->raceIdList.end(), [&msg, user](uint16_t raceid) { msg.add(raceid); msg.addByte(user->isCreatureUnlockedOnTaskHunting(g_monsters().getMonsterTypeByRaceId(raceid)) ? 0x01 : 0x00); }); } else if (slot->state == PreyTaskDataState_ListSelection) { - const auto &user = player; + std::shared_ptr user = player; const std::map bestiaryList = g_game().getBestiaryList(); msg.add(static_cast(bestiaryList.size())); std::for_each(bestiaryList.begin(), bestiaryList.end(), [&msg, user](auto mType) { diff --git a/src/server/network/protocol/protocolgame.hpp b/src/server/network/protocol/protocolgame.hpp index 4689a7a0ce4..a167ab9559e 100644 --- a/src/server/network/protocol/protocolgame.hpp +++ b/src/server/network/protocol/protocolgame.hpp @@ -233,7 +233,7 @@ class ProtocolGame final : public Protocol { void sendOpenPrivateChannel(const std::string &receiver); void sendExperienceTracker(int64_t rawExp, int64_t finalExp); void sendToChannel(std::shared_ptr creature, SpeakClasses type, const std::string &text, uint16_t channelId); - void sendPrivateMessage(const std::shared_ptr &speaker, SpeakClasses type, const std::string &text); + void sendPrivateMessage(std::shared_ptr speaker, SpeakClasses type, const std::string &text); void sendIcons(uint32_t icons); void sendFYIBox(const std::string &message); @@ -281,10 +281,10 @@ class ProtocolGame final : public Protocol { void sendPartyCreatureShield(std::shared_ptr target); void sendPartyCreatureSkull(std::shared_ptr target); void sendPartyCreatureHealth(std::shared_ptr target, uint8_t healthPercent); - void sendPartyPlayerMana(const std::shared_ptr &target, uint8_t manaPercent); + void sendPartyPlayerMana(std::shared_ptr target, uint8_t manaPercent); void sendPartyCreatureShowStatus(std::shared_ptr target, bool showStatus); - void sendPartyPlayerVocation(const std::shared_ptr &target); - void sendPlayerVocation(const std::shared_ptr &target); + void sendPartyPlayerVocation(std::shared_ptr target); + void sendPlayerVocation(std::shared_ptr target); void sendSkills(); void sendPing(); void sendPingBack(); From bc417b1401b5209dd80dd509025c1fa358621665 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Tue, 19 Sep 2023 13:08:19 -0700 Subject: [PATCH 31/67] fix: use fewer auto refs --- src/creatures/combat/combat.cpp | 8 ++--- src/creatures/creature.cpp | 17 ++++++---- src/creatures/monsters/monster.cpp | 2 +- src/creatures/players/player.cpp | 6 ++-- src/creatures/players/wheel/player_wheel.cpp | 27 ++++++++++++--- src/game/game.cpp | 28 +++++++-------- src/game/zones/zone.cpp | 10 +++--- src/io/functions/iologindata_save_player.cpp | 2 +- src/io/io_wheel.cpp | 8 ++--- src/items/containers/container.cpp | 2 +- src/items/item.cpp | 2 +- src/items/tile.cpp | 2 +- src/lua/creature/movement.cpp | 4 +-- src/lua/creature/raids.cpp | 4 +-- .../functions/core/game/game_functions.cpp | 12 +++---- .../functions/core/game/zone_functions.cpp | 4 +-- .../creatures/combat/spell_functions.cpp | 34 +++++++++---------- .../creatures/creature_functions.cpp | 4 +-- .../creatures/monster/monster_functions.cpp | 4 +-- .../monster/monster_type_functions.cpp | 4 +-- .../creatures/player/guild_functions.cpp | 2 +- .../creatures/player/player_functions.cpp | 6 ++-- .../events/creature_event_functions.cpp | 2 +- .../events/global_event_functions.cpp | 10 +++--- .../functions/items/imbuement_functions.cpp | 2 +- src/lua/functions/map/house_functions.cpp | 8 ++--- src/lua/global/globalevent.cpp | 6 ++-- src/lua/scripts/scripts.cpp | 2 +- src/map/map.cpp | 2 +- src/map/mapcache.cpp | 8 ++--- src/server/network/protocol/protocolgame.cpp | 32 ++++++++--------- .../network/protocol/protocolstatus.cpp | 2 +- 32 files changed, 143 insertions(+), 123 deletions(-) diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index 10c7b2ee67d..23649b889c0 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -1215,7 +1215,7 @@ void Combat::doCombatHealth(std::shared_ptr caster, const Position &po } } } - const auto &origin = caster ? caster->getPosition() : Position(); + const auto origin = caster ? caster->getPosition() : Position(); CombatFunc(caster, origin, position, area, params, CombatHealthFunc, &damage); } @@ -1269,12 +1269,12 @@ void Combat::doCombatMana(std::shared_ptr caster, const Position &posi damage.secondary.value += (damage.secondary.value * (caster->getPlayer()->getSkillLevel(SKILL_CRITICAL_HIT_DAMAGE) + damage.criticalDamage)) / 100; } } - const auto &origin = caster ? caster->getPosition() : Position(); + const auto origin = caster ? caster->getPosition() : Position(); CombatFunc(caster, origin, position, area, params, CombatManaFunc, &damage); } void Combat::doCombatCondition(std::shared_ptr caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms) { - const auto &origin = caster ? caster->getPosition() : Position(); + const auto origin = caster ? caster->getPosition() : Position(); CombatFunc(caster, origin, position, area, params, CombatConditionFunc, nullptr); } @@ -1303,7 +1303,7 @@ void Combat::doCombatCondition(std::shared_ptr caster, std::shared_ptr } void Combat::doCombatDispel(std::shared_ptr caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms) { - const auto &origin = caster ? caster->getPosition() : Position(); + const auto origin = caster ? caster->getPosition() : Position(); CombatFunc(caster, origin, position, area, params, CombatDispelFunc, nullptr); } diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index af985316dbe..b9545cdf7e1 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -739,14 +739,17 @@ bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared corpse->startDecaying(); bool corpses = corpse->isRewardCorpse() || (corpse->getID() == ITEM_MALE_CORPSE || corpse->getID() == ITEM_FEMALE_CORPSE); if (corpse->getContainer() && mostDamageCreature && mostDamageCreature->getPlayer() && !corpses) { - auto player = mostDamageCreature->getPlayer(); - std::ostringstream lootMessage; - lootMessage << "Loot of " << getNameDescription() << ": " << corpse->getContainer()->getContentDescription(player->getProtocolVersion() < 1200); - auto suffix = corpse->getContainer()->getAttribute(ItemAttribute_t::LOOTMESSAGE_SUFFIX); - if (!suffix.empty()) { - lootMessage << suffix; + const auto player = mostDamageCreature->getPlayer(); + auto monster = getMonster(); + if (monster && !monster->isRewardBoss()) { + std::ostringstream lootMessage; + lootMessage << "Loot of " << getNameDescription() << ": " << corpse->getContainer()->getContentDescription(player->getProtocolVersion() < 1200); + auto suffix = corpse->getContainer()->getAttribute(ItemAttribute_t::LOOTMESSAGE_SUFFIX); + if (!suffix.empty()) { + lootMessage << suffix; + } + player->sendLootMessage(lootMessage.str()); } - player->sendLootMessage(lootMessage.str()); if (player->checkAutoLoot()) { int32_t pos = tile->getStackposOfItem(player, corpse); diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 037a8b4c651..c52da75f837 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -552,7 +552,7 @@ bool Monster::searchTarget(TargetSearchType_t searchType /*= TARGETSEARCH_DEFAUL if (++it != resultList.end()) { int32_t mostDamage = 0; do { - const auto &dmg = damageMap.find((*it)->getID()); + const auto dmg = damageMap.find((*it)->getID()); if (dmg != damageMap.end()) { if (dmg->second.total > mostDamage) { mostDamage = dmg->second.total; diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index aa9180921f7..4ccce311bef 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -1326,7 +1326,7 @@ void Player::onApplyImbuement(Imbuement* imbuement, std::shared_ptr item, return; } - const auto &items = imbuement->getItems(); + const auto items = imbuement->getItems(); for (auto &[key, value] : items) { const ItemType &itemType = Item::items[key]; if (static_self_cast()->getItemTypeCount(key) + this->getStashItemCount(itemType.id) < value) { @@ -5909,10 +5909,10 @@ uint16_t Player::getHelpers() const { const auto guildMembers = guild->getMembersOnline(); helperSet.insert(guildMembers.begin(), guildMembers.end()); - const auto &partyMembers = party->getMembers(); + const auto partyMembers = party->getMembers(); helperSet.insert(partyMembers.begin(), partyMembers.end()); - const auto &partyInvitees = party->getInvitees(); + const auto partyInvitees = party->getInvitees(); helperSet.insert(partyInvitees.begin(), partyInvitees.end()); helperSet.insert(party->getLeader()); diff --git a/src/creatures/players/wheel/player_wheel.cpp b/src/creatures/players/wheel/player_wheel.cpp index bdf64fc63b0..31dea94d8dd 100644 --- a/src/creatures/players/wheel/player_wheel.cpp +++ b/src/creatures/players/wheel/player_wheel.cpp @@ -883,7 +883,7 @@ bool PlayerWheel::saveDBPlayerSlotPointsOnLogout() const { DBInsert insertWheelData("INSERT INTO `player_wheeldata` (`player_id`, `slot`) VALUES "); insertWheelData.upsert({ "slot" }); PropWriteStream stream; - const auto &wheelSlots = getSlots(); + const auto wheelSlots = getSlots(); for (uint8_t i = 1; i < wheelSlots.size(); ++i) { auto value = wheelSlots[i]; if (value == 0) { @@ -935,7 +935,7 @@ uint16_t PlayerWheel::getWheelPoints(bool includeExtraPoints /* = true*/) const auto totalPoints = std::max(0u, (level - m_minLevelToStartCountPoints)) * m_pointsPerLevel; if (includeExtraPoints) { - const auto &extraPoints = getExtraPoints(); + const auto extraPoints = getExtraPoints(); totalPoints += extraPoints; } @@ -1375,7 +1375,7 @@ void PlayerWheel::printPlayerWheelMethodsBonusData(const PlayerWheelMethodsBonus void PlayerWheel::loadDedicationAndConvictionPerks() { using VocationBonusFunction = std::function &, uint16_t, uint8_t, PlayerWheelMethodsBonusData &)>; - auto &wheelFunctions = g_game().getIOWheel()->getWheelMapFunctions(); + auto wheelFunctions = g_game().getIOWheel()->getWheelMapFunctions(); auto vocationCipId = getPlayerVocationEnum(); if (vocationCipId < VOCATION_KNIGHT_CIP || vocationCipId > VOCATION_DRUID_CIP) { return; @@ -1794,8 +1794,25 @@ bool PlayerWheel::checkDivineEmpowerment() { setOnThinkTimer(WheelOnThink_t::DIVINE_EMPOWERMENT, OTSYS_TIME() + 2000); const auto tile = m_player.getTile(); - if (tile && tile->getItemTypeCount(ITEM_DIVINE_EMPOWERMENT) > 0) { - int32_t damageBonus = 0; + if (!tile) { + return updateClient; + } + + const auto items = tile->getItemList(); + if (!items) { + return updateClient; + } + + int32_t damageBonus = 0; + bool isOwner = false; + for (const auto &item : *items) { + if (item->getID() == ITEM_DIVINE_EMPOWERMENT && item->getAttribute(ItemAttribute_t::OWNER) == m_player.getID()) { + isOwner = true; + break; + } + } + + if (isOwner) { uint8_t stage = getStage(WheelStage_t::DIVINE_EMPOWERMENT); if (stage >= 3) { damageBonus = 12; diff --git a/src/game/game.cpp b/src/game/game.cpp index 1b84a7ffc3f..a3a7df6997c 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -205,7 +205,7 @@ void Game::resetNpcs() const { void Game::loadBoostedCreature() { auto &db = Database::getInstance(); - const auto &result = db.storeQuery("SELECT * FROM `boosted_creature`"); + const auto result = db.storeQuery("SELECT * FROM `boosted_creature`"); if (!result) { g_logger().warn("[Game::loadBoostedCreature] - " "Failed to detect boosted creature database. (CODE 01)"); @@ -222,7 +222,7 @@ void Game::loadBoostedCreature() { } const uint16_t oldRace = result->getNumber("raceid"); - const auto &monsterlist = getBestiaryList(); + const auto monsterlist = getBestiaryList(); struct MonsterRace { uint16_t raceId { 0 }; @@ -460,7 +460,7 @@ void Game::loadCustomMaps(const std::filesystem::path &customMapPath) { int customMapIndex = 0; for (const auto &entry : fs::directory_iterator(customMapPath)) { - const auto &realPath = entry.path(); + const auto realPath = entry.path(); if (realPath.extension() != ".otbm") { continue; @@ -1625,7 +1625,7 @@ ReturnValue Game::checkMoveItemToCylinder(std::shared_ptr player, std::s } } } else if (toCylinder->getTile()) { - std::shared_ptr toHouseTile = std::dynamic_pointer_cast(toCylinder->getTile()); + const auto toHouseTile = std::dynamic_pointer_cast(toCylinder->getTile()); if (fromCylinder->getContainer()) { if (item->isStoreItem()) { if (!toHouseTile || toHouseTile && toHouseTile->getHouse()->getOwner() != player->getGUID()) { @@ -5319,7 +5319,7 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, uint8_t isMoun outfit.lookMount = randomMount->clientId; } - const auto &playerOutfit = Outfits::getInstance().getOutfitByLookType(player->getSex(), outfit.lookType); + const auto playerOutfit = Outfits::getInstance().getOutfitByLookType(player->getSex(), outfit.lookType); if (!playerOutfit) { outfit.lookMount = 0; } @@ -6321,7 +6321,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt } if (damage.origin != ORIGIN_NONE) { - const auto &events = target->getCreatureEvents(CREATURE_EVENT_HEALTHCHANGE); + const auto events = target->getCreatureEvents(CREATURE_EVENT_HEALTHCHANGE); if (!events.empty()) { for (const auto creatureEvent : events) { creatureEvent->executeHealthChange(target, attacker, damage); @@ -6551,7 +6551,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt } if (manaDamage != 0) { if (damage.origin != ORIGIN_NONE) { - const auto &events = target->getCreatureEvents(CREATURE_EVENT_MANACHANGE); + const auto events = target->getCreatureEvents(CREATURE_EVENT_MANACHANGE); if (!events.empty()) { for (const auto creatureEvent : events) { creatureEvent->executeManaChange(target, attacker, damage); @@ -6649,7 +6649,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt } if (damage.origin != ORIGIN_NONE) { - const auto &events = target->getCreatureEvents(CREATURE_EVENT_HEALTHCHANGE); + const auto events = target->getCreatureEvents(CREATURE_EVENT_HEALTHCHANGE); if (!events.empty()) { for (const auto creatureEvent : events) { creatureEvent->executeHealthChange(target, attacker, damage); @@ -6956,7 +6956,7 @@ void Game::applyLifeLeech( if (targetMonster) { if (uint16_t playerCharmRaceidVamp = attackerPlayer->parseRacebyCharm(CHARM_VAMP, false, 0); playerCharmRaceidVamp != 0 && playerCharmRaceidVamp == targetMonster->getRaceId()) { - if (const auto &lifec = g_iobestiary().getBestiaryCharm(CHARM_VAMP)) { + if (const auto lifec = g_iobestiary().getBestiaryCharm(CHARM_VAMP)) { lifeSkill += lifec->percent; } } @@ -6994,7 +6994,7 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< } if (damage.origin != ORIGIN_NONE) { - const auto &events = target->getCreatureEvents(CREATURE_EVENT_MANACHANGE); + const auto events = target->getCreatureEvents(CREATURE_EVENT_MANACHANGE); if (!events.empty()) { for (const auto creatureEvent : events) { creatureEvent->executeManaChange(target, attacker, damage); @@ -7091,7 +7091,7 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< } if (damage.origin != ORIGIN_NONE) { - const auto &events = target->getCreatureEvents(CREATURE_EVENT_MANACHANGE); + const auto events = target->getCreatureEvents(CREATURE_EVENT_MANACHANGE); if (!events.empty()) { for (const auto creatureEvent : events) { creatureEvent->executeManaChange(target, attacker, damage); @@ -7921,7 +7921,7 @@ void Game::playerHighscores(std::shared_ptr player, HighscoreType_t type if (vocation != 0xFFFFFFFF) { bool firstVocation = true; - const auto &vocationsMap = g_vocations().getVocations(); + const auto vocationsMap = g_vocations().getVocations(); for (const auto &it : vocationsMap) { const Vocation &voc = it.second; if (voc.getFromVocation() == vocation) { @@ -7941,7 +7941,7 @@ void Game::playerHighscores(std::shared_ptr player, HighscoreType_t type if (vocation != 0xFFFFFFFF) { bool firstVocation = true; - const auto &vocationsMap = g_vocations().getVocations(); + const auto vocationsMap = g_vocations().getVocations(); for (const auto &it : vocationsMap) { const Vocation &voc = it.second; if (voc.getFromVocation() == vocation) { @@ -8929,7 +8929,7 @@ void Game::playerSetMonsterPodium(uint32_t playerId, uint32_t monsterRaceId, con return; } - const auto &[podiumVisible, monsterVisible] = podiumAndMonsterVisible; + const auto [podiumVisible, monsterVisible] = podiumAndMonsterVisible; bool changeTentuglyName = false; if (auto monsterOutfit = mType->info.outfit; (monsterOutfit.lookType != 0 || monsterOutfit.lookTypeEx != 0) && monsterVisible) { diff --git a/src/game/zones/zone.cpp b/src/game/zones/zone.cpp index dc0958e6c1d..40ec4e01833 100644 --- a/src/game/zones/zone.cpp +++ b/src/game/zones/zone.cpp @@ -91,7 +91,7 @@ const phmap::parallel_flat_hash_set> &Zone::getTiles() con static phmap::parallel_flat_hash_set> tiles; tiles.clear(); for (const auto &position : positions) { - const auto &tile = g_game().map.getTile(position); + const auto tile = g_game().map.getTile(position); if (tile) { tiles.insert(tile); } @@ -103,7 +103,7 @@ const phmap::parallel_flat_hash_set> &Zone::getCreatur static phmap::parallel_flat_hash_set> creatures; creatures.clear(); for (const auto creatureId : creaturesCache) { - const auto &creature = g_game().getCreatureByID(creatureId); + const auto creature = g_game().getCreatureByID(creatureId); if (creature) { creatures.insert(creature); } @@ -115,7 +115,7 @@ const phmap::parallel_flat_hash_set> &Zone::getPlayers() static phmap::parallel_flat_hash_set> players; players.clear(); for (const auto playerId : playersCache) { - const auto &player = g_game().getPlayerByID(playerId); + const auto player = g_game().getPlayerByID(playerId); if (player) { players.insert(player); } @@ -127,7 +127,7 @@ const phmap::parallel_flat_hash_set> &Zone::getMonsters static phmap::parallel_flat_hash_set> monsters; monsters.clear(); for (const auto monsterId : monstersCache) { - const auto &monster = g_game().getMonsterByID(monsterId); + const auto monster = g_game().getMonsterByID(monsterId); if (monster) { monsters.insert(monster); } @@ -139,7 +139,7 @@ const phmap::parallel_flat_hash_set> &Zone::getNpcs() const static phmap::parallel_flat_hash_set> npcs; npcs.clear(); for (const auto npcId : npcsCache) { - const auto &npc = g_game().getNpcByID(npcId); + const auto npc = g_game().getNpcByID(npcId); if (npc) { npcs.insert(npc); } diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index 877c2483786..4c146d50c82 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -27,7 +27,7 @@ bool IOLoginDataSave::saveItems(std::shared_ptr player, const ItemBlockL int32_t runningId = 100; // Loop through each item in itemList - const auto &openContainers = player->getOpenContainers(); + const auto openContainers = player->getOpenContainers(); for (const auto &it : itemList) { int32_t pid = it.first; std::shared_ptr item = it.second; diff --git a/src/io/io_wheel.cpp b/src/io/io_wheel.cpp index fba20d54674..3db059a8023 100644 --- a/src/io/io_wheel.cpp +++ b/src/io/io_wheel.cpp @@ -59,7 +59,7 @@ namespace InternalPlayerWheel { if (spell) { g_logger().debug("[{}] registering instant spell with name {}", __FUNCTION__, spell->getName()); // Increase data - const auto &increaseData = spellData.increase; + const auto increaseData = spellData.increase; if (increaseData.damage > 0) { spell->setWheelOfDestinyBoost(WheelSpellBoost_t::DAMAGE, gradeType, increaseData.damage); } @@ -74,7 +74,7 @@ namespace InternalPlayerWheel { } // Decrease data - const auto &decreaseData = spellData.decrease; + const auto decreaseData = spellData.decrease; if (decreaseData.cooldown > 0) { spell->setWheelOfDestinyBoost(WheelSpellBoost_t::COOLDOWN, gradeType, decreaseData.cooldown * 1000); } @@ -85,7 +85,7 @@ namespace InternalPlayerWheel { spell->setWheelOfDestinyBoost(WheelSpellBoost_t::SECONDARY_GROUP_COOLDOWN, gradeType, decreaseData.secondaryGroupCooldown * 1000); } // Leech data - const auto &leechData = spellData.leech; + const auto leechData = spellData.leech; if (leechData.mana > 0) { spell->setWheelOfDestinyBoost(WheelSpellBoost_t::MANA_LEECH, gradeType, leechData.mana * 100); } @@ -124,7 +124,7 @@ bool IOWheel::initializeGlobalData(bool reload /* = false*/) { // Register spells for druid for (const auto &data : getWheelBonusData().spells.druid) { for (size_t i = 1; i < 3; ++i) { - const auto &grade = data.grade[i]; + const auto grade = data.grade[i]; InternalPlayerWheel::registerWheelSpellTable(grade, data.name, static_cast(i)); } } diff --git a/src/items/containers/container.cpp b/src/items/containers/container.cpp index 3d71bdb72dc..262a647e0d1 100644 --- a/src/items/containers/container.cpp +++ b/src/items/containers/container.cpp @@ -300,7 +300,7 @@ phmap::flat_hash_set Container::getStoreInboxValidCategorie } std::shared_ptr Container::getFilteredItemByIndex(size_t index) const { - const auto &filteredItems = getStoreInboxFilteredItems(); + const auto filteredItems = getStoreInboxFilteredItems(); if (index >= filteredItems.size()) { return nullptr; } diff --git a/src/items/item.cpp b/src/items/item.cpp index 66170747b07..4d632714133 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -1290,7 +1290,7 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr item /*= nullptr for (uint8_t i = 0; i < item->getImbuementSlot(); ++i) { slotName = fmt::format("Imbuement Slot {}", i + 1); ss.str(""); - const auto &castItem = item; + const auto castItem = item; if (!castItem) { continue; } diff --git a/src/items/tile.cpp b/src/items/tile.cpp index 030ba0ab8c7..2849a8818cf 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -920,7 +920,7 @@ std::shared_ptr Tile::queryDestination(int32_t &, const std::shared_pt } std::vector> Tile::getSurroundingTiles() { - const auto &position = getPosition(); + const auto position = getPosition(); return { g_game().map.getTile(position.x - 1, position.y, position.z), g_game().map.getTile(position.x + 1, position.y, position.z), diff --git a/src/lua/creature/movement.cpp b/src/lua/creature/movement.cpp index 29ba10f8cce..800d421c7e6 100644 --- a/src/lua/creature/movement.cpp +++ b/src/lua/creature/movement.cpp @@ -311,7 +311,7 @@ uint32_t MoveEvents::onCreatureMove(const std::shared_ptr &creature, c } uint32_t MoveEvents::onPlayerEquip(const std::shared_ptr &player, const std::shared_ptr &item, Slots_t slot, bool isCheck) { - const auto &moveEvent = getEvent(item, MOVE_EVENT_EQUIP, slot); + const auto moveEvent = getEvent(item, MOVE_EVENT_EQUIP, slot); if (!moveEvent) { return 1; } @@ -321,7 +321,7 @@ uint32_t MoveEvents::onPlayerEquip(const std::shared_ptr &player, const } uint32_t MoveEvents::onPlayerDeEquip(const std::shared_ptr &player, const std::shared_ptr &item, Slots_t slot) { - const auto &moveEvent = getEvent(item, MOVE_EVENT_DEEQUIP, slot); + const auto moveEvent = getEvent(item, MOVE_EVENT_DEEQUIP, slot); if (!moveEvent) { return 1; } diff --git a/src/lua/creature/raids.cpp b/src/lua/creature/raids.cpp index 1e0ec6b0bde..93335b0c7f1 100644 --- a/src/lua/creature/raids.cpp +++ b/src/lua/creature/raids.cpp @@ -210,7 +210,7 @@ bool Raid::loadFromXml(const std::string &filename) { } void Raid::startRaid() { - const auto &raidEvent = getNextRaidEvent(); + const auto raidEvent = getNextRaidEvent(); if (raidEvent) { state = RAIDSTATE_EXECUTING; nextEventEvent = g_scheduler().addEvent(raidEvent->getDelay(), std::bind(&Raid::executeRaidEvent, this, raidEvent), "Raid::executeRaidEvent"); @@ -223,7 +223,7 @@ void Raid::startRaid() { void Raid::executeRaidEvent(const std::shared_ptr raidEvent) { if (raidEvent->executeEvent()) { nextEvent++; - const auto &newRaidEvent = getNextRaidEvent(); + const auto newRaidEvent = getNextRaidEvent(); if (newRaidEvent) { uint32_t ticks = static_cast(std::max(RAID_MINTICKS, newRaidEvent->getDelay() - raidEvent->getDelay())); diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index 1a23358aaf7..c10d6988295 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -192,7 +192,7 @@ int GameFunctions::luaGameGetMonsterTypes(lua_State* L) { int GameFunctions::luaGameGetTowns(lua_State* L) { // Game.getTowns() - const auto &towns = g_game().map.towns.getTowns(); + const auto towns = g_game().map.towns.getTowns(); lua_createtable(L, towns.size(), 0); int index = 0; @@ -206,7 +206,7 @@ int GameFunctions::luaGameGetTowns(lua_State* L) { int GameFunctions::luaGameGetHouses(lua_State* L) { // Game.getHouses() - const auto &houses = g_game().map.houses.getHouses(); + const auto houses = g_game().map.houses.getHouses(); lua_createtable(L, houses.size(), 0); int index = 0; @@ -494,7 +494,7 @@ int GameFunctions::luaGameCreateTile(lua_State* L) { int GameFunctions::luaGameGetBestiaryCharm(lua_State* L) { // Game.getBestiaryCharm() - const auto &c_list = g_game().getCharmList(); + const auto c_list = g_game().getCharmList(); lua_createtable(L, c_list.size(), 0); int index = 0; @@ -533,7 +533,7 @@ int GameFunctions::luaGameStartRaid(lua_State* L) { // Game.startRaid(raidName) const std::string &raidName = getString(L, 1); - const auto &raid = g_game().raids.getRaidByName(raidName); + const auto raid = g_game().raids.getRaidByName(raidName); if (!raid || !raid->isLoaded()) { lua_pushnumber(L, RETURNVALUE_NOSUCHRAIDEXISTS); return 1; @@ -693,7 +693,7 @@ int GameFunctions::luaGameGetDummies(lua_State* L) { local rate = dummies[1] -- Retrieve dummy rate */ - const auto &dummies = Item::items.getDummys(); + const auto dummies = Item::items.getDummys(); lua_createtable(L, dummies.size(), 0); for (const auto &[dummyId, rate] : dummies) { lua_pushnumber(L, static_cast(rate)); @@ -741,7 +741,7 @@ int GameFunctions::luaGameGetBoostedBoss(lua_State* L) { int GameFunctions::luaGameGetTalkActions(lua_State* L) { // Game.getTalkActions() - const auto &talkactionsMap = g_talkActions().getTalkActionsMap(); + const auto talkactionsMap = g_talkActions().getTalkActionsMap(); lua_createtable(L, static_cast(talkactionsMap.size()), 0); for (const auto &[talkName, talkactionSharedPtr] : talkactionsMap) { diff --git a/src/lua/functions/core/game/zone_functions.cpp b/src/lua/functions/core/game/zone_functions.cpp index d1b341a1aea..9aa000caf1e 100644 --- a/src/lua/functions/core/game/zone_functions.cpp +++ b/src/lua/functions/core/game/zone_functions.cpp @@ -306,7 +306,7 @@ int ZoneFunctions::luaZoneGetByPosition(lua_State* L) { return 1; } int index = 0; - const auto &zones = tile->getZones(); + const auto zones = tile->getZones(); lua_createtable(L, static_cast(zones.size()), 0); for (auto zone : zones) { index++; @@ -319,7 +319,7 @@ int ZoneFunctions::luaZoneGetByPosition(lua_State* L) { int ZoneFunctions::luaZoneGetAll(lua_State* L) { // Zone.getAll() - const auto &zones = Zone::getZones(); + const auto zones = Zone::getZones(); lua_createtable(L, static_cast(zones.size()), 0); int index = 0; for (auto zone : zones) { diff --git a/src/lua/functions/creatures/combat/spell_functions.cpp b/src/lua/functions/creatures/combat/spell_functions.cpp index 00bd785c616..3691645e263 100644 --- a/src/lua/functions/creatures/combat/spell_functions.cpp +++ b/src/lua/functions/creatures/combat/spell_functions.cpp @@ -88,8 +88,8 @@ int SpellFunctions::luaSpellOnCastSpell(lua_State* L) { const auto spell = getUserdataShared(L, 1); if (spell) { if (spell->spellType == SPELL_INSTANT) { - const auto &spellBase = getUserdataShared(L, 1); - const auto &instant = std::static_pointer_cast(spellBase); + const auto spellBase = getUserdataShared(L, 1); + const auto instant = std::static_pointer_cast(spellBase); if (!instant->loadCallback()) { pushBoolean(L, false); return 1; @@ -122,16 +122,16 @@ int SpellFunctions::luaSpellRegister(lua_State* L) { } if (spell->spellType == SPELL_INSTANT) { - const auto &spellBase = getUserdataShared(L, 1); - const auto &instant = std::static_pointer_cast(spellBase); + const auto spellBase = getUserdataShared(L, 1); + const auto instant = std::static_pointer_cast(spellBase); if (!instant->isLoadedCallback()) { pushBoolean(L, false); return 1; } pushBoolean(L, g_spells().registerInstantLuaEvent(instant)); } else if (spell->spellType == SPELL_RUNE) { - const auto &spellBase = getUserdataShared(L, 1); - const auto &rune = std::static_pointer_cast(spellBase); + const auto spellBase = getUserdataShared(L, 1); + const auto rune = std::static_pointer_cast(spellBase); if (rune->getMagicLevel() != 0 || rune->getLevel() != 0) { // Change information in the ItemType to get accurate description ItemType &iType = Item::items.getItemType(rune->getRuneItemId()); @@ -636,7 +636,7 @@ int SpellFunctions::luaSpellVocation(lua_State* L) { // only for InstantSpells int SpellFunctions::luaSpellWords(lua_State* L) { // spell:words(words[, separator = ""]) - const auto &spellBase = getUserdataShared(L, 1); + const auto spellBase = getUserdataShared(L, 1); const auto spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_INSTANT, it means that this actually is no InstantSpell, so we return nil @@ -667,7 +667,7 @@ int SpellFunctions::luaSpellWords(lua_State* L) { // only for InstantSpells int SpellFunctions::luaSpellNeedDirection(lua_State* L) { // spell:needDirection(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto spellBase = getUserdataShared(L, 1); const auto spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_INSTANT, it means that this actually is no InstantSpell, so we return nil @@ -691,7 +691,7 @@ int SpellFunctions::luaSpellNeedDirection(lua_State* L) { // only for InstantSpells int SpellFunctions::luaSpellHasParams(lua_State* L) { // spell:hasParams(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto spellBase = getUserdataShared(L, 1); const auto spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_INSTANT, it means that this actually is no InstantSpell, so we return nil @@ -715,7 +715,7 @@ int SpellFunctions::luaSpellHasParams(lua_State* L) { // only for InstantSpells int SpellFunctions::luaSpellHasPlayerNameParam(lua_State* L) { // spell:hasPlayerNameParam(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto spellBase = getUserdataShared(L, 1); const auto spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_INSTANT, it means that this actually is no InstantSpell, so we return nil @@ -739,7 +739,7 @@ int SpellFunctions::luaSpellHasPlayerNameParam(lua_State* L) { // only for InstantSpells int SpellFunctions::luaSpellNeedCasterTargetOrDirection(lua_State* L) { // spell:needCasterTargetOrDirection(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto spellBase = getUserdataShared(L, 1); const auto spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_INSTANT, it means that this actually is no InstantSpell, so we return nil @@ -763,7 +763,7 @@ int SpellFunctions::luaSpellNeedCasterTargetOrDirection(lua_State* L) { // only for InstantSpells int SpellFunctions::luaSpellIsBlockingWalls(lua_State* L) { // spell:blockWalls(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto spellBase = getUserdataShared(L, 1); const auto spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_INSTANT, it means that this actually is no InstantSpell, so we return nil @@ -787,7 +787,7 @@ int SpellFunctions::luaSpellIsBlockingWalls(lua_State* L) { // only for RuneSpells int SpellFunctions::luaSpellRuneId(lua_State* L) { // spell:runeId(id) - const auto &spellBase = getUserdataShared(L, 1); + const auto spellBase = getUserdataShared(L, 1); const auto spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_RUNE, it means that this actually is no RuneSpell, so we return nil @@ -811,7 +811,7 @@ int SpellFunctions::luaSpellRuneId(lua_State* L) { // only for RuneSpells int SpellFunctions::luaSpellCharges(lua_State* L) { // spell:charges(charges) - const auto &spellBase = getUserdataShared(L, 1); + const auto spellBase = getUserdataShared(L, 1); const auto spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_RUNE, it means that this actually is no RuneSpell, so we return nil @@ -835,7 +835,7 @@ int SpellFunctions::luaSpellCharges(lua_State* L) { // only for RuneSpells int SpellFunctions::luaSpellAllowFarUse(lua_State* L) { // spell:allowFarUse(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto spellBase = getUserdataShared(L, 1); const auto spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_RUNE, it means that this actually is no RuneSpell, so we return nil @@ -859,7 +859,7 @@ int SpellFunctions::luaSpellAllowFarUse(lua_State* L) { // only for RuneSpells int SpellFunctions::luaSpellBlockWalls(lua_State* L) { // spell:blockWalls(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto spellBase = getUserdataShared(L, 1); const auto spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_RUNE, it means that this actually is no RuneSpell, so we return nil @@ -883,7 +883,7 @@ int SpellFunctions::luaSpellBlockWalls(lua_State* L) { // only for RuneSpells int SpellFunctions::luaSpellCheckFloor(lua_State* L) { // spell:checkFloor(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto spellBase = getUserdataShared(L, 1); const auto spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_RUNE, it means that this actually is no RuneSpell, so we return nil diff --git a/src/lua/functions/creatures/creature_functions.cpp b/src/lua/functions/creatures/creature_functions.cpp index 897ee2b9638..6b6a02d6430 100644 --- a/src/lua/functions/creatures/creature_functions.cpp +++ b/src/lua/functions/creatures/creature_functions.cpp @@ -49,7 +49,7 @@ int CreatureFunctions::luaCreatureGetEvents(lua_State* L) { } CreatureEventType_t eventType = getNumber(L, 2); - const auto &eventList = creature->getCreatureEvents(eventType); + const auto eventList = creature->getCreatureEvents(eventType); lua_createtable(L, static_cast(eventList.size()), 0); int index = 0; @@ -971,7 +971,7 @@ int CreatureFunctions::luaCreatureGetZones(lua_State* L) { return 1; } - const auto &zones = creature->getZones(); + const auto zones = creature->getZones(); lua_createtable(L, static_cast(zones.size()), 0); int index = 0; for (auto zone : zones) { diff --git a/src/lua/functions/creatures/monster/monster_functions.cpp b/src/lua/functions/creatures/monster/monster_functions.cpp index 14c400fa5ff..fef180f08ae 100644 --- a/src/lua/functions/creatures/monster/monster_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_functions.cpp @@ -222,7 +222,7 @@ int MonsterFunctions::luaMonsterGetFriendList(lua_State* L) { return 1; } - const auto &friendList = monster->getFriendList(); + const auto friendList = monster->getFriendList(); lua_createtable(L, friendList.size(), 0); int index = 0; @@ -281,7 +281,7 @@ int MonsterFunctions::luaMonsterGetTargetList(lua_State* L) { return 1; } - const auto &targetList = monster->getTargetList(); + const auto targetList = monster->getTargetList(); lua_createtable(L, targetList.size(), 0); int index = 0; diff --git a/src/lua/functions/creatures/monster/monster_type_functions.cpp b/src/lua/functions/creatures/monster/monster_type_functions.cpp index aa910387768..1beea8de66b 100644 --- a/src/lua/functions/creatures/monster/monster_type_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_type_functions.cpp @@ -622,7 +622,7 @@ int MonsterTypeFunctions::luaMonsterTypeBestiaryrace(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeCombatImmunities(lua_State* L) { // get: monsterType:combatImmunities() set: monsterType:combatImmunities(immunity) - const auto &monsterType = getUserdataShared(L, 1); + const auto monsterType = getUserdataShared(L, 1); if (!monsterType) { pushBoolean(L, false); reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); @@ -678,7 +678,7 @@ int MonsterTypeFunctions::luaMonsterTypeCombatImmunities(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeConditionImmunities(lua_State* L) { // get: monsterType:conditionImmunities() set: monsterType:conditionImmunities(immunity) - const auto &monsterType = getUserdataShared(L, 1); + const auto monsterType = getUserdataShared(L, 1); if (!monsterType) { pushBoolean(L, false); reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); diff --git a/src/lua/functions/creatures/player/guild_functions.cpp b/src/lua/functions/creatures/player/guild_functions.cpp index 7dd23f45844..81464483fdc 100644 --- a/src/lua/functions/creatures/player/guild_functions.cpp +++ b/src/lua/functions/creatures/player/guild_functions.cpp @@ -54,7 +54,7 @@ int GuildFunctions::luaGuildGetMembersOnline(lua_State* L) { return 1; } - const auto &members = guild->getMembersOnline(); + const auto members = guild->getMembersOnline(); lua_createtable(L, members.size(), 0); int index = 0; diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index afb991f816d..f6e3db2531a 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -1676,7 +1676,7 @@ int PlayerFunctions::luaPlayerSetBankBalance(lua_State* L) { int PlayerFunctions::luaPlayerGetStorageValue(lua_State* L) { // player:getStorageValue(key) - const auto &player = getUserdataShared(L, 1); + const auto player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2702,7 +2702,7 @@ int PlayerFunctions::luaPlayerCanLearnSpell(lua_State* L) { return 1; } - const auto &vocMap = spell->getVocMap(); + const auto vocMap = spell->getVocMap(); if (vocMap.count(player->getVocationId()) == 0) { pushBoolean(L, false); } else if (player->getLevel() < spell->getLevel()) { @@ -3778,7 +3778,7 @@ int PlayerFunctions::luaPlayerGetLoyaltyBonus(lua_State* L) { int PlayerFunctions::luaPlayerGetLoyaltyPoints(lua_State* L) { // player:getLoyaltyPoints() - const auto &player = getUserdataShared(L, 1); + const auto player = getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/events/creature_event_functions.cpp b/src/lua/functions/events/creature_event_functions.cpp index 4ed08aa7985..2c5da7661f8 100644 --- a/src/lua/functions/events/creature_event_functions.cpp +++ b/src/lua/functions/events/creature_event_functions.cpp @@ -24,7 +24,7 @@ int CreatureEventFunctions::luaCreateCreatureEvent(lua_State* L) { int CreatureEventFunctions::luaCreatureEventType(lua_State* L) { // creatureevent:type(callback) - const auto &creatureEvent = getUserdataShared(L, 1); + const auto creatureEvent = getUserdataShared(L, 1); if (creatureEvent) { std::string typeName = getString(L, 2); std::string tmpStr = asLowerCaseString(typeName); diff --git a/src/lua/functions/events/global_event_functions.cpp b/src/lua/functions/events/global_event_functions.cpp index cab8b4f66b4..955f477bcae 100644 --- a/src/lua/functions/events/global_event_functions.cpp +++ b/src/lua/functions/events/global_event_functions.cpp @@ -26,7 +26,7 @@ int GlobalEventFunctions::luaCreateGlobalEvent(lua_State* L) { int GlobalEventFunctions::luaGlobalEventType(lua_State* L) { // globalevent:type(callback) - const auto &global = getUserdataShared(L, 1); + const auto global = getUserdataShared(L, 1); if (global) { std::string typeName = getString(L, 2); std::string tmpStr = asLowerCaseString(typeName); @@ -54,7 +54,7 @@ int GlobalEventFunctions::luaGlobalEventType(lua_State* L) { int GlobalEventFunctions::luaGlobalEventRegister(lua_State* L) { // globalevent:register() - const auto &globalevent = getUserdataShared(L, 1); + const auto globalevent = getUserdataShared(L, 1); if (globalevent) { if (!globalevent->isLoadedCallback()) { pushBoolean(L, false); @@ -74,7 +74,7 @@ int GlobalEventFunctions::luaGlobalEventRegister(lua_State* L) { int GlobalEventFunctions::luaGlobalEventOnCallback(lua_State* L) { // globalevent:onThink / record / etc. (callback) - const auto &globalevent = getUserdataShared(L, 1); + const auto globalevent = getUserdataShared(L, 1); if (globalevent) { if (!globalevent->loadCallback()) { pushBoolean(L, false); @@ -89,7 +89,7 @@ int GlobalEventFunctions::luaGlobalEventOnCallback(lua_State* L) { int GlobalEventFunctions::luaGlobalEventTime(lua_State* L) { // globalevent:time(time) - const auto &globalevent = getUserdataShared(L, 1); + const auto globalevent = getUserdataShared(L, 1); if (globalevent) { std::string timer = getString(L, 2); std::vector params = vectorAtoi(explodeString(timer, ":")); @@ -152,7 +152,7 @@ int GlobalEventFunctions::luaGlobalEventTime(lua_State* L) { int GlobalEventFunctions::luaGlobalEventInterval(lua_State* L) { // globalevent:interval(interval) - const auto &globalevent = getUserdataShared(L, 1); + const auto globalevent = getUserdataShared(L, 1); if (globalevent) { globalevent->setInterval(getNumber(L, 2)); globalevent->setNextExecution(OTSYS_TIME() + getNumber(L, 2)); diff --git a/src/lua/functions/items/imbuement_functions.cpp b/src/lua/functions/items/imbuement_functions.cpp index dcb89ca867a..f512e56a62b 100644 --- a/src/lua/functions/items/imbuement_functions.cpp +++ b/src/lua/functions/items/imbuement_functions.cpp @@ -58,7 +58,7 @@ int ImbuementFunctions::luaImbuementGetItems(lua_State* L) { return 1; } - const auto &items = imbuement->getItems(); + const auto items = imbuement->getItems(); lua_createtable(L, items.size(), 0); for (const auto &itm : items) { diff --git a/src/lua/functions/map/house_functions.cpp b/src/lua/functions/map/house_functions.cpp index 18c4d66b0fa..b8f188d11f0 100644 --- a/src/lua/functions/map/house_functions.cpp +++ b/src/lua/functions/map/house_functions.cpp @@ -182,7 +182,7 @@ int HouseFunctions::luaHouseGetBeds(lua_State* L) { return 1; } - const auto &beds = house->getBeds(); + const auto beds = house->getBeds(); lua_createtable(L, beds.size(), 0); int index = 0; @@ -213,7 +213,7 @@ int HouseFunctions::luaHouseGetDoors(lua_State* L) { return 1; } - const auto &doors = house->getDoors(); + const auto doors = house->getDoors(); lua_createtable(L, doors.size(), 0); int index = 0; @@ -261,7 +261,7 @@ int HouseFunctions::luaHouseGetTiles(lua_State* L) { return 1; } - const auto &tiles = house->getTiles(); + const auto tiles = house->getTiles(); lua_newtable(L); int index = 0; @@ -281,7 +281,7 @@ int HouseFunctions::luaHouseGetItems(lua_State* L) { return 1; } - const auto &tiles = house->getTiles(); + const auto tiles = house->getTiles(); lua_newtable(L); int index = 0; diff --git a/src/lua/global/globalevent.cpp b/src/lua/global/globalevent.cpp index 2366ef26182..a8acb01bb86 100644 --- a/src/lua/global/globalevent.cpp +++ b/src/lua/global/globalevent.cpp @@ -71,7 +71,7 @@ void GlobalEvents::timer() { auto it = timerMap.begin(); while (it != timerMap.end()) { - const auto &globalEvent = it->second; + const auto globalEvent = it->second; int64_t nextExecutionTime = globalEvent->getNextExecution() - now; if (nextExecutionTime > 0) { @@ -108,7 +108,7 @@ void GlobalEvents::think() { int64_t nextScheduledTime = std::numeric_limits::max(); for (auto &it : thinkMap) { - const auto &globalEvent = it.second; + const auto globalEvent = it.second; int64_t nextExecutionTime = globalEvent->getNextExecution() - now; if (nextExecutionTime > 0) { @@ -142,7 +142,7 @@ void GlobalEvents::think() { void GlobalEvents::execute(GlobalEvent_t type) const { for (const auto &it : serverMap) { - const auto &globalEvent = it.second; + const auto globalEvent = it.second; if (globalEvent->getEventType() == type) { globalEvent->executeEvent(); } diff --git a/src/lua/scripts/scripts.cpp b/src/lua/scripts/scripts.cpp index 5a9627af179..bb7c5a6a629 100644 --- a/src/lua/scripts/scripts.cpp +++ b/src/lua/scripts/scripts.cpp @@ -72,7 +72,7 @@ bool Scripts::loadScripts(std::string loadPath, bool isLib, bool reload) { // Recursive iterate through all entries in the directory for (const auto &entry : std::filesystem::recursive_directory_iterator(dir)) { // Get the filename of the entry as a string - const auto &realPath = entry.path(); + const auto realPath = entry.path(); std::string fileFolder = realPath.parent_path().filename().string(); // Script folder, example: "actions" std::string scriptFolder = realPath.parent_path().string(); diff --git a/src/map/map.cpp b/src/map/map.cpp index f31bf45f6ff..17e678e7338 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -384,7 +384,7 @@ void Map::getSpectatorsInternal(SpectatorHashSet &spectators, const Position &ce leafE = leafS; for (int_fast32_t nx = startx1; nx <= endx2; nx += FLOOR_SIZE) { if (leafE) { - const auto &node_list = (onlyPlayers ? leafE->player_list : leafE->creature_list); + const auto node_list = (onlyPlayers ? leafE->player_list : leafE->creature_list); for (std::shared_ptr creature : node_list) { const Position &cpos = creature->getPosition(); if (minRangeZ > cpos.z || maxRangeZ < cpos.z) { diff --git a/src/map/mapcache.cpp b/src/map/mapcache.cpp index e99500946e4..dfbbc58c3e3 100644 --- a/src/map/mapcache.cpp +++ b/src/map/mapcache.cpp @@ -101,7 +101,7 @@ std::shared_ptr MapCache::createItem(const std::shared_ptr &Bas } std::shared_ptr MapCache::getOrCreateTileFromCache(const std::unique_ptr &floor, uint16_t x, uint16_t y) { - const auto &cachedTile = floor->getTileCache(x, y); + const auto cachedTile = floor->getTileCache(x, y); if (!cachedTile) { return floor->getTile(x, y); } @@ -147,7 +147,7 @@ void MapCache::setBasicTile(uint16_t x, uint16_t y, uint8_t z, const std::shared return; } - const auto &tile = static_tryGetTileFromCache(newTile); + const auto tile = static_tryGetTileFromCache(newTile); if (const auto leaf = QTreeNode::getLeafStatic(&root, x, y)) { leaf->createFloor(z)->setTileCache(x, y, tile); } else { @@ -267,14 +267,14 @@ void BasicItem::readAttr(FileStream &stream) { } break; case ATTR_TEXT: { - const auto &str = stream.getString(); + const auto str = stream.getString(); if (!str.empty()) { text = str; } } break; case ATTR_DESC: { - const auto &str = stream.getString(); + const auto str = stream.getString(); // if (!str.empty()) // text = str; } break; diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 576ce8ae777..fdd033cb295 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -2093,7 +2093,7 @@ void ProtocolGame::sendHighscores(const std::vector &charact msg.addString("(all)"); // All Vocations - hardcoded uint32_t selectedVocation = 0xFFFFFFFF; - const auto &vocationsMap = g_vocations().getVocations(); + const auto vocationsMap = g_vocations().getVocations(); for (const auto &it : vocationsMap) { const Vocation &vocation = it.second; if (vocation.getFromVocation() == static_cast(vocation.getId())) { @@ -2367,7 +2367,7 @@ void ProtocolGame::parseCyclopediaMonsterTracker(NetworkMessage &msg) { } // Bestiary tracker logic - const auto &bestiaryMonsters = g_game().getBestiaryList(); + const auto bestiaryMonsters = g_game().getBestiaryList(); auto it = bestiaryMonsters.find(monsterRaceId); if (it != bestiaryMonsters.end()) { const auto mtype = g_monsters().getMonsterType(it->second); @@ -2772,7 +2772,7 @@ void ProtocolGame::refreshCyclopediaMonsterTracker(const phmap::parallel_flat_ha msg.addByte(trackerSet.size()); for (const auto mtype : trackerSet) { auto raceId = mtype->info.raceid; - const auto &stages = g_ioBosstiary().getBossRaceKillStages(mtype->info.bosstiaryRace); + const auto stages = g_ioBosstiary().getBossRaceKillStages(mtype->info.bosstiaryRace); if (isBoss && (stages.empty() || stages.size() != 3)) { return; } @@ -3177,7 +3177,7 @@ void ProtocolGame::addCreatureIcon(NetworkMessage &msg, std::shared_ptr 3 ? 3 : icons.size(); msg.addByte(count); for (uint8_t i = 0; i < count; ++i) { - const auto &icon = icons[i]; + const auto icon = icons[i]; msg.addByte(icon.serialize()); msg.addByte(static_cast(icon.category)); msg.add(icon.count); @@ -3673,7 +3673,7 @@ void ProtocolGame::sendCyclopediaCharacterOutfitsMounts() { auto startOutfits = msg.getBufferPosition(); msg.skipBytes(2); - const auto &outfits = Outfits::getInstance().getOutfits(player->getSex()); + const auto outfits = Outfits::getInstance().getOutfits(player->getSex()); for (const auto &outfit : outfits) { uint8_t addons; if (!player->getOutfitAddons(outfit, addons)) { @@ -3735,7 +3735,7 @@ void ProtocolGame::sendCyclopediaCharacterOutfitsMounts() { uint16_t familiarsSize = 0; auto startFamiliars = msg.getBufferPosition(); msg.skipBytes(2); - const auto &familiars = Familiars::getInstance().getFamiliars(player->getVocationId()); + const auto familiars = Familiars::getInstance().getFamiliars(player->getVocationId()); for (const Familiar &familiar : familiars) { const std::string type = familiar.type; if (!player->getFamiliar(familiar)) { @@ -3844,7 +3844,7 @@ void ProtocolGame::sendCyclopediaCharacterInspection() { // Outfit description playerDescriptionSize++; msg.addString("Outfit"); - if (const auto &outfit = Outfits::getInstance().getOutfitByLookType(player->getSex(), player->getDefaultOutfit().lookType)) { + if (const auto outfit = Outfits::getInstance().getOutfitByLookType(player->getSex(), player->getDefaultOutfit().lookType)) { msg.addString(outfit->name); } else { msg.addString("unknown"); @@ -4853,7 +4853,7 @@ void ProtocolGame::sendForgingData() { std::map tierCorePrices; - const auto &classifications = g_game().getItemsClassifications(); + const auto classifications = g_game().getItemsClassifications(); msg.addByte(classifications.size()); for (const auto &classification : classifications) { msg.addByte(classification->id); @@ -6456,7 +6456,7 @@ void ProtocolGame::sendOutfitWindow() { protocolOutfits.emplace_back(communityManager, 302, 0); } - const auto &outfits = Outfits::getInstance().getOutfits(player->getSex()); + const auto outfits = Outfits::getInstance().getOutfits(player->getSex()); protocolOutfits.reserve(outfits.size()); for (const auto &outfit : outfits) { uint8_t addons; @@ -6537,7 +6537,7 @@ void ProtocolGame::sendOutfitWindow() { ++outfitSize; } - const auto &outfits = Outfits::getInstance().getOutfits(player->getSex()); + const auto outfits = Outfits::getInstance().getOutfits(player->getSex()); for (const auto &outfit : outfits) { uint8_t addons; @@ -6613,7 +6613,7 @@ void ProtocolGame::sendOutfitWindow() { uint16_t familiarSize = 0; msg.skipBytes(2); - const auto &familiars = Familiars::getInstance().getFamiliars(player->getVocationId()); + const auto familiars = Familiars::getInstance().getFamiliars(player->getVocationId()); for (const Familiar &familiar : familiars) { if (!player->getFamiliar(familiar)) { @@ -6677,7 +6677,7 @@ void ProtocolGame::sendPodiumWindow(std::shared_ptr podium, const Position uint16_t outfitSize = 0; msg.skipBytes(2); - const auto &outfits = Outfits::getInstance().getOutfits(player->getSex()); + const auto outfits = Outfits::getInstance().getOutfits(player->getSex()); for (const auto &outfit : outfits) { uint8_t addons; if (!player->getOutfitAddons(outfit, addons)) { @@ -7243,7 +7243,7 @@ void ProtocolGame::addImbuementInfo(NetworkMessage &msg, uint16_t imbuementId) c msg.addByte(imbuement->isPremium() ? 0x01 : 0x00); - const auto &items = imbuement->getItems(); + const auto items = imbuement->getItems(); msg.addByte(items.size()); for (const auto &itm : items) { @@ -7294,7 +7294,7 @@ void ProtocolGame::openImbuementWindow(std::shared_ptr item) { for (const Imbuement* imbuement : imbuements) { addImbuementInfo(msg, imbuement->getID()); - const auto &items = imbuement->getItems(); + const auto items = imbuement->getItems(); for (const auto &itm : items) { if (!needItems.count(itm.first)) { needItems[itm.first] = player->getItemTypeCount(itm.first); @@ -8418,10 +8418,10 @@ void ProtocolGame::sendMonsterPodiumWindow(std::shared_ptr podium, const P bool isBossPodium = podium->getID() == ITEM_PODIUM_OF_VIGOUR; msg.addByte(isBossPodium ? 0x01 : 0x00); // Bosstiary or bestiary if (isBossPodium) { - const auto &unlockedBosses = g_ioBosstiary().getBosstiaryFinished(player, 2); + const auto unlockedBosses = g_ioBosstiary().getBosstiaryFinished(player, 2); sendPodiumDetails(msg, unlockedBosses, true); } else { - const auto &unlockedMonsters = g_iobestiary().getBestiaryFinished(player); + const auto unlockedMonsters = g_iobestiary().getBestiaryFinished(player); sendPodiumDetails(msg, unlockedMonsters, false); } diff --git a/src/server/network/protocol/protocolstatus.cpp b/src/server/network/protocol/protocolstatus.cpp index 9ca24df82bc..3d2ce459ce0 100644 --- a/src/server/network/protocol/protocolstatus.cpp +++ b/src/server/network/protocol/protocolstatus.cpp @@ -189,7 +189,7 @@ void ProtocolStatus::sendInfo(uint16_t requestedInfo, const std::string &charact if (requestedInfo & REQUEST_EXT_PLAYERS_INFO) { output->addByte(0x21); // players info - online players list - const auto &players = g_game().getPlayers(); + const auto players = g_game().getPlayers(); output->add(players.size()); for (const auto &it : players) { output->addString(it.second->getName()); From 799c943ddebcafa076d7f688046b99dcf5e5ae05 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Tue, 19 Sep 2023 15:23:39 -0700 Subject: [PATCH 32/67] fix: bank ptr --- src/game/bank/bank.cpp | 9 +++++---- src/game/bank/bank.hpp | 4 ++-- src/game/game.cpp | 4 ++-- src/lua/functions/core/game/bank_functions.cpp | 2 ++ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/game/bank/bank.cpp b/src/game/bank/bank.cpp index 56e06150bdb..bab052b8a38 100644 --- a/src/game/bank/bank.cpp +++ b/src/game/bank/bank.cpp @@ -82,14 +82,17 @@ const uint32_t minTownId = 3; bool Bank::transferTo(const std::shared_ptr destination, uint64_t amount) { if (!destination) { + g_logger().error("Bank::transferTo: destination is nullptr"); return false; } auto bankable = getBankable(); if (!bankable) { + g_logger().error("Bank::transferTo: bankable is nullptr"); return false; } auto destinationBankable = destination->getBankable(); if (!destinationBankable) { + g_logger().error("Bank::transferTo: destinationBankable is nullptr"); return false; } if (destinationBankable->getPlayer() != nullptr) { @@ -97,17 +100,15 @@ bool Bank::transferTo(const std::shared_ptr destination, uint64_t amount) auto name = asLowerCaseString(player->getName()); replaceString(name, " ", ""); if (deniedNames.contains(name)) { + g_logger().warn("Bank::transferTo: denied name: {}", name); return false; } if (player->getTown()->getID() < minTownId) { + g_logger().warn("Bank::transferTo: denied town: {}", player->getTown()->getID()); return false; } } - if (!hasBalance(amount)) { - return false; - } - return debit(amount) && destination->credit(amount); } diff --git a/src/game/bank/bank.hpp b/src/game/bank/bank.hpp index b04a02a9998..f4ebbb7beb9 100644 --- a/src/game/bank/bank.hpp +++ b/src/game/bank/bank.hpp @@ -49,7 +49,7 @@ class Bank : public SharedObject { private: std::shared_ptr getBankable() const { - return m_bankable.lock(); + return m_bankable; } - std::weak_ptr m_bankable; + std::shared_ptr m_bankable; }; diff --git a/src/game/game.cpp b/src/game/game.cpp index a3a7df6997c..abce8b82fa1 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -779,13 +779,13 @@ std::shared_ptr Game::getPlayerByName(const std::string &s, bool loadTmp } auto it = mappedPlayerNames.find(asLowerCaseString(s)); - if (it == mappedPlayerNames.end()) { + if (it == mappedPlayerNames.end() || it->second.expired()) { if (!loadTmp) { return nullptr; } std::shared_ptr tmpPlayer = std::make_shared(nullptr); if (!IOLoginData::loadPlayerByName(tmpPlayer, s)) { - + g_logger().error("Failed to load player {} from database", s); return nullptr; } tmpPlayer->setOnline(false); diff --git a/src/lua/functions/core/game/bank_functions.cpp b/src/lua/functions/core/game/bank_functions.cpp index e9451a5a637..90e4fdecb5f 100644 --- a/src/lua/functions/core/game/bank_functions.cpp +++ b/src/lua/functions/core/game/bank_functions.cpp @@ -59,11 +59,13 @@ int BankFunctions::luaBankTransfer(lua_State* L) { // Bank.transfer(fromPlayerOrGuild, toPlayerOrGuild, amount) auto source = getBank(L, 1); if (source == nullptr) { + g_logger().debug("BankFunctions::luaBankTransfer: source is null"); lua_pushnil(L); return 1; } std::shared_ptr destination = getBank(L, 2); if (destination == nullptr) { + g_logger().debug("BankFunctions::luaBankTransfer: destination is null"); lua_pushnil(L); return 1; } From 2af082413c4598387ef6d59efd35cf92a0a40901 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 20 Sep 2023 09:13:19 -0300 Subject: [PATCH 33/67] fix: check nullptr pointer "Party::getLeader()" getLeader is now std::weak_ptr and need nullptr check --- src/creatures/players/player.cpp | 4 +++- src/lua/callbacks/event_callback.cpp | 4 ++-- src/lua/creature/events.cpp | 4 ++-- src/server/network/protocol/protocolgame.cpp | 10 ++++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 4ccce311bef..04de7235cf3 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -7666,7 +7666,9 @@ void Player::sendLootMessage(const std::string &message) const { return; } - party->getLeader()->sendTextMessage(MESSAGE_LOOT, message); + if (auto partyLeader = party->getLeader()) { + partyLeader->sendTextMessage(MESSAGE_LOOT, message); + } for (const auto partyMember : party->getMembers()) { if (partyMember) { partyMember->sendTextMessage(MESSAGE_LOOT, message); diff --git a/src/lua/callbacks/event_callback.cpp b/src/lua/callbacks/event_callback.cpp index e9ac54f15e6..8f6a27be29c 100644 --- a/src/lua/callbacks/event_callback.cpp +++ b/src/lua/callbacks/event_callback.cpp @@ -280,7 +280,7 @@ bool EventCallback::partyOnDisband(Party* party) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::partyOnDisband - Party leader {}] Call stack " "overflow. Too many lua script calls being nested.", - party->getLeader()->getName()); + party->getLeader() ? party->getLeader()->getName() : "unknown"); return false; } @@ -298,7 +298,7 @@ bool EventCallback::partyOnDisband(Party* party) const { void EventCallback::partyOnShareExperience(Party* party, uint64_t &exp) const { if (!getScriptInterface()->reserveScriptEnv()) { - g_logger().error("Party leader {}. Call stack overflow. Too many lua script calls being nested.", party->getLeader()->getName()); + g_logger().error("Party leader {}. Call stack overflow. Too many lua script calls being nested.", party->getLeader() ? party->getLeader()->getName() : "unknown"); return; } diff --git a/src/lua/creature/events.cpp b/src/lua/creature/events.cpp index 65f9270a58a..b79f770b3ce 100644 --- a/src/lua/creature/events.cpp +++ b/src/lua/creature/events.cpp @@ -488,7 +488,7 @@ bool Events::eventPartyOnDisband(Party* party) { if (!scriptInterface.reserveScriptEnv()) { g_logger().error("[Events::eventPartyOnDisband - Party leader {}] Call stack " "overflow. Too many lua script calls being nested.", - party->getLeader()->getName()); + party->getLeader() ? party->getLeader()->getName() : "unknown"); return false; } @@ -511,7 +511,7 @@ void Events::eventPartyOnShareExperience(Party* party, uint64_t &exp) { } if (!scriptInterface.reserveScriptEnv()) { - g_logger().error("Party leader {}. Call stack overflow. Too many lua script calls being nested.", party->getLeader()->getName()); + g_logger().error("Party leader {}. Call stack overflow. Too many lua script calls being nested.", party->getLeader() ? party->getLeader()->getName() : "unknown"); return; } diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index fdd033cb295..50fbbcedb2a 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -2597,14 +2597,16 @@ void ProtocolGame::createLeaderTeamFinder(NetworkMessage &msg) { teamAssemble->questID = questID; teamAssemble->leaderGuid = player->getGUID(); - if (teamAssemble->partyBool && player->getParty()) { - for (std::shared_ptr member : player->getParty()->getMembers()) { + auto party = player->getParty(); + if (teamAssemble->partyBool && party) { + for (std::shared_ptr member : party->getMembers()) { if (member && member->getGUID() != player->getGUID()) { members.insert({ member->getGUID(), 3 }); } } - if (player->getParty()->getLeader()->getGUID() != player->getGUID()) { - members.insert({ player->getParty()->getLeader()->getGUID(), 3 }); + auto partyLeader = party->getLeader(); + if (partyLeader && partyLeader->getGUID() != player->getGUID()) { + members.insert({ partyLeader->getGUID(), 3 }); } } teamAssemble->membersMap = members; From adb6978c5314a1e1940ba4f10b6501193bc377c2 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 20 Sep 2023 10:11:07 -0300 Subject: [PATCH 34/67] fix: compilation (conflict error) --- src/lua/functions/items/container_functions.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lua/functions/items/container_functions.cpp b/src/lua/functions/items/container_functions.cpp index 3e0904e5262..b3503b662e1 100644 --- a/src/lua/functions/items/container_functions.cpp +++ b/src/lua/functions/items/container_functions.cpp @@ -155,7 +155,6 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) { setItemMetatable(L, -1, item); } else { reportErrorFunc(fmt::format("Cannot add item to container, error code: '{}'", getReturnMessage(ret))); - delete item; } return 1; } From 2c791156c2ec53cc4f22122ccb04dbdf334a3da0 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Wed, 20 Sep 2023 20:29:35 -0300 Subject: [PATCH 35/67] feat: collectGarbage method --- src/lua/scripts/lua_environment.cpp | 16 ++++++++++++++++ src/lua/scripts/lua_environment.hpp | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/lua/scripts/lua_environment.cpp b/src/lua/scripts/lua_environment.cpp index af41513be61..bf4a0377d51 100644 --- a/src/lua/scripts/lua_environment.cpp +++ b/src/lua/scripts/lua_environment.cpp @@ -182,3 +182,19 @@ void LuaEnvironment::executeTimerEvent(uint32_t eventIndex) { luaL_unref(luaState, LUA_REGISTRYINDEX, parameter); } } + +void LuaEnvironment::collectGarbage() const { + // prevents recursive collects + static bool collecting = false; + if (!collecting) { + collecting = true; + + // we must collect two times because __gc metamethod + // is called on uservalues only the second time + for (int i = -1; ++i < 2;) { + lua_gc(luaState, LUA_GCCOLLECT, 0); + } + + collecting = false; + } +} diff --git a/src/lua/scripts/lua_environment.hpp b/src/lua/scripts/lua_environment.hpp index 752a0712337..91481d208cb 100644 --- a/src/lua/scripts/lua_environment.hpp +++ b/src/lua/scripts/lua_environment.hpp @@ -82,6 +82,8 @@ class LuaEnvironment : public LuaScriptInterface { return shuttingDown; } + void collectGarbage() const; + private: void executeTimerEvent(uint32_t eventIndex); From f96aa5696e1d14e9afd07237b9a68a1ebc33a897 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Wed, 20 Sep 2023 20:54:28 -0300 Subject: [PATCH 36/67] collectGarbage on shutdown --- src/game/game.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index abce8b82fa1..cc8de4e8b83 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -7383,6 +7383,8 @@ void Game::shutdown() { ConnectionManager::getInstance().closeAll(); + g_luaEnvironment().collectGarbage(); + g_logger().info("Done!"); } @@ -8402,7 +8404,6 @@ void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 int32_t stackCount = std::min(it.stackSize, tmpAmount); std::shared_ptr item = Item::CreateItem(it.id, stackCount); if (internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { - break; } @@ -8423,7 +8424,6 @@ void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 for (uint16_t i = 0; i < offer.amount; ++i) { std::shared_ptr item = Item::CreateItem(it.id, subType); if (internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { - break; } @@ -8496,7 +8496,6 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 if (!buyerPlayer) { buyerPlayer = std::make_shared(nullptr); if (!IOLoginData::loadPlayerById(buyerPlayer, offer.playerId)) { - offerStatus << "Failed to load buyer player " << player->getName(); return; } From 46761c5eae4974a4f6324d6622db9de8ce05e2a7 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Wed, 20 Sep 2023 21:30:45 -0300 Subject: [PATCH 37/67] feat: call LUA_GC every 10min --- src/game/game.cpp | 6 ++++++ src/game/game.hpp | 1 + 2 files changed, 7 insertions(+) diff --git a/src/game/game.cpp b/src/game/game.cpp index cc8de4e8b83..904a14544cb 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -297,6 +297,12 @@ void Game::start(ServiceManager* manager) { g_scheduler().addEvent(EVENT_MS, std::bind_front(&Game::updateForgeableMonsters, this), "Game::updateForgeableMonsters"); g_scheduler().addEvent(EVENT_MS + 1000, std::bind_front(&Game::createFiendishMonsters, this), "Game::createFiendishMonsters"); g_scheduler().addEvent(EVENT_MS + 1000, std::bind_front(&Game::createInfluencedMonsters, this), "Game::createInfluencedMonsters"); + + static const std::function &LUA_GC = [] { + g_scheduler().addEvent(EVENT_LUA_GARBAGE_COLLECTION, LUA_GC, "Calling GC"); + g_luaEnvironment().collectGarbage(); + }; + LUA_GC(); } GameState_t Game::getGameState() const { diff --git a/src/game/game.hpp b/src/game/game.hpp index eb6de64001a..72dd0686a7c 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -42,6 +42,7 @@ static constexpr int32_t EVENT_LIGHTINTERVAL_MS = 10000; static constexpr int32_t EVENT_DECAYINTERVAL = 250; static constexpr int32_t EVENT_DECAY_BUCKETS = 4; static constexpr int32_t EVENT_FORGEABLEMONSTERCHECKINTERVAL = 300000; +static constexpr int32_t EVENT_LUA_GARBAGE_COLLECTION = 60000 * 10; // 10min class Game { public: From 5df0b048bd412a714b53d29630656d7d4673d2ac Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 21 Sep 2023 09:02:05 -0700 Subject: [PATCH 38/67] free child ptr when destroying qtreenode --- src/map/utils/qtreenode.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/map/utils/qtreenode.hpp b/src/map/utils/qtreenode.hpp index 798e020fe03..aefa5fcd28c 100644 --- a/src/map/utils/qtreenode.hpp +++ b/src/map/utils/qtreenode.hpp @@ -21,6 +21,7 @@ class QTreeNode { virtual ~QTreeNode() { for (auto* ptr : child) { + delete ptr; } }; From 60fd43f4a3787db8756e706cfef515b02dc7fadf Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 21 Sep 2023 09:32:50 -0700 Subject: [PATCH 39/67] improve: move Party/PartyAnalyzer to smart ptrs --- src/creatures/combat/combat.cpp | 2 +- src/creatures/creature.cpp | 6 +- src/creatures/interactions/chat.cpp | 6 +- src/creatures/interactions/chat.hpp | 2 +- src/creatures/monsters/monster.cpp | 1 - src/creatures/players/grouping/party.cpp | 58 +++++++++---------- src/creatures/players/grouping/party.hpp | 12 ++-- src/creatures/players/player.cpp | 6 +- src/creatures/players/player.hpp | 12 ++-- src/game/game.cpp | 24 ++++---- src/items/tile.cpp | 24 ++++---- src/lua/callbacks/event_callback.cpp | 8 +-- src/lua/callbacks/event_callback.hpp | 8 +-- src/lua/creature/events.cpp | 8 +-- src/lua/creature/events.hpp | 8 +-- .../creatures/player/party_functions.cpp | 36 ++++++------ .../creatures/player/party_functions.hpp | 2 +- .../creatures/player/player_functions.cpp | 2 +- src/server/network/protocol/protocolgame.cpp | 8 +-- src/server/network/protocol/protocolgame.hpp | 2 +- 20 files changed, 116 insertions(+), 119 deletions(-) diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index 23649b889c0..7538a10680b 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -671,7 +671,7 @@ bool Combat::checkFearConditionAffected(std::shared_ptr player) { return false; } - Party* party = player->getParty(); + auto party = player->getParty(); if (party) { auto affectedCount = (party->getMemberCount() + 5) / 5; g_logger().debug("[{}] Player is member of a party, {} members can be feared", __FUNCTION__, affectedCount); diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index b9545cdf7e1..c2544eefb1c 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -641,7 +641,7 @@ void Creature::onDeath() { int32_t mostDamage = 0; std::map, uint64_t> experienceMap; for (const auto &it : damageMap) { - if (std::shared_ptr attacker = g_game().getCreatureByID(it.first)) { + if (auto attacker = g_game().getCreatureByID(it.first)) { CountBlock_t cb = it.second; if ((cb.total > mostDamage && (timeNow - cb.ticks <= inFightTicks))) { mostDamage = cb.total; @@ -650,10 +650,10 @@ void Creature::onDeath() { if (attacker != getCreature()) { uint64_t gainExp = getGainedExperience(attacker); - if (std::shared_ptr attackerPlayer = attacker->getPlayer()) { + if (auto attackerPlayer = attacker->getPlayer()) { attackerPlayer->removeAttacked(getPlayer()); - Party* party = attackerPlayer->getParty(); + auto party = attackerPlayer->getParty(); if (party && party->getLeader() && party->isSharedExperienceActive() && party->isSharedExperienceEnabled()) { attacker = party->getLeader(); mostDamageCreature = attacker; diff --git a/src/creatures/interactions/chat.cpp b/src/creatures/interactions/chat.cpp index 33659479618..d58da460728 100644 --- a/src/creatures/interactions/chat.cpp +++ b/src/creatures/interactions/chat.cpp @@ -341,7 +341,7 @@ ChatChannel* Chat::createChannel(const std::shared_ptr &player, uint16_t } case CHANNEL_PARTY: { - Party* party = player->getParty(); + auto party = player->getParty(); if (party != nullptr) { auto ret = partyChannels.emplace(std::make_pair(party, ChatChannel(channelId, "Party"))); return &ret.first->second; @@ -391,7 +391,7 @@ bool Chat::deleteChannel(const std::shared_ptr &player, uint16_t channel } case CHANNEL_PARTY: { - Party* party = player->getParty(); + auto party = player->getParty(); if (party == nullptr) { return false; } @@ -558,7 +558,7 @@ ChatChannel* Chat::getChannel(const std::shared_ptr &player, uint16_t ch } case CHANNEL_PARTY: { - Party* party = player->getParty(); + auto party = player->getParty(); if (party != nullptr) { auto it = partyChannels.find(party); if (it != partyChannels.end()) { diff --git a/src/creatures/interactions/chat.hpp b/src/creatures/interactions/chat.hpp index fcacca6865c..31d2a612e1c 100644 --- a/src/creatures/interactions/chat.hpp +++ b/src/creatures/interactions/chat.hpp @@ -146,7 +146,7 @@ class Chat { private: std::map normalChannels; std::map privateChannels; - std::map partyChannels; + std::map, ChatChannel> partyChannels; std::map guildChannels; LuaScriptInterface scriptInterface; diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index c52da75f837..1948c24581c 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -1034,7 +1034,6 @@ void Monster::onThinkDefense(uint32_t interval) { g_game().addMagicEffect(getPosition(), CONST_ME_MAGIC_BLUE); g_game().addMagicEffect(summon->getPosition(), CONST_ME_TELEPORT); g_game().sendSingleSoundEffect(summon->getPosition(), SoundEffect_t::MONSTER_SPELL_SUMMON, getMonster()); - } else { } } } diff --git a/src/creatures/players/grouping/party.cpp b/src/creatures/players/grouping/party.cpp index 5701adb6708..ac9986658d5 100644 --- a/src/creatures/players/grouping/party.cpp +++ b/src/creatures/players/grouping/party.cpp @@ -17,18 +17,18 @@ Party::Party(std::shared_ptr initLeader) : m_leader(initLeader) { - initLeader->setParty(this); + initLeader->setParty(getParty()); if (g_configManager().getBoolean(PARTY_AUTO_SHARE_EXPERIENCE)) { setSharedExperience(initLeader, true); } } void Party::disband() { - if (!g_events().eventPartyOnDisband(this)) { + if (!g_events().eventPartyOnDisband(getParty())) { return; } - if (!g_callbacks().checkCallback(EventCallback_t::partyOnDisband, &EventCallback::partyOnDisband, this)) { + if (!g_callbacks().checkCallback(EventCallback_t::partyOnDisband, &EventCallback::partyOnDisband, getParty())) { return; } @@ -46,7 +46,7 @@ void Party::disband() { currentLeader->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, "Your party has been disbanded."); for (auto invitee : getInvitees()) { - invitee->removePartyInvitation(this); + invitee->removePartyInvitation(getParty()); currentLeader->sendCreatureShield(invitee); } inviteList.clear(); @@ -70,9 +70,6 @@ void Party::disband() { g_game().updatePlayerHelpers(member); } memberList.clear(); - - for (PartyAnalyzer* analyzer : membersData) { - } membersData.clear(); } @@ -86,15 +83,15 @@ bool Party::leaveParty(std::shared_ptr player) { return false; } - if (player->getParty() != this && leader != player) { + if (player->getParty().get() != this && leader != player) { return false; } - if (!g_events().eventPartyOnLeave(this, player)) { + if (!g_events().eventPartyOnLeave(getParty(), player)) { return false; } - if (!g_callbacks().checkCallback(EventCallback_t::partyOnLeave, &EventCallback::partyOnLeave, this, player)) { + if (!g_callbacks().checkCallback(EventCallback_t::partyOnLeave, &EventCallback::partyOnLeave, getParty(), player)) { return false; } @@ -164,7 +161,7 @@ bool Party::leaveParty(std::shared_ptr player) { bool Party::passPartyLeadership(std::shared_ptr player) { auto leader = getLeader(); - if (!leader || !player || leader == player || player->getParty() != this) { + if (!leader || !player || leader == player || player->getParty().get() != this) { return false; } @@ -209,11 +206,11 @@ bool Party::joinParty(const std::shared_ptr &player) { return false; } - if (!g_events().eventPartyOnJoin(this, player)) { + if (!g_events().eventPartyOnJoin(getParty(), player)) { return false; } - if (!g_callbacks().checkCallback(EventCallback_t::partyOnJoin, &EventCallback::partyOnJoin, this, player)) { + if (!g_callbacks().checkCallback(EventCallback_t::partyOnJoin, &EventCallback::partyOnJoin, getParty(), player)) { return false; } @@ -228,7 +225,7 @@ bool Party::joinParty(const std::shared_ptr &player) { ss << player->getName() << " has joined the party."; broadcastPartyMessage(MESSAGE_PARTY_MANAGEMENT, ss.str()); - player->setParty(this); + player->setParty(getParty()); g_game().updatePlayerShield(player); @@ -247,7 +244,7 @@ bool Party::joinParty(const std::shared_ptr &player) { updatePlayerStatus(player); - player->removePartyInvitation(this); + player->removePartyInvitation(getParty()); updateSharedExperience(); const std::string &leaderName = leader->getName(); @@ -275,7 +272,7 @@ bool Party::removeInvite(const std::shared_ptr &player, bool removeFromP player->sendCreatureShield(leader); if (removeFromPlayer) { - player->removePartyInvitation(this); + player->removePartyInvitation(getParty()); } if (empty()) { @@ -339,7 +336,7 @@ bool Party::invitePlayer(const std::shared_ptr &player) { leader->sendCreatureShield(player); player->sendCreatureShield(leader); - player->addPartyInvitation(this); + player->addPartyInvitation(getParty()); ss.str(std::string()); ss << leader->getName() << " has invited you to " << leader->getPossessivePronoun() << " party (Share range: " << getMinLevel() << "-" << getMaxLevel() << ")."; @@ -450,8 +447,8 @@ void Party::shareExperience(uint64_t experience, std::shared_ptr targe } uint64_t shareExperience = experience; - g_events().eventPartyOnShareExperience(this, shareExperience); - g_callbacks().executeCallback(EventCallback_t::partyOnShareExperience, &EventCallback::partyOnShareExperience, this, shareExperience); + g_events().eventPartyOnShareExperience(getParty(), shareExperience); + g_callbacks().executeCallback(EventCallback_t::partyOnShareExperience, &EventCallback::partyOnShareExperience, getParty(), shareExperience); for (auto member : getMembers()) { member->onGainSharedExperience(shareExperience, target); @@ -578,7 +575,7 @@ bool Party::canOpenCorpse(uint32_t ownerId) const { } if (std::shared_ptr player = g_game().getPlayerByID(ownerId)) { - return leader->getID() == ownerId || player->getParty() == this; + return leader->getID() == ownerId || player->getParty().get() == this; } return false; } @@ -739,9 +736,9 @@ void Party::addPlayerLoot(std::shared_ptr player, std::shared_ptr return; } - PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); + auto playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { - playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); + playerAnalyzer = std::make_shared(player->getID(), player->getName()); membersData.push_back(playerAnalyzer); } @@ -767,9 +764,9 @@ void Party::addPlayerSupply(std::shared_ptr player, std::shared_ptrgetID()); + std::shared_ptr playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { - playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); + playerAnalyzer = std::make_shared(player->getID(), player->getName()); membersData.push_back(playerAnalyzer); } @@ -789,9 +786,9 @@ void Party::addPlayerSupply(std::shared_ptr player, std::shared_ptr player, uint64_t amount) { - PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); + auto playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { - playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); + playerAnalyzer = std::make_shared(player->getID(), player->getName()); membersData.push_back(playerAnalyzer); } @@ -800,9 +797,9 @@ void Party::addPlayerDamage(std::shared_ptr player, uint64_t amount) { } void Party::addPlayerHealing(std::shared_ptr player, uint64_t amount) { - PartyAnalyzer* playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); + auto playerAnalyzer = getPlayerPartyAnalyzerStruct(player->getID()); if (!playerAnalyzer) { - playerAnalyzer = new PartyAnalyzer(player->getID(), player->getName()); + playerAnalyzer = std::make_shared(player->getID(), player->getName()); membersData.push_back(playerAnalyzer); } @@ -823,9 +820,6 @@ void Party::switchAnalyzerPriceType() { void Party::resetAnalyzer() { trackerTime = time(nullptr); - for (PartyAnalyzer* analyzer : membersData) { - } - membersData.clear(); updateTrackerAnalyzer(); } @@ -836,7 +830,7 @@ void Party::reloadPrices() { return; } - for (PartyAnalyzer* analyzer : membersData) { + for (const auto &analyzer : membersData) { if (priceType == MARKET_PRICE) { analyzer->lootPrice = g_game().getItemMarketPrice(analyzer->lootMap, false); analyzer->supplyPrice = g_game().getItemMarketPrice(analyzer->supplyMap, true); diff --git a/src/creatures/players/grouping/party.hpp b/src/creatures/players/grouping/party.hpp index d6c0e9ea6bc..34e1c6e26b7 100644 --- a/src/creatures/players/grouping/party.hpp +++ b/src/creatures/players/grouping/party.hpp @@ -24,10 +24,14 @@ enum SharedExpStatus_t : uint8_t { class Player; class Party; -class Party { +class Party : public SharedObject { public: explicit Party(std::shared_ptr leader); + std::shared_ptr getParty() { + return static_self_cast(); + } + std::shared_ptr getLeader() const { return m_leader.lock(); } @@ -92,8 +96,8 @@ class Party { void resetAnalyzer(); void reloadPrices(); - PartyAnalyzer* getPlayerPartyAnalyzerStruct(uint32_t playerId) const { - if (auto it = std::find_if(membersData.begin(), membersData.end(), [playerId](const PartyAnalyzer* preyIt) { + std::shared_ptr getPlayerPartyAnalyzerStruct(uint32_t playerId) const { + if (auto it = std::find_if(membersData.begin(), membersData.end(), [playerId](const std::shared_ptr preyIt) { return preyIt->id == playerId; }); it != membersData.end()) { @@ -111,7 +115,7 @@ class Party { // Party analyzer time_t trackerTime = time(nullptr); PartyAnalyzer_t priceType = MARKET_PRICE; - std::vector membersData; + std::vector> membersData; private: const char* getSharedExpReturnMessage(SharedExpStatus_t value); diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 04de7235cf3..641662cf286 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -5471,7 +5471,7 @@ void Player::sendPlayerPartyIcons(std::shared_ptr player) { sendPartyCreatureSkull(player); } -bool Player::addPartyInvitation(Party* newParty) { +bool Player::addPartyInvitation(std::shared_ptr newParty) { auto it = std::find(invitePartyList.begin(), invitePartyList.end(), newParty); if (it != invitePartyList.end()) { return false; @@ -5481,12 +5481,12 @@ bool Player::addPartyInvitation(Party* newParty) { return true; } -void Player::removePartyInvitation(Party* remParty) { +void Player::removePartyInvitation(std::shared_ptr remParty) { invitePartyList.remove(remParty); } void Player::clearPartyInvitations() { - for (Party* invitingParty : invitePartyList) { + for (const auto &invitingParty : invitePartyList) { invitingParty->removeInvite(getPlayer(), false); } invitePartyList.clear(); diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 7ff7e02a505..566c3e793e9 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -335,10 +335,10 @@ class Player final : public Creature, public Cylinder, public Bankable { return secureMode; } - void setParty(Party* newParty) { + void setParty(std::shared_ptr newParty) { this->party = newParty; } - Party* getParty() const { + std::shared_ptr getParty() const { return party; } @@ -387,8 +387,8 @@ class Player final : public Creature, public Cylinder, public Bankable { bool isInviting(std::shared_ptr player) const; bool isPartner(std::shared_ptr player) const; void sendPlayerPartyIcons(std::shared_ptr player); - bool addPartyInvitation(Party* party); - void removePartyInvitation(Party* party); + bool addPartyInvitation(std::shared_ptr party); + void removePartyInvitation(std::shared_ptr party); void clearPartyInvitations(); void sendUnjustifiedPoints(); @@ -2598,7 +2598,7 @@ class Player final : public Creature, public Cylinder, public Bankable { GuildWarVector guildWarVector; - std::forward_list invitePartyList; + std::forward_list> invitePartyList; std::forward_list modalWindows; std::forward_list learnedInstantSpellList; // TODO: This variable is only temporarily used when logging in, get rid of it somehow. @@ -2658,7 +2658,7 @@ class Player final : public Creature, public Cylinder, public Bankable { std::shared_ptr writeItem = nullptr; House* editHouse = nullptr; std::shared_ptr shopOwner = nullptr; - Party* party = nullptr; + std::shared_ptr party = nullptr; std::shared_ptr tradePartner = nullptr; ProtocolGame_ptr client; std::shared_ptr walkTask; diff --git a/src/game/game.cpp b/src/game/game.cpp index 904a14544cb..32038df9703 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -6350,7 +6350,7 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt } // Party hunt analyzer - if (Party* party = attackerPlayer ? attackerPlayer->getParty() : nullptr) { + if (auto party = attackerPlayer ? attackerPlayer->getParty() : nullptr) { party->addPlayerHealing(attackerPlayer, realHealthChange); } @@ -6732,7 +6732,7 @@ void Game::updatePlayerPartyHuntAnalyzer(const CombatDamage &damage, std::shared return; } - if (Party* party = player->getParty()) { + if (auto party = player->getParty()) { if (damage.primary.value != 0) { party->addPlayerDamage(player, damage.primary.value); } @@ -7197,12 +7197,12 @@ void Game::addCreatureHealth(std::shared_ptr target) { void Game::addCreatureHealth(const SpectatorHashSet &spectators, std::shared_ptr target) { uint8_t healthPercent = std::ceil((static_cast(target->getHealth()) / std::max(target->getMaxHealth(), 1)) * 100); if (std::shared_ptr targetPlayer = target->getPlayer()) { - if (Party* party = targetPlayer->getParty()) { + if (std::shared_ptr party = targetPlayer->getParty()) { party->updatePlayerHealth(targetPlayer, target, healthPercent); } } else if (std::shared_ptr master = target->getMaster()) { if (std::shared_ptr masterPlayer = master->getPlayer()) { - if (Party* party = masterPlayer->getParty()) { + if (std::shared_ptr party = masterPlayer->getParty()) { party->updatePlayerHealth(masterPlayer, target, healthPercent); } } @@ -7215,14 +7215,14 @@ void Game::addCreatureHealth(const SpectatorHashSet &spectators, std::shared_ptr } void Game::addPlayerMana(std::shared_ptr target) { - if (Party* party = target->getParty()) { + if (std::shared_ptr party = target->getParty()) { uint8_t manaPercent = std::ceil((static_cast(target->getMana()) / std::max(target->getMaxMana(), 1)) * 100); party->updatePlayerMana(target, manaPercent); } } void Game::addPlayerVocation(std::shared_ptr target) { - if (Party* party = target->getParty()) { + if (auto party = target->getParty()) { party->updatePlayerVocation(target); } @@ -7583,9 +7583,9 @@ void Game::playerInviteToParty(uint32_t playerId, uint32_t invitedId) { return; } - Party* party = player->getParty(); + std::shared_ptr party = player->getParty(); if (!party) { - party = new Party(player); + party = std::make_shared(player); } else if (party->getLeader() != player) { return; } @@ -7622,7 +7622,7 @@ void Game::playerJoinParty(uint32_t playerId, uint32_t leaderId) { return; } - Party* party = leader->getParty(); + auto party = leader->getParty(); if (!party || party->getLeader() != leader) { return; } @@ -7641,7 +7641,7 @@ void Game::playerRevokePartyInvitation(uint32_t playerId, uint32_t invitedId) { return; } - Party* party = player->getParty(); + std::shared_ptr party = player->getParty(); if (!party || party->getLeader() != player) { return; } @@ -7660,7 +7660,7 @@ void Game::playerPassPartyLeadership(uint32_t playerId, uint32_t newLeaderId) { return; } - Party* party = player->getParty(); + std::shared_ptr party = player->getParty(); if (!party || party->getLeader() != player) { return; } @@ -7679,7 +7679,7 @@ void Game::playerLeaveParty(uint32_t playerId) { return; } - Party* party = player->getParty(); + std::shared_ptr party = player->getParty(); if (!party || player->hasCondition(CONDITION_INFIGHT)) { return; } diff --git a/src/items/tile.cpp b/src/items/tile.cpp index 2849a8818cf..17c082a6886 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -31,7 +31,7 @@ bool Tile::hasProperty(ItemProperty prop) const { } if (const TileItemVector* items = getItemList()) { - for (std::shared_ptr item : *items) { + for (auto &item : *items) { if (item->hasProperty(prop)) { return true; } @@ -48,7 +48,7 @@ bool Tile::hasProperty(std::shared_ptr exclude, ItemProperty prop) const { } if (const TileItemVector* items = getItemList()) { - for (std::shared_ptr item : *items) { + for (auto &item : *items) { if (item != exclude && item->hasProperty(prop)) { return true; } @@ -72,7 +72,7 @@ bool Tile::hasHeight(uint32_t n) const { } if (const TileItemVector* items = getItemList()) { - for (std::shared_ptr item : *items) { + for (auto &item : *items) { if (item->hasProperty(CONST_PROP_HASHEIGHT)) { ++height; } @@ -593,7 +593,7 @@ ReturnValue Tile::queryAdd(int32_t, const std::shared_ptr &thing, uint32_ } } } else if (creatures && !creatures->empty()) { - for (std::shared_ptr tileCreature : *creatures) { + for (auto &tileCreature : *creatures) { if (!tileCreature->isInGhostMode()) { return RETURNVALUE_NOTENOUGHROOM; } @@ -638,7 +638,7 @@ ReturnValue Tile::queryAdd(int32_t, const std::shared_ptr &thing, uint32_ const CreatureVector* creatures = getCreatures(); if (std::shared_ptr player = creature->getPlayer()) { if (creatures && !creatures->empty() && !hasBitSet(FLAG_IGNOREBLOCKCREATURE, tileFlags) && !player->isAccessPlayer()) { - for (std::shared_ptr tileCreature : *creatures) { + for (auto &tileCreature : *creatures) { if (!player->canWalkthrough(tileCreature)) { return RETURNVALUE_NOTPOSSIBLE; } @@ -672,7 +672,7 @@ ReturnValue Tile::queryAdd(int32_t, const std::shared_ptr &thing, uint32_ } } } else if (creatures && !creatures->empty() && !hasBitSet(FLAG_IGNOREBLOCKCREATURE, tileFlags)) { - for (std::shared_ptr tileCreature : *creatures) { + for (auto &tileCreature : *creatures) { if (!tileCreature->isInGhostMode()) { return RETURNVALUE_NOTENOUGHROOM; } @@ -707,7 +707,7 @@ ReturnValue Tile::queryAdd(int32_t, const std::shared_ptr &thing, uint32_ } if (const auto items = getItemList()) { - for (std::shared_ptr item : *items) { + for (auto &item : *items) { const ItemType &iiType = Item::items[item->getID()]; if (iiType.blockSolid && (!iiType.moveable || item->hasAttribute(ItemAttribute_t::UNIQUEID))) { return RETURNVALUE_NOTPOSSIBLE; @@ -728,7 +728,7 @@ ReturnValue Tile::queryAdd(int32_t, const std::shared_ptr &thing, uint32_ const CreatureVector* creatures = getCreatures(); if (creatures && !creatures->empty() && item->isBlocking() && !hasBitSet(FLAG_IGNOREBLOCKCREATURE, tileFlags)) { - for (std::shared_ptr tileCreature : *creatures) { + for (auto &tileCreature : *creatures) { if (!tileCreature->isInGhostMode()) { return RETURNVALUE_NOTENOUGHROOM; } @@ -737,7 +737,7 @@ ReturnValue Tile::queryAdd(int32_t, const std::shared_ptr &thing, uint32_ if (itemIsHangable && hasFlag(TILESTATE_SUPPORTS_HANGABLE)) { if (items) { - for (std::shared_ptr tileItem : *items) { + for (auto &tileItem : *items) { if (tileItem->isHangable()) { return RETURNVALUE_NEEDEXCHANGE; } @@ -760,7 +760,7 @@ ReturnValue Tile::queryAdd(int32_t, const std::shared_ptr &thing, uint32_ } if (items) { - for (std::shared_ptr tileItem : *items) { + for (auto &tileItem : *items) { const ItemType &iiType = Item::items[tileItem->getID()]; if (!iiType.blockSolid) { continue; @@ -1362,7 +1362,7 @@ int32_t Tile::getStackposOfItem(std::shared_ptr player, std::shared_ptr< } if (const CreatureVector* creatures = getCreatures()) { - for (std::shared_ptr creature : *creatures) { + for (auto &creature : *creatures) { if (player->canSeeCreature(creature)) { if (++n >= 10) { return -1; @@ -1399,7 +1399,7 @@ uint32_t Tile::getItemTypeCount(uint16_t itemId, int32_t subType /*= -1*/) const const TileItemVector* items = getItemList(); if (items) { - for (std::shared_ptr item : *items) { + for (auto &item : *items) { if (item->getID() == itemId) { count += Item::countByType(item, subType); } diff --git a/src/lua/callbacks/event_callback.cpp b/src/lua/callbacks/event_callback.cpp index 8f6a27be29c..6444446bde9 100644 --- a/src/lua/callbacks/event_callback.cpp +++ b/src/lua/callbacks/event_callback.cpp @@ -228,7 +228,7 @@ void EventCallback::creatureOnDrainHealth(std::shared_ptr creature, st } // Party -bool EventCallback::partyOnJoin(Party* party, std::shared_ptr player) const { +bool EventCallback::partyOnJoin(std::shared_ptr party, std::shared_ptr player) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::partyOnJoin - " "Player {}] " @@ -252,7 +252,7 @@ bool EventCallback::partyOnJoin(Party* party, std::shared_ptr player) co return getScriptInterface()->callFunction(2); } -bool EventCallback::partyOnLeave(Party* party, std::shared_ptr player) const { +bool EventCallback::partyOnLeave(std::shared_ptr party, std::shared_ptr player) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::partyOnLeave - " "Player {}] " @@ -276,7 +276,7 @@ bool EventCallback::partyOnLeave(Party* party, std::shared_ptr player) c return getScriptInterface()->callFunction(2); } -bool EventCallback::partyOnDisband(Party* party) const { +bool EventCallback::partyOnDisband(std::shared_ptr party) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::partyOnDisband - Party leader {}] Call stack " "overflow. Too many lua script calls being nested.", @@ -296,7 +296,7 @@ bool EventCallback::partyOnDisband(Party* party) const { return getScriptInterface()->callFunction(1); } -void EventCallback::partyOnShareExperience(Party* party, uint64_t &exp) const { +void EventCallback::partyOnShareExperience(std::shared_ptr party, uint64_t &exp) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("Party leader {}. Call stack overflow. Too many lua script calls being nested.", party->getLeader() ? party->getLeader()->getName() : "unknown"); return; diff --git a/src/lua/callbacks/event_callback.hpp b/src/lua/callbacks/event_callback.hpp index e5712a06d71..152c86b8ed7 100644 --- a/src/lua/callbacks/event_callback.hpp +++ b/src/lua/callbacks/event_callback.hpp @@ -86,10 +86,10 @@ class EventCallback : public Script { void creatureOnDrainHealth(std::shared_ptr creature, std::shared_ptr attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) const; // Party - bool partyOnJoin(Party* party, std::shared_ptr player) const; - bool partyOnLeave(Party* party, std::shared_ptr player) const; - bool partyOnDisband(Party* party) const; - void partyOnShareExperience(Party* party, uint64_t &exp) const; + bool partyOnJoin(std::shared_ptr party, std::shared_ptr player) const; + bool partyOnLeave(std::shared_ptr party, std::shared_ptr player) const; + bool partyOnDisband(std::shared_ptr party) const; + void partyOnShareExperience(std::shared_ptr party, uint64_t &exp) const; // Player bool playerOnBrowseField(std::shared_ptr player, const Position &position) const; diff --git a/src/lua/creature/events.cpp b/src/lua/creature/events.cpp index b79f770b3ce..176044d666e 100644 --- a/src/lua/creature/events.cpp +++ b/src/lua/creature/events.cpp @@ -421,7 +421,7 @@ void Events::eventCreatureOnDrainHealth(std::shared_ptr creature, std: } // Party -bool Events::eventPartyOnJoin(Party* party, std::shared_ptr player) { +bool Events::eventPartyOnJoin(std::shared_ptr party, std::shared_ptr player) { // Party:onJoin(player) or Party.onJoin(self, player) if (info.partyOnJoin == -1) { return true; @@ -450,7 +450,7 @@ bool Events::eventPartyOnJoin(Party* party, std::shared_ptr player) { return scriptInterface.callFunction(2); } -bool Events::eventPartyOnLeave(Party* party, std::shared_ptr player) { +bool Events::eventPartyOnLeave(std::shared_ptr party, std::shared_ptr player) { // Party:onLeave(player) or Party.onLeave(self, player) if (info.partyOnLeave == -1) { return true; @@ -479,7 +479,7 @@ bool Events::eventPartyOnLeave(Party* party, std::shared_ptr player) { return scriptInterface.callFunction(2); } -bool Events::eventPartyOnDisband(Party* party) { +bool Events::eventPartyOnDisband(std::shared_ptr party) { // Party:onDisband() or Party.onDisband(self) if (info.partyOnDisband == -1) { return true; @@ -504,7 +504,7 @@ bool Events::eventPartyOnDisband(Party* party) { return scriptInterface.callFunction(1); } -void Events::eventPartyOnShareExperience(Party* party, uint64_t &exp) { +void Events::eventPartyOnShareExperience(std::shared_ptr party, uint64_t &exp) { // Party:onShareExperience(exp) or Party.onShareExperience(self, exp) if (info.partyOnShareExperience == -1) { return; diff --git a/src/lua/creature/events.hpp b/src/lua/creature/events.hpp index 172144a6f9a..08260c8aef4 100644 --- a/src/lua/creature/events.hpp +++ b/src/lua/creature/events.hpp @@ -88,10 +88,10 @@ class Events { void eventCreatureOnDrainHealth(std::shared_ptr creature, std::shared_ptr attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary); // Party - bool eventPartyOnJoin(Party* party, std::shared_ptr player); - bool eventPartyOnLeave(Party* party, std::shared_ptr player); - bool eventPartyOnDisband(Party* party); - void eventPartyOnShareExperience(Party* party, uint64_t &exp); + bool eventPartyOnJoin(std::shared_ptr party, std::shared_ptr player); + bool eventPartyOnLeave(std::shared_ptr party, std::shared_ptr player); + bool eventPartyOnDisband(std::shared_ptr party); + void eventPartyOnShareExperience(std::shared_ptr party, uint64_t &exp); // Player bool eventPlayerOnBrowseField(std::shared_ptr player, const Position &position); diff --git a/src/lua/functions/creatures/player/party_functions.cpp b/src/lua/functions/creatures/player/party_functions.cpp index e51d231ebf8..36c133a14cf 100644 --- a/src/lua/functions/creatures/player/party_functions.cpp +++ b/src/lua/functions/creatures/player/party_functions.cpp @@ -22,9 +22,9 @@ int32_t PartyFunctions::luaPartyCreate(lua_State* L) { return 1; } - Party* party = player->getParty(); + std::shared_ptr party = player->getParty(); if (!party) { - party = new Party(player); + party = std::make_shared(player); g_game().updatePlayerShield(player); player->sendCreatureSkull(player); pushUserdata(L, party); @@ -37,9 +37,9 @@ int32_t PartyFunctions::luaPartyCreate(lua_State* L) { int PartyFunctions::luaPartyDisband(lua_State* L) { // party:disband() - Party** partyPtr = getRawUserdata(L, 1); + std::shared_ptr* partyPtr = getRawUserDataShared(L, 1); if (partyPtr && *partyPtr) { - Party*&party = *partyPtr; + std::shared_ptr &party = *partyPtr; party->disband(); party = nullptr; pushBoolean(L, true); @@ -51,7 +51,7 @@ int PartyFunctions::luaPartyDisband(lua_State* L) { int PartyFunctions::luaPartyGetLeader(lua_State* L) { // party:getLeader() - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (!party) { lua_pushnil(L); return 1; @@ -70,7 +70,7 @@ int PartyFunctions::luaPartyGetLeader(lua_State* L) { int PartyFunctions::luaPartySetLeader(lua_State* L) { // party:setLeader(player) std::shared_ptr player = getPlayer(L, 2); - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (party && player) { pushBoolean(L, party->passPartyLeadership(player)); } else { @@ -81,7 +81,7 @@ int PartyFunctions::luaPartySetLeader(lua_State* L) { int PartyFunctions::luaPartyGetMembers(lua_State* L) { // party:getMembers() - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (!party) { lua_pushnil(L); return 1; @@ -99,7 +99,7 @@ int PartyFunctions::luaPartyGetMembers(lua_State* L) { int PartyFunctions::luaPartyGetMemberCount(lua_State* L) { // party:getMemberCount() - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (party) { lua_pushnumber(L, party->getMemberCount()); } else { @@ -110,7 +110,7 @@ int PartyFunctions::luaPartyGetMemberCount(lua_State* L) { int PartyFunctions::luaPartyGetInvitees(lua_State* L) { // party:getInvitees() - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (party) { lua_createtable(L, party->getInvitationCount(), 0); @@ -128,7 +128,7 @@ int PartyFunctions::luaPartyGetInvitees(lua_State* L) { int PartyFunctions::luaPartyGetInviteeCount(lua_State* L) { // party:getInviteeCount() - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (party) { lua_pushnumber(L, party->getInvitationCount()); } else { @@ -140,7 +140,7 @@ int PartyFunctions::luaPartyGetInviteeCount(lua_State* L) { int PartyFunctions::luaPartyAddInvite(lua_State* L) { // party:addInvite(player) std::shared_ptr player = getPlayer(L, 2); - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (party && player) { pushBoolean(L, party->invitePlayer(player)); } else { @@ -152,7 +152,7 @@ int PartyFunctions::luaPartyAddInvite(lua_State* L) { int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { // party:removeInvite(player) std::shared_ptr player = getPlayer(L, 2); - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (party && player) { pushBoolean(L, party->removeInvite(player)); } else { @@ -164,7 +164,7 @@ int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { int PartyFunctions::luaPartyAddMember(lua_State* L) { // party:addMember(player) std::shared_ptr player = getPlayer(L, 2); - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (party && player) { pushBoolean(L, party->joinParty(player)); } else { @@ -176,7 +176,7 @@ int PartyFunctions::luaPartyAddMember(lua_State* L) { int PartyFunctions::luaPartyRemoveMember(lua_State* L) { // party:removeMember(player) std::shared_ptr player = getPlayer(L, 2); - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (party && player) { pushBoolean(L, party->leaveParty(player)); } else { @@ -187,7 +187,7 @@ int PartyFunctions::luaPartyRemoveMember(lua_State* L) { int PartyFunctions::luaPartyIsSharedExperienceActive(lua_State* L) { // party:isSharedExperienceActive() - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (party) { pushBoolean(L, party->isSharedExperienceActive()); } else { @@ -198,7 +198,7 @@ int PartyFunctions::luaPartyIsSharedExperienceActive(lua_State* L) { int PartyFunctions::luaPartyIsSharedExperienceEnabled(lua_State* L) { // party:isSharedExperienceEnabled() - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (party) { pushBoolean(L, party->isSharedExperienceEnabled()); } else { @@ -210,7 +210,7 @@ int PartyFunctions::luaPartyIsSharedExperienceEnabled(lua_State* L) { int PartyFunctions::luaPartyShareExperience(lua_State* L) { // party:shareExperience(experience) uint64_t experience = getNumber(L, 2); - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (party) { party->shareExperience(experience); pushBoolean(L, true); @@ -223,7 +223,7 @@ int PartyFunctions::luaPartyShareExperience(lua_State* L) { int PartyFunctions::luaPartySetSharedExperience(lua_State* L) { // party:setSharedExperience(active) bool active = getBoolean(L, 2); - Party* party = getUserdata(L, 1); + std::shared_ptr party = getUserdataShared(L, 1); if (party) { pushBoolean(L, party->setSharedExperience(party->getLeader(), active)); } else { diff --git a/src/lua/functions/creatures/player/party_functions.hpp b/src/lua/functions/creatures/player/party_functions.hpp index 4c9a1463f71..30ff517201d 100644 --- a/src/lua/functions/creatures/player/party_functions.hpp +++ b/src/lua/functions/creatures/player/party_functions.hpp @@ -14,7 +14,7 @@ class PartyFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "Party", "", PartyFunctions::luaPartyCreate); + registerSharedClass(L, "Party", "", PartyFunctions::luaPartyCreate); registerMetaMethod(L, "Party", "__eq", PartyFunctions::luaUserdataCompare); registerMethod(L, "Party", "disband", PartyFunctions::luaPartyDisband); registerMethod(L, "Party", "getLeader", PartyFunctions::luaPartyGetLeader); diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index f6e3db2531a..8c8c76180e2 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -2193,7 +2193,7 @@ int PlayerFunctions::luaPlayerGetParty(lua_State* L) { return 1; } - Party* party = player->getParty(); + std::shared_ptr party = player->getParty(); if (party) { pushUserdata(L, party); setMetatable(L, -1, "Party"); diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 50fbbcedb2a..097018c2ecb 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -2618,7 +2618,7 @@ void ProtocolGame::parsePartyAnalyzerAction(NetworkMessage &msg) const { return; } - Party* party = player->getParty(); + std::shared_ptr party = player->getParty(); if (!party || !party->getLeader() || party->getLeader()->getID() != player->getID()) { return; } @@ -7359,7 +7359,7 @@ void ProtocolGame::sendSpecialContainersAvailable() { writeToOutputBuffer(msg); } -void ProtocolGame::updatePartyTrackerAnalyzer(const Party* party) { +void ProtocolGame::updatePartyTrackerAnalyzer(const std::shared_ptr party) { if (oldProtocol || !player || !party || !party->getLeader()) { return; } @@ -7371,7 +7371,7 @@ void ProtocolGame::updatePartyTrackerAnalyzer(const Party* party) { msg.addByte(static_cast(party->priceType)); msg.addByte(static_cast(party->membersData.size())); - for (const PartyAnalyzer* analyzer : party->membersData) { + for (const std::shared_ptr analyzer : party->membersData) { msg.add(analyzer->id); if (std::shared_ptr member = g_game().getPlayerByID(analyzer->id); !member || !member->getParty() || member->getParty() != party) { @@ -7390,7 +7390,7 @@ void ProtocolGame::updatePartyTrackerAnalyzer(const Party* party) { msg.addByte(showNames ? 0x01 : 0x00); if (showNames) { msg.addByte(static_cast(party->membersData.size())); - for (const PartyAnalyzer* analyzer : party->membersData) { + for (const std::shared_ptr analyzer : party->membersData) { msg.add(analyzer->id); msg.addString(analyzer->name); } diff --git a/src/server/network/protocol/protocolgame.hpp b/src/server/network/protocol/protocolgame.hpp index a167ab9559e..62b4c615d6b 100644 --- a/src/server/network/protocol/protocolgame.hpp +++ b/src/server/network/protocol/protocolgame.hpp @@ -344,7 +344,7 @@ class ProtocolGame final : public Protocol { void sendMarketDetail(uint16_t itemId, uint8_t tier); void sendTradeItemRequest(const std::string &traderName, std::shared_ptr item, bool ack); void sendCloseTrade(); - void updatePartyTrackerAnalyzer(const Party* party); + void updatePartyTrackerAnalyzer(const std::shared_ptr party); void sendTextWindow(uint32_t windowTextId, uint32_t itemId, const std::string &text); void sendTextWindow(uint32_t windowTextId, std::shared_ptr item, uint16_t maxlen, bool canWrite); From ff4321aa3c2c51317b8251a5cdc0ace71819509b Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 21 Sep 2023 10:08:58 -0700 Subject: [PATCH 40/67] improve: move Condition to smart ptrs --- src/creatures/combat/combat.cpp | 4 +- src/creatures/combat/combat.hpp | 4 +- src/creatures/combat/condition.cpp | 158 +++++++++--------- src/creatures/combat/condition.hpp | 90 +++++----- src/creatures/combat/spells.cpp | 6 +- src/creatures/creature.cpp | 54 +++--- src/creatures/creature.hpp | 16 +- src/creatures/monsters/monsters.cpp | 14 +- src/creatures/monsters/monsters.hpp | 2 +- src/creatures/players/player.cpp | 32 ++-- src/creatures/players/player.hpp | 6 +- src/creatures/players/wheel/player_wheel.cpp | 2 +- src/game/game.cpp | 2 +- src/io/functions/iologindata_load_player.cpp | 2 +- src/io/functions/iologindata_save_player.cpp | 2 +- src/io/iobestiary.cpp | 6 +- src/items/bed.cpp | 2 +- src/items/functions/item/item_parse.cpp | 8 +- src/items/functions/item/item_parse.hpp | 2 +- src/items/items.hpp | 2 +- src/lua/creature/movement.cpp | 6 +- .../functions/core/game/global_functions.cpp | 6 +- .../creatures/combat/combat_functions.cpp | 2 +- .../creatures/combat/condition_functions.cpp | 31 ++-- .../creatures/combat/condition_functions.hpp | 2 +- .../creatures/creature_functions.cpp | 8 +- src/server/network/protocol/protocolgame.cpp | 4 +- 27 files changed, 236 insertions(+), 237 deletions(-) diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index 7538a10680b..51389b11f57 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -729,7 +729,7 @@ void Combat::CombatConditionFunc(std::shared_ptr caster, std::shared_p } if (caster == target || target && !target->isImmune(condition->getType())) { - Condition* conditionCopy = condition->clone(); + auto conditionCopy = condition->clone(); if (caster) { conditionCopy->setParam(CONDITION_PARAM_OWNER, caster->getID()); conditionCopy->setPositionParam(CONDITION_PARAM_CASTER_POSITION, caster->getPosition()); @@ -2054,7 +2054,7 @@ void MagicField::onStepInField(const std::shared_ptr &creature) { const ItemType &it = items[getID()]; if (it.conditionDamage) { - Condition* conditionCopy = it.conditionDamage->clone(); + auto conditionCopy = it.conditionDamage->clone(); auto ownerId = getAttribute(ItemAttribute_t::OWNER); if (ownerId) { bool harmfulField = true; diff --git a/src/creatures/combat/combat.hpp b/src/creatures/combat/combat.hpp index 780b1b5eb2c..a13898865c7 100644 --- a/src/creatures/combat/combat.hpp +++ b/src/creatures/combat/combat.hpp @@ -67,7 +67,7 @@ class ChainPickerCallback final : public CallBack { }; struct CombatParams { - std::forward_list> conditionList; + std::forward_list> conditionList; std::unique_ptr valueCallback; std::unique_ptr tileCallback; @@ -296,7 +296,7 @@ class Combat { bool hasArea() const { return area != nullptr; } - void addCondition(const Condition* condition) { + void addCondition(const std::shared_ptr condition) { params.conditionList.emplace_front(condition); } void setPlayerCombatValues(formulaType_t formulaType, double mina, double minb, double maxa, double maxb); diff --git a/src/creatures/combat/condition.cpp b/src/creatures/combat/condition.cpp index b4e09da0d58..8b58e6ff0fa 100644 --- a/src/creatures/combat/condition.cpp +++ b/src/creatures/combat/condition.cpp @@ -184,7 +184,7 @@ bool Condition::executeCondition(std::shared_ptr creature, int32_t int return true; } -Condition* Condition::createCondition(ConditionId_t id, ConditionType_t type, int32_t ticks, int32_t param /* = 0*/, bool buff /* = false*/, uint32_t subId /* = 0*/) { +std::shared_ptr Condition::createCondition(ConditionId_t id, ConditionType_t type, int32_t ticks, int32_t param /* = 0*/, bool buff /* = false*/, uint32_t subId /* = 0*/) { switch (type) { case CONDITION_POISON: case CONDITION_FIRE: @@ -194,41 +194,41 @@ Condition* Condition::createCondition(ConditionId_t id, ConditionType_t type, in case CONDITION_DAZZLED: case CONDITION_CURSED: case CONDITION_BLEEDING: - return new ConditionDamage(id, type, buff, subId); + return std::make_shared(id, type, buff, subId); case CONDITION_HASTE: case CONDITION_PARALYZE: - return new ConditionSpeed(id, type, ticks, buff, subId, param); + return std::make_shared(id, type, ticks, buff, subId, param); case CONDITION_INVISIBLE: - return new ConditionInvisible(id, type, ticks, buff, subId); + return std::make_shared(id, type, ticks, buff, subId); case CONDITION_OUTFIT: - return new ConditionOutfit(id, type, ticks, buff, subId); + return std::make_shared(id, type, ticks, buff, subId); case CONDITION_LIGHT: - return new ConditionLight(id, type, ticks, buff, subId, param & 0xFF, (param & 0xFF00) >> 8); + return std::make_shared(id, type, ticks, buff, subId, param & 0xFF, (param & 0xFF00) >> 8); case CONDITION_REGENERATION: - return new ConditionRegeneration(id, type, ticks, buff, subId); + return std::make_shared(id, type, ticks, buff, subId); case CONDITION_SOUL: - return new ConditionSoul(id, type, ticks, buff, subId); + return std::make_shared(id, type, ticks, buff, subId); case CONDITION_ATTRIBUTES: - return new ConditionAttributes(id, type, ticks, buff, subId); + return std::make_shared(id, type, ticks, buff, subId); case CONDITION_SPELLCOOLDOWN: - return new ConditionSpellCooldown(id, type, ticks, buff, subId); + return std::make_shared(id, type, ticks, buff, subId); case CONDITION_SPELLGROUPCOOLDOWN: - return new ConditionSpellGroupCooldown(id, type, ticks, buff, subId); + return std::make_shared(id, type, ticks, buff, subId); case CONDITION_MANASHIELD: - return new ConditionManaShield(id, type, ticks, buff, subId); + return std::make_shared(id, type, ticks, buff, subId); case CONDITION_FEARED: - return new ConditionFeared(id, type, ticks, buff, subId); + return std::make_shared(id, type, ticks, buff, subId); case CONDITION_ROOTED: case CONDITION_INFIGHT: @@ -240,14 +240,14 @@ Condition* Condition::createCondition(ConditionId_t id, ConditionType_t type, in case CONDITION_CHANNELMUTEDTICKS: case CONDITION_YELLTICKS: case CONDITION_PACIFIED: - return new ConditionGeneric(id, type, ticks, buff, subId); + return std::make_shared(id, type, ticks, buff, subId); default: return nullptr; } } -Condition* Condition::createCondition(PropStream &propStream) { +std::shared_ptr Condition::createCondition(PropStream &propStream) { uint8_t attr; if (!propStream.read(attr) || attr != CONDITIONATTR_TYPE) { return nullptr; @@ -332,7 +332,7 @@ uint32_t Condition::getIcons() const { return isBuff ? ICON_PARTY_BUFF : 0; } -bool Condition::updateCondition(const Condition* addCondition) { +bool Condition::updateCondition(const std::shared_ptr addCondition) { if (conditionType != addCondition->getType()) { return false; } @@ -364,7 +364,7 @@ void ConditionGeneric::endCondition(std::shared_ptr) { // } -void ConditionGeneric::addCondition(std::shared_ptr creature, const Condition* addCondition) { +void ConditionGeneric::addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) { if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); @@ -401,7 +401,7 @@ uint32_t ConditionGeneric::getIcons() const { * ConditionAttributes */ -void ConditionAttributes::addCondition(std::shared_ptr creature, const Condition* addCondition) { +void ConditionAttributes::addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) { if (!creature) { return; } @@ -409,24 +409,24 @@ void ConditionAttributes::addCondition(std::shared_ptr creature, const if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); - const ConditionAttributes &conditionAttrs = static_cast(*addCondition); + const std::shared_ptr &conditionAttrs = addCondition->static_self_cast(); // Remove the old condition endCondition(creature); // Apply the new one - memcpy(skills, conditionAttrs.skills, sizeof(skills)); - memcpy(skillsPercent, conditionAttrs.skillsPercent, sizeof(skillsPercent)); - memcpy(stats, conditionAttrs.stats, sizeof(stats)); - memcpy(statsPercent, conditionAttrs.statsPercent, sizeof(statsPercent)); - memcpy(buffs, conditionAttrs.buffs, sizeof(buffs)); - memcpy(buffsPercent, conditionAttrs.buffsPercent, sizeof(buffsPercent)); + memcpy(skills, conditionAttrs->skills, sizeof(skills)); + memcpy(skillsPercent, conditionAttrs->skillsPercent, sizeof(skillsPercent)); + memcpy(stats, conditionAttrs->stats, sizeof(stats)); + memcpy(statsPercent, conditionAttrs->statsPercent, sizeof(statsPercent)); + memcpy(buffs, conditionAttrs->buffs, sizeof(buffs)); + memcpy(buffsPercent, conditionAttrs->buffsPercent, sizeof(buffsPercent)); // Using std::array can only increment to the new instead of use memcpy - absorbs = conditionAttrs.absorbs; - absorbsPercent = conditionAttrs.absorbsPercent; - increases = conditionAttrs.increases; - increasesPercent = conditionAttrs.increasesPercent; - charmChanceModifier = conditionAttrs.charmChanceModifier; + absorbs = conditionAttrs->absorbs; + absorbsPercent = conditionAttrs->absorbsPercent; + increases = conditionAttrs->increases; + increasesPercent = conditionAttrs->increasesPercent; + charmChanceModifier = conditionAttrs->charmChanceModifier; updatePercentBuffs(creature); updateBuffs(creature); @@ -435,7 +435,7 @@ void ConditionAttributes::addCondition(std::shared_ptr creature, const updatePercentIncreases(creature); updateIncreases(creature); updateCharmChanceModifier(creature); - disableDefense = conditionAttrs.disableDefense; + disableDefense = conditionAttrs->disableDefense; if (std::shared_ptr player = creature->getPlayer()) { updatePercentSkills(player); @@ -1113,20 +1113,20 @@ void ConditionRegeneration::endCondition(std::shared_ptr creature) { } } -void ConditionRegeneration::addCondition(std::shared_ptr creature, const Condition* addCondition) { +void ConditionRegeneration::addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) { if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); - const ConditionRegeneration &conditionRegen = static_cast(*addCondition); + const std::shared_ptr &conditionRegen = addCondition->static_self_cast(); - healthTicks = conditionRegen.healthTicks; - manaTicks = conditionRegen.manaTicks; + healthTicks = conditionRegen->healthTicks; + manaTicks = conditionRegen->manaTicks; - healthGain = conditionRegen.healthGain; - manaGain = conditionRegen.manaGain; + healthGain = conditionRegen->healthGain; + manaGain = conditionRegen->manaGain; } - if (std::shared_ptr player = creature->getPlayer()) { + if (auto player = creature->getPlayer()) { player->sendStats(); } } @@ -1291,13 +1291,13 @@ void ConditionManaShield::endCondition(std::shared_ptr creature) { } } -void ConditionManaShield::addCondition(std::shared_ptr creature, const Condition* addCondition) { +void ConditionManaShield::addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) { endCondition(creature); setTicks(addCondition->getTicks()); - const ConditionManaShield &conditionManaShield = static_cast(*addCondition); + const std::shared_ptr &conditionManaShield = addCondition->static_self_cast(); - manaShield = conditionManaShield.manaShield; + manaShield = conditionManaShield->manaShield; creature->setManaShield(manaShield); creature->setMaxManaShield(manaShield); @@ -1346,14 +1346,14 @@ uint32_t ConditionManaShield::getIcons() const { * ConditionSoul */ -void ConditionSoul::addCondition(std::shared_ptr, const Condition* addCondition) { +void ConditionSoul::addCondition(std::shared_ptr, const std::shared_ptr addCondition) { if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); - const ConditionSoul &conditionSoul = static_cast(*addCondition); + const std::shared_ptr &conditionSoul = addCondition->static_self_cast(); - soulTicks = conditionSoul.soulTicks; - soulGain = conditionSoul.soulGain; + soulTicks = conditionSoul->soulTicks; + soulGain = conditionSoul->soulGain; } } @@ -1501,17 +1501,17 @@ void ConditionDamage::serialize(PropWriteStream &propWriteStream) { } } -bool ConditionDamage::updateCondition(const Condition* addCondition) { - const ConditionDamage &conditionDamage = static_cast(*addCondition); - if (conditionDamage.doForceUpdate()) { +bool ConditionDamage::updateCondition(const std::shared_ptr addCondition) { + const std::shared_ptr &conditionDamage = addCondition->static_self_cast(); + if (conditionDamage->doForceUpdate()) { return true; } - if (ticks == -1 && conditionDamage.ticks > 0) { + if (ticks == -1 && conditionDamage->ticks > 0) { return false; } - return conditionDamage.getTotalDamage() > getTotalDamage(); + return conditionDamage->getTotalDamage() > getTotalDamage(); } bool ConditionDamage::addDamage(int32_t rounds, int32_t time, int32_t value) { @@ -1680,7 +1680,7 @@ void ConditionDamage::endCondition(std::shared_ptr) { // } -void ConditionDamage::addCondition(std::shared_ptr creature, const Condition* addCondition) { +void ConditionDamage::addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) { if (addCondition->getType() != conditionType) { return; } @@ -1689,15 +1689,15 @@ void ConditionDamage::addCondition(std::shared_ptr creature, const Con return; } - const ConditionDamage &conditionDamage = static_cast(*addCondition); + const std::shared_ptr &conditionDamage = addCondition->static_self_cast(); setTicks(addCondition->getTicks()); - owner = conditionDamage.owner; - maxDamage = conditionDamage.maxDamage; - minDamage = conditionDamage.minDamage; - startDamage = conditionDamage.startDamage; - tickInterval = conditionDamage.tickInterval; - periodDamage = conditionDamage.periodDamage; + owner = conditionDamage->owner; + maxDamage = conditionDamage->maxDamage; + minDamage = conditionDamage->minDamage; + startDamage = conditionDamage->startDamage; + tickInterval = conditionDamage->tickInterval; + periodDamage = conditionDamage->periodDamage; int32_t nextTimeLeft = tickInterval; if (!damageList.empty()) { @@ -1707,7 +1707,7 @@ void ConditionDamage::addCondition(std::shared_ptr creature, const Con damageList.clear(); } - damageList = conditionDamage.damageList; + damageList = conditionDamage->damageList; if (init()) { if (!damageList.empty()) { @@ -2059,7 +2059,7 @@ void ConditionFeared::endCondition(std::shared_ptr creature) { } } -void ConditionFeared::addCondition(std::shared_ptr, const Condition* addCondition) { +void ConditionFeared::addCondition(std::shared_ptr, const std::shared_ptr addCondition) { if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); } @@ -2162,7 +2162,7 @@ void ConditionSpeed::endCondition(std::shared_ptr creature) { g_game().changeSpeed(creature, -speedDelta); } -void ConditionSpeed::addCondition(std::shared_ptr creature, const Condition* addCondition) { +void ConditionSpeed::addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) { if (conditionType != addCondition->getType()) { return; } @@ -2173,13 +2173,13 @@ void ConditionSpeed::addCondition(std::shared_ptr creature, const Cond setTicks(addCondition->getTicks()); - const ConditionSpeed &conditionSpeed = static_cast(*addCondition); + const std::shared_ptr &conditionSpeed = addCondition->static_self_cast(); int32_t oldSpeedDelta = speedDelta; - speedDelta = conditionSpeed.speedDelta; - mina = conditionSpeed.mina; - maxa = conditionSpeed.maxa; - minb = conditionSpeed.minb; - maxb = conditionSpeed.maxb; + speedDelta = conditionSpeed->speedDelta; + mina = conditionSpeed->mina; + maxa = conditionSpeed->maxa; + minb = conditionSpeed->minb; + maxb = conditionSpeed->maxb; if (speedDelta == 0) { int32_t min; @@ -2288,7 +2288,7 @@ void ConditionOutfit::endCondition(std::shared_ptr creature) { g_game().internalCreatureChangeOutfit(creature, creature->getDefaultOutfit()); } -void ConditionOutfit::addCondition(std::shared_ptr creature, const Condition* addCondition) { +void ConditionOutfit::addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) { if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && outfit.lookType != 0 && !g_game().isLookTypeRegistered(outfit.lookType)) { g_logger().warn("[ConditionOutfit::addCondition] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", outfit.lookType); return; @@ -2297,17 +2297,17 @@ void ConditionOutfit::addCondition(std::shared_ptr creature, const Con if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); - const ConditionOutfit &conditionOutfit = static_cast(*addCondition); - if (!conditionOutfit.monsterName.empty() && conditionOutfit.monsterName.compare(monsterName) != 0) { - const auto monsterType = g_monsters().getMonsterType(conditionOutfit.monsterName); + const std::shared_ptr &conditionOutfit = addCondition->static_self_cast(); + if (!conditionOutfit->monsterName.empty() && conditionOutfit->monsterName.compare(monsterName) != 0) { + const auto monsterType = g_monsters().getMonsterType(conditionOutfit->monsterName); if (monsterType) { setOutfit(monsterType->info.outfit); } else { g_logger().error("[ConditionOutfit::addCondition] - Monster {} does not exist", monsterName); return; } - } else if (conditionOutfit.outfit.lookType != 0 || conditionOutfit.outfit.lookTypeEx != 0) { - setOutfit(conditionOutfit.outfit); + } else if (conditionOutfit->outfit.lookType != 0 || conditionOutfit->outfit.lookTypeEx != 0) { + setOutfit(conditionOutfit->outfit); } g_game().internalCreatureChangeOutfit(creature, outfit); @@ -2352,13 +2352,13 @@ void ConditionLight::endCondition(std::shared_ptr creature) { g_game().changeLight(creature); } -void ConditionLight::addCondition(std::shared_ptr creature, const Condition* condition) { +void ConditionLight::addCondition(std::shared_ptr creature, const std::shared_ptr condition) { if (updateCondition(condition)) { setTicks(condition->getTicks()); - const ConditionLight &conditionLight = static_cast(*condition); - lightInfo.level = conditionLight.lightInfo.level; - lightInfo.color = conditionLight.lightInfo.color; + const std::shared_ptr &conditionLight = condition->static_self_cast(); + lightInfo.level = conditionLight->lightInfo.level; + lightInfo.color = conditionLight->lightInfo.color; lightChangeInterval = ticks / lightInfo.level; internalLightTicks = 0; creature->setCreatureLight(lightInfo); @@ -2434,7 +2434,7 @@ void ConditionLight::serialize(PropWriteStream &propWriteStream) { * ConditionSpellCooldown */ -void ConditionSpellCooldown::addCondition(std::shared_ptr creature, const Condition* addCondition) { +void ConditionSpellCooldown::addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) { if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); @@ -2465,7 +2465,7 @@ bool ConditionSpellCooldown::startCondition(std::shared_ptr creature) * ConditionSpellGroupCooldown */ -void ConditionSpellGroupCooldown::addCondition(std::shared_ptr creature, const Condition* addCondition) { +void ConditionSpellGroupCooldown::addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) { if (updateCondition(addCondition)) { setTicks(addCondition->getTicks()); diff --git a/src/creatures/combat/condition.hpp b/src/creatures/combat/condition.hpp index d2704c4c49d..f8228e074ca 100644 --- a/src/creatures/combat/condition.hpp +++ b/src/creatures/combat/condition.hpp @@ -16,7 +16,7 @@ class Player; class PropStream; class PropWriteStream; -class Condition { +class Condition : public SharedObject { public: Condition() = default; Condition(ConditionId_t initId, ConditionType_t initType, int32_t initTicks, bool initBuff = false, uint32_t initSubId = 0) : @@ -27,7 +27,7 @@ class Condition { virtual bool startCondition(std::shared_ptr creature); virtual bool executeCondition(std::shared_ptr creature, int32_t interval); virtual void endCondition(std::shared_ptr creature) = 0; - virtual void addCondition(std::shared_ptr creature, const Condition* condition) = 0; + virtual void addCondition(std::shared_ptr creature, const std::shared_ptr condition) = 0; virtual uint32_t getIcons() const; ConditionId_t getId() const { return id; @@ -36,7 +36,7 @@ class Condition { return subId; } - virtual Condition* clone() const = 0; + virtual std::shared_ptr clone() const = 0; ConditionType_t getType() const { return conditionType; @@ -49,8 +49,8 @@ class Condition { } void setTicks(int32_t newTicks); - static Condition* createCondition(ConditionId_t id, ConditionType_t type, int32_t ticks, int32_t param = 0, bool buff = false, uint32_t subId = 0); - static Condition* createCondition(PropStream &propStream); + static std::shared_ptr createCondition(ConditionId_t id, ConditionType_t type, int32_t ticks, int32_t param = 0, bool buff = false, uint32_t subId = 0); + static std::shared_ptr createCondition(PropStream &propStream); virtual bool setParam(ConditionParam_t param, int32_t value); virtual bool setPositionParam(ConditionParam_t param, const Position &pos); @@ -72,7 +72,7 @@ class Condition { ConditionId_t id; bool isBuff; - virtual bool updateCondition(const Condition* addCondition); + virtual bool updateCondition(const std::shared_ptr addCondition); private: SoundEffect_t tickSound = SoundEffect_t::SILENCE; @@ -90,11 +90,11 @@ class ConditionGeneric : public Condition { bool startCondition(std::shared_ptr creature) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const Condition* condition) override; + void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; uint32_t getIcons() const override; - ConditionGeneric* clone() const override { - return new ConditionGeneric(*this); + std::shared_ptr clone() const override { + return std::make_shared(*this); } }; @@ -106,12 +106,12 @@ class ConditionAttributes final : public ConditionGeneric { bool startCondition(std::shared_ptr creature) final; bool executeCondition(std::shared_ptr creature, int32_t interval) final; void endCondition(std::shared_ptr creature) final; - void addCondition(std::shared_ptr creature, const Condition* condition) final; + void addCondition(std::shared_ptr creature, const std::shared_ptr condition) final; bool setParam(ConditionParam_t param, int32_t value) final; - ConditionAttributes* clone() const final { - return new ConditionAttributes(*this); + std::shared_ptr clone() const final { + return std::make_shared(*this); } // serialization @@ -172,7 +172,7 @@ class ConditionRegeneration final : public ConditionGeneric { bool startCondition(std::shared_ptr creature) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const Condition* addCondition) override; + void addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; bool setParam(ConditionParam_t param, int32_t value) override; @@ -180,8 +180,8 @@ class ConditionRegeneration final : public ConditionGeneric { uint32_t getHealthTicks(std::shared_ptr creature) const; uint32_t getManaTicks(std::shared_ptr creature) const; - ConditionRegeneration* clone() const override { - return new ConditionRegeneration(*this); + std::shared_ptr clone() const override { + return std::make_shared(*this); } // serialization @@ -205,13 +205,13 @@ class ConditionManaShield final : public Condition { bool startCondition(std::shared_ptr creature) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const Condition* addCondition) override; + void addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) override; uint32_t getIcons() const override; bool setParam(ConditionParam_t param, int32_t value) override; - ConditionManaShield* clone() const override { - return new ConditionManaShield(*this); + std::shared_ptr clone() const override { + return std::make_shared(*this); } // serialization @@ -227,13 +227,13 @@ class ConditionSoul final : public ConditionGeneric { ConditionSoul(ConditionId_t initId, ConditionType_t initType, int32_t iniTicks, bool initBuff = false, uint32_t initSubId = 0) : ConditionGeneric(initId, initType, iniTicks, initBuff, initSubId) { } - void addCondition(std::shared_ptr creature, const Condition* addCondition) override; + void addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; bool setParam(ConditionParam_t param, int32_t value) override; - ConditionSoul* clone() const override { - return new ConditionSoul(*this); + std::shared_ptr clone() const override { + return std::make_shared(*this); } // serialization @@ -254,8 +254,8 @@ class ConditionInvisible final : public ConditionGeneric { bool startCondition(std::shared_ptr creature) override; void endCondition(std::shared_ptr creature) override; - ConditionInvisible* clone() const override { - return new ConditionInvisible(*this); + std::shared_ptr clone() const override { + return std::make_shared(*this); } }; @@ -270,11 +270,11 @@ class ConditionDamage final : public Condition { bool startCondition(std::shared_ptr creature) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const Condition* condition) override; + void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; uint32_t getIcons() const override; - ConditionDamage* clone() const override { - return new ConditionDamage(*this); + std::shared_ptr clone() const override { + return std::make_shared(*this); } bool setParam(ConditionParam_t param, int32_t value) override; @@ -309,7 +309,7 @@ class ConditionDamage final : public Condition { bool getNextDamage(int32_t &damage); bool doDamage(std::shared_ptr creature, int32_t healthChange); - bool updateCondition(const Condition* addCondition) override; + bool updateCondition(const std::shared_ptr addCondition) override; }; class ConditionFeared final : public Condition { @@ -321,11 +321,11 @@ class ConditionFeared final : public Condition { bool startCondition(std::shared_ptr creature) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const Condition* condition) override; + void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; uint32_t getIcons() const override; - ConditionFeared* clone() const override { - return new ConditionFeared(*this); + std::shared_ptr clone() const override { + return std::make_shared(*this); } bool setPositionParam(ConditionParam_t param, const Position &pos) override; @@ -360,11 +360,11 @@ class ConditionSpeed final : public Condition { bool startCondition(std::shared_ptr creature) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const Condition* condition) override; + void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; uint32_t getIcons() const override; - ConditionSpeed* clone() const override { - return new ConditionSpeed(*this); + std::shared_ptr clone() const override { + return std::make_shared(*this); } bool setParam(ConditionParam_t param, int32_t value) override; @@ -395,10 +395,10 @@ class ConditionOutfit final : public Condition { bool startCondition(std::shared_ptr creature) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const Condition* condition) override; + void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; - ConditionOutfit* clone() const override { - return new ConditionOutfit(*this); + std::shared_ptr clone() const override { + return std::make_shared(*this); } void setOutfit(const Outfit_t &outfit); @@ -421,10 +421,10 @@ class ConditionLight final : public Condition { bool startCondition(std::shared_ptr creature) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const Condition* addCondition) override; + void addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) override; - ConditionLight* clone() const override { - return new ConditionLight(*this); + std::shared_ptr clone() const override { + return std::make_shared(*this); } bool setParam(ConditionParam_t param, int32_t value) override; @@ -445,10 +445,10 @@ class ConditionSpellCooldown final : public ConditionGeneric { ConditionGeneric(initId, initType, initTicks, initBuff, initSubId) { } bool startCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const Condition* condition) override; + void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; - ConditionSpellCooldown* clone() const override { - return new ConditionSpellCooldown(*this); + std::shared_ptr clone() const override { + return std::make_shared(*this); } }; @@ -458,9 +458,9 @@ class ConditionSpellGroupCooldown final : public ConditionGeneric { ConditionGeneric(initId, initType, initTicks, initBuff, initSubId) { } bool startCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const Condition* condition) override; + void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; - ConditionSpellGroupCooldown* clone() const override { - return new ConditionSpellGroupCooldown(*this); + std::shared_ptr clone() const override { + return std::make_shared(*this); } }; diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 46c5ba8f604..d0f4d260df0 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -616,7 +616,7 @@ void Spell::applyCooldownConditions(std::shared_ptr player) const { spellCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::COOLDOWN, spellGrade); } if (spellCooldown > 0) { - Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, spellCooldown / rate_cooldown, 0, false, spellId); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, spellCooldown / rate_cooldown, 0, false, spellId); player->addCondition(condition); } } @@ -627,7 +627,7 @@ void Spell::applyCooldownConditions(std::shared_ptr player) const { spellGroupCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::GROUP_COOLDOWN, spellGrade); } if (spellGroupCooldown > 0) { - Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellGroupCooldown / rate_cooldown, 0, false, group); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellGroupCooldown / rate_cooldown, 0, false, group); player->addCondition(condition); } } @@ -638,7 +638,7 @@ void Spell::applyCooldownConditions(std::shared_ptr player) const { spellSecondaryGroupCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::SECONDARY_GROUP_COOLDOWN, spellGrade); } if (spellSecondaryGroupCooldown > 0) { - Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellSecondaryGroupCooldown / rate_cooldown, 0, false, secondaryGroup); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellSecondaryGroupCooldown / rate_cooldown, 0, false, secondaryGroup); player->addCondition(condition); } } diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index c2544eefb1c..5c01bb4e5a2 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -1154,7 +1154,7 @@ void Creature::onTickCondition(ConditionType_t type, bool &bRemove) { } } -void Creature::onCombatRemoveCondition(Condition* condition) { +void Creature::onCombatRemoveCondition(std::shared_ptr condition) { removeCondition(condition); } @@ -1247,19 +1247,19 @@ bool Creature::setMaster(std::shared_ptr newMaster, bool reloadCreatur return true; } -bool Creature::addCondition(Condition* condition) { +bool Creature::addCondition(std::shared_ptr condition) { if (condition == nullptr) { return false; } - Condition* prevCond = getCondition(condition->getType(), condition->getId(), condition->getSubId()); + std::shared_ptr prevCond = getCondition(condition->getType(), condition->getId(), condition->getSubId()); if (prevCond) { - prevCond->addCondition(static_self_cast(), condition); + prevCond->addCondition(getCreature(), condition); return true; } - if (condition->startCondition(static_self_cast())) { + if (condition->startCondition(getCreature())) { conditions.push_back(condition); onAddCondition(condition->getType()); return true; @@ -1268,7 +1268,7 @@ bool Creature::addCondition(Condition* condition) { return false; } -bool Creature::addCombatCondition(Condition* condition) { +bool Creature::addCombatCondition(std::shared_ptr condition) { // Caution: condition variable could be deleted after the call to addCondition ConditionType_t type = condition->getType(); @@ -1283,7 +1283,7 @@ bool Creature::addCombatCondition(Condition* condition) { void Creature::removeCondition(ConditionType_t type) { auto it = conditions.begin(), end = conditions.end(); while (it != end) { - Condition* condition = *it; + std::shared_ptr condition = *it; if (condition->getType() != type) { ++it; continue; @@ -1291,7 +1291,7 @@ void Creature::removeCondition(ConditionType_t type) { it = conditions.erase(it); - condition->endCondition(static_self_cast()); + condition->endCondition(getCreature()); onEndCondition(type); } @@ -1300,7 +1300,7 @@ void Creature::removeCondition(ConditionType_t type) { void Creature::removeCondition(ConditionType_t conditionType, ConditionId_t conditionId, bool force /* = false*/) { auto it = conditions.begin(), end = conditions.end(); while (it != end) { - Condition* condition = *it; + std::shared_ptr condition = *it; if (condition->getType() != conditionType || condition->getId() != conditionId) { ++it; continue; @@ -1320,26 +1320,26 @@ void Creature::removeCondition(ConditionType_t conditionType, ConditionId_t cond it = conditions.erase(it); - condition->endCondition(static_self_cast()); + condition->endCondition(getCreature()); onEndCondition(conditionType); } } void Creature::removeCombatCondition(ConditionType_t type) { - std::vector removeConditions; - for (Condition* condition : conditions) { + std::vector> removeConditions; + for (const auto &condition : conditions) { if (condition->getType() == type) { removeConditions.push_back(condition); } } - for (Condition* condition : removeConditions) { + for (const auto &condition : removeConditions) { onCombatRemoveCondition(condition); } } -void Creature::removeCondition(Condition* condition) { +void Creature::removeCondition(std::shared_ptr condition) { auto it = std::find(conditions.begin(), conditions.end(), condition); if (it == conditions.end()) { return; @@ -1347,12 +1347,12 @@ void Creature::removeCondition(Condition* condition) { conditions.erase(it); - condition->endCondition(static_self_cast()); + condition->endCondition(getCreature()); onEndCondition(condition->getType()); } -Condition* Creature::getCondition(ConditionType_t type) const { - for (Condition* condition : conditions) { +std::shared_ptr Creature::getCondition(ConditionType_t type) const { + for (const auto &condition : conditions) { if (condition->getType() == type) { return condition; } @@ -1360,8 +1360,8 @@ Condition* Creature::getCondition(ConditionType_t type) const { return nullptr; } -Condition* Creature::getCondition(ConditionType_t type, ConditionId_t conditionId, uint32_t subId /* = 0*/) const { - for (Condition* condition : conditions) { +std::shared_ptr Creature::getCondition(ConditionType_t type, ConditionId_t conditionId, uint32_t subId /* = 0*/) const { + for (const auto &condition : conditions) { if (condition->getType() == type && condition->getId() == conditionId && condition->getSubId() == subId) { return condition; } @@ -1369,9 +1369,9 @@ Condition* Creature::getCondition(ConditionType_t type, ConditionId_t conditionI return nullptr; } -std::vector Creature::getConditionsByType(ConditionType_t type) const { - std::vector conditionsVec; - for (Condition* condition : conditions) { +std::vector> Creature::getConditionsByType(ConditionType_t type) const { + std::vector> conditionsVec; + for (const auto &condition : conditions) { if (condition->getType() == type) { conditionsVec.push_back(condition); } @@ -1382,13 +1382,13 @@ std::vector Creature::getConditionsByType(ConditionType_t type) cons void Creature::executeConditions(uint32_t interval) { auto it = conditions.begin(), end = conditions.end(); while (it != end) { - Condition* condition = *it; - if (!condition->executeCondition(static_self_cast(), interval)) { + std::shared_ptr condition = *it; + if (!condition->executeCondition(getCreature(), interval)) { ConditionType_t type = condition->getType(); it = conditions.erase(it); - condition->endCondition(static_self_cast()); + condition->endCondition(getCreature()); onEndCondition(type); } else { @@ -1403,7 +1403,7 @@ bool Creature::hasCondition(ConditionType_t type, uint32_t subId /* = 0*/) const } int64_t timeNow = OTSYS_TIME(); - for (Condition* condition : conditions) { + for (const auto &condition : conditions) { if (condition->getType() != type || condition->getSubId() != subId) { continue; } @@ -1639,7 +1639,7 @@ bool FrozenPathingConditionCall::operator()(const Position &startPos, const Posi } bool Creature::isInvisible() const { - return std::find_if(conditions.begin(), conditions.end(), [](const Condition* condition) { + return std::find_if(conditions.begin(), conditions.end(), [](const std::shared_ptr condition) { return condition->getType() == CONDITION_INVISIBLE; }) != conditions.end(); diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index a1b7bd386b4..b6a8df61a8f 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -17,7 +17,7 @@ #include "game/movement/position.hpp" #include "items/tile.hpp" -using ConditionList = std::list; +using ConditionList = std::list>; using CreatureEventList = std::list>; class Map; @@ -355,15 +355,15 @@ class Creature : virtual public Thing, public SharedObject { return SPEECHBUBBLE_NONE; } - bool addCondition(Condition* condition); - bool addCombatCondition(Condition* condition); + bool addCondition(std::shared_ptr condition); + bool addCombatCondition(std::shared_ptr condition); void removeCondition(ConditionType_t conditionType, ConditionId_t conditionId, bool force = false); void removeCondition(ConditionType_t type); - void removeCondition(Condition* condition); + void removeCondition(std::shared_ptr condition); void removeCombatCondition(ConditionType_t type); - Condition* getCondition(ConditionType_t type) const; - Condition* getCondition(ConditionType_t type, ConditionId_t conditionId, uint32_t subId = 0) const; - std::vector getConditionsByType(ConditionType_t type) const; + std::shared_ptr getCondition(ConditionType_t type) const; + std::shared_ptr getCondition(ConditionType_t type, ConditionId_t conditionId, uint32_t subId = 0) const; + std::vector> getConditionsByType(ConditionType_t type) const; void executeConditions(uint32_t interval); bool hasCondition(ConditionType_t type, uint32_t subId = 0) const; @@ -405,7 +405,7 @@ class Creature : virtual public Thing, public SharedObject { virtual void onAddCombatCondition(ConditionType_t type); virtual void onEndCondition(ConditionType_t type); void onTickCondition(ConditionType_t type, bool &bRemove); - virtual void onCombatRemoveCondition(Condition* condition); + virtual void onCombatRemoveCondition(std::shared_ptr condition); virtual void onAttackedCreature(std::shared_ptr) { } virtual void onAttacked(); virtual void onAttackedCreatureDrainHealth(std::shared_ptr target, int32_t points); diff --git a/src/creatures/monsters/monsters.cpp b/src/creatures/monsters/monsters.cpp index 6bba7422553..072c6463e7d 100644 --- a/src/creatures/monsters/monsters.cpp +++ b/src/creatures/monsters/monsters.cpp @@ -42,8 +42,8 @@ bool MonsterType::canSpawn(const Position &pos) { return canSpawn; } -ConditionDamage* Monsters::getDamageCondition(ConditionType_t conditionType, int32_t maxDamage, int32_t minDamage, int32_t startDamage, uint32_t tickInterval) { - ConditionDamage* condition = static_cast(Condition::createCondition(CONDITIONID_COMBAT, conditionType, 0, 0)); +std::shared_ptr Monsters::getDamageCondition(ConditionType_t conditionType, int32_t maxDamage, int32_t minDamage, int32_t startDamage, uint32_t tickInterval) { + std::shared_ptr condition = Condition::createCondition(CONDITIONID_COMBAT, conditionType, 0, 0)->static_self_cast(); condition->setParam(CONDITION_PARAM_TICKINTERVAL, tickInterval); condition->setParam(CONDITION_PARAM_MINVALUE, minDamage); condition->setParam(CONDITION_PARAM_MAXVALUE, maxDamage); @@ -143,7 +143,7 @@ bool Monsters::deserializeSpell(const std::shared_ptr spell, spell conditionType = CONDITION_PARALYZE; } - ConditionSpeed* condition = static_cast(Condition::createCondition(CONDITIONID_COMBAT, conditionType, duration, 0)); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_COMBAT, conditionType, duration, 0)->static_self_cast(); condition->setFormulaVars(speedChange / 1000.0, 0, speedChange / 1000.0, 0); combatPtr->addCondition(condition); } else if (spellName == "outfit") { @@ -153,7 +153,7 @@ bool Monsters::deserializeSpell(const std::shared_ptr spell, spell duration = spell->duration; } - ConditionOutfit* condition = static_cast(Condition::createCondition(CONDITIONID_COMBAT, CONDITION_OUTFIT, duration, 0)); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_OUTFIT, duration, 0)->static_self_cast(); if (spell->outfitMonster != "") { condition->setLazyMonsterOutfit(spell->outfitMonster); @@ -177,7 +177,7 @@ bool Monsters::deserializeSpell(const std::shared_ptr spell, spell duration = spell->duration; } - Condition* condition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_INVISIBLE, duration, 0); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_INVISIBLE, duration, 0); combatPtr->setParam(COMBAT_PARAM_AGGRESSIVE, 0); combatPtr->addCondition(condition); } else if (spellName == "drunk") { @@ -187,7 +187,7 @@ bool Monsters::deserializeSpell(const std::shared_ptr spell, spell duration = spell->duration; } - Condition* condition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_DRUNK, duration, 0); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_DRUNK, duration, 0); combatPtr->addCondition(condition); } else if (spellName == "soulwars fear" || spellName == "fear") { int32_t duration = 6000; @@ -247,7 +247,7 @@ bool Monsters::deserializeSpell(const std::shared_ptr spell, spell maxDamage = minDamage; } - Condition* condition = getDamageCondition(spell->conditionType, maxDamage, minDamage, startDamage, tickInterval); + std::shared_ptr condition = getDamageCondition(spell->conditionType, maxDamage, minDamage, startDamage, tickInterval); combatPtr->addCondition(condition); } diff --git a/src/creatures/monsters/monsters.hpp b/src/creatures/monsters/monsters.hpp index ceea9d44aa5..a13792fd297 100644 --- a/src/creatures/monsters/monsters.hpp +++ b/src/creatures/monsters/monsters.hpp @@ -272,7 +272,7 @@ class Monsters { std::map> monsters; private: - ConditionDamage* getDamageCondition(ConditionType_t conditionType, int32_t maxDamage, int32_t minDamage, int32_t startDamage, uint32_t tickInterval); + std::shared_ptr getDamageCondition(ConditionType_t conditionType, int32_t maxDamage, int32_t minDamage, int32_t startDamage, uint32_t tickInterval); }; constexpr auto g_monsters = Monsters::getInstance; diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 641662cf286..327183ef970 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -447,7 +447,7 @@ float Player::getDefenseFactor() const { uint32_t Player::getClientIcons() { uint32_t icons = 0; - for (Condition* condition : conditions) { + for (const auto &condition : conditions) { if (!isSuppress(condition->getType())) { icons |= condition->getIcons(); } @@ -1580,7 +1580,7 @@ void Player::onCreatureAppear(std::shared_ptr creature, bool isLogin) } } - for (Condition* condition : storedConditionList) { + for (const auto &condition : storedConditionList) { addCondition(condition); } storedConditionList.clear(); @@ -1607,7 +1607,7 @@ void Player::onCreatureAppear(std::shared_ptr creature, bool isLogin) offlineTime = 0; } - for (Condition* condition : getMuteConditions()) { + for (std::shared_ptr condition : getMuteConditions()) { condition->setTicks(condition->getTicks() - (offlineTime * 1000)); if (condition->getTicks() <= 0) { removeCondition(condition); @@ -1841,7 +1841,7 @@ void Player::onCreatureMove(std::shared_ptr creature, std::shared_ptr< if (teleport || oldPos.z != newPos.z) { int32_t ticks = g_configManager().getNumber(STAIRHOP_DELAY); if (ticks > 0) { - if (Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_PACIFIED, ticks, 0)) { + if (std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_PACIFIED, ticks, 0)) { addCondition(condition); } } @@ -2075,7 +2075,7 @@ uint32_t Player::isMuted() const { } int32_t muteTicks = 0; - for (Condition* condition : conditions) { + for (std::shared_ptr condition : conditions) { if (condition->getType() == CONDITION_MUTED && condition->getTicks() > muteTicks) { muteTicks = condition->getTicks(); } @@ -2105,7 +2105,7 @@ void Player::removeMessageBuffer() { uint32_t muteTime = 5 * muteCount * muteCount; muteCountMap[guid] = muteCount + 1; - Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_MUTED, muteTime * 1000, 0); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_MUTED, muteTime * 1000, 0); addCondition(condition); std::ostringstream ss; @@ -2707,7 +2707,7 @@ void Player::death(std::shared_ptr lastHitCreature) { auto it = conditions.begin(), end = conditions.end(); while (it != end) { - Condition* condition = *it; + std::shared_ptr condition = *it; // isSupress block to delete spells conditions (ensures that the player cannot, for example, reset the cooldown time of the familiar and summon several) if (condition->isPersistent() && condition->isRemovableOnDeath()) { it = conditions.erase(it); @@ -2724,7 +2724,7 @@ void Player::death(std::shared_ptr lastHitCreature) { auto it = conditions.begin(), end = conditions.end(); while (it != end) { - Condition* condition = *it; + std::shared_ptr condition = *it; if (condition->isPersistent()) { it = conditions.erase(it); @@ -2872,7 +2872,7 @@ void Player::addInFightTicks(bool pzlock /*= false*/) { updateImbuementTrackerStats(); - Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_INFIGHT, g_configManager().getNumber(PZ_LOCKED), 0); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_INFIGHT, g_configManager().getNumber(PZ_LOCKED), 0); addCondition(condition); } @@ -4300,7 +4300,7 @@ void Player::onWalkComplete() { */ g_logger().debug("[Player::onWalkComplete] Executing feared conditions as players completed it's walk."); - Condition* f = getCondition(CONDITION_FEARED); + std::shared_ptr f = getCondition(CONDITION_FEARED); f->executeCondition(static_self_cast(), 0); } @@ -4425,7 +4425,7 @@ void Player::onEndCondition(ConditionType_t type) { sendIcons(); } -void Player::onCombatRemoveCondition(Condition* condition) { +void Player::onCombatRemoveCondition(std::shared_ptr condition) { // Creature::onCombatRemoveCondition(condition); if (condition->getId() > 0) { // Means the condition is from an item, id == slot @@ -4588,7 +4588,7 @@ bool Player::onKilledCreature(std::shared_ptr target, bool lastHit /* if (lastHit && hasCondition(CONDITION_INFIGHT)) { pzLocked = true; - Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_INFIGHT, g_configManager().getNumber(WHITE_SKULL_TIME), 0); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_INFIGHT, g_configManager().getNumber(WHITE_SKULL_TIME), 0); addCondition(condition); } } @@ -6018,9 +6018,9 @@ size_t Player::getMaxDepotItems() const { return g_configManager().getNumber(FREE_DEPOT_LIMIT); } -std::forward_list Player::getMuteConditions() const { - std::forward_list muteConditions; - for (Condition* condition : conditions) { +std::forward_list> Player::getMuteConditions() const { + std::forward_list> muteConditions; + for (std::shared_ptr condition : conditions) { if (condition->getTicks() <= 0) { continue; } @@ -6065,7 +6065,7 @@ void Player::updateRegeneration() { return; } - Condition* condition = getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT); + std::shared_ptr condition = getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT); if (condition) { condition->setParam(CONDITION_PARAM_HEALTHGAIN, vocation->getHealthGainAmount()); condition->setParam(CONDITION_PARAM_HEALTHTICKS, vocation->getHealthGainTicks()); diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 566c3e793e9..b6751e9b034 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -893,7 +893,7 @@ class Player final : public Creature, public Cylinder, public Bankable { void onAddCondition(ConditionType_t type) override; void onAddCombatCondition(ConditionType_t type) override; void onEndCondition(ConditionType_t type) override; - void onCombatRemoveCondition(Condition* condition) override; + void onCombatRemoveCondition(std::shared_ptr condition) override; void onAttackedCreature(std::shared_ptr target) override; void onAttacked() override; void onAttackedCreatureDrainHealth(std::shared_ptr target, int32_t points) override; @@ -2504,7 +2504,7 @@ class Player final : public Creature, public Cylinder, public Bankable { static uint32_t playerFirstID; static uint32_t playerLastID; - std::forward_list getMuteConditions() const; + std::forward_list> getMuteConditions() const; void checkTradeState(std::shared_ptr item); bool hasCapacity(std::shared_ptr item, uint32_t count) const; @@ -2602,7 +2602,7 @@ class Player final : public Creature, public Cylinder, public Bankable { std::forward_list modalWindows; std::forward_list learnedInstantSpellList; // TODO: This variable is only temporarily used when logging in, get rid of it somehow. - std::forward_list storedConditionList; + std::forward_list> storedConditionList; phmap::parallel_flat_hash_set> m_bestiaryMonsterTracker; phmap::parallel_flat_hash_set> m_bosstiaryMonsterTracker; diff --git a/src/creatures/players/wheel/player_wheel.cpp b/src/creatures/players/wheel/player_wheel.cpp index 31dea94d8dd..6890f7b4ed7 100644 --- a/src/creatures/players/wheel/player_wheel.cpp +++ b/src/creatures/players/wheel/player_wheel.cpp @@ -2088,7 +2088,7 @@ void PlayerWheel::onThink(bool force /* = false*/) { } void PlayerWheel::reduceAllSpellsCooldownTimer(int32_t value) { - for (Condition* condition : m_player.getConditionsByType(CONDITION_SPELLCOOLDOWN)) { + for (const auto &condition : m_player.getConditionsByType(CONDITION_SPELLCOOLDOWN)) { if (condition->getTicks() <= value) { m_player.sendSpellCooldown(condition->getSubId(), 0); condition->endCondition(m_player.getPlayer()); diff --git a/src/game/game.cpp b/src/game/game.cpp index 32038df9703..81238fe68ef 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -5521,7 +5521,7 @@ bool Game::playerYell(std::shared_ptr player, const std::string &text) { } if (player->getAccountType() < account::AccountType::ACCOUNT_TYPE_GAMEMASTER) { - Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_YELLTICKS, 30000, 0); + auto condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_YELLTICKS, 30000, 0); player->addCondition(condition); } diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index b89c7257c63..2d547955eb6 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -230,7 +230,7 @@ void IOLoginDataLoad::loadPlayerConditions(std::shared_ptr player, DBRes PropStream propStream; propStream.init(attr, attrSize); - Condition* condition = Condition::createCondition(propStream); + auto condition = Condition::createCondition(propStream); while (condition) { if (condition->unserialize(propStream)) { player->storedConditionList.push_front(condition); diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index 4c146d50c82..1e634277265 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -227,7 +227,7 @@ bool IOLoginDataSave::savePlayerFirst(std::shared_ptr player) { // serialize conditions PropWriteStream propWriteStream; - for (Condition* condition : player->conditions) { + for (const auto &condition : player->conditions) { if (condition->isPersistent()) { condition->serialize(propWriteStream); propWriteStream.write(CONDITIONATTR_END); diff --git a/src/io/iobestiary.cpp b/src/io/iobestiary.cpp index 7e5d1c9ad55..0797428898b 100644 --- a/src/io/iobestiary.cpp +++ b/src/io/iobestiary.cpp @@ -25,7 +25,7 @@ bool IOBestiary::parseCharmCombat(const std::shared_ptr charm, std::share CombatDamage charmDamage; if (charm->type == CHARM_OFFENSIVE) { if (charm->id == CHARM_CRIPPLE) { - ConditionSpeed* cripple = static_cast(Condition::createCondition(CONDITIONID_COMBAT, CONDITION_PARALYZE, 10000, 0)); + std::shared_ptr cripple = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_PARALYZE, 10000, 0)->static_self_cast(); cripple->setFormulaVars(-1, 81, -1, 81); target->addCondition(cripple); player->sendCancelMessage(charm->cancelMsg); @@ -69,14 +69,14 @@ bool IOBestiary::parseCharmCombat(const std::shared_ptr charm, std::share return true; } case CHARM_ADRENALINE: { - ConditionSpeed* adrenaline = static_cast(Condition::createCondition(CONDITIONID_COMBAT, CONDITION_HASTE, 10000, 0)); + std::shared_ptr adrenaline = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_HASTE, 10000, 0)->static_self_cast(); adrenaline->setFormulaVars(1.5, -0, 1.5, -0); player->addCondition(adrenaline); player->sendCancelMessage(charm->cancelMsg); return false; } case CHARM_NUMB: { - ConditionSpeed* numb = static_cast(Condition::createCondition(CONDITIONID_COMBAT, CONDITION_PARALYZE, 10000, 0)); + std::shared_ptr numb = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_PARALYZE, 10000, 0)->static_self_cast(); numb->setFormulaVars(-1, 81, -1, 81); target->addCondition(numb); player->sendCancelMessage(charm->cancelMsg); diff --git a/src/items/bed.cpp b/src/items/bed.cpp index 2f029cb1eea..6c93e988a05 100644 --- a/src/items/bed.cpp +++ b/src/items/bed.cpp @@ -209,7 +209,7 @@ void BedItem::wakeUp(std::shared_ptr player) { void BedItem::regeneratePlayer(std::shared_ptr player) const { const uint32_t sleptTime = time(nullptr) - sleepStart; - Condition* condition = player->getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT); + std::shared_ptr condition = player->getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT); if (condition != nullptr) { uint32_t regen; if (condition->getTicks() != -1) { diff --git a/src/items/functions/item/item_parse.cpp b/src/items/functions/item/item_parse.cpp index b1d70a0396f..986b1f532b2 100644 --- a/src/items/functions/item/item_parse.cpp +++ b/src/items/functions/item/item_parse.cpp @@ -653,7 +653,7 @@ CombatType_t ItemParse::parseFieldCombatType(std::string lowerStringValue, pugi: return COMBAT_NONE; } -void ItemParse::parseFieldCombatDamage(ConditionDamage* conditionDamage, std::string stringValue, pugi::xml_node attributeNode) { +void ItemParse::parseFieldCombatDamage(std::shared_ptr conditionDamage, std::string stringValue, pugi::xml_node attributeNode) { uint32_t combatTicks = 0; int32_t combatDamage = 0; int32_t combatStart = 0; @@ -697,7 +697,7 @@ void ItemParse::parseFieldCombatDamage(ConditionDamage* conditionDamage, std::st void ItemParse::parseField(const std::string &tmpStrValue, pugi::xml_node attributeNode, pugi::xml_attribute valueAttribute, ItemType &itemType) { if (tmpStrValue == "field") { CombatType_t combatType = COMBAT_NONE; - ConditionDamage* conditionDamage = nullptr; + std::shared_ptr conditionDamage = nullptr; // Parse fields conditions (fire/energy/poison/drown/physical) combatType = parseFieldCombatType(tmpStrValue, valueAttribute); @@ -707,10 +707,10 @@ void ItemParse::parseField(const std::string &tmpStrValue, pugi::xml_node attrib if (conditionDamage) { } - conditionDamage = new ConditionDamage(conditionId, conditionType); + conditionDamage = std::make_shared(conditionId, conditionType); itemType.combatType = combatType; - itemType.conditionDamage.reset(conditionDamage); + itemType.conditionDamage = conditionDamage; parseFieldCombatDamage(conditionDamage, tmpStrValue, attributeNode); diff --git a/src/items/functions/item/item_parse.hpp b/src/items/functions/item/item_parse.hpp index 510129df918..f29fc79971a 100644 --- a/src/items/functions/item/item_parse.hpp +++ b/src/items/functions/item/item_parse.hpp @@ -315,5 +315,5 @@ class ItemParse : public Items { // Parent of the function: static void parseField static std::tuple parseFieldConditions(std::string lowerStringValue, pugi::xml_attribute valueAttribute); static CombatType_t parseFieldCombatType(std::string string, pugi::xml_attribute valueAttribute); - static void parseFieldCombatDamage(ConditionDamage* conditionDamage, std::string stringValue, pugi::xml_node attributeNode); + static void parseFieldCombatDamage(std::shared_ptr conditionDamage, std::string stringValue, pugi::xml_node attributeNode); }; diff --git a/src/items/items.hpp b/src/items/items.hpp index b21dbc7e414..e350d0177cf 100644 --- a/src/items/items.hpp +++ b/src/items/items.hpp @@ -242,7 +242,7 @@ class ItemType { std::string m_primaryType; std::unique_ptr abilities; - std::unique_ptr conditionDamage; + std::shared_ptr conditionDamage; uint32_t levelDoor = 0; uint32_t decayTime = 0; diff --git a/src/lua/creature/movement.cpp b/src/lua/creature/movement.cpp index 800d421c7e6..a011c32343e 100644 --- a/src/lua/creature/movement.cpp +++ b/src/lua/creature/movement.cpp @@ -520,12 +520,12 @@ uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, std::s if (it.abilities) { if (it.abilities->invisible) { - Condition* condition = Condition::createCondition(static_cast(slot), CONDITION_INVISIBLE, -1, 0); + std::shared_ptr condition = Condition::createCondition(static_cast(slot), CONDITION_INVISIBLE, -1, 0); player->addCondition(condition); } if (it.abilities->manaShield) { - Condition* condition = Condition::createCondition(static_cast(slot), CONDITION_MANASHIELD, -1, 0); + std::shared_ptr condition = Condition::createCondition(static_cast(slot), CONDITION_MANASHIELD, -1, 0); player->addCondition(condition); } @@ -537,7 +537,7 @@ uint32_t MoveEvent::EquipItem(const std::shared_ptr moveEvent, std::s player->sendIcons(); if (it.abilities->regeneration) { - Condition* condition = Condition::createCondition(static_cast(slot), CONDITION_REGENERATION, -1, 0); + std::shared_ptr condition = Condition::createCondition(static_cast(slot), CONDITION_REGENERATION, -1, 0); if (it.abilities->getHealthGain() != 0) { condition->setParam(CONDITION_PARAM_HEALTHGAIN, it.abilities->getHealthGain()); diff --git a/src/lua/functions/core/game/global_functions.cpp b/src/lua/functions/core/game/global_functions.cpp index a0f283188ae..ac1b146fd83 100644 --- a/src/lua/functions/core/game/global_functions.cpp +++ b/src/lua/functions/core/game/global_functions.cpp @@ -105,7 +105,7 @@ int GlobalFunctions::luaDoSetCreatureLight(lua_State* L) { uint16_t level = getNumber(L, 2); uint16_t color = getNumber(L, 3); uint32_t time = getNumber(L, 4); - Condition* condition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_LIGHT, time, level | (color << 8)); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_LIGHT, time, level | (color << 8)); creature->addCondition(condition); pushBoolean(L, true); return 1; @@ -449,7 +449,7 @@ int GlobalFunctions::luaDoAreaCombatCondition(lua_State* L) { return 1; } - const Condition* condition = getUserdata(L, 4); + const std::shared_ptr condition = getUserdataShared(L, 4); if (!condition) { reportErrorFunc(getErrorDesc(LUA_ERROR_CONDITION_NOT_FOUND)); pushBoolean(L, false); @@ -487,7 +487,7 @@ int GlobalFunctions::luaDoTargetCombatCondition(lua_State* L) { return 1; } - const Condition* condition = getUserdata(L, 3); + const std::shared_ptr condition = getUserdataShared(L, 3); if (!condition) { reportErrorFunc(getErrorDesc(LUA_ERROR_CONDITION_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/creatures/combat/combat_functions.cpp b/src/lua/functions/creatures/combat/combat_functions.cpp index 889afefb2b8..9a09113bd99 100644 --- a/src/lua/functions/creatures/combat/combat_functions.cpp +++ b/src/lua/functions/creatures/combat/combat_functions.cpp @@ -86,7 +86,7 @@ int CombatFunctions::luaCombatSetArea(lua_State* L) { int CombatFunctions::luaCombatSetCondition(lua_State* L) { // combat:addCondition(condition) - Condition* condition = getUserdata(L, 2); + std::shared_ptr condition = getUserdataShared(L, 2); Combat* combat = getUserdata(L, 1); if (combat && condition) { combat->addCondition(condition->clone()); diff --git a/src/lua/functions/creatures/combat/condition_functions.cpp b/src/lua/functions/creatures/combat/condition_functions.cpp index ac49eb6ffd7..efd468ac3d6 100644 --- a/src/lua/functions/creatures/combat/condition_functions.cpp +++ b/src/lua/functions/creatures/combat/condition_functions.cpp @@ -19,7 +19,7 @@ int ConditionFunctions::luaConditionCreate(lua_State* L) { ConditionId_t conditionId = getNumber(L, 3, CONDITIONID_COMBAT); uint32_t subId = getNumber(L, 4, 0); - Condition* condition = Condition::createCondition(conditionId, conditionType, 0, 0, false, subId); + std::shared_ptr condition = Condition::createCondition(conditionId, conditionType, 0, 0, false, subId); if (condition) { pushUserdata(L, condition); setMetatable(L, -1, "Condition"); @@ -31,17 +31,16 @@ int ConditionFunctions::luaConditionCreate(lua_State* L) { int ConditionFunctions::luaConditionDelete(lua_State* L) { // condition:delete() - Condition** conditionPtr = getRawUserdata(L, 1); + std::shared_ptr* conditionPtr = getRawUserDataShared(L, 1); if (conditionPtr && *conditionPtr) { - delete *conditionPtr; - *conditionPtr = nullptr; + conditionPtr->reset(); } return 0; } int ConditionFunctions::luaConditionGetId(lua_State* L) { // condition:getId() - Condition* condition = getUserdata(L, 1); + std::shared_ptr condition = getUserdataShared(L, 1); if (condition) { lua_pushnumber(L, condition->getId()); } else { @@ -52,7 +51,7 @@ int ConditionFunctions::luaConditionGetId(lua_State* L) { int ConditionFunctions::luaConditionGetSubId(lua_State* L) { // condition:getSubId() - Condition* condition = getUserdata(L, 1); + std::shared_ptr condition = getUserdataShared(L, 1); if (condition) { lua_pushnumber(L, condition->getSubId()); } else { @@ -63,7 +62,7 @@ int ConditionFunctions::luaConditionGetSubId(lua_State* L) { int ConditionFunctions::luaConditionGetType(lua_State* L) { // condition:getType() - Condition* condition = getUserdata(L, 1); + std::shared_ptr condition = getUserdataShared(L, 1); if (condition) { lua_pushnumber(L, condition->getType()); } else { @@ -74,7 +73,7 @@ int ConditionFunctions::luaConditionGetType(lua_State* L) { int ConditionFunctions::luaConditionGetIcons(lua_State* L) { // condition:getIcons() - Condition* condition = getUserdata(L, 1); + std::shared_ptr condition = getUserdataShared(L, 1); if (condition) { lua_pushnumber(L, condition->getIcons()); } else { @@ -85,7 +84,7 @@ int ConditionFunctions::luaConditionGetIcons(lua_State* L) { int ConditionFunctions::luaConditionGetEndTime(lua_State* L) { // condition:getEndTime() - Condition* condition = getUserdata(L, 1); + std::shared_ptr condition = getUserdataShared(L, 1); if (condition) { lua_pushnumber(L, condition->getEndTime()); } else { @@ -96,7 +95,7 @@ int ConditionFunctions::luaConditionGetEndTime(lua_State* L) { int ConditionFunctions::luaConditionClone(lua_State* L) { // condition:clone() - Condition* condition = getUserdata(L, 1); + std::shared_ptr condition = getUserdataShared(L, 1); if (condition) { pushUserdata(L, condition->clone()); setMetatable(L, -1, "Condition"); @@ -108,7 +107,7 @@ int ConditionFunctions::luaConditionClone(lua_State* L) { int ConditionFunctions::luaConditionGetTicks(lua_State* L) { // condition:getTicks() - Condition* condition = getUserdata(L, 1); + std::shared_ptr condition = getUserdataShared(L, 1); if (condition) { lua_pushnumber(L, condition->getTicks()); } else { @@ -120,7 +119,7 @@ int ConditionFunctions::luaConditionGetTicks(lua_State* L) { int ConditionFunctions::luaConditionSetTicks(lua_State* L) { // condition:setTicks(ticks) int32_t ticks = getNumber(L, 2); - Condition* condition = getUserdata(L, 1); + std::shared_ptr condition = getUserdataShared(L, 1); if (condition) { condition->setTicks(ticks); pushBoolean(L, true); @@ -132,7 +131,7 @@ int ConditionFunctions::luaConditionSetTicks(lua_State* L) { int ConditionFunctions::luaConditionSetParameter(lua_State* L) { // condition:setParameter(key, value) - Condition* condition = getUserdata(L, 1); + std::shared_ptr condition = getUserdataShared(L, 1); if (!condition) { lua_pushnil(L); return 1; @@ -156,7 +155,7 @@ int ConditionFunctions::luaConditionSetFormula(lua_State* L) { double maxa = getNumber(L, 4); double minb = getNumber(L, 3); double mina = getNumber(L, 2); - ConditionSpeed* condition = dynamic_cast(getUserdata(L, 1)); + std::shared_ptr condition = getUserdataShared(L, 1)->dynamic_self_cast(); if (condition) { condition->setFormulaVars(mina, minb, maxa, maxb); pushBoolean(L, true); @@ -189,7 +188,7 @@ int ConditionFunctions::luaConditionSetOutfit(lua_State* L) { outfit.lookTypeEx = getNumber(L, 2); } - ConditionOutfit* condition = dynamic_cast(getUserdata(L, 1)); + std::shared_ptr condition = getUserdataShared(L, 1)->dynamic_self_cast(); if (condition) { condition->setOutfit(outfit); pushBoolean(L, true); @@ -204,7 +203,7 @@ int ConditionFunctions::luaConditionAddDamage(lua_State* L) { int32_t value = getNumber(L, 4); int32_t time = getNumber(L, 3); int32_t rounds = getNumber(L, 2); - ConditionDamage* condition = dynamic_cast(getUserdata(L, 1)); + std::shared_ptr condition = getUserdataShared(L, 1)->dynamic_self_cast(); if (condition) { pushBoolean(L, condition->addDamage(rounds, time, value)); } else { diff --git a/src/lua/functions/creatures/combat/condition_functions.hpp b/src/lua/functions/creatures/combat/condition_functions.hpp index 5c2e7a2774d..7357cf9a991 100644 --- a/src/lua/functions/creatures/combat/condition_functions.hpp +++ b/src/lua/functions/creatures/combat/condition_functions.hpp @@ -14,7 +14,7 @@ class ConditionFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "Condition", "", ConditionFunctions::luaConditionCreate); + registerSharedClass(L, "Condition", "", ConditionFunctions::luaConditionCreate); registerMetaMethod(L, "Condition", "__eq", ConditionFunctions::luaUserdataCompare); registerMetaMethod(L, "Condition", "__gc", ConditionFunctions::luaConditionDelete); registerMethod(L, "Condition", "delete", ConditionFunctions::luaConditionDelete); diff --git a/src/lua/functions/creatures/creature_functions.cpp b/src/lua/functions/creatures/creature_functions.cpp index 6b6a02d6430..6257bf1ea25 100644 --- a/src/lua/functions/creatures/creature_functions.cpp +++ b/src/lua/functions/creatures/creature_functions.cpp @@ -645,7 +645,7 @@ int CreatureFunctions::luaCreatureGetCondition(lua_State* L) { ConditionId_t conditionId = getNumber(L, 3, CONDITIONID_COMBAT); uint32_t subId = getNumber(L, 4, 0); - const Condition* condition = creature->getCondition(conditionType, conditionId, subId); + const std::shared_ptr condition = creature->getCondition(conditionType, conditionId, subId); if (condition) { pushUserdata(L, condition); setWeakMetatable(L, -1, "Condition"); @@ -658,7 +658,7 @@ int CreatureFunctions::luaCreatureGetCondition(lua_State* L) { int CreatureFunctions::luaCreatureAddCondition(lua_State* L) { // creature:addCondition(condition) std::shared_ptr creature = getUserdataShared(L, 1); - Condition* condition = getUserdata(L, 2); + std::shared_ptr condition = getUserdataShared(L, 2); if (creature && condition) { pushBoolean(L, creature->addCondition(condition->clone())); } else { @@ -678,7 +678,7 @@ int CreatureFunctions::luaCreatureRemoveCondition(lua_State* L) { ConditionType_t conditionType = getNumber(L, 2); ConditionId_t conditionId = getNumber(L, 3, CONDITIONID_COMBAT); uint32_t subId = getNumber(L, 4, 0); - const Condition* condition = creature->getCondition(conditionType, conditionId, subId); + const std::shared_ptr condition = creature->getCondition(conditionType, conditionId, subId); if (condition) { bool force = getBoolean(L, 5, false); creature->removeCondition(conditionType, conditionId, force); @@ -713,7 +713,7 @@ int CreatureFunctions::luaCreatureIsImmune(lua_State* L) { if (isNumber(L, 2)) { pushBoolean(L, creature->isImmune(getNumber(L, 2))); - } else if (Condition* condition = getUserdata(L, 2)) { + } else if (auto condition = getUserdataShared(L, 2)) { pushBoolean(L, creature->isImmune(condition->getType())); } else { lua_pushnil(L); diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 097018c2ecb..17e9f24a1a9 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -3394,7 +3394,7 @@ void ProtocolGame::sendCyclopediaCharacterGeneralStats() { msg.addByte(player->getSoul()); msg.add(player->getStaminaMinutes()); - Condition* condition = player->getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT); + std::shared_ptr condition = player->getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT); msg.add(condition ? condition->getTicks() / 1000 : 0x00); msg.add(player->getOfflineTrainingTime() / 60 / 1000); msg.add(player->getSpeed()); @@ -7153,7 +7153,7 @@ void ProtocolGame::AddPlayerStats(NetworkMessage &msg) { msg.add(player->getBaseSpeed()); - Condition* condition = player->getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT); + std::shared_ptr condition = player->getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT); msg.add(condition ? condition->getTicks() / 1000 : 0x00); msg.add(player->getOfflineTrainingTime() / 60 / 1000); From 2bbb58babaa928bd250f95b757db9dba56473a4d Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Thu, 21 Sep 2023 19:24:59 -0300 Subject: [PATCH 41/67] rewrite enableCompression --- src/server/network/protocol/protocol.cpp | 33 +++++++++++++----------- src/server/network/protocol/protocol.hpp | 3 ++- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/server/network/protocol/protocol.cpp b/src/server/network/protocol/protocol.cpp index 735e06c949f..d011887adde 100644 --- a/src/server/network/protocol/protocol.cpp +++ b/src/server/network/protocol/protocol.cpp @@ -14,8 +14,6 @@ #include "security/rsa.hpp" #include "game/scheduling/dispatcher.hpp" -Protocol::~Protocol() = default; - void Protocol::onSendMessage(const OutputMessage_ptr &msg) { if (!rawMessages) { uint32_t sendMessageChecksum = 0; @@ -205,20 +203,25 @@ uint32_t Protocol::getIP() const { } void Protocol::enableCompression() { + if (compreesionEnabled) { + return; + } + + int32_t compressionLevel = g_configManager().getNumber(COMPRESSION_LEVEL); + if (compressionLevel <= 0) { + return; + } + + defStream = std::make_unique(); + defStream->zalloc = nullptr; + defStream->zfree = nullptr; + defStream->opaque = nullptr; + + compreesionEnabled = deflateInit2(defStream.get(), compressionLevel, Z_DEFLATED, -15, 9, Z_DEFAULT_STRATEGY) == Z_OK; + if (!compreesionEnabled) { - int32_t compressionLevel = g_configManager().getNumber(COMPRESSION_LEVEL); - if (compressionLevel != 0) { - defStream.reset(new z_stream); - defStream->zalloc = Z_NULL; - defStream->zfree = Z_NULL; - defStream->opaque = Z_NULL; - if (deflateInit2(defStream.get(), compressionLevel, Z_DEFLATED, -15, 9, Z_DEFAULT_STRATEGY) != Z_OK) { - defStream.reset(); - g_logger().error("[Protocol::enableCompression()] - Zlib deflateInit2 error: {}", (defStream->msg ? defStream->msg : " unknown error")); - } else { - compreesionEnabled = true; - } - } + defStream.reset(); + g_logger().error("[Protocol::enableCompression()] - Zlib deflateInit2 error: {}", (defStream->msg ? defStream->msg : " unknown error")); } } diff --git a/src/server/network/protocol/protocol.hpp b/src/server/network/protocol/protocol.hpp index f736c89647d..79c2dcd4451 100644 --- a/src/server/network/protocol/protocol.hpp +++ b/src/server/network/protocol/protocol.hpp @@ -16,7 +16,8 @@ class Protocol : public std::enable_shared_from_this { public: explicit Protocol(Connection_ptr initConnection) : connectionPtr(initConnection) { } - virtual ~Protocol(); + + virtual ~Protocol() = default; // non-copyable Protocol(const Protocol &) = delete; From 74ec60dced529f8002e1198d33715a40dcd72463 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Thu, 21 Sep 2023 20:16:50 -0300 Subject: [PATCH 42/67] operator new to make_unique --- src/creatures/combat/combat.cpp | 12 ++++++------ src/items/item.cpp | 4 ++-- src/items/item.hpp | 4 ++-- src/items/items.hpp | 2 +- src/items/tile.hpp | 8 +++----- src/map/house/house.cpp | 6 ++---- 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index 51389b11f57..26ee27b05be 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -485,32 +485,32 @@ bool Combat::setParam(CombatParam_t param, uint32_t value) { bool Combat::setCallback(CallBackParam_t key) { switch (key) { case CALLBACK_PARAM_LEVELMAGICVALUE: { - params.valueCallback.reset(new ValueCallback(COMBAT_FORMULA_LEVELMAGIC)); + params.valueCallback = std::make_unique(COMBAT_FORMULA_LEVELMAGIC); return true; } case CALLBACK_PARAM_SKILLVALUE: { - params.valueCallback.reset(new ValueCallback(COMBAT_FORMULA_SKILL)); + params.valueCallback = std::make_unique(COMBAT_FORMULA_SKILL); return true; } case CALLBACK_PARAM_TARGETTILE: { - params.tileCallback.reset(new TileCallback()); + params.tileCallback = std::make_unique(); return true; } case CALLBACK_PARAM_TARGETCREATURE: { - params.targetCallback.reset(new TargetCallback()); + params.targetCallback = std::make_unique(); return true; } case CALLBACK_PARAM_CHAINVALUE: { - params.chainCallback.reset(new ChainCallback()); + params.chainCallback = std::make_unique(); return true; } case CALLBACK_PARAM_CHAINPICKER: { - params.chainPickerCallback.reset(new ChainPickerCallback()); + params.chainPickerCallback = std::make_unique(); return true; } } diff --git a/src/items/item.cpp b/src/items/item.cpp index 4d632714133..9d185eacfbc 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -207,7 +207,7 @@ Item::Item(const uint16_t itemId, uint16_t itemCount /*= 0*/) : Item::Item(const std::shared_ptr &i) : Thing(), id(i->id), count(i->count), loadedFromMap(i->loadedFromMap) { if (i->attributePtr) { - attributePtr.reset(new ItemAttribute(*i->attributePtr)); + attributePtr = std::make_unique(*i->attributePtr); } } @@ -219,7 +219,7 @@ std::shared_ptr Item::clone() const { } if (attributePtr) { - item->attributePtr.reset(new ItemAttribute(*attributePtr)); + item->attributePtr = std::make_unique(*attributePtr); } return item; diff --git a/src/items/item.hpp b/src/items/item.hpp index 9febd27a917..b8db280dea8 100644 --- a/src/items/item.hpp +++ b/src/items/item.hpp @@ -159,14 +159,14 @@ class ItemProperties { protected: std::unique_ptr &initAttributePtr() { if (!attributePtr) { - attributePtr.reset(new ItemAttribute()); + attributePtr = std::make_unique(); } return attributePtr; } const std::unique_ptr &initAttributePtr() const { if (!attributePtr) { - std::bit_cast(this)->attributePtr.reset(new ItemAttribute()); + std::bit_cast(this)->attributePtr = std::make_unique(); } return attributePtr; diff --git a/src/items/items.hpp b/src/items/items.hpp index e350d0177cf..d8b76189446 100644 --- a/src/items/items.hpp +++ b/src/items/items.hpp @@ -204,7 +204,7 @@ class ItemType { Abilities &getAbilities() { if (!abilities) { - abilities.reset(new Abilities()); + abilities = std::make_unique(); } return *abilities; } diff --git a/src/items/tile.hpp b/src/items/tile.hpp index 7e9c4973c59..900f16788d8 100644 --- a/src/items/tile.hpp +++ b/src/items/tile.hpp @@ -105,9 +105,7 @@ class Tile : public Cylinder, public SharedObject { static const std::shared_ptr &nullptr_tile; Tile(uint16_t x, uint16_t y, uint8_t z) : tilePos(x, y, z) { } - virtual ~Tile() { - - }; + virtual ~Tile() {}; // non-copyable Tile(const Tile &) = delete; @@ -325,7 +323,7 @@ class StaticTile final : public Tile { } TileItemVector* makeItemList() override { if (!items) { - items.reset(new TileItemVector); + items = std::make_unique(); } return items.get(); } @@ -338,7 +336,7 @@ class StaticTile final : public Tile { } CreatureVector* makeCreatures() override { if (!creatures) { - creatures.reset(new CreatureVector); + creatures = std::make_unique(); } return creatures.get(); } diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index 4b1864d43f5..956c18454cf 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -466,7 +466,6 @@ void AccessList::addPlayer(const std::string &name) { } namespace { - std::shared_ptr getGuildByName(const std::string &name) { uint32_t guildId = IOGuild::getGuildIdByName(name); if (guildId == 0) { @@ -480,7 +479,6 @@ namespace { return IOGuild::loadGuild(guildId); } - } void AccessList::addGuild(const std::string &name) { @@ -544,7 +542,7 @@ void Door::setHouse(House* newHouse) { this->house = newHouse; if (!accessList) { - accessList.reset(new AccessList()); + accessList = std::make_unique(); } } @@ -562,7 +560,7 @@ bool Door::canUse(std::shared_ptr player) { void Door::setAccessList(const std::string &textlist) { if (!accessList) { - accessList.reset(new AccessList()); + accessList = std::make_unique(); } accessList->parseList(textlist); From 44c4a5b6cd650e1fe0a930d8ea597f6d3817c5ff Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Thu, 21 Sep 2023 20:36:16 -0300 Subject: [PATCH 43/67] AreaCombat to unique_ptr --- src/creatures/combat/combat.cpp | 18 ++++++++--------- src/creatures/combat/combat.hpp | 20 +++++++++++-------- src/creatures/monsters/monsters.cpp | 4 ++-- .../functions/core/game/global_functions.cpp | 12 +++++------ .../creatures/combat/combat_functions.cpp | 5 +++-- src/lua/scripts/lua_environment.cpp | 5 ++--- src/lua/scripts/lua_environment.hpp | 4 ++-- 7 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index 26ee27b05be..f14f5eb6e89 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -99,7 +99,7 @@ CombatDamage Combat::getCombatDamage(std::shared_ptr creature, std::sh return damage; } -void Combat::getCombatArea(const Position ¢erPos, const Position &targetPos, const AreaCombat* area, std::forward_list> &list) { +void Combat::getCombatArea(const Position ¢erPos, const Position &targetPos, const std::unique_ptr &area, std::forward_list> &list) { if (targetPos.z >= MAP_MAX_LAYERS) { return; } @@ -977,19 +977,19 @@ bool Combat::doCombat(std::shared_ptr caster, const Position &position if (params.combatType != COMBAT_NONE) { CombatDamage damage = getCombatDamage(caster, nullptr); if (damage.primary.type != COMBAT_MANADRAIN) { - doCombatHealth(caster, position, area.get(), damage, params); + doCombatHealth(caster, position, area, damage, params); } else { - doCombatMana(caster, position, area.get(), damage, params); + doCombatMana(caster, position, area, damage, params); } } else { auto origin = caster != nullptr ? caster->getPosition() : Position(); - CombatFunc(caster, origin, position, area.get(), params, CombatNullFunc, nullptr); + CombatFunc(caster, origin, position, area, params, CombatNullFunc, nullptr); } return true; } -void Combat::CombatFunc(std::shared_ptr caster, const Position &origin, const Position &pos, const AreaCombat* area, const CombatParams ¶ms, CombatFunction func, CombatDamage* data) { +void Combat::CombatFunc(std::shared_ptr caster, const Position &origin, const Position &pos, const std::unique_ptr &area, const CombatParams ¶ms, CombatFunction func, CombatDamage* data) { std::forward_list> tileList; if (caster) { @@ -1193,7 +1193,7 @@ void Combat::doCombatHealth(std::shared_ptr caster, std::shared_ptr caster, const Position &position, const AreaCombat* area, CombatDamage &damage, const CombatParams ¶ms) { +void Combat::doCombatHealth(std::shared_ptr caster, const Position &position, const std::unique_ptr &area, CombatDamage &damage, const CombatParams ¶ms) { if (caster && caster->getPlayer()) { // Critical damage uint16_t chance = caster->getPlayer()->getSkillLevel(SKILL_CRITICAL_HIT_CHANCE) + (uint16_t)damage.criticalChance; @@ -1259,7 +1259,7 @@ void Combat::doCombatMana(std::shared_ptr caster, std::shared_ptr caster, const Position &position, const AreaCombat* area, CombatDamage &damage, const CombatParams ¶ms) { +void Combat::doCombatMana(std::shared_ptr caster, const Position &position, const std::unique_ptr &area, CombatDamage &damage, const CombatParams ¶ms) { if (caster && caster->getPlayer()) { // Critical damage uint16_t chance = caster->getPlayer()->getSkillLevel(SKILL_CRITICAL_HIT_CHANCE) + (uint16_t)damage.criticalChance; @@ -1273,7 +1273,7 @@ void Combat::doCombatMana(std::shared_ptr caster, const Position &posi CombatFunc(caster, origin, position, area, params, CombatManaFunc, &damage); } -void Combat::doCombatCondition(std::shared_ptr caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms) { +void Combat::doCombatCondition(std::shared_ptr caster, const Position &position, const std::unique_ptr &area, const CombatParams ¶ms) { const auto origin = caster ? caster->getPosition() : Position(); CombatFunc(caster, origin, position, area, params, CombatConditionFunc, nullptr); } @@ -1302,7 +1302,7 @@ void Combat::doCombatCondition(std::shared_ptr caster, std::shared_ptr } } -void Combat::doCombatDispel(std::shared_ptr caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms) { +void Combat::doCombatDispel(std::shared_ptr caster, const Position &position, const std::unique_ptr &area, const CombatParams ¶ms) { const auto origin = caster ? caster->getPosition() : Position(); CombatFunc(caster, origin, position, area, params, CombatDispelFunc, nullptr); } diff --git a/src/creatures/combat/combat.hpp b/src/creatures/combat/combat.hpp index a13898865c7..0ba316c6daa 100644 --- a/src/creatures/combat/combat.hpp +++ b/src/creatures/combat/combat.hpp @@ -205,6 +205,10 @@ class AreaCombat { void setupExtArea(const std::list &list, uint32_t rows); void clear(); + std::unique_ptr clone() { + return std::make_unique(*this); + } + private: MatrixArea* createArea(const std::list &list, uint32_t rows); void copyArea(const MatrixArea* input, MatrixArea* output, MatrixOperation_t op) const; @@ -257,18 +261,18 @@ class Combat { Combat &operator=(const Combat &) = delete; static void doCombatHealth(std::shared_ptr caster, std::shared_ptr target, CombatDamage &damage, const CombatParams ¶ms); - static void doCombatHealth(std::shared_ptr caster, const Position &position, const AreaCombat* area, CombatDamage &damage, const CombatParams ¶ms); + static void doCombatHealth(std::shared_ptr caster, const Position &position, const std::unique_ptr &area, CombatDamage &damage, const CombatParams ¶ms); static void doCombatMana(std::shared_ptr caster, std::shared_ptr target, CombatDamage &damage, const CombatParams ¶ms); - static void doCombatMana(std::shared_ptr caster, const Position &position, const AreaCombat* area, CombatDamage &damage, const CombatParams ¶ms); + static void doCombatMana(std::shared_ptr caster, const Position &position, const std::unique_ptr &area, CombatDamage &damage, const CombatParams ¶ms); static void doCombatCondition(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms); - static void doCombatCondition(std::shared_ptr caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms); + static void doCombatCondition(std::shared_ptr caster, const Position &position, const std::unique_ptr &area, const CombatParams ¶ms); static void doCombatDispel(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms); - static void doCombatDispel(std::shared_ptr caster, const Position &position, const AreaCombat* area, const CombatParams ¶ms); + static void doCombatDispel(std::shared_ptr caster, const Position &position, const std::unique_ptr &area, const CombatParams ¶ms); - static void getCombatArea(const Position ¢erPos, const Position &targetPos, const AreaCombat* area, std::forward_list> &list); + static void getCombatArea(const Position ¢erPos, const Position &targetPos, const std::unique_ptr &area, std::forward_list> &list); static bool isInPvpZone(std::shared_ptr attacker, std::shared_ptr target); static bool isProtected(std::shared_ptr attacker, std::shared_ptr target); @@ -290,8 +294,8 @@ class Combat { CallBack* getCallback(CallBackParam_t key); bool setParam(CombatParam_t param, uint32_t value); - void setArea(AreaCombat* newArea) { - this->area.reset(newArea); + void setArea(std::unique_ptr &newArea) { + this->area = std::move(newArea); } bool hasArea() const { return area != nullptr; @@ -333,7 +337,7 @@ class Combat { static void doCombatMana(std::shared_ptr caster, std::shared_ptr target, const Position &origin, CombatDamage &damage, const CombatParams ¶ms); static void doCombatDefault(std::shared_ptr caster, std::shared_ptr target, const Position &origin, const CombatParams ¶ms); - static void CombatFunc(std::shared_ptr caster, const Position &origin, const Position &pos, const AreaCombat* area, const CombatParams ¶ms, CombatFunction func, CombatDamage* data); + static void CombatFunc(std::shared_ptr caster, const Position &origin, const Position &pos, const std::unique_ptr &area, const CombatParams ¶ms, CombatFunction func, CombatDamage* data); static void CombatHealthFunc(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms, CombatDamage* data); static CombatDamage applyImbuementElementalDamage(std::shared_ptr attackerPlayer, std::shared_ptr item, CombatDamage damage); diff --git a/src/creatures/monsters/monsters.cpp b/src/creatures/monsters/monsters.cpp index 072c6463e7d..eb74178c0d0 100644 --- a/src/creatures/monsters/monsters.cpp +++ b/src/creatures/monsters/monsters.cpp @@ -83,7 +83,7 @@ bool Monsters::deserializeSpell(const std::shared_ptr spell, spell if (spell->length > 0) { spell->spread = std::max(0, spell->spread); - AreaCombat* area = new AreaCombat(); + auto area = std::make_unique(); area->setupArea(spell->length, spell->spread); combatPtr->setArea(area); @@ -91,7 +91,7 @@ bool Monsters::deserializeSpell(const std::shared_ptr spell, spell } if (spell->radius > 0) { - AreaCombat* area = new AreaCombat(); + auto area = std::make_unique(); area->setupArea(spell->radius); combatPtr->setArea(area); } diff --git a/src/lua/functions/core/game/global_functions.cpp b/src/lua/functions/core/game/global_functions.cpp index ac1b146fd83..e0a2ddcc710 100644 --- a/src/lua/functions/core/game/global_functions.cpp +++ b/src/lua/functions/core/game/global_functions.cpp @@ -71,7 +71,6 @@ int GlobalFunctions::luaDoPlayerAddItem(lua_State* L) { ReturnValue ret = g_game().internalPlayerAddItem(player, newItem, canDropOnMap); if (ret != RETURNVALUE_NOERROR) { - pushBoolean(L, false); return 1; } @@ -176,7 +175,6 @@ int GlobalFunctions::luaDoAddContainerItem(lua_State* L) { ReturnValue ret = g_game().internalAddItem(container, newItem); if (ret != RETURNVALUE_NOERROR) { - pushBoolean(L, false); return 1; } @@ -250,7 +248,7 @@ int GlobalFunctions::luaCreateCombatArea(lua_State* L) { } uint32_t areaId = g_luaEnvironment().createAreaObject(env->getScriptInterface()); - AreaCombat* area = g_luaEnvironment().getAreaObject(areaId); + const auto &area = g_luaEnvironment().getAreaObject(areaId); int parameters = lua_gettop(L); if (parameters >= 2) { @@ -287,7 +285,7 @@ int GlobalFunctions::luaDoAreaCombatHealth(lua_State* L) { } uint32_t areaId = getNumber(L, 4); - const AreaCombat* area = g_luaEnvironment().getAreaObject(areaId); + const auto &area = g_luaEnvironment().getAreaObject(areaId); if (area || areaId == 0) { CombatType_t combatType = getNumber(L, 2); @@ -372,7 +370,7 @@ int GlobalFunctions::luaDoAreaCombatMana(lua_State* L) { } uint32_t areaId = getNumber(L, 3); - const AreaCombat* area = g_luaEnvironment().getAreaObject(areaId); + const auto &area = g_luaEnvironment().getAreaObject(areaId); if (area || areaId == 0) { CombatParams params; params.impactEffect = getNumber(L, 6); @@ -457,7 +455,7 @@ int GlobalFunctions::luaDoAreaCombatCondition(lua_State* L) { } uint32_t areaId = getNumber(L, 3); - const AreaCombat* area = g_luaEnvironment().getAreaObject(areaId); + const auto &area = g_luaEnvironment().getAreaObject(areaId); if (area || areaId == 0) { CombatParams params; params.impactEffect = getNumber(L, 5); @@ -512,7 +510,7 @@ int GlobalFunctions::luaDoAreaCombatDispel(lua_State* L) { } uint32_t areaId = getNumber(L, 3); - const AreaCombat* area = g_luaEnvironment().getAreaObject(areaId); + const auto &area = g_luaEnvironment().getAreaObject(areaId); if (area || areaId == 0) { CombatParams params; params.impactEffect = getNumber(L, 5); diff --git a/src/lua/functions/creatures/combat/combat_functions.cpp b/src/lua/functions/creatures/combat/combat_functions.cpp index 9a09113bd99..0349456fd94 100644 --- a/src/lua/functions/creatures/combat/combat_functions.cpp +++ b/src/lua/functions/creatures/combat/combat_functions.cpp @@ -67,7 +67,7 @@ int CombatFunctions::luaCombatSetArea(lua_State* L) { return 1; } - const AreaCombat* area = g_luaEnvironment().getAreaObject(getNumber(L, 2)); + const std::unique_ptr &area = g_luaEnvironment().getAreaObject(getNumber(L, 2)); if (!area) { reportErrorFunc(getErrorDesc(LUA_ERROR_AREA_NOT_FOUND)); lua_pushnil(L); @@ -76,7 +76,8 @@ int CombatFunctions::luaCombatSetArea(lua_State* L) { Combat* combat = getUserdata(L, 1); if (combat) { - combat->setArea(new AreaCombat(*area)); + auto areaClone = area->clone(); + combat->setArea(areaClone); pushBoolean(L, true); } else { lua_pushnil(L); diff --git a/src/lua/scripts/lua_environment.cpp b/src/lua/scripts/lua_environment.cpp index bf4a0377d51..869f3952a8c 100644 --- a/src/lua/scripts/lua_environment.cpp +++ b/src/lua/scripts/lua_environment.cpp @@ -117,7 +117,7 @@ void LuaEnvironment::clearCombatObjects(LuaScriptInterface* interface) { combatMap.clear(); } -AreaCombat* LuaEnvironment::getAreaObject(uint32_t id) const { +const std::unique_ptr &LuaEnvironment::getAreaObject(uint32_t id) const { auto it = areaMap.find(id); if (it == areaMap.end()) { return nullptr; @@ -126,7 +126,7 @@ AreaCombat* LuaEnvironment::getAreaObject(uint32_t id) const { } uint32_t LuaEnvironment::createAreaObject(LuaScriptInterface* interface) { - areaMap[++lastAreaId] = new AreaCombat; + areaMap[++lastAreaId] = std::make_unique(); areaIdMap[interface].push_back(lastAreaId); return lastAreaId; } @@ -140,7 +140,6 @@ void LuaEnvironment::clearAreaObjects(LuaScriptInterface* interface) { for (uint32_t id : it->second) { auto itt = areaMap.find(id); if (itt != areaMap.end()) { - delete itt->second; areaMap.erase(itt); } } diff --git a/src/lua/scripts/lua_environment.hpp b/src/lua/scripts/lua_environment.hpp index 91481d208cb..216abb8ec78 100644 --- a/src/lua/scripts/lua_environment.hpp +++ b/src/lua/scripts/lua_environment.hpp @@ -75,7 +75,7 @@ class LuaEnvironment : public LuaScriptInterface { weaponMap.clear(); } - AreaCombat* getAreaObject(uint32_t id) const; + const std::unique_ptr &getAreaObject(uint32_t id) const; uint32_t createAreaObject(LuaScriptInterface* interface); void clearAreaObjects(LuaScriptInterface* interface); static bool isShuttingDown() { @@ -90,7 +90,7 @@ class LuaEnvironment : public LuaScriptInterface { phmap::flat_hash_map timerEvents; uint32_t lastEventTimerId = 1; - phmap::flat_hash_map areaMap; + phmap::flat_hash_map> areaMap; phmap::flat_hash_map> areaIdMap; uint32_t lastAreaId = 0; From f8914e540f77e36a1598526a9abb95c5b62c5f5b Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Thu, 21 Sep 2023 21:05:14 -0300 Subject: [PATCH 44/67] AreaCombat and MatrixArea to unique_ptr --- src/creatures/combat/combat.cpp | 64 +++++++++++++---------------- src/creatures/combat/combat.hpp | 19 ++++++--- src/lua/scripts/lua_environment.cpp | 4 +- 3 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index f14f5eb6e89..96be730f79e 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -1770,21 +1770,18 @@ bool ChainPickerCallback::onChainCombat(std::shared_ptr creature, std: //**********************************************************// void AreaCombat::clear() { - for (const auto &it : areas) { - delete it.second; - } areas.clear(); } AreaCombat::AreaCombat(const AreaCombat &rhs) { hasExtArea = rhs.hasExtArea; for (const auto &it : rhs.areas) { - areas[it.first] = new MatrixArea(*it.second); + areas[it.first] = it.second->clone(); } } void AreaCombat::getList(const Position ¢erPos, const Position &targetPos, std::forward_list> &list) const { - const MatrixArea* area = getArea(centerPos, targetPos); + const std::unique_ptr &area = getArea(centerPos, targetPos); if (!area) { return; } @@ -1806,7 +1803,7 @@ void AreaCombat::getList(const Position ¢erPos, const Position &targetPos, s } } -void AreaCombat::copyArea(const MatrixArea* input, MatrixArea* output, MatrixOperation_t op) const { +void AreaCombat::copyArea(const std::unique_ptr &input, const std::unique_ptr &output, MatrixOperation_t op) const { uint32_t centerY, centerX; input->getCenter(centerY, centerX); @@ -1887,7 +1884,7 @@ void AreaCombat::copyArea(const MatrixArea* input, MatrixArea* output, MatrixOpe } } -MatrixArea* AreaCombat::createArea(const std::list &list, uint32_t rows) { +std::unique_ptr AreaCombat::createArea(const std::list &list, uint32_t rows) { uint32_t cols; if (rows == 0) { cols = 0; @@ -1895,7 +1892,7 @@ MatrixArea* AreaCombat::createArea(const std::list &list, uint32_t row cols = list.size() / rows; } - MatrixArea* area = new MatrixArea(rows, cols); + auto area = std::make_unique(rows, cols); uint32_t x = 0; uint32_t y = 0; @@ -1920,27 +1917,23 @@ MatrixArea* AreaCombat::createArea(const std::list &list, uint32_t row } void AreaCombat::setupArea(const std::list &list, uint32_t rows) { - MatrixArea* area = createArea(list, rows); + auto northArea = createArea(list, rows); - // NORTH - areas[DIRECTION_NORTH] = area; + const uint32_t maxOutput = std::max(northArea->getCols(), northArea->getRows()) * 2; - uint32_t maxOutput = std::max(area->getCols(), area->getRows()) * 2; + auto southArea = std::make_unique(maxOutput, maxOutput); + copyArea(northArea, southArea, MATRIXOPERATION_ROTATE180); - // SOUTH - MatrixArea* southArea = new MatrixArea(maxOutput, maxOutput); - copyArea(area, southArea, MATRIXOPERATION_ROTATE180); - areas[DIRECTION_SOUTH] = southArea; + auto eastArea = std::make_unique(maxOutput, maxOutput); + copyArea(northArea, eastArea, MATRIXOPERATION_ROTATE90); - // EAST - MatrixArea* eastArea = new MatrixArea(maxOutput, maxOutput); - copyArea(area, eastArea, MATRIXOPERATION_ROTATE90); - areas[DIRECTION_EAST] = eastArea; + auto westArea = std::make_unique(maxOutput, maxOutput); + copyArea(northArea, westArea, MATRIXOPERATION_ROTATE270); - // WEST - MatrixArea* westArea = new MatrixArea(maxOutput, maxOutput); - copyArea(area, westArea, MATRIXOPERATION_ROTATE270); - areas[DIRECTION_WEST] = westArea; + areas[DIRECTION_NORTH] = std::move(northArea); + areas[DIRECTION_SOUTH] = std::move(southArea); + areas[DIRECTION_EAST] = std::move(eastArea); + areas[DIRECTION_WEST] = std::move(westArea); } void AreaCombat::setupArea(int32_t length, int32_t spread) { @@ -2017,27 +2010,28 @@ void AreaCombat::setupExtArea(const std::list &list, uint32_t rows) { } hasExtArea = true; - MatrixArea* area = createArea(list, rows); // NORTH-WEST - areas[DIRECTION_NORTHWEST] = area; + auto nwArea = createArea(list, rows); - uint32_t maxOutput = std::max(area->getCols(), area->getRows()) * 2; + const uint32_t maxOutput = std::max(nwArea->getCols(), nwArea->getRows()) * 2; // NORTH-EAST - MatrixArea* neArea = new MatrixArea(maxOutput, maxOutput); - copyArea(area, neArea, MATRIXOPERATION_MIRROR); - areas[DIRECTION_NORTHEAST] = neArea; + auto neArea = std::make_unique(maxOutput, maxOutput); + copyArea(nwArea, neArea, MATRIXOPERATION_MIRROR); // SOUTH-WEST - MatrixArea* swArea = new MatrixArea(maxOutput, maxOutput); - copyArea(area, swArea, MATRIXOPERATION_FLIP); - areas[DIRECTION_SOUTHWEST] = swArea; + auto swArea = std::make_unique(maxOutput, maxOutput); + copyArea(nwArea, swArea, MATRIXOPERATION_FLIP); // SOUTH-EAST - MatrixArea* seArea = new MatrixArea(maxOutput, maxOutput); + auto seArea = std::make_unique(maxOutput, maxOutput); copyArea(swArea, seArea, MATRIXOPERATION_MIRROR); - areas[DIRECTION_SOUTHEAST] = seArea; + + areas[DIRECTION_NORTHWEST] = std::move(nwArea); + areas[DIRECTION_SOUTHWEST] = std::move(swArea); + areas[DIRECTION_NORTHEAST] = std::move(neArea); + areas[DIRECTION_SOUTHEAST] = std::move(seArea); } //**********************************************************// diff --git a/src/creatures/combat/combat.hpp b/src/creatures/combat/combat.hpp index 0ba316c6daa..56096b9fd71 100644 --- a/src/creatures/combat/combat.hpp +++ b/src/creatures/combat/combat.hpp @@ -19,6 +19,9 @@ class Creature; class Item; class Spell; class Player; +class MatrixArea; + +static const std::unique_ptr &MatrixAreaNull {}; // for luascript callback class ValueCallback final : public CallBack { @@ -138,6 +141,10 @@ class MatrixArea { delete[] data_; } + std::unique_ptr clone() const { + return std::make_unique(*this); + } + // non-assignable MatrixArea &operator=(const MatrixArea &) = delete; @@ -205,15 +212,15 @@ class AreaCombat { void setupExtArea(const std::list &list, uint32_t rows); void clear(); - std::unique_ptr clone() { + std::unique_ptr clone() const { return std::make_unique(*this); } private: - MatrixArea* createArea(const std::list &list, uint32_t rows); - void copyArea(const MatrixArea* input, MatrixArea* output, MatrixOperation_t op) const; + std::unique_ptr createArea(const std::list &list, uint32_t rows); + void copyArea(const std::unique_ptr &input, const std::unique_ptr &output, MatrixOperation_t op) const; - MatrixArea* getArea(const Position ¢erPos, const Position &targetPos) const { + const std::unique_ptr &getArea(const Position ¢erPos, const Position &targetPos) const { int32_t dx = Position::getOffsetX(targetPos, centerPos); int32_t dy = Position::getOffsetY(targetPos, centerPos); @@ -242,13 +249,13 @@ class AreaCombat { auto it = areas.find(dir); if (it == areas.end()) { - return nullptr; + return MatrixAreaNull; } return it->second; } - std::map areas; + std::map> areas; bool hasExtArea = false; }; diff --git a/src/lua/scripts/lua_environment.cpp b/src/lua/scripts/lua_environment.cpp index 869f3952a8c..717ce36ae48 100644 --- a/src/lua/scripts/lua_environment.cpp +++ b/src/lua/scripts/lua_environment.cpp @@ -16,6 +16,8 @@ bool LuaEnvironment::shuttingDown = false; +static const std::unique_ptr &AreaCombatNull {}; + LuaEnvironment::LuaEnvironment() : LuaScriptInterface("Main Interface") { } @@ -120,7 +122,7 @@ void LuaEnvironment::clearCombatObjects(LuaScriptInterface* interface) { const std::unique_ptr &LuaEnvironment::getAreaObject(uint32_t id) const { auto it = areaMap.find(id); if (it == areaMap.end()) { - return nullptr; + return AreaCombatNull; } return it->second; } From aad6e2026b7a6024eb85815ebe6fdeb7921c1552 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Thu, 21 Sep 2023 21:22:29 -0300 Subject: [PATCH 45/67] PreySlot to unique_ptr --- src/creatures/combat/combat.cpp | 4 +-- src/creatures/players/player.cpp | 15 ++--------- src/creatures/players/player.hpp | 27 +++++++++---------- src/io/functions/iologindata_load_player.cpp | 4 +-- src/io/functions/iologindata_save_player.cpp | 3 +-- src/io/ioprey.cpp | 4 +-- src/io/ioprey.hpp | 2 ++ .../creatures/player/player_functions.cpp | 12 +++++---- src/server/network/protocol/protocolgame.cpp | 5 ++-- src/server/network/protocol/protocolgame.hpp | 4 +-- 10 files changed, 34 insertions(+), 46 deletions(-) diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index 96be730f79e..30b0208ad0a 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -588,7 +588,7 @@ void Combat::CombatHealthFunc(std::shared_ptr caster, std::shared_ptr< // Player attacking monster if (attackerPlayer && targetMonster) { - const PreySlot* slot = attackerPlayer->getPreyWithMonster(targetMonster->getRaceId()); + const std::unique_ptr &slot = attackerPlayer->getPreyWithMonster(targetMonster->getRaceId()); if (slot && slot->isOccupied() && slot->bonus == PreyBonus_Damage && slot->bonusTimeLeft > 0) { damage.primary.value += static_cast(std::ceil((damage.primary.value * slot->bonusPercentage) / 100)); damage.secondary.value += static_cast(std::ceil((damage.secondary.value * slot->bonusPercentage) / 100)); @@ -597,7 +597,7 @@ void Combat::CombatHealthFunc(std::shared_ptr caster, std::shared_ptr< // Monster attacking player if (attackerMonster && targetPlayer) { - const PreySlot* slot = targetPlayer->getPreyWithMonster(attackerMonster->getRaceId()); + const std::unique_ptr &slot = targetPlayer->getPreyWithMonster(attackerMonster->getRaceId()); if (slot && slot->isOccupied() && slot->bonus == PreyBonus_Defense && slot->bonusTimeLeft > 0) { damage.primary.value -= static_cast(std::ceil((damage.primary.value * slot->bonusPercentage) / 100)); damage.secondary.value -= static_cast(std::ceil((damage.secondary.value * slot->bonusPercentage) / 100)); diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 327183ef970..74bbf1ae823 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -2714,7 +2714,6 @@ void Player::death(std::shared_ptr lastHitCreature) { condition->endCondition(static_self_cast()); onEndCondition(condition->getType()); - } else { ++it; } @@ -2730,7 +2729,6 @@ void Player::death(std::shared_ptr lastHitCreature) { condition->endCondition(static_self_cast()); onEndCondition(condition->getType()); - } else { ++it; } @@ -6343,22 +6341,16 @@ void Player::initializePrey() { slot->reloadMonsterGrid(getPreyBlackList(), getLevel()); } - if (!setPreySlotClass(std::move(slot))) { - slot.reset(); - } + setPreySlotClass(slot); } } } void Player::removePreySlotById(PreySlot_t slotid) { - auto it = std::remove_if(preys.begin(), preys.end(), [slotid](const PreySlot* preyIt) { + auto it = std::remove_if(preys.begin(), preys.end(), [slotid](const std::unique_ptr &preyIt) { return preyIt->id == slotid; }); - for (auto i = it; i != preys.end(); ++i) { - delete *i; - } - preys.erase(it, preys.end()); } @@ -7384,15 +7376,12 @@ void Player::registerForgeHistoryDescription(ForgeHistory history) { ); } else if (history.actionType == ForgeConversion_t::FORGE_ACTION_DUSTTOSLIVERS) { detailsResponse << fmt::format("Converted {:d} dust to {:d} slivers.", history.cost, history.gained); - } else if (history.actionType == ForgeConversion_t::FORGE_ACTION_SLIVERSTOCORES) { history.actionType = ForgeConversion_t::FORGE_ACTION_DUSTTOSLIVERS; detailsResponse << fmt::format("Converted {:d} slivers to {:d} exalted core.", history.cost, history.gained); - } else if (history.actionType == ForgeConversion_t::FORGE_ACTION_INCREASELIMIT) { history.actionType = ForgeConversion_t::FORGE_ACTION_DUSTTOSLIVERS; detailsResponse << fmt::format("Spent {:d} dust to increase the dust limit to {:d}.", history.cost, history.gained + 1); - } else { detailsResponse << "(unknown)"; } diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index b6751e9b034..3e0772b4dea 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -491,7 +491,6 @@ class Player final : public Creature, public Cylinder, public Bankable { return inMarket; } void setSpecialMenuAvailable(bool supplyStashBool, bool marketMenuBool, bool depotSearchBool) { - // Closing depot search when player have special container disabled and it's still open. if (isDepotSearchOpen() && !depotSearchBool && depotSearch) { depotSearchOnItem = { 0, 0 }; @@ -2042,7 +2041,7 @@ class Player final : public Creature, public Cylinder, public Bankable { void sendPreyData() const { if (client) { - for (const PreySlot* slot : preys) { + for (const std::unique_ptr &slot : preys) { client->sendPreyData(slot); } @@ -2050,7 +2049,7 @@ class Player final : public Creature, public Cylinder, public Bankable { } } - void sendPreyTimeLeft(const PreySlot* slot) const { + void sendPreyTimeLeft(const std::unique_ptr &slot) const { if (g_configManager().getBoolean(PREY_ENABLED) && client) { client->sendPreyTimeLeft(slot); } @@ -2063,23 +2062,23 @@ class Player final : public Creature, public Cylinder, public Bankable { } } - PreySlot* getPreySlotById(PreySlot_t slotid) { - if (auto it = std::find_if(preys.begin(), preys.end(), [slotid](const PreySlot* preyIt) { + const std::unique_ptr &getPreySlotById(PreySlot_t slotid) { + if (auto it = std::find_if(preys.begin(), preys.end(), [slotid](const std::unique_ptr &preyIt) { return preyIt->id == slotid; }); it != preys.end()) { return *it; } - return nullptr; + return PreySlotNull; } - bool setPreySlotClass(std::unique_ptr slot) { + bool setPreySlotClass(std::unique_ptr &slot) { if (getPreySlotById(slot->id)) { return false; } - preys.emplace_back(slot.release()); + preys.emplace_back(std::move(slot)); return true; } @@ -2112,7 +2111,7 @@ class Player final : public Creature, public Cylinder, public Bankable { std::vector getPreyBlackList() const { std::vector rt; - for (const PreySlot* slot : preys) { + for (const std::unique_ptr &slot : preys) { if (slot) { if (slot->isOccupied()) { rt.push_back(slot->selectedRaceId); @@ -2126,19 +2125,19 @@ class Player final : public Creature, public Cylinder, public Bankable { return rt; } - PreySlot* getPreyWithMonster(uint16_t raceId) const { + const std::unique_ptr &getPreyWithMonster(uint16_t raceId) const { if (!g_configManager().getBoolean(PREY_ENABLED)) { - return nullptr; + return PreySlotNull; } - if (auto it = std::find_if(preys.begin(), preys.end(), [raceId](const PreySlot* it) { + if (auto it = std::find_if(preys.begin(), preys.end(), [raceId](const std::unique_ptr &it) { return it->selectedRaceId == raceId; }); it != preys.end()) { return *it; } - return nullptr; + return PreySlotNull; } // Task hunting system @@ -2593,7 +2592,7 @@ class Player final : public Creature, public Cylinder, public Bankable { std::vector outfits; std::vector familiars; - std::vector preys; + std::vector> preys; std::vector taskHunting; GuildWarVector guildWarVector; diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index 2d547955eb6..7cd6b984d76 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -586,7 +586,6 @@ void IOLoginDataLoad::loadPlayerDepotItems(std::shared_ptr player, DBRes std::ostringstream query; query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_depotitems` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC"; if ((result = db.storeQuery(query.str()))) { - loadItems(depotItems, result, player); for (ItemsMap::const_reverse_iterator it = depotItems.rbegin(), end = depotItems.rend(); it != end; ++it) { const std::pair, int32_t> &pair = it->second; @@ -625,7 +624,6 @@ void IOLoginDataLoad::loadPlayerInboxItems(std::shared_ptr player, DBRes std::ostringstream query; query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_inboxitems` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC"; if ((result = db.storeQuery(query.str()))) { - ItemsMap inboxItems; loadItems(inboxItems, result, player); @@ -725,7 +723,7 @@ void IOLoginDataLoad::loadPlayerPreyClass(std::shared_ptr player, DBResu slot->raceIdList.push_back(raceId); } - player->setPreySlotClass(std::move(slot)); + player->setPreySlotClass(slot); } while (result->next()); } } diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index 1e634277265..257d2577cb1 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -586,8 +586,7 @@ bool IOLoginDataSave::savePlayerPreyClass(std::shared_ptr player) { if (g_configManager().getBoolean(PREY_ENABLED)) { std::ostringstream query; for (uint8_t slotId = PreySlot_First; slotId <= PreySlot_Last; slotId++) { - PreySlot* slot = player->getPreySlotById(static_cast(slotId)); - if (slot) { + if (const auto &slot = player->getPreySlotById(static_cast(slotId))) { query.str(std::string()); query << "INSERT INTO player_prey (`player_id`, `slot`, `state`, `raceid`, `option`, `bonus_type`, `bonus_rarity`, `bonus_percentage`, `bonus_time`, `free_reroll`, `monster_list`) " << "VALUES (" << player->getGUID() << ", " diff --git a/src/io/ioprey.cpp b/src/io/ioprey.cpp index 449383a1b87..20b6faacc8e 100644 --- a/src/io/ioprey.cpp +++ b/src/io/ioprey.cpp @@ -252,7 +252,7 @@ void IOPrey::CheckPlayerPreys(std::shared_ptr player, uint8_t amount) co } for (uint8_t slotId = PreySlot_First; slotId <= PreySlot_Last; slotId++) { - if (PreySlot* slot = player->getPreySlotById(static_cast(slotId)); + if (const auto &slot = player->getPreySlotById(static_cast(slotId)); slot && slot->isOccupied()) { if (slot->bonusTimeLeft <= amount) { if (slot->option == PreyOption_AutomaticReroll) { @@ -290,7 +290,7 @@ void IOPrey::CheckPlayerPreys(std::shared_ptr player, uint8_t amount) co } void IOPrey::ParsePreyAction(std::shared_ptr player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const { - PreySlot* slot = player->getPreySlotById(slotId); + const auto &slot = player->getPreySlotById(slotId); if (!slot || slot->state == PreyDataState_Locked) { player->sendMessageDialog("To unlock this prey slot first you must buy it on store."); return; diff --git a/src/io/ioprey.hpp b/src/io/ioprey.hpp index 5885615d225..629ad3fc0dd 100644 --- a/src/io/ioprey.hpp +++ b/src/io/ioprey.hpp @@ -137,6 +137,8 @@ class PreySlot { int64_t freeRerollTimeStamp = 0; }; +static const std::unique_ptr &PreySlotNull {}; + class TaskHuntingSlot { public: TaskHuntingSlot() = default; diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 8c8c76180e2..1dd9b3d9caa 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -397,7 +397,7 @@ int PlayerFunctions::luaPlayerGetPreyCards(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyExperiencePercentage(lua_State* L) { // player:getPreyExperiencePercentage(raceId) if (std::shared_ptr player = getUserdataShared(L, 1)) { - if (const PreySlot* slot = player->getPreyWithMonster(getNumber(L, 2, 0)); + if (const std::unique_ptr &slot = player->getPreyWithMonster(getNumber(L, 2, 0)); slot && slot->isOccupied() && slot->bonus == PreyBonus_Experience && slot->bonusTimeLeft > 0) { lua_pushnumber(L, static_cast(100 + slot->bonusPercentage)); } else { @@ -447,7 +447,7 @@ int PlayerFunctions::luaPlayerAddTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyLootPercentage(lua_State* L) { // player:getPreyLootPercentage(raceid) if (std::shared_ptr player = getUserdataShared(L, 1)) { - if (const PreySlot* slot = player->getPreyWithMonster(getNumber(L, 2, 0)); + if (const std::unique_ptr &slot = player->getPreyWithMonster(getNumber(L, 2, 0)); slot && slot->isOccupied() && slot->bonus == PreyBonus_Loot) { lua_pushnumber(L, slot->bonusPercentage); } else { @@ -462,8 +462,10 @@ int PlayerFunctions::luaPlayerGetPreyLootPercentage(lua_State* L) { int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { // get: player:preyThirdSlot() set: player:preyThirdSlot(bool) if (std::shared_ptr player = getUserdataShared(L, 1); - PreySlot* slot = player->getPreySlotById(PreySlot_Three)) { - if (lua_gettop(L) == 1) { + const auto &slot = player->getPreySlotById(PreySlot_Three)) { + if (!slot) { + lua_pushnil(L); + } else if (lua_gettop(L) == 1) { pushBoolean(L, slot->state != PreyDataState_Locked); } else { if (getBoolean(L, 2, false)) { @@ -480,6 +482,7 @@ int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { } else { lua_pushnil(L); } + return 1; } @@ -1810,7 +1813,6 @@ int PlayerFunctions::luaPlayerAddItem(lua_State* L) { ReturnValue ret = g_game().internalPlayerAddItem(player, item, canDropOnMap, slot); if (ret != RETURNVALUE_NOERROR) { - if (!hasTable) { lua_pushnil(L); } diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 17e9f24a1a9..9b9d06ad754 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -232,7 +232,6 @@ namespace { msg.addString(toStartCaseWithSpace(magic_enum::enum_name(value).data())); } } - } // namespace ProtocolGame::ProtocolGame(Connection_ptr initConnection) : @@ -6809,7 +6808,7 @@ void ProtocolGame::sendUseItemCooldown(uint32_t time) { writeToOutputBuffer(msg); } -void ProtocolGame::sendPreyTimeLeft(const PreySlot* slot) { +void ProtocolGame::sendPreyTimeLeft(const std::unique_ptr &slot) { if (!player || !slot) { return; } @@ -6823,7 +6822,7 @@ void ProtocolGame::sendPreyTimeLeft(const PreySlot* slot) { writeToOutputBuffer(msg); } -void ProtocolGame::sendPreyData(const PreySlot* slot) { +void ProtocolGame::sendPreyData(const std::unique_ptr &slot) { if (!player) { return; } diff --git a/src/server/network/protocol/protocolgame.hpp b/src/server/network/protocol/protocolgame.hpp index 62b4c615d6b..264e09d6dcf 100644 --- a/src/server/network/protocol/protocolgame.hpp +++ b/src/server/network/protocol/protocolgame.hpp @@ -374,8 +374,8 @@ class ProtocolGame final : public Protocol { void sendCoinBalance(); - void sendPreyTimeLeft(const PreySlot* slot); - void sendPreyData(const PreySlot* slot); + void sendPreyTimeLeft(const std::unique_ptr& slot); + void sendPreyData(const std::unique_ptr& slot); void sendPreyPrices(); // tiles From b2c18213a8bb640c9e21f36de115b8b912c03493 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 22 Sep 2023 00:23:18 +0000 Subject: [PATCH 46/67] Code format - (Clang-format) --- src/server/network/protocol/protocolgame.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/network/protocol/protocolgame.hpp b/src/server/network/protocol/protocolgame.hpp index 264e09d6dcf..5aa78e7db1c 100644 --- a/src/server/network/protocol/protocolgame.hpp +++ b/src/server/network/protocol/protocolgame.hpp @@ -374,8 +374,8 @@ class ProtocolGame final : public Protocol { void sendCoinBalance(); - void sendPreyTimeLeft(const std::unique_ptr& slot); - void sendPreyData(const std::unique_ptr& slot); + void sendPreyTimeLeft(const std::unique_ptr &slot); + void sendPreyData(const std::unique_ptr &slot); void sendPreyPrices(); // tiles From 89b12a666d8f922c0e63918795f1a68ff35acb9b Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 21 Sep 2023 17:37:00 -0700 Subject: [PATCH 47/67] fix: crash when starting a party --- src/creatures/players/grouping/party.cpp | 10 ++++++---- src/creatures/players/grouping/party.hpp | 2 +- src/game/game.cpp | 2 +- src/lua/functions/creatures/player/party_functions.cpp | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/creatures/players/grouping/party.cpp b/src/creatures/players/grouping/party.cpp index ac9986658d5..57cfab4da75 100644 --- a/src/creatures/players/grouping/party.cpp +++ b/src/creatures/players/grouping/party.cpp @@ -15,12 +15,14 @@ #include "lua/callbacks/event_callback.hpp" #include "lua/callbacks/events_callbacks.hpp" -Party::Party(std::shared_ptr initLeader) : - m_leader(initLeader) { - initLeader->setParty(getParty()); +std::shared_ptr Party::create(std::shared_ptr leader) { + auto party = std::make_shared(); + party->m_leader = leader; + leader->setParty(party); if (g_configManager().getBoolean(PARTY_AUTO_SHARE_EXPERIENCE)) { - setSharedExperience(initLeader, true); + party->setSharedExperience(leader, true); } + return party; } void Party::disband() { diff --git a/src/creatures/players/grouping/party.hpp b/src/creatures/players/grouping/party.hpp index 34e1c6e26b7..e7bc2c2fc55 100644 --- a/src/creatures/players/grouping/party.hpp +++ b/src/creatures/players/grouping/party.hpp @@ -26,7 +26,7 @@ class Party; class Party : public SharedObject { public: - explicit Party(std::shared_ptr leader); + static std::shared_ptr create(std::shared_ptr leader); std::shared_ptr getParty() { return static_self_cast(); diff --git a/src/game/game.cpp b/src/game/game.cpp index 81238fe68ef..0d50dd1cf6c 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -7585,7 +7585,7 @@ void Game::playerInviteToParty(uint32_t playerId, uint32_t invitedId) { std::shared_ptr party = player->getParty(); if (!party) { - party = std::make_shared(player); + party = Party::create(player); } else if (party->getLeader() != player) { return; } diff --git a/src/lua/functions/creatures/player/party_functions.cpp b/src/lua/functions/creatures/player/party_functions.cpp index 36c133a14cf..6b5872d836e 100644 --- a/src/lua/functions/creatures/player/party_functions.cpp +++ b/src/lua/functions/creatures/player/party_functions.cpp @@ -24,7 +24,7 @@ int32_t PartyFunctions::luaPartyCreate(lua_State* L) { std::shared_ptr party = player->getParty(); if (!party) { - party = std::make_shared(player); + party = Party::create(player); g_game().updatePlayerShield(player); player->sendCreatureSkull(player); pushUserdata(L, party); From 3d55d1bf5937e754db1c00a2c3276c8f59ed75d0 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Thu, 21 Sep 2023 21:41:52 -0300 Subject: [PATCH 48/67] TaskHuntingSlot and TaskHuntingOption to unique_ptr --- src/canary_server.cpp | 2 +- src/creatures/players/player.cpp | 10 ++--- src/creatures/players/player.hpp | 24 +++++------ src/game/game.cpp | 4 +- src/io/functions/iologindata_load_player.cpp | 2 +- src/io/functions/iologindata_save_player.cpp | 3 +- src/io/ioprey.cpp | 40 +++++++++---------- src/io/ioprey.hpp | 28 +++++++------ .../creatures/player/player_functions.cpp | 4 +- src/server/network/protocol/protocolgame.cpp | 6 +-- src/server/network/protocol/protocolgame.hpp | 6 +-- 11 files changed, 64 insertions(+), 65 deletions(-) diff --git a/src/canary_server.cpp b/src/canary_server.cpp index d14bb30fc0e..7a36d6fb924 100644 --- a/src/canary_server.cpp +++ b/src/canary_server.cpp @@ -352,7 +352,7 @@ void CanaryServer::loadModules() { g_game().loadBoostedCreature(); g_ioBosstiary().loadBoostedBoss(); - g_ioprey().InitializeTaskHuntOptions(); + g_ioprey().initializeTaskHuntOptions(); } void CanaryServer::modulesLoadHelper(bool loaded, std::string moduleName) { diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 74bbf1ae823..6d504304ff2 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -4606,12 +4606,12 @@ bool Player::onKilledCreature(std::shared_ptr target, bool lastHit /* continue; } - TaskHuntingSlot* taskSlot = damagePlayer->getTaskHuntingWithCreature(monster->getRaceId()); + const auto &taskSlot = damagePlayer->getTaskHuntingWithCreature(monster->getRaceId()); if (!taskSlot || monster->isSummon()) { continue; } - if (const TaskHuntingOption* option = g_ioprey().GetTaskRewardOption(taskSlot)) { + if (const auto &option = g_ioprey().getTaskRewardOption(taskSlot)) { taskSlot->currentKills += 1; if ((taskSlot->upgrade && taskSlot->currentKills >= option->secondKills) || (!taskSlot->upgrade && taskSlot->currentKills >= option->firstKills)) { taskSlot->state = PreyTaskDataState_Completed; @@ -6369,14 +6369,12 @@ void Player::initializeTaskHunting() { slot->reloadMonsterGrid(getTaskHuntingBlackList(), getLevel()); } - if (!setTaskHuntingSlotClass(std::move(slot))) { - slot.reset(); - } + setTaskHuntingSlotClass(slot); } } if (client && g_configManager().getBoolean(TASK_HUNTING_ENABLED) && !client->oldProtocol) { - client->writeToOutputBuffer(g_ioprey().GetTaskHuntingBaseDate()); + client->writeToOutputBuffer(g_ioprey().getTaskHuntingBaseDate()); } } diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 3e0772b4dea..957545a265a 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -2144,12 +2144,12 @@ class Player final : public Creature, public Cylinder, public Bankable { void initializeTaskHunting(); bool isCreatureUnlockedOnTaskHunting(const std::shared_ptr mtype) const; - bool setTaskHuntingSlotClass(std::unique_ptr slot) { + bool setTaskHuntingSlotClass(std::unique_ptr &slot) { if (getTaskHuntingSlotById(slot->id)) { return false; } - taskHunting.emplace_back(slot.release()); + taskHunting.emplace_back(std::move(slot)); return true; } @@ -2160,21 +2160,21 @@ class Player final : public Creature, public Cylinder, public Bankable { } } - TaskHuntingSlot* getTaskHuntingSlotById(PreySlot_t slotid) { - if (auto it = std::find_if(taskHunting.begin(), taskHunting.end(), [slotid](const TaskHuntingSlot* itTask) { + const std::unique_ptr &getTaskHuntingSlotById(PreySlot_t slotid) { + if (auto it = std::find_if(taskHunting.begin(), taskHunting.end(), [slotid](const std::unique_ptr &itTask) { return itTask->id == slotid; }); it != taskHunting.end()) { return *it; } - return nullptr; + return TaskHuntingSlotNull; } std::vector getTaskHuntingBlackList() const { std::vector rt; - std::for_each(taskHunting.begin(), taskHunting.end(), [&rt](const TaskHuntingSlot* slot) { + std::for_each(taskHunting.begin(), taskHunting.end(), [&rt](const std::unique_ptr &slot) { if (slot->isOccupied()) { rt.push_back(slot->selectedRaceId); } else { @@ -2190,7 +2190,7 @@ class Player final : public Creature, public Cylinder, public Bankable { void sendTaskHuntingData() const { if (client) { client->sendResourcesBalance(getMoney(), getBankBalance(), getPreyCards(), getTaskHuntingPoints()); - for (const TaskHuntingSlot* slot : taskHunting) { + for (const std::unique_ptr &slot : taskHunting) { if (slot) { client->sendTaskHuntingData(slot); } @@ -2225,19 +2225,19 @@ class Player final : public Creature, public Cylinder, public Bankable { return getLevel() * g_configManager().getNumber(TASK_HUNTING_REROLL_PRICE_LEVEL); } - TaskHuntingSlot* getTaskHuntingWithCreature(uint16_t raceId) const { + const std::unique_ptr &getTaskHuntingWithCreature(uint16_t raceId) const { if (!g_configManager().getBoolean(TASK_HUNTING_ENABLED)) { - return nullptr; + return TaskHuntingSlotNull; } - if (auto it = std::find_if(taskHunting.begin(), taskHunting.end(), [raceId](const TaskHuntingSlot* itTask) { + if (auto it = std::find_if(taskHunting.begin(), taskHunting.end(), [raceId](const std::unique_ptr &itTask) { return itTask->selectedRaceId == raceId; }); it != taskHunting.end()) { return *it; } - return nullptr; + return TaskHuntingSlotNull; } uint32_t getLoyaltyPoints() const { @@ -2593,7 +2593,7 @@ class Player final : public Creature, public Cylinder, public Bankable { std::vector familiars; std::vector> preys; - std::vector taskHunting; + std::vector> taskHunting; GuildWarVector guildWarVector; diff --git a/src/game/game.cpp b/src/game/game.cpp index 81238fe68ef..7907b4d8bc1 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -8042,7 +8042,7 @@ void Game::playerPreyAction(uint32_t playerId, uint8_t slot, uint8_t action, uin return; } - g_ioprey().ParsePreyAction(player, static_cast(slot), static_cast(action), static_cast(option), index, raceId); + g_ioprey().parsePreyAction(player, static_cast(slot), static_cast(action), static_cast(option), index, raceId); } void Game::playerTaskHuntingAction(uint32_t playerId, uint8_t slot, uint8_t action, bool upgrade, uint16_t raceId) { @@ -8051,7 +8051,7 @@ void Game::playerTaskHuntingAction(uint32_t playerId, uint8_t slot, uint8_t acti return; } - g_ioprey().ParseTaskHuntingAction(player, static_cast(slot), static_cast(action), upgrade, raceId); + g_ioprey().parseTaskHuntingAction(player, static_cast(slot), static_cast(action), upgrade, raceId); } void Game::playerNpcGreet(uint32_t playerId, uint32_t npcId) { diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index 7cd6b984d76..f072c5d5707 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -773,7 +773,7 @@ void IOLoginDataLoad::loadPlayerTaskHuntingClass(std::shared_ptr player, slot->state = PreyTaskDataState_Selection; } - player->setTaskHuntingSlotClass(std::move(slot)); + player->setTaskHuntingSlotClass(slot); } while (result->next()); } } diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index 257d2577cb1..71439efac4d 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -640,8 +640,7 @@ bool IOLoginDataSave::savePlayerTaskHuntingClass(std::shared_ptr player) if (g_configManager().getBoolean(TASK_HUNTING_ENABLED)) { std::ostringstream query; for (uint8_t slotId = PreySlot_First; slotId <= PreySlot_Last; slotId++) { - TaskHuntingSlot* slot = player->getTaskHuntingSlotById(static_cast(slotId)); - if (slot) { + if (const auto &slot = player->getTaskHuntingSlotById(static_cast(slotId))) { query.str(""); query << "INSERT INTO `player_taskhunt` (`player_id`, `slot`, `state`, `raceid`, `upgrade`, `rarity`, `kills`, `disabled_time`, `free_reroll`, `monster_list`) VALUES ("; query << player->getGUID() << ", "; diff --git a/src/io/ioprey.cpp b/src/io/ioprey.cpp index 20b6faacc8e..b81dad1fdf7 100644 --- a/src/io/ioprey.cpp +++ b/src/io/ioprey.cpp @@ -246,7 +246,7 @@ void TaskHuntingSlot::reloadReward() { } // Prey/Task hunting global class -void IOPrey::CheckPlayerPreys(std::shared_ptr player, uint8_t amount) const { +void IOPrey::checkPlayerPreys(std::shared_ptr player, uint8_t amount) const { if (!player) { return; } @@ -289,7 +289,7 @@ void IOPrey::CheckPlayerPreys(std::shared_ptr player, uint8_t amount) co } } -void IOPrey::ParsePreyAction(std::shared_ptr player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const { +void IOPrey::parsePreyAction(std::shared_ptr player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const { const auto &slot = player->getPreySlotById(slotId); if (!slot || slot->state == PreyDataState_Locked) { player->sendMessageDialog("To unlock this prey slot first you must buy it on store."); @@ -382,15 +382,15 @@ void IOPrey::ParsePreyAction(std::shared_ptr player, PreySlot_t slotId, slot->option = option; } else { - g_logger().warn("[IOPrey::ParsePreyAction] - Unknown prey action: {}", fmt::underlying(action)); + g_logger().warn("[IOPrey::parsePreyAction] - Unknown prey action: {}", fmt::underlying(action)); return; } player->reloadPreySlot(slotId); } -void IOPrey::ParseTaskHuntingAction(std::shared_ptr player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const { - TaskHuntingSlot* slot = player->getTaskHuntingSlotById(slotId); +void IOPrey::parseTaskHuntingAction(std::shared_ptr player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const { + const auto &slot = player->getTaskHuntingSlotById(slotId); if (!slot || slot->state == PreyTaskDataState_Locked) { player->sendMessageDialog("To unlock this task hunting slot first you must buy it on store."); return; @@ -476,7 +476,7 @@ void IOPrey::ParseTaskHuntingAction(std::shared_ptr player, PreySlot_t s return; } - if (const TaskHuntingOption* option = GetTaskRewardOption(slot)) { + if (const auto &option = getTaskRewardOption(slot)) { uint64_t reward; int32_t boostChange = uniform_random(0, 100); if (slot->rarity >= 4 && boostChange <= 5) { @@ -516,13 +516,13 @@ void IOPrey::ParseTaskHuntingAction(std::shared_ptr player, PreySlot_t s slot->disabledUntilTimeStamp = OTSYS_TIME() + g_configManager().getNumber(TASK_HUNTING_LIMIT_EXHAUST) * 1000; } } else { - g_logger().warn("[IOPrey::ParseTaskHuntingAction] - Unknown task action: {}", fmt::underlying(action)); + g_logger().warn("[IOPrey::parseTaskHuntingAction] - Unknown task action: {}", fmt::underlying(action)); return; } player->reloadTaskSlot(slotId); } -void IOPrey::InitializeTaskHuntOptions() { +void IOPrey::initializeTaskHuntOptions() { if (!g_configManager().getBoolean(TASK_HUNTING_ENABLED)) { return; } @@ -540,7 +540,8 @@ void IOPrey::InitializeTaskHuntOptions() { auto reward = static_cast(std::round((10 * kills) / killStage)); // Amount of task stars on task hunting for (uint8_t star = 1; star <= limitOfStars; ++star) { - auto option = new TaskHuntingOption(); + const auto &option = taskOption.emplace_back(std::make_unique()); + option->difficult = static_cast(difficulty); option->rarity = star; @@ -550,8 +551,6 @@ void IOPrey::InitializeTaskHuntOptions() { option->secondKills = kills * 2; option->secondReward = reward * 2; - taskOption.push_back(option); - reward = static_cast(std::round((reward * (115 + (difficulty * limitOfStars))) / 100)); } @@ -578,7 +577,7 @@ void IOPrey::InitializeTaskHuntOptions() { }); msg.addByte(static_cast(taskOption.size())); - std::for_each(taskOption.begin(), taskOption.end(), [&msg](const TaskHuntingOption* option) { + std::for_each(taskOption.begin(), taskOption.end(), [&msg](const std::unique_ptr &option) { msg.addByte(static_cast(option->difficult)); msg.addByte(option->rarity); msg.add(option->firstKills); @@ -589,14 +588,14 @@ void IOPrey::InitializeTaskHuntOptions() { baseDataMessage = msg; } -TaskHuntingOption* IOPrey::GetTaskRewardOption(const TaskHuntingSlot* slot) const { +const std::unique_ptr &IOPrey::getTaskRewardOption(const std::unique_ptr &slot) const { if (!slot) { - return nullptr; + return TaskHuntingOptionNull; } const auto mtype = g_monsters().getMonsterTypeByRaceId(slot->selectedRaceId); if (!mtype) { - return nullptr; + return TaskHuntingOptionNull; } PreyTaskDifficult_t difficult; @@ -608,12 +607,13 @@ TaskHuntingOption* IOPrey::GetTaskRewardOption(const TaskHuntingSlot* slot) cons difficult = PreyTaskDifficult_Hard; } - if (auto it = std::find_if(taskOption.begin(), taskOption.end(), [difficult, slot](const TaskHuntingOption* optionIt) { - return optionIt->difficult == difficult && optionIt->rarity == slot->rarity; - }); - it != taskOption.end()) { + auto it = std::find_if(taskOption.begin(), taskOption.end(), [difficult, &slot](const std::unique_ptr &optionIt) { + return optionIt->difficult == difficult && optionIt->rarity == slot->rarity; + }); + + if (it != taskOption.end()) { return *it; } - return nullptr; + return TaskHuntingOptionNull; } diff --git a/src/io/ioprey.hpp b/src/io/ioprey.hpp index 629ad3fc0dd..2219e630b92 100644 --- a/src/io/ioprey.hpp +++ b/src/io/ioprey.hpp @@ -12,6 +12,14 @@ #include "lib/di/container.hpp" #include "server/network/protocol/protocolgame.hpp" +class PreySlot; +class TaskHuntingSlot; +class TaskHuntingOption; + +static const std::unique_ptr &PreySlotNull {}; +static const std::unique_ptr &TaskHuntingSlotNull {}; +static const std::unique_ptr &TaskHuntingOptionNull {}; + enum PreySlot_t : uint8_t { PreySlot_One = 0, PreySlot_Two = 1, @@ -137,8 +145,6 @@ class PreySlot { int64_t freeRerollTimeStamp = 0; }; -static const std::unique_ptr &PreySlotNull {}; - class TaskHuntingSlot { public: TaskHuntingSlot() = default; @@ -219,24 +225,20 @@ class IOPrey { return inject(); } - void CheckPlayerPreys(std::shared_ptr player, uint8_t amount) const; - void ParsePreyAction(std::shared_ptr player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const; - - void ParseTaskHuntingAction(std::shared_ptr player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const; + void checkPlayerPreys(std::shared_ptr player, uint8_t amount) const; + void parsePreyAction(std::shared_ptr player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const; - void InitializeTaskHuntOptions(); - TaskHuntingOption* GetTaskRewardOption(const TaskHuntingSlot* slot) const; + void parseTaskHuntingAction(std::shared_ptr player, PreySlot_t slotId, PreyTaskAction_t action, bool upgrade, uint16_t raceId) const; - std::vector GetTaskOptions() const { - return taskOption; - } + void initializeTaskHuntOptions(); + const std::unique_ptr &getTaskRewardOption(const std::unique_ptr &slot) const; - NetworkMessage GetTaskHuntingBaseDate() const { + NetworkMessage getTaskHuntingBaseDate() const { return baseDataMessage; } NetworkMessage baseDataMessage; - std::vector taskOption; + std::vector> taskOption; }; constexpr auto g_ioprey = IOPrey::getInstance; diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 1dd9b3d9caa..c6afd126e95 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -365,7 +365,7 @@ int PlayerFunctions::luaPlayerRemovePreyStamina(lua_State* L) { // player:removePreyStamina(amount) std::shared_ptr player = getUserdataShared(L, 1); if (player) { - g_ioprey().CheckPlayerPreys(player, getNumber(L, 2, 1)); + g_ioprey().checkPlayerPreys(player, getNumber(L, 2, 1)); pushBoolean(L, true); } else { lua_pushnil(L); @@ -489,7 +489,7 @@ int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { int PlayerFunctions::luaPlayerTaskThirdSlot(lua_State* L) { // get: player:taskHuntingThirdSlot() set: player:taskHuntingThirdSlot(bool) if (std::shared_ptr player = getUserdataShared(L, 1); - TaskHuntingSlot* slot = player->getTaskHuntingSlotById(PreySlot_Three)) { + const auto &slot = player->getTaskHuntingSlotById(PreySlot_Three)) { if (lua_gettop(L) == 1) { pushBoolean(L, slot->state != PreyTaskDataState_Locked); } else { diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 9b9d06ad754..cac9abf9da4 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -7499,7 +7499,7 @@ void ProtocolGame::sendUpdateInputAnalyzer(CombatType_t type, int32_t amount, st writeToOutputBuffer(msg); } -void ProtocolGame::sendTaskHuntingData(const TaskHuntingSlot* slot) { +void ProtocolGame::sendTaskHuntingData(const std::unique_ptr &slot) { if (!player || oldProtocol) { return; } @@ -7528,7 +7528,7 @@ void ProtocolGame::sendTaskHuntingData(const TaskHuntingSlot* slot) { msg.addByte(user->isCreatureUnlockedOnTaskHunting(g_monsters().getMonsterType(mType.second)) ? 0x01 : 0x00); }); } else if (slot->state == PreyTaskDataState_Active) { - if (const TaskHuntingOption* option = g_ioprey().GetTaskRewardOption(slot)) { + if (const auto &option = g_ioprey().getTaskRewardOption(slot)) { msg.add(slot->selectedRaceId); if (slot->upgrade) { msg.addByte(0x01); @@ -7544,7 +7544,7 @@ void ProtocolGame::sendTaskHuntingData(const TaskHuntingSlot* slot) { return; } } else if (slot->state == PreyTaskDataState_Completed) { - if (const TaskHuntingOption* option = g_ioprey().GetTaskRewardOption(slot)) { + if (const auto &option = g_ioprey().getTaskRewardOption(slot)) { msg.add(slot->selectedRaceId); if (slot->upgrade) { msg.addByte(0x01); diff --git a/src/server/network/protocol/protocolgame.hpp b/src/server/network/protocol/protocolgame.hpp index 264e09d6dcf..60eac6f1821 100644 --- a/src/server/network/protocol/protocolgame.hpp +++ b/src/server/network/protocol/protocolgame.hpp @@ -374,8 +374,8 @@ class ProtocolGame final : public Protocol { void sendCoinBalance(); - void sendPreyTimeLeft(const std::unique_ptr& slot); - void sendPreyData(const std::unique_ptr& slot); + void sendPreyTimeLeft(const std::unique_ptr &slot); + void sendPreyData(const std::unique_ptr &slot); void sendPreyPrices(); // tiles @@ -440,7 +440,7 @@ class ProtocolGame final : public Protocol { // tiles static void RemoveTileThing(NetworkMessage &msg, const Position &pos, uint32_t stackpos); - void sendTaskHuntingData(const TaskHuntingSlot* slot); + void sendTaskHuntingData(const std::unique_ptr &slot); void MoveUpCreature(NetworkMessage &msg, std::shared_ptr creature, const Position &newPos, const Position &oldPos); void MoveDownCreature(NetworkMessage &msg, std::shared_ptr creature, const Position &newPos, const Position &oldPos); From 87cf03e5472017524cfaddc9a9930a63405ab744 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Thu, 21 Sep 2023 22:06:02 -0300 Subject: [PATCH 49/67] TeamFinder to unique_ptr --- .../players/grouping/team_finder.hpp | 2 + src/game/game.hpp | 24 +++++++-- src/server/network/protocol/protocolgame.cpp | 53 ++++--------------- 3 files changed, 33 insertions(+), 46 deletions(-) diff --git a/src/creatures/players/grouping/team_finder.hpp b/src/creatures/players/grouping/team_finder.hpp index b0c77930624..609ce0f673f 100644 --- a/src/creatures/players/grouping/team_finder.hpp +++ b/src/creatures/players/grouping/team_finder.hpp @@ -51,3 +51,5 @@ class TeamFinder { // list: player:getGuid(), player status std::map membersMap = {}; }; + +static const std::unique_ptr &TeamFinderNull {}; diff --git a/src/game/game.hpp b/src/game/game.hpp index 72dd0686a7c..9ab683d15d5 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -89,12 +89,28 @@ class Game { return worldType; } - std::map getTeamFinderList() const { + const std::map> &getTeamFinderList() const { return teamFinderMap; } - void registerTeamFinderAssemble(uint32_t leaderGuid, TeamFinder* teamFinder) { - teamFinderMap[leaderGuid] = teamFinder; + + const std::unique_ptr &getTeamFinder(const std::shared_ptr &player) const { + auto it = teamFinderMap.find(player->getGUID()); + if (it != teamFinderMap.end()) { + return it->second; + } + + return TeamFinderNull; + } + + const std::unique_ptr &getOrCreateTeamFinder(const std::shared_ptr &player) { + auto it = teamFinderMap.find(player->getGUID()); + if (it != teamFinderMap.end()) { + return it->second; + } + + return teamFinderMap[player->getGUID()] = std::make_unique(); } + void removeTeamFinderListed(uint32_t leaderGuid) { teamFinderMap.erase(leaderGuid); } @@ -765,7 +781,7 @@ class Game { std::map> monsters; std::vector forgeableMonsters; - std::map teamFinderMap; // [leaderGUID] = TeamFinder* + std::map> teamFinderMap; // [leaderGUID] = TeamFinder* // list of items that are in trading state, mapped to the player std::map, uint32_t> tradeItems; diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index cac9abf9da4..60eab858b09 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -2391,15 +2391,15 @@ void ProtocolGame::sendTeamFinderList() { NetworkMessage msg; msg.addByte(0x2D); msg.addByte(0x00); // Bool value, with 'true' the player exceed packets for second. - std::map teamFinder = g_game().getTeamFinderList(); + const auto &teamFinder = g_game().getTeamFinderList(); msg.add(teamFinder.size()); - for (auto it : teamFinder) { - std::shared_ptr leader = g_game().getPlayerByGUID(it.first); + for (const auto &it : teamFinder) { + const auto &leader = g_game().getPlayerByGUID(it.first); if (!leader) { return; } - TeamFinder* teamAssemble = it.second; + const auto &teamAssemble = it.second; if (!teamAssemble) { return; } @@ -2458,13 +2458,7 @@ void ProtocolGame::sendLeaderTeamFinder(bool reset) { return; } - TeamFinder* teamAssemble = nullptr; - std::map teamFinder = g_game().getTeamFinderList(); - auto it = teamFinder.find(player->getGUID()); - if (it != teamFinder.end()) { - teamAssemble = it->second; - } - + const auto &teamAssemble = g_game().getTeamFinder(player); if (!teamAssemble) { return; } @@ -2476,6 +2470,7 @@ void ProtocolGame::sendLeaderTeamFinder(bool reset) { g_game().removeTeamFinderListed(player->getGUID()); return; } + msg.add(teamAssemble->minLevel); msg.add(teamAssemble->maxLevel); msg.addByte(teamAssemble->vocationIDs); @@ -2543,19 +2538,7 @@ void ProtocolGame::createLeaderTeamFinder(NetworkMessage &msg) { return; } - std::map members; - std::map teamFinder = g_game().getTeamFinderList(); - TeamFinder* teamAssemble = nullptr; - auto it = teamFinder.find(player->getGUID()); - if (it != teamFinder.end()) { - members = it->second->membersMap; - teamAssemble = it->second; - } - - if (!teamAssemble) { - teamAssemble = new TeamFinder(); - } - + const auto &teamAssemble = g_game().getOrCreateTeamFinder(player); teamAssemble->minLevel = msg.get(); teamAssemble->maxLevel = msg.get(); teamAssemble->vocationIDs = msg.getByte(); @@ -2600,16 +2583,14 @@ void ProtocolGame::createLeaderTeamFinder(NetworkMessage &msg) { if (teamAssemble->partyBool && party) { for (std::shared_ptr member : party->getMembers()) { if (member && member->getGUID() != player->getGUID()) { - members.insert({ member->getGUID(), 3 }); + teamAssemble->membersMap.insert({ member->getGUID(), 3 }); } } auto partyLeader = party->getLeader(); if (partyLeader && partyLeader->getGUID() != player->getGUID()) { - members.insert({ partyLeader->getGUID(), 3 }); + teamAssemble->membersMap.insert({ partyLeader->getGUID(), 3 }); } } - teamAssemble->membersMap = members; - g_game().registerTeamFinderAssemble(player->getGUID(), teamAssemble); } void ProtocolGame::parsePartyAnalyzerAction(NetworkMessage &msg) const { @@ -2661,13 +2642,7 @@ void ProtocolGame::parseLeaderFinderWindow(NetworkMessage &msg) { return; } - std::map teamFinder = g_game().getTeamFinderList(); - TeamFinder* teamAssemble = nullptr; - auto it = teamFinder.find(player->getGUID()); - if (it != teamFinder.end()) { - teamAssemble = it->second; - } - + const auto &teamAssemble = g_game().getTeamFinder(player); if (!teamAssemble) { return; } @@ -2725,13 +2700,7 @@ void ProtocolGame::parseMemberFinderWindow(NetworkMessage &msg) { return; } - std::map teamFinder = g_game().getTeamFinderList(); - TeamFinder* teamAssemble = nullptr; - auto it = teamFinder.find(leaderID); - if (it != teamFinder.end()) { - teamAssemble = it->second; - } - + const auto &teamAssemble = g_game().getTeamFinder(player); if (!teamAssemble) { return; } From acc87b3d06fa688fa865ac45121c0ae3da095125 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Thu, 21 Sep 2023 22:13:24 -0300 Subject: [PATCH 50/67] smallfix --- src/lua/functions/creatures/player/player_functions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index c6afd126e95..795654cd750 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -461,8 +461,8 @@ int PlayerFunctions::luaPlayerGetPreyLootPercentage(lua_State* L) { int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { // get: player:preyThirdSlot() set: player:preyThirdSlot(bool) - if (std::shared_ptr player = getUserdataShared(L, 1); - const auto &slot = player->getPreySlotById(PreySlot_Three)) { + if (const auto &player = getUserdataShared(L, 1)) { + const auto &slot = player->getPreySlotById(PreySlot_Three); if (!slot) { lua_pushnil(L); } else if (lua_gettop(L) == 1) { From 0191a3dc8369daa64bbf8ed1f309484299e943e1 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Fri, 22 Sep 2023 14:36:48 -0300 Subject: [PATCH 51/67] fix: check spectator get player nullptr --- src/game/game.cpp | 70 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index 4e31e0efce4..7d877557620 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -5736,7 +5736,12 @@ void Game::changeSpeed(std::shared_ptr creature, int32_t varSpeedDelta SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), false, true); for (auto spectator : spectators) { - spectator->getPlayer()->sendChangeSpeed(creature, creature->getStepSpeed()); + auto player = spectator->getPlayer(); + if (!player) { + continue; + } + + player->sendChangeSpeed(creature, creature->getStepSpeed()); } } @@ -5747,7 +5752,12 @@ void Game::setCreatureSpeed(std::shared_ptr creature, int32_t speed) { SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), false, true); for (auto spectator : spectators) { - spectator->getPlayer()->sendChangeSpeed(creature, creature->getStepSpeed()); + auto player = spectator->getPlayer(); + if (!player) { + continue; + } + + player->sendChangeSpeed(creature, creature->getStepSpeed()); } } @@ -5795,7 +5805,12 @@ void Game::internalCreatureChangeOutfit(std::shared_ptr creature, cons SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); for (auto spectator : spectators) { - spectator->getPlayer()->sendCreatureChangeOutfit(creature, outfit); + auto player = spectator->getPlayer(); + if (!player) { + continue; + } + + player->sendCreatureChangeOutfit(creature, outfit); } } @@ -5804,7 +5819,12 @@ void Game::internalCreatureChangeVisible(std::shared_ptr creature, boo SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); for (auto spectator : spectators) { - spectator->getPlayer()->sendCreatureChangeVisible(creature, visible); + auto player = spectator->getPlayer(); + if (!player) { + continue; + } + + player->sendCreatureChangeVisible(creature, visible); } } @@ -5813,7 +5833,12 @@ void Game::changeLight(std::shared_ptr creature) { SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); for (auto spectator : spectators) { - spectator->getPlayer()->sendCreatureLight(creature); + auto player = spectator->getPlayer(); + if (!player) { + continue; + } + + player->sendCreatureLight(creature); } } @@ -5822,7 +5847,12 @@ void Game::updateCreatureIcon(std::shared_ptr creature) { SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); for (auto spectator : spectators) { - spectator->getPlayer()->sendCreatureIcon(creature); + auto player = spectator->getPlayer(); + if (!player) { + continue; + } + + player->sendCreatureIcon(creature); } } @@ -6370,7 +6400,6 @@ bool Game::combatChangeHealth(std::shared_ptr attacker, std::shared_pt map.getSpectators(spectators, targetPos, false, true); for (auto spectator : spectators) { auto tmpPlayer = spectator->getPlayer(); - if (!tmpPlayer) { continue; } @@ -6794,7 +6823,7 @@ void Game::sendMessages( for (std::shared_ptr spectator : spectators) { std::shared_ptr tmpPlayer = spectator->getPlayer(); - if (tmpPlayer->getPosition().z != targetPos.z) { + if (!tmpPlayer || tmpPlayer->getPosition().z != targetPos.z) { continue; } @@ -7041,7 +7070,6 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< map.getSpectators(spectators, targetPos, false, true); for (auto spectator : spectators) { auto tmpPlayer = spectator->getPlayer(); - if (!tmpPlayer) { continue; } @@ -7141,7 +7169,6 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< map.getSpectators(spectators, targetPos, false, true); for (auto spectator : spectators) { auto tmpPlayer = spectator->getPlayer(); - if (!tmpPlayer) { continue; } @@ -7426,6 +7453,10 @@ void Game::updateCreatureWalkthrough(std::shared_ptr creature) { map.getSpectators(spectators, creature->getPosition(), true, true); for (auto spectator : spectators) { auto tmpPlayer = spectator->getPlayer(); + if (!tmpPlayer) { + continue; + } + tmpPlayer->sendCreatureWalkthrough(creature, tmpPlayer->canWalkthroughEx(creature)); } } @@ -7438,7 +7469,12 @@ void Game::updateCreatureSkull(std::shared_ptr creature) { SpectatorHashSet spectators; map.getSpectators(spectators, creature->getPosition(), true, true); for (auto spectator : spectators) { - spectator->getPlayer()->sendCreatureSkull(creature); + auto player = spectator->getPlayer(); + if (!player) { + continue; + } + + player->sendCreatureSkull(creature); } } @@ -7446,7 +7482,12 @@ void Game::updatePlayerShield(std::shared_ptr player) { SpectatorHashSet spectators; map.getSpectators(spectators, player->getPosition(), true, true); for (auto spectator : spectators) { - spectator->getPlayer()->sendCreatureShield(player); + auto player = spectator->getPlayer(); + if (!player) { + continue; + } + + player->sendCreatureShield(player); } } @@ -7603,11 +7644,12 @@ void Game::updatePlayerHelpers(std::shared_ptr player) { SpectatorHashSet spectators; map.getSpectators(spectators, player->getPosition(), true, true); for (auto spectator : spectators) { - if (!spectator || !spectator->getPlayer()) { + auto specPlayer = spectator->getPlayer(); + if (!specPlayer) { continue; } - spectator->getPlayer()->sendCreatureHelpers(player->getID(), helpers); + specPlayer->sendCreatureHelpers(player->getID(), helpers); } } From 88a5f47eef723a8ae3817ff4709c5dc5f0233e75 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 17:29:23 -0300 Subject: [PATCH 52/67] fix: z_stream memory leak --- src/server/network/protocol/protocol.cpp | 6 ++++++ src/server/network/protocol/protocol.hpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/server/network/protocol/protocol.cpp b/src/server/network/protocol/protocol.cpp index d011887adde..895780b3fea 100644 --- a/src/server/network/protocol/protocol.cpp +++ b/src/server/network/protocol/protocol.cpp @@ -14,6 +14,12 @@ #include "security/rsa.hpp" #include "game/scheduling/dispatcher.hpp" +Protocol::~Protocol() { + if (compreesionEnabled) { + deflateEnd(defStream.get()); + } +} + void Protocol::onSendMessage(const OutputMessage_ptr &msg) { if (!rawMessages) { uint32_t sendMessageChecksum = 0; diff --git a/src/server/network/protocol/protocol.hpp b/src/server/network/protocol/protocol.hpp index 79c2dcd4451..b209c306951 100644 --- a/src/server/network/protocol/protocol.hpp +++ b/src/server/network/protocol/protocol.hpp @@ -17,7 +17,7 @@ class Protocol : public std::enable_shared_from_this { explicit Protocol(Connection_ptr initConnection) : connectionPtr(initConnection) { } - virtual ~Protocol() = default; + virtual ~Protocol(); // non-copyable Protocol(const Protocol &) = delete; From d28646dcd5c4513ffca60a029084b6b9cdd312ef Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 17:41:46 -0300 Subject: [PATCH 53/67] SpawnNpc to smart pointer --- src/creatures/npcs/npc.cpp | 9 +-- src/creatures/npcs/npc.hpp | 4 +- src/creatures/npcs/npcs.cpp | 12 +--- src/creatures/npcs/npcs.hpp | 6 +- src/creatures/npcs/spawns/spawn_npc.cpp | 4 +- src/creatures/npcs/spawns/spawn_npc.hpp | 4 +- .../creatures/npc/npc_type_functions.cpp | 64 +++++++++---------- 7 files changed, 47 insertions(+), 56 deletions(-) diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index b8775ee148a..61896f2f4db 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -23,14 +23,11 @@ int32_t Npc::despawnRadius; uint32_t Npc::npcAutoID = 0x80000000; std::shared_ptr Npc::createNpc(const std::string &name) { - NpcType* npcType = g_npcs().getNpcType(name); - if (!npcType) { - return nullptr; - } - return std::make_shared(npcType); + const auto &npcType = g_npcs().getNpcType(name); + return npcType ? std::make_shared(npcType) : nullptr; } -Npc::Npc(NpcType* npcType) : +Npc::Npc(const std::shared_ptr &npcType) : Creature(), strDescription(npcType->nameDescription), npcType(npcType) { diff --git a/src/creatures/npcs/npc.hpp b/src/creatures/npcs/npc.hpp index 3af93863fc3..c55fff0911c 100644 --- a/src/creatures/npcs/npc.hpp +++ b/src/creatures/npcs/npc.hpp @@ -25,7 +25,7 @@ class Npc final : public Creature { static int32_t despawnRange; static int32_t despawnRadius; - explicit Npc(NpcType* npcType); + explicit Npc(const std::shared_ptr &npcType); Npc() = default; ~Npc(); @@ -177,7 +177,7 @@ class Npc final : public Creature { phmap::flat_hash_map> shopPlayerMap; - NpcType* npcType; + std::shared_ptr npcType; SpawnNpc* spawnNpc = nullptr; uint8_t speechBubble; diff --git a/src/creatures/npcs/npcs.cpp b/src/creatures/npcs/npcs.cpp index d3c1fff7adc..432b0adbe15 100644 --- a/src/creatures/npcs/npcs.cpp +++ b/src/creatures/npcs/npcs.cpp @@ -73,7 +73,7 @@ bool NpcType::loadCallback(LuaScriptInterface* scriptInterface) { return true; } -void NpcType::loadShop(NpcType* npcType, ShopBlock shopBlock) { +void NpcType::loadShop(const std::shared_ptr &npcType, ShopBlock shopBlock) { ItemType &iType = Item::items.getItemType(shopBlock.itemId); // Registering item prices globaly. @@ -134,7 +134,7 @@ bool Npcs::reload() { return false; } -NpcType* Npcs::getNpcType(const std::string &name, bool create /* = false*/) { +std::shared_ptr Npcs::getNpcType(const std::string &name, bool create /* = false*/) { std::string key = asLowerCaseString(name); auto it = npcs.find(key); @@ -142,11 +142,5 @@ NpcType* Npcs::getNpcType(const std::string &name, bool create /* = false*/) { return it->second; } - if (!create) { - return nullptr; - } - - npcs[key] = new NpcType(name); - - return npcs[key]; + return create ? npcs[key] = std::make_shared(name) : nullptr; } diff --git a/src/creatures/npcs/npcs.hpp b/src/creatures/npcs/npcs.hpp index 4b8f59186a2..472af4e89ad 100644 --- a/src/creatures/npcs/npcs.hpp +++ b/src/creatures/npcs/npcs.hpp @@ -86,7 +86,7 @@ class NpcType { std::string nameDescription; NpcInfo info; - void loadShop(NpcType* npcType, ShopBlock shopBlock); + void loadShop(const std::shared_ptr &npcType, ShopBlock shopBlock); bool loadCallback(LuaScriptInterface* scriptInterface); bool canSpawn(const Position &pos); @@ -103,7 +103,7 @@ class Npcs { return inject(); } - NpcType* getNpcType(const std::string &name, bool create = false); + std::shared_ptr getNpcType(const std::string &name, bool create = false); // Reset npcs informations on reload bool load(bool loadLibs = true, bool loadNpcs = true, bool reloading = false) const; @@ -111,7 +111,7 @@ class Npcs { private: std::unique_ptr scriptInterface; - std::map npcs; + std::map> npcs; }; constexpr auto g_npcs = Npcs::getInstance; diff --git a/src/creatures/npcs/spawns/spawn_npc.cpp b/src/creatures/npcs/spawns/spawn_npc.cpp index 9d29598792f..36430ec025e 100644 --- a/src/creatures/npcs/spawns/spawn_npc.cpp +++ b/src/creatures/npcs/spawns/spawn_npc.cpp @@ -157,7 +157,7 @@ bool SpawnNpc::isInSpawnNpcZone(const Position &pos) { return SpawnsNpc::isInZone(centerPos, radius, pos); } -bool SpawnNpc::spawnNpc(uint32_t spawnId, NpcType* npcType, const Position &pos, Direction dir, bool startup /*= false*/) { +bool SpawnNpc::spawnNpc(uint32_t spawnId, const std::shared_ptr &npcType, const Position &pos, Direction dir, bool startup /*= false*/) { auto npc = std::make_shared(npcType); if (startup) { // No need to send out events to the surrounding since there is no one out there to listen! @@ -246,7 +246,7 @@ void SpawnNpc::cleanup() { } bool SpawnNpc::addNpc(const std::string &name, const Position &pos, Direction dir, uint32_t scheduleInterval) { - NpcType* npcType = g_npcs().getNpcType(name); + const auto &npcType = g_npcs().getNpcType(name); if (!npcType) { g_logger().error("Can not find {}", name); return false; diff --git a/src/creatures/npcs/spawns/spawn_npc.hpp b/src/creatures/npcs/spawns/spawn_npc.hpp index 4926d2c8d09..eeb5c2edcd2 100644 --- a/src/creatures/npcs/spawns/spawn_npc.hpp +++ b/src/creatures/npcs/spawns/spawn_npc.hpp @@ -17,7 +17,7 @@ class NpcType; struct spawnBlockNpc_t { Position pos; - NpcType* npcType; + std::shared_ptr npcType; int64_t lastSpawnNpc; uint32_t interval; Direction direction; @@ -63,7 +63,7 @@ class SpawnNpc { uint32_t checkSpawnNpcEvent = 0; static bool findPlayer(const Position &pos); - bool spawnNpc(uint32_t spawnId, NpcType* npcType, const Position &pos, Direction dir, bool startup = false); + bool spawnNpc(uint32_t spawnId, const std::shared_ptr &npcType, const Position &pos, Direction dir, bool startup = false); void checkSpawnNpc(); void scheduleSpawnNpc(uint32_t spawnId, spawnBlockNpc_t &sb, uint16_t interval); }; diff --git a/src/lua/functions/creatures/npc/npc_type_functions.cpp b/src/lua/functions/creatures/npc/npc_type_functions.cpp index 6f1d553ea34..8c520a4ae4d 100644 --- a/src/lua/functions/creatures/npc/npc_type_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_type_functions.cpp @@ -37,7 +37,7 @@ void NpcTypeFunctions::createNpcTypeShopLuaTable(lua_State* L, const std::vector int NpcTypeFunctions::luaNpcTypeCreate(lua_State* L) { // NpcType(name) - NpcType* npcType = g_npcs().getNpcType(getString(L, 1), true); + const auto &npcType = g_npcs().getNpcType(getString(L, 1), true); pushUserdata(L, npcType); setMetatable(L, -1, "NpcType"); return 1; @@ -45,7 +45,7 @@ int NpcTypeFunctions::luaNpcTypeCreate(lua_State* L) { int NpcTypeFunctions::luaNpcTypeIsPushable(lua_State* L) { // get: npcType:isPushable() set: npcType:isPushable(bool) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { pushBoolean(L, npcType->info.pushable); @@ -61,7 +61,7 @@ int NpcTypeFunctions::luaNpcTypeIsPushable(lua_State* L) { int NpcTypeFunctions::luaNpcTypeFloorChange(lua_State* L) { // get: npcType:floorChange() set: npcType:floorChange(bool) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { pushBoolean(L, npcType->info.floorChange); @@ -77,7 +77,7 @@ int NpcTypeFunctions::luaNpcTypeFloorChange(lua_State* L) { int NpcTypeFunctions::luaNpcTypeCanSpawn(lua_State* L) { // monsterType:canSpawn(pos) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); const Position &position = getPosition(L, 2); if (npcType) { pushBoolean(L, npcType->canSpawn(position)); @@ -89,7 +89,7 @@ int NpcTypeFunctions::luaNpcTypeCanSpawn(lua_State* L) { int NpcTypeFunctions::luaNpcTypeCanPushItems(lua_State* L) { // get: npcType:canPushItems() set: npcType:canPushItems(bool) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { pushBoolean(L, npcType->info.canPushItems); @@ -105,7 +105,7 @@ int NpcTypeFunctions::luaNpcTypeCanPushItems(lua_State* L) { int NpcTypeFunctions::luaNpcTypeCanPushCreatures(lua_State* L) { // get: npcType:canPushCreatures() set: npcType:canPushCreatures(bool) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { pushBoolean(L, npcType->info.canPushCreatures); @@ -121,7 +121,7 @@ int NpcTypeFunctions::luaNpcTypeCanPushCreatures(lua_State* L) { int32_t NpcTypeFunctions::luaNpcTypeName(lua_State* L) { // get: npcType:name() set: npcType:name(name) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { pushString(L, npcType->name); @@ -137,7 +137,7 @@ int32_t NpcTypeFunctions::luaNpcTypeName(lua_State* L) { int NpcTypeFunctions::luaNpcTypeNameDescription(lua_State* L) { // get: npcType:nameDescription() set: npcType:nameDescription(desc) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { pushString(L, npcType->nameDescription); @@ -153,7 +153,7 @@ int NpcTypeFunctions::luaNpcTypeNameDescription(lua_State* L) { int NpcTypeFunctions::luaNpcTypeHealth(lua_State* L) { // get: npcType:health() set: npcType:health(health) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.health); @@ -169,7 +169,7 @@ int NpcTypeFunctions::luaNpcTypeHealth(lua_State* L) { int NpcTypeFunctions::luaNpcTypeMaxHealth(lua_State* L) { // get: npcType:maxHealth() set: npcType:maxHealth(health) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.healthMax); @@ -185,7 +185,7 @@ int NpcTypeFunctions::luaNpcTypeMaxHealth(lua_State* L) { int NpcTypeFunctions::luaNpcTypeAddShopItem(lua_State* L) { // npcType:addShopItem(shop) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (!npcType) { lua_pushnil(L); return 1; @@ -203,7 +203,7 @@ int NpcTypeFunctions::luaNpcTypeAddShopItem(lua_State* L) { int NpcTypeFunctions::luaNpcTypeAddVoice(lua_State* L) { // npcType:addVoice(sentence, interval, chance, yell) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { voiceBlock_t voice; voice.text = getString(L, 2); @@ -220,7 +220,7 @@ int NpcTypeFunctions::luaNpcTypeAddVoice(lua_State* L) { int NpcTypeFunctions::luaNpcTypeGetVoices(lua_State* L) { // npcType:getVoices() - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (!npcType) { lua_pushnil(L); return 1; @@ -239,7 +239,7 @@ int NpcTypeFunctions::luaNpcTypeGetVoices(lua_State* L) { int NpcTypeFunctions::luaNpcTypeGetCreatureEvents(lua_State* L) { // npcType:getCreatureEvents() - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (!npcType) { lua_pushnil(L); return 1; @@ -256,7 +256,7 @@ int NpcTypeFunctions::luaNpcTypeGetCreatureEvents(lua_State* L) { int NpcTypeFunctions::luaNpcTypeRegisterEvent(lua_State* L) { // npcType:registerEvent(name) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { npcType->info.scripts.push_back(getString(L, 2)); pushBoolean(L, true); @@ -275,7 +275,7 @@ int NpcTypeFunctions::luaNpcTypeEventOnCallback(lua_State* L) { // npcType:onBuyItem(callback) // npcType:onSellItem(callback) // npcType:onCheckItem(callback) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (npcType->loadCallback(&g_scripts().getScriptInterface())) { pushBoolean(L, true); @@ -290,7 +290,7 @@ int NpcTypeFunctions::luaNpcTypeEventOnCallback(lua_State* L) { int NpcTypeFunctions::luaNpcTypeEventType(lua_State* L) { // npcType:eventType(event) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { npcType->info.eventType = getNumber(L, 2); pushBoolean(L, true); @@ -302,7 +302,7 @@ int NpcTypeFunctions::luaNpcTypeEventType(lua_State* L) { int NpcTypeFunctions::luaNpcTypeOutfit(lua_State* L) { // get: npcType:outfit() set: npcType:outfit(outfit) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { pushOutfit(L, npcType->info.outfit); @@ -324,7 +324,7 @@ int NpcTypeFunctions::luaNpcTypeOutfit(lua_State* L) { int NpcTypeFunctions::luaNpcTypeBaseSpeed(lua_State* L) { // npcType:getBaseSpeed() - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.baseSpeed); @@ -340,7 +340,7 @@ int NpcTypeFunctions::luaNpcTypeBaseSpeed(lua_State* L) { int NpcTypeFunctions::luaNpcTypeWalkInterval(lua_State* L) { // get: npcType:walkInterval() set: npcType:walkInterval(interval) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.walkInterval); @@ -356,7 +356,7 @@ int NpcTypeFunctions::luaNpcTypeWalkInterval(lua_State* L) { int NpcTypeFunctions::luaNpcTypeWalkRadius(lua_State* L) { // get: npcType:walkRadius() set: npcType:walkRadius(id) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.walkRadius); @@ -372,7 +372,7 @@ int NpcTypeFunctions::luaNpcTypeWalkRadius(lua_State* L) { int NpcTypeFunctions::luaNpcTypeLight(lua_State* L) { // get: npcType:light() set: npcType:light(color, level) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (!npcType) { lua_pushnil(L); return 1; @@ -392,7 +392,7 @@ int NpcTypeFunctions::luaNpcTypeLight(lua_State* L) { int NpcTypeFunctions::luaNpcTypeYellChance(lua_State* L) { // get: npcType:yellChance() set: npcType:yellChance(chance) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { if (lua_gettop(L) == 1) { @@ -413,7 +413,7 @@ int NpcTypeFunctions::luaNpcTypeYellChance(lua_State* L) { int NpcTypeFunctions::luaNpcTypeYellSpeedTicks(lua_State* L) { // get: npcType:yellSpeedTicks() set: npcType:yellSpeedTicks(rate) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.yellSpeedTicks); @@ -433,7 +433,7 @@ int NpcTypeFunctions::luaNpcTypeYellSpeedTicks(lua_State* L) { int NpcTypeFunctions::luaNpcTypeRespawnTypePeriod(lua_State* L) { // npcType:respawnTypePeriod() - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.respawnType.period); @@ -449,7 +449,7 @@ int NpcTypeFunctions::luaNpcTypeRespawnTypePeriod(lua_State* L) { int NpcTypeFunctions::luaNpcTypeRespawnTypeIsUnderground(lua_State* L) { // npcType:respawnTypeIsUnderground() - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.respawnType.underground); @@ -466,7 +466,7 @@ int NpcTypeFunctions::luaNpcTypeRespawnTypeIsUnderground(lua_State* L) { int NpcTypeFunctions::luaNpcTypeSpeechBubble(lua_State* L) { // get = npcType:speechBubble() // set = npcType:speechBubble(newSpeechBubble) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (!npcType) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); pushBoolean(L, false); @@ -485,7 +485,7 @@ int NpcTypeFunctions::luaNpcTypeSpeechBubble(lua_State* L) { int NpcTypeFunctions::luaNpcTypeCurrency(lua_State* L) { // get = npcType:currency() // set = npcType:currency(newCurrency) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (!npcType) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); pushBoolean(L, false); @@ -503,7 +503,7 @@ int NpcTypeFunctions::luaNpcTypeCurrency(lua_State* L) { int NpcTypeFunctions::luaNpcTypeSoundChance(lua_State* L) { // get: npcType:soundChance() set: npcType:soundChance(chance) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (!npcType) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); pushBoolean(L, false); @@ -521,7 +521,7 @@ int NpcTypeFunctions::luaNpcTypeSoundChance(lua_State* L) { int NpcTypeFunctions::luaNpcTypeSoundSpeedTicks(lua_State* L) { // get: npcType:soundSpeedTicks() set: npcType:soundSpeedTicks(ticks) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (!npcType) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); pushBoolean(L, false); @@ -539,7 +539,7 @@ int NpcTypeFunctions::luaNpcTypeSoundSpeedTicks(lua_State* L) { int NpcTypeFunctions::luaNpcTypeAddSound(lua_State* L) { // npcType:addSound(soundId) - NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (!npcType) { reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); pushBoolean(L, false); @@ -553,7 +553,7 @@ int NpcTypeFunctions::luaNpcTypeAddSound(lua_State* L) { int NpcTypeFunctions::luaNpcTypeGetSounds(lua_State* L) { // npcType:getSounds() - const NpcType* npcType = getUserdata(L, 1); + const auto &npcType = getUserdataShared(L, 1); if (!npcType) { lua_pushnil(L); return 1; From d2ab35f8fdddbce729b648c6190c6472937883c0 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 17:50:59 -0300 Subject: [PATCH 54/67] SpawnNpc to smart pointer --- src/creatures/npcs/npc.hpp | 6 +++--- src/creatures/npcs/npcs.hpp | 2 +- src/creatures/npcs/spawns/spawn_npc.cpp | 18 ++++++++---------- src/creatures/npcs/spawns/spawn_npc.hpp | 6 +++--- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/creatures/npcs/npc.hpp b/src/creatures/npcs/npc.hpp index c55fff0911c..45941706f65 100644 --- a/src/creatures/npcs/npc.hpp +++ b/src/creatures/npcs/npc.hpp @@ -112,8 +112,8 @@ class Npc final : public Creature { RespawnType getRespawnType() const { return npcType->info.respawnType; } - void setSpawnNpc(SpawnNpc* newSpawn) { - this->spawnNpc = newSpawn; + void setSpawnNpc(const std::shared_ptr &newSpawn) { + spawnNpc = newSpawn; } void setPlayerInteraction(uint32_t playerId, uint16_t topicId = 0); @@ -178,7 +178,7 @@ class Npc final : public Creature { phmap::flat_hash_map> shopPlayerMap; std::shared_ptr npcType; - SpawnNpc* spawnNpc = nullptr; + std::shared_ptr spawnNpc; uint8_t speechBubble; diff --git a/src/creatures/npcs/npcs.hpp b/src/creatures/npcs/npcs.hpp index 472af4e89ad..d836e6e9252 100644 --- a/src/creatures/npcs/npcs.hpp +++ b/src/creatures/npcs/npcs.hpp @@ -23,7 +23,7 @@ class Shop { ShopBlock shopBlock; }; -class NpcType { +class NpcType : public SharedObject { struct NpcInfo { LuaScriptInterface* scriptInterface; diff --git a/src/creatures/npcs/spawns/spawn_npc.cpp b/src/creatures/npcs/spawns/spawn_npc.cpp index 36430ec025e..c7605f36c06 100644 --- a/src/creatures/npcs/spawns/spawn_npc.cpp +++ b/src/creatures/npcs/spawns/spawn_npc.cpp @@ -56,8 +56,7 @@ bool SpawnsNpc::loadFromXml(const std::string &fileNpcName) { continue; } - spawnNpcList.emplace_front(centerPos, radius); - SpawnNpc &spawnNpc = spawnNpcList.front(); + const auto &spawnNpc = spawnNpcList.emplace_front(std::make_shared(centerPos, radius)); for (auto childNode : spawnNode.children()) { if (strcasecmp(childNode.name(), "npc") == 0) { @@ -84,7 +83,7 @@ bool SpawnsNpc::loadFromXml(const std::string &fileNpcName) { ); int64_t interval = pugi::cast(childNode.attribute("spawntime").value()) * 1000; if (interval >= MINSPAWN_INTERVAL && interval <= MAXSPAWN_INTERVAL) { - spawnNpc.addNpc(nameAttribute.as_string(), pos, dir, static_cast(interval)); + spawnNpc->addNpc(nameAttribute.as_string(), pos, dir, static_cast(interval)); } else { if (interval <= MINSPAWN_INTERVAL) { g_logger().warn("[SpawnsNpc::loadFromXml] - {} {} spawntime can not be less than {} seconds", nameAttribute.as_string(), pos.toString(), MINSPAWN_INTERVAL / 1000); @@ -103,16 +102,16 @@ void SpawnsNpc::startup() { return; } - for (SpawnNpc &spawnNpc : spawnNpcList) { - spawnNpc.startup(); + for (const auto &spawnNpc : spawnNpcList) { + spawnNpc->startup(); } setStarted(true); } void SpawnsNpc::clear() { - for (SpawnNpc &spawnNpc : spawnNpcList) { - spawnNpc.stopEvent(); + for (const auto &spawnNpc : spawnNpcList) { + spawnNpc->stopEvent(); } spawnNpcList.clear(); @@ -137,8 +136,7 @@ void SpawnNpc::startSpawnNpcCheck() { SpawnNpc::~SpawnNpc() { for (const auto &it : spawnedNpcMap) { - auto npc = it.second; - npc->setSpawnNpc(nullptr); + it.second->setSpawnNpc(nullptr); } } @@ -171,7 +169,7 @@ bool SpawnNpc::spawnNpc(uint32_t spawnId, const std::shared_ptr &npcTyp } npc->setDirection(dir); - npc->setSpawnNpc(this); + npc->setSpawnNpc(static_self_cast()); npc->setMasterPos(pos); spawnedNpcMap.insert(spawned_pair(spawnId, npc)); diff --git a/src/creatures/npcs/spawns/spawn_npc.hpp b/src/creatures/npcs/spawns/spawn_npc.hpp index eeb5c2edcd2..dccc1a75e62 100644 --- a/src/creatures/npcs/spawns/spawn_npc.hpp +++ b/src/creatures/npcs/spawns/spawn_npc.hpp @@ -23,7 +23,7 @@ struct spawnBlockNpc_t { Direction direction; }; -class SpawnNpc { +class SpawnNpc : public SharedObject { public: SpawnNpc(Position initPos, int32_t initRadius) : centerPos(std::move(initPos)), radius(initRadius) { } @@ -94,12 +94,12 @@ class SpawnsNpc { return fileName = setName; } - std::forward_list &getSpawnNpcList() { + std::forward_list> &getSpawnNpcList() { return spawnNpcList; } private: - std::forward_list spawnNpcList; + std::forward_list> spawnNpcList; std::string fileName; bool loaded = false; bool started = false; From d40ee19409722d4c96dd3c3e76a0336143541c20 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 17:51:57 -0300 Subject: [PATCH 55/67] Update npc_type_functions.hpp --- src/lua/functions/creatures/npc/npc_type_functions.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua/functions/creatures/npc/npc_type_functions.hpp b/src/lua/functions/creatures/npc/npc_type_functions.hpp index 4a3a44e5d24..a6646b7b2f4 100644 --- a/src/lua/functions/creatures/npc/npc_type_functions.hpp +++ b/src/lua/functions/creatures/npc/npc_type_functions.hpp @@ -14,7 +14,7 @@ class NpcTypeFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "NpcType", "", NpcTypeFunctions::luaNpcTypeCreate); + registerSharedClass(L, "NpcType", "", NpcTypeFunctions::luaNpcTypeCreate); registerMetaMethod(L, "NpcType", "__eq", NpcTypeFunctions::luaUserdataCompare); registerMethod(L, "NpcType", "isPushable", NpcTypeFunctions::luaNpcTypeIsPushable); From 363e9029367786e78a8e58bc0ecfdfacfcf278c6 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 17:56:42 -0300 Subject: [PATCH 56/67] shop to smart pointer --- .../creatures/npc/shop_functions.cpp | 48 +++++-------------- .../creatures/npc/shop_functions.hpp | 6 +-- 2 files changed, 14 insertions(+), 40 deletions(-) diff --git a/src/lua/functions/creatures/npc/shop_functions.cpp b/src/lua/functions/creatures/npc/shop_functions.cpp index 61330ba5a63..66de7afd962 100644 --- a/src/lua/functions/creatures/npc/shop_functions.cpp +++ b/src/lua/functions/creatures/npc/shop_functions.cpp @@ -14,30 +14,15 @@ int ShopFunctions::luaCreateShop(lua_State* L) { // Shop() will create a new shop item - Shop* shop = new Shop(); - if (shop) { - pushUserdata(L, shop); - setMetatable(L, -1, "Shop"); - } else { - lua_pushnil(L); - } + pushUserdata(L, std::make_shared()); + setMetatable(L, -1, "Shop"); return 1; } -int ShopFunctions::luaDeleteShop(lua_State* L) { - // shop:delete() shop:__gc() - Shop** shopPtr = getRawUserdata(L, 1); - if (shopPtr && *shopPtr) { - delete *shopPtr; - *shopPtr = nullptr; - } - return 0; -} - int ShopFunctions::luaShopSetId(lua_State* L) { // shop:setId(id) - Shop* shop = getUserdata(L, 1); - if (shop) { + + if (const auto &shop = getUserdataShared(L, 1)) { if (isNumber(L, 2)) { shop->shopBlock.itemId = getNumber(L, 2); pushBoolean(L, true); @@ -54,7 +39,7 @@ int ShopFunctions::luaShopSetId(lua_State* L) { int ShopFunctions::luaShopSetIdFromName(lua_State* L) { // shop:setIdFromName(name) - Shop* shop = getUserdata(L, 1); + const auto &shop = getUserdataShared(L, 1); if (shop && isString(L, 2)) { auto name = getString(L, 2); auto ids = Item::items.nameToItems.equal_range(asLowerCaseString(name)); @@ -87,8 +72,7 @@ int ShopFunctions::luaShopSetIdFromName(lua_State* L) { int ShopFunctions::luaShopSetNameItem(lua_State* L) { // shop:setNameItem(name) - Shop* shop = getUserdata(L, 1); - if (shop) { + if (const auto &shop = getUserdataShared(L, 1)) { shop->shopBlock.itemName = getString(L, 2); pushBoolean(L, true); } else { @@ -99,8 +83,7 @@ int ShopFunctions::luaShopSetNameItem(lua_State* L) { int ShopFunctions::luaShopSetCount(lua_State* L) { // shop:setCount(count) - Shop* shop = getUserdata(L, 1); - if (shop) { + if (const auto &shop = getUserdataShared(L, 1)) { shop->shopBlock.itemSubType = getNumber(L, 2); pushBoolean(L, true); } else { @@ -111,8 +94,7 @@ int ShopFunctions::luaShopSetCount(lua_State* L) { int ShopFunctions::luaShopSetBuyPrice(lua_State* L) { // shop:setBuyPrice(price) - Shop* shop = getUserdata(L, 1); - if (shop) { + if (const auto &shop = getUserdataShared(L, 1)) { shop->shopBlock.itemBuyPrice = getNumber(L, 2); pushBoolean(L, true); } else { @@ -123,8 +105,7 @@ int ShopFunctions::luaShopSetBuyPrice(lua_State* L) { int ShopFunctions::luaShopSetSellPrice(lua_State* L) { // shop:setSellPrice(chance) - Shop* shop = getUserdata(L, 1); - if (shop) { + if (const auto &shop = getUserdataShared(L, 1)) { shop->shopBlock.itemSellPrice = getNumber(L, 2); pushBoolean(L, true); } else { @@ -135,8 +116,7 @@ int ShopFunctions::luaShopSetSellPrice(lua_State* L) { int ShopFunctions::luaShopSetStorageKey(lua_State* L) { // shop:setStorageKey(storage) - Shop* shop = getUserdata(L, 1); - if (shop) { + if (const auto &shop = getUserdataShared(L, 1)) { shop->shopBlock.itemStorageKey = getNumber(L, 2); pushBoolean(L, true); } else { @@ -147,8 +127,7 @@ int ShopFunctions::luaShopSetStorageKey(lua_State* L) { int ShopFunctions::luaShopSetStorageValue(lua_State* L) { // shop:setStorageValue(value) - Shop* shop = getUserdata(L, 1); - if (shop) { + if (const auto &shop = getUserdataShared(L, 1)) { shop->shopBlock.itemStorageValue = getNumber(L, 2); pushBoolean(L, true); } else { @@ -159,9 +138,8 @@ int ShopFunctions::luaShopSetStorageValue(lua_State* L) { int ShopFunctions::luaShopAddChildShop(lua_State* L) { // shop:addChildShop(shop) - Shop* shop = getUserdata(L, 1); - if (shop) { - shop->shopBlock.childShop.push_back(getUserdata(L, 2)->shopBlock); + if (const auto &shop = getUserdataShared(L, 1)) { + shop->shopBlock.childShop.push_back(getUserdataShared(L, 2)->shopBlock); } else { lua_pushnil(L); } diff --git a/src/lua/functions/creatures/npc/shop_functions.hpp b/src/lua/functions/creatures/npc/shop_functions.hpp index 0ec0cefb5c3..1ffb53c92dc 100644 --- a/src/lua/functions/creatures/npc/shop_functions.hpp +++ b/src/lua/functions/creatures/npc/shop_functions.hpp @@ -14,10 +14,7 @@ class ShopFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "Shop", "", ShopFunctions::luaCreateShop); - registerMetaMethod(L, "Shop", "__gc", ShopFunctions::luaDeleteShop); - registerMethod(L, "Shop", "delete", ShopFunctions::luaDeleteShop); - + registerSharedClass(L, "Shop", "", ShopFunctions::luaCreateShop); registerMethod(L, "Shop", "setId", ShopFunctions::luaShopSetId); registerMethod(L, "Shop", "setIdFromName", ShopFunctions::luaShopSetIdFromName); registerMethod(L, "Shop", "setNameItem", ShopFunctions::luaShopSetNameItem); @@ -31,7 +28,6 @@ class ShopFunctions final : LuaScriptInterface { private: static int luaCreateShop(lua_State* L); - static int luaDeleteShop(lua_State* L); static int luaShopSetId(lua_State* L); static int luaShopSetIdFromName(lua_State* L); static int luaShopSetNameItem(lua_State* L); From 4bd1f43d8a713187e8323ed700dbd2725ecac881 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 18:07:02 -0300 Subject: [PATCH 57/67] town to smart pointer --- src/creatures/players/player.hpp | 6 +++--- src/io/functions/iologindata_load_player.cpp | 2 +- .../creatures/player/player_functions.cpp | 2 +- src/lua/functions/map/house_functions.cpp | 3 +-- src/lua/functions/map/town_functions.cpp | 11 ++++------- src/lua/functions/map/town_functions.hpp | 2 +- src/map/house/house.cpp | 2 +- src/map/town.hpp | 19 +++++++------------ 8 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 957545a265a..b7bb64b588c 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -634,10 +634,10 @@ class Player final : public Creature, public Cylinder, public Bankable { const Position &getTemplePosition() const { return town->getTemplePosition(); } - Town* getTown() const { + std::shared_ptr getTown() const { return town; } - void setTown(Town* newTown) { + void setTown(const std::shared_ptr &newTown) { this->town = newTown; } @@ -2661,7 +2661,7 @@ class Player final : public Creature, public Cylinder, public Bankable { std::shared_ptr tradePartner = nullptr; ProtocolGame_ptr client; std::shared_ptr walkTask; - Town* town = nullptr; + std::shared_ptr town; Vocation* vocation = nullptr; std::shared_ptr rewardChest = nullptr; diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index f072c5d5707..0fa1cd86795 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -162,7 +162,7 @@ bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr player, DBResult_p player->offlineTrainingTime = result->getNumber("offlinetraining_time") * 1000; auto skill = result->getInt8FromString(result->getString("offlinetraining_skill"), __FUNCTION__); player->setOfflineTrainingSkill(skill); - Town* town = g_game().map.towns.getTown(result->getNumber("town_id")); + const auto &town = g_game().map.towns.getTown(result->getNumber("town_id")); if (!town) { g_logger().error("Player {} has town id {} which doesn't exist", player->name, result->getNumber("town_id")); return false; diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 795654cd750..4425a6373e2 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -1444,7 +1444,7 @@ int PlayerFunctions::luaPlayerGetTown(lua_State* L) { int PlayerFunctions::luaPlayerSetTown(lua_State* L) { // player:setTown(town) - Town* town = getUserdata(L, 2); + const auto &town = getUserdataShared(L, 2); if (!town) { pushBoolean(L, false); return 1; diff --git a/src/lua/functions/map/house_functions.cpp b/src/lua/functions/map/house_functions.cpp index b8f188d11f0..b86c99ac131 100644 --- a/src/lua/functions/map/house_functions.cpp +++ b/src/lua/functions/map/house_functions.cpp @@ -58,8 +58,7 @@ int HouseFunctions::luaHouseGetTown(lua_State* L) { return 1; } - Town* town = g_game().map.towns.getTown(house->getTownId()); - if (town) { + if (const auto &town = g_game().map.towns.getTown(house->getTownId())) { pushUserdata(L, town); setMetatable(L, -1, "Town"); } else { diff --git a/src/lua/functions/map/town_functions.cpp b/src/lua/functions/map/town_functions.cpp index 44dfc493477..f50042c1566 100644 --- a/src/lua/functions/map/town_functions.cpp +++ b/src/lua/functions/map/town_functions.cpp @@ -15,7 +15,7 @@ int TownFunctions::luaTownCreate(lua_State* L) { // Town(id or name) - Town* town; + std::shared_ptr town; if (isNumber(L, 2)) { town = g_game().map.towns.getTown(getNumber(L, 2)); } else if (isString(L, 2)) { @@ -35,8 +35,7 @@ int TownFunctions::luaTownCreate(lua_State* L) { int TownFunctions::luaTownGetId(lua_State* L) { // town:getId() - Town* town = getUserdata(L, 1); - if (town) { + if (const auto &town = getUserdataShared(L, 1)) { lua_pushnumber(L, town->getID()); } else { lua_pushnil(L); @@ -46,8 +45,7 @@ int TownFunctions::luaTownGetId(lua_State* L) { int TownFunctions::luaTownGetName(lua_State* L) { // town:getName() - Town* town = getUserdata(L, 1); - if (town) { + if (const auto &town = getUserdataShared(L, 1)) { pushString(L, town->getName()); } else { lua_pushnil(L); @@ -57,8 +55,7 @@ int TownFunctions::luaTownGetName(lua_State* L) { int TownFunctions::luaTownGetTemplePosition(lua_State* L) { // town:getTemplePosition() - Town* town = getUserdata(L, 1); - if (town) { + if (const auto &town = getUserdataShared(L, 1)) { pushPosition(L, town->getTemplePosition()); } else { lua_pushnil(L); diff --git a/src/lua/functions/map/town_functions.hpp b/src/lua/functions/map/town_functions.hpp index 68be86689e4..4f60eeab28e 100644 --- a/src/lua/functions/map/town_functions.hpp +++ b/src/lua/functions/map/town_functions.hpp @@ -14,7 +14,7 @@ class TownFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "Town", "", TownFunctions::luaTownCreate); + registerSharedClass(L, "Town", "", TownFunctions::luaTownCreate); registerMetaMethod(L, "Town", "__eq", TownFunctions::luaUserdataCompare); registerMethod(L, "Town", "getId", TownFunctions::luaTownGetId); diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index 956c18454cf..fc5251f8ade 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -661,7 +661,7 @@ void Houses::payHouses(RentPeriod_t rentPeriod) const { } const uint32_t ownerId = house->getOwner(); - const Town* town = g_game().map.towns.getTown(house->getTownId()); + const auto &town = g_game().map.towns.getTown(house->getTownId()); if (!town) { continue; } diff --git a/src/map/town.hpp b/src/map/town.hpp index 8e56308cef9..f6ab241b54b 100644 --- a/src/map/town.hpp +++ b/src/map/town.hpp @@ -39,26 +39,22 @@ class Town { Position templePosition; }; -using TownMap = std::map; +using TownMap = std::map>; class Towns { public: Towns() = default; - ~Towns() { - for (const auto &it : townMap) { - delete it.second; - } - } + ~Towns() = default; // non-copyable Towns(const Towns &) = delete; Towns &operator=(const Towns &) = delete; - bool addTown(uint32_t townId, Town* town) { + bool addTown(uint32_t townId, const std::shared_ptr &town) { return townMap.emplace(townId, town).second; } - Town* getTown(const std::string &townName) const { + std::shared_ptr getTown(const std::string &townName) const { for (const auto &it : townMap) { if (strcasecmp(townName.c_str(), it.second->getName().c_str()) == 0) { return it.second; @@ -67,7 +63,7 @@ class Towns { return nullptr; } - Town* getTown(uint32_t townId) const { + std::shared_ptr getTown(uint32_t townId) const { auto it = townMap.find(townId); if (it == townMap.end()) { return nullptr; @@ -75,11 +71,10 @@ class Towns { return it->second; } - Town* getOrCreateTown(uint32_t townId) { + std::shared_ptr getOrCreateTown(uint32_t townId) { auto town = getTown(townId); if (!town) { - town = new Town(townId); - addTown(townId, town); + addTown(townId, town = std::make_shared(townId)); } return town; } From 0d5365ae2c258d44fc8bc15823e43939e363f0aa Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 18:08:29 -0300 Subject: [PATCH 58/67] registerSharedClass combat --- src/lua/functions/creatures/combat/combat_functions.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua/functions/creatures/combat/combat_functions.hpp b/src/lua/functions/creatures/combat/combat_functions.hpp index b6816c565ed..652255d7ae4 100644 --- a/src/lua/functions/creatures/combat/combat_functions.hpp +++ b/src/lua/functions/creatures/combat/combat_functions.hpp @@ -17,7 +17,7 @@ class CombatFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "Combat", "", CombatFunctions::luaCombatCreate); + registerSharedClass(L, "Combat", "", CombatFunctions::luaCombatCreate); registerMetaMethod(L, "Combat", "__eq", CombatFunctions::luaUserdataCompare); registerMethod(L, "Combat", "setParameter", CombatFunctions::luaCombatSetParameter); From 2aaf42f8754e2a55efc72eb207f95e195b8446aa Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 18:24:12 -0300 Subject: [PATCH 59/67] house to smart pointer --- src/creatures/players/player.cpp | 6 +- src/creatures/players/player.hpp | 8 +-- src/game/game.cpp | 16 +++--- src/game/game.hpp | 4 +- src/io/iomapserialize.cpp | 5 +- src/items/bed.hpp | 4 +- src/items/tile.hpp | 2 +- .../creatures/player/player_functions.cpp | 6 +- src/lua/functions/map/house_functions.cpp | 56 ++++++++----------- src/lua/functions/map/house_functions.hpp | 2 +- src/map/house/house.cpp | 18 +++--- src/map/house/house.hpp | 32 +++++------ src/map/house/housetile.cpp | 2 +- src/map/house/housetile.hpp | 6 +- 14 files changed, 75 insertions(+), 92 deletions(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 6d504304ff2..354c368ef1f 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -1291,19 +1291,19 @@ void Player::setWriteItem(std::shared_ptr item, uint16_t maxWriteLength /* } } -House* Player::getEditHouse(uint32_t &retWindowTextId, uint32_t &retListId) { +std::shared_ptr Player::getEditHouse(uint32_t &retWindowTextId, uint32_t &retListId) { retWindowTextId = this->windowTextId; retListId = this->editListId; return editHouse; } -void Player::setEditHouse(House* house, uint32_t listId /*= 0*/) { +void Player::setEditHouse(std::shared_ptr house, uint32_t listId /*= 0*/) { windowTextId++; editHouse = house; editListId = listId; } -void Player::sendHouseWindow(House* house, uint32_t listId) const { +void Player::sendHouseWindow(std::shared_ptr house, uint32_t listId) const { if (!client) { return; } diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index b7bb64b588c..f8347cdd6be 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -1301,7 +1301,7 @@ class Player final : public Creature, public Cylinder, public Bankable { client->sendDistanceShoot(from, to, type); } } - void sendHouseWindow(House* house, uint32_t listId) const; + void sendHouseWindow(std::shared_ptr house, uint32_t listId) const; void sendCreatePrivateChannel(uint16_t channelId, const std::string &channelName) { if (client) { client->sendCreatePrivateChannel(channelId, channelName); @@ -1669,8 +1669,8 @@ class Player final : public Creature, public Cylinder, public Bankable { std::shared_ptr getWriteItem(uint32_t &windowTextId, uint16_t &maxWriteLen); void setWriteItem(std::shared_ptr item, uint16_t maxWriteLen = 0); - House* getEditHouse(uint32_t &windowTextId, uint32_t &listId); - void setEditHouse(House* house, uint32_t listId = 0); + std::shared_ptr getEditHouse(uint32_t &windowTextId, uint32_t &listId); + void setEditHouse(std::shared_ptr house, uint32_t listId = 0); void learnInstantSpell(const std::string &spellName); void forgetInstantSpell(const std::string &spellName); @@ -2655,7 +2655,7 @@ class Player final : public Creature, public Cylinder, public Bankable { std::shared_ptr tradeItem = nullptr; std::shared_ptr inventory[CONST_SLOT_LAST + 1] = {}; std::shared_ptr writeItem = nullptr; - House* editHouse = nullptr; + std::shared_ptr editHouse = nullptr; std::shared_ptr shopOwner = nullptr; std::shared_ptr party = nullptr; std::shared_ptr tradePartner = nullptr; diff --git a/src/game/game.cpp b/src/game/game.cpp index 7d877557620..70c03fcdeba 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -102,7 +102,7 @@ namespace InternalGame { } if (std::shared_ptr houseTile = std::dynamic_pointer_cast(itemTile)) { - House* house = houseTile->getHouse(); + const auto &house = houseTile->getHouse(); if (!house || !house->isInvited(player)) { return false; } @@ -136,7 +136,7 @@ namespace InternalGame { if (g_configManager().getBoolean(ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { if (std::shared_ptr houseTile = std::dynamic_pointer_cast(itemTile)) { - House* house = houseTile->getHouse(); + const auto &house = houseTile->getHouse(); std::shared_ptr targetThing = g_game().internalGetThing(player, toPos, toStackPos, toItemId, STACKPOS_FIND_THING); auto targetItem = targetThing ? targetThing->getItem() : nullptr; uint16_t targetId = targetItem ? targetItem->getID() : 0; @@ -3392,7 +3392,7 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin if (g_configManager().getBoolean(ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { if (std::shared_ptr houseTile = std::dynamic_pointer_cast(item->getTile())) { - House* house = houseTile->getHouse(); + const auto &house = houseTile->getHouse(); if (house && item->getRealParent() && item->getRealParent() != player && (!house->isInvited(player) || house->getHouseAccessLevel(player) == HOUSE_GUEST)) { player->sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT); return; @@ -3766,7 +3766,7 @@ void Game::playerWrapableItem(uint32_t playerId, const Position &pos, uint8_t st return; } - House* house = map.houses.getHouseByPlayerId(player->getGUID()); + const auto &house = map.houses.getHouseByPlayerId(player->getGUID()); if (!house) { player->sendCancelMessage("You don't own a house, you need own a house to use this."); return; @@ -3843,7 +3843,7 @@ void Game::playerWrapableItem(uint32_t playerId, const Position &pos, uint8_t st addMagicEffect(pos, CONST_ME_POFF); } -std::shared_ptr Game::wrapItem(std::shared_ptr item, House* house) { +std::shared_ptr Game::wrapItem(std::shared_ptr item, std::shared_ptr house) { uint16_t hiddenCharges = 0; uint16_t amount = item->getItemCount(); if (isCaskItem(item->getID())) { @@ -3867,7 +3867,7 @@ std::shared_ptr Game::wrapItem(std::shared_ptr item, House* house) { return newItem; } -void Game::unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* house, std::shared_ptr player) { +void Game::unwrapItem(std::shared_ptr item, uint16_t unWrapId, std::shared_ptr house, std::shared_ptr player) { auto hiddenCharges = item->getAttribute(DATE); const ItemType &newiType = Item::items.getItemType(unWrapId); if (player != nullptr && house != nullptr && newiType.isBed() && house->getMaxBeds() > -1 && house->getBedCount() >= house->getMaxBeds()) { @@ -4152,7 +4152,7 @@ void Game::playerUpdateHouseWindow(uint32_t playerId, uint8_t listId, uint32_t w uint32_t internalWindowTextId; uint32_t internalListId; - House* house = player->getEditHouse(internalWindowTextId, internalListId); + const auto &house = player->getEditHouse(internalWindowTextId, internalListId); if (house && house->canEditAccessList(internalListId, player) && internalWindowTextId == windowTextId && listId == 0) { house->setAccessList(internalListId, text); } @@ -4198,7 +4198,7 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st if (g_configManager().getBoolean(ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { if (std::shared_ptr houseTile = std::dynamic_pointer_cast(tradeItem->getTile())) { - House* house = houseTile->getHouse(); + const auto &house = houseTile->getHouse(); if (house && tradeItem->getRealParent() != player && (!house->isInvited(player) || house->getHouseAccessLevel(player) == HOUSE_GUEST)) { player->sendCancelMessage(RETURNVALUE_NOTMOVEABLE); return; diff --git a/src/game/game.hpp b/src/game/game.hpp index 9ab683d15d5..2db44312746 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -595,7 +595,7 @@ class Game { bool addInfluencedMonster(std::shared_ptr monster); void sendUpdateCreature(std::shared_ptr creature); - std::shared_ptr wrapItem(std::shared_ptr item, House* house); + std::shared_ptr wrapItem(std::shared_ptr item, std::shared_ptr house); /** * @brief Adds a player to the unique login map. @@ -865,7 +865,7 @@ class Game { const std::string &damageString, std::string &spectatorMessage ) const; - void unwrapItem(std::shared_ptr item, uint16_t unWrapId, House* house, std::shared_ptr player); + void unwrapItem(std::shared_ptr item, uint16_t unWrapId, std::shared_ptr house, std::shared_ptr player); // Variable members (m_) std::unique_ptr m_IOWheel; diff --git a/src/io/iomapserialize.cpp b/src/io/iomapserialize.cpp index ca382c9215d..efde02c390f 100644 --- a/src/io/iomapserialize.cpp +++ b/src/io/iomapserialize.cpp @@ -141,7 +141,6 @@ bool IOMapSerialize::loadItem(PropStream &propStream, std::shared_ptr if (item->unserializeAttr(propStream)) { std::shared_ptr container = item->getContainer(); if (container && !loadContainer(propStream, container)) { - return false; } @@ -265,7 +264,7 @@ bool IOMapSerialize::loadHouseInfo() { } do { - House* house = g_game().map.houses.getHouse(result->getNumber("id")); + const auto &house = g_game().map.houses.getHouse(result->getNumber("id")); if (house) { house->setOwner(result->getNumber("owner"), false); house->setPaidUntil(result->getNumber("paid")); @@ -276,7 +275,7 @@ bool IOMapSerialize::loadHouseInfo() { result = db.storeQuery("SELECT `house_id`, `listid`, `list` FROM `house_lists`"); if (result) { do { - House* house = g_game().map.houses.getHouse(result->getNumber("house_id")); + const auto &house = g_game().map.houses.getHouse(result->getNumber("house_id")); if (house) { house->setAccessList(result->getNumber("listid"), result->getString("list")); } diff --git a/src/items/bed.hpp b/src/items/bed.hpp index bdacbd88204..6fafe858a90 100644 --- a/src/items/bed.hpp +++ b/src/items/bed.hpp @@ -33,7 +33,7 @@ class BedItem final : public Item { return sleeperGUID; } - void setHouse(House* h) { + void setHouse(const std::shared_ptr &h) { house = h; } @@ -53,7 +53,7 @@ class BedItem final : public Item { void internalSetSleeper(std::shared_ptr player); void internalRemoveSleeper(); - House* house = nullptr; + std::shared_ptr house; uint64_t sleepStart; uint32_t sleeperGUID; }; diff --git a/src/items/tile.hpp b/src/items/tile.hpp index 900f16788d8..35f5e36232a 100644 --- a/src/items/tile.hpp +++ b/src/items/tile.hpp @@ -118,7 +118,7 @@ class Tile : public Cylinder, public SharedObject { virtual CreatureVector* getCreatures() = 0; virtual const CreatureVector* getCreatures() const = 0; virtual CreatureVector* makeCreatures() = 0; - virtual House* getHouse() { + virtual std::shared_ptr getHouse() { return nullptr; } diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 4425a6373e2..a69891a9369 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -2878,7 +2878,7 @@ int PlayerFunctions::luaPlayerGetHouse(lua_State* L) { return 1; } - House* house = g_game().map.houses.getHouseByPlayerId(player->getGUID()); + const auto &house = g_game().map.houses.getHouseByPlayerId(player->getGUID()); if (house) { pushUserdata(L, house); setMetatable(L, -1, "House"); @@ -2896,7 +2896,7 @@ int PlayerFunctions::luaPlayerSendHouseWindow(lua_State* L) { return 1; } - House* house = getUserdata(L, 2); + const auto &house = getUserdataShared(L, 2); if (!house) { lua_pushnil(L); return 1; @@ -2916,7 +2916,7 @@ int PlayerFunctions::luaPlayerSetEditHouse(lua_State* L) { return 1; } - House* house = getUserdata(L, 2); + const auto &house = getUserdataShared(L, 2); if (!house) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/map/house_functions.cpp b/src/lua/functions/map/house_functions.cpp index b86c99ac131..b94e44b8837 100644 --- a/src/lua/functions/map/house_functions.cpp +++ b/src/lua/functions/map/house_functions.cpp @@ -18,8 +18,7 @@ int HouseFunctions::luaHouseCreate(lua_State* L) { // House(id) - House* house = g_game().map.houses.getHouse(getNumber(L, 2)); - if (house) { + if (const auto &house = g_game().map.houses.getHouse(getNumber(L, 2))) { pushUserdata(L, house); setMetatable(L, -1, "House"); } else { @@ -30,8 +29,7 @@ int HouseFunctions::luaHouseCreate(lua_State* L) { int HouseFunctions::luaHouseGetId(lua_State* L) { // house:getId() - House* house = getUserdata(L, 1); - if (house) { + if (const auto &house = getUserdataShared(L, 1)) { lua_pushnumber(L, house->getId()); } else { lua_pushnil(L); @@ -41,8 +39,7 @@ int HouseFunctions::luaHouseGetId(lua_State* L) { int HouseFunctions::luaHouseGetName(lua_State* L) { // house:getName() - House* house = getUserdata(L, 1); - if (house) { + if (const auto &house = getUserdataShared(L, 1)) { pushString(L, house->getName()); } else { lua_pushnil(L); @@ -52,7 +49,7 @@ int HouseFunctions::luaHouseGetName(lua_State* L) { int HouseFunctions::luaHouseGetTown(lua_State* L) { // house:getTown() - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -69,8 +66,7 @@ int HouseFunctions::luaHouseGetTown(lua_State* L) { int HouseFunctions::luaHouseGetExitPosition(lua_State* L) { // house:getExitPosition() - House* house = getUserdata(L, 1); - if (house) { + if (const auto &house = getUserdataShared(L, 1)) { pushPosition(L, house->getEntryPosition()); } else { lua_pushnil(L); @@ -80,8 +76,7 @@ int HouseFunctions::luaHouseGetExitPosition(lua_State* L) { int HouseFunctions::luaHouseGetRent(lua_State* L) { // house:getRent() - House* house = getUserdata(L, 1); - if (house) { + if (const auto &house = getUserdataShared(L, 1)) { lua_pushnumber(L, house->getRent()); } else { lua_pushnil(L); @@ -91,7 +86,7 @@ int HouseFunctions::luaHouseGetRent(lua_State* L) { int HouseFunctions::luaHouseGetPrice(lua_State* L) { // house:getPrice() - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); if (!house) { reportErrorFunc("House not found"); lua_pushnumber(L, 0); @@ -104,8 +99,7 @@ int HouseFunctions::luaHouseGetPrice(lua_State* L) { int HouseFunctions::luaHouseGetOwnerGuid(lua_State* L) { // house:getOwnerGuid() - const House* house = getUserdata(L, 1); - if (house) { + if (const auto &house = getUserdataShared(L, 1)) { lua_pushnumber(L, house->getOwner()); } else { lua_pushnil(L); @@ -115,8 +109,7 @@ int HouseFunctions::luaHouseGetOwnerGuid(lua_State* L) { int HouseFunctions::luaHouseSetOwnerGuid(lua_State* L) { // house:setOwnerGuid(guid[, updateDatabase = true]) - House* house = getUserdata(L, 1); - if (house) { + if (const auto &house = getUserdataShared(L, 1)) { uint32_t guid = getNumber(L, 2); bool updateDatabase = getBoolean(L, 3, true); house->setOwner(guid, updateDatabase); @@ -129,7 +122,7 @@ int HouseFunctions::luaHouseSetOwnerGuid(lua_State* L) { int HouseFunctions::luaHouseStartTrade(lua_State* L) { // house:startTrade(player, tradePartner) - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); std::shared_ptr player = getUserdataShared(L, 2); std::shared_ptr tradePartner = getUserdataShared(L, 3); @@ -175,7 +168,7 @@ int HouseFunctions::luaHouseStartTrade(lua_State* L) { int HouseFunctions::luaHouseGetBeds(lua_State* L) { // house:getBeds() - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -195,8 +188,7 @@ int HouseFunctions::luaHouseGetBeds(lua_State* L) { int HouseFunctions::luaHouseGetBedCount(lua_State* L) { // house:getBedCount() - House* house = getUserdata(L, 1); - if (house) { + if (const auto &house = getUserdataShared(L, 1)) { lua_pushnumber(L, house->getBedCount()); } else { lua_pushnil(L); @@ -206,7 +198,7 @@ int HouseFunctions::luaHouseGetBedCount(lua_State* L) { int HouseFunctions::luaHouseGetDoors(lua_State* L) { // house:getDoors() - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -226,8 +218,7 @@ int HouseFunctions::luaHouseGetDoors(lua_State* L) { int HouseFunctions::luaHouseGetDoorCount(lua_State* L) { // house:getDoorCount() - House* house = getUserdata(L, 1); - if (house) { + if (const auto &house = getUserdataShared(L, 1)) { lua_pushnumber(L, house->getDoors().size()); } else { lua_pushnil(L); @@ -237,7 +228,7 @@ int HouseFunctions::luaHouseGetDoorCount(lua_State* L) { int HouseFunctions::luaHouseGetDoorIdByPosition(lua_State* L) { // house:getDoorIdByPosition(position) - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -254,7 +245,7 @@ int HouseFunctions::luaHouseGetDoorIdByPosition(lua_State* L) { int HouseFunctions::luaHouseGetTiles(lua_State* L) { // house:getTiles() - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -274,7 +265,7 @@ int HouseFunctions::luaHouseGetTiles(lua_State* L) { int HouseFunctions::luaHouseGetItems(lua_State* L) { // house:getItems() - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -299,8 +290,7 @@ int HouseFunctions::luaHouseGetItems(lua_State* L) { int HouseFunctions::luaHouseGetTileCount(lua_State* L) { // house:getTileCount() - House* house = getUserdata(L, 1); - if (house) { + if (const auto &house = getUserdataShared(L, 1)) { lua_pushnumber(L, house->getTiles().size()); } else { lua_pushnil(L); @@ -310,7 +300,7 @@ int HouseFunctions::luaHouseGetTileCount(lua_State* L) { int HouseFunctions::luaHouseCanEditAccessList(lua_State* L) { // house:canEditAccessList(listId, player) - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -325,7 +315,7 @@ int HouseFunctions::luaHouseCanEditAccessList(lua_State* L) { int HouseFunctions::luaHouseGetAccessList(lua_State* L) { // house:getAccessList(listId) - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -343,7 +333,7 @@ int HouseFunctions::luaHouseGetAccessList(lua_State* L) { int HouseFunctions::luaHouseSetAccessList(lua_State* L) { // house:setAccessList(listId, list) - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -358,7 +348,7 @@ int HouseFunctions::luaHouseSetAccessList(lua_State* L) { int HouseFunctions::luaHouseKickPlayer(lua_State* L) { // house:kickPlayer(player, targetPlayer) - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -370,7 +360,7 @@ int HouseFunctions::luaHouseKickPlayer(lua_State* L) { int HouseFunctions::luaHouseIsInvited(lua_State* L) { // house:isInvited(player) - House* house = getUserdata(L, 1); + const auto &house = getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/map/house_functions.hpp b/src/lua/functions/map/house_functions.hpp index 31ef31eb3f6..c9ce1cf2da7 100644 --- a/src/lua/functions/map/house_functions.hpp +++ b/src/lua/functions/map/house_functions.hpp @@ -14,7 +14,7 @@ class HouseFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "House", "", HouseFunctions::luaHouseCreate); + registerSharedClass(L, "House", "", HouseFunctions::luaHouseCreate); registerMetaMethod(L, "House", "__eq", HouseFunctions::luaUserdataCompare); registerMethod(L, "House", "getId", HouseFunctions::luaHouseGetId); diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index fc5251f8ade..47ecd9f71fb 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -172,7 +172,7 @@ bool House::kickPlayer(std::shared_ptr player, std::shared_ptr t } std::shared_ptr houseTile = std::dynamic_pointer_cast(target->getTile()); - if (!houseTile || houseTile->getHouse() != this) { + if (!houseTile || houseTile->getHouse() != static_self_cast()) { return false; } @@ -306,7 +306,7 @@ bool House::isInvited(std::shared_ptr player) { void House::addDoor(std::shared_ptr door) { doorList.push_back(door); - door->setHouse(this); + door->setHouse(static_self_cast()); updateDoorDescription(); } @@ -319,7 +319,7 @@ void House::removeDoor(std::shared_ptr door) { void House::addBed(std::shared_ptr bed) { bedsList.push_back(bed); - bed->setHouse(this); + bed->setHouse(static_self_cast()); } void House::removeBed(std::shared_ptr bed) { @@ -364,7 +364,7 @@ std::shared_ptr House::getTransferItem() { } transfer_container.resetParent(); - transferItem = HouseTransferItem::createHouseTransferItem(this); + transferItem = HouseTransferItem::createHouseTransferItem(static_self_cast()); transfer_container.addThing(transferItem); return transferItem; } @@ -378,7 +378,7 @@ void House::resetTransferItem() { } } -std::shared_ptr HouseTransferItem::createHouseTransferItem(House* house) { +std::shared_ptr HouseTransferItem::createHouseTransferItem(std::shared_ptr house) { std::shared_ptr transferItem = std::make_shared(house); transferItem->setID(ITEM_DOCUMENT_RO); transferItem->setSubType(1); @@ -534,7 +534,7 @@ Attr_ReadValue Door::readAttr(AttrTypes_t attr, PropStream &propStream) { return Item::readAttr(attr, propStream); } -void Door::setHouse(House* newHouse) { +void Door::setHouse(std::shared_ptr newHouse) { if (this->house != nullptr) { return; } @@ -583,7 +583,7 @@ void Door::onRemoved() { } } -House* Houses::getHouseByPlayerId(uint32_t playerId) { +std::shared_ptr Houses::getHouseByPlayerId(uint32_t playerId) { for (const auto &it : houseMap) { if (it.second->getOwner() == playerId) { return it.second; @@ -608,7 +608,7 @@ bool Houses::loadHousesXML(const std::string &filename) { int32_t houseId = pugi::cast(houseIdAttribute.value()); - House* house = getHouse(houseId); + std::shared_ptr house = getHouse(houseId); if (!house) { g_logger().error("[Houses::loadHousesXML] - Unknown house, id: {}", houseId); return false; @@ -650,7 +650,7 @@ void Houses::payHouses(RentPeriod_t rentPeriod) const { time_t currentTime = time(nullptr); for (const auto &it : houseMap) { - House* house = it.second; + std::shared_ptr house = it.second; if (house->getOwner() == 0) { continue; } diff --git a/src/map/house/house.hpp b/src/map/house/house.hpp index d5331001372..a11f93a8936 100644 --- a/src/map/house/house.hpp +++ b/src/map/house/house.hpp @@ -48,7 +48,7 @@ class Door final : public Item { return static_self_cast(); } - House* getHouse() { + std::shared_ptr getHouse() { return house; } @@ -71,9 +71,9 @@ class Door final : public Item { void onRemoved() override; private: - void setHouse(House* house); + void setHouse(std::shared_ptr house); - House* house = nullptr; + std::shared_ptr house = nullptr; std::unique_ptr accessList; friend class House; }; @@ -83,9 +83,9 @@ using HouseBedItemList = std::list>; class HouseTransferItem final : public Item { public: - static std::shared_ptr createHouseTransferItem(House* house); + static std::shared_ptr createHouseTransferItem(std::shared_ptr house); - explicit HouseTransferItem(House* newHouse) : + explicit HouseTransferItem(std::shared_ptr newHouse) : Item(0), house(newHouse) { } void onTradeEvent(TradeEvents_t event, std::shared_ptr owner) override; @@ -94,10 +94,10 @@ class HouseTransferItem final : public Item { } private: - House* house; + std::shared_ptr house; }; -class House { +class House : public SharedObject { public: explicit House(uint32_t houseId); @@ -245,32 +245,26 @@ class House { void handleWrapableItem(ItemList &moveItemList, std::shared_ptr item, std::shared_ptr player, std::shared_ptr houseTile) const; }; -using HouseMap = std::map; +using HouseMap = std::map>; class Houses { public: Houses() = default; - ~Houses() { - for (const auto &it : houseMap) { - delete it.second; - } - } + ~Houses() = default; // non-copyable Houses(const Houses &) = delete; Houses &operator=(const Houses &) = delete; - House* addHouse(uint32_t id) { + std::shared_ptr addHouse(uint32_t id) { if (auto it = houseMap.find(id); it != houseMap.end()) { return it->second; } - auto house = new House(id); - houseMap[id] = house; - return house; + return houseMap[id] = std::make_shared(id); } - House* getHouse(uint32_t houseId) { + std::shared_ptr getHouse(uint32_t houseId) { auto it = houseMap.find(houseId); if (it == houseMap.end()) { return nullptr; @@ -278,7 +272,7 @@ class Houses { return it->second; } - House* getHouseByPlayerId(uint32_t playerId); + std::shared_ptr getHouseByPlayerId(uint32_t playerId); bool loadHousesXML(const std::string &filename); diff --git a/src/map/house/housetile.cpp b/src/map/house/housetile.cpp index 615a7862c8e..f67e16868e6 100644 --- a/src/map/house/housetile.cpp +++ b/src/map/house/housetile.cpp @@ -15,7 +15,7 @@ #include "map/house/house.hpp" #include "game/game.hpp" -HouseTile::HouseTile(int32_t initX, int32_t initY, int32_t initZ, House* initHouse) : +HouseTile::HouseTile(int32_t initX, int32_t initY, int32_t initZ, std::shared_ptr initHouse) : DynamicTile(initX, initY, initZ), house(initHouse) { } void HouseTile::addThing(int32_t index, std::shared_ptr thing) { diff --git a/src/map/house/housetile.hpp b/src/map/house/housetile.hpp index 916f040aa94..04da8a4e7f2 100644 --- a/src/map/house/housetile.hpp +++ b/src/map/house/housetile.hpp @@ -15,7 +15,7 @@ class House; class HouseTile final : public DynamicTile { public: - HouseTile(int32_t x, int32_t y, int32_t z, House* house); + HouseTile(int32_t x, int32_t y, int32_t z, std::shared_ptr house); // cylinder implementations ReturnValue queryAdd(int32_t index, const std::shared_ptr &thing, uint32_t count, uint32_t flags, std::shared_ptr actor = nullptr) override; @@ -27,12 +27,12 @@ class HouseTile final : public DynamicTile { void addThing(int32_t index, std::shared_ptr thing) override; void virtual internalAddThing(uint32_t index, std::shared_ptr thing) override; - House* getHouse() override { + std::shared_ptr getHouse() override { return house; } private: void updateHouse(std::shared_ptr item); - House* house; + std::shared_ptr house; }; From fdbc9182671f6a91838223ff217326a6923c181a Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 18:30:16 -0300 Subject: [PATCH 60/67] NetworkMessage to smart pointer --- .../network/network_message_functions.cpp | 53 ++++++++----------- .../network/network_message_functions.hpp | 5 +- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/src/lua/functions/core/network/network_message_functions.cpp b/src/lua/functions/core/network/network_message_functions.cpp index d989df46095..0e676cc7adc 100644 --- a/src/lua/functions/core/network/network_message_functions.cpp +++ b/src/lua/functions/core/network/network_message_functions.cpp @@ -15,23 +15,14 @@ int NetworkMessageFunctions::luaNetworkMessageCreate(lua_State* L) { // NetworkMessage() - pushUserdata(L, new NetworkMessage); + pushUserdata(L, std::make_shared()); setMetatable(L, -1, "NetworkMessage"); return 1; } -int NetworkMessageFunctions::luaNetworkMessageDelete(lua_State* L) { - NetworkMessage** messagePtr = getRawUserdata(L, 1); - if (messagePtr && *messagePtr) { - delete *messagePtr; - *messagePtr = nullptr; - } - return 0; -} - int NetworkMessageFunctions::luaNetworkMessageGetByte(lua_State* L) { // networkMessage:getByte() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { lua_pushnumber(L, message->getByte()); } else { @@ -42,7 +33,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetByte(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetU16(lua_State* L) { // networkMessage:getU16() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { lua_pushnumber(L, message->get()); } else { @@ -53,7 +44,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetU16(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetU32(lua_State* L) { // networkMessage:getU32() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { lua_pushnumber(L, message->get()); } else { @@ -64,7 +55,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetU32(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetU64(lua_State* L) { // networkMessage:getU64() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { lua_pushnumber(L, message->get()); } else { @@ -75,7 +66,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetU64(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetString(lua_State* L) { // networkMessage:getString() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { pushString(L, message->getString()); } else { @@ -86,7 +77,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetString(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetPosition(lua_State* L) { // networkMessage:getPosition() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { pushPosition(L, message->getPosition()); } else { @@ -98,7 +89,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetPosition(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddByte(lua_State* L) { // networkMessage:addByte(number) uint8_t number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->addByte(number); pushBoolean(L, true); @@ -111,7 +102,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddByte(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddU16(lua_State* L) { // networkMessage:addU16(number) uint16_t number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -124,7 +115,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddU16(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddU32(lua_State* L) { // networkMessage:addU32(number) uint32_t number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -137,7 +128,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddU32(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddU64(lua_State* L) { // networkMessage:addU64(number) uint64_t number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -150,7 +141,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddU64(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd8(lua_State* L) { // networkMessage:add8(number) auto number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -163,7 +154,7 @@ int NetworkMessageFunctions::luaNetworkMessageAdd8(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd16(lua_State* L) { // networkMessage:add16(number) auto number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -176,7 +167,7 @@ int NetworkMessageFunctions::luaNetworkMessageAdd16(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd32(lua_State* L) { // networkMessage:add32(number) auto number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -189,7 +180,7 @@ int NetworkMessageFunctions::luaNetworkMessageAdd32(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd64(lua_State* L) { // networkMessage:add64(number) auto number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -202,7 +193,7 @@ int NetworkMessageFunctions::luaNetworkMessageAdd64(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddString(lua_State* L) { // networkMessage:addString(string) const std::string &string = getString(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->addString(string); pushBoolean(L, true); @@ -215,7 +206,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddString(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddPosition(lua_State* L) { // networkMessage:addPosition(position) const Position &position = getPosition(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->addPosition(position); pushBoolean(L, true); @@ -228,7 +219,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddPosition(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddDouble(lua_State* L) { // networkMessage:addDouble(number) double number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->addDouble(number); pushBoolean(L, true); @@ -254,7 +245,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddItem(lua_State* L) { return 1; } - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message && player->client) { player->client->AddItem(*message, item); pushBoolean(L, true); @@ -266,7 +257,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddItem(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageReset(lua_State* L) { // networkMessage:reset() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->reset(); pushBoolean(L, true); @@ -279,7 +270,7 @@ int NetworkMessageFunctions::luaNetworkMessageReset(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageSkipBytes(lua_State* L) { // networkMessage:skipBytes(number) int16_t number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->skipBytes(number); pushBoolean(L, true); @@ -291,7 +282,7 @@ int NetworkMessageFunctions::luaNetworkMessageSkipBytes(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageSendToPlayer(lua_State* L) { // networkMessage:sendToPlayer(player) - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (!message) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/core/network/network_message_functions.hpp b/src/lua/functions/core/network/network_message_functions.hpp index 637f3366da8..7f1fb94cf3f 100644 --- a/src/lua/functions/core/network/network_message_functions.hpp +++ b/src/lua/functions/core/network/network_message_functions.hpp @@ -14,10 +14,8 @@ class NetworkMessageFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "NetworkMessage", "", NetworkMessageFunctions::luaNetworkMessageCreate); + registerSharedClass(L, "NetworkMessage", "", NetworkMessageFunctions::luaNetworkMessageCreate); registerMetaMethod(L, "NetworkMessage", "__eq", NetworkMessageFunctions::luaUserdataCompare); - registerMetaMethod(L, "NetworkMessage", "__gc", NetworkMessageFunctions::luaNetworkMessageDelete); - registerMethod(L, "NetworkMessage", "delete", NetworkMessageFunctions::luaNetworkMessageDelete); registerMethod(L, "NetworkMessage", "getByte", NetworkMessageFunctions::luaNetworkMessageGetByte); registerMethod(L, "NetworkMessage", "getU16", NetworkMessageFunctions::luaNetworkMessageGetU16); @@ -46,7 +44,6 @@ class NetworkMessageFunctions final : LuaScriptInterface { private: static int luaNetworkMessageCreate(lua_State* L); - static int luaNetworkMessageDelete(lua_State* L); static int luaNetworkMessageGetByte(lua_State* L); static int luaNetworkMessageGetU16(lua_State* L); From c084e2241a40677482df2f635448b81f5fb6ac48 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 18:47:35 -0300 Subject: [PATCH 61/67] Revert "NetworkMessage to smart pointer" This reverts commit fdbc9182671f6a91838223ff217326a6923c181a. --- .../network/network_message_functions.cpp | 53 +++++++++++-------- .../network/network_message_functions.hpp | 5 +- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/lua/functions/core/network/network_message_functions.cpp b/src/lua/functions/core/network/network_message_functions.cpp index 0e676cc7adc..d989df46095 100644 --- a/src/lua/functions/core/network/network_message_functions.cpp +++ b/src/lua/functions/core/network/network_message_functions.cpp @@ -15,14 +15,23 @@ int NetworkMessageFunctions::luaNetworkMessageCreate(lua_State* L) { // NetworkMessage() - pushUserdata(L, std::make_shared()); + pushUserdata(L, new NetworkMessage); setMetatable(L, -1, "NetworkMessage"); return 1; } +int NetworkMessageFunctions::luaNetworkMessageDelete(lua_State* L) { + NetworkMessage** messagePtr = getRawUserdata(L, 1); + if (messagePtr && *messagePtr) { + delete *messagePtr; + *messagePtr = nullptr; + } + return 0; +} + int NetworkMessageFunctions::luaNetworkMessageGetByte(lua_State* L) { // networkMessage:getByte() - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { lua_pushnumber(L, message->getByte()); } else { @@ -33,7 +42,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetByte(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetU16(lua_State* L) { // networkMessage:getU16() - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { lua_pushnumber(L, message->get()); } else { @@ -44,7 +53,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetU16(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetU32(lua_State* L) { // networkMessage:getU32() - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { lua_pushnumber(L, message->get()); } else { @@ -55,7 +64,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetU32(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetU64(lua_State* L) { // networkMessage:getU64() - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { lua_pushnumber(L, message->get()); } else { @@ -66,7 +75,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetU64(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetString(lua_State* L) { // networkMessage:getString() - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { pushString(L, message->getString()); } else { @@ -77,7 +86,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetString(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetPosition(lua_State* L) { // networkMessage:getPosition() - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { pushPosition(L, message->getPosition()); } else { @@ -89,7 +98,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetPosition(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddByte(lua_State* L) { // networkMessage:addByte(number) uint8_t number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->addByte(number); pushBoolean(L, true); @@ -102,7 +111,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddByte(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddU16(lua_State* L) { // networkMessage:addU16(number) uint16_t number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -115,7 +124,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddU16(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddU32(lua_State* L) { // networkMessage:addU32(number) uint32_t number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -128,7 +137,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddU32(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddU64(lua_State* L) { // networkMessage:addU64(number) uint64_t number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -141,7 +150,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddU64(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd8(lua_State* L) { // networkMessage:add8(number) auto number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -154,7 +163,7 @@ int NetworkMessageFunctions::luaNetworkMessageAdd8(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd16(lua_State* L) { // networkMessage:add16(number) auto number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -167,7 +176,7 @@ int NetworkMessageFunctions::luaNetworkMessageAdd16(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd32(lua_State* L) { // networkMessage:add32(number) auto number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -180,7 +189,7 @@ int NetworkMessageFunctions::luaNetworkMessageAdd32(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd64(lua_State* L) { // networkMessage:add64(number) auto number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -193,7 +202,7 @@ int NetworkMessageFunctions::luaNetworkMessageAdd64(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddString(lua_State* L) { // networkMessage:addString(string) const std::string &string = getString(L, 2); - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->addString(string); pushBoolean(L, true); @@ -206,7 +215,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddString(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddPosition(lua_State* L) { // networkMessage:addPosition(position) const Position &position = getPosition(L, 2); - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->addPosition(position); pushBoolean(L, true); @@ -219,7 +228,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddPosition(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddDouble(lua_State* L) { // networkMessage:addDouble(number) double number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->addDouble(number); pushBoolean(L, true); @@ -245,7 +254,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddItem(lua_State* L) { return 1; } - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message && player->client) { player->client->AddItem(*message, item); pushBoolean(L, true); @@ -257,7 +266,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddItem(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageReset(lua_State* L) { // networkMessage:reset() - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->reset(); pushBoolean(L, true); @@ -270,7 +279,7 @@ int NetworkMessageFunctions::luaNetworkMessageReset(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageSkipBytes(lua_State* L) { // networkMessage:skipBytes(number) int16_t number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (message) { message->skipBytes(number); pushBoolean(L, true); @@ -282,7 +291,7 @@ int NetworkMessageFunctions::luaNetworkMessageSkipBytes(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageSendToPlayer(lua_State* L) { // networkMessage:sendToPlayer(player) - const auto &message = getUserdataShared(L, 1); + NetworkMessage* message = getUserdata(L, 1); if (!message) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/core/network/network_message_functions.hpp b/src/lua/functions/core/network/network_message_functions.hpp index 7f1fb94cf3f..637f3366da8 100644 --- a/src/lua/functions/core/network/network_message_functions.hpp +++ b/src/lua/functions/core/network/network_message_functions.hpp @@ -14,8 +14,10 @@ class NetworkMessageFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerSharedClass(L, "NetworkMessage", "", NetworkMessageFunctions::luaNetworkMessageCreate); + registerClass(L, "NetworkMessage", "", NetworkMessageFunctions::luaNetworkMessageCreate); registerMetaMethod(L, "NetworkMessage", "__eq", NetworkMessageFunctions::luaUserdataCompare); + registerMetaMethod(L, "NetworkMessage", "__gc", NetworkMessageFunctions::luaNetworkMessageDelete); + registerMethod(L, "NetworkMessage", "delete", NetworkMessageFunctions::luaNetworkMessageDelete); registerMethod(L, "NetworkMessage", "getByte", NetworkMessageFunctions::luaNetworkMessageGetByte); registerMethod(L, "NetworkMessage", "getU16", NetworkMessageFunctions::luaNetworkMessageGetU16); @@ -44,6 +46,7 @@ class NetworkMessageFunctions final : LuaScriptInterface { private: static int luaNetworkMessageCreate(lua_State* L); + static int luaNetworkMessageDelete(lua_State* L); static int luaNetworkMessageGetByte(lua_State* L); static int luaNetworkMessageGetU16(lua_State* L); From 6cb2332a91821aef70734b53c19311cdc023cd8c Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 18:49:47 -0300 Subject: [PATCH 62/67] ModalWindow to smart pointer --- .../core/game/modal_window_functions.cpp | 43 ++++++++----------- .../core/game/modal_window_functions.hpp | 5 +-- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/lua/functions/core/game/modal_window_functions.cpp b/src/lua/functions/core/game/modal_window_functions.cpp index a56db5a6b65..11441993fa4 100644 --- a/src/lua/functions/core/game/modal_window_functions.cpp +++ b/src/lua/functions/core/game/modal_window_functions.cpp @@ -19,23 +19,14 @@ int ModalWindowFunctions::luaModalWindowCreate(lua_State* L) { const std::string &title = getString(L, 3); uint32_t id = getNumber(L, 2); - pushUserdata(L, new ModalWindow(id, title, message)); + pushUserdata(L, std::make_shared(id, title, message)); setMetatable(L, -1, "ModalWindow"); return 1; } -int ModalWindowFunctions::luaModalWindowDelete(lua_State* L) { - ModalWindow** windowPtr = getRawUserdata(L, 1); - if (windowPtr && *windowPtr) { - delete *windowPtr; - *windowPtr = nullptr; - } - return 0; -} - int ModalWindowFunctions::luaModalWindowGetId(lua_State* L) { // modalWindow:getId() - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { lua_pushnumber(L, window->id); } else { @@ -46,7 +37,7 @@ int ModalWindowFunctions::luaModalWindowGetId(lua_State* L) { int ModalWindowFunctions::luaModalWindowGetTitle(lua_State* L) { // modalWindow:getTitle() - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { pushString(L, window->title); } else { @@ -57,7 +48,7 @@ int ModalWindowFunctions::luaModalWindowGetTitle(lua_State* L) { int ModalWindowFunctions::luaModalWindowGetMessage(lua_State* L) { // modalWindow:getMessage() - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { pushString(L, window->message); } else { @@ -69,7 +60,7 @@ int ModalWindowFunctions::luaModalWindowGetMessage(lua_State* L) { int ModalWindowFunctions::luaModalWindowSetTitle(lua_State* L) { // modalWindow:setTitle(text) const std::string &text = getString(L, 2); - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { window->title = text; pushBoolean(L, true); @@ -82,7 +73,7 @@ int ModalWindowFunctions::luaModalWindowSetTitle(lua_State* L) { int ModalWindowFunctions::luaModalWindowSetMessage(lua_State* L) { // modalWindow:setMessage(text) const std::string &text = getString(L, 2); - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { window->message = text; pushBoolean(L, true); @@ -94,7 +85,7 @@ int ModalWindowFunctions::luaModalWindowSetMessage(lua_State* L) { int ModalWindowFunctions::luaModalWindowGetButtonCount(lua_State* L) { // modalWindow:getButtonCount() - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { lua_pushnumber(L, window->buttons.size()); } else { @@ -105,7 +96,7 @@ int ModalWindowFunctions::luaModalWindowGetButtonCount(lua_State* L) { int ModalWindowFunctions::luaModalWindowGetChoiceCount(lua_State* L) { // modalWindow:getChoiceCount() - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { lua_pushnumber(L, window->choices.size()); } else { @@ -118,7 +109,7 @@ int ModalWindowFunctions::luaModalWindowAddButton(lua_State* L) { // modalWindow:addButton(id, text) const std::string &text = getString(L, 3); uint8_t id = getNumber(L, 2); - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { window->buttons.emplace_back(text, id); pushBoolean(L, true); @@ -132,7 +123,7 @@ int ModalWindowFunctions::luaModalWindowAddChoice(lua_State* L) { // modalWindow:addChoice(id, text) const std::string &text = getString(L, 3); uint8_t id = getNumber(L, 2); - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { window->choices.emplace_back(text, id); pushBoolean(L, true); @@ -144,7 +135,7 @@ int ModalWindowFunctions::luaModalWindowAddChoice(lua_State* L) { int ModalWindowFunctions::luaModalWindowGetDefaultEnterButton(lua_State* L) { // modalWindow:getDefaultEnterButton() - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { lua_pushnumber(L, window->defaultEnterButton); } else { @@ -155,7 +146,7 @@ int ModalWindowFunctions::luaModalWindowGetDefaultEnterButton(lua_State* L) { int ModalWindowFunctions::luaModalWindowSetDefaultEnterButton(lua_State* L) { // modalWindow:setDefaultEnterButton(buttonId) - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { window->defaultEnterButton = getNumber(L, 2); pushBoolean(L, true); @@ -167,7 +158,7 @@ int ModalWindowFunctions::luaModalWindowSetDefaultEnterButton(lua_State* L) { int ModalWindowFunctions::luaModalWindowGetDefaultEscapeButton(lua_State* L) { // modalWindow:getDefaultEscapeButton() - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { lua_pushnumber(L, window->defaultEscapeButton); } else { @@ -178,7 +169,7 @@ int ModalWindowFunctions::luaModalWindowGetDefaultEscapeButton(lua_State* L) { int ModalWindowFunctions::luaModalWindowSetDefaultEscapeButton(lua_State* L) { // modalWindow:setDefaultEscapeButton(buttonId) - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { window->defaultEscapeButton = getNumber(L, 2); pushBoolean(L, true); @@ -190,7 +181,7 @@ int ModalWindowFunctions::luaModalWindowSetDefaultEscapeButton(lua_State* L) { int ModalWindowFunctions::luaModalWindowHasPriority(lua_State* L) { // modalWindow:hasPriority() - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { pushBoolean(L, window->priority); } else { @@ -201,7 +192,7 @@ int ModalWindowFunctions::luaModalWindowHasPriority(lua_State* L) { int ModalWindowFunctions::luaModalWindowSetPriority(lua_State* L) { // modalWindow:setPriority(priority) - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { window->priority = getBoolean(L, 2); pushBoolean(L, true); @@ -219,7 +210,7 @@ int ModalWindowFunctions::luaModalWindowSendToPlayer(lua_State* L) { return 1; } - ModalWindow* window = getUserdata(L, 1); + const auto &window = getUserdataShared(L, 1); if (window) { if (!player->hasModalWindowOpen(window->id)) { player->sendModalWindow(*window); diff --git a/src/lua/functions/core/game/modal_window_functions.hpp b/src/lua/functions/core/game/modal_window_functions.hpp index 4d4ced1635e..78e935314bc 100644 --- a/src/lua/functions/core/game/modal_window_functions.hpp +++ b/src/lua/functions/core/game/modal_window_functions.hpp @@ -14,10 +14,8 @@ class ModalWindowFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "ModalWindow", "", ModalWindowFunctions::luaModalWindowCreate); + registerSharedClass(L, "ModalWindow", "", ModalWindowFunctions::luaModalWindowCreate); registerMetaMethod(L, "ModalWindow", "__eq", ModalWindowFunctions::luaUserdataCompare); - registerMetaMethod(L, "ModalWindow", "__gc", ModalWindowFunctions::luaModalWindowDelete); - registerMethod(L, "ModalWindow", "delete", ModalWindowFunctions::luaModalWindowDelete); registerMethod(L, "ModalWindow", "getId", ModalWindowFunctions::luaModalWindowGetId); registerMethod(L, "ModalWindow", "getTitle", ModalWindowFunctions::luaModalWindowGetTitle); @@ -46,7 +44,6 @@ class ModalWindowFunctions final : LuaScriptInterface { private: static int luaModalWindowCreate(lua_State* L); - static int luaModalWindowDelete(lua_State* L); static int luaModalWindowGetId(lua_State* L); static int luaModalWindowGetTitle(lua_State* L); From 16e8c77b4e13bf65c60b46c839de7e6192ac560e Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 19:10:55 -0300 Subject: [PATCH 63/67] Update combat_functions.hpp --- src/lua/functions/creatures/combat/combat_functions.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua/functions/creatures/combat/combat_functions.hpp b/src/lua/functions/creatures/combat/combat_functions.hpp index 652255d7ae4..b6816c565ed 100644 --- a/src/lua/functions/creatures/combat/combat_functions.hpp +++ b/src/lua/functions/creatures/combat/combat_functions.hpp @@ -17,7 +17,7 @@ class CombatFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerSharedClass(L, "Combat", "", CombatFunctions::luaCombatCreate); + registerClass(L, "Combat", "", CombatFunctions::luaCombatCreate); registerMetaMethod(L, "Combat", "__eq", CombatFunctions::luaUserdataCompare); registerMethod(L, "Combat", "setParameter", CombatFunctions::luaCombatSetParameter); From 294263bf675f994923fa0d9c41bd44786c3ed536 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 19:29:13 -0300 Subject: [PATCH 64/67] Update npc.cpp --- src/creatures/npcs/npc.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index 61896f2f4db..ab9ca5795d5 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -24,7 +24,10 @@ uint32_t Npc::npcAutoID = 0x80000000; std::shared_ptr Npc::createNpc(const std::string &name) { const auto &npcType = g_npcs().getNpcType(name); - return npcType ? std::make_shared(npcType) : nullptr; + if (!npcType) { + return nullptr; + } + return std::make_shared(npcType); } Npc::Npc(const std::shared_ptr &npcType) : From 50eabe883dacdd925c61320f2f595e50ec117519 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 21:53:35 -0300 Subject: [PATCH 65/67] combat --- .../creatures/combat/combat_functions.cpp | 16 ++++++++-------- .../creatures/combat/combat_functions.hpp | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lua/functions/creatures/combat/combat_functions.cpp b/src/lua/functions/creatures/combat/combat_functions.cpp index 0349456fd94..6c1529726bf 100644 --- a/src/lua/functions/creatures/combat/combat_functions.cpp +++ b/src/lua/functions/creatures/combat/combat_functions.cpp @@ -16,14 +16,14 @@ int CombatFunctions::luaCombatCreate(lua_State* L) { // Combat() - pushUserdata(L, g_luaEnvironment().createCombatObject(getScriptEnv()->getScriptInterface()).get()); + pushUserdata(L, g_luaEnvironment().createCombatObject(getScriptEnv()->getScriptInterface())); setMetatable(L, -1, "Combat"); return 1; } int CombatFunctions::luaCombatSetParameter(lua_State* L) { // combat:setParameter(key, value) - Combat* combat = getUserdata(L, 1); + const auto &combat = getUserdataShared(L, 1); if (!combat) { lua_pushnil(L); return 1; @@ -43,7 +43,7 @@ int CombatFunctions::luaCombatSetParameter(lua_State* L) { int CombatFunctions::luaCombatSetFormula(lua_State* L) { // combat:setFormula(type, mina, minb, maxa, maxb) - Combat* combat = getUserdata(L, 1); + const auto &combat = getUserdataShared(L, 1); if (!combat) { lua_pushnil(L); return 1; @@ -74,7 +74,7 @@ int CombatFunctions::luaCombatSetArea(lua_State* L) { return 1; } - Combat* combat = getUserdata(L, 1); + const auto &combat = getUserdataShared(L, 1); if (combat) { auto areaClone = area->clone(); combat->setArea(areaClone); @@ -88,7 +88,7 @@ int CombatFunctions::luaCombatSetArea(lua_State* L) { int CombatFunctions::luaCombatSetCondition(lua_State* L) { // combat:addCondition(condition) std::shared_ptr condition = getUserdataShared(L, 2); - Combat* combat = getUserdata(L, 1); + const auto &combat = getUserdataShared(L, 1); if (combat && condition) { combat->addCondition(condition->clone()); pushBoolean(L, true); @@ -100,7 +100,7 @@ int CombatFunctions::luaCombatSetCondition(lua_State* L) { int CombatFunctions::luaCombatSetCallback(lua_State* L) { // combat:setCallback(key, function) - Combat* combat = getUserdata(L, 1); + const auto &combat = getUserdataShared(L, 1); if (!combat) { lua_pushnil(L); return 1; @@ -125,7 +125,7 @@ int CombatFunctions::luaCombatSetCallback(lua_State* L) { int CombatFunctions::luaCombatSetOrigin(lua_State* L) { // combat:setOrigin(origin) - Combat* combat = getUserdata(L, 1); + const auto &combat = getUserdataShared(L, 1); if (combat) { combat->setOrigin(getNumber(L, 2)); pushBoolean(L, true); @@ -137,7 +137,7 @@ int CombatFunctions::luaCombatSetOrigin(lua_State* L) { int CombatFunctions::luaCombatExecute(lua_State* L) { // combat:execute(creature, variant) - Combat* combat = getUserdata(L, 1); + const auto &combat = getUserdataShared(L, 1); if (!combat) { pushBoolean(L, false); return 1; diff --git a/src/lua/functions/creatures/combat/combat_functions.hpp b/src/lua/functions/creatures/combat/combat_functions.hpp index b6816c565ed..652255d7ae4 100644 --- a/src/lua/functions/creatures/combat/combat_functions.hpp +++ b/src/lua/functions/creatures/combat/combat_functions.hpp @@ -17,7 +17,7 @@ class CombatFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "Combat", "", CombatFunctions::luaCombatCreate); + registerSharedClass(L, "Combat", "", CombatFunctions::luaCombatCreate); registerMetaMethod(L, "Combat", "__eq", CombatFunctions::luaUserdataCompare); registerMethod(L, "Combat", "setParameter", CombatFunctions::luaCombatSetParameter); From e1ee00d4f40709f5076a1a226cb526f099e61a83 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 22:07:03 -0300 Subject: [PATCH 66/67] NetworkMessage smart pointer --- .../network/network_message_functions.cpp | 57 ++++++++----------- .../network/network_message_functions.hpp | 5 +- src/lua/modules/modules.cpp | 2 +- 3 files changed, 26 insertions(+), 38 deletions(-) diff --git a/src/lua/functions/core/network/network_message_functions.cpp b/src/lua/functions/core/network/network_message_functions.cpp index d989df46095..a0f02631a1c 100644 --- a/src/lua/functions/core/network/network_message_functions.cpp +++ b/src/lua/functions/core/network/network_message_functions.cpp @@ -15,23 +15,14 @@ int NetworkMessageFunctions::luaNetworkMessageCreate(lua_State* L) { // NetworkMessage() - pushUserdata(L, new NetworkMessage); + pushUserdata(L, std::make_shared()); setMetatable(L, -1, "NetworkMessage"); return 1; } -int NetworkMessageFunctions::luaNetworkMessageDelete(lua_State* L) { - NetworkMessage** messagePtr = getRawUserdata(L, 1); - if (messagePtr && *messagePtr) { - delete *messagePtr; - *messagePtr = nullptr; - } - return 0; -} - int NetworkMessageFunctions::luaNetworkMessageGetByte(lua_State* L) { // networkMessage:getByte() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { lua_pushnumber(L, message->getByte()); } else { @@ -42,7 +33,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetByte(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetU16(lua_State* L) { // networkMessage:getU16() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { lua_pushnumber(L, message->get()); } else { @@ -53,7 +44,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetU16(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetU32(lua_State* L) { // networkMessage:getU32() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { lua_pushnumber(L, message->get()); } else { @@ -64,7 +55,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetU32(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetU64(lua_State* L) { // networkMessage:getU64() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { lua_pushnumber(L, message->get()); } else { @@ -75,7 +66,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetU64(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetString(lua_State* L) { // networkMessage:getString() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { pushString(L, message->getString()); } else { @@ -86,7 +77,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetString(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetPosition(lua_State* L) { // networkMessage:getPosition() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { pushPosition(L, message->getPosition()); } else { @@ -98,7 +89,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetPosition(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddByte(lua_State* L) { // networkMessage:addByte(number) uint8_t number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->addByte(number); pushBoolean(L, true); @@ -111,7 +102,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddByte(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddU16(lua_State* L) { // networkMessage:addU16(number) uint16_t number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -124,7 +115,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddU16(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddU32(lua_State* L) { // networkMessage:addU32(number) uint32_t number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -137,7 +128,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddU32(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddU64(lua_State* L) { // networkMessage:addU64(number) uint64_t number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -150,7 +141,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddU64(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd8(lua_State* L) { // networkMessage:add8(number) auto number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -163,7 +154,7 @@ int NetworkMessageFunctions::luaNetworkMessageAdd8(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd16(lua_State* L) { // networkMessage:add16(number) auto number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -176,7 +167,7 @@ int NetworkMessageFunctions::luaNetworkMessageAdd16(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd32(lua_State* L) { // networkMessage:add32(number) auto number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -189,7 +180,7 @@ int NetworkMessageFunctions::luaNetworkMessageAdd32(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd64(lua_State* L) { // networkMessage:add64(number) auto number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->add(number); pushBoolean(L, true); @@ -202,7 +193,7 @@ int NetworkMessageFunctions::luaNetworkMessageAdd64(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddString(lua_State* L) { // networkMessage:addString(string) const std::string &string = getString(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->addString(string); pushBoolean(L, true); @@ -215,7 +206,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddString(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddPosition(lua_State* L) { // networkMessage:addPosition(position) const Position &position = getPosition(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->addPosition(position); pushBoolean(L, true); @@ -228,7 +219,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddPosition(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddDouble(lua_State* L) { // networkMessage:addDouble(number) double number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->addDouble(number); pushBoolean(L, true); @@ -240,7 +231,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddDouble(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddItem(lua_State* L) { // networkMessage:addItem(item, player) - std::shared_ptr item = getUserdataShared(L, 2); + const auto &item = getUserdataShared(L, 2); if (!item) { reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); lua_pushnil(L); @@ -254,7 +245,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddItem(lua_State* L) { return 1; } - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message && player->client) { player->client->AddItem(*message, item); pushBoolean(L, true); @@ -266,7 +257,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddItem(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageReset(lua_State* L) { // networkMessage:reset() - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->reset(); pushBoolean(L, true); @@ -279,7 +270,7 @@ int NetworkMessageFunctions::luaNetworkMessageReset(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageSkipBytes(lua_State* L) { // networkMessage:skipBytes(number) int16_t number = getNumber(L, 2); - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (message) { message->skipBytes(number); pushBoolean(L, true); @@ -291,13 +282,13 @@ int NetworkMessageFunctions::luaNetworkMessageSkipBytes(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageSendToPlayer(lua_State* L) { // networkMessage:sendToPlayer(player) - NetworkMessage* message = getUserdata(L, 1); + const auto &message = getUserdataShared(L, 1); if (!message) { lua_pushnil(L); return 1; } - std::shared_ptr player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (player) { player->sendNetworkMessage(*message); pushBoolean(L, true); diff --git a/src/lua/functions/core/network/network_message_functions.hpp b/src/lua/functions/core/network/network_message_functions.hpp index 637f3366da8..7f1fb94cf3f 100644 --- a/src/lua/functions/core/network/network_message_functions.hpp +++ b/src/lua/functions/core/network/network_message_functions.hpp @@ -14,10 +14,8 @@ class NetworkMessageFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "NetworkMessage", "", NetworkMessageFunctions::luaNetworkMessageCreate); + registerSharedClass(L, "NetworkMessage", "", NetworkMessageFunctions::luaNetworkMessageCreate); registerMetaMethod(L, "NetworkMessage", "__eq", NetworkMessageFunctions::luaUserdataCompare); - registerMetaMethod(L, "NetworkMessage", "__gc", NetworkMessageFunctions::luaNetworkMessageDelete); - registerMethod(L, "NetworkMessage", "delete", NetworkMessageFunctions::luaNetworkMessageDelete); registerMethod(L, "NetworkMessage", "getByte", NetworkMessageFunctions::luaNetworkMessageGetByte); registerMethod(L, "NetworkMessage", "getU16", NetworkMessageFunctions::luaNetworkMessageGetU16); @@ -46,7 +44,6 @@ class NetworkMessageFunctions final : LuaScriptInterface { private: static int luaNetworkMessageCreate(lua_State* L); - static int luaNetworkMessageDelete(lua_State* L); static int luaNetworkMessageGetByte(lua_State* L); static int luaNetworkMessageGetU16(lua_State* L); diff --git a/src/lua/modules/modules.cpp b/src/lua/modules/modules.cpp index 18d1107ff76..5e1565251c8 100644 --- a/src/lua/modules/modules.cpp +++ b/src/lua/modules/modules.cpp @@ -168,7 +168,7 @@ void Module::executeOnRecvbyte(std::shared_ptr player, NetworkMessage &m LuaScriptInterface::pushUserdata(L, player); LuaScriptInterface::setMetatable(L, -1, "Player"); - LuaScriptInterface::pushUserdata(L, &msg); + LuaScriptInterface::pushUserdata(L, std::shared_ptr(&msg)); LuaScriptInterface::setWeakMetatable(L, -1, "NetworkMessage"); lua_pushnumber(L, recvbyte); From 215d20e5e009581b80592f4f917a52a9b6bfa3fb Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Fri, 22 Sep 2023 22:19:57 -0300 Subject: [PATCH 67/67] fix network --- src/lua/functions/core/network/network_message_functions.hpp | 1 + src/lua/functions/lua_functions_loader.hpp | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lua/functions/core/network/network_message_functions.hpp b/src/lua/functions/core/network/network_message_functions.hpp index 7f1fb94cf3f..df27dbd19af 100644 --- a/src/lua/functions/core/network/network_message_functions.hpp +++ b/src/lua/functions/core/network/network_message_functions.hpp @@ -16,6 +16,7 @@ class NetworkMessageFunctions final : LuaScriptInterface { static void init(lua_State* L) { registerSharedClass(L, "NetworkMessage", "", NetworkMessageFunctions::luaNetworkMessageCreate); registerMetaMethod(L, "NetworkMessage", "__eq", NetworkMessageFunctions::luaUserdataCompare); + registerMethod(L, "NetworkMessage", "delete", luaGarbageCollection); registerMethod(L, "NetworkMessage", "getByte", NetworkMessageFunctions::luaNetworkMessageGetByte); registerMethod(L, "NetworkMessage", "getU16", NetworkMessageFunctions::luaNetworkMessageGetU16); diff --git a/src/lua/functions/lua_functions_loader.hpp b/src/lua/functions/lua_functions_loader.hpp index d4d312247a0..3ae8e3ec15b 100644 --- a/src/lua/functions/lua_functions_loader.hpp +++ b/src/lua/functions/lua_functions_loader.hpp @@ -215,10 +215,8 @@ class LuaFunctionsLoader { static void registerGlobalString(lua_State* L, const std::string &variable, const std::string &name); static int luaUserdataCompare(lua_State* L); + static int luaGarbageCollection(lua_State* L); static ScriptEnvironment scriptEnv[16]; static int32_t scriptEnvIndex; - -private: - static int luaGarbageCollection(lua_State* L); };