Patch of the promotion exploit (#3214)

This commit is contained in:
Jack Rainy 2020-10-03 20:24:19 +03:00 committed by GitHub
parent ae182fb7b5
commit bddded04f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Button import com.badlogic.gdx.scenes.scene2d.ui.Button
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
import com.badlogic.gdx.utils.Align import com.badlogic.gdx.utils.Align
import com.unciv.UncivGame import com.unciv.UncivGame
import com.unciv.logic.map.MapUnit import com.unciv.logic.map.MapUnit
@ -17,11 +16,15 @@ import com.unciv.ui.utils.*
class PromotionPickerScreen(val unit: MapUnit) : PickerScreen() { class PromotionPickerScreen(val unit: MapUnit) : PickerScreen() {
private var selectedPromotion: Promotion? = null private var selectedPromotion: Promotion? = null
private fun acceptPromotion(promotion: Promotion?) {
// if user managed to click disabled button, still do nothing
if (promotion == null) return
fun acceptPromotion(promotion: Promotion?) { unit.promotions.addPromotion(promotion.name)
unit.promotions.addPromotion(promotion!!.name) if (unit.promotions.canBePromoted())
if(unit.promotions.canBePromoted()) game.setScreen(PromotionPickerScreen(unit)) game.setScreen(PromotionPickerScreen(unit))
else game.setWorldScreen() else
game.setWorldScreen()
dispose() dispose()
game.worldScreen.shouldUpdate = true game.worldScreen.shouldUpdate = true
} }
@ -59,10 +62,13 @@ class PromotionPickerScreen(val unit: MapUnit) : PickerScreen() {
selectPromotionButton.add(promotion.name.toLabel()).pad(10f).padRight(20f) selectPromotionButton.add(promotion.name.toLabel()).pad(10f).padRight(20f)
selectPromotionButton.touchable = Touchable.enabled selectPromotionButton.touchable = Touchable.enabled
selectPromotionButton.onClick { selectPromotionButton.onClick {
if(canBePromoted && isPromotionAvailable && !unitHasPromotion && canChangeState) if(canBePromoted && isPromotionAvailable && !unitHasPromotion && canChangeState) {
rightSideButton.enable()
else rightSideButton.disable()
selectedPromotion = promotion selectedPromotion = promotion
rightSideButton.enable()
} else {
selectedPromotion = null
rightSideButton.disable()
}
rightSideButton.setText(promotion.name.tr()) rightSideButton.setText(promotion.name.tr())
descriptionLabel.setText(promotion.getDescription(promotionsForUnitType)) descriptionLabel.setText(promotion.getDescription(promotionsForUnitType))