Add a TriggerUponDiscoveringTile unique type (#10523)

* Add a TriggerUponDiscoveringTile unique type

* Add a check for trigger presence
This commit is contained in:
Sergey 2023-11-21 01:47:17 +05:00 committed by GitHub
parent 90767fce9a
commit 4adbd2e634
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import com.unciv.models.ruleset.unique.StateForConditionals
import com.unciv.models.ruleset.unique.Unique
import com.unciv.models.ruleset.unique.UniqueMap
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.ruleset.unit.UnitType
import com.unciv.models.stats.Stats
@ -344,8 +345,29 @@ class MapUnit : IsPartOfGameInfoSerialization {
if (updateCivViewableTiles && oldViewableTiles != viewableTiles
// Don't bother updating if all previous and current viewable tiles are within our borders
&& (oldViewableTiles.any { it !in civ.cache.ourTilesAndNeighboringTiles }
|| viewableTiles.any { it !in civ.cache.ourTilesAndNeighboringTiles }))
|| viewableTiles.any { it !in civ.cache.ourTilesAndNeighboringTiles })) {
val unfilteredTriggeredUniques = getTriggeredUniques(UniqueType.TriggerUponDiscoveringTile, StateForConditionals.IgnoreConditionals).toList()
if (unfilteredTriggeredUniques.isNotEmpty()) {
val newlyExploredTiles = viewableTiles.filter {
!it.isExplored(civ)
}
for (tile in newlyExploredTiles) {
// Include tile in the state for correct RNG seeding
val state = StateForConditionals(civInfo=civ, unit=this, tile=tile);
for (unique in unfilteredTriggeredUniques) {
if (unique.conditionals.any {
it.type == UniqueType.TriggerUponDiscoveringTile
&& tile.matchesFilter(it.params[0], civ)
} && unique.conditionalsApply(state)
)
UniqueTriggerActivation.triggerUnitwideUnique(unique, this)
}
}
}
civ.cache.updateViewableTiles(explorerPosition)
}
}
fun isActionUntilHealed() = action?.endsWith("until healed") == true

View File

@ -766,6 +766,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
TriggerUponPromotion("upon being promoted", UniqueTarget.UnitTriggerCondition),
TriggerUponLosingHealth("upon losing at least [amount] HP in a single attack", UniqueTarget.UnitTriggerCondition),
TriggerUponEndingTurnInTile("upon ending a turn in a [tileFilter] tile", UniqueTarget.UnitTriggerCondition),
TriggerUponDiscoveringTile("upon discovering a [tileFilter] tile", UniqueTarget.UnitTriggerCondition),
//endregion

View File

@ -2133,6 +2133,12 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
Applicable to: UnitTriggerCondition
??? example "<upon discovering a [tileFilter] tile>"
Triggers for each tile discovered (unfogged) by the unit.
Example: "<upon discovering a [Farm] tile>"
Applicable to: UnitTriggerCondition
## UnitActionModifier uniques
!!! note ""