mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 11:34:54 -04:00
Add upon entering combat trigger (#13614)
* Add upon entering combat trigger * whoops * temporarily revert getMatchingUnique changes as out of scope * Last rename in functions
This commit is contained in:
parent
dc937f91d2
commit
fa7d075cde
@ -138,6 +138,8 @@ object Battle {
|
|||||||
|
|
||||||
val isAlreadyDefeatedCity = defender is CityCombatant && defender.isDefeated()
|
val isAlreadyDefeatedCity = defender is CityCombatant && defender.isDefeated()
|
||||||
|
|
||||||
|
triggerCombatUniques(attacker, defender, attackedTile)
|
||||||
|
|
||||||
val damageDealt = takeDamage(attacker, defender)
|
val damageDealt = takeDamage(attacker, defender)
|
||||||
|
|
||||||
// check if unit is captured by the attacker (prize ships unique)
|
// check if unit is captured by the attacker (prize ships unique)
|
||||||
@ -215,6 +217,21 @@ object Battle {
|
|||||||
|
|
||||||
return damageDealt + interceptDamage
|
return damageDealt + interceptDamage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun triggerCombatUniques(attacker: ICombatant, defender: ICombatant, attackedTile: Tile) {
|
||||||
|
val attackerContext = GameContext(attacker.getCivInfo(),
|
||||||
|
ourCombatant = attacker, theirCombatant = defender, tile = attackedTile, combatAction = CombatAction.Attack)
|
||||||
|
if (attacker is MapUnitCombatant)
|
||||||
|
for (unique in attacker.unit.getTriggeredUniques(UniqueType.TriggerUponCombat, attackerContext)) {
|
||||||
|
UniqueTriggerActivation.triggerUnique(unique, attacker.unit)
|
||||||
|
}
|
||||||
|
val defenderContext = GameContext(defender.getCivInfo(),
|
||||||
|
ourCombatant = defender, theirCombatant = attacker, tile = attackedTile, combatAction = CombatAction.Defend)
|
||||||
|
if (defender is MapUnitCombatant)
|
||||||
|
for (unique in defender.unit.getTriggeredUniques(UniqueType.TriggerUponCombat, defenderContext)) {
|
||||||
|
UniqueTriggerActivation.triggerUnique(unique, defender.unit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun triggerVictoryUniques(ourUnit: MapUnitCombatant, enemy: MapUnitCombatant, attackedTile: Tile) {
|
private fun triggerVictoryUniques(ourUnit: MapUnitCombatant, enemy: MapUnitCombatant, attackedTile: Tile) {
|
||||||
|
@ -46,8 +46,8 @@ class MapUnitCombatant(val unit: MapUnit) : ICombatant {
|
|||||||
return unit.name+" of "+unit.civ.civName
|
return unit.name+" of "+unit.civ.civName
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMatchingUniques(uniqueType: UniqueType, conditionalState: GameContext, checkCivUniques: Boolean): Sequence<Unique> =
|
fun getMatchingUniques(uniqueType: UniqueType, gameContext: GameContext, checkCivUniques: Boolean): Sequence<Unique> =
|
||||||
unit.getMatchingUniques(uniqueType, conditionalState, checkCivUniques)
|
unit.getMatchingUniques(uniqueType, gameContext, checkCivUniques)
|
||||||
|
|
||||||
fun hasUnique(uniqueType: UniqueType, conditionalState: GameContext? = null): Boolean =
|
fun hasUnique(uniqueType: UniqueType, conditionalState: GameContext? = null): Boolean =
|
||||||
if (conditionalState == null) unit.hasUnique(uniqueType)
|
if (conditionalState == null) unit.hasUnique(uniqueType)
|
||||||
|
@ -938,6 +938,7 @@ enum class UniqueType(
|
|||||||
|
|
||||||
///////////////////////////////////////// region 11 UNIT TRIGGERS /////////////////////////////////////////
|
///////////////////////////////////////// region 11 UNIT TRIGGERS /////////////////////////////////////////
|
||||||
|
|
||||||
|
TriggerUponCombat("upon entering combat", UniqueTarget.UnitTriggerCondition),
|
||||||
TriggerUponDamagingUnit("upon damaging a [mapUnitFilter] unit", UniqueTarget.UnitTriggerCondition,
|
TriggerUponDamagingUnit("upon damaging a [mapUnitFilter] unit", UniqueTarget.UnitTriggerCondition,
|
||||||
docDescription = "Can apply triggers to to damaged unit by setting the first parameter to 'Target Unit'"),
|
docDescription = "Can apply triggers to to damaged unit by setting the first parameter to 'Target Unit'"),
|
||||||
TriggerUponDefeatingUnit("upon defeating a [mapUnitFilter] unit", UniqueTarget.UnitTriggerCondition),
|
TriggerUponDefeatingUnit("upon defeating a [mapUnitFilter] unit", UniqueTarget.UnitTriggerCondition),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user