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

fix: correctly reflect damage #1941

Merged
merged 5 commits into from
Dec 7, 2023
Merged
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
103 changes: 50 additions & 53 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5990,6 +5990,31 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr<Creature> attack
std::shared_ptr<Player> 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) {
Expand Down Expand Up @@ -6028,57 +6053,12 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr<Creature> 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;
}
}
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);
} else {
primaryBlockType = BLOCK_NONE;
}

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);
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<int32_t>(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.secondary.value, -(static_cast<int32_t>(secondaryReflectFlat))));
if (!damageReflected.exString.empty()) {
damageReflected.exString += ", ";
}
damageReflected.extension = true;
damageReflected.exString += "damage reflection";
damageReflectedParams.combatType = damage.primary.type;
damageReflectedParams.aggressive = true;
canReflect = true;
} else {
damageReflected.secondary.type = damage.secondary.type;
damageReflected.primary.value = std::ceil(damage.secondary.value * secondaryReflectPercent / 100.) + std::max(-static_cast<int32_t>(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.secondary.value, -(static_cast<int32_t>(secondaryReflectFlat))));
}
}
}

damage.secondary.value = -damage.secondary.value;
// Damage healing secondary
if (attacker && target->getMonster()) {
Expand All @@ -6102,9 +6082,32 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr<Creature> attack

damage.secondary.value = -damage.secondary.value;
InternalGame::sendBlockEffect(secondaryBlockType, damage.secondary.type, target->getPosition(), attacker);

if (!damage.extension && attacker && target->getMonster()) {
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 * secondaryReflectPercent / 100.) + std::max(-static_cast<int32_t>(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.secondary.value, -(static_cast<int32_t>(secondaryReflectFlat))));
if (!damageReflected.exString.empty()) {
damageReflected.exString += ", ";
}
damageReflected.extension = true;
damageReflected.exString += "damage reflection";
damageReflectedParams.combatType = damage.primary.type;
damageReflectedParams.aggressive = true;
canReflect = true;
} else {
damageReflected.secondary.type = damage.secondary.type;
damageReflected.primary.value = std::ceil(damage.secondary.value * secondaryReflectPercent / 100.) + std::max(-static_cast<int32_t>(std::ceil(attacker->getMaxHealth() * 0.01)), std::max(damage.secondary.value, -(static_cast<int32_t>(secondaryReflectFlat))));
}
}
}
} else {
secondaryBlockType = BLOCK_NONE;
}
// Damage reflection secondary

if (damage.primary.type == COMBAT_HEALING) {
damage.primary.value *= target->getBuff(BUFF_HEALINGRECEIVED) / 100.;
Expand Down Expand Up @@ -7223,13 +7226,7 @@ bool Game::combatChangeMana(std::shared_ptr<Creature> 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);
Expand Down
Loading