mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-05 15:59:50 +07:00
Fixed pillage tests
This commit is contained in:
@ -237,10 +237,10 @@ class ConsoleTileCommands: ConsoleCommandNode {
|
|||||||
|
|
||||||
class ConsoleCivCommands : ConsoleCommandNode {
|
class ConsoleCivCommands : ConsoleCommandNode {
|
||||||
override val subcommands = hashMapOf<String, ConsoleCommand>(
|
override val subcommands = hashMapOf<String, ConsoleCommand>(
|
||||||
"addstat" to ConsoleAction { console, params ->
|
"add" to ConsoleAction { console, params ->
|
||||||
var statPos = 0
|
var statPos = 0
|
||||||
if (params.size !in 2..3)
|
if (params.size !in 2..3)
|
||||||
return@ConsoleAction DevConsoleResponse.hint("Format: civ addstat [civ] [stat] <amount>")
|
return@ConsoleAction DevConsoleResponse.hint("Format: civ add [civ] <stat> <amount>")
|
||||||
val civ = if (params.size == 2) console.screen.selectedCiv
|
val civ = if (params.size == 2) console.screen.selectedCiv
|
||||||
else {
|
else {
|
||||||
statPos++
|
statPos++
|
||||||
|
@ -11,7 +11,6 @@ import com.unciv.models.ruleset.unique.UniqueType
|
|||||||
import com.unciv.models.stats.Stat
|
import com.unciv.models.stats.Stat
|
||||||
import com.unciv.models.stats.Stats
|
import com.unciv.models.stats.Stats
|
||||||
import com.unciv.ui.popups.ConfirmPopup
|
import com.unciv.ui.popups.ConfirmPopup
|
||||||
import com.unciv.ui.popups.hasOpenPopups
|
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
object UnitActionsPillage {
|
object UnitActionsPillage {
|
||||||
@ -19,21 +18,19 @@ object UnitActionsPillage {
|
|||||||
fun getPillageActions(unit: MapUnit, tile: Tile): List<UnitAction> {
|
fun getPillageActions(unit: MapUnit, tile: Tile): List<UnitAction> {
|
||||||
val pillageAction = getPillageAction(unit, tile)
|
val pillageAction = getPillageAction(unit, tile)
|
||||||
?: return listOf()
|
?: return listOf()
|
||||||
if (pillageAction.action == null)
|
if (pillageAction.action == null || unit.civ.isAI())
|
||||||
return listOf(pillageAction)
|
return listOf(pillageAction)
|
||||||
else return listOf(UnitAction(UnitActionType.Pillage, pillageAction.title) {
|
else return listOf(UnitAction(UnitActionType.Pillage, pillageAction.title) {
|
||||||
if (!GUI.getWorldScreen().hasOpenPopups()) {
|
val pillageText = "Are you sure you want to pillage this [${tile.getImprovementToPillageName()!!}]?"
|
||||||
val pillageText = "Are you sure you want to pillage this [${tile.getImprovementToPillageName()!!}]?"
|
ConfirmPopup(
|
||||||
ConfirmPopup(
|
GUI.getWorldScreen(),
|
||||||
GUI.getWorldScreen(),
|
pillageText,
|
||||||
pillageText,
|
"Pillage",
|
||||||
"Pillage",
|
true
|
||||||
true
|
) {
|
||||||
) {
|
(pillageAction.action)()
|
||||||
(pillageAction.action)()
|
GUI.setUpdateWorldOnNextRender()
|
||||||
GUI.setUpdateWorldOnNextRender()
|
}.open()
|
||||||
}.open()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,9 +2,10 @@ package com.unciv.uniques
|
|||||||
|
|
||||||
import com.badlogic.gdx.math.Vector2
|
import com.badlogic.gdx.math.Vector2
|
||||||
import com.unciv.Constants
|
import com.unciv.Constants
|
||||||
|
import com.unciv.models.UnitActionType
|
||||||
import com.unciv.testing.GdxTestRunner
|
import com.unciv.testing.GdxTestRunner
|
||||||
import com.unciv.testing.TestGame
|
import com.unciv.testing.TestGame
|
||||||
import com.unciv.ui.screens.worldscreen.unit.actions.UnitActionsPillage
|
import com.unciv.ui.screens.worldscreen.unit.actions.UnitActions
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@ -35,8 +36,7 @@ class TileUniquesTests {
|
|||||||
val unit = game.addUnit("Warrior", civInfo, tile)
|
val unit = game.addUnit("Warrior", civInfo, tile)
|
||||||
unit.currentMovement = 2f
|
unit.currentMovement = 2f
|
||||||
|
|
||||||
val pillageAction = UnitActionsPillage.getPillageAction(unit)
|
UnitActions.invokeUnitAction(unit, UnitActionType.Pillage)
|
||||||
pillageAction?.action?.invoke()
|
|
||||||
Assert.assertTrue("Pillaging should transfer gold to the civ", civInfo.gold == 20)
|
Assert.assertTrue("Pillaging should transfer gold to the civ", civInfo.gold == 20)
|
||||||
Assert.assertTrue("Pillaging should transfer food to the nearest city", city.population.foodStored == 11)
|
Assert.assertTrue("Pillaging should transfer food to the nearest city", city.population.foodStored == 11)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user