"can be promoted" notification only when it's actually new (#9230)

* "can be promoted" notification only when it's actually new

* Reviews - sumOf instead of fold
This commit is contained in:
SomeTroglodyte
2023-04-24 21:27:28 +02:00
committed by GitHub
parent dc5cc6d601
commit 42dff5584e

View File

@ -523,43 +523,48 @@ object Battle {
// XP! // XP!
private fun addXp(thisCombatant: ICombatant, amount: Int, otherCombatant: ICombatant) { private fun addXp(thisCombatant: ICombatant, amount: Int, otherCombatant: ICombatant) {
var baseXP = amount
if (thisCombatant !is MapUnitCombatant) return if (thisCombatant !is MapUnitCombatant) return
val modConstants = thisCombatant.unit.civ.gameInfo.ruleset.modOptions.constants val civ = thisCombatant.getCivInfo()
if (thisCombatant.unit.promotions.totalXpProduced() >= modConstants.maxXPfromBarbarians val otherIsBarbarian = otherCombatant.getCivInfo().isBarbarian()
&& otherCombatant.getCivInfo().isBarbarian()) val promotions = thisCombatant.unit.promotions
val modConstants = civ.gameInfo.ruleset.modOptions.constants
if (otherIsBarbarian && promotions.totalXpProduced() >= modConstants.maxXPfromBarbarians)
return return
val unitCouldAlreadyPromote = promotions.canBePromoted()
val stateForConditionals = StateForConditionals(civInfo = thisCombatant.getCivInfo(), ourCombatant = thisCombatant, theirCombatant = otherCombatant) val stateForConditionals = StateForConditionals(civInfo = civ, ourCombatant = thisCombatant, theirCombatant = otherCombatant)
for (unique in thisCombatant.getMatchingUniques(UniqueType.FlatXPGain, stateForConditionals, true)) val baseXP = amount + thisCombatant
baseXP += unique.params[0].toInt() .getMatchingUniques(UniqueType.FlatXPGain, stateForConditionals, true)
.sumOf { it.params[0].toInt() }
var xpModifier = 1f val xpBonus = thisCombatant
.getMatchingUniques(UniqueType.PercentageXPGain, stateForConditionals, true)
for (unique in thisCombatant.getMatchingUniques(UniqueType.PercentageXPGain, stateForConditionals, true)) .sumOf { it.params[0].toDouble() }
xpModifier += unique.params[0].toFloat() / 100 val xpModifier = 1.0 + xpBonus / 100
val xpGained = (baseXP * xpModifier).toInt() val xpGained = (baseXP * xpModifier).toInt()
thisCombatant.unit.promotions.XP += xpGained promotions.XP += xpGained
if (!otherIsBarbarian && civ.isMajorCiv()) { // Can't get great generals from Barbarians
if (thisCombatant.getCivInfo().isMajorCiv() && !otherCombatant.getCivInfo().isBarbarian()) { // Can't get great generals from Barbarians val greatGeneralPointsBonus = thisCombatant
var greatGeneralPointsModifier = 1f .getMatchingUniques(UniqueType.GreatPersonEarnedFaster, stateForConditionals, true)
for (unique in thisCombatant.getMatchingUniques(UniqueType.GreatPersonEarnedFaster, stateForConditionals, true)) { .filter { unique ->
val unitName = unique.params[0] val unitName = unique.params[0]
// From the unique we know this unit exists // From the unique we know this unit exists
val unit = thisCombatant.getCivInfo().gameInfo.ruleset.units[unitName]!! val unit = civ.gameInfo.ruleset.units[unitName]!!
if (unit.uniques.contains("Great Person - [War]")) unit.uniques.contains("Great Person - [War]")
greatGeneralPointsModifier += unique.params[1].toFloat() / 100
} }
.sumOf { it.params[1].toDouble() }
val greatGeneralPointsModifier = 1.0 + greatGeneralPointsBonus / 100
val greatGeneralPointsGained = (xpGained * greatGeneralPointsModifier).toInt() val greatGeneralPointsGained = (xpGained * greatGeneralPointsModifier).toInt()
thisCombatant.getCivInfo().greatPeople.greatGeneralPoints += greatGeneralPointsGained civ.greatPeople.greatGeneralPoints += greatGeneralPointsGained
} }
if (!thisCombatant.isDefeated() && thisCombatant.unit.promotions.canBePromoted()) if (!thisCombatant.isDefeated() && !unitCouldAlreadyPromote && promotions.canBePromoted())
thisCombatant.getCivInfo().addNotification("[${thisCombatant.unit.displayName()}] can be promoted!",thisCombatant.getTile().position, NotificationCategory.Units, thisCombatant.unit.name) civ.addNotification("[${thisCombatant.unit.displayName()}] can be promoted!",thisCombatant.getTile().position, NotificationCategory.Units, thisCombatant.unit.name)
} }
private fun conquerCity(city: City, attacker: MapUnitCombatant) { private fun conquerCity(city: City, attacker: MapUnitCombatant) {