mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-12 19:10:12 +07:00
Fixed bug where melee attacker would always move to attack, even if attackee was right next to it
This commit is contained in:
parent
fe09351db7
commit
5eec4deb84
@ -5,6 +5,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
import com.unciv.UnCivGame
|
import com.unciv.UnCivGame
|
||||||
import com.unciv.logic.battle.*
|
import com.unciv.logic.battle.*
|
||||||
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.logic.map.UnitType
|
import com.unciv.logic.map.UnitType
|
||||||
import com.unciv.ui.cityscreen.addClickListener
|
import com.unciv.ui.cityscreen.addClickListener
|
||||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||||
@ -110,36 +111,42 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
|
|||||||
|
|
||||||
val attackerDistanceToTiles = attacker.unit.getDistanceToTiles()
|
val attackerDistanceToTiles = attacker.unit.getDistanceToTiles()
|
||||||
|
|
||||||
if(attacker.getCombatantType() == CombatantType.Melee){
|
val attackerCanReachDefender:Boolean
|
||||||
val tilesCanAttackFrom = attackerDistanceToTiles.filter {
|
var tileToMoveTo:TileInfo? = null
|
||||||
attacker.unit.currentMovement - it.value > 0 // once we reach it we'll still have energy to attack
|
|
||||||
&& it.key.unit==null
|
|
||||||
&& it.key.neighbors.contains(defender.getTile()) }
|
|
||||||
|
|
||||||
if(tilesCanAttackFrom.isEmpty()) attackButton.disable()
|
if(attacker.getCombatantType() == CombatantType.Melee){
|
||||||
|
if(attacker.getTile().neighbors.contains(defender.getTile())){
|
||||||
|
attackerCanReachDefender=true
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
val tileToMoveTo = tilesCanAttackFrom.minBy { it.value }!!.key // travel least distance
|
val tilesCanAttackFrom = attackerDistanceToTiles.filter {
|
||||||
attackButton.addClickListener {
|
attacker.unit.currentMovement - it.value > 0 // once we reach it we'll still have energy to attack
|
||||||
attacker.unit.moveToTile(tileToMoveTo)
|
&& it.key.unit == null
|
||||||
battle.attack(attacker,defender)
|
&& it.key.neighbors.contains(defender.getTile())
|
||||||
worldScreen.update()
|
}
|
||||||
|
|
||||||
|
if (tilesCanAttackFrom.isEmpty()) attackerCanReachDefender=false
|
||||||
|
else {
|
||||||
|
tileToMoveTo = tilesCanAttackFrom.minBy { it.value }!!.key // travel least distance
|
||||||
|
attackerCanReachDefender=true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else { // ranged
|
else { // ranged
|
||||||
val tilesInRange = UnCivGame.Current.gameInfo.tileMap.getTilesInDistance(attacker.getTile().position, 2)
|
val tilesInRange = UnCivGame.Current.gameInfo.tileMap.getTilesInDistance(attacker.getTile().position, 2)
|
||||||
val attackerCanReachDefender = tilesInRange.contains(defender.getTile())
|
attackerCanReachDefender = tilesInRange.contains(defender.getTile())
|
||||||
if(!attackerCanReachDefender) attackButton.disable()
|
}
|
||||||
else {
|
|
||||||
attackButton.addClickListener {
|
if(!attackerCanReachDefender || attacker.unit.currentMovement==0f) attackButton.disable()
|
||||||
battle.attack(attacker, defender)
|
else {
|
||||||
worldScreen.update()
|
attackButton.addClickListener {
|
||||||
}
|
if(tileToMoveTo!=null) attacker.unit.moveToTile(tileToMoveTo)
|
||||||
|
battle.attack(attacker, defender)
|
||||||
|
worldScreen.update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(attacker.unit.currentMovement==0f) attackButton.disable()
|
|
||||||
add(attackButton).colspan(2)
|
add(attackButton).colspan(2)
|
||||||
|
|
||||||
pack()
|
pack()
|
||||||
|
Loading…
Reference in New Issue
Block a user