mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-23 14:19:15 +07:00
Added all promotions for air units, and a couple for other units that were previously missed
This commit is contained in:
@ -295,25 +295,30 @@ class Battle(val gameInfo:GameInfo) {
|
||||
|
||||
fun intercept(attacker:MapUnitCombatant, defender: ICombatant){
|
||||
val attackedTile = defender.getTile()
|
||||
for(unit in defender.getCivInfo().getCivUnits().filter { it.canIntercept(attackedTile) }){
|
||||
if(Random().nextFloat() > 100f/unit.interceptChance()) continue
|
||||
val damage = BattleDamage().calculateDamageToDefender(MapUnitCombatant(unit),attacker)
|
||||
for(interceptor in defender.getCivInfo().getCivUnits().filter { it.canIntercept(attackedTile) }){
|
||||
if(Random().nextFloat() > 100f/interceptor.interceptChance()) continue
|
||||
|
||||
var damage = BattleDamage().calculateDamageToDefender(MapUnitCombatant(interceptor),attacker)
|
||||
damage += damage*interceptor.interceptDamagePercentBonus()/100
|
||||
if(attacker.unit.hasUnique("Reduces damage taken from interception by 50%")) damage/=2
|
||||
|
||||
attacker.takeDamage(damage)
|
||||
interceptor.attacksThisTurn++
|
||||
|
||||
val attackerName = attacker.getName()
|
||||
val interceptorName = unit.name
|
||||
val interceptorName = interceptor.name
|
||||
|
||||
if(attacker.isDefeated()){
|
||||
attacker.getCivInfo().addNotification("Our [$attackerName] was destroyed by an intercepting [$interceptorName]",
|
||||
Color.RED)
|
||||
defender.getCivInfo().addNotification("Our [$interceptorName] intercepted and destroyed an enemy [$attackerName]",
|
||||
unit.currentTile.position, Color.RED)
|
||||
interceptor.currentTile.position, Color.RED)
|
||||
}
|
||||
else{
|
||||
attacker.getCivInfo().addNotification("Our [$attackerName] was attacked by an intercepting [$interceptorName]",
|
||||
Color.RED)
|
||||
defender.getCivInfo().addNotification("Our [$interceptorName] intercepted and attacked an enemy [$attackerName]",
|
||||
unit.currentTile.position, Color.RED)
|
||||
interceptor.currentTile.position, Color.RED)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -180,6 +180,7 @@ class MapUnit {
|
||||
if(type.isMelee()) return 1
|
||||
var range = baseUnit().range
|
||||
if(hasUnique("+1 Range")) range++
|
||||
if(hasUnique("+2 Range")) range+=2
|
||||
return range
|
||||
}
|
||||
|
||||
@ -475,7 +476,8 @@ class MapUnit {
|
||||
}
|
||||
|
||||
fun canIntercept(attackedTile: TileInfo): Boolean {
|
||||
return interceptChance()!=0 && attacksThisTurn==0
|
||||
return interceptChance()!=0
|
||||
&& (attacksThisTurn==0 || hasUnique("1 extra Interception may be made per turn") && attacksThisTurn<2)
|
||||
&& currentTile.arialDistanceTo(attackedTile) <= getRange()
|
||||
}
|
||||
|
||||
@ -483,8 +485,17 @@ class MapUnit {
|
||||
val interceptUnique = getUniques()
|
||||
.firstOrNull { it.endsWith(" chance to intercept air attacks") }
|
||||
if(interceptUnique==null) return 0
|
||||
val percent = Regex("\\d+").find(interceptUnique)!!.value
|
||||
return percent.toInt()
|
||||
val percent = Regex("\\d+").find(interceptUnique)!!.value.toInt()
|
||||
return percent
|
||||
}
|
||||
|
||||
fun interceptDamagePercentBonus():Int{
|
||||
var sum=0
|
||||
for(unique in getUniques().filter { it.startsWith("Bonus when intercepting") }){
|
||||
val percent = Regex("\\d+").find(unique)!!.value.toInt()
|
||||
sum += percent
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
Reference in New Issue
Block a user