More bug fixes (#4370)

* Fixed Air Targetting not having icon

* Fixed the huns not having battering ram unique unit

* Plundering with multiple levels of coastal raider no longer creates multiple notifications

* Implemented requested changes
This commit is contained in:
Xander Lenstra
2021-07-04 18:18:15 +02:00
committed by GitHub
parent 2a4ca74e7b
commit 0d26c69710
3 changed files with 25 additions and 14 deletions

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -273,7 +273,7 @@
{
"name": "Battering Ram",
"replaces": "Spearman",
"uniqueTo": "Huns",
"uniqueTo": "The Huns",
"unitType": "Melee",
"movement": 2,
"strength": 10,

View File

@ -12,6 +12,7 @@ import com.unciv.models.AttackableTile
import com.unciv.models.ruleset.Unique
import com.unciv.models.ruleset.unit.UnitType
import com.unciv.models.stats.Stat
import com.unciv.models.stats.Stats
import java.util.*
import kotlin.math.max
@ -186,20 +187,30 @@ object Battle {
}
private fun plunderFromDamage(plunderingUnit: ICombatant, plunderedUnit: ICombatant, damageDealt: Int) {
if (plunderingUnit is MapUnitCombatant) {
val plunderedGoods = Stats()
if (plunderingUnit !is MapUnitCombatant) return
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 * damageDealt).toInt()
plunderingUnit.getCivInfo().addStat(Stat.valueOf(unique.params[2]), resourcesPlundered)
unique.params[0].toFloat() / 100f * damageDealt
plunderedGoods.add(Stat.valueOf(unique.params[2]), resourcesPlundered)
}
}
val plunderableStats = listOf("Gold", "Science", "Culture", "Faith").map { Stat.valueOf(it) }
for (stat in plunderableStats) {
val resourcesPlundered = plunderedGoods.get(stat)
if (resourcesPlundered == 0f) continue
plunderingUnit.getCivInfo().addStat(stat, resourcesPlundered.toInt())
plunderingUnit.getCivInfo()
.addNotification(
"Your [${plunderingUnit.getName()}] plundered [${resourcesPlundered}] [${unique.params[2]}] from [${plunderedUnit.getName()}]",
"Your [${plunderingUnit.getName()}] plundered [${resourcesPlundered}] [${stat.name}] from [${plunderedUnit.getName()}]",
plunderedUnit.getTile().position,
NotificationIcon.War
)
}
}
}
}