From cde26d325e5c49f516034e0c5ba701a2990f0395 Mon Sep 17 00:00:00 2001 From: PLynx Date: Sun, 17 Dec 2023 21:03:52 +0100 Subject: [PATCH] Add the remove unit promotion unique (#10759) * Added the remove unit promotion unique * Moved two lines of code inside if --- .../src/com/unciv/logic/map/mapunit/UnitPromotions.kt | 11 +++++++++++ .../models/ruleset/unique/UniqueTriggerActivation.kt | 8 ++++++++ .../src/com/unciv/models/ruleset/unique/UniqueType.kt | 1 + docs/Modders/uniques.md | 5 +++++ 4 files changed, 25 insertions(+) diff --git a/core/src/com/unciv/logic/map/mapunit/UnitPromotions.kt b/core/src/com/unciv/logic/map/mapunit/UnitPromotions.kt index 950013a05d..c9c6602269 100644 --- a/core/src/com/unciv/logic/map/mapunit/UnitPromotions.kt +++ b/core/src/com/unciv/logic/map/mapunit/UnitPromotions.kt @@ -91,6 +91,17 @@ class UnitPromotions : IsPartOfGameInfoSerialization { unit.updateVisibleTiles() // some promotions/uniques give the unit bonus sight } + fun removePromotion(promotionName: String) { + val ruleset = unit.civ.gameInfo.ruleset + val promotion = ruleset.unitPromotions[promotionName]!! + + if (getPromotions().contains(promotion)) { + promotions.remove(promotionName) + unit.updateUniques() + unit.updateVisibleTiles() + } + } + private fun doDirectPromotionEffects(promotion: Promotion) { for (unique in promotion.uniqueObjects) if (unique.conditionalsApply(StateForConditionals(civInfo = unit.civ, unit = unit)) diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt index feb9843d95..ca11c3ec3e 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt @@ -809,6 +809,14 @@ object UniqueTriggerActivation { unit.civ.addNotification(notification, unit.getTile().position, NotificationCategory.Units, unit.name) return true } + UniqueType.OneTimeUnitRemovePromotion -> { + val promotion = unit.civ.gameInfo.ruleset.unitPromotions.keys + .firstOrNull { it == unique.params[0]} + ?: return false + unit.promotions.removePromotion(promotion) + return true + } + else -> return triggerCivwideUnique(unique, civInfo = unit.civ, tile=unit.currentTile, triggerNotificationText = triggerNotificationText) } } diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 1e83607ecf..ad4222e6b5 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -734,6 +734,7 @@ enum class UniqueType( OneTimeUnitUpgrade("This Unit upgrades for free", UniqueTarget.UnitTriggerable), // Not used in Vanilla OneTimeUnitSpecialUpgrade("This Unit upgrades for free including special upgrades", UniqueTarget.UnitTriggerable), OneTimeUnitGainPromotion("This Unit gains the [promotion] promotion", UniqueTarget.UnitTriggerable), // Not used in Vanilla + OneTimeUnitRemovePromotion("This Unit loses the [promotion] promotion", UniqueTarget.UnitTriggerable), SkipPromotion("Doing so will consume this opportunity to choose a Promotion", UniqueTarget.Promotion), FreePromotion("This Promotion is free", UniqueTarget.Promotion), diff --git a/docs/Modders/uniques.md b/docs/Modders/uniques.md index 939ffdc966..99aa3c0f6a 100644 --- a/docs/Modders/uniques.md +++ b/docs/Modders/uniques.md @@ -185,6 +185,11 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl Applicable to: UnitTriggerable +??? example "This Unit loses the [promotion] promotion" + Example: "This Unit loses the [Shock I] promotion" + + Applicable to: UnitTriggerable + ## Global uniques !!! note ""