mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-08 23:08:35 +07:00
invokeUnitAction will take the first *actionable* action, instead of the first one that exists, which may not be actionable
This commit is contained in:
@ -23,9 +23,10 @@ object UnitActions {
|
||||
|
||||
/** Returns whether the action was invoked */
|
||||
fun invokeUnitAction(unit: MapUnit, unitActionType: UnitActionType): Boolean {
|
||||
val unitAction = actionTypeToFunctions[unitActionType]?.invoke(unit, unit.getTile())?.firstOrNull()
|
||||
?: getNormalActions(unit).firstOrNull { it.type == unitActionType }
|
||||
?: getAdditionalActions(unit).firstOrNull { it.type == unitActionType }
|
||||
val unitAction = if (unitActionType in actionTypeToFunctions) actionTypeToFunctions[unitActionType]!!.invoke(unit, unit.getTile())
|
||||
.firstOrNull{ it.action != null }
|
||||
else getNormalActions(unit).firstOrNull { it.type == unitActionType && it.action != null }
|
||||
?: getAdditionalActions(unit).firstOrNull { it.type == unitActionType && it.action != null }
|
||||
val internalAction = unitAction?.action ?: return false
|
||||
internalAction.invoke()
|
||||
return true
|
||||
|
Reference in New Issue
Block a user