mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-09 23:39:40 +07:00
Introduced "upon defeating [unitFilter] unit" trigger
This commit is contained in:
@ -149,14 +149,28 @@ object Battle {
|
||||
if (!defender.isDefeated() && defender is MapUnitCombatant && defender.unit.isExploring())
|
||||
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
|
||||
// or any enemy military unit with Sacrificial captives unique (can be either attacker or defender!)
|
||||
if (defender.isDefeated() && defender is MapUnitCombatant && !defender.unit.isCivilian()) {
|
||||
tryEarnFromKilling(attacker, defender)
|
||||
tryHealAfterKilling(attacker)
|
||||
|
||||
if (attacker is MapUnitCombatant) triggerUniques(attacker, defender)
|
||||
|
||||
} else if (attacker.isDefeated() && attacker is MapUnitCombatant && !attacker.unit.isCivilian()) {
|
||||
tryEarnFromKilling(defender, attacker)
|
||||
tryHealAfterKilling(defender)
|
||||
|
||||
if (defender is MapUnitCombatant) triggerUniques(defender, attacker)
|
||||
}
|
||||
|
||||
if (attacker is MapUnitCombatant) {
|
||||
|
@ -425,6 +425,11 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
||||
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) {
|
||||
turnsFortified = 0
|
||||
currentMovement -= amount
|
||||
|
@ -2,6 +2,7 @@ package com.unciv.logic.map.mapunit
|
||||
|
||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||
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.UniqueType
|
||||
import com.unciv.models.ruleset.unit.Promotion
|
||||
@ -84,10 +85,11 @@ class UnitPromotions : IsPartOfGameInfoSerialization {
|
||||
}
|
||||
|
||||
private fun doDirectPromotionEffects(promotion: Promotion) {
|
||||
for (unique in promotion.uniqueObjects) {
|
||||
for (unique in promotion.uniqueObjects)
|
||||
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]
|
||||
* Checks unit type, already acquired promotions, prerequisites and incompatibility uniques.
|
||||
|
@ -4,9 +4,9 @@ import com.unciv.logic.battle.CombatAction
|
||||
import com.unciv.logic.battle.ICombatant
|
||||
import com.unciv.logic.city.City
|
||||
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.tile.Tile
|
||||
import com.unciv.logic.map.mapgenerator.Region
|
||||
|
||||
data class StateForConditionals(
|
||||
val civInfo: Civilization? = null,
|
||||
|
@ -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
|
||||
OneTimeGlobalSpiesWhenEnteringEra("Every major Civilization gains a spy once a civilization enters this era", UniqueTarget.Era),
|
||||
|
||||
OneTimeUnitHeal("Heal this unit by [amount] HP", UniqueTarget.Promotion),
|
||||
OneTimeUnitGainXP("This Unit gains [amount] XP", UniqueTarget.Ruins),
|
||||
OneTimeUnitUpgrade("This Unit upgrades for free", UniqueTarget.Global), // Not used in Vanilla
|
||||
OneTimeUnitHeal("Heal this unit by [amount] HP", UniqueTarget.Unit),
|
||||
OneTimeUnitGainXP("This Unit gains [amount] XP", UniqueTarget.Ruins, UniqueTarget.Unit),
|
||||
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),
|
||||
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),
|
||||
|
||||
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),
|
||||
TriggerUponEnhancingReligion("upon enhancing a Religion", UniqueTarget.TriggerCondition),
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
///////////////////////////////////////// region UNIT TRIGGERS /////////////////////////////////////////
|
||||
|
||||
TriggerUponDefeatingUnit("upon defeating a [mapUnitFilter] unit", UniqueTarget.TriggerCondition),
|
||||
|
||||
//endregion
|
||||
|
||||
|
@ -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 [Shock I] promotion"
|
||||
|
||||
Applicable to: Triggerable
|
||||
Applicable to: Triggerable, Unit
|
||||
|
||||
??? example "[mapUnitFilter] units gain the [promotion] 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
|
||||
|
||||
??? example "This Unit upgrades for free"
|
||||
Applicable to: Global
|
||||
Applicable to: Global, Unit
|
||||
|
||||
## Nation uniques
|
||||
??? 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
|
||||
|
||||
## Promotion uniques
|
||||
??? example "Heal this unit by [amount] 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"
|
||||
Applicable to: Promotion
|
||||
|
||||
@ -1612,11 +1617,6 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
|
||||
|
||||
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"
|
||||
Applicable to: Ruins
|
||||
|
||||
@ -1944,6 +1944,11 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
|
||||
??? example "<upon enhancing a Religion>"
|
||||
Applicable to: TriggerCondition
|
||||
|
||||
??? example "<upon defeating a [unitFilter] unit>"
|
||||
Example: "<upon defeating a [Unknown] unit>"
|
||||
|
||||
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'
|
||||
*[amount]: This indicates a whole number, possibly with a + or - sign, such as `2`, `+13`, or `-3`.
|
||||
|
Reference in New Issue
Block a user