mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
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
This commit is contained in:
parent
10818de096
commit
d75541e5b4
@ -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",
|
||||
|
@ -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"],
|
||||
}
|
||||
]
|
||||
},{
|
||||
|
@ -850,6 +850,7 @@ Civilian =
|
||||
land units =
|
||||
water units =
|
||||
air units =
|
||||
Barbarian =
|
||||
WaterCivilian =
|
||||
Melee =
|
||||
WaterMelee =
|
||||
|
@ -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<Unique>()
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user