Modify how bonuses are managed

This commit is contained in:
Nate Bowman
2026-10-16 11:17:01 -04:00
parent c24f347af6
commit 045f8bc2c3
4 changed files with 212 additions and 152 deletions

View File

@@ -1,7 +1,19 @@
import math
from copy import deepcopy
def _calculate_hp_bonus(hp, bonuses):
for b in bonuses:
b_amount, _ = b.values()
if 'Amount' in b.keys():
hp += b_amount
else:
hp *= b_amount
hp = int(hp)
return hp
def _calculate_bonus(orig, bonuses, attack=False):
for b in bonuses:
b_amount, b_clss = b.values()
@@ -9,32 +21,41 @@ def _calculate_bonus(orig, bonuses, attack=False):
for iorig in range(len(orig)):
_, clss = orig[iorig].values()
if clss == b_clss:
orig[iorig]['Amount'] += b_amount
if 'Amount' in b.keys():
orig[iorig]['Amount'] += b_amount
else:
orig[iorig]['Amount'] *= b_amount
orig[iorig]['Amount'] = int(orig[iorig]['Amount'])
used = True
if attack and not used:
# bonus can add an attack but should not add an armor type
orig.append(b)
def generate_bonus_with_value(amount, clss):
return {"Amount": amount, "Class": clss}
def generate_bonus_with_percent(amount, clss):
return {"Percent": amount, "Class": clss}
def calculate_hits_to_kill(attacker,
defender,
data,
nums,
attack_bonuses=[],
armor_bonuses=[],
hp_bonus=0):
hp_bonuses=[]):
# Get base values
attacks = data[nums[attacker]]['Attacks']
armors = data[nums[defender]]['Armours']
attacks = deepcopy(data[nums[attacker]]['Attacks'])
armors = deepcopy(data[nums[defender]]['Armours'])
hp = data[nums[defender]]['HP']
# Apply any bonuses from technologies or civilizations
_calculate_bonus(attacks, attack_bonuses, attack=True)
_calculate_bonus(armors, armor_bonuses)
hp += hp_bonus
# TODO incorporate percent bonuses as well in separate function
# TODO use json data for hp_bonus instead of just a number
hp = _calculate_hp_bonus(hp, hp_bonuses)
damage = 0
for a in attacks: