Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Fix Code Style Checks #28

Merged
merged 13 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python_code_style_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
- name: Install Dependencies
run: pip install pycodestyle
- name: Style Checks
run : python -m pycodestyle --statistics --count --max-line-length=130 source
run : python -m pycodestyle --max-line-length=130 source
120 changes: 88 additions & 32 deletions source/battle.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,29 @@
turn = True
fighting = True


def calculate_player_risk(player, item, enemies_remaining, chosen_enemy, enemy):
# get all stats
player_hp = player["health"]
player_agi = player["agility"]
player_prot = player["armor protection"]
player_av_dmg = round(( item[player["held item"]]["damage"] + 1 + item[player["held item"]]["damage"] * item[player["held item"]]["critical hit chance"] * 2.3) / 2, 2 )
player_av_dmg = round(
(
(
item[player["held item"]]["damage"] + 1 + item[player["held item"]]["damage"]
) * item[player["held item"]]["critical hit chance"] * 2.3
) / 2, 2
)
player_def = item[player["held item"]]["defend"]
player_critic_ch = item[player["held item"]]["critical hit chance"]
player_health_cap = 1 # placeholder
player_health_cap = 1 # placeholder
enemies_number = enemies_remaining
enemy_health = random.randint(chosen_enemy["health"]["min spawning health"], chosen_enemy["health"]["max spawning health"])
enemy_agility = chosen_enemy["agility"]
enemy_max_damage = chosen_enemy["damage"]["max damage"]
enemy_min_damage = chosen_enemy["damage"]["min damage"]
enemy_critical_chance = chosen_enemy["damage"]["critical chance"]
enemy_av_dmg = round(( enemy_max_damage + enemy_min_damage + enemy_max_damage * enemy_critical_chance * 1.8) / 2, 2 )
enemy_av_dmg = round((enemy_max_damage + enemy_min_damage + enemy_max_damage * enemy_critical_chance * 1.8) / 2, 2)

# calculate player health capabilities (how many HP the player can restore)
count = 0
Expand All @@ -53,13 +60,12 @@ def calculate_player_risk(player, item, enemies_remaining, chosen_enemy, enemy):
if item_health_bonus != 0:
item_health_bonus = int(item[selected_item]["max bonus"]) / 2


player_health_cap += current_item_health_restoration
player_health_cap += item_health_bonus

count += 1
# get differences between player and enemy HP
hp_diff = ( (player_hp + player_health_cap + player_def * 1.5) - ( enemy_health * enemies_number ) )
hp_diff = ((player_hp + player_health_cap + player_def * 1.5) - (enemy_health * enemies_number))

# dodge formula is if round(random.uniform(.30, player_agility), 2) > enemy_agility / 1.15:
# enemy agility / 1.15
Expand All @@ -73,19 +79,19 @@ def calculate_player_risk(player, item, enemies_remaining, chosen_enemy, enemy):

# player
real_enemy_agility = enemy_agility / 1.15
player_true_dodge_possibilities = ( player_agi - .3 ) * 100
player_false_dodge_possibilities = ( real_enemy_agility - .3 ) * 100
player_true_dodge_possibilities = (player_agi - .3) * 100
player_false_dodge_possibilities = (real_enemy_agility - .3) * 100
player_total_possibilities = player_true_dodge_possibilities + player_false_dodge_possibilities

player_dodge_chance = round(( player_true_dodge_possibilities / player_total_possibilities) * 100)
player_dodge_chance = round((player_true_dodge_possibilities / player_total_possibilities) * 100)

# enemy
real_player_agility = player_agi / 1.15
enemy_true_dodge_possibilities = ( enemy_agility - .3 ) * 100
enemy_false_dodge_possibilities = ( real_player_agility - .3 ) * 100
enemy_true_dodge_possibilities = (enemy_agility - .3) * 100
enemy_false_dodge_possibilities = (real_player_agility - .3) * 100
enemy_total_possibilities = enemy_true_dodge_possibilities + enemy_false_dodge_possibilities

enemy_dodge_chance = round(( enemy_true_dodge_possibilities / enemy_total_possibilities ) * 100)
enemy_dodge_chance = round((enemy_true_dodge_possibilities / enemy_total_possibilities) * 100)

av_dmg_diff = player_av_dmg - enemy_av_dmg

Expand Down Expand Up @@ -124,19 +130,23 @@ def calculate_player_risk(player, item, enemies_remaining, chosen_enemy, enemy):
enemy_dodged = False
while player_turn:
# if player health is less than 45% and random formula, defend
if player_fake_health > player_fake_health * ( 45 / 100 ) and round(random.uniform(.20, .60), 2) > .45:
if player_fake_health > player_fake_health * (45 / 100) and round(random.uniform(.20, .60), 2) > .45:
defend = 0
defend += random.randint(0, int(item[player["held item"]]["defend"])) * player_fake_agility
# defend formula
player_fake_health+= random.randint(0, 3)
player_fake_health += random.randint(0, 3)
if player_fake_health > player_fake_health_max:
player_fake_health = player_fake_health_max
# else, the player attack
else:
# attack formula
enemy_dodged = False
player_critical_hit = False
player_critical_hit_chance = round(player_critical_hit_chance / random.uniform(.03, player_critical_hit_chance * 2.8), 2)
player_critical_hit_chance = round(
player_critical_hit_chance / random.uniform(
.03, player_critical_hit_chance * 2.8
), 2
)
if round(random.uniform(.30, enemy_agility), 2) > player_fake_agility / 1.15:
enemy_dodged = True
if player_critical_hit_chance / random.uniform(.20, .35) < player_critical_hit_chance and not enemy_dodged:
Expand All @@ -160,13 +170,25 @@ def calculate_player_risk(player, item, enemies_remaining, chosen_enemy, enemy):
while not player_turn:
# if enemy is still alive
if enemy_health > 0:
damage = random.randint(enemy_min_damage, enemy_max_damage) - player_fake_defend * ( player_fake_armor_protection * round(random.uniform(.50, .90), 1) )
damage = random.randint(enemy_min_damage, enemy_max_damage) - player_fake_defend * (
player_fake_armor_protection * round(
random.uniform(.50, .90), 1
)
)
damage = round(damage)
defend = 0
player_dodged = False
enemy_critical_hit = False
enemy_critical_hit_chance = round(enemy_fake_critical_hit_chance / random.uniform(.03, enemy_fake_critical_hit_chance * 2.8), 2)
critical_hit_chance_formula = round(enemy_critical_hit_chance / random.uniform(.03, enemy_critical_hit_chance * 2.8), 2)
enemy_critical_hit_chance = round(
enemy_fake_critical_hit_chance / random.uniform(
.03, enemy_fake_critical_hit_chance * 2.8
), 2
)
critical_hit_chance_formula = round(
enemy_critical_hit_chance / random.uniform(
.03, enemy_critical_hit_chance * 2.8
), 2
)
if enemy_critical_hit_chance / random.uniform(.20, .35) < critical_hit_chance_formula and not enemy_dodged:
enemy_critical_hit = True
elif round(random.uniform(.30, enemy_agility), 2) > enemy_agility / 1.15:
Expand All @@ -182,7 +204,6 @@ def calculate_player_risk(player, item, enemies_remaining, chosen_enemy, enemy):
someone_died = True
player_deaths += 1


count += 1

# compute percentage of defeat chance
Expand All @@ -195,12 +216,15 @@ def calculate_player_risk(player, item, enemies_remaining, chosen_enemy, enemy):

return defeat_percentage


def encounter_text_show(player, item, enemy, map, map_location, enemies_remaining, lists, defeat_percentage):
# import stats
global turn, defend, fighting, already_encountered
global enemy_singular, enemy_plural, enemy_max, enemy_health, enemy_max_damage, enemy_min_damage, enemy_agility, enemy_damage, chosen_item
global enemy_singular, enemy_plural, enemy_max
global enemy_health, enemy_max_damage, enemy_min_damage
global enemy_agility, enemy_damage, chosen_item
player_agility = player["agility"]
print(" ") # do not merge with possible actions text
print(" ") # do not merge with possible actions text
# load and create enemies list type

health_color = COLOR_GREEN
Expand Down Expand Up @@ -239,7 +263,11 @@ def encounter_text_show(player, item, enemy, map, map_location, enemies_remainin
health_color = COLOR_STYLE_BRIGHT + COLOR_GREEN

sys.stdout.write(f"RISK: {risk}% \n")
sys.stdout.write(f"|{health_color}{remaining_risk_bars * remaining_risk_symbol}{lost_risk_bars * lost_risk_symbol}{COLOR_RESET_ALL}|\n")
sys.stdout.write(
f"|{health_color}{
remaining_risk_bars * remaining_risk_symbol
}{lost_risk_bars * lost_risk_symbol}{COLOR_RESET_ALL}|\n"
)
sys.stdout.flush()

print("[R]un Away, [F]ight, [U]se Item? ")
Expand All @@ -266,7 +294,7 @@ def encounter_text_show(player, item, enemy, map, map_location, enemies_remainin
text_handling.print_separator(text)
fighting = True
elif startup_action.lower().startswith('f'):
fighting = True
fighting = True
elif startup_action.lower().startswith('u'):
player_inventory = str(player["inventory"])
player_inventory = player_inventory.replace("'", '')
Expand Down Expand Up @@ -307,11 +335,17 @@ def encounter_text_show(player, item, enemy, map, map_location, enemies_remainin
print("'" + startup_action + "' is not a valid option")
fighting = True


print(" ")

def get_enemy_stats(player, item, enemy, map, map_location, lists, choose_rand_enemy, chosen_enemy, chosen_item, enemy_items_number, enemy_total_inventory, enemies_remaining):
global enemy_singular, enemy_plural, enemy_max, enemy_health, enemy_max_damage, enemy_min_damage, enemy_agility, enemy_damage

def get_enemy_stats(
player, item, enemy, map, map_location,
lists, choose_rand_enemy, chosen_enemy,
chosen_item, enemy_items_number,
enemy_total_inventory, enemies_remaining
):
global enemy_singular, enemy_plural, enemy_max, enemy_health
global enemy_max_damage, enemy_min_damage, enemy_agility, enemy_damage
# load enemy stat

# enemy stats
Expand All @@ -328,10 +362,13 @@ def get_enemy_stats(player, item, enemy, map, map_location, lists, choose_rand_e
if choose_rand_enemy not in player["enemies list"]:
player["enemies list"].append(choose_rand_enemy)


def fight(player, item, enemy, map, map_location, enemies_remaining, lists):
# import stats
global turn, defend, fighting, already_encountered
global enemy_singular, enemy_plural, enemy_max, enemy_health, enemy_max_damage, enemy_min_damage, enemy_agility, enemy_damage, chosen_item
global enemy_singular, enemy_plural, enemy_max
global enemy_health, enemy_max_damage, enemy_min_damage
global enemy_agility, enemy_damage, chosen_item
armor_protection = player["armor protection"]
player_agility = player["agility"]
# load and create enemies list type
Expand Down Expand Up @@ -387,9 +424,17 @@ def fight(player, item, enemy, map, map_location, enemies_remaining, lists):
health_color_enemy = COLOR_MAGENTA

sys.stdout.write(f"PLAYER: {player_health} / {player_max_health}\n")
sys.stdout.write(f"|{health_color}{remaining_health_bars * remaining_health_symbol}{lost_health_bars * lost_health_symbol}{color_default}|\n")
sys.stdout.write(
f"|{health_color}{
remaining_health_bars * remaining_health_symbol
}{lost_health_bars * lost_health_symbol}{color_default}|\n"
)
sys.stdout.write(f"ENEMY: {enemy_health} / {enemy_max_health}\n")
sys.stdout.write(f"|{health_color_enemy}{remaining_health_bars_enemy * remaining_health_symbol}{lost_health_bars_enemy * lost_health_symbol}{color_default}|")
sys.stdout.write(
f"|{health_color_enemy}{
remaining_health_bars_enemy * remaining_health_symbol
}{lost_health_bars_enemy * lost_health_symbol}{color_default}|"
)
sys.stdout.flush()

action = input("\n[A]ttack, [D]efend, [U]se Item? ")
Expand Down Expand Up @@ -474,7 +519,11 @@ def fight(player, item, enemy, map, map_location, enemies_remaining, lists):
while not turn:
# if enemy is still alive
if enemy_health > 0:
damage = random.randint(enemy_min_damage, enemy_max_damage) - defend * ( armor_protection * round(random.uniform(.50, .90), 1) )
damage = random.randint(
enemy_min_damage, enemy_max_damage
) - defend * (
armor_protection * round(random.uniform(.50, .90), 1)
)
damage = round(damage)
defend = 0
player_dodged = False
Expand Down Expand Up @@ -506,9 +555,17 @@ def fight(player, item, enemy, map, map_location, enemies_remaining, lists):
remaining_health_bars_enemy = round(enemy_health / enemy_max_health * bars)
lost_health_bars_enemy = bars - remaining_health_bars_enemy
sys.stdout.write(f"PLAYER: {player_health} / {player_max_health}\n")
sys.stdout.write(f"|{health_color}{remaining_health_bars * remaining_health_symbol}{lost_health_bars * lost_health_symbol}{color_default}|\n")
sys.stdout.write(f"|{health_color}{
remaining_health_bars * remaining_health_symbol
}{
lost_health_bars * lost_health_symbol
}{color_default}|\n")
sys.stdout.write(f"ENEMY: {enemy_health} / {enemy_max_health}\n")
sys.stdout.write(f"|{health_color_enemy}{remaining_health_bars_enemy * remaining_health_symbol}{lost_health_bars_enemy * lost_health_symbol}{color_default}|")
sys.stdout.write(f"|{health_color_enemy}{
remaining_health_bars_enemy * remaining_health_symbol
}{
lost_health_bars_enemy * lost_health_symbol
}{color_default}|")
sys.stdout.flush()
print("\n")
player["xp"] += enemy_max * enemy_max_damage / 3
Expand All @@ -521,7 +578,6 @@ def fight(player, item, enemy, map, map_location, enemies_remaining, lists):
return



still_playing = True

# deinitialize colorama
Expand Down
25 changes: 21 additions & 4 deletions source/check_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# to access the program config/data folder
program_dir = str(appdirs.user_config_dir(appname='Bane-Of-Wargs'))


def check_yaml(file_path):
file_type = 'none'
with open(file_path, 'r') as f:
Expand Down Expand Up @@ -44,7 +45,11 @@ def check_yaml(file_path):
elif file_path.startswith('saves/'):
file_type = 'saves'
file_schema = str(f'{program_dir}/game/schemas/{file_type}.yaml')
if file_type == 'drinks' or file_type == 'mounts' or file_type == 'map' or file_type == 'lists' or file_type == 'npcs' or file_type == 'enemies' or file_type == 'dialogs' or file_type == 'missions':
long_files_types = [
'drinks', 'mounts', 'map', 'lists', 'npcs',
'enemies', 'dialogs', 'missions'
]
if file_type in long_files_types:
count = 0
file_len = int(len(list(file)))
while count < file_len:
Expand All @@ -53,7 +58,11 @@ def check_yaml(file_path):

schema = yamale.make_schema(file_schema)
data = yamale.make_data(content=str(current_object_data))
logger_sys.log_message(f"INFO: Validating file '{file_path}' data: '{current_object_data}' with schema '{file_schema}'")
logger_sys.log_message(
f"INFO: Validating file '{
file_path
}' data: '{current_object_data}' with schema '{file_schema}'"
)
yamale.validate(schema, data)

count += 1
Expand Down Expand Up @@ -81,7 +90,11 @@ def check_yaml(file_path):

schema = yamale.make_schema(str(file_schema))
data = yamale.make_data(content=str(current_object_data))
logger_sys.log_message(f"INFO: Validating file '{file_path}' data: '{current_object_data}' with schema '{file_schema}'")
logger_sys.log_message(
f"INFO: Validating file '{
file_path
}' data: '{current_object_data}' with schema '{file_schema}'"
)
yamale.validate(schema, data)

count += 1
Expand All @@ -92,10 +105,14 @@ def check_yaml(file_path):
logger_sys.log_message(f"INFO: Validating file '{file_path}' data: '{data}' with schema '{file_schema}'")
yamale.validate(schema, data)


def examine(file_path):
try:
check_yaml(str(file_path))
except Exception as error:
print(COLOR_RED + "ERROR: " + COLOR_RESET_ALL + COLOR_RED + COLOR_STYLE_BRIGHT + "A parsing error in a yaml file has been detected:\n" + COLOR_RESET_ALL + str(error))
print(
COLOR_RED + "ERROR: " + COLOR_RESET_ALL + COLOR_RED + COLOR_STYLE_BRIGHT +
"A parsing error in a yaml file has been detected:\n" + COLOR_RESET_ALL + str(error)
)
logger_sys.log_message(f"ERROR: A parsing error in a yaml file has been detected:\n{error}")
text_handling.exit_game()
9 changes: 7 additions & 2 deletions source/data_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# Handling functions


def load_game_data(which_type, what_plugin=None):

# Check if the which_type variable is valid,
Expand All @@ -25,7 +26,10 @@ def load_game_data(which_type, what_plugin=None):
# and stop the program immediately
if which_type != 'vanilla' and which_type != 'plugin':
logger_sys.log_message(f"ERROR: Yaml data loading inputted key '{which_type}' is not valid --> crashing program")
print(f"{COLOR_RED}ERROR: {COLOR_STYLE_BRIGHT}Yaml data loading inputted key '{which_type}' is not valid --> crashing program{COLOR_RESET_ALL}")
print(
f"{COLOR_RED}ERROR: {COLOR_STYLE_BRIGHT}Yaml" +
f"data loading inputted key '{which_type}' is not valid --> crashing program{COLOR_RESET_ALL}"
)
time.sleep(5)
text_handling.exit_game()

Expand Down Expand Up @@ -81,7 +85,7 @@ def load_game_data(which_type, what_plugin=None):
else:
logger_sys.log_message(f"INFO: Loading plugin '{what_plugin}' data")
check_file = os.path.exists(program_dir + "/plugins/" + what_plugin)
if check_file == False:
if check_file:
print(COLOR_RED + COLOR_STYLE_BRIGHT + "ERROR: Couldn't find plugin '" + what_plugin + "'" + COLOR_RESET_ALL)
logger_sys.log_message(f"ERROR: Couldn't find plugin '{what_plugin}'")
play = 0
Expand Down Expand Up @@ -132,5 +136,6 @@ def load_game_data(which_type, what_plugin=None):

return map, item, drinks, enemy, npcs, start_player, lists, zone, dialog, mission, mounts


# deinitialize colorama
deinit()
Loading
Loading