71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
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()
|
|
used = False
|
|
for iorig in range(len(orig)):
|
|
_, clss = orig[iorig].values()
|
|
if clss == b_clss:
|
|
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_bonuses=[]):
|
|
# Get base values
|
|
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 = _calculate_hp_bonus(hp, hp_bonuses)
|
|
|
|
damage = 0
|
|
for a in attacks:
|
|
amount, clss = a.values()
|
|
for d in armors:
|
|
d_amount, d_clss = d.values()
|
|
if clss == d_clss:
|
|
damage += max(0, amount - d_amount)
|
|
damage = max(1, damage)
|
|
|
|
hits = math.ceil(hp/damage)
|
|
return hits
|