Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
58a8971
remove slots
doluk Nov 2, 2022
0abafaf
escape not initialized attributes
doluk Nov 2, 2022
1004a86
Merge branch 'mathsman5133:master' into api_request_update
doluk Nov 2, 2022
435e694
change login_with_keys to be similar to login
doluk Nov 2, 2022
857c35b
make client.login_with_keys async
doluk Nov 2, 2022
ef298b8
update docs
doluk Nov 2, 2022
c00b86b
Merge pull request #4 from doluk/api_request_update
doluk Nov 11, 2022
26f10e3
Merge pull request #5 from doluk/cwl_fix_2
doluk Nov 11, 2022
f5437e6
Update iterators.py
doluk Nov 11, 2022
043a854
Merge pull request #6 from doluk/fixed_coc_py
doluk Nov 11, 2022
3f56385
Merge branch 'mathsman5133:master' into master
doluk Nov 14, 2022
71962be
wrapperchanges
doluk Nov 14, 2022
6e1445e
extend lab_to_townhall to work properly with townhalls with no lab
doluk Nov 28, 2022
76ae7ff
newest changes in static files
doluk Nov 28, 2022
904f8b6
handle load of DataContainer from json properly in terms of cls.lab_l…
doluk Nov 28, 2022
69ffbf0
Create FullWarApi.py (#7)
MagicTheDev Nov 28, 2022
ccfb7d0
make it mergeable with the official repo
doluk Nov 28, 2022
bd06c2b
refactoring as extentension
doluk Nov 28, 2022
a2390a3
make it mergeable with official repo
doluk Nov 28, 2022
bb95938
make it mergeable with official repo
doluk Nov 28, 2022
aba4217
minor changes
doluk Nov 29, 2022
38a5989
Merge pull request #8 from doluk/FullWarAPI
doluk Dec 1, 2022
9d8cde7
Merge pull request #9 from doluk/fullwarapi_public
doluk Dec 1, 2022
205a017
Merge branch 'master' into max_troop_lvl
doluk Dec 1, 2022
d426c1a
clean up of mysterious commits
doluk Dec 1, 2022
9e2ff7c
clean up of mysterious commits part 2
doluk Dec 1, 2022
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
58 changes: 44 additions & 14 deletions coc/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
SOFTWARE.
"""
import ujson

from pathlib import Path
from typing import AsyncIterator, Any, Dict, Type, Optional, TYPE_CHECKING

from .enums import Resource
Expand All @@ -33,6 +33,8 @@
if TYPE_CHECKING:
from .players import Player

BUILDING_FILE_PATH = Path(__file__).parent.joinpath(Path("static/buildings.json"))


class BaseClan:
"""An ABC that implements some common operations on clans, regardless of type.
Expand Down Expand Up @@ -187,8 +189,47 @@ def _load_json_meta(cls, troop_meta, id, name, lab_to_townhall):
cls.ground_target = _get_maybe_first(troop_meta, "GroundTargets", default=True)
cls.hitpoints = try_enum(UnitStat, troop_meta.get("Hitpoints"))

# get production building
production_building = troop_meta.get("ProductionBuilding", [None])[0]
if production_building == "Barrack":
cls.is_elixir_troop = True
elif production_building == "Dark Elixir Barrack":
cls.is_dark_troop = True
elif production_building == "SiegeWorkshop":
cls.is_siege_machine = True
elif production_building == "Spell Forge":
cls.is_elixir_spell = True
elif production_building == "Mini Spell Factory":
cls.is_dark_spell = True

# load buildings
with open(BUILDING_FILE_PATH) as fp:
buildings = ujson.load(fp)

# without production_building, it is a hero or pet
if not production_building:
laboratory_levels = troop_meta.get("LaboratoryLevel")
else:
# it is a troop or spell
prod_unit = buildings.get(production_building)
min_prod_unit_level = troop_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")
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 enumerate(prod_unit["TownHallLevel"], start=1)
if i == min_prod_unit_level]
# map the min th level to a lab level
[first_lab_level] = [lab_level for lab_level, th_level in lab_to_townhall.items()
if th_level in min_th_level]
# 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 = [x if x > first_lab_level else first_lab_level
for x in troop_meta.get("LaboratoryLevel")]

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

Expand All @@ -197,6 +238,7 @@ def _load_json_meta(cls, troop_meta, id, name, lab_to_townhall):
cls.upgrade_resource = Resource(value=troop_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
cls.village = "home" if cls._is_home_village else "builderBase"

# spells and troops
cls.training_cost = try_enum(UnitStat, troop_meta.get("TrainingCost"))
Expand All @@ -208,18 +250,6 @@ def _load_json_meta(cls, troop_meta, id, name, lab_to_townhall):
cls.required_th_level = try_enum(UnitStat, troop_meta.get("RequiredTownHallLevel"))
cls.regeneration_time = try_enum(UnitStat, [TimeDelta(minutes=value) for value in troop_meta.get("RegenerationTimeMinutes", [])])

production_building = troop_meta.get("ProductionBuilding", [None])[0]
if production_building == "Barrack":
cls.is_elixir_troop = True
elif production_building == "Dark Elixir Barrack":
cls.is_dark_troop = True
elif production_building == "SiegeWorkshop":
cls.is_siege_machine = True
elif production_building == "Spell Forge":
cls.is_elixir_spell = True
elif production_building == "Mini Spell Factory":
cls.is_dark_spell = True

cls.is_loaded = True
return cls

Expand Down
5 changes: 4 additions & 1 deletion coc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,13 @@ def _load_holders(self):
for supercell_name, data in buildings.items():
if supercell_name == "Laboratory":
lab_to_townhall = {index: th_level for index, th_level in enumerate(data["TownHallLevel"], start=1)}
# there are troops with no lab ...
lab_to_townhall[-1] = 1
lab_to_townhall[0] = 2
break
else:
# if the files failed to load, fallback to the old formula of lab level = TH level - 2
lab_to_townhall = {i: i + 2 for i in range(1, 15)}
lab_to_townhall = {i-2: i for i in range(1, 15)}

for holder in (self._troop_holder, self._spell_holder, self._hero_holder, self._pet_holder):
holder._load_json(object_ids, english_aliases, lab_to_townhall)
Expand Down
2 changes: 1 addition & 1 deletion coc/static/pets.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion coc/static/texts_EN.json

Large diffs are not rendered by default.