Introduced "upon defeating [unitFilter] unit" trigger

This commit is contained in:
Yair Morgenstern 2023-02-26 20:31:08 +02:00
parent 7bfaeb274c
commit 090c421f9b
6 changed files with 49 additions and 17 deletions

View File

@ -149,14 +149,28 @@ object Battle {
if (!defender.isDefeated() && defender is MapUnitCombatant && defender.unit.isExploring()) if (!defender.isDefeated() && defender is MapUnitCombatant && defender.unit.isExploring())
defender.unit.action = null defender.unit.action = null
fun triggerUniques(ourUnit:MapUnitCombatant, enemy:MapUnitCombatant){
val stateForConditionals = StateForConditionals(civInfo = ourUnit.getCivInfo(),
ourCombatant = ourUnit, theirCombatant=enemy, tile = attackedTile)
for (unique in ourUnit.unit.getTriggeredUniques(UniqueType.TriggerUponDefeatingUnit, stateForConditionals))
if (unique.conditionals.any { it.type == UniqueType.TriggerUponDefeatingUnit
&& enemy.unit.matchesFilter(it.params[0]) })
UniqueTriggerActivation.triggerUnitwideUnique(unique, ourUnit.unit)
}
// Add culture when defeating a barbarian when Honor policy is adopted, gold from enemy killed when honor is complete // Add culture when defeating a barbarian when Honor policy is adopted, gold from enemy killed when honor is complete
// or any enemy military unit with Sacrificial captives unique (can be either attacker or defender!) // or any enemy military unit with Sacrificial captives unique (can be either attacker or defender!)
if (defender.isDefeated() && defender is MapUnitCombatant && !defender.unit.isCivilian()) { if (defender.isDefeated() && defender is MapUnitCombatant && !defender.unit.isCivilian()) {
tryEarnFromKilling(attacker, defender) tryEarnFromKilling(attacker, defender)
tryHealAfterKilling(attacker) tryHealAfterKilling(attacker)
if (attacker is MapUnitCombatant) triggerUniques(attacker, defender)
} else if (attacker.isDefeated() && attacker is MapUnitCombatant && !attacker.unit.isCivilian()) { } else if (attacker.isDefeated() && attacker is MapUnitCombatant && !attacker.unit.isCivilian()) {
tryEarnFromKilling(defender, attacker) tryEarnFromKilling(defender, attacker)
tryHealAfterKilling(defender) tryHealAfterKilling(defender)
if (defender is MapUnitCombatant) triggerUniques(defender, attacker)
} }
if (attacker is MapUnitCombatant) { if (attacker is MapUnitCombatant) {

View File

@ -425,6 +425,11 @@ class MapUnit : IsPartOfGameInfoSerialization {
updateUniques() updateUniques()
} }
fun getTriggeredUniques(trigger: UniqueType,
stateForConditionals: StateForConditionals = StateForConditionals(civInfo = civ, unit = this)): Sequence<Unique> {
return getUniques().filter { it.conditionals.any { it.type == trigger } && it.conditionalsApply(stateForConditionals) }
}
fun useMovementPoints(amount: Float) { fun useMovementPoints(amount: Float) {
turnsFortified = 0 turnsFortified = 0
currentMovement -= amount currentMovement -= amount

View File

@ -2,6 +2,7 @@ package com.unciv.logic.map.mapunit
import com.unciv.logic.IsPartOfGameInfoSerialization import com.unciv.logic.IsPartOfGameInfoSerialization
import com.unciv.models.ruleset.unique.StateForConditionals import com.unciv.models.ruleset.unique.StateForConditionals
import com.unciv.models.ruleset.unique.UniqueTarget
import com.unciv.models.ruleset.unique.UniqueTriggerActivation import com.unciv.models.ruleset.unique.UniqueTriggerActivation
import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.ruleset.unit.Promotion import com.unciv.models.ruleset.unit.Promotion
@ -84,9 +85,10 @@ class UnitPromotions : IsPartOfGameInfoSerialization {
} }
private fun doDirectPromotionEffects(promotion: Promotion) { private fun doDirectPromotionEffects(promotion: Promotion) {
for (unique in promotion.uniqueObjects) { for (unique in promotion.uniqueObjects)
UniqueTriggerActivation.triggerUnitwideUnique(unique, unit) if (unique.conditionalsApply(StateForConditionals(civInfo = unit.civ, unit = unit))
} && unique.conditionals.none { it.type?.targetTypes?.contains(UniqueTarget.TriggerCondition) == true })
UniqueTriggerActivation.triggerUnitwideUnique(unique, unit)
} }
/** Gets all promotions this unit could currently "buy" with enough [XP] /** Gets all promotions this unit could currently "buy" with enough [XP]

View File

@ -4,9 +4,9 @@ import com.unciv.logic.battle.CombatAction
import com.unciv.logic.battle.ICombatant import com.unciv.logic.battle.ICombatant
import com.unciv.logic.city.City import com.unciv.logic.city.City
import com.unciv.logic.civilization.Civilization import com.unciv.logic.civilization.Civilization
import com.unciv.logic.map.mapgenerator.Region
import com.unciv.logic.map.mapunit.MapUnit import com.unciv.logic.map.mapunit.MapUnit
import com.unciv.logic.map.tile.Tile import com.unciv.logic.map.tile.Tile
import com.unciv.logic.map.mapgenerator.Region
data class StateForConditionals( data class StateForConditionals(
val civInfo: Civilization? = null, val civInfo: Civilization? = null,

View File

@ -689,11 +689,11 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
OneTimeGlobalAlert("Triggers the following global alert: [comment]", UniqueTarget.Policy), // used in Policy OneTimeGlobalAlert("Triggers the following global alert: [comment]", UniqueTarget.Policy), // used in Policy
OneTimeGlobalSpiesWhenEnteringEra("Every major Civilization gains a spy once a civilization enters this era", UniqueTarget.Era), OneTimeGlobalSpiesWhenEnteringEra("Every major Civilization gains a spy once a civilization enters this era", UniqueTarget.Era),
OneTimeUnitHeal("Heal this unit by [amount] HP", UniqueTarget.Promotion), OneTimeUnitHeal("Heal this unit by [amount] HP", UniqueTarget.Unit),
OneTimeUnitGainXP("This Unit gains [amount] XP", UniqueTarget.Ruins), OneTimeUnitGainXP("This Unit gains [amount] XP", UniqueTarget.Ruins, UniqueTarget.Unit),
OneTimeUnitUpgrade("This Unit upgrades for free", UniqueTarget.Global), // Not used in Vanilla OneTimeUnitUpgrade("This Unit upgrades for free", UniqueTarget.Global, UniqueTarget.Unit), // Not used in Vanilla
OneTimeUnitSpecialUpgrade("This Unit upgrades for free including special upgrades", UniqueTarget.Ruins), OneTimeUnitSpecialUpgrade("This Unit upgrades for free including special upgrades", UniqueTarget.Ruins),
OneTimeUnitGainPromotion("This Unit gains the [promotion] promotion", UniqueTarget.Triggerable), // Not used in Vanilla OneTimeUnitGainPromotion("This Unit gains the [promotion] promotion", UniqueTarget.Triggerable, UniqueTarget.Unit), // Not used in Vanilla
SkipPromotion("Doing so will consume this opportunity to choose a Promotion", UniqueTarget.Promotion), SkipPromotion("Doing so will consume this opportunity to choose a Promotion", UniqueTarget.Promotion),
UnitsGainPromotion("[mapUnitFilter] units gain the [promotion] promotion", UniqueTarget.Triggerable), // Not used in Vanilla UnitsGainPromotion("[mapUnitFilter] units gain the [promotion] promotion", UniqueTarget.Triggerable), // Not used in Vanilla
@ -723,6 +723,12 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
TriggerUponFoundingReligion("upon founding a Religion", UniqueTarget.TriggerCondition), TriggerUponFoundingReligion("upon founding a Religion", UniqueTarget.TriggerCondition),
TriggerUponEnhancingReligion("upon enhancing a Religion", UniqueTarget.TriggerCondition), TriggerUponEnhancingReligion("upon enhancing a Religion", UniqueTarget.TriggerCondition),
//endregion
///////////////////////////////////////// region UNIT TRIGGERS /////////////////////////////////////////
TriggerUponDefeatingUnit("upon defeating a [mapUnitFilter] unit", UniqueTarget.TriggerCondition),
//endregion //endregion

View File

@ -80,7 +80,7 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
??? example "This Unit gains the [promotion] promotion" ??? example "This Unit gains the [promotion] promotion"
Example: "This Unit gains the [Shock I] promotion" Example: "This Unit gains the [Shock I] promotion"
Applicable to: Triggerable Applicable to: Triggerable, Unit
??? example "[mapUnitFilter] units gain the [promotion] promotion" ??? example "[mapUnitFilter] units gain the [promotion] promotion"
Example: "[Wounded] units gain the [Shock I] promotion" Example: "[Wounded] units gain the [Shock I] promotion"
@ -814,7 +814,7 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
Applicable to: Global, Unit Applicable to: Global, Unit
??? example "This Unit upgrades for free" ??? example "This Unit upgrades for free"
Applicable to: Global Applicable to: Global, Unit
## Nation uniques ## Nation uniques
??? example "Will not be chosen for new games" ??? example "Will not be chosen for new games"
@ -1300,12 +1300,17 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
Applicable to: Unit Applicable to: Unit
## Promotion uniques
??? example "Heal this unit by [amount] HP" ??? example "Heal this unit by [amount] HP"
Example: "Heal this unit by [3] HP" Example: "Heal this unit by [3] HP"
Applicable to: Promotion Applicable to: Unit
??? example "This Unit gains [amount] XP"
Example: "This Unit gains [3] XP"
Applicable to: Unit, Ruins
## Promotion uniques
??? example "Doing so will consume this opportunity to choose a Promotion" ??? example "Doing so will consume this opportunity to choose a Promotion"
Applicable to: Promotion Applicable to: Promotion
@ -1612,11 +1617,6 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
Applicable to: Ruins Applicable to: Ruins
??? example "This Unit gains [amount] XP"
Example: "This Unit gains [3] XP"
Applicable to: Ruins
??? example "This Unit upgrades for free including special upgrades" ??? example "This Unit upgrades for free including special upgrades"
Applicable to: Ruins Applicable to: Ruins
@ -1944,6 +1944,11 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
??? example "&lt;upon enhancing a Religion&gt;" ??? example "&lt;upon enhancing a Religion&gt;"
Applicable to: TriggerCondition Applicable to: TriggerCondition
??? example "&lt;upon defeating a [unitFilter] unit&gt;"
Example: "&lt;upon defeating a [Unknown] unit&gt;"
Applicable to: TriggerCondition
*[action]: An action that a unit can perform. Currently, there are only two actions part of this: 'Spread Religion' and 'Remove Foreign religions from your own cities' *[action]: An action that a unit can perform. Currently, there are only two actions part of this: 'Spread Religion' and 'Remove Foreign religions from your own cities'
*[amount]: This indicates a whole number, possibly with a + or - sign, such as `2`, `+13`, or `-3`. *[amount]: This indicates a whole number, possibly with a + or - sign, such as `2`, `+13`, or `-3`.