Added "removing the [promotion] promotion/status" unit action modifier

This commit is contained in:
yairm210 2024-09-23 23:35:05 +03:00
parent 980126ff06
commit d22bbaab39
2 changed files with 21 additions and 0 deletions

View File

@ -516,6 +516,10 @@ enum class UniqueType(
/** @see CostsResources */
UnitActionStockpileCost("costs [amount] [stockpiledResource]", UniqueTarget.UnitActionModifier,
docDescription = "A positive Integer value will be subtracted from your stock. Do not confuse with \"Costs [amount] [stockpiledResource]\" (uppercase 'C') for Improvements, Buildings, and Units."),
UnitActionRemovingPromotion("removing the [promotion] promotion/status", UniqueTarget.UnitActionModifier,
docDescription = "Removes the promotion/status from the unit -" +
" this is not a cost, units will be able to activate the action even without the promotion/status. " +
"To limit, use <with the [promotion] promotion> conditional"),
UnitActionOnce("once", UniqueTarget.UnitActionModifier),
UnitActionLimitedTimes("[amount] times", UniqueTarget.UnitActionModifier),
UnitActionExtraLimitedTimes("[amount] additional time(s)", UniqueTarget.UnitActionModifier),

View File

@ -7,6 +7,7 @@ import com.unciv.models.stats.Stat
import com.unciv.models.stats.Stats
import com.unciv.models.translations.removeConditionals
import com.unciv.models.translations.tr
import com.unciv.ui.components.fonts.FontRulesetIcons
import com.unciv.ui.components.fonts.Fonts
import kotlin.math.ceil
@ -116,6 +117,16 @@ object UnitActionModifiers {
if(unit.civ.getCivResourcesByName()[resourceName] != null)
unit.civ.resourceStockpiles.add(resourceName, -amount)
}
UniqueType.UnitActionRemovingPromotion -> {
val promotionName = conditional.params[0]
// if has a status, remove that instead - the promotion is 'safe'
val unitStatus = unit.statuses.firstOrNull { it.name == promotionName }
if (unitStatus != null) {
unit.statuses.remove(unitStatus)
} else { // check for real promotion
unit.promotions.removePromotion(promotionName)
}
}
else -> continue
}
}
@ -176,6 +187,12 @@ object UnitActionModifiers {
actionUnique,
defaultAllMovement
).tr() + Fonts.movement
for (removes in actionUnique.getModifiers(UniqueType.UnitActionRemovingPromotion)) {
val promotionName = removes.params[0]
val promotionChar = FontRulesetIcons.rulesetObjectNameToChar[promotionName]
if (promotionChar != null) effects += "-$promotionChar"
}
return if (effects.isEmpty()) ""
else "(${effects.joinToString { it.tr() }})"