From d75541e5b4eb9f165d81890651fbede769d83875 Mon Sep 17 00:00:00 2001 From: givehub99 <71454921+givehub99@users.noreply.github.com> Date: Sun, 18 Oct 2020 08:10:26 -0700 Subject: [PATCH] Consolidated unit kill bonus uniques (#3267) * -Consolidated unit kill bonus uniques. Syntax is "Earn []% of [] opponent's [] as [] for kills" for both units and nations. Ex. "Earn [10]% of [military] opponent's [Cost] as [Gold] for kills" or "Earn [100]% of [Barbarians] opponent's [Strength] as [Culture] for kills" Only Culture and Gold are supported as rewards now, but it can be expanded later. The pictish warrior unit in G&K gets 50% of opponent's strength as faith, so we can have the function edited to allow for faith when we get to that point. Only Strength or Cost is supported as what the reward amount is based on. -Policies.json and Nations.json were changed to fit the new syntax. The old syntax still works for mods for now. -matchesCategory MapUnit function can now check if the unit is a barbarian * -Compatibility for depecrated unit kill bonus uniques done more efficiently and counted only once (since prior to this PR, it was also counted only once) * -Changed it to "Barbarian" instead of "Barbarians", added "Barbarian" to template.properties * space after translation template --- .../assets/jsons/Civ V - Vanilla/Nations.json | 2 +- .../jsons/Civ V - Vanilla/Policies.json | 4 +- .../jsons/translations/template.properties | 1 + core/src/com/unciv/logic/battle/Battle.kt | 73 ++++++++++++++----- core/src/com/unciv/logic/map/MapUnit.kt | 1 + 5 files changed, 59 insertions(+), 22 deletions(-) diff --git a/android/assets/jsons/Civ V - Vanilla/Nations.json b/android/assets/jsons/Civ V - Vanilla/Nations.json index 3439d8a8b8..80b0f780d0 100644 --- a/android/assets/jsons/Civ V - Vanilla/Nations.json +++ b/android/assets/jsons/Civ V - Vanilla/Nations.json @@ -597,7 +597,7 @@ "outerColor": [139,32,23], "innerColor": [134,238,214], "uniqueName": "Sacrificial Captives", - "uniques": ["Gains culture from each enemy unit killed"], + "uniques": ["Earn [100]% of [military] opponent's [Strength] as [Culture] for kills"], "cities": ["Tenochtitlan","Teotihuacan","Tlatelolco","Texcoco","Tlaxcala","Calixtlahuaca","Xochicalco","Tlacopan", "Atzcapotzalco","Tzintzuntzan","Malinalco","Tula","Tamuin","Teayo","Cempoala","Chalco","Tlalmanalco", "Ixtapaluca","Huexotla","Tepexpan","Tepetlaoxtoc","Chiconautla","Zitlaltepec","Coyotepec","Tequixquiac", diff --git a/android/assets/jsons/Civ V - Vanilla/Policies.json b/android/assets/jsons/Civ V - Vanilla/Policies.json index 4b9b87a11f..38bb356ee8 100644 --- a/android/assets/jsons/Civ V - Vanilla/Policies.json +++ b/android/assets/jsons/Civ V - Vanilla/Policies.json @@ -104,7 +104,7 @@ "name": "Honor", "era": "Ancient era", "effect": "+25% bonus vs Barbarians; gain Culture when you kill a barbarian unit", - "uniques": ["+25% bonus vs Barbarians", "Gain Culture when you kill a barbarian unit", "Notified of new Barbarian encampments"], + "uniques": ["+25% bonus vs Barbarians", "Earn [100]% of [Barbarian] opponent's [Strength] as [Culture] for kills", "Notified of new Barbarian encampments"], "policies": [ { "name": "Warrior Code", @@ -147,7 +147,7 @@ { "name": "Honor Complete", "effect": "Gain gold for each unit killed", - "uniques": ["Gain gold for each unit killed"], + "uniques": ["Earn [10]% of [military] opponent's [Cost] as [Gold] for kills"], } ] },{ diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 5124b50523..c3aa554ed4 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -850,6 +850,7 @@ Civilian = land units = water units = air units = +Barbarian = WaterCivilian = Melee = WaterMelee = diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index efc370baf3..0bc6760607 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -76,12 +76,10 @@ object Battle { // Add culture when defeating a barbarian when Honor policy is adopted, gold from enemy killed when honor is complete // or any enemy military unit with Sacrificial captives unique (can be either attacker or defender!) if (defender.isDefeated() && defender is MapUnitCombatant && !defender.getUnitType().isCivilian()) { - tryGetCultureFromKilling(attacker, defender) - tryGetGoldFromKilling(attacker, defender) + tryEarnFromKilling(attacker, defender) tryHealAfterKilling(attacker, defender) } else if (attacker.isDefeated() && attacker is MapUnitCombatant && !attacker.getUnitType().isCivilian()) { - tryGetCultureFromKilling(defender, attacker) - tryGetGoldFromKilling(defender, attacker) + tryEarnFromKilling(defender, attacker) tryHealAfterKilling(defender, attacker) } @@ -93,6 +91,58 @@ object Battle { } } + private fun tryEarnFromKilling(civUnit:ICombatant, defeatedUnit:MapUnitCombatant){ + val unitStr = max(defeatedUnit.unit.baseUnit.strength, defeatedUnit.unit.baseUnit.rangedStrength) + val unitCost = defeatedUnit.unit.baseUnit.cost + val bonusUniquePlaceholderText = "Earn []% of [] opponent's [] as [] for kills" + + var goldReward = 0 + var cultureReward = 0 + var bonusUniques = ArrayList() + + bonusUniques.addAll(civUnit.getCivInfo().getMatchingUniques(bonusUniquePlaceholderText)) + + if (civUnit is MapUnitCombatant) { + bonusUniques.addAll(civUnit.unit.getMatchingUniques(bonusUniquePlaceholderText)) + } + + // As of 3.11.5 This is to be deprecated and converted to "Earn [100]% of [Barbarian] opponent's [Strength] as [Culture] for kills" - keeping it here so that mods with this can still work for now + if (defeatedUnit.unit.civInfo.isBarbarian() && civUnit.getCivInfo().hasUnique("Gain Culture when you kill a barbarian unit")) { + cultureReward += unitStr + } + + // As of 3.11.5 This is to be deprecated and converted to "Earn [100]% of [military] opponent's [Strength] as [Culture] for kills" - keeping it here so that mods with this can still work for now + if (civUnit.getCivInfo().hasUnique("Gains culture from each enemy unit killed")) { + cultureReward += unitStr + } + + // As of 3.11.5 This is to be deprecated and converted to "Earn [10]% of [military] opponent's [Cost] as [Gold] for kills" - keeping it here so that mods with this can still work for now + if (civUnit.getCivInfo().hasUnique("Gain gold for each unit killed")) { + goldReward += (unitCost.toFloat() * 0.10).toInt() + } + + for (unique in bonusUniques) { + if (!defeatedUnit.matchesCategory(unique.params[1])) { + continue + } + + val yieldPercent = unique.params[0].toFloat() / 100 + val defeatedUnitYieldSourceType = unique.params[2] + val yieldType = unique.params[3] + val yieldTypeSourceAmount = if (defeatedUnitYieldSourceType == "Cost") unitCost else unitStr + val yieldAmount = (yieldTypeSourceAmount * yieldPercent).toInt() + + + if (yieldType == "Gold") + goldReward += yieldAmount + else if (yieldType == "Culture") + cultureReward += yieldAmount + } + + civUnit.getCivInfo().policies.addCulture(cultureReward) + civUnit.getCivInfo().gold += goldReward + } + private fun takeDamage(attacker: ICombatant, defender: ICombatant) { var damageToDefender = BattleDamage.calculateDamageToDefender(attacker, attacker.getTile(), defender) var damageToAttacker = BattleDamage.calculateDamageToAttacker(attacker, attacker.getTile(), defender) @@ -216,21 +266,6 @@ object Battle { } } - private fun tryGetCultureFromKilling(civUnit:ICombatant, defeatedUnit:MapUnitCombatant){ - //Aztecs get melee strength of the unit killed in culture and honor opener does the same thing. - //They stack. So you get culture equal to 200% of the dead unit's strength. - val civInfo = civUnit.getCivInfo() - if (defeatedUnit.getCivInfo().isBarbarian() && civInfo.hasUnique("Gain Culture when you kill a barbarian unit")) - civInfo.policies.addCulture(defeatedUnit.unit.baseUnit.strength) - if (civInfo.hasUnique("Gains culture from each enemy unit killed")) - civInfo.policies.addCulture(defeatedUnit.unit.baseUnit.strength) - } - - private fun tryGetGoldFromKilling(civUnit:ICombatant, defeatedUnit:MapUnitCombatant) { - if (civUnit.getCivInfo().hasUnique("Gain gold for each unit killed")) - civUnit.getCivInfo().gold += defeatedUnit.unit.baseUnit.getProductionCost(defeatedUnit.getCivInfo()) / 10 - } - // XP! private fun addXp(thisCombatant:ICombatant, amount:Int, otherCombatant:ICombatant){ if(thisCombatant !is MapUnitCombatant) return diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index f71017faa6..fb45e7050c 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -686,6 +686,7 @@ class MapUnit { if (category == "non-air" && !type.isAirUnit()) return true if ((category == "military" || category == "military units") && type.isMilitary()) return true if (hasUnique(category)) return true + if ((category == "Barbarians" || category == "Barbarian") && civInfo.isBarbarian()) return true return false }