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

fix several TypeErrors in generate_dts() with unknown mon values #873

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
57 changes: 36 additions & 21 deletions PokeAlarm/Events/MonEvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, data):
self.atk_iv = check_for_none(int, data.get("individual_attack"), Unknown.TINY)
self.def_iv = check_for_none(int, data.get("individual_defense"), Unknown.TINY)
self.sta_iv = check_for_none(int, data.get("individual_stamina"), Unknown.TINY)
if Unknown.is_not(self.atk_iv, self.def_iv, self.sta_iv):
if Unknown.is_not(self.atk_iv, self.def_iv, self.sta_iv, self.mon_lvl):
self.iv = 100 * (self.atk_iv + self.def_iv + self.sta_iv) / float(45)
(
self.great_product,
Expand All @@ -112,6 +112,8 @@ def __init__(self, data):
self.sta_iv,
self.mon_lvl,
)
self.great_stardust = f"{self.great_stardust:,}".replace(",", " ")
self.ultra_stardust = f"{self.ultra_stardust:,}".replace(",", " ")
else:
self.iv = Unknown.SMALL
self.great_product = Unknown.SMALL
Expand Down Expand Up @@ -227,10 +229,37 @@ def generate_dts(self, locale, timezone, units):
self.monster_id, last_evo_id, evolutions, evolution_costs
)

if Unknown.is_not(self.atk_iv, self.def_iv, self.sta_iv):
max_cp_ = calculate_cp(
self.monster_id,
self.form_id,
self.atk_iv,
self.def_iv,
self.sta_iv,
50,
)
max_evo_cp_ = calculate_cp(
last_evo_id,
last_evo_form_id,
self.atk_iv,
self.def_iv,
self.sta_iv,
50,
)
else:
max_cp_ = Unknown.TINY
max_evo_cp_ = Unknown.TINY

# Remove ".0" from full PvP levels
if Unknown.is_not(self.great_level) and int(self.great_level) == self.great_level:
if (
Unknown.is_not(self.great_level)
and int(self.great_level) == self.great_level
):
self.great_level = int(self.great_level)
if Unknown.is_not(self.ultra_level) and int(self.ultra_level) == self.ultra_level:
if (
Unknown.is_not(self.ultra_level)
and int(self.ultra_level) == self.ultra_level
):
self.ultra_level = int(self.ultra_level)

# Stringify PvP candy costs
Expand Down Expand Up @@ -366,25 +395,11 @@ def generate_dts(self, locale, timezone, units):
"mon_lvl": self.mon_lvl,
"cp": self.cp,
# Max out
"max_cp": calculate_cp(
self.monster_id,
self.form_id,
self.atk_iv,
self.def_iv,
self.sta_iv,
50,
),
"max_cp": max_cp_,
"max_perfect_cp": max_cp(self.monster_id, self.form_id),
"stardust_cost": calculate_stardust_cost(self.mon_lvl, 50),
"candy_cost": calculate_candy_cost(self.mon_lvl, 50),
"max_evo_cp": calculate_cp(
last_evo_id,
last_evo_form_id,
self.atk_iv,
self.def_iv,
self.sta_iv,
50,
),
"max_evo_cp": max_evo_cp_,
"max_perfect_evo_cp": max_cp(last_evo_id, last_evo_form_id),
"candy_cost_with_evo": calculate_candy_cost(
self.mon_lvl, 50, evo_candy_cost
Expand Down Expand Up @@ -418,7 +433,7 @@ def generate_dts(self, locale, timezone, units):
),
"great_pvpoke": f"https://{pvpoke_domain}/rankings/all/1500/overall/{great_pvpoke_monster_formatted}/",
"great_candy": great_candy,
"great_stardust": f"{self.great_stardust:,}".replace(",", " "),
"great_stardust": self.great_stardust,
"ultra_mon_id": self.ultra_id,
"ultra_product": self.ultra_product,
"ultra_mon_name": locale.get_pokemon_name(self.ultra_id),
Expand All @@ -438,7 +453,7 @@ def generate_dts(self, locale, timezone, units):
),
"ultra_pvpoke": f"https://{pvpoke_domain}/rankings/all/2500/overall/{ultra_pvpoke_monster_formatted}/",
"ultra_candy": ultra_candy,
"ultra_stardust": f"{self.ultra_stardust:,}".replace(",", " "),
"ultra_stardust": self.ultra_stardust,
# Type
"type1": type1,
"type1_or_empty": Unknown.or_empty(type1),
Expand Down
4 changes: 2 additions & 2 deletions PokeAlarm/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ def get_xl_candy_costs():


def calculate_candy_cost(start_level, target_level, evo_candy_cost=0):
if start_level >= target_level:
if Unknown.is_(start_level) or start_level >= target_level:
return (0, 0)

candy_costs = get_candy_costs()
Expand All @@ -771,7 +771,7 @@ def calculate_candy_cost(start_level, target_level, evo_candy_cost=0):


def calculate_stardust_cost(start_level, target_level):
if start_level >= target_level:
if Unknown.is_(start_level) or start_level >= target_level:
return 0

stardust_costs = get_stardust_costs()
Expand Down