From 07621d36680d41369a658714493d156b226bff58 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Tue, 5 Mar 2024 19:01:40 -0300 Subject: [PATCH] fix: correct disable chain system and formula to config (#2362) Resolves #2381 --- config.lua.dist | 3 +++ src/config/config_enums.hpp | 3 +++ src/config/configmanager.cpp | 3 +++ src/creatures/combat/combat.cpp | 12 +++++++----- src/items/functions/item/item_parse.cpp | 11 ++++++++--- src/items/weapons/weapons.cpp | 2 +- src/items/weapons/weapons.hpp | 9 +++++++++ 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/config.lua.dist b/config.lua.dist index d667bb48952..450d29e3a0d 100644 --- a/config.lua.dist +++ b/config.lua.dist @@ -427,6 +427,9 @@ maxDamageReflection = 200 toggleChainSystem = true combatChainDelay = 50 combatChainTargets = 5 +combatChainSkillFormulaAxe = 0.9 +combatChainSkillFormulaClub = 0.7 +combatChainSkillFormulaSword = 1.1 -- Global server Save -- NOTE: globalServerSaveNotifyDuration in minutes diff --git a/src/config/config_enums.hpp b/src/config/config_enums.hpp index ee8b531ddcc..39640918a90 100644 --- a/src/config/config_enums.hpp +++ b/src/config/config_enums.hpp @@ -37,6 +37,9 @@ enum ConfigKey_t : uint16_t { CLEAN_PROTECTION_ZONES, COMBAT_CHAIN_DELAY, COMBAT_CHAIN_TARGETS, + COMBAT_CHAIN_SKILL_FORMULA_AXE, + COMBAT_CHAIN_SKILL_FORMULA_CLUB, + COMBAT_CHAIN_SKILL_FORMULA_SWORD, COMPRESSION_LEVEL, CONVERT_UNSAFE_SCRIPTS, CORE_DIRECTORY, diff --git a/src/config/configmanager.cpp b/src/config/configmanager.cpp index 7069ca10fb2..2880da644fb 100644 --- a/src/config/configmanager.cpp +++ b/src/config/configmanager.cpp @@ -217,6 +217,9 @@ bool ConfigManager::load() { loadIntConfig(L, CHECK_EXPIRED_MARKET_OFFERS_EACH_MINUTES, "checkExpiredMarketOffersEachMinutes", 60); loadIntConfig(L, COMBAT_CHAIN_DELAY, "combatChainDelay", 50); loadIntConfig(L, COMBAT_CHAIN_TARGETS, "combatChainTargets", 5); + loadFloatConfig(L, COMBAT_CHAIN_SKILL_FORMULA_AXE, "combatChainSkillFormulaAxe", 0.9); + loadFloatConfig(L, COMBAT_CHAIN_SKILL_FORMULA_CLUB, "combatChainSkillFormulaClub", 0.7); + loadFloatConfig(L, COMBAT_CHAIN_SKILL_FORMULA_SWORD, "combatChainSkillFormulaSword", 1.1); loadIntConfig(L, COMPRESSION_LEVEL, "packetCompressionLevel", 6); loadIntConfig(L, CRITICALCHANCE, "criticalChance", 10); loadIntConfig(L, DAY_KILLS_TO_RED, "dayKillsToRedSkull", 3); diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index 62c9e1638a8..532f4d48bb1 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -941,6 +941,10 @@ void Combat::setupChain(const std::shared_ptr &weapon) { return; } + if (weapon->isChainDisabled()) { + return; + } + const auto &weaponType = weapon->getWeaponType(); if (weaponType == WEAPON_NONE || weaponType == WEAPON_SHIELD || weaponType == WEAPON_AMMO || weaponType == WEAPON_DISTANCE) { return; @@ -980,15 +984,13 @@ void Combat::setupChain(const std::shared_ptr &weapon) { switch (weaponType) { case WEAPON_SWORD: - setCommonValues(1.1, MELEE_ATK_SWORD, CONST_ME_SLASH); + setCommonValues(g_configManager().getFloat(COMBAT_CHAIN_SKILL_FORMULA_SWORD, __FUNCTION__), MELEE_ATK_SWORD, CONST_ME_SLASH); break; - case WEAPON_CLUB: - setCommonValues(0.7, MELEE_ATK_CLUB, CONST_ME_BLACK_BLOOD); + setCommonValues(g_configManager().getFloat(COMBAT_CHAIN_SKILL_FORMULA_CLUB, __FUNCTION__), MELEE_ATK_CLUB, CONST_ME_BLACK_BLOOD); break; - case WEAPON_AXE: - setCommonValues(0.9, MELEE_ATK_AXE, CONST_ANI_WHIRLWINDAXE); + setCommonValues(g_configManager().getFloat(COMBAT_CHAIN_SKILL_FORMULA_AXE, __FUNCTION__), MELEE_ATK_AXE, CONST_ANI_WHIRLWINDAXE); break; } diff --git a/src/items/functions/item/item_parse.cpp b/src/items/functions/item/item_parse.cpp index 365cda202ce..a6255983f67 100644 --- a/src/items/functions/item/item_parse.cpp +++ b/src/items/functions/item/item_parse.cpp @@ -1165,9 +1165,14 @@ void ItemParse::createAndRegisterScript(ItemType &itemType, pugi::xml_node attri g_logger().warn("[{}] - wandtype '{}' does not exist", __FUNCTION__, elementName); } } else if (stringKey == "chain" && weapon) { - auto value = subValueAttribute.as_double(); - weapon->setChainSkillValue(value); - g_logger().trace("Found chain skill value '{}' for weapon: {}", value, itemType.name); + if (auto value = subValueAttribute.as_double()) { + weapon->setChainSkillValue(value); + g_logger().trace("Found chain skill value '{}' for weapon: {}", value, itemType.name); + } + if (subValueAttribute.as_bool() == false) { + weapon->setDisabledChain(); + g_logger().warn("Chain disabled for weapon: {}", itemType.name); + } } } diff --git a/src/items/weapons/weapons.cpp b/src/items/weapons/weapons.cpp index 25287ca9f92..ecc04adfbe1 100644 --- a/src/items/weapons/weapons.cpp +++ b/src/items/weapons/weapons.cpp @@ -245,7 +245,7 @@ void Weapon::internalUseWeapon(std::shared_ptr player, std::shared_ptrdoCombatChain(player, target, params.aggressive); } else { Combat::doCombatHealth(player, target, damage, params); diff --git a/src/items/weapons/weapons.hpp b/src/items/weapons/weapons.hpp index 2cf97568aef..5b2b260e2ee 100644 --- a/src/items/weapons/weapons.hpp +++ b/src/items/weapons/weapons.hpp @@ -192,6 +192,14 @@ class Weapon : public Script { return m_chainSkillValue; } + void setDisabledChain() { + m_isDisabledChain = true; + } + + bool isChainDisabled() const { + return m_isDisabledChain; + } + const WeaponType_t getWeaponType() const { return weaponType; } @@ -243,6 +251,7 @@ class Weapon : public Script { bool enabled = true; bool premium = false; bool wieldUnproperly = false; + bool m_isDisabledChain = false; std::string vocationString = ""; void onUsedWeapon(std::shared_ptr player, std::shared_ptr item, std::shared_ptr destTile) const;