-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
MapUnitCombatant.kt
56 lines (46 loc) · 2.22 KB
/
MapUnitCombatant.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.unciv.logic.battle
import com.unciv.logic.civilization.Civilization
import com.unciv.logic.map.mapunit.MapUnit
import com.unciv.logic.map.tile.Tile
import com.unciv.models.UncivSound
import com.unciv.models.ruleset.unique.StateForConditionals
import com.unciv.models.ruleset.unique.Unique
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.ruleset.unit.UnitType
class MapUnitCombatant(val unit: MapUnit) : ICombatant {
override fun getHealth(): Int = unit.health
override fun getMaxHealth() = 100
override fun getCivInfo(): Civilization = unit.civ
override fun getTile(): Tile = unit.getTile()
override fun getName(): String = unit.name
override fun isDefeated(): Boolean = unit.health <= 0
override fun isInvisible(to: Civilization): Boolean = unit.isInvisible(to)
override fun canAttack(): Boolean = unit.canAttack()
override fun matchesFilter(filter: String, multiFilter: Boolean) = unit.matchesFilter(filter, multiFilter)
override fun getAttackSound() = unit.baseUnit.attackSound.let {
if (it == null) UncivSound.Click else UncivSound(it)
}
override fun takeDamage(damage: Int) = unit.takeDamage(damage)
override fun getAttackingStrength(): Int {
return if (isRanged()) unit.baseUnit.rangedStrength
else unit.baseUnit.strength
}
override fun getDefendingStrength(attackedByRanged: Boolean): Int {
return if (unit.isEmbarked() && !isCivilian())
unit.civ.getEra().embarkDefense
else if (isRanged() && attackedByRanged)
unit.baseUnit.rangedStrength
else unit.baseUnit.strength
}
override fun getUnitType(): UnitType {
return unit.type
}
override fun toString(): String {
return unit.name+" of "+unit.civ.civName
}
fun getMatchingUniques(uniqueType: UniqueType, conditionalState: StateForConditionals, checkCivUniques: Boolean): Sequence<Unique> =
unit.getMatchingUniques(uniqueType, conditionalState, checkCivUniques)
fun hasUnique(uniqueType: UniqueType, conditionalState: StateForConditionals? = null): Boolean =
if (conditionalState == null) unit.hasUnique(uniqueType)
else unit.hasUnique(uniqueType, conditionalState)
}