Skip to content

Commit

Permalink
fix: correct disable chain system and formula to config (#2362)
Browse files Browse the repository at this point in the history
Resolves #2381
  • Loading branch information
dudantas authored Mar 5, 2024
1 parent 9a4b49d commit 07621d3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
3 changes: 3 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 7 additions & 5 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,10 @@ void Combat::setupChain(const std::shared_ptr<Weapon> &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;
Expand Down Expand Up @@ -980,15 +984,13 @@ void Combat::setupChain(const std::shared_ptr<Weapon> &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;
}

Expand Down
11 changes: 8 additions & 3 deletions src/items/functions/item/item_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/items/weapons/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void Weapon::internalUseWeapon(std::shared_ptr<Player> player, std::shared_ptr<I
damage.secondary.value = (getElementDamage(player, target, item) * damageModifier / 100) * damagePercent / 100;
}

if (params.chainCallback) {
if (g_configManager().getBoolean(TOGGLE_CHAIN_SYSTEM, __FUNCTION__) && params.chainCallback) {
m_combat->doCombatChain(player, target, params.aggressive);
} else {
Combat::doCombatHealth(player, target, damage, params);
Expand Down
9 changes: 9 additions & 0 deletions src/items/weapons/weapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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> player, std::shared_ptr<Item> item, std::shared_ptr<Tile> destTile) const;
Expand Down

0 comments on commit 07621d3

Please sign in to comment.