From 433204bd6f8d6550170cc33b900edb1af2c37ceb Mon Sep 17 00:00:00 2001 From: Xander Lenstra <71121390+xlenstra@users.noreply.github.com> Date: Fri, 2 Jul 2021 15:56:41 +0200 Subject: [PATCH] Added missing notification when a privateer is attacked by a unit and plunders goods as a result (#4341) * Added missing notification when a privateer is attacked by a unit and plunders goods as a result * Added an extra function to do it instead --- core/src/com/unciv/logic/battle/Battle.kt | 29 +++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index cd4ce94d22..0fcdcc800c 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -181,29 +181,28 @@ object Battle { damageToAttacker -= attacker.getHealth() // ... but from here on they are accurate damageToDefender -= defender.getHealth() - if (attacker is MapUnitCombatant) { - for (unique in attacker.unit.getMatchingUniques("Earn []% of the damage done to [] units as []")) - if (defender.matchesCategory(unique.params[1])) { + plunderFromDamage(attacker, defender, damageToDefender) + plunderFromDamage(defender, attacker, damageToAttacker) + } + + private fun plunderFromDamage(plunderingUnit: ICombatant, plunderedUnit: ICombatant, damageDealt: Int) { + if (plunderingUnit is MapUnitCombatant) { + for (unique in plunderingUnit.unit.getMatchingUniques("Earn []% of the damage done to [] units as []")) { + if (plunderedUnit.matchesCategory(unique.params[1])) { val resourcesPlundered = - (unique.params[0].toFloat() / 100f * damageToDefender).toInt() - attacker.getCivInfo().addStat(Stat.valueOf(unique.params[2]), resourcesPlundered) - attacker.getCivInfo() + (unique.params[0].toFloat() / 100f * damageDealt).toInt() + plunderingUnit.getCivInfo().addStat(Stat.valueOf(unique.params[2]), resourcesPlundered) + plunderingUnit.getCivInfo() .addNotification( - "Your [${attacker.getName()}] plundered [${resourcesPlundered}] [${unique.params[2]}] from [${defender.getName()}]", - defender.getTile().position, + "Your [${plunderingUnit.getName()}] plundered [${resourcesPlundered}] [${unique.params[2]}] from [${plunderedUnit.getName()}]", + plunderedUnit.getTile().position, NotificationIcon.War ) } + } } - if (defender is MapUnitCombatant) { - for (unique in defender.unit.getMatchingUniques("Earn []% of the damage done to [] units as []")) - if (attacker.matchesCategory(unique.params[1])) - defender.getCivInfo().addStat(Stat.valueOf(unique.params[2]), (unique.params[0].toFloat() / 100f * damageToAttacker).toInt()) - } - } - private fun postBattleNotifications( attacker: ICombatant, defender: ICombatant,