Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: player components to scoped object #3130

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions data-canary/npc/canary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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}?")
Expand Down
78 changes: 78 additions & 0 deletions docs/python-scripts/remove_player_includes.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 7 additions & 7 deletions src/creatures/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
14 changes: 7 additions & 7 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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> &player, const std::shared_ptr<Spell> &wheelSpell, const CombatDamage &damage) const {
if (!player) {
Expand All @@ -38,7 +38,7 @@ int32_t Combat::getLevelFormula(const std::shared_ptr<Player> &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;
Expand All @@ -61,7 +61,7 @@ CombatDamage Combat::getCombatDamage(const std::shared_ptr<Creature> &creature,
std::shared_ptr<Spell> wheelSpell = nullptr;
std::shared_ptr<Player> attackerPlayer = creature ? creature->getPlayer() : nullptr;
if (attackerPlayer) {
wheelSpell = attackerPlayer->wheel()->getCombatDataSpell(damage);
wheelSpell = attackerPlayer->wheel().getCombatDataSpell(damage);
}
// End
if (formulaType == COMBAT_FORMULA_DAMAGE) {
Expand Down Expand Up @@ -641,7 +641,7 @@ void Combat::CombatHealthFunc(const std::shared_ptr<Creature> &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);
}

Expand Down Expand Up @@ -1238,7 +1238,7 @@ void Combat::CombatFunc(const std::shared_ptr<Creature> &caster, const Position
// Wheel of destiny get beam affected total
auto spectators = Spectators().find<Player>(pos, true, rangeX, rangeX, rangeY, rangeY);
const std::shared_ptr<Player> &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;
Expand All @@ -1265,7 +1265,7 @@ void Combat::CombatFunc(const std::shared_ptr<Creature> &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) {
Expand Down Expand Up @@ -1562,7 +1562,7 @@ uint32_t ValueCallback::getMagicLevelSkill(const std::shared_ptr<Player> &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> &spell = g_spells().getRuneSpellByName(damage.runeSpellName);
// Rune conjuring spell have the same name as the rune item spell.
const std::shared_ptr<InstantSpell> &conjuringSpell = g_spells().getInstantSpellByName(damage.runeSpellName);
Expand Down
19 changes: 9 additions & 10 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -729,7 +728,7 @@ int32_t Spell::calculateAugmentSpellCooldownReduction(const std::shared_ptr<Play
}

void Spell::applyCooldownConditions(const std::shared_ptr<Player> &player) const {
WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName());
WheelSpellGrade_t spellGrade = player->wheel().getSpellUpgrade(getName());
bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast<uint8_t>(spellGrade) > 0;
// Safety check to prevent division by zero
auto rateCooldown = g_configManager().getFloat(RATE_SPELL_COOLDOWN);
Expand All @@ -743,13 +742,13 @@ void Spell::applyCooldownConditions(const std::shared_ptr<Player> &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);
}
Expand All @@ -771,9 +770,9 @@ void Spell::applyCooldownConditions(const std::shared_ptr<Player> &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);
}
Expand Down Expand Up @@ -835,12 +834,12 @@ bool Spell::isLearnable() const {
}

uint32_t Spell::getManaCost(const std::shared_ptr<Player> &player) const {
WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName());
WheelSpellGrade_t spellGrade = player->wheel().getSpellUpgrade(getName());
uint32_t manaRedution = 0;
if (getWheelOfDestinyUpgraded() && static_cast<uint8_t>(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) {
Expand Down
6 changes: 3 additions & 3 deletions src/creatures/combat/spells.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -254,8 +254,8 @@ class Spell : public BaseSpell {
bool pzLocked = false;

bool whellOfDestinyUpgraded = false;
std::array<int32_t, static_cast<uint8_t>(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyRegularBoost = { 0 };
std::array<int32_t, static_cast<uint8_t>(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyUpgradedBoost = { 0 };
std::array<int32_t, magic_enum::enum_count<WheelSpellBoost_t>() + 1> wheelOfDestinyRegularBoost = { 0 };
std::array<int32_t, magic_enum::enum_count<WheelSpellBoost_t>() + 1> wheelOfDestinyUpgradedBoost = { 0 };

private:
uint32_t mana = 0;
Expand Down
7 changes: 3 additions & 4 deletions src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -897,8 +896,8 @@ BlockType_t Monster::blockHit(const std::shared_ptr<Creature> &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) {
Expand Down Expand Up @@ -2426,7 +2425,7 @@ bool Monster::challengeCreature(const std::shared_ptr<Creature> &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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading
Loading