Modify how bonuses are managed
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"points": {
|
|
||||||
"armor": {
|
"armor": {
|
||||||
"Parthian Tactics": {
|
"Parthian Tactics": {
|
||||||
{"Amount": 1, "Class": 4},
|
{"Amount": 1, "Class": 4},
|
||||||
@@ -109,38 +108,43 @@
|
|||||||
},
|
},
|
||||||
"Arrowslits (Keep or Donjon)": {
|
"Arrowslits (Keep or Donjon)": {
|
||||||
{"Amount": 3, "Class": 3}
|
{"Amount": 3, "Class": 3}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"hp": {
|
|
||||||
"Bloodlines": 20,
|
|
||||||
"Hoardings": 1000,
|
|
||||||
"Sanctity": 15,
|
|
||||||
"Loom": 15
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"percents": {
|
|
||||||
"attack": {
|
|
||||||
"Siege Engineers (siege)": {
|
"Siege Engineers (siege)": {
|
||||||
{"Amount": 20, "Class": 11},
|
{"Percent": 20, "Class": 11},
|
||||||
{"Amount": 20, "Class": 13},
|
{"Percent": 20, "Class": 13},
|
||||||
{"Amount": 20, "Class": 21},
|
{"Percent": 20, "Class": 21},
|
||||||
{"Amount": 20, "Class": 22},
|
{"Percent": 20, "Class": 22},
|
||||||
{"Amount": 20, "Class": 26}
|
{"Percent": 20, "Class": 26}
|
||||||
},
|
},
|
||||||
"Siege Engineers (demo)": {
|
"Siege Engineers (demo)": {
|
||||||
{"Amount": 40, "Class": 11},
|
{"Percent": 40, "Class": 11},
|
||||||
{"Amount": 40, "Class": 13},
|
{"Percent": 40, "Class": 13},
|
||||||
{"Amount": 40, "Class": 21},
|
{"Percent": 40, "Class": 21},
|
||||||
{"Amount": 40, "Class": 22},
|
{"Percent": 40, "Class": 22},
|
||||||
{"Amount": 40, "Class": 26}
|
{"Percent": 40, "Class": 26}
|
||||||
},
|
},
|
||||||
"Heated Shot (Tower)": {
|
"Heated Shot (Tower)": {
|
||||||
{"Amount": 125, "Class": 16}
|
{"Percent": 125, "Class": 16}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"hp": {
|
"hp": {
|
||||||
"Masonry": 10,
|
"Bloodlines": {
|
||||||
"Architecture": 10
|
{"Amount": 20, "Class": -1}
|
||||||
|
},
|
||||||
|
"Hoardings": {
|
||||||
|
{"Amount": 1000, "Class": -1}
|
||||||
|
},
|
||||||
|
"Sanctity": {
|
||||||
|
{"Amount": 15, "Class": -1}
|
||||||
|
},
|
||||||
|
"Loom": {
|
||||||
|
{"Amount": 15, "Class": -1}
|
||||||
|
},
|
||||||
|
"Masonry": {
|
||||||
|
{"Percent": 10, "Class": -1}
|
||||||
|
},
|
||||||
|
"Architecture": {
|
||||||
|
{"Percent": 10, "Class": -1}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ from flashcards.maps import (create_maps,
|
|||||||
read_data_to_dict,
|
read_data_to_dict,
|
||||||
read_name_data_to_dict,
|
read_name_data_to_dict,
|
||||||
read_string_data_to_dict)
|
read_string_data_to_dict)
|
||||||
from flashcards.fighting import calculate_hits_to_kill
|
from flashcards.fighting import (calculate_hits_to_kill,
|
||||||
|
generate_bonus_with_value)
|
||||||
|
from flashcards.types import ArmorClasses
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# specify the namelist to be used to create the deck
|
# specify the namelist to be used to create the deck
|
||||||
# give the relative path of the file from config.namelists_dir
|
# give the relative path of the file from config.namelists_dir
|
||||||
namelist = 'units-basic.txt'
|
namelist = 'units-buildings-trimmed.txt'
|
||||||
|
|
||||||
# key into json file specifying which data you want
|
# key into json file specifying which data you want
|
||||||
name_json_keys = 'units_buildings'
|
name_json_keys = 'units_buildings'
|
||||||
@@ -19,8 +21,33 @@ string_json_keys = ()
|
|||||||
_, nums = create_maps(namelist, name_json_keys)
|
_, nums = create_maps(namelist, name_json_keys)
|
||||||
data = read_data_to_dict(data_json_keys)
|
data = read_data_to_dict(data_json_keys)
|
||||||
|
|
||||||
hits = calculate_hits_to_kill('Hulk',
|
attacker = 'Spearman'
|
||||||
'Fire Ship',
|
defender = 'Scout Cavalry'
|
||||||
|
bloodlines = False
|
||||||
|
|
||||||
|
print(f'{attacker} attacking {defender} with bloodlines={bloodlines}')
|
||||||
|
print('--------------------------------')
|
||||||
|
|
||||||
|
for i in range(-3, 5):
|
||||||
|
attack_bonuses = []
|
||||||
|
armor_bonuses = []
|
||||||
|
hp_bonuses = []
|
||||||
|
|
||||||
|
b = generate_bonus_with_value(abs(i), ArmorClasses.MELEE)
|
||||||
|
if i < 0:
|
||||||
|
armor_bonuses.append(b)
|
||||||
|
else:
|
||||||
|
attack_bonuses.append(b)
|
||||||
|
|
||||||
|
if bloodlines:
|
||||||
|
bloodlines_bonus = generate_bonus_with_value(20, ArmorClasses.HP)
|
||||||
|
hp_bonuses.append(bloodlines_bonus)
|
||||||
|
|
||||||
|
hits = calculate_hits_to_kill(attacker,
|
||||||
|
defender,
|
||||||
data,
|
data,
|
||||||
nums)
|
nums,
|
||||||
print(hits)
|
attack_bonuses=attack_bonuses,
|
||||||
|
armor_bonuses=armor_bonuses,
|
||||||
|
hp_bonuses=hp_bonuses)
|
||||||
|
print(f'Net attack bonus: {i}\thits: {hits}')
|
||||||
|
|||||||
@@ -1,7 +1,19 @@
|
|||||||
import math
|
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):
|
def _calculate_bonus(orig, bonuses, attack=False):
|
||||||
for b in bonuses:
|
for b in bonuses:
|
||||||
b_amount, b_clss = b.values()
|
b_amount, b_clss = b.values()
|
||||||
@@ -9,32 +21,41 @@ def _calculate_bonus(orig, bonuses, attack=False):
|
|||||||
for iorig in range(len(orig)):
|
for iorig in range(len(orig)):
|
||||||
_, clss = orig[iorig].values()
|
_, clss = orig[iorig].values()
|
||||||
if clss == b_clss:
|
if clss == b_clss:
|
||||||
|
if 'Amount' in b.keys():
|
||||||
orig[iorig]['Amount'] += b_amount
|
orig[iorig]['Amount'] += b_amount
|
||||||
|
else:
|
||||||
|
orig[iorig]['Amount'] *= b_amount
|
||||||
|
orig[iorig]['Amount'] = int(orig[iorig]['Amount'])
|
||||||
used = True
|
used = True
|
||||||
if attack and not used:
|
if attack and not used:
|
||||||
# bonus can add an attack but should not add an armor type
|
# bonus can add an attack but should not add an armor type
|
||||||
orig.append(b)
|
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,
|
def calculate_hits_to_kill(attacker,
|
||||||
defender,
|
defender,
|
||||||
data,
|
data,
|
||||||
nums,
|
nums,
|
||||||
attack_bonuses=[],
|
attack_bonuses=[],
|
||||||
armor_bonuses=[],
|
armor_bonuses=[],
|
||||||
hp_bonus=0):
|
hp_bonuses=[]):
|
||||||
# Get base values
|
# Get base values
|
||||||
attacks = data[nums[attacker]]['Attacks']
|
attacks = deepcopy(data[nums[attacker]]['Attacks'])
|
||||||
armors = data[nums[defender]]['Armours']
|
armors = deepcopy(data[nums[defender]]['Armours'])
|
||||||
hp = data[nums[defender]]['HP']
|
hp = data[nums[defender]]['HP']
|
||||||
|
|
||||||
# Apply any bonuses from technologies or civilizations
|
# Apply any bonuses from technologies or civilizations
|
||||||
_calculate_bonus(attacks, attack_bonuses, attack=True)
|
_calculate_bonus(attacks, attack_bonuses, attack=True)
|
||||||
_calculate_bonus(armors, armor_bonuses)
|
_calculate_bonus(armors, armor_bonuses)
|
||||||
hp += hp_bonus
|
hp = _calculate_hp_bonus(hp, hp_bonuses)
|
||||||
|
|
||||||
# TODO incorporate percent bonuses as well in separate function
|
|
||||||
# TODO use json data for hp_bonus instead of just a number
|
|
||||||
|
|
||||||
damage = 0
|
damage = 0
|
||||||
for a in attacks:
|
for a in attacks:
|
||||||
|
|||||||
8
flashcards/types.py
Normal file
8
flashcards/types.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from enum import IntEnum
|
||||||
|
|
||||||
|
|
||||||
|
class ArmorClasses(IntEnum):
|
||||||
|
# taken as genie editor value unless otherwise noted
|
||||||
|
HP = -1 # my own addition
|
||||||
|
PIERCE = 3
|
||||||
|
MELEE = 4
|
||||||
Reference in New Issue
Block a user