Skip to content

Commit

Permalink
rename troop_meta to json_meta
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasthaler committed Dec 15, 2023
1 parent 4a2cc3b commit 88b91ca
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions coc/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,19 @@ def __repr__(self):
self.__class__.__name__, " ".join("%s=%r" % t for t in attrs),)

@classmethod
def _load_json_meta(cls, troop_meta, id, name, lab_to_townhall):
def _load_json_meta(cls, json_meta, id, name, lab_to_townhall):
cls.id = int(id)
cls.name = name
cls.lab_to_townhall = lab_to_townhall

cls.range = try_enum(UnitStat, troop_meta.get("AttackRange"))
cls.dps = try_enum(UnitStat, troop_meta.get("DPS"))
cls.ground_target = _get_maybe_first(troop_meta, "GroundTargets",
cls.range = try_enum(UnitStat, json_meta.get("AttackRange"))
cls.dps = try_enum(UnitStat, json_meta.get("DPS"))
cls.ground_target = _get_maybe_first(json_meta, "GroundTargets",
default=True)
cls.hitpoints = try_enum(UnitStat, troop_meta.get("Hitpoints"))
cls.hitpoints = try_enum(UnitStat, json_meta.get("Hitpoints"))

# get production building
production_building = troop_meta.get("ProductionBuilding", [None])[0] if troop_meta.get("ProductionBuilding") else None
production_building = json_meta.get("ProductionBuilding", [None])[0] if json_meta.get("ProductionBuilding") else None
if production_building == "Barrack":
cls.is_elixir_troop = True
elif production_building == "Dark Elixir Barrack":
Expand All @@ -213,16 +213,16 @@ def _load_json_meta(cls, troop_meta, id, name, lab_to_townhall):

# without production_building, it is a hero
if not production_building:
laboratory_levels = troop_meta.get("LaboratoryLevel")
laboratory_levels = json_meta.get("LaboratoryLevel")
else:
# it is a troop or spell or siege
prod_unit = buildings.get(production_building)
if production_building in ("SiegeWorkshop", "Spell Forge", "Mini Spell Factory",
"Dark Elixir Barrack", "Barrack", "Barrack2"):
min_prod_unit_level = troop_meta.get("BarrackLevel", [None, ])[0]
min_prod_unit_level = json_meta.get("BarrackLevel", [None, ])[0]
# there are some special troops, which have no BarrackLevel attribute
if not min_prod_unit_level:
laboratory_levels = troop_meta.get("LaboratoryLevel")
laboratory_levels = json_meta.get("LaboratoryLevel")
else:
# get the min th level were we can unlock by the required level of the production building
min_th_level = [th for i, th in
Expand All @@ -235,10 +235,10 @@ def _load_json_meta(cls, troop_meta, id, name, lab_to_townhall):
# the first_lab_level is the lowest possible (there are some inconsistencies with siege machines)
# To handle them properly, replacing all lab_level lower than first_lab_level with first_lab_level
laboratory_levels = []
for lab_level in troop_meta.get("LaboratoryLevel"):
for lab_level in json_meta.get("LaboratoryLevel"):
laboratory_levels.append(max(lab_level, first_lab_level))
elif production_building == "Pet Shop":
min_prod_unit_level = troop_meta.get("LaboratoryLevel", [None, ])[0]
min_prod_unit_level = json_meta.get("LaboratoryLevel", [None, ])[0]
# there are some special troops, which have no BarrackLevel attribute

# get the min th level were we can unlock by the required level of the production building
Expand All @@ -252,35 +252,35 @@ def _load_json_meta(cls, troop_meta, id, name, lab_to_townhall):
# the first_lab_level is the lowest possible (there are some inconsistencies with siege machines)
# To handle them properly, replacing all lab_level lower than first_lab_level with first_lab_level
laboratory_levels = []
for lab_level in troop_meta.get("LaboratoryLevel"):
for lab_level in json_meta.get("LaboratoryLevel"):
laboratory_levels.append(max(lab_level, first_lab_level))
else:
return

cls.lab_level = try_enum(UnitStat, laboratory_levels)
cls.housing_space = _get_maybe_first(troop_meta, "HousingSpace", default=0)
cls.speed = try_enum(UnitStat, troop_meta.get("Speed"))
cls.housing_space = _get_maybe_first(json_meta, "HousingSpace", default=0)
cls.speed = try_enum(UnitStat, json_meta.get("Speed"))
cls.level = cls.dps and UnitStat(range(1, len(cls.dps) + 1))

# all 3
cls.upgrade_cost = try_enum(UnitStat, troop_meta.get("UpgradeCost"))
cls.upgrade_resource = Resource(value=troop_meta["UpgradeResource"][0])
cls.upgrade_cost = try_enum(UnitStat, json_meta.get("UpgradeCost"))
cls.upgrade_resource = Resource(value=json_meta["UpgradeResource"][0])
cls.upgrade_time = try_enum(UnitStat,
[TimeDelta(hours=hours) for hours in
troop_meta.get("UpgradeTimeH", [])])
cls._is_home_village = False if troop_meta.get("VillageType") else True
json_meta.get("UpgradeTimeH", [])])
cls._is_home_village = False if json_meta.get("VillageType") else True
cls.village = "home" if cls._is_home_village else "builderBase"

# spells and troops
cls.training_cost = try_enum(UnitStat, troop_meta.get("TrainingCost"))
cls.training_time = try_enum(UnitStat, troop_meta.get("TrainingTime"))
cls.training_cost = try_enum(UnitStat, json_meta.get("TrainingCost"))
cls.training_time = try_enum(UnitStat, json_meta.get("TrainingTime"))

# only heroes
cls.ability_time = try_enum(UnitStat, troop_meta.get("AbilityTime"))
cls.ability_troop_count = try_enum(UnitStat, troop_meta.get("AbilitySummonTroopCount"))
cls.required_th_level = try_enum(UnitStat, troop_meta.get("RequiredTownHallLevel") or laboratory_levels)
cls.ability_time = try_enum(UnitStat, json_meta.get("AbilityTime"))
cls.ability_troop_count = try_enum(UnitStat, json_meta.get("AbilitySummonTroopCount"))
cls.required_th_level = try_enum(UnitStat, json_meta.get("RequiredTownHallLevel") or laboratory_levels)
cls.regeneration_time = try_enum(
UnitStat, [TimeDelta(minutes=value) for value in troop_meta.get("RegenerationTimeMinutes", [])]
UnitStat, [TimeDelta(minutes=value) for value in json_meta.get("RegenerationTimeMinutes", [])]
)

cls.is_loaded = True
Expand Down

0 comments on commit 88b91ca

Please sign in to comment.