mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 22:37:02 -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)
|
if (it == null) UncivSound.Click else UncivSound(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun takeDamage(damage: Int) {
|
override fun takeDamage(damage: Int) = unit.takeDamage(damage)
|
||||||
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 getAttackingStrength(): Int {
|
override fun getAttackingStrength(): Int {
|
||||||
return if (isRanged()) unit.baseUnit().rangedStrength
|
return if (isRanged()) unit.baseUnit().rangedStrength
|
||||||
|
@ -752,6 +752,13 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
|||||||
if (health > 100) health = 100
|
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) {
|
fun destroy(destroyTransportedUnit: Boolean = true) {
|
||||||
stopEscorting()
|
stopEscorting()
|
||||||
val currentPosition = Vector2(getTile().position)
|
val currentPosition = Vector2(getTile().position)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.unciv.logic.map.mapunit
|
package com.unciv.logic.map.mapunit
|
||||||
|
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
import com.unciv.logic.battle.MapUnitCombatant
|
|
||||||
import com.unciv.logic.civilization.LocationAction
|
import com.unciv.logic.civilization.LocationAction
|
||||||
import com.unciv.logic.civilization.MapUnitAction
|
import com.unciv.logic.civilization.MapUnitAction
|
||||||
import com.unciv.logic.civilization.NotificationCategory
|
import com.unciv.logic.civilization.NotificationCategory
|
||||||
@ -85,7 +84,7 @@ class UnitTurnManager(val unit: MapUnit) {
|
|||||||
}.maxByOrNull { it.second }
|
}.maxByOrNull { it.second }
|
||||||
?: return
|
?: return
|
||||||
if (damage == 0) return
|
if (damage == 0) return
|
||||||
MapUnitCombatant(unit).takeDamage(damage)
|
unit.takeDamage(damage)
|
||||||
val improvementName = citadelTile.improvement!! // guarded by `getUnpillagedImprovement() != null` above
|
val improvementName = citadelTile.improvement!! // guarded by `getUnpillagedImprovement() != null` above
|
||||||
val improvementIcon = "ImprovementIcons/$improvementName"
|
val improvementIcon = "ImprovementIcons/$improvementName"
|
||||||
val locations = LocationAction(citadelTile.position, unit.currentTile.position)
|
val locations = LocationAction(citadelTile.position, unit.currentTile.position)
|
||||||
@ -116,7 +115,7 @@ class UnitTurnManager(val unit: MapUnit) {
|
|||||||
val tileDamage = unit.getDamageFromTerrain()
|
val tileDamage = unit.getDamageFromTerrain()
|
||||||
if (tileDamage == 0) return
|
if (tileDamage == 0) return
|
||||||
|
|
||||||
MapUnitCombatant(unit).takeDamage(tileDamage)
|
unit.takeDamage(tileDamage)
|
||||||
|
|
||||||
if (unit.isDestroyed) {
|
if (unit.isDestroyed) {
|
||||||
unit.civ.addNotification(
|
unit.civ.addNotification(
|
||||||
|
@ -869,7 +869,7 @@ object UniqueTriggerActivation {
|
|||||||
UniqueType.OneTimeUnitDamage -> {
|
UniqueType.OneTimeUnitDamage -> {
|
||||||
if (unit == null) return null
|
if (unit == null) return null
|
||||||
return {
|
return {
|
||||||
MapUnitCombatant(unit).takeDamage(unique.params[0].toInt())
|
unit.takeDamage(unique.params[0].toInt())
|
||||||
if (notification != null)
|
if (notification != null)
|
||||||
unit.civ.addNotification(notification, unit.getTile().position, NotificationCategory.Units) // Do we have a heal icon?
|
unit.civ.addNotification(notification, unit.getTile().position, NotificationCategory.Units) // Do we have a heal icon?
|
||||||
true
|
true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user