From 8f67086b56e37a0a622ab97d5eadbaccfeeb89fe Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Thu, 14 Nov 2024 01:03:36 -0300 Subject: [PATCH 1/5] improve: move folders and remove includes --- docs/python-scripts/remove_player_includes.py | 78 +++++++++++++++++++ src/creatures/CMakeLists.txt | 14 ++-- .../player_achievement.cpp | 0 .../player_achievement.hpp | 0 .../player_badge.cpp | 0 .../player_badge.hpp | 0 .../player_cyclopedia.cpp | 0 .../player_cyclopedia.hpp | 0 .../player_title.cpp | 0 .../player_title.hpp | 0 .../{vip => components}/player_vip.cpp | 0 .../{vip => components}/player_vip.hpp | 0 .../{ => components}/wheel/player_wheel.cpp | 0 .../{ => components}/wheel/player_wheel.hpp | 0 .../wheel/wheel_definitions.hpp | 0 .../{ => components}/wheel/wheel_gems.cpp | 0 .../{ => components}/wheel/wheel_gems.hpp | 0 17 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 docs/python-scripts/remove_player_includes.py rename src/creatures/players/{achievement => components}/player_achievement.cpp (100%) rename src/creatures/players/{achievement => components}/player_achievement.hpp (100%) rename src/creatures/players/{cyclopedia => components}/player_badge.cpp (100%) rename src/creatures/players/{cyclopedia => components}/player_badge.hpp (100%) rename src/creatures/players/{cyclopedia => components}/player_cyclopedia.cpp (100%) rename src/creatures/players/{cyclopedia => components}/player_cyclopedia.hpp (100%) rename src/creatures/players/{cyclopedia => components}/player_title.cpp (100%) rename src/creatures/players/{cyclopedia => components}/player_title.hpp (100%) rename src/creatures/players/{vip => components}/player_vip.cpp (100%) rename src/creatures/players/{vip => components}/player_vip.hpp (100%) rename src/creatures/players/{ => components}/wheel/player_wheel.cpp (100%) rename src/creatures/players/{ => components}/wheel/player_wheel.hpp (100%) rename src/creatures/players/{ => components}/wheel/wheel_definitions.hpp (100%) rename src/creatures/players/{ => components}/wheel/wheel_gems.cpp (100%) rename src/creatures/players/{ => components}/wheel/wheel_gems.hpp (100%) diff --git a/docs/python-scripts/remove_player_includes.py b/docs/python-scripts/remove_player_includes.py new file mode 100644 index 00000000000..6bc97925812 --- /dev/null +++ b/docs/python-scripts/remove_player_includes.py @@ -0,0 +1,78 @@ +import os +import re +import argparse + +# List of includes to remove +includes_to_remove = [ + '#include "creatures/players/wheel/player_wheel.hpp"', + '#include "creatures/players/vip/player_vip.hpp"', + '#include "creatures/players/achievement/player_achievement.hpp"', + '#include "creatures/players/cyclopedia/player_badge.hpp"', + '#include "creatures/players/cyclopedia/player_cyclopedia.hpp"', + '#include "creatures/players/cyclopedia/player_title.hpp"', + '#include "creatures/players/wheel/wheel_gems.hpp"', +] + +# List of method calls to update from '->' to '.' +methods_to_update = [ + 'wheel', + 'vip', + 'achiev', + 'badge', + 'title', + 'cyclopedia' + 'm_wheelPlayer' +] + +def remove_includes(content): + for include in includes_to_remove: + # Remove the specific include statement + include_pattern = r'^' + re.escape(include) + r'\s*\n' + content = re.sub(include_pattern, '', content, flags=re.MULTILINE) + + # Remove only the blank lines below the removed include + content = re.sub(r'(' + re.escape(include) + r'\s*\n)\n+', r'\1', content) + + return content + +def update_method_calls(content): + for method in methods_to_update: + # Replace 'method()->' with 'method().' for each method in the list + pattern = rf'\b{method}\(\)->' + replacement = f'{method}().' + content = re.sub(pattern, replacement, content) + + return content + +def process_files(file_path): + with open(file_path, 'r', encoding='utf-8') as file: + content = file.read() + + # Apply the include removal + modified_content = remove_includes(content) + + # Apply the method call update + modified_content = update_method_calls(modified_content) + + # Save the modified file if changes were made + if content != modified_content: + with open(file_path, 'w', encoding='utf-8') as file: + file.write(modified_content) + print(f'Modifications applied to: {file_path}') + else: + print(f'No modifications needed for: {file_path}') + +def main(directory): + # Traverse the specified folder and find all .hpp and .cpp files + for root, _, files in os.walk(directory): + for file in files: + if file.endswith(('.cpp', '.hpp')): + file_path = os.path.join(root, file) + process_files(file_path) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Remove specific includes and update method calls in .cpp and .hpp files.') + parser.add_argument('directory', type=str, nargs='?', default='../../src/', help='Path of the directory to be scanned.') + args = parser.parse_args() + + main(args.directory) diff --git a/src/creatures/CMakeLists.txt b/src/creatures/CMakeLists.txt index c87a45a0aa0..0f747bf0b5c 100644 --- a/src/creatures/CMakeLists.txt +++ b/src/creatures/CMakeLists.txt @@ -21,12 +21,12 @@ target_sources(${PROJECT_NAME}_lib PRIVATE players/management/waitlist.cpp players/storages/storages.cpp players/player.cpp - players/achievement/player_achievement.cpp - players/cyclopedia/player_badge.cpp - players/cyclopedia/player_cyclopedia.cpp - players/cyclopedia/player_title.cpp - players/wheel/player_wheel.cpp - players/wheel/wheel_gems.cpp + players/components/player_achievement.cpp + players/components/player_badge.cpp + players/components/player_cyclopedia.cpp + players/components/player_title.cpp + players/components/wheel/player_wheel.cpp + players/components/player_vip.cpp + players/components/wheel/wheel_gems.cpp players/vocations/vocation.cpp - players/vip/player_vip.cpp ) diff --git a/src/creatures/players/achievement/player_achievement.cpp b/src/creatures/players/components/player_achievement.cpp similarity index 100% rename from src/creatures/players/achievement/player_achievement.cpp rename to src/creatures/players/components/player_achievement.cpp diff --git a/src/creatures/players/achievement/player_achievement.hpp b/src/creatures/players/components/player_achievement.hpp similarity index 100% rename from src/creatures/players/achievement/player_achievement.hpp rename to src/creatures/players/components/player_achievement.hpp diff --git a/src/creatures/players/cyclopedia/player_badge.cpp b/src/creatures/players/components/player_badge.cpp similarity index 100% rename from src/creatures/players/cyclopedia/player_badge.cpp rename to src/creatures/players/components/player_badge.cpp diff --git a/src/creatures/players/cyclopedia/player_badge.hpp b/src/creatures/players/components/player_badge.hpp similarity index 100% rename from src/creatures/players/cyclopedia/player_badge.hpp rename to src/creatures/players/components/player_badge.hpp diff --git a/src/creatures/players/cyclopedia/player_cyclopedia.cpp b/src/creatures/players/components/player_cyclopedia.cpp similarity index 100% rename from src/creatures/players/cyclopedia/player_cyclopedia.cpp rename to src/creatures/players/components/player_cyclopedia.cpp diff --git a/src/creatures/players/cyclopedia/player_cyclopedia.hpp b/src/creatures/players/components/player_cyclopedia.hpp similarity index 100% rename from src/creatures/players/cyclopedia/player_cyclopedia.hpp rename to src/creatures/players/components/player_cyclopedia.hpp diff --git a/src/creatures/players/cyclopedia/player_title.cpp b/src/creatures/players/components/player_title.cpp similarity index 100% rename from src/creatures/players/cyclopedia/player_title.cpp rename to src/creatures/players/components/player_title.cpp diff --git a/src/creatures/players/cyclopedia/player_title.hpp b/src/creatures/players/components/player_title.hpp similarity index 100% rename from src/creatures/players/cyclopedia/player_title.hpp rename to src/creatures/players/components/player_title.hpp diff --git a/src/creatures/players/vip/player_vip.cpp b/src/creatures/players/components/player_vip.cpp similarity index 100% rename from src/creatures/players/vip/player_vip.cpp rename to src/creatures/players/components/player_vip.cpp diff --git a/src/creatures/players/vip/player_vip.hpp b/src/creatures/players/components/player_vip.hpp similarity index 100% rename from src/creatures/players/vip/player_vip.hpp rename to src/creatures/players/components/player_vip.hpp diff --git a/src/creatures/players/wheel/player_wheel.cpp b/src/creatures/players/components/wheel/player_wheel.cpp similarity index 100% rename from src/creatures/players/wheel/player_wheel.cpp rename to src/creatures/players/components/wheel/player_wheel.cpp diff --git a/src/creatures/players/wheel/player_wheel.hpp b/src/creatures/players/components/wheel/player_wheel.hpp similarity index 100% rename from src/creatures/players/wheel/player_wheel.hpp rename to src/creatures/players/components/wheel/player_wheel.hpp diff --git a/src/creatures/players/wheel/wheel_definitions.hpp b/src/creatures/players/components/wheel/wheel_definitions.hpp similarity index 100% rename from src/creatures/players/wheel/wheel_definitions.hpp rename to src/creatures/players/components/wheel/wheel_definitions.hpp diff --git a/src/creatures/players/wheel/wheel_gems.cpp b/src/creatures/players/components/wheel/wheel_gems.cpp similarity index 100% rename from src/creatures/players/wheel/wheel_gems.cpp rename to src/creatures/players/components/wheel/wheel_gems.cpp diff --git a/src/creatures/players/wheel/wheel_gems.hpp b/src/creatures/players/components/wheel/wheel_gems.hpp similarity index 100% rename from src/creatures/players/wheel/wheel_gems.hpp rename to src/creatures/players/components/wheel/wheel_gems.hpp From e0e5b2ed6a41e65b4bc68a935dc16f98fad303f0 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Mon, 18 Nov 2024 15:17:28 -0300 Subject: [PATCH 2/5] improve: set player components to scoped objects --- data-canary/npc/canary.lua | 19 +++ src/creatures/combat/combat.cpp | 14 +- src/creatures/combat/spells.cpp | 19 ++- src/creatures/monsters/monster.cpp | 7 +- .../players/components/player_achievement.cpp | 4 +- .../players/components/player_badge.cpp | 4 +- .../players/components/player_cyclopedia.cpp | 4 +- .../players/components/player_title.cpp | 4 +- .../players/components/player_vip.cpp | 4 +- .../players/components/wheel/player_wheel.cpp | 38 ++--- .../players/components/wheel/player_wheel.hpp | 89 ++++++++++-- .../components/wheel/wheel_definitions.hpp | 106 +------------- .../players/components/wheel/wheel_gems.cpp | 6 +- .../players/components/wheel/wheel_gems.hpp | 2 +- .../players/components/wheel/wheel_spells.hpp | 40 ++++++ src/creatures/players/player.cpp | 134 +++++++++--------- src/creatures/players/player.hpp | 44 +++--- src/game/game.cpp | 70 +++++---- src/game/game.hpp | 7 +- src/io/functions/iologindata_load_player.cpp | 24 ++-- src/io/io_wheel.cpp | 7 +- src/io/io_wheel.hpp | 13 +- src/io/iologindata.cpp | 3 +- .../functions/core/game/game_functions.cpp | 1 - .../functions/core/game/global_functions.cpp | 9 +- src/lua/functions/core/game/lua_enums.cpp | 2 +- .../creatures/player/player_functions.cpp | 68 +++++---- src/server/network/protocol/protocolgame.cpp | 49 +++---- 28 files changed, 397 insertions(+), 394 deletions(-) create mode 100644 src/creatures/players/components/wheel/wheel_spells.hpp diff --git a/data-canary/npc/canary.lua b/data-canary/npc/canary.lua index dca6f1777b1..55e1dc34a75 100644 --- a/data-canary/npc/canary.lua +++ b/data-canary/npc/canary.lua @@ -123,6 +123,25 @@ end -- On check npc shop message (look item) npcType.onCheckItem = function(npc, player, clientId, subType) end +-- Promotion +local node1 = keywordHandler:addKeyword({ "promot" }, StdModule.say, { + npcHandler = npcHandler, + onlyFocus = true, + text = "I can promote you for 20000 gold coins. Do you want me to promote you?", +}) +node1:addChildKeyword({ "yes" }, StdModule.promotePlayer, { + npcHandler = npcHandler, + cost = 20000, + level = 20, + text = "Congratulations! You are now promoted.", +}) +node1:addChildKeyword({ "no" }, StdModule.say, { + npcHandler = npcHandler, + onlyFocus = true, + text = "Alright then, come back when you are ready.", + reset = true, +}) + -- Function called by the callback "npcHandler:setCallback(CALLBACK_GREET, greetCallback)" in end of file local function greetCallback(npc, player) npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|, you need more info about {canary}?") diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index 34a28398e9e..6c4ee181cad 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -17,7 +17,6 @@ #include "creatures/players/grouping/party.hpp" #include "creatures/players/player.hpp" #include "creatures/players/imbuements/imbuements.hpp" -#include "creatures/players/wheel/player_wheel.hpp" #include "game/game.hpp" #include "game/scheduling/dispatcher.hpp" #include "io/iobestiary.hpp" @@ -30,6 +29,7 @@ #include "lua/creature/events.hpp" #include "map/spectators.hpp" #include "creatures/players/player.hpp" +#include "creatures/players/components/wheel/wheel_definitions.hpp" int32_t Combat::getLevelFormula(const std::shared_ptr &player, const std::shared_ptr &wheelSpell, const CombatDamage &damage) const { if (!player) { @@ -38,7 +38,7 @@ int32_t Combat::getLevelFormula(const std::shared_ptr &player, const std uint32_t magicLevelSkill = player->getMagicLevel(); // Wheel of destiny - Runic Mastery - if (player->wheel()->getInstant("Runic Mastery") && wheelSpell && damage.instantSpellName.empty() && normal_random(0, 100) <= 25) { + if (player->wheel().getInstant("Runic Mastery") && wheelSpell && damage.instantSpellName.empty() && normal_random(0, 100) <= 25) { const auto conjuringSpell = g_spells().getInstantSpellByName(damage.runeSpellName); if (conjuringSpell && conjuringSpell != wheelSpell) { uint32_t castResult = conjuringSpell->canCast(player) ? 20 : 10; @@ -61,7 +61,7 @@ CombatDamage Combat::getCombatDamage(const std::shared_ptr &creature, std::shared_ptr wheelSpell = nullptr; std::shared_ptr attackerPlayer = creature ? creature->getPlayer() : nullptr; if (attackerPlayer) { - wheelSpell = attackerPlayer->wheel()->getCombatDataSpell(damage); + wheelSpell = attackerPlayer->wheel().getCombatDataSpell(damage); } // End if (formulaType == COMBAT_FORMULA_DAMAGE) { @@ -641,7 +641,7 @@ void Combat::CombatHealthFunc(const std::shared_ptr &caster, const std } } - damage.damageMultiplier += attackerPlayer->wheel()->getMajorStatConditional("Divine Empowerment", WheelMajor_t::DAMAGE); + damage.damageMultiplier += attackerPlayer->wheel().getMajorStatConditional("Divine Empowerment", WheelMajor_t::DAMAGE); g_logger().trace("Wheel Divine Empowerment damage multiplier {}", damage.damageMultiplier); } @@ -1238,7 +1238,7 @@ void Combat::CombatFunc(const std::shared_ptr &caster, const Position // Wheel of destiny get beam affected total auto spectators = Spectators().find(pos, true, rangeX, rangeX, rangeY, rangeY); const std::shared_ptr &casterPlayer = caster ? caster->getPlayer() : nullptr; - uint8_t beamAffectedTotal = casterPlayer ? casterPlayer->wheel()->getBeamAffectedTotal(tmpDamage) : 0; + uint8_t beamAffectedTotal = casterPlayer ? casterPlayer->wheel().getBeamAffectedTotal(tmpDamage) : 0; uint8_t beamAffectedCurrent = 0; tmpDamage.affected = affected; @@ -1265,7 +1265,7 @@ void Combat::CombatFunc(const std::shared_ptr &caster, const Position if (!params.aggressive || (caster != creature && Combat::canDoCombat(caster, creature, params.aggressive) == RETURNVALUE_NOERROR)) { // Wheel of destiny update beam mastery damage if (casterPlayer) { - casterPlayer->wheel()->updateBeamMasteryDamage(tmpDamage, beamAffectedTotal, beamAffectedCurrent); + casterPlayer->wheel().updateBeamMasteryDamage(tmpDamage, beamAffectedTotal, beamAffectedCurrent); } func(caster, creature, params, &tmpDamage); if (params.targetCallback) { @@ -1562,7 +1562,7 @@ uint32_t ValueCallback::getMagicLevelSkill(const std::shared_ptr &player uint32_t magicLevelSkill = player->getMagicLevel(); // Wheel of destiny - if (player && player->wheel()->getInstant("Runic Mastery") && damage.instantSpellName.empty()) { + if (player && player->wheel().getInstant("Runic Mastery") && damage.instantSpellName.empty()) { const std::shared_ptr &spell = g_spells().getRuneSpellByName(damage.runeSpellName); // Rune conjuring spell have the same name as the rune item spell. const std::shared_ptr &conjuringSpell = g_spells().getInstantSpellByName(damage.runeSpellName); diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 327d97f3284..e027bad5a09 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -13,8 +13,7 @@ #include "creatures/combat/combat.hpp" #include "creatures/combat/condition.hpp" #include "creatures/players/player.hpp" -#include "creatures/players/wheel/player_wheel.hpp" -#include "creatures/players/wheel/wheel_definitions.hpp" +#include "creatures/players/components/wheel/wheel_definitions.hpp" #include "enums/account_group_type.hpp" #include "enums/account_type.hpp" #include "game/game.hpp" @@ -732,7 +731,7 @@ int32_t Spell::calculateAugmentSpellCooldownReduction(const std::shared_ptr &player) const { - WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); + WheelSpellGrade_t spellGrade = player->wheel().getSpellUpgrade(getName()); bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0; // Safety check to prevent division by zero auto rateCooldown = g_configManager().getFloat(RATE_SPELL_COOLDOWN); @@ -746,13 +745,13 @@ void Spell::applyCooldownConditions(const std::shared_ptr &player) const spellCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::COOLDOWN, spellGrade); } int32_t augmentCooldownReduction = calculateAugmentSpellCooldownReduction(player); - g_logger().debug("[{}] spell name: {}, spellCooldown: {}, bonus: {}, augment {}", __FUNCTION__, name, spellCooldown, player->wheel()->getSpellBonus(name, WheelSpellBoost_t::COOLDOWN), augmentCooldownReduction); - spellCooldown -= player->wheel()->getSpellBonus(name, WheelSpellBoost_t::COOLDOWN); + g_logger().debug("[{}] spell name: {}, grade: {}, originalCooldown: {}, spellCooldown: {}, bonus: {}, augment {}", __FUNCTION__, name, spellGrade, cooldown, spellCooldown, player->wheel().getSpellBonus(name, WheelSpellBoost_t::COOLDOWN), augmentCooldownReduction); + spellCooldown -= player->wheel().getSpellBonus(name, WheelSpellBoost_t::COOLDOWN); spellCooldown -= augmentCooldownReduction; const int32_t halfBaseCooldown = cooldown / 2; spellCooldown = halfBaseCooldown > spellCooldown ? halfBaseCooldown : spellCooldown; // The cooldown should never be reduced less than half (50%) of its base cooldown if (spellCooldown > 0) { - player->wheel()->handleTwinBurstsCooldown(player, name, spellCooldown, rateCooldown); + player->wheel().handleTwinBurstsCooldown(player, name, spellCooldown, rateCooldown); const auto &condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, spellCooldown / rateCooldown, 0, false, m_spellId); player->addCondition(condition); } @@ -774,9 +773,9 @@ void Spell::applyCooldownConditions(const std::shared_ptr &player) const if (isUpgraded) { spellSecondaryGroupCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::SECONDARY_GROUP_COOLDOWN, spellGrade); } - spellSecondaryGroupCooldown -= player->wheel()->getSpellBonus(name, WheelSpellBoost_t::SECONDARY_GROUP_COOLDOWN); + spellSecondaryGroupCooldown -= player->wheel().getSpellBonus(name, WheelSpellBoost_t::SECONDARY_GROUP_COOLDOWN); if (spellSecondaryGroupCooldown > 0) { - player->wheel()->handleBeamMasteryCooldown(player, name, spellSecondaryGroupCooldown, rateCooldown); + player->wheel().handleBeamMasteryCooldown(player, name, spellSecondaryGroupCooldown, rateCooldown); const auto &condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellSecondaryGroupCooldown / rateCooldown, 0, false, secondaryGroup); player->addCondition(condition); } @@ -838,12 +837,12 @@ bool Spell::isLearnable() const { } uint32_t Spell::getManaCost(const std::shared_ptr &player) const { - WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); + WheelSpellGrade_t spellGrade = player->wheel().getSpellUpgrade(getName()); uint32_t manaRedution = 0; if (getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0) { manaRedution += getWheelOfDestinyBoost(WheelSpellBoost_t::MANA, spellGrade); } - manaRedution += player->wheel()->getSpellBonus(name, WheelSpellBoost_t::MANA); + manaRedution += player->wheel().getSpellBonus(name, WheelSpellBoost_t::MANA); if (mana != 0) { if (manaRedution > mana) { diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 7276bea19d1..90610d90399 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -13,7 +13,6 @@ #include "creatures/combat/spells.hpp" #include "creatures/monsters/monsters.hpp" #include "creatures/players/player.hpp" -#include "creatures/players/wheel/player_wheel.hpp" #include "game/game.hpp" #include "game/scheduling/dispatcher.hpp" #include "items/tile.hpp" @@ -897,8 +896,8 @@ BlockType_t Monster::blockHit(const std::shared_ptr &attacker, const C // Wheel of destiny const auto &player = attacker ? attacker->getPlayer() : nullptr; - if (player && player->wheel()->getInstant("Ballistic Mastery")) { - elementMod -= player->wheel()->checkElementSensitiveReduction(combatType); + if (player && player->wheel().getInstant("Ballistic Mastery")) { + elementMod -= player->wheel().checkElementSensitiveReduction(combatType); } if (elementMod != 0) { @@ -2426,7 +2425,7 @@ bool Monster::challengeCreature(const std::shared_ptr &creature, int t // Wheel of destiny const auto &player = creature ? creature->getPlayer() : nullptr; if (player && !player->isRemoved()) { - player->wheel()->healIfBattleHealingActive(); + player->wheel().healIfBattleHealingActive(); } } return result; diff --git a/src/creatures/players/components/player_achievement.cpp b/src/creatures/players/components/player_achievement.cpp index 0be4244b25e..2344d5d3ca0 100644 --- a/src/creatures/players/components/player_achievement.cpp +++ b/src/creatures/players/components/player_achievement.cpp @@ -7,9 +7,9 @@ * Website: https://docs.opentibiabr.com/ */ -#include "creatures/players/achievement/player_achievement.hpp" - +// Player.hpp already includes the achievement #include "creatures/players/player.hpp" + #include "game/game.hpp" #include "kv/kv.hpp" diff --git a/src/creatures/players/components/player_badge.cpp b/src/creatures/players/components/player_badge.cpp index c27e98cb1aa..95ca06337e7 100644 --- a/src/creatures/players/components/player_badge.cpp +++ b/src/creatures/players/components/player_badge.cpp @@ -7,10 +7,10 @@ * Website: https://docs.opentibiabr.com/ */ -#include "creatures/players/cyclopedia/player_badge.hpp" +// Player.hpp already includes the badge +#include "creatures/players/player.hpp" #include "account/account.hpp" -#include "creatures/players/player.hpp" #include "enums/account_errors.hpp" #include "enums/player_cyclopedia.hpp" #include "game/game.hpp" diff --git a/src/creatures/players/components/player_cyclopedia.cpp b/src/creatures/players/components/player_cyclopedia.cpp index 980d6897c31..e7fddc26d63 100644 --- a/src/creatures/players/components/player_cyclopedia.cpp +++ b/src/creatures/players/components/player_cyclopedia.cpp @@ -7,9 +7,9 @@ * Website: https://docs.opentibiabr.com/ */ -#include "creatures/players/cyclopedia/player_cyclopedia.hpp" - +// Player.hpp already includes the cylopedia #include "creatures/players/player.hpp" + #include "database/databasetasks.hpp" #include "enums/player_blessings.hpp" #include "enums/player_cyclopedia.hpp" diff --git a/src/creatures/players/components/player_title.cpp b/src/creatures/players/components/player_title.cpp index 089d02f281c..fc958c39cbf 100644 --- a/src/creatures/players/components/player_title.cpp +++ b/src/creatures/players/components/player_title.cpp @@ -7,11 +7,11 @@ * Website: https://docs.opentibiabr.com/ */ -#include "creatures/players/cyclopedia/player_title.hpp" +// Player.hpp already includes the title +#include "creatures/players/player.hpp" #include "creatures/appearance/mounts/mounts.hpp" #include "creatures/monsters/monsters.hpp" -#include "creatures/players/player.hpp" #include "enums/account_group_type.hpp" #include "game/game.hpp" #include "kv/kv.hpp" diff --git a/src/creatures/players/components/player_vip.cpp b/src/creatures/players/components/player_vip.cpp index 8a64aebcf85..22ed33a61a3 100644 --- a/src/creatures/players/components/player_vip.cpp +++ b/src/creatures/players/components/player_vip.cpp @@ -7,11 +7,11 @@ * Website: https://docs.opentibiabr.com/ */ -#include "creatures/players/vip/player_vip.hpp" +// Player.hpp already includes the vip +#include "creatures/players/player.hpp" #include "account/account.hpp" #include "creatures/players/grouping/groups.hpp" -#include "creatures/players/player.hpp" #include "io/iologindata.hpp" #include "server/network/protocol/protocolgame.hpp" diff --git a/src/creatures/players/components/wheel/player_wheel.cpp b/src/creatures/players/components/wheel/player_wheel.cpp index 7d39720dc4d..470a36a9116 100644 --- a/src/creatures/players/components/wheel/player_wheel.cpp +++ b/src/creatures/players/components/wheel/player_wheel.cpp @@ -7,16 +7,15 @@ * Website: https://docs.opentibiabr.org/ */ -#include "creatures/players/wheel/player_wheel.hpp" +// Player.hpp already includes the wheel +#include "creatures/players/player.hpp" #include "map/spectators.hpp" #include "creatures/monsters/monster.hpp" #include "config/configmanager.hpp" #include "creatures/combat/condition.hpp" #include "creatures/combat/spells.hpp" -#include "creatures/players/player.hpp" #include "creatures/players/vocations/vocation.hpp" -#include "creatures/players/wheel/wheel_gems.hpp" #include "enums/player_wheel.hpp" #include "game/game.hpp" #include "io/io_wheel.hpp" @@ -24,6 +23,7 @@ #include "kv/kv_definitions.hpp" #include "server/network/message/networkmessage.hpp" #include "server/network/protocol/protocolgame.hpp" +#include "creatures/players/components/wheel/wheel_definitions.hpp" std::array m_resistance = { 0 }; @@ -883,8 +883,8 @@ uint16_t PlayerWheel::getUnusedPoints() const { g_logger().error("[{}] supreme modifications not found for vocation base id: {}", std::source_location::current().function_name(), vocationBaseId); } - for (uint8_t i = WheelSlots_t::SLOT_FIRST; i <= WheelSlots_t::SLOT_LAST; ++i) { - totalPoints -= getPointsBySlotType(static_cast(i)); + for (auto slot : magic_enum::enum_values()) { + totalPoints -= getPointsBySlotType(slot); } return totalPoints; @@ -1513,8 +1513,8 @@ void PlayerWheel::sendOpenWheelWindow(NetworkMessage &msg, uint32_t ownerId) { msg.add(getWheelPoints(false)); // Points (false param for not send extra points) msg.add(getExtraPoints()); // Extra points - for (uint8_t i = WheelSlots_t::SLOT_FIRST; i <= WheelSlots_t::SLOT_LAST; ++i) { - msg.add(getPointsBySlotType(i)); + for (auto slot : magic_enum::enum_values()) { + msg.add(getPointsBySlotType(slot)); } addPromotionScrolls(msg); addGems(msg); @@ -1603,7 +1603,7 @@ void PlayerWheel::saveSlotPointsOnPressSaveButton(NetworkMessage &msg) { // Creates a vector to store slot information in order. std::vector sortedTable; // Iterates over all slots, getting the points for each slot from the message. If the slot points exceed - for (uint8_t slot = WheelSlots_t::SLOT_FIRST; slot <= WheelSlots_t::SLOT_LAST; ++slot) { + for (auto slot : magic_enum::enum_values()) { auto slotPoints = msg.get(); // Points per Slot auto maxPointsPerSlot = getMaxPointsPerSlot(static_cast(slot)); if (slotPoints > maxPointsPerSlot) { @@ -1619,7 +1619,7 @@ void PlayerWheel::saveSlotPointsOnPressSaveButton(NetworkMessage &msg) { } // The slot information is then added to the vector in order. - sortedTable.emplace_back(order, slot, slotPoints); + sortedTable.emplace_back(order, enumToValue(slot), slotPoints); } // After iterating over all slots, the vector is sorted according to the slot order. @@ -1991,16 +1991,6 @@ void PlayerWheel::registerPlayerBonusData() { for (int i = 0; i < m_playerBonusData.stages.divineGrenade; ++i) { setSpellInstant("Divine Grenade", true); } - if (m_playerBonusData.stages.divineGrenade >= 2) { - WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 4 * 1000; - addSpellBonus("Divine Grenade", bonus); - } - if (m_playerBonusData.stages.divineGrenade >= 3) { - WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 6 * 1000; - addSpellBonus("Divine Grenade", bonus); - } } else { setSpellInstant("Divine Grenade", false); } @@ -2313,11 +2303,11 @@ void PlayerWheel::loadDedicationAndConvictionPerks() { return; } - for (uint8_t i = WheelSlots_t::SLOT_FIRST; i <= WheelSlots_t::SLOT_LAST; ++i) { - const uint16_t points = getPointsBySlotType(static_cast(i)); + for (auto slot : magic_enum::enum_values()) { + const uint16_t points = getPointsBySlotType(slot); if (points > 0) { VocationBonusFunction internalData = nullptr; - auto it = wheelFunctions.find(static_cast(i)); + auto it = wheelFunctions.find(slot); if (it != wheelFunctions.end()) { internalData = it->second; } @@ -3632,9 +3622,9 @@ void PlayerWheel::sendOpenWheelWindow(uint32_t ownerId) const { } } -uint16_t PlayerWheel::getPointsBySlotType(uint8_t slotType) const { +uint16_t PlayerWheel::getPointsBySlotType(WheelSlots_t slotType) const { try { - return m_wheelSlots.at(slotType); + return m_wheelSlots.at(static_cast(slotType)); } catch (const std::out_of_range &e) { g_logger().error("[{}]. Index {} is out of range, invalid slot type. Error message: {}", __FUNCTION__, slotType, e.what()); return 0; diff --git a/src/creatures/players/components/wheel/player_wheel.hpp b/src/creatures/players/components/wheel/player_wheel.hpp index 7c3bd2348a6..cc2697e8785 100644 --- a/src/creatures/players/components/wheel/player_wheel.hpp +++ b/src/creatures/players/components/wheel/player_wheel.hpp @@ -10,7 +10,7 @@ #pragma once #include "creatures/creatures_definitions.hpp" -#include "creatures/players/wheel/wheel_definitions.hpp" +#include "creatures/players/components/wheel/wheel_definitions.hpp" class Creature; class IOWheel; @@ -22,16 +22,89 @@ class WheelModifierContext; class ValueWrapper; struct CombatDamage; +struct SlotInfo; enum class WheelFragmentType_t : uint8_t; enum class WheelGemAffinity_t : uint8_t; enum class WheelGemBasicModifier_t : uint8_t; enum class WheelGemQuality_t : uint8_t; enum class WheelGemSupremeModifier_t : uint8_t; + enum CombatType_t : uint8_t; enum skills_t : int8_t; enum Vocation_t : uint16_t; +namespace WheelSpells { + struct Bonus; +} + +struct PlayerWheelMethodsBonusData { + // Raw value. Example: 1 == 1 + struct Stats { + int health = 0; + int mana = 0; + int capacity = 0; + int damage = 0; + int healing = 0; + }; + // value * 100. Example: 1% == 100 + std::array unlockedVesselResonances = {}; + + // Raw value. Example: 1 == 1 + struct Skills { + int melee = 0; + int distance = 0; + int magic = 0; + }; + + // value * 100. Example: 1% == 100 + struct Leech { + double manaLeech = 0; + double lifeLeech = 0; + }; + + struct Instant { + bool battleInstinct = false; // Knight + bool battleHealing = false; // Knight + bool positionalTactics = false; // Paladin + bool ballisticMastery = false; // Paladin + bool healingLink = false; // Druid + bool runicMastery = false; // Druid/sorcerer + bool focusMastery = false; // Sorcerer + }; + + struct Stages { + int combatMastery = 0; // Knight + int giftOfLife = 0; // Knight/Paladin/Druid/Sorcerer + int divineEmpowerment = 0; // Paladin + int divineGrenade = 0; // Paladin + int blessingOfTheGrove = 0; // Druid + int drainBody = 0; // Sorcerer + int beamMastery = 0; // Sorcerer + int twinBurst = 0; // Druid + int executionersThrow = 0; // Knight + }; + + struct Avatar { + int light = 0; // Paladin + int nature = 0; // Druid + int steel = 0; // Knight + int storm = 0; // Sorcerer + }; + + // Initialize structs + Stats stats; + Skills skills; + Leech leech; + Instant instant; + Stages stages; + Avatar avatar; + + float momentum = 0; + float mitigation = 0; + std::vector spells; +}; + struct PlayerWheelGem { std::string uuid; bool locked; @@ -340,7 +413,7 @@ class PlayerWheel { void sendOpenWheelWindow(uint32_t ownerId) const; - uint16_t getPointsBySlotType(uint8_t slotType) const; + uint16_t getPointsBySlotType(WheelSlots_t slotType) const; const std::array &getSlots() const; @@ -415,17 +488,17 @@ class PlayerWheel { Player &m_player; // Starting count in 1 (1-37), slot enums are from 1 to 36, but the index always starts at 0 in c++ - std::array m_wheelSlots = {}; + std::array() + 1> m_wheelSlots = {}; std::array m_bonusRevelationPoints = { 0, 0, 0, 0 }; PlayerWheelMethodsBonusData m_playerBonusData; std::unique_ptr m_modifierContext; - std::array(WheelStage_t::STAGE_COUNT)> m_stages = { 0 }; - std::array(WheelOnThink_t::TOTAL_COUNT)> m_onThink = { 0 }; - std::array(WheelStat_t::TOTAL_COUNT)> m_stats = { 0 }; - std::array(WheelMajor_t::TOTAL_COUNT)> m_majorStats = { 0 }; - std::array(WheelInstant_t::INSTANT_COUNT)> m_instant = { false }; + std::array()> m_stages = { 0 }; + std::array()> m_onThink = { 0 }; + std::array()> m_stats = { 0 }; + std::array()> m_majorStats = { 0 }; + std::array()> m_instant = { false }; std::array m_resistance = { 0 }; std::array m_specializedMagic = { 0 }; diff --git a/src/creatures/players/components/wheel/wheel_definitions.hpp b/src/creatures/players/components/wheel/wheel_definitions.hpp index a136bd620d3..e88cb9a62df 100644 --- a/src/creatures/players/components/wheel/wheel_definitions.hpp +++ b/src/creatures/players/components/wheel/wheel_definitions.hpp @@ -9,7 +9,7 @@ #pragma once -enum WheelSlots_t : uint8_t { +enum class WheelSlots_t : uint8_t { SLOT_GREEN_200 = 1, SLOT_GREEN_TOP_150 = 2, SLOT_GREEN_TOP_100 = 3, @@ -57,18 +57,13 @@ enum WheelSlots_t : uint8_t { SLOT_PURPLE_BOTTOM_100 = 34, SLOT_PURPLE_BOTTOM_150 = 35, SLOT_PURPLE_200 = 36, - - SLOT_FIRST = SLOT_GREEN_200, - SLOT_LAST = SLOT_PURPLE_200 }; -enum class WheelStageEnum_t { +enum class WheelStageEnum_t : uint8_t { NONE = 0, ONE = 1, TWO = 2, THREE = 3, - - TOTAL_COUNT = 4 }; enum class WheelStagePointsEnum_t { @@ -189,73 +184,6 @@ enum class WheelSpellBoost_t : uint8_t { TOTAL_COUNT = 13 }; -struct PlayerWheelMethodsBonusData { - // Raw value. Example: 1 == 1 - struct Stats { - int health = 0; - int mana = 0; - int capacity = 0; - int damage = 0; - int healing = 0; - }; - // value * 100. Example: 1% == 100 - std::array unlockedVesselResonances = {}; - - // Raw value. Example: 1 == 1 - struct Skills { - int melee = 0; - int distance = 0; - int magic = 0; - }; - - // value * 100. Example: 1% == 100 - struct Leech { - double manaLeech = 0; - double lifeLeech = 0; - }; - - struct Instant { - bool battleInstinct = false; // Knight - bool battleHealing = false; // Knight - bool positionalTactics = false; // Paladin - bool ballisticMastery = false; // Paladin - bool healingLink = false; // Druid - bool runicMastery = false; // Druid/sorcerer - bool focusMastery = false; // Sorcerer - }; - - struct Stages { - int combatMastery = 0; // Knight - int giftOfLife = 0; // Knight/Paladin/Druid/Sorcerer - int divineEmpowerment = 0; // Paladin - int divineGrenade = 0; // Paladin - int blessingOfTheGrove = 0; // Druid - int drainBody = 0; // Sorcerer - int beamMastery = 0; // Sorcerer - int twinBurst = 0; // Druid - int executionersThrow = 0; // Knight - }; - - struct Avatar { - int light = 0; // Paladin - int nature = 0; // Druid - int steel = 0; // Knight - int storm = 0; // Sorcerer - }; - - // Initialize structs - Stats stats; - Skills skills; - Leech leech; - Instant instant; - Stages stages; - Avatar avatar; - - float momentum = 0; - float mitigation = 0; - std::vector spells; -}; - /** * @brief Slot information struct. * @@ -266,33 +194,3 @@ struct SlotInfo { uint8_t slot; ///< The slot index. uint16_t points; ///< The points for the slot. }; - -namespace WheelSpells { - struct Increase { - bool area = false; - int damage = 0; - int heal = 0; - int aditionalTarget = 0; - int damageReduction = 0; - int duration = 0; - int criticalDamage = 0; - int criticalChance = 0; - }; - - struct Decrease { - int cooldown = 0; - int manaCost = 0; - int secondaryGroupCooldown = 0; - }; - - struct Leech { - int mana = 0; - int life = 0; - }; - - struct Bonus { - Leech leech; - Increase increase; - Decrease decrease; - }; -} diff --git a/src/creatures/players/components/wheel/wheel_gems.cpp b/src/creatures/players/components/wheel/wheel_gems.cpp index 766fa9ee049..b7e1e32a5ee 100644 --- a/src/creatures/players/components/wheel/wheel_gems.cpp +++ b/src/creatures/players/components/wheel/wheel_gems.cpp @@ -7,10 +7,12 @@ * Website: https://docs.opentibiabr.org/ */ -#include "creatures/players/wheel/wheel_gems.hpp" +#include "creatures/players/components/wheel/wheel_gems.hpp" + +#include "creatures/players/components/wheel/player_wheel.hpp" +#include "creatures/players/components/wheel/wheel_definitions.hpp" #include "creatures/creatures_definitions.hpp" -#include "creatures/players/wheel/player_wheel.hpp" #include "enums/player_wheel.hpp" void GemModifierResistanceStrategy::execute() { diff --git a/src/creatures/players/components/wheel/wheel_gems.hpp b/src/creatures/players/components/wheel/wheel_gems.hpp index 7b748266781..2c3cac08682 100644 --- a/src/creatures/players/components/wheel/wheel_gems.hpp +++ b/src/creatures/players/components/wheel/wheel_gems.hpp @@ -9,7 +9,7 @@ #pragma once -#include "creatures/players/wheel/wheel_definitions.hpp" +#include "creatures/players/components/wheel/wheel_spells.hpp" class PlayerWheel; diff --git a/src/creatures/players/components/wheel/wheel_spells.hpp b/src/creatures/players/components/wheel/wheel_spells.hpp new file mode 100644 index 00000000000..d6b85aae34b --- /dev/null +++ b/src/creatures/players/components/wheel/wheel_spells.hpp @@ -0,0 +1,40 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 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.org/ + */ + +#pragma once + +namespace WheelSpells { + struct Increase { + bool area = false; + int damage = 0; + int heal = 0; + int aditionalTarget = 0; + int damageReduction = 0; + int duration = 0; + int criticalDamage = 0; + int criticalChance = 0; + }; + + struct Decrease { + int cooldown = 0; + int manaCost = 0; + int secondaryGroupCooldown = 0; + }; + + struct Leech { + int mana = 0; + int life = 0; + }; + + struct Bonus { + Leech leech; + Increase increase; + Decrease decrease; + }; +} diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index d838f8b96a0..67c1da14e62 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -19,17 +19,9 @@ #include "creatures/monsters/monster.hpp" #include "creatures/monsters/monsters.hpp" #include "creatures/npcs/npc.hpp" -#include "creatures/players/wheel/player_wheel.hpp" -#include "creatures/players/wheel/wheel_gems.hpp" -#include "creatures/players/achievement/player_achievement.hpp" -#include "creatures/players/cyclopedia/player_badge.hpp" -#include "creatures/players/cyclopedia/player_cyclopedia.hpp" -#include "creatures/players/cyclopedia/player_title.hpp" #include "creatures/players/grouping/party.hpp" #include "creatures/players/imbuements/imbuements.hpp" #include "creatures/players/storages/storages.hpp" -#include "creatures/players/vip/player_vip.hpp" -#include "creatures/players/wheel/player_wheel.hpp" #include "server/network/protocol/protocolgame.hpp" #include "enums/account_errors.hpp" #include "enums/account_group_type.hpp" @@ -63,6 +55,7 @@ #include "lua/creature/movement.hpp" #include "map/spectators.hpp" #include "creatures/players/vocations/vocation.hpp" +#include "creatures/players/components/wheel/wheel_definitions.hpp" MuteCountMap Player::muteCountMap; @@ -70,14 +63,13 @@ Player::Player(std::shared_ptr p) : lastPing(OTSYS_TIME()), lastPong(lastPing), inbox(std::make_shared(ITEM_INBOX)), - client(std::move(p)) { - m_playerVIP = std::make_unique(*this); - m_wheelPlayer = std::make_unique(*this); - m_playerAchievement = std::make_unique(*this); - m_playerBadge = std::make_unique(*this); - m_playerCyclopedia = std::make_unique(*this); - m_playerTitle = std::make_unique(*this); -} + client(std::move(p)), + m_playerVIP(*this), + m_wheelPlayer(*this), + m_playerAchievement(*this), + m_playerBadge(*this), + m_playerCyclopedia(*this), + m_playerTitle(*this) { } Player::~Player() { for (const auto &item : inventory) { @@ -150,7 +142,7 @@ std::string Player::getDescription(int32_t lookDistance) { std::ostringstream s; std::string subjectPronoun = getSubjectPronoun(); capitalizeWords(subjectPronoun); - const auto playerTitle = title()->getCurrentTitle() == 0 ? "" : (", " + title()->getCurrentTitleName()); + const auto playerTitle = title().getCurrentTitle() == 0 ? "" : (", " + title().getCurrentTitleName()); if (lookDistance == -1) { s << "yourself" << playerTitle << "."; @@ -436,7 +428,7 @@ void Player::getShieldAndWeapon(std::shared_ptr &shield, std::shared_ptrcalculateMitigation(); + return wheel().calculateMitigation(); } int32_t Player::getDefense() const { @@ -459,7 +451,7 @@ int32_t Player::getDefense() const { defenseValue = weapon != nullptr ? shield->getDefense() + weapon->getExtraDefense() : shield->getDefense(); // Wheel of destiny - Combat Mastery if (shield->getDefense() > 0) { - defenseValue += wheel()->getMajorStatConditional("Combat Mastery", WheelMajor_t::DEFENSE); + defenseValue += wheel().getMajorStatConditional("Combat Mastery", WheelMajor_t::DEFENSE); } defenseSkill = getSkillLevel(SKILL_SHIELD); } @@ -2424,8 +2416,8 @@ void Player::onChangeZone(ZoneType_t zone) { } updateImbuementTrackerStats(); - wheel()->onThink(true); - wheel()->sendGiftOfLifeCooldown(); + wheel().onThink(true); + wheel().sendGiftOfLifeCooldown(); g_game().updateCreatureWalkthrough(static_self_cast()); sendIcons(); g_events().eventPlayerOnChangeZone(static_self_cast(), zone); @@ -2779,10 +2771,10 @@ int32_t Player::getIdleTime() const { void Player::setTraining(bool value) { for (const auto &[key, player] : g_game().getPlayers()) { if (!this->isInGhostMode() || player->isAccessPlayer()) { - player->vip()->notifyStatusChange(static_self_cast(), value ? VipStatus_t::Training : VipStatus_t::Online, false); + player->vip().notifyStatusChange(static_self_cast(), value ? VipStatus_t::Training : VipStatus_t::Online, false); } } - vip()->setStatus(VipStatus_t::Training); + vip().setStatus(VipStatus_t::Training); setExerciseTraining(value); } @@ -3374,7 +3366,7 @@ BlockType_t Player::blockHit(const std::shared_ptr &attacker, const Co } // Wheel of destiny - apply resistance - wheel()->adjustDamageBasedOnResistanceAndSkill(damage, combatType); + wheel().adjustDamageBasedOnResistanceAndSkill(damage, combatType); if (damage <= 0) { damage = 0; @@ -3746,7 +3738,7 @@ void Player::despawn() { // show player as pending for (const auto &[key, player] : g_game().getPlayers()) { - player->vip()->notifyStatusChange(static_self_cast(), VipStatus_t::Pending, false); + player->vip().notifyStatusChange(static_self_cast(), VipStatus_t::Pending, false); } setDead(true); @@ -3779,7 +3771,7 @@ std::shared_ptr Player::getCorpse(const std::shared_ptr &lastHit } void Player::addInFightTicks(bool pzlock /*= false*/) { - wheel()->checkAbilities(); + wheel().checkAbilities(); if (hasFlag(PlayerFlags_t::NotGainInFight)) { return; @@ -3805,13 +3797,13 @@ void Player::removeList() { g_game().removePlayer(static_self_cast()); for (const auto &[key, player] : g_game().getPlayers()) { - player->vip()->notifyStatusChange(static_self_cast(), VipStatus_t::Offline); + player->vip().notifyStatusChange(static_self_cast(), VipStatus_t::Offline); } } void Player::addList() { for (const auto &[key, player] : g_game().getPlayers()) { - player->vip()->notifyStatusChange(static_self_cast(), vip()->getStatus()); + player->vip().notifyStatusChange(static_self_cast(), vip().getStatus()); } g_game().addPlayer(static_self_cast()); @@ -4681,7 +4673,7 @@ uint32_t Player::getCapacity() const { if (hasFlag(PlayerFlags_t::HasInfiniteCapacity)) { return std::numeric_limits::max(); } - return capacity + bonusCapacity + varStats[STAT_CAPACITY] + (m_wheelPlayer->getStat(WheelStat_t::CAPACITY) * 100); + return capacity + bonusCapacity + varStats[STAT_CAPACITY] + (m_wheelPlayer.getStat(WheelStat_t::CAPACITY) * 100); } uint32_t Player::getBonusCapacity() const { @@ -6356,8 +6348,8 @@ bool Player::isInWarList(uint32_t guildId) const { uint32_t Player::getMagicLevel() const { uint32_t magic = std::max(0, getLoyaltyMagicLevel() + varStats[STAT_MAGICPOINTS]); // Wheel of destiny magic bonus - magic += m_wheelPlayer->getStat(WheelStat_t::MAGIC); // Regular bonus - magic += m_wheelPlayer->getMajorStatConditional("Positional Tactics", WheelMajor_t::MAGIC); // Revelation bonus + magic += m_wheelPlayer.getStat(WheelStat_t::MAGIC); // Regular bonus + magic += m_wheelPlayer.getMajorStatConditional("Positional Tactics", WheelMajor_t::MAGIC); // Revelation bonus return magic; } @@ -6389,11 +6381,11 @@ uint32_t Player::getLoyaltyMagicLevel() const { } int32_t Player::getMaxHealth() const { - return std::max(1, healthMax + varStats[STAT_MAXHITPOINTS] + m_wheelPlayer->getStat(WheelStat_t::HEALTH)); + return std::max(1, healthMax + varStats[STAT_MAXHITPOINTS] + m_wheelPlayer.getStat(WheelStat_t::HEALTH)); } uint32_t Player::getMaxMana() const { - return std::max(0, manaMax + varStats[STAT_MAXMANAPOINTS] + m_wheelPlayer->getStat(WheelStat_t::MANA)); + return std::max(0, manaMax + varStats[STAT_MAXMANAPOINTS] + m_wheelPlayer.getStat(WheelStat_t::MANA)); } bool Player::hasExtraSwing() { @@ -6412,28 +6404,28 @@ uint16_t Player::getSkillLevel(skills_t skill) const { // Wheel of destiny if (skill >= SKILL_CLUB && skill <= SKILL_AXE) { - skillLevel += m_wheelPlayer->getStat(WheelStat_t::MELEE); - skillLevel += m_wheelPlayer->getMajorStatConditional("Battle Instinct", WheelMajor_t::MELEE); + skillLevel += m_wheelPlayer.getStat(WheelStat_t::MELEE); + skillLevel += m_wheelPlayer.getMajorStatConditional("Battle Instinct", WheelMajor_t::MELEE); } else if (skill == SKILL_DISTANCE) { - skillLevel += m_wheelPlayer->getMajorStatConditional("Positional Tactics", WheelMajor_t::DISTANCE); - skillLevel += m_wheelPlayer->getStat(WheelStat_t::DISTANCE); + skillLevel += m_wheelPlayer.getMajorStatConditional("Positional Tactics", WheelMajor_t::DISTANCE); + skillLevel += m_wheelPlayer.getStat(WheelStat_t::DISTANCE); } else if (skill == SKILL_SHIELD) { - skillLevel += m_wheelPlayer->getMajorStatConditional("Battle Instinct", WheelMajor_t::SHIELD); + skillLevel += m_wheelPlayer.getMajorStatConditional("Battle Instinct", WheelMajor_t::SHIELD); } else if (skill == SKILL_MAGLEVEL) { - skillLevel += m_wheelPlayer->getMajorStatConditional("Positional Tactics", WheelMajor_t::MAGIC); - skillLevel += m_wheelPlayer->getStat(WheelStat_t::MAGIC); + skillLevel += m_wheelPlayer.getMajorStatConditional("Positional Tactics", WheelMajor_t::MAGIC); + skillLevel += m_wheelPlayer.getStat(WheelStat_t::MAGIC); } else if (skill == SKILL_LIFE_LEECH_AMOUNT) { - skillLevel += m_wheelPlayer->getStat(WheelStat_t::LIFE_LEECH); + skillLevel += m_wheelPlayer.getStat(WheelStat_t::LIFE_LEECH); } else if (skill == SKILL_MANA_LEECH_AMOUNT) { - skillLevel += m_wheelPlayer->getStat(WheelStat_t::MANA_LEECH); + skillLevel += m_wheelPlayer.getStat(WheelStat_t::MANA_LEECH); } else if (skill == SKILL_CRITICAL_HIT_DAMAGE) { - skillLevel += m_wheelPlayer->getStat(WheelStat_t::CRITICAL_DAMAGE); - skillLevel += m_wheelPlayer->getMajorStatConditional("Combat Mastery", WheelMajor_t::CRITICAL_DMG_2); - skillLevel += m_wheelPlayer->getMajorStatConditional("Ballistic Mastery", WheelMajor_t::CRITICAL_DMG); - skillLevel += m_wheelPlayer->checkAvatarSkill(WheelAvatarSkill_t::CRITICAL_DAMAGE); + skillLevel += m_wheelPlayer.getStat(WheelStat_t::CRITICAL_DAMAGE); + skillLevel += m_wheelPlayer.getMajorStatConditional("Combat Mastery", WheelMajor_t::CRITICAL_DMG_2); + skillLevel += m_wheelPlayer.getMajorStatConditional("Ballistic Mastery", WheelMajor_t::CRITICAL_DMG); + skillLevel += m_wheelPlayer.checkAvatarSkill(WheelAvatarSkill_t::CRITICAL_DAMAGE); } - const int32_t avatarCritChance = m_wheelPlayer->checkAvatarSkill(WheelAvatarSkill_t::CRITICAL_CHANCE); + const int32_t avatarCritChance = m_wheelPlayer.checkAvatarSkill(WheelAvatarSkill_t::CRITICAL_CHANCE); if (skill == SKILL_CRITICAL_HIT_CHANCE && avatarCritChance > 0) { skillLevel = avatarCritChance; // 100% } @@ -6522,7 +6514,7 @@ void Player::setPerfectShotDamage(uint8_t range, int32_t damage) { } int32_t Player::getSpecializedMagicLevel(CombatType_t combat, bool useCharges) const { - int32_t result = specializedMagicLevel[combatTypeToIndex(combat)] + m_wheelPlayer->getSpecializedMagic(combat); + int32_t result = specializedMagicLevel[combatTypeToIndex(combat)] + m_wheelPlayer.getSpecializedMagic(combat); for (const auto &item : getEquippedItems()) { const ItemType &itemType = Item::items[item->getID()]; if (!itemType.abilities) { @@ -6825,9 +6817,15 @@ void Player::sendUnjustifiedPoints() const { uint8_t Player::getLastMount() const { const int32_t value = getStorageValue(PSTRG_MOUNTS_CURRENTMOUNT); if (value > 0) { - return value; + return static_cast(value); + } + + auto lastMountOpt = kv()->get("last-mount"); + if (lastMountOpt) { + return static_cast(lastMountOpt->get()); } - return static_cast(kv()->get("last-mount")->get()); + + return 0; } uint8_t Player::getCurrentMount() const { @@ -7470,7 +7468,7 @@ void Player::onThink(uint32_t interval) { } // Wheel of destiny major spells - wheel()->onThink(); + wheel().onThink(); g_callbacks().executeCallback(EventCallback_t::playerOnThink, &EventCallback::playerOnThink, getPlayer(), interval); } @@ -8741,7 +8739,7 @@ void Player::triggerMomentum() { chance += item->getMomentumChance(); } - chance += m_wheelPlayer->getBonusData().momentum; + chance += m_wheelPlayer.getBonusData().momentum; double_t randomChance = uniform_random(0, 10000) / 100.; if (getZoneType() != ZONE_PROTECTION && hasCondition(CONDITION_INFIGHT) && ((OTSYS_TIME() / 1000) % 2) == 0 && chance > 0 && randomChance < chance) { bool triggered = false; @@ -8790,7 +8788,7 @@ void Player::clearCooldowns() { } void Player::triggerTranscendance() { - if (wheel()->getOnThinkTimer(WheelOnThink_t::AVATAR_FORGE) > OTSYS_TIME()) { + if (wheel().getOnThinkTimer(WheelOnThink_t::AVATAR_FORGE) > OTSYS_TIME()) { return; } @@ -8808,7 +8806,7 @@ void Player::triggerTranscendance() { outfit.lookType = getVocation()->getAvatarLookType(); outfitCondition->setOutfit(outfit); addCondition(outfitCondition); - wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR_FORGE, OTSYS_TIME() + duration); + wheel().setOnThinkTimer(WheelOnThink_t::AVATAR_FORGE, OTSYS_TIME() + duration); g_game().addMagicEffect(getPosition(), CONST_ME_AVATAR_APPEAR); sendSkills(); @@ -8832,7 +8830,7 @@ void Player::triggerTranscendance() { ); g_dispatcher().scheduleEvent(task); - wheel()->sendGiftOfLifeCooldown(); + wheel().sendGiftOfLifeCooldown(); g_game().reloadCreature(getPlayer()); } } @@ -10199,56 +10197,56 @@ void Player::sendInventoryImbuements(const std::map &Player::wheel() { +PlayerWheel &Player::wheel() { return m_wheelPlayer; } -const std::unique_ptr &Player::wheel() const { +const PlayerWheel &Player::wheel() const { return m_wheelPlayer; } // Achievement interface -std::unique_ptr &Player::achiev() { +PlayerAchievement &Player::achiev() { return m_playerAchievement; } -const std::unique_ptr &Player::achiev() const { +const PlayerAchievement &Player::achiev() const { return m_playerAchievement; } // Badge interface -std::unique_ptr &Player::badge() { +PlayerBadge &Player::badge() { return m_playerBadge; } -const std::unique_ptr &Player::badge() const { +const PlayerBadge &Player::badge() const { return m_playerBadge; } // Title interface -std::unique_ptr &Player::title() { +PlayerTitle &Player::title() { return m_playerTitle; } -const std::unique_ptr &Player::title() const { +const PlayerTitle &Player::title() const { return m_playerTitle; } // VIP interface -std::unique_ptr &Player::vip() { +PlayerVIP &Player::vip() { return m_playerVIP; } -const std::unique_ptr &Player::vip() const { +const PlayerVIP &Player::vip() const { return m_playerVIP; } // Cyclopedia -std::unique_ptr &Player::cyclopedia() { +PlayerCyclopedia &Player::cyclopedia() { return m_playerCyclopedia; } -const std::unique_ptr &Player::cyclopedia() const { +const PlayerCyclopedia &Player::cyclopedia() const { return m_playerCyclopedia; } @@ -10334,7 +10332,7 @@ uint16_t Player::getDodgeChance() const { chance += static_cast(playerArmor->getDodgeChance() * 100); } - chance += m_wheelPlayer->getStat(WheelStat_t::DODGE); + chance += m_wheelPlayer.getStat(WheelStat_t::DODGE); return chance; } diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 03f248cfa2f..7f46b59ed8f 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -17,6 +17,14 @@ #include "game/movement/position.hpp" #include "creatures/creatures_definitions.hpp" +#include "creatures/players/components/player_achievement.hpp" +#include "creatures/players/components/player_badge.hpp" +#include "creatures/players/components/player_cyclopedia.hpp" +#include "creatures/players/components/player_title.hpp" +#include "creatures/players/components/wheel/player_wheel.hpp" +#include "creatures/players/components/player_vip.hpp" +#include "creatures/players/components/wheel/wheel_gems.hpp" + class House; class NetworkMessage; class Weapon; @@ -1227,28 +1235,28 @@ class Player final : public Creature, public Cylinder, public Bankable { std::vector> getEquippedItems() const; // Player wheel interface - std::unique_ptr &wheel(); - const std::unique_ptr &wheel() const; + PlayerWheel &wheel(); + const PlayerWheel &wheel() const; // Player achievement interface - std::unique_ptr &achiev(); - const std::unique_ptr &achiev() const; + PlayerAchievement &achiev(); + const PlayerAchievement &achiev() const; // Player badge interface - std::unique_ptr &badge(); - const std::unique_ptr &badge() const; + PlayerBadge &badge(); + const PlayerBadge &badge() const; // Player title interface - std::unique_ptr &title(); - const std::unique_ptr &title() const; + PlayerTitle &title(); + const PlayerTitle &title() const; // Player summary interface - std::unique_ptr &cyclopedia(); - const std::unique_ptr &cyclopedia() const; + PlayerCyclopedia &cyclopedia(); + const PlayerCyclopedia &cyclopedia() const; // Player vip interface - std::unique_ptr &vip(); - const std::unique_ptr &vip() const; + PlayerVIP &vip(); + const PlayerVIP &vip() const; void sendLootMessage(const std::string &message) const; @@ -1615,12 +1623,12 @@ class Player final : public Creature, public Cylinder, public Bankable { friend class PlayerTitle; friend class PlayerVIP; - std::unique_ptr m_wheelPlayer; - std::unique_ptr m_playerAchievement; - std::unique_ptr m_playerBadge; - std::unique_ptr m_playerCyclopedia; - std::unique_ptr m_playerTitle; - std::unique_ptr m_playerVIP; + PlayerWheel m_wheelPlayer; + PlayerAchievement m_playerAchievement; + PlayerBadge m_playerBadge; + PlayerCyclopedia m_playerCyclopedia; + PlayerTitle m_playerTitle; + PlayerVIP m_playerVIP; std::mutex quickLootMutex; diff --git a/src/game/game.cpp b/src/game/game.cpp index 77a277c69ad..6502e10cf6c 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -18,16 +18,11 @@ #include "creatures/monsters/monster.hpp" #include "creatures/monsters/monsters.hpp" #include "creatures/npcs/npc.hpp" -#include "creatures/players/achievement/player_achievement.hpp" -#include "creatures/players/cyclopedia/player_badge.hpp" -#include "creatures/players/cyclopedia/player_cyclopedia.hpp" #include "creatures/players/grouping/party.hpp" #include "creatures/players/grouping/team_finder.hpp" #include "creatures/players/highscore_category.hpp" #include "creatures/players/imbuements/imbuements.hpp" #include "creatures/players/player.hpp" -#include "creatures/players/vip/player_vip.hpp" -#include "creatures/players/wheel/player_wheel.hpp" #include "enums/player_wheel.hpp" #include "database/databasetasks.hpp" #include "game/scheduling/dispatcher.hpp" @@ -63,6 +58,7 @@ #include "utils/tools.hpp" #include "utils/wildcardtree.hpp" #include "creatures/players/vocations/vocation.hpp" +#include "creatures/players/components/wheel/wheel_definitions.hpp" #include "enums/account_coins.hpp" #include "enums/account_errors.hpp" @@ -5933,7 +5929,7 @@ void Game::playerRequestAddVip(uint32_t playerId, const std::string &name) { return; } - player->vip()->add(guid, formattedName, VipStatus_t::Offline); + player->vip().add(guid, formattedName, VipStatus_t::Offline); } else { if (vipPlayer->hasFlag(PlayerFlags_t::SpecialVIP) && !player->hasFlag(PlayerFlags_t::SpecialVIP)) { player->sendTextMessage(MESSAGE_FAILURE, "You can not add this player"); @@ -5941,9 +5937,9 @@ void Game::playerRequestAddVip(uint32_t playerId, const std::string &name) { } if (!vipPlayer->isInGhostMode() || player->isAccessPlayer()) { - player->vip()->add(vipPlayer->getGUID(), vipPlayer->getName(), vipPlayer->vip()->getStatus()); + player->vip().add(vipPlayer->getGUID(), vipPlayer->getName(), vipPlayer->vip().getStatus()); } else { - player->vip()->add(vipPlayer->getGUID(), vipPlayer->getName(), VipStatus_t::Offline); + player->vip().add(vipPlayer->getGUID(), vipPlayer->getName(), VipStatus_t::Offline); } } } @@ -5954,7 +5950,7 @@ void Game::playerRequestRemoveVip(uint32_t playerId, uint32_t guid) { return; } - player->vip()->remove(guid); + player->vip().remove(guid); } void Game::playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::string &description, uint32_t icon, bool notify, std::vector vipGroupsId) { @@ -5963,7 +5959,7 @@ void Game::playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::str return; } - player->vip()->edit(guid, description, icon, notify, vipGroupsId); + player->vip().edit(guid, description, icon, notify, vipGroupsId); } void Game::playerApplyImbuement(uint32_t playerId, uint16_t imbuementid, uint8_t slot, bool protectionCharm) { @@ -6971,10 +6967,10 @@ void Game::applyWheelOfDestinyHealing(CombatDamage &damage, const std::shared_pt damage.primary.value += (damage.primary.value * damage.healingMultiplier) / 100.; if (attackerPlayer) { - damage.primary.value += attackerPlayer->wheel()->getStat(WheelStat_t::HEALING); + damage.primary.value += attackerPlayer->wheel().getStat(WheelStat_t::HEALING); if (damage.secondary.value != 0) { - damage.secondary.value += attackerPlayer->wheel()->getStat(WheelStat_t::HEALING); + damage.secondary.value += attackerPlayer->wheel().getStat(WheelStat_t::HEALING); } if (damage.healingLink > 0) { @@ -6984,8 +6980,8 @@ void Game::applyWheelOfDestinyHealing(CombatDamage &damage, const std::shared_pt combatChangeHealth(attackerPlayer, attackerPlayer, tmpDamage); } - if (attackerPlayer->wheel()->getInstant("Blessing of the Grove")) { - damage.primary.value += (damage.primary.value * attackerPlayer->wheel()->checkBlessingGroveHealingByTarget(target)) / 100.; + if (attackerPlayer->wheel().getInstant("Blessing of the Grove")) { + damage.primary.value += (damage.primary.value * attackerPlayer->wheel().checkBlessingGroveHealingByTarget(target)) / 100.; } } } @@ -7002,26 +6998,26 @@ void Game::applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, const std::s } if (attackerPlayer) { - damage.primary.value -= attackerPlayer->wheel()->getStat(WheelStat_t::DAMAGE); + damage.primary.value -= attackerPlayer->wheel().getStat(WheelStat_t::DAMAGE); if (damage.secondary.value != 0) { - damage.secondary.value -= attackerPlayer->wheel()->getStat(WheelStat_t::DAMAGE); + damage.secondary.value -= attackerPlayer->wheel().getStat(WheelStat_t::DAMAGE); } if (damage.instantSpellName == "Ice Burst" || damage.instantSpellName == "Terra Burst") { - int32_t damageBonus = attackerPlayer->wheel()->checkTwinBurstByTarget(target); + int32_t damageBonus = attackerPlayer->wheel().checkTwinBurstByTarget(target); if (damageBonus != 0) { damage.primary.value += (damage.primary.value * damageBonus) / 100.; damage.secondary.value += (damage.secondary.value * damageBonus) / 100.; } } if (damage.instantSpellName == "Executioner's Throw") { - int32_t damageBonus = attackerPlayer->wheel()->checkExecutionersThrow(target); + int32_t damageBonus = attackerPlayer->wheel().checkExecutionersThrow(target); if (damageBonus != 0) { damage.primary.value += (damage.primary.value * damageBonus) / 100.; damage.secondary.value += (damage.secondary.value * damageBonus) / 100.; } } if (damage.instantSpellName == "Divine Grenade") { - int32_t damageBonus = attackerPlayer->wheel()->checkDivineGrenade(target); + int32_t damageBonus = attackerPlayer->wheel().checkDivineGrenade(target); if (damageBonus != 0) { damage.primary.value += (damage.primary.value * damageBonus) / 100.; damage.secondary.value += (damage.secondary.value * damageBonus) / 100.; @@ -7035,11 +7031,11 @@ int32_t Game::applyHealthChange(const CombatDamage &damage, const std::shared_pt // Wheel of destiny (Gift of Life) 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) { + 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(); - if (overkillMultiplier <= targetPlayer->wheel()->getGiftOfLifeValue()) { - targetPlayer->wheel()->checkGiftOfLife(); + if (overkillMultiplier <= targetPlayer->wheel().getGiftOfLifeValue()) { + targetPlayer->wheel().checkGiftOfLife(); targetHealth = target->getHealth(); } } @@ -7664,8 +7660,8 @@ void Game::applyManaLeech( const std::shared_ptr &attackerPlayer, const std::shared_ptr &targetMonster, const 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); - auto wheelLeechAmount = attackerPlayer->wheel()->checkDrainBodyLeech(target, SKILL_MANA_LEECH_AMOUNT); + auto wheelLeechChance = attackerPlayer->wheel().checkDrainBodyLeech(target, SKILL_MANA_LEECH_CHANCE); + auto wheelLeechAmount = attackerPlayer->wheel().checkDrainBodyLeech(target, SKILL_MANA_LEECH_AMOUNT); uint16_t manaChance = attackerPlayer->getSkillLevel(SKILL_MANA_LEECH_CHANCE) + wheelLeechChance + damage.manaLeechChance; uint16_t manaSkill = attackerPlayer->getSkillLevel(SKILL_MANA_LEECH_AMOUNT) + wheelLeechAmount + damage.manaLeech; @@ -7697,8 +7693,8 @@ void Game::applyLifeLeech( const std::shared_ptr &attackerPlayer, const std::shared_ptr &targetMonster, const 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); - auto wheelLeechAmount = attackerPlayer->wheel()->checkDrainBodyLeech(target, SKILL_LIFE_LEECH_AMOUNT); + auto wheelLeechChance = attackerPlayer->wheel().checkDrainBodyLeech(target, SKILL_LIFE_LEECH_CHANCE); + auto wheelLeechAmount = attackerPlayer->wheel().checkDrainBodyLeech(target, SKILL_LIFE_LEECH_AMOUNT); uint16_t lifeChance = attackerPlayer->getSkillLevel(SKILL_LIFE_LEECH_CHANCE) + wheelLeechChance + damage.lifeLeechChance; uint16_t lifeSkill = attackerPlayer->getSkillLevel(SKILL_LIFE_LEECH_AMOUNT) + wheelLeechAmount + damage.lifeLeech; if (normal_random(0, 100) >= lifeChance) { @@ -8432,7 +8428,7 @@ void Game::kickPlayer(uint32_t playerId, bool displayEffect) { void Game::playerFriendSystemAction(const std::shared_ptr &player, uint8_t type, uint8_t titleId) { if (type == 0x0E) { - player->title()->setCurrentTitle(titleId); + player->title().setCurrentTitle(titleId); player->sendCyclopediaCharacterBaseInformation(); player->sendCyclopediaCharacterTitles(); return; @@ -8458,13 +8454,13 @@ void Game::playerCyclopediaCharacterInfo(const std::shared_ptr &player, player->sendCyclopediaCharacterCombatStats(); break; case CYCLOPEDIA_CHARACTERINFO_RECENTDEATHS: - player->cyclopedia()->loadDeathHistory(page, entriesPerPage); + player->cyclopedia().loadDeathHistory(page, entriesPerPage); break; case CYCLOPEDIA_CHARACTERINFO_RECENTPVPKILLS: - player->cyclopedia()->loadRecentKills(page, entriesPerPage); + player->cyclopedia().loadRecentKills(page, entriesPerPage); break; case CYCLOPEDIA_CHARACTERINFO_ACHIEVEMENTS: - player->achiev()->sendUnlockedSecretAchievements(); + player->achiev().sendUnlockedSecretAchievements(); break; case CYCLOPEDIA_CHARACTERINFO_ITEMSUMMARY: { const ItemsTierCountList &inventoryItems = player->getInventoryItemsId(true); @@ -9828,7 +9824,7 @@ void Game::playerOpenWheel(uint32_t playerId, uint32_t ownerId) { return; } - player->wheel()->sendOpenWheelWindow(ownerId); + player->wheel().sendOpenWheelWindow(ownerId); player->updateUIExhausted(); } @@ -9843,7 +9839,7 @@ void Game::playerSaveWheel(uint32_t playerId, NetworkMessage &msg) { return; } - player->wheel()->saveSlotPointsOnPressSaveButton(msg); + player->wheel().saveSlotPointsOnPressSaveButton(msg); player->updateUIExhausted(); } @@ -9864,20 +9860,20 @@ void Game::playerWheelGemAction(uint32_t playerId, NetworkMessage &msg) { switch (static_cast(action)) { case WheelGemAction_t::Destroy: - player->wheel()->destroyGem(param); + player->wheel().destroyGem(param); break; case WheelGemAction_t::Reveal: - player->wheel()->revealGem(static_cast(param)); + player->wheel().revealGem(static_cast(param)); break; case WheelGemAction_t::SwitchDomain: - player->wheel()->switchGemDomain(param); + player->wheel().switchGemDomain(param); break; case WheelGemAction_t::ToggleLock: - player->wheel()->toggleGemLock(param); + player->wheel().toggleGemLock(param); break; case WheelGemAction_t::ImproveGrade: pos = msg.getByte(); - player->wheel()->improveGemGrade(static_cast(param), pos); + player->wheel().improveGemGrade(static_cast(param), pos); break; default: g_logger().error("[{}] player {} is trying to do invalid action {} on wheel", __FUNCTION__, player->getName(), action); diff --git a/src/game/game.hpp b/src/game/game.hpp index b1afd810100..ae1681d303e 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -10,8 +10,8 @@ #pragma once #include "creatures/appearance/outfit/outfit.hpp" -#include "creatures/players/cyclopedia/player_badge.hpp" -#include "creatures/players/cyclopedia/player_title.hpp" +#include "creatures/players/components/player_badge.hpp" +#include "creatures/players/components/player_title.hpp" #include "creatures/players/grouping/familiars.hpp" #include "creatures/players/grouping/groups.hpp" #include "lua/creature/raids.hpp" @@ -364,7 +364,6 @@ 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 playerRequestAddVip(uint32_t playerId, const std::string &name); void playerRequestRemoveVip(uint32_t playerId, uint32_t guid); @@ -479,7 +478,6 @@ class Game { 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 std::vector> &players, const Position &pos, uint16_t effect); static void addMagicEffect(const CreatureVector &spectators, const Position &pos, uint16_t effect); void removeMagicEffect(const Position &pos, uint16_t effect); static void removeMagicEffect(const CreatureVector &spectators, const Position &pos, uint16_t effect); @@ -709,7 +707,6 @@ class Game { const std::string &getSummaryKeyByType(uint8_t type); - const std::map &getBlessingNames(); const std::unordered_map &getHirelingSkills(); const std::unordered_map &getHirelingOutfits(); diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index 7cb08a7b9a6..31bc60e546f 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -14,13 +14,7 @@ #include "creatures/combat/condition.hpp" #include "database/database.hpp" #include "creatures/monsters/monsters.hpp" -#include "creatures/players/achievement/player_achievement.hpp" -#include "creatures/players/cyclopedia/player_badge.hpp" -#include "creatures/players/cyclopedia/player_cyclopedia.hpp" -#include "creatures/players/cyclopedia/player_title.hpp" -#include "creatures/players/vip/player_vip.hpp" #include "creatures/players/vocations/vocation.hpp" -#include "creatures/players/wheel/player_wheel.hpp" #include "enums/account_coins.hpp" #include "enums/account_errors.hpp" #include "enums/object_category.hpp" @@ -739,14 +733,14 @@ void IOLoginDataLoad::loadPlayerVip(const std::shared_ptr &player, DBRes std::string query = fmt::format("SELECT `player_id` FROM `account_viplist` WHERE `account_id` = {}", accountId); if ((result = db.storeQuery(query))) { do { - player->vip()->addInternal(result->getNumber("player_id")); + player->vip().addInternal(result->getNumber("player_id")); } while (result->next()); } query = fmt::format("SELECT `id`, `name`, `customizable` FROM `account_vipgroups` WHERE `account_id` = {}", accountId); if ((result = db.storeQuery(query))) { do { - player->vip()->addGroupInternal( + player->vip().addGroupInternal( result->getNumber("id"), result->getString("name"), result->getNumber("customizable") == 0 ? false : true @@ -757,7 +751,7 @@ void IOLoginDataLoad::loadPlayerVip(const std::shared_ptr &player, DBRes query = fmt::format("SELECT `player_id`, `vipgroup_id` FROM `account_vipgrouplist` WHERE `account_id` = {}", accountId); if ((result = db.storeQuery(query))) { do { - player->vip()->addGuidToGroupInternal( + player->vip().addGuidToGroupInternal( result->getNumber("vipgroup_id"), result->getNumber("player_id") ); @@ -971,13 +965,13 @@ void IOLoginDataLoad::loadPlayerInitializeSystem(const std::shared_ptr & } // Wheel loading - player->wheel()->loadDBPlayerSlotPointsOnLogin(); - player->wheel()->initializePlayerData(); + player->wheel().loadDBPlayerSlotPointsOnLogin(); + player->wheel().initializePlayerData(); - player->achiev()->loadUnlockedAchievements(); - player->badge()->checkAndUpdateNewBadges(); - player->title()->checkAndUpdateNewTitles(); - player->cyclopedia()->loadSummaryData(); + player->achiev().loadUnlockedAchievements(); + player->badge().checkAndUpdateNewBadges(); + player->title().checkAndUpdateNewTitles(); + player->cyclopedia().loadSummaryData(); player->initializePrey(); player->initializeTaskHunting(); diff --git a/src/io/io_wheel.cpp b/src/io/io_wheel.cpp index 2e1b57c79bc..03bb9c4552f 100644 --- a/src/io/io_wheel.cpp +++ b/src/io/io_wheel.cpp @@ -11,8 +11,8 @@ #include "enums/player_wheel.hpp" #include "kv/kv.hpp" -#include "creatures/players/wheel/player_wheel.hpp" #include "creatures/players/player.hpp" +#include "creatures/players/components/wheel/wheel_definitions.hpp" #include "creatures/combat/spells.hpp" #include "utils/tools.hpp" @@ -79,6 +79,7 @@ namespace InternalPlayerWheel { // Decrease data const auto decreaseData = spellData.decrease; if (decreaseData.cooldown > 0) { + g_logger().info("Registering spell {}, grade {}, cooldown {}", name, gradeType, decreaseData.cooldown); spell->setWheelOfDestinyBoost(WheelSpellBoost_t::COOLDOWN, gradeType, decreaseData.cooldown * 1000); } if (decreaseData.manaCost > 0) { @@ -206,7 +207,7 @@ int8_t IOWheel::getSlotPrioritaryOrder(WheelSlots_t slot) const { return 4; } - g_logger().error("[{}] unknown whell slot type': {}", __FUNCTION__, std::to_string(slot)); + g_logger().error("[{}] unknown wheel slot type': {}", __FUNCTION__, slot); return -1; } @@ -310,7 +311,7 @@ void IOWheel::initializeSorcererSpells() { } 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); + return points == player->wheel().getPointsBySlotType(slotType) && points == player->wheel().getMaxPointsPerSlot(slotType); } bool IOWheel::isKnight(uint8_t vocationId) const { diff --git a/src/io/io_wheel.hpp b/src/io/io_wheel.hpp index e354f9aee52..0c27b267ce1 100644 --- a/src/io/io_wheel.hpp +++ b/src/io/io_wheel.hpp @@ -9,15 +9,16 @@ #pragma once -// Definitions of wheel of destiny enums -#include "creatures/players/wheel/wheel_definitions.hpp" -#include "creatures/players/wheel/wheel_gems.hpp" - #include "creatures/creatures_definitions.hpp" +#include "creatures/players/components/wheel/wheel_definitions.hpp" +#include "creatures/players/components/wheel/wheel_spells.hpp" -// It prevents us from including the player.h file class Player; +struct PlayerWheelMethodsBonusData; + +enum class WheelGemAffinity_t : uint8_t; + /** * @brief Represents the bonus data for the wheel of destiny in the game. * @@ -40,7 +41,7 @@ class IOWheelBonusData { }; struct Revelation { - std::array(WheelStageEnum_t::TOTAL_COUNT)> stats = { + std::array() + 1> stats = { Stats { 4, 4 }, Stats { 9, 9 }, Stats { 20, 20 } diff --git a/src/io/iologindata.cpp b/src/io/iologindata.cpp index c0a6a13f363..ba441699a47 100644 --- a/src/io/iologindata.cpp +++ b/src/io/iologindata.cpp @@ -16,7 +16,6 @@ #include "io/functions/iologindata_save_player.hpp" #include "game/game.hpp" #include "creatures/monsters/monster.hpp" -#include "creatures/players/wheel/player_wheel.hpp" #include "creatures/players/player.hpp" #include "lib/metrics/metrics.hpp" #include "enums/account_type.hpp" @@ -262,7 +261,7 @@ bool IOLoginData::savePlayerGuard(const std::shared_ptr &player) { throw DatabaseException("[IOLoginDataSave::savePlayerBosstiary] - Failed to save player bosstiary: " + player->getName()); } - if (!player->wheel()->saveDBPlayerSlotPointsOnLogout()) { + if (!player->wheel().saveDBPlayerSlotPointsOnLogout()) { throw DatabaseException("[PlayerWheel::saveDBPlayerSlotPointsOnLogout] - Failed to save player wheel info: " + player->getName()); } diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index aad4b71d06c..bd3f16f8152 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -13,7 +13,6 @@ #include "creatures/monsters/monster.hpp" #include "creatures/monsters/monsters.hpp" #include "creatures/npcs/npc.hpp" -#include "creatures/players/achievement/player_achievement.hpp" #include "creatures/players/player.hpp" #include "game/functions/game_reload.hpp" #include "game/game.hpp" diff --git a/src/lua/functions/core/game/global_functions.cpp b/src/lua/functions/core/game/global_functions.cpp index 6eb21910701..509f256fdb7 100644 --- a/src/lua/functions/core/game/global_functions.cpp +++ b/src/lua/functions/core/game/global_functions.cpp @@ -13,7 +13,6 @@ #include "creatures/creature.hpp" #include "creatures/combat/condition.hpp" #include "creatures/interactions/chat.hpp" -#include "creatures/players/wheel/player_wheel.hpp" #include "creatures/players/player.hpp" #include "game/game.hpp" #include "game/scheduling/dispatcher.hpp" @@ -332,7 +331,7 @@ int GlobalFunctions::luaDoAreaCombatHealth(lua_State* L) { damage.runeSpellName = Lua::getString(L, 10); if (creature) { if (const auto &player = creature->getPlayer()) { - player->wheel()->getCombatDataSpell(damage); + player->wheel().getCombatDataSpell(damage); } } @@ -376,7 +375,7 @@ int GlobalFunctions::luaDoTargetCombatHealth(lua_State* L) { damage.runeSpellName = Lua::getString(L, 10); if (creature) { if (const auto &player = creature->getPlayer()) { - player->wheel()->getCombatDataSpell(damage); + player->wheel().getCombatDataSpell(damage); } } @@ -414,7 +413,7 @@ int GlobalFunctions::luaDoAreaCombatMana(lua_State* L) { damage.runeSpellName = Lua::getString(L, 9); if (creature) { if (const auto &player = creature->getPlayer()) { - player->wheel()->getCombatDataSpell(damage); + player->wheel().getCombatDataSpell(damage); } } @@ -459,7 +458,7 @@ int GlobalFunctions::luaDoTargetCombatMana(lua_State* L) { damage.runeSpellName = Lua::getString(L, 8); if (creature) { if (const auto &player = creature->getPlayer()) { - player->wheel()->getCombatDataSpell(damage); + player->wheel().getCombatDataSpell(damage); } } diff --git a/src/lua/functions/core/game/lua_enums.cpp b/src/lua/functions/core/game/lua_enums.cpp index 2136a3e5927..a1b09f0ebbd 100644 --- a/src/lua/functions/core/game/lua_enums.cpp +++ b/src/lua/functions/core/game/lua_enums.cpp @@ -9,13 +9,13 @@ #include "lua/functions/core/game/lua_enums.hpp" -#include "creatures/players/wheel/wheel_definitions.hpp" #include "enums/account_group_type.hpp" #include "enums/account_type.hpp" #include "enums/item_attribute.hpp" #include "game/functions/game_reload.hpp" #include "io/io_bosstiary.hpp" #include "lua/functions/lua_functions_loader.hpp" +#include "creatures/players/components/wheel/wheel_definitions.hpp" constexpr const char* soundNamespace = "SOUND_EFFECT_TYPE_"; diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 08045f1de00..33dcc284189 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -15,13 +15,8 @@ #include "creatures/creature.hpp" #include "creatures/interactions/chat.hpp" #include "creatures/monsters/monsters.hpp" -#include "creatures/players/achievement/player_achievement.hpp" -#include "creatures/players/cyclopedia/player_cyclopedia.hpp" -#include "creatures/players/cyclopedia/player_title.hpp" #include "creatures/players/player.hpp" -#include "creatures/players/vip/player_vip.hpp" #include "creatures/players/vocations/vocation.hpp" -#include "creatures/players/wheel/player_wheel.hpp" #include "server/network/protocol/protocolgame.hpp" #include "game/game.hpp" #include "game/scheduling/save_manager.hpp" @@ -34,6 +29,7 @@ #include "items/item.hpp" #include "map/spectators.hpp" #include "kv/kv.hpp" +#include "creatures/players/components/wheel/wheel_definitions.hpp" #include "enums/account_coins.hpp" #include "enums/account_errors.hpp" @@ -1786,7 +1782,7 @@ int PlayerFunctions::luaPlayerSetVocation(lua_State* L) { player->sendSkills(); player->sendStats(); player->sendBasicData(); - player->wheel()->sendGiftOfLifeCooldown(); + player->wheel().sendGiftOfLifeCooldown(); g_game().reloadCreature(player); Lua::pushBoolean(L, true); return 1; @@ -3433,13 +3429,13 @@ int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { if (player->isInGhostMode()) { for (const auto &it : g_game().getPlayers()) { if (!it.second->isAccessPlayer()) { - it.second->vip()->notifyStatusChange(player, VipStatus_t::Offline); + it.second->vip().notifyStatusChange(player, VipStatus_t::Offline); } } } else { for (const auto &it : g_game().getPlayers()) { if (!it.second->isAccessPlayer()) { - it.second->vip()->notifyStatusChange(player, player->vip()->getStatus()); + it.second->vip().notifyStatusChange(player, player->vip().getStatus()); } } } @@ -4310,9 +4306,9 @@ int PlayerFunctions::luaPlayerInstantSkillWOD(lua_State* L) { const std::string name = Lua::getString(L, 2); if (lua_gettop(L) == 2) { - Lua::pushBoolean(L, player->wheel()->getInstant(name)); + Lua::pushBoolean(L, player->wheel().getInstant(name)); } else { - player->wheel()->setSpellInstant(name, Lua::getBoolean(L, 3)); + player->wheel().setSpellInstant(name, Lua::getBoolean(L, 3)); Lua::pushBoolean(L, true); } return 1; @@ -4327,21 +4323,21 @@ int PlayerFunctions::luaPlayerUpgradeSpellWOD(lua_State* L) { } if (lua_gettop(L) == 1) { - player->wheel()->resetUpgradedSpells(); + player->wheel().resetUpgradedSpells(); return 1; } const std::string name = Lua::getString(L, 2); if (lua_gettop(L) == 2) { - lua_pushnumber(L, static_cast(player->wheel()->getSpellUpgrade(name))); + lua_pushnumber(L, static_cast(player->wheel().getSpellUpgrade(name))); return 1; } const bool add = Lua::getBoolean(L, 3); if (add) { - player->wheel()->upgradeSpell(name); + player->wheel().upgradeSpell(name); } else { - player->wheel()->downgradeSpell(name); + player->wheel().downgradeSpell(name); } Lua::pushBoolean(L, true); @@ -4357,18 +4353,18 @@ int PlayerFunctions::luaPlayerRevelationStageWOD(lua_State* L) { } if (lua_gettop(L) == 1) { - player->wheel()->resetUpgradedSpells(); + player->wheel().resetUpgradedSpells(); return 1; } const std::string name = Lua::getString(L, 2); if (lua_gettop(L) == 2) { - lua_pushnumber(L, static_cast(player->wheel()->getStage(name))); + lua_pushnumber(L, static_cast(player->wheel().getStage(name))); return 1; } const bool value = Lua::getNumber(L, 3); - player->wheel()->setSpellInstant(name, value); + player->wheel().setSpellInstant(name, value); Lua::pushBoolean(L, true); return 1; @@ -4385,7 +4381,7 @@ int PlayerFunctions::luaPlayerReloadData(lua_State* L) { player->sendSkills(); player->sendStats(); player->sendBasicData(); - player->wheel()->sendGiftOfLifeCooldown(); + player->wheel().sendGiftOfLifeCooldown(); g_game().reloadCreature(player); Lua::pushBoolean(L, true); return 1; @@ -4399,7 +4395,7 @@ int PlayerFunctions::luaPlayerOnThinkWheelOfDestiny(lua_State* L) { return 1; } - player->wheel()->onThink(Lua::getBoolean(L, 2, false)); + player->wheel().onThink(Lua::getBoolean(L, 2, false)); Lua::pushBoolean(L, true); return 1; } @@ -4413,9 +4409,9 @@ int PlayerFunctions::luaPlayerAvatarTimer(lua_State* L) { } if (lua_gettop(L) == 1) { - lua_pushnumber(L, static_cast(player->wheel()->getOnThinkTimer(WheelOnThink_t::AVATAR_SPELL))); + lua_pushnumber(L, static_cast(player->wheel().getOnThinkTimer(WheelOnThink_t::AVATAR_SPELL))); } else { - player->wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR_SPELL, Lua::getNumber(L, 2)); + player->wheel().setOnThinkTimer(WheelOnThink_t::AVATAR_SPELL, Lua::getNumber(L, 2)); Lua::pushBoolean(L, true); } return 1; @@ -4444,7 +4440,7 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalArea(lua_State* L) { return 0; } - Lua::pushBoolean(L, player->wheel()->getSpellAdditionalArea(spellName)); + Lua::pushBoolean(L, player->wheel().getSpellAdditionalArea(spellName)); return 1; } @@ -4471,7 +4467,7 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalTarget(lua_State* L) { return 0; } - lua_pushnumber(L, player->wheel()->getSpellAdditionalTarget(spellName)); + lua_pushnumber(L, player->wheel().getSpellAdditionalTarget(spellName)); return 1; } @@ -4498,7 +4494,7 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalDuration(lua_State* L) { return 0; } - lua_pushnumber(L, player->wheel()->getSpellAdditionalDuration(spellName)); + lua_pushnumber(L, player->wheel().getSpellAdditionalDuration(spellName)); return 1; } @@ -4610,7 +4606,7 @@ int PlayerFunctions::luaPlayerHasAchievement(lua_State* L) { achievementId = g_game().getAchievementByName(Lua::getString(L, 2)).id; } - Lua::pushBoolean(L, player->achiev()->isUnlocked(achievementId)); + Lua::pushBoolean(L, player->achiev().isUnlocked(achievementId)); return 1; } @@ -4629,7 +4625,7 @@ int PlayerFunctions::luaPlayerAddAchievement(lua_State* L) { achievementId = g_game().getAchievementByName(Lua::getString(L, 2)).id; } - const bool success = player->achiev()->add(achievementId, Lua::getBoolean(L, 3, true)); + const bool success = player->achiev().add(achievementId, Lua::getBoolean(L, 3, true)); if (success) { player->sendTakeScreenshot(SCREENSHOT_TYPE_ACHIEVEMENT); } @@ -4653,7 +4649,7 @@ int PlayerFunctions::luaPlayerRemoveAchievement(lua_State* L) { achievementId = g_game().getAchievementByName(Lua::getString(L, 2)).id; } - Lua::pushBoolean(L, player->achiev()->remove(achievementId)); + Lua::pushBoolean(L, player->achiev().remove(achievementId)); return 1; } @@ -4665,7 +4661,7 @@ int PlayerFunctions::luaPlayerGetAchievementPoints(lua_State* L) { return 1; } - lua_pushnumber(L, player->achiev()->getPoints()); + lua_pushnumber(L, player->achiev().getPoints()); return 1; } @@ -4679,7 +4675,7 @@ int PlayerFunctions::luaPlayerAddAchievementPoints(lua_State* L) { const auto points = Lua::getNumber(L, 2); if (points > 0) { - player->achiev()->addPoints(points); + player->achiev().addPoints(points); } Lua::pushBoolean(L, true); return 1; @@ -4695,7 +4691,7 @@ int PlayerFunctions::luaPlayerRemoveAchievementPoints(lua_State* L) { const auto points = Lua::getNumber(L, 2); if (points > 0) { - player->achiev()->removePoints(points); + player->achiev().removePoints(points); } Lua::pushBoolean(L, true); return 1; @@ -4709,7 +4705,7 @@ int PlayerFunctions::luaPlayerAddBadge(lua_State* L) { return 1; } - player->badge()->add(Lua::getNumber(L, 2, 0)); + player->badge().add(Lua::getNumber(L, 2, 0)); Lua::pushBoolean(L, true); return 1; } @@ -4722,7 +4718,7 @@ int PlayerFunctions::luaPlayerAddTitle(lua_State* L) { return 1; } - player->title()->manage(true, Lua::getNumber(L, 2, 0)); + player->title().manage(true, Lua::getNumber(L, 2, 0)); Lua::pushBoolean(L, true); return 1; } @@ -4735,14 +4731,14 @@ int PlayerFunctions::luaPlayerGetTitles(lua_State* L) { return 1; } - const auto playerTitles = player->title()->getUnlockedTitles(); + const auto playerTitles = player->title().getUnlockedTitles(); lua_createtable(L, static_cast(playerTitles.size()), 0); int index = 0; for (const auto &title : playerTitles) { lua_createtable(L, 0, 3); Lua::setField(L, "id", title.first.m_id); - Lua::setField(L, "name", player->title()->getNameBySex(player->getSex(), title.first.m_maleName, title.first.m_femaleName)); + Lua::setField(L, "name", player->title().getNameBySex(player->getSex(), title.first.m_maleName, title.first.m_femaleName)); Lua::setField(L, "description", title.first.m_description); lua_rawseti(L, -2, ++index); } @@ -4763,7 +4759,7 @@ int PlayerFunctions::luaPlayerSetCurrentTitle(lua_State* L) { return 1; } - player->title()->setCurrentTitle(title.m_id); + player->title().setCurrentTitle(title.m_id); Lua::pushBoolean(L, true); return 1; } @@ -4785,7 +4781,7 @@ int PlayerFunctions::luaPlayerCreateTransactionSummary(lua_State* L) { const auto amount = Lua::getNumber(L, 3, 1); const auto id = Lua::getString(L, 4, ""); - player->cyclopedia()->updateStoreSummary(type, amount, id); + player->cyclopedia().updateStoreSummary(type, amount, id); Lua::pushBoolean(L, true); return 1; } diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 727c1cc0097..e9486ce0f39 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -19,9 +19,6 @@ #include "creatures/monsters/monster.hpp" #include "creatures/monsters/monsters.hpp" #include "creatures/npcs/npc.hpp" -#include "creatures/players/achievement/player_achievement.hpp" -#include "creatures/players/cyclopedia/player_badge.hpp" -#include "creatures/players/cyclopedia/player_cyclopedia.hpp" #include "creatures/players/grouping/familiars.hpp" #include "creatures/players/grouping/party.hpp" #include "creatures/players/grouping/team_finder.hpp" @@ -30,8 +27,6 @@ #include "creatures/players/management/ban.hpp" #include "creatures/players/management/waitlist.hpp" #include "creatures/players/player.hpp" -#include "creatures/players/vip/player_vip.hpp" -#include "creatures/players/wheel/player_wheel.hpp" #include "enums/player_icons.hpp" #include "game/game.hpp" #include "game/modal_window/modal_window.hpp" @@ -209,7 +204,7 @@ namespace { for (size_t i = 0; i < COMBAT_COUNT; ++i) { damageModifiers[i] -= 100 * player->getAbsorbPercent(indexToCombatType(i)); if (g_configManager().getBoolean(TOGGLE_WHEELSYSTEM)) { - damageModifiers[i] -= player->wheel()->getResistance(indexToCombatType(i)); + damageModifiers[i] -= player->wheel().getResistance(indexToCombatType(i)); } if (damageModifiers[i] != 10000) { @@ -2025,18 +2020,18 @@ void ProtocolGame::parseVipGroupActions(NetworkMessage &msg) { switch (action) { case 0x01: { const std::string groupName = msg.getString(); - player->vip()->addGroup(groupName); + player->vip().addGroup(groupName); break; } case 0x02: { const uint8_t groupId = msg.getByte(); const std::string newGroupName = msg.getString(); - player->vip()->editGroup(groupId, newGroupName); + player->vip().editGroup(groupId, newGroupName); break; } case 0x03: { const uint8_t groupId = msg.getByte(); - player->vip()->removeGroup(groupId); + player->vip().removeGroup(groupId); break; } default: { @@ -3458,7 +3453,7 @@ void ProtocolGame::sendCyclopediaCharacterBaseInformation() { AddOutfit(msg, player->getDefaultOutfit(), false); msg.addByte(0x01); // Store summary & Character titles - msg.addString(player->title()->getCurrentTitleName()); // character title + msg.addString(player->title().getCurrentTitleName()); // character title writeToOutputBuffer(msg); } @@ -3739,7 +3734,7 @@ void ProtocolGame::sendCyclopediaCharacterAchievements(uint16_t secretsUnlocked, msg.addByte(0xDA); msg.addByte(CYCLOPEDIA_CHARACTERINFO_ACHIEVEMENTS); msg.addByte(0x00); // 0x00 Here means 'no error' - msg.add(player->achiev()->getPoints()); + msg.add(player->achiev().getPoints()); msg.add(secretsUnlocked); msg.add(static_cast(achievementsUnlocked.size())); for (const auto &[achievement, addedTimestamp] : achievementsUnlocked) { @@ -3985,7 +3980,7 @@ void ProtocolGame::sendCyclopediaCharacterStoreSummary() { auto remaining = player->kv()->get("daily-reward-xp-boost"); msg.add(remaining ? static_cast(remaining->getNumber()) : 0); // Remaining Daily Reward Xp Boost Time - auto cyclopediaSummary = player->cyclopedia()->getSummary(); + auto cyclopediaSummary = player->cyclopedia().getSummary(); msg.addByte(static_cast(magic_enum::enum_count())); for (auto bless : magic_enum::enum_values()) { @@ -4042,7 +4037,7 @@ void ProtocolGame::sendCyclopediaCharacterStoreSummary() { }*/ msg.addByte(0x00); // hireling outfit size - auto houseItems = player->cyclopedia()->getResult(static_cast(Summary_t::HOUSE_ITEMS)); + auto houseItems = player->cyclopedia().getResult(static_cast(Summary_t::HOUSE_ITEMS)); msg.add(houseItems.size()); for (const auto &hItem_it : houseItems) { const ItemType &it = Item::items[hItem_it.first]; @@ -4110,10 +4105,10 @@ void ProtocolGame::sendCyclopediaCharacterInspection() { msg.skipBytes(1); // Player title - if (player->title()->getCurrentTitle() != 0) { + if (player->title().getCurrentTitle() != 0) { playerDescriptionSize++; msg.addString("Character Title"); - msg.addString(player->title()->getCurrentTitleName()); + msg.addString(player->title().getCurrentTitleName()); } // Level description @@ -4213,7 +4208,7 @@ void ProtocolGame::sendCyclopediaCharacterBadges() { auto badgesSizePosition = msg.getBufferPosition(); msg.skipBytes(1); for (const auto &badge : g_game().getBadges()) { - if (player->badge()->hasBadge(badge.m_id)) { + if (player->badge().hasBadge(badge.m_id)) { msg.add(badge.m_id); msg.addString(badge.m_name); badgesSize++; @@ -4237,15 +4232,15 @@ void ProtocolGame::sendCyclopediaCharacterTitles() { msg.addByte(0xDA); msg.addByte(CYCLOPEDIA_CHARACTERINFO_TITLES); msg.addByte(0x00); // 0x00 Here means 'no error' - msg.addByte(player->title()->getCurrentTitle()); + msg.addByte(player->title().getCurrentTitle()); msg.addByte(static_cast(titles.size())); for (const auto &title : titles) { msg.addByte(title.m_id); - auto titleName = player->title()->getNameBySex(player->getSex(), title.m_maleName, title.m_femaleName); + auto titleName = player->title().getNameBySex(player->getSex(), title.m_maleName, title.m_femaleName); msg.addString(titleName); msg.addString(title.m_description); msg.addByte(title.m_permanent ? 0x01 : 0x00); - auto isUnlocked = player->title()->isTitleUnlocked(title.m_id); + auto isUnlocked = player->title().isTitleUnlocked(title.m_id); msg.addByte(isUnlocked ? 0x01 : 0x00); } @@ -4320,7 +4315,7 @@ void ProtocolGame::sendBasicData() { msg.add(0); } else if (spell && spell->isLearnable() && player->hasLearnedInstantSpell(spell->getName())) { // Ignore spell if not have wheel grade (or send if you have) - auto grade = player->wheel()->getSpellUpgrade(spell->getName()); + auto grade = player->wheel().getSpellUpgrade(spell->getName()); if (static_cast(grade) == 0) { msg.add(0); } else { @@ -6874,7 +6869,7 @@ void ProtocolGame::sendAddCreature(const std::shared_ptr &creature, co if (!vipPlayer) { vipStatus = VipStatus_t::Offline; } else { - vipStatus = vipPlayer->vip()->getStatus(); + vipStatus = vipPlayer->vip().getStatus(); } sendVIP(entry.guid, entry.name, entry.description, entry.icon, entry.notify, vipStatus); @@ -6887,7 +6882,7 @@ void ProtocolGame::sendAddCreature(const std::shared_ptr &creature, co if (!vipPlayer || vipPlayer->isInGhostMode()) { vipStatus = VipStatus_t::Offline; } else { - vipStatus = vipPlayer->vip()->getStatus(); + vipStatus = vipPlayer->vip().getStatus(); } sendVIP(entry.guid, entry.name, entry.description, entry.icon, entry.notify, vipStatus); @@ -6904,7 +6899,7 @@ void ProtocolGame::sendAddCreature(const std::shared_ptr &creature, co sendBasicData(); // Wheel of destiny cooldown if (!oldProtocol && g_configManager().getBoolean(TOGGLE_WHEELSYSTEM)) { - player->wheel()->sendGiftOfLifeCooldown(); + player->wheel().sendGiftOfLifeCooldown(); } player->sendClientCheck(); @@ -7437,7 +7432,7 @@ void ProtocolGame::sendVIP(uint32_t guid, const std::string &name, const std::st msg.addByte(notify ? 0x01 : 0x00); msg.addByte(enumToValue(status)); - const auto &vipGuidGroups = player->vip()->getGroupsIdGuidBelongs(guid); + const auto &vipGuidGroups = player->vip().getGroupsIdGuidBelongs(guid); if (!oldProtocol) { msg.addByte(vipGuidGroups.size()); // vipGroups @@ -7454,7 +7449,7 @@ void ProtocolGame::sendVIPGroups() { return; } - const auto &vipGroups = player->vip()->getGroups(); + const auto &vipGroups = player->vip().getGroups(); NetworkMessage msg; msg.addByte(0xD4); @@ -7464,7 +7459,7 @@ void ProtocolGame::sendVIPGroups() { msg.addString(vipGroup->name); msg.addByte(vipGroup->customizable ? 0x01 : 0x00); // 0x00 = not Customizable, 0x01 = Customizable } - msg.addByte(player->vip()->getMaxGroupEntries() - vipGroups.size()); // max vip groups + msg.addByte(player->vip().getMaxGroupEntries() - vipGroups.size()); // max vip groups writeToOutputBuffer(msg); } @@ -9287,7 +9282,7 @@ void ProtocolGame::sendOpenWheelWindow(uint32_t ownerId) { } NetworkMessage msg; - player->wheel()->sendOpenWheelWindow(msg, ownerId); + player->wheel().sendOpenWheelWindow(msg, ownerId); writeToOutputBuffer(msg); } From c8b05c343a936ec367ec1ec85e5f1c0783164682 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Mon, 18 Nov 2024 15:29:03 -0300 Subject: [PATCH 3/5] remove log and add comment --- src/creatures/players/player.hpp | 1 + src/io/io_wheel.cpp | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 7f46b59ed8f..6dd9837c609 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -17,6 +17,7 @@ #include "game/movement/position.hpp" #include "creatures/creatures_definitions.hpp" +// Player components are decoupled to reduce complexity. Keeping includes here aids in clarity and maintainability, but avoid including player.hpp in headers to prevent circular dependencies. #include "creatures/players/components/player_achievement.hpp" #include "creatures/players/components/player_badge.hpp" #include "creatures/players/components/player_cyclopedia.hpp" diff --git a/src/io/io_wheel.cpp b/src/io/io_wheel.cpp index 03bb9c4552f..d2aac054ef6 100644 --- a/src/io/io_wheel.cpp +++ b/src/io/io_wheel.cpp @@ -79,7 +79,6 @@ namespace InternalPlayerWheel { // Decrease data const auto decreaseData = spellData.decrease; if (decreaseData.cooldown > 0) { - g_logger().info("Registering spell {}, grade {}, cooldown {}", name, gradeType, decreaseData.cooldown); spell->setWheelOfDestinyBoost(WheelSpellBoost_t::COOLDOWN, gradeType, decreaseData.cooldown * 1000); } if (decreaseData.manaCost > 0) { From 21e4d97cec1842672291a68190dfe7ae3f86d0dd Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Tue, 19 Nov 2024 12:10:40 -0300 Subject: [PATCH 4/5] fix: revert wrong remotion --- .../players/components/wheel/player_wheel.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/creatures/players/components/wheel/player_wheel.cpp b/src/creatures/players/components/wheel/player_wheel.cpp index 470a36a9116..f295e9fbd04 100644 --- a/src/creatures/players/components/wheel/player_wheel.cpp +++ b/src/creatures/players/components/wheel/player_wheel.cpp @@ -1991,6 +1991,16 @@ void PlayerWheel::registerPlayerBonusData() { for (int i = 0; i < m_playerBonusData.stages.divineGrenade; ++i) { setSpellInstant("Divine Grenade", true); } + if (m_playerBonusData.stages.divineGrenade >= 2) { + WheelSpells::Bonus bonus; + bonus.decrease.cooldown = 4 * 1000; + addSpellBonus("Divine Grenade", bonus); + } + if (m_playerBonusData.stages.divineGrenade >= 3) { + WheelSpells::Bonus bonus; + bonus.decrease.cooldown = 6 * 1000; + addSpellBonus("Divine Grenade", bonus); + } } else { setSpellInstant("Divine Grenade", false); } From 192a07267a338b802f772c9981b3bcf5ac91aa95 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Tue, 19 Nov 2024 12:32:14 -0300 Subject: [PATCH 5/5] fix: enums size --- src/creatures/combat/spells.hpp | 6 +++--- .../players/components/wheel/player_wheel.hpp | 10 +++++----- .../players/components/wheel/wheel_definitions.hpp | 2 -- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/creatures/combat/spells.hpp b/src/creatures/combat/spells.hpp index 56ff1a330de..b50d1d5a555 100644 --- a/src/creatures/combat/spells.hpp +++ b/src/creatures/combat/spells.hpp @@ -10,7 +10,7 @@ #pragma once #include "lua/creature/actions.hpp" -#include "creatures/players/wheel/wheel_definitions.hpp" +#include "creatures/players/components/wheel/wheel_definitions.hpp" class InstantSpell; class RuneSpell; @@ -254,8 +254,8 @@ class Spell : public BaseSpell { bool pzLocked = false; bool whellOfDestinyUpgraded = false; - std::array(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyRegularBoost = { 0 }; - std::array(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyUpgradedBoost = { 0 }; + std::array() + 1> wheelOfDestinyRegularBoost = { 0 }; + std::array() + 1> wheelOfDestinyUpgradedBoost = { 0 }; private: uint32_t mana = 0; diff --git a/src/creatures/players/components/wheel/player_wheel.hpp b/src/creatures/players/components/wheel/player_wheel.hpp index cc2697e8785..072f520ad33 100644 --- a/src/creatures/players/components/wheel/player_wheel.hpp +++ b/src/creatures/players/components/wheel/player_wheel.hpp @@ -494,11 +494,11 @@ class PlayerWheel { PlayerWheelMethodsBonusData m_playerBonusData; std::unique_ptr m_modifierContext; - std::array()> m_stages = { 0 }; - std::array()> m_onThink = { 0 }; - std::array()> m_stats = { 0 }; - std::array()> m_majorStats = { 0 }; - std::array()> m_instant = { false }; + std::array() + 1> m_stages = { 0 }; + std::array() + 1> m_onThink = { 0 }; + std::array() + 1> m_stats = { 0 }; + std::array() + 1> m_majorStats = { 0 }; + std::array() + 1> m_instant = { false }; std::array m_resistance = { 0 }; std::array m_specializedMagic = { 0 }; diff --git a/src/creatures/players/components/wheel/wheel_definitions.hpp b/src/creatures/players/components/wheel/wheel_definitions.hpp index e88cb9a62df..8da01ec9b9c 100644 --- a/src/creatures/players/components/wheel/wheel_definitions.hpp +++ b/src/creatures/players/components/wheel/wheel_definitions.hpp @@ -180,8 +180,6 @@ enum class WheelSpellBoost_t : uint8_t { HEAL = 10, CRITICAL_DAMAGE = 11, CRITICAL_CHANCE = 12, - - TOTAL_COUNT = 13 }; /**