chore: Added test that battle triggers work, investigating #13291

This commit is contained in:
yairm210 2025-05-05 21:04:56 +03:00
parent 053691e18d
commit 4ff8442023
2 changed files with 20 additions and 2 deletions

View File

@ -584,8 +584,6 @@ class MapUnit : IsPartOfGameInfoSerialization {
if (civ.matchesFilter(filter, cache.state, false)) return true
if (nonUnitUniquesMap.hasUnique(filter, cache.state)) return true
if (promotions.promotions.contains(filter)) return true
// Badly optimized, but it's rare that statuses is even non-empty
// Statuses really should be converted to a hashmap
if (hasStatus(filter)) return true
return false
}

View File

@ -514,4 +514,24 @@ class BattleTest {
// then
assertTrue(attackerUnit.isDestroyed)
}
@Test
fun `should trigger damage triggers when ranged attacking`() {
// given
val unitType = testGame.createBaseUnit("Archery",
"[This Unit] takes [5] damage <upon damaging a [Test] unit>")
unitType.rangedStrength = 10
val attackerUnit = testGame.addUnit(unitType.name, attackerCiv, testGame.getTile(Vector2.Y))
attackerUnit.currentMovement = 2f
defaultDefenderUnit.health = 1
// when
defaultDefenderUnit.setStatus("Test", 1)
Battle.attack(MapUnitCombatant(attackerUnit), MapUnitCombatant(defaultDefenderUnit))
// then
assertEquals(95, attackerUnit.health)
assertTrue(defaultDefenderUnit.isDestroyed)
}
}