mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-25 21:03:15 -04:00
Move takeDamage function from MapUnitCombatant to MApUnit where it belongs
This commit is contained in:
parent
adccee0b2e
commit
2494b1dcbc
@ -23,12 +23,7 @@ class MapUnitCombatant(val unit: MapUnit) : ICombatant {
|
||||
if (it == null) UncivSound.Click else UncivSound(it)
|
||||
}
|
||||
|
||||
override fun takeDamage(damage: Int) {
|
||||
unit.health -= damage
|
||||
if (unit.health > 100) unit.health = 100 // For cheating modders, e.g. negative tile damage
|
||||
if (unit.health < 0) unit.health = 0
|
||||
if (isDefeated()) unit.destroy()
|
||||
}
|
||||
override fun takeDamage(damage: Int) = unit.takeDamage(damage)
|
||||
|
||||
override fun getAttackingStrength(): Int {
|
||||
return if (isRanged()) unit.baseUnit().rangedStrength
|
||||
|
@ -575,13 +575,13 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
||||
power /= 100
|
||||
return power
|
||||
}
|
||||
|
||||
|
||||
fun getOtherEscortUnit(): MapUnit? {
|
||||
if (isCivilian()) return getTile().militaryUnit
|
||||
if (isMilitary()) return getTile().civilianUnit
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
fun isEscorting(): Boolean {
|
||||
if (escorting) {
|
||||
if (getOtherEscortUnit() != null) return true
|
||||
@ -752,6 +752,13 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
||||
if (health > 100) health = 100
|
||||
}
|
||||
|
||||
fun takeDamage(amount: Int) {
|
||||
health -= amount
|
||||
if (health > 100) health = 100 // For cheating modders, e.g. negative tile damage
|
||||
if (health < 0) health = 0
|
||||
if (health == 0) destroy()
|
||||
}
|
||||
|
||||
fun destroy(destroyTransportedUnit: Boolean = true) {
|
||||
stopEscorting()
|
||||
val currentPosition = Vector2(getTile().position)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.unciv.logic.map.mapunit
|
||||
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.battle.MapUnitCombatant
|
||||
import com.unciv.logic.civilization.LocationAction
|
||||
import com.unciv.logic.civilization.MapUnitAction
|
||||
import com.unciv.logic.civilization.NotificationCategory
|
||||
@ -85,7 +84,7 @@ class UnitTurnManager(val unit: MapUnit) {
|
||||
}.maxByOrNull { it.second }
|
||||
?: return
|
||||
if (damage == 0) return
|
||||
MapUnitCombatant(unit).takeDamage(damage)
|
||||
unit.takeDamage(damage)
|
||||
val improvementName = citadelTile.improvement!! // guarded by `getUnpillagedImprovement() != null` above
|
||||
val improvementIcon = "ImprovementIcons/$improvementName"
|
||||
val locations = LocationAction(citadelTile.position, unit.currentTile.position)
|
||||
@ -116,7 +115,7 @@ class UnitTurnManager(val unit: MapUnit) {
|
||||
val tileDamage = unit.getDamageFromTerrain()
|
||||
if (tileDamage == 0) return
|
||||
|
||||
MapUnitCombatant(unit).takeDamage(tileDamage)
|
||||
unit.takeDamage(tileDamage)
|
||||
|
||||
if (unit.isDestroyed) {
|
||||
unit.civ.addNotification(
|
||||
|
@ -869,7 +869,7 @@ object UniqueTriggerActivation {
|
||||
UniqueType.OneTimeUnitDamage -> {
|
||||
if (unit == null) return null
|
||||
return {
|
||||
MapUnitCombatant(unit).takeDamage(unique.params[0].toInt())
|
||||
unit.takeDamage(unique.params[0].toInt())
|
||||
if (notification != null)
|
||||
unit.civ.addNotification(notification, unit.getTile().position, NotificationCategory.Units) // Do we have a heal icon?
|
||||
true
|
||||
|
Loading…
x
Reference in New Issue
Block a user