From 44ed47fccb65c69e067031a551e3a1903878e66d Mon Sep 17 00:00:00 2001 From: Karol <69658@student.pb.edu.pl> Date: Thu, 30 Nov 2023 09:01:48 -0800 Subject: [PATCH 1/3] fix: correctly reflect damage on ek/rp weapons --- src/game/game.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index a9a2786de1a..7743a83fb65 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -6064,7 +6064,7 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr attack if (secondaryReflectPercent > 0 || secondaryReflectFlat > 0) { if (!canReflect) { damageReflected.primary.type = damage.secondary.type; - damageReflected.primary.value = std::ceil(damage.secondary.value * secondaryReflectPercent / 100.) + std::max(-static_cast(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.secondary.value, -(static_cast(secondaryReflectFlat)))); + damageReflected.primary.value = std::ceil(damage.secondary.value * (int)secondaryReflectPercent / 100.) + std::max(-static_cast(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.secondary.value, -(static_cast(secondaryReflectFlat)))); if (!damageReflected.exString.empty()) { damageReflected.exString += ", "; } @@ -6075,7 +6075,7 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr attack canReflect = true; } else { damageReflected.secondary.type = damage.secondary.type; - damageReflected.primary.value = std::ceil(damage.secondary.value * secondaryReflectPercent / 100.) + std::max(-static_cast(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.secondary.value, -(static_cast(secondaryReflectFlat)))); + damageReflected.primary.value = std::ceil(damage.secondary.value * (int)secondaryReflectPercent / 100.) + std::max(-static_cast(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.secondary.value, -(static_cast(secondaryReflectFlat)))); } } } From 6a04a48a473597af06e650b0a7238f07bf8870cf Mon Sep 17 00:00:00 2001 From: un000000 <101636937+un000000@users.noreply.github.com> Date: Fri, 1 Dec 2023 12:51:32 +0100 Subject: [PATCH 2/3] improve: change variable types instead of casting --- src/game/game.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index 7743a83fb65..63434812ada 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -6059,12 +6059,12 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr attack if (damage.secondary.type != COMBAT_NONE) { // Damage reflection secondary if (!damage.extension && attacker && target->getMonster()) { - uint32_t secondaryReflectPercent = target->getReflectPercent(damage.secondary.type, true); - uint32_t secondaryReflectFlat = target->getReflectFlat(damage.secondary.type, true); + int32_t secondaryReflectPercent = target->getReflectPercent(damage.secondary.type, true); + int32_t secondaryReflectFlat = target->getReflectFlat(damage.secondary.type, true); if (secondaryReflectPercent > 0 || secondaryReflectFlat > 0) { if (!canReflect) { damageReflected.primary.type = damage.secondary.type; - damageReflected.primary.value = std::ceil(damage.secondary.value * (int)secondaryReflectPercent / 100.) + std::max(-static_cast(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.secondary.value, -(static_cast(secondaryReflectFlat)))); + damageReflected.primary.value = std::ceil(damage.secondary.value * secondaryReflectPercent / 100.) + std::max(-static_cast(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.secondary.value, -(static_cast(secondaryReflectFlat)))); if (!damageReflected.exString.empty()) { damageReflected.exString += ", "; } @@ -6075,7 +6075,7 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr attack canReflect = true; } else { damageReflected.secondary.type = damage.secondary.type; - damageReflected.primary.value = std::ceil(damage.secondary.value * (int)secondaryReflectPercent / 100.) + std::max(-static_cast(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.secondary.value, -(static_cast(secondaryReflectFlat)))); + damageReflected.primary.value = std::ceil(damage.secondary.value * secondaryReflectPercent / 100.) + std::max(-static_cast(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.secondary.value, -(static_cast(secondaryReflectFlat)))); } } } From 5ad00a8c6fb13ec17d74277a392d5ba6f7ae61f3 Mon Sep 17 00:00:00 2001 From: un000000 <101636937+un000000@users.noreply.github.com> Date: Sun, 3 Dec 2023 22:47:01 +0100 Subject: [PATCH 3/3] fix: calculate reflect based on damage AFTER mitigation --- src/game/game.cpp | 99 +++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index 945d5a9f55b..893a9dcec8d 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -5990,6 +5990,31 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr attack std::shared_ptr targetPlayer = target->getPlayer(); if (damage.primary.type != COMBAT_NONE) { + + damage.primary.value = -damage.primary.value; + // Damage healing primary + if (attacker) { + if (target->getMonster()) { + uint32_t primaryHealing = target->getMonster()->getHealingCombatValue(damage.primary.type); + if (primaryHealing > 0) { + damageHeal.primary.value = std::ceil((damage.primary.value) * (primaryHealing / 100.)); + canHeal = true; + } + } + if (targetPlayer && attacker->getAbsorbPercent(damage.primary.type) != 0) { + damageAbsorbMessage = true; + } + if (attacker->getPlayer() && attacker->getIncreasePercent(damage.primary.type) != 0) { + damageIncreaseMessage = true; + } + damage.primary.value *= attacker->getBuff(BUFF_DAMAGEDEALT) / 100.; + } + damage.primary.value *= target->getBuff(BUFF_DAMAGERECEIVED) / 100.; + + primaryBlockType = target->blockHit(attacker, damage.primary.type, damage.primary.value, checkDefense, checkArmor, field); + + damage.primary.value = -damage.primary.value; + InternalGame::sendBlockEffect(primaryBlockType, damage.primary.type, target->getPosition(), attacker); // Damage reflection primary if (!damage.extension && attacker) { if (targetPlayer && attacker->getMonster() && damage.primary.type != COMBAT_HEALING) { @@ -6028,36 +6053,36 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr attack } } } - damage.primary.value = -damage.primary.value; - // Damage healing primary - if (attacker) { - if (target->getMonster()) { - uint32_t primaryHealing = target->getMonster()->getHealingCombatValue(damage.primary.type); - if (primaryHealing > 0) { - damageHeal.primary.value = std::ceil((damage.primary.value) * (primaryHealing / 100.)); - canHeal = true; - } + } else { + primaryBlockType = BLOCK_NONE; + } + + if (damage.secondary.type != COMBAT_NONE) { + + damage.secondary.value = -damage.secondary.value; + // Damage healing secondary + if (attacker && target->getMonster()) { + uint32_t secondaryHealing = target->getMonster()->getHealingCombatValue(damage.secondary.type); + if (secondaryHealing > 0) { + ; + damageHeal.primary.value += std::ceil((damage.secondary.value) * (secondaryHealing / 100.)); + canHeal = true; } - if (targetPlayer && attacker->getAbsorbPercent(damage.primary.type) != 0) { + if (targetPlayer && attacker->getAbsorbPercent(damage.secondary.type) != 0) { damageAbsorbMessage = true; } - if (attacker->getPlayer() && attacker->getIncreasePercent(damage.primary.type) != 0) { + if (attacker->getPlayer() && attacker->getIncreasePercent(damage.secondary.type) != 0) { damageIncreaseMessage = true; } - damage.primary.value *= attacker->getBuff(BUFF_DAMAGEDEALT) / 100.; + damage.secondary.value *= attacker->getBuff(BUFF_DAMAGEDEALT) / 100.; } - damage.primary.value *= target->getBuff(BUFF_DAMAGERECEIVED) / 100.; + damage.secondary.value *= target->getBuff(BUFF_DAMAGERECEIVED) / 100.; - primaryBlockType = target->blockHit(attacker, damage.primary.type, damage.primary.value, checkDefense, checkArmor, field); + secondaryBlockType = target->blockHit(attacker, damage.secondary.type, damage.secondary.value, false, false, field); - damage.primary.value = -damage.primary.value; - InternalGame::sendBlockEffect(primaryBlockType, damage.primary.type, target->getPosition(), attacker); - } else { - primaryBlockType = BLOCK_NONE; - } + damage.secondary.value = -damage.secondary.value; + InternalGame::sendBlockEffect(secondaryBlockType, damage.secondary.type, target->getPosition(), attacker); - if (damage.secondary.type != COMBAT_NONE) { - // Damage reflection secondary if (!damage.extension && attacker && target->getMonster()) { int32_t secondaryReflectPercent = target->getReflectPercent(damage.secondary.type, true); int32_t secondaryReflectFlat = target->getReflectFlat(damage.secondary.type, true); @@ -6079,32 +6104,10 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr attack } } } - damage.secondary.value = -damage.secondary.value; - // Damage healing secondary - if (attacker && target->getMonster()) { - uint32_t secondaryHealing = target->getMonster()->getHealingCombatValue(damage.secondary.type); - if (secondaryHealing > 0) { - ; - damageHeal.primary.value += std::ceil((damage.secondary.value) * (secondaryHealing / 100.)); - canHeal = true; - } - if (targetPlayer && attacker->getAbsorbPercent(damage.secondary.type) != 0) { - damageAbsorbMessage = true; - } - if (attacker->getPlayer() && attacker->getIncreasePercent(damage.secondary.type) != 0) { - damageIncreaseMessage = true; - } - damage.secondary.value *= attacker->getBuff(BUFF_DAMAGEDEALT) / 100.; - } - damage.secondary.value *= target->getBuff(BUFF_DAMAGERECEIVED) / 100.; - - secondaryBlockType = target->blockHit(attacker, damage.secondary.type, damage.secondary.value, false, false, field); - - damage.secondary.value = -damage.secondary.value; - InternalGame::sendBlockEffect(secondaryBlockType, damage.secondary.type, target->getPosition(), attacker); } else { secondaryBlockType = BLOCK_NONE; } + // Damage reflection secondary if (damage.primary.type == COMBAT_HEALING) { damage.primary.value *= target->getBuff(BUFF_HEALINGRECEIVED) / 100.; @@ -7223,13 +7226,7 @@ bool Game::combatChangeMana(std::shared_ptr attacker, std::shared_ptr< } target->drainMana(attacker, manaLoss); - if (targetPlayer) { - std::string cause = "(other)"; - if (attacker) { - cause = attacker->getName(); - } - targetPlayer->updateInputAnalyzer(damage.primary.type, damage.primary.value * -1, cause); - } + std::stringstream ss; std::string damageString = std::to_string(manaLoss);