mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-26 07:39:44 +07:00
Added unit trigger for 'upon defeat'
This commit is contained in:
@ -149,7 +149,7 @@ 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){
|
fun triggerVictoryUniques(ourUnit:MapUnitCombatant, enemy:MapUnitCombatant){
|
||||||
val stateForConditionals = StateForConditionals(civInfo = ourUnit.getCivInfo(),
|
val stateForConditionals = StateForConditionals(civInfo = ourUnit.getCivInfo(),
|
||||||
ourCombatant = ourUnit, theirCombatant=enemy, tile = attackedTile)
|
ourCombatant = ourUnit, theirCombatant=enemy, tile = attackedTile)
|
||||||
for (unique in ourUnit.unit.getTriggeredUniques(UniqueType.TriggerUponDefeatingUnit, stateForConditionals))
|
for (unique in ourUnit.unit.getTriggeredUniques(UniqueType.TriggerUponDefeatingUnit, stateForConditionals))
|
||||||
@ -158,19 +158,28 @@ object Battle {
|
|||||||
UniqueTriggerActivation.triggerUnitwideUnique(unique, ourUnit.unit)
|
UniqueTriggerActivation.triggerUnitwideUnique(unique, ourUnit.unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun triggerDefeatUniques(ourUnit: MapUnitCombatant, enemy: ICombatant){
|
||||||
|
val stateForConditionals = StateForConditionals(civInfo = ourUnit.getCivInfo(),
|
||||||
|
ourCombatant = ourUnit, theirCombatant=enemy, tile = attackedTile)
|
||||||
|
for (unique in ourUnit.unit.getTriggeredUniques(UniqueType.TriggerUponDefeat, stateForConditionals))
|
||||||
|
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)
|
if (attacker is MapUnitCombatant) triggerVictoryUniques(attacker, defender)
|
||||||
|
triggerDefeatUniques(defender, attacker)
|
||||||
|
|
||||||
} 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 (defender is MapUnitCombatant) triggerVictoryUniques(defender, attacker)
|
||||||
|
triggerDefeatUniques(attacker, defender)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attacker is MapUnitCombatant) {
|
if (attacker is MapUnitCombatant) {
|
||||||
|
@ -52,7 +52,8 @@ enum class UniqueTarget(val inheritsFrom: UniqueTarget? = null) {
|
|||||||
CityState(Global),
|
CityState(Global),
|
||||||
ModOptions,
|
ModOptions,
|
||||||
Conditional,
|
Conditional,
|
||||||
TriggerCondition(Global)
|
TriggerCondition(Global),
|
||||||
|
UnitTriggerCondition(TriggerCondition)
|
||||||
;
|
;
|
||||||
|
|
||||||
fun canAcceptUniqueTarget(uniqueTarget: UniqueTarget): Boolean {
|
fun canAcceptUniqueTarget(uniqueTarget: UniqueTarget): Boolean {
|
||||||
@ -730,7 +731,8 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
|||||||
|
|
||||||
///////////////////////////////////////// region UNIT TRIGGERS /////////////////////////////////////////
|
///////////////////////////////////////// region UNIT TRIGGERS /////////////////////////////////////////
|
||||||
|
|
||||||
TriggerUponDefeatingUnit("upon defeating a [mapUnitFilter] unit", UniqueTarget.TriggerCondition),
|
TriggerUponDefeatingUnit("upon defeating a [mapUnitFilter] unit", UniqueTarget.UnitTriggerCondition),
|
||||||
|
TriggerUponDefeat("upon defeat", UniqueTarget.UnitTriggerCondition),
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user