Make running fights easier
This commit is contained in:
@@ -12,6 +12,7 @@ root_path = Path(c['storage']['root'])
|
||||
|
||||
config = SimpleNamespace()
|
||||
config.data_file = root_path / c['storage']['data'] / c['data_file']
|
||||
config.bonus_data_file = root_path / c['storage']['data'] / c['bonus_data_file']
|
||||
config.name_data_file = root_path / c['storage']['data'] / c['name_data_file']
|
||||
config.string_data_file = root_path / c['storage']['data'] / c['string_data_file']
|
||||
config.namelists_dir = root_path / c['storage']['namelists']
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import json
|
||||
import math
|
||||
from copy import deepcopy
|
||||
|
||||
from flashcards.config import config
|
||||
|
||||
|
||||
|
||||
def _calculate_hp_bonus(hp, bonuses):
|
||||
@@ -40,6 +43,18 @@ def generate_bonus_with_percent(amount, clss):
|
||||
return {"Percent": amount, "Class": clss}
|
||||
|
||||
|
||||
def get_bonuses_from_names(clss, names):
|
||||
bonuses = []
|
||||
|
||||
if len(names) > 0:
|
||||
with open(config.bonus_data_file, 'r') as f:
|
||||
bonus_data = json.load(f)
|
||||
for name in names:
|
||||
bonuses.extend(bonus_data[clss.value][name])
|
||||
|
||||
return bonuses
|
||||
|
||||
|
||||
def calculate_hits_to_kill(attacker,
|
||||
defender,
|
||||
data,
|
||||
@@ -68,3 +83,48 @@ def calculate_hits_to_kill(attacker,
|
||||
|
||||
hits = math.ceil(hp/damage)
|
||||
return hits
|
||||
|
||||
|
||||
def generate_fight_results(attacker,
|
||||
defender,
|
||||
armor_class,
|
||||
bonus_range,
|
||||
data,
|
||||
nums,
|
||||
notes='',
|
||||
extra_attack_bonuses=[],
|
||||
extra_armor_bonuses=[],
|
||||
hp_bonuses=[],
|
||||
verbose=False):
|
||||
|
||||
if verbose:
|
||||
print(f'{attacker} attacking {defender}')
|
||||
if len(notes) > 0:
|
||||
print(notes)
|
||||
print('--------------------------------')
|
||||
|
||||
results = {'hits': {}}
|
||||
for i in bonus_range:
|
||||
attack_bonuses = deepcopy(extra_attack_bonuses)
|
||||
armor_bonuses = deepcopy(extra_armor_bonuses)
|
||||
|
||||
b = generate_bonus_with_value(abs(i), armor_class)
|
||||
if i < 0:
|
||||
armor_bonuses.append(b)
|
||||
else:
|
||||
attack_bonuses.append(b)
|
||||
|
||||
hits = calculate_hits_to_kill(attacker,
|
||||
defender,
|
||||
data,
|
||||
nums,
|
||||
attack_bonuses=attack_bonuses,
|
||||
armor_bonuses=armor_bonuses,
|
||||
hp_bonuses=hp_bonuses)
|
||||
|
||||
results['hits'][i] = hits
|
||||
if verbose:
|
||||
print(f'Net attack bonus: {i}\thits: {hits}')
|
||||
|
||||
results['notes'] = notes
|
||||
return results
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from enum import IntEnum
|
||||
from enum import Enum, IntEnum
|
||||
|
||||
|
||||
class ArmorClasses(IntEnum):
|
||||
@@ -6,3 +6,9 @@ class ArmorClasses(IntEnum):
|
||||
HP = -1 # my own addition
|
||||
PIERCE = 3
|
||||
MELEE = 4
|
||||
|
||||
|
||||
class BonusTypes(Enum):
|
||||
ARMOR = 'armor'
|
||||
ATTACK = 'attack'
|
||||
HP = 'hp'
|
||||
|
||||
Reference in New Issue
Block a user