Intercept damage bonus (from promotions) treated as a unique

This commit is contained in:
Yair Morgenstern 2020-09-06 20:19:20 +03:00
parent 588aa7a177
commit 9034729dfd

View File

@ -73,8 +73,6 @@ class MapUnit {
private const val ANCIENT_RUIN_MAP_REVEAL_OFFSET = 4 private const val ANCIENT_RUIN_MAP_REVEAL_OFFSET = 4
private const val ANCIENT_RUIN_MAP_REVEAL_RANGE = 4 private const val ANCIENT_RUIN_MAP_REVEAL_RANGE = 4
private const val ANCIENT_RUIN_MAP_REVEAL_CHANCE = 0.8f private const val ANCIENT_RUIN_MAP_REVEAL_CHANCE = 0.8f
const val BONUS_WHEN_INTERCEPTING = "Bonus when intercepting"
const val CHANCE_TO_INTERCEPT_AIR_ATTACKS = " chance to intercept air attacks"
} }
//region pure functions //region pure functions
@ -125,9 +123,7 @@ class MapUnit {
// will not get counted twice! // will not get counted twice!
@Transient var tempUniques= ArrayList<Unique>() @Transient var tempUniques= ArrayList<Unique>()
fun getUniques(): ArrayList<Unique> { fun getUniques(): ArrayList<Unique> = tempUniques
return tempUniques
}
fun getMatchingUniques(placeholderText:String): Sequence<Unique> fun getMatchingUniques(placeholderText:String): Sequence<Unique>
= tempUniques.asSequence().filter { it.placeholderText == placeholderText } = tempUniques.asSequence().filter { it.placeholderText == placeholderText }
@ -190,9 +186,7 @@ class MapUnit {
return action!!.split(" ")[1].toInt() return action!!.split(" ")[1].toInt()
} }
override fun toString(): String { override fun toString() = "$name - $owner"
return "$name - $owner"
}
fun isIdle(): Boolean { fun isIdle(): Boolean {
@ -287,9 +281,7 @@ class MapUnit {
fun fortifyUntilHealed() { action = "Fortify 0 until healed" } fun fortifyUntilHealed() { action = "Fortify 0 until healed" }
fun fortifyIfCan() { fun fortifyIfCan() {
if (canFortify()) { if (canFortify()) fortify()
fortify()
}
} }
private fun adjacentHealingBonus():Int{ private fun adjacentHealingBonus():Int{
@ -436,8 +428,7 @@ class MapUnit {
if (hasUnique("This unit and all others in adjacent tiles heal 5 additional HP. This unit heals 5 additional HP outside of friendly territory.") if (hasUnique("This unit and all others in adjacent tiles heal 5 additional HP. This unit heals 5 additional HP outside of friendly territory.")
&& !isFriendlyTerritory && !isFriendlyTerritory
// Additional healing from medic is only applied when the unit is able to heal && healing > 0)// Additional healing from medic is only applied when the unit is able to heal
&& healing > 0)
healing += 5 healing += 5
return healing return healing
@ -669,18 +660,14 @@ class MapUnit {
var unitCapacity = 2 var unitCapacity = 2
unitCapacity += getUniques().count { it.text == "Can carry 1 extra air unit" } unitCapacity += getUniques().count { it.text == "Can carry 1 extra air unit" }
if (currentTile.airUnits.filter { it.isTransported }.size >= unitCapacity) return false if (currentTile.airUnits.count { it.isTransported } >= unitCapacity) return false
return true return true
} }
fun interceptDamagePercentBonus():Int { fun interceptDamagePercentBonus():Int {
var sum=0 return getUniques().filter { it.placeholderText == "Bonus when intercepting []%" }
for(unique in getUniques().filter { it.text.startsWith(BONUS_WHEN_INTERCEPTING) }){ .sumBy { it.params[0].toInt() }
val percent = Regex("\\d+").find(unique.text)!!.value.toInt()
sum += percent
}
return sum
} }
private fun getCitadelDamage() { private fun getCitadelDamage() {