Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jjmaldonis committed May 5, 2024
1 parent 9bbdf4d commit 55c044e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 131 deletions.
4 changes: 4 additions & 0 deletions cassiopeia/core/staticdata/rune.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ def is_keystone(self) -> bool:
5005,
5007,
5008,
5010,
5011,
5012,
5013,
} # These are the ids of the stat shard runes which have a tier of 0 but are not keystones
# alternatively, we could add tier values to the hardcoded stat runes in datastores/ddragon.py
return self.tier == 0 and self.id not in excluded_ids
Expand Down
94 changes: 25 additions & 69 deletions cassiopeia/datastores/ddragon.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,75 +32,6 @@
T = TypeVar("T")


# Manually add stat runes since Riot doesn't provide static data for them...
statperk_health = {
"id": 5001,
"name": "HealthScaling",
"key": "HealthScaling",
"shortDesc": "+15-90 Health (based on level)",
"longDesc": "+15-90 Health (based on level)",
"icon": "/lol-game-data/assets/v1/perk-images/StatMods/StatModsHealthScalingIcon.png",
}
statperk_armor = {
"id": 5002,
"name": "Armor",
"key": "Armor",
"shortDesc": "+6 Armor",
"longDesc": "+6 Armor",
"icon": "/lol-game-data/assets/v1/perk-images/StatMods/StatModsArmorIcon.png",
}
statperk_magic_resist = {
"id": 5003,
"name": "MagicResist",
"key": "MagicRes",
"shortDesc": "+8 Magic Resist",
"longDesc": "+8 Magic Resist",
"icon": "/lol-game-data/assets/v1/perk-images/StatMods/StatModsMagicResIcon.png",
}
statperk_attack_speed = {
"id": 5005,
"name": "AttackSpeed",
"key": "AttackSpeed",
"shortDesc": "+10% Attack Speed",
"longDesc": "+10% Attack Speed",
"icon": "/lol-game-data/assets/v1/perk-images/StatMods/StatModsAttackSpeedIcon.png",
}
statperk_cdr = {
"id": 5007,
"name": "CDRScaling",
"key": "CDRScaling",
"shortDesc": "+1-10% <lol-uikit-tooltipped-keyword key='LinkTooltip_Description_CDR'>CDR</lol-uikit-tooltipped-keyword> (based on level)",
"longDesc": "+1-10% <lol-uikit-tooltipped-keyword key='LinkTooltip_Description_CDR'>CDR</lol-uikit-tooltipped-keyword> (based on level)",
"icon": "/lol-game-data/assets/v1/perk-images/StatMods/StatModsCDRScalingIcon.png",
}
statperk_adaptive = {
"id": 5008,
"name": "Adaptive",
"key": "Adaptive",
"shortDesc": "+9 <lol-uikit-tooltipped-keyword key='LinkTooltip_Description_Adaptive'><font color='#48C4B7'>Adaptive Force</font></lol-uikit-tooltipped-keyword>",
"longDesc": "+9 <lol-uikit-tooltipped-keyword key='LinkTooltip_Description_Adaptive'><font color='#48C4B7'>Adaptive Force</font></lol-uikit-tooltipped-keyword>",
"icon": "/lol-game-data/assets/v1/perk-images/StatMods/StatModsAdaptiveForceIcon.png",
}
statperks = {
"id": 5000,
"key": "stats",
"name": "stats",
"icon": "",
"slots": [
{
"runes": [
statperk_health,
statperk_armor,
statperk_magic_resist,
statperk_attack_speed,
statperk_cdr,
statperk_adaptive,
]
}
],
}


class DDragon(DataSource):
def __init__(self, http_client: HTTPClient = None) -> None:
if http_client is None:
Expand Down Expand Up @@ -587,6 +518,31 @@ def get_rune_list(
except HTTPError as e:
raise NotFoundError(str(e)) from e

cdragon_url = "https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/v1/perks.json"
try:
cdragon_body = json.loads(self._client.get(cdragon_url)[0])
except HTTPError as e:
raise NotFoundError(str(e)) from e

cdragon_runes = []
for rune in cdragon_body:
if str(rune["id"]).startswith("50"):
rune = {
"id": rune["id"],
"name": rune["name"],
"key": rune["name"].replace(" ", ""),
"shortDesc": rune["shortDesc"].encode("utf-8").decode("utf-8"),
"longDesc": rune["longDesc"].encode("utf-8").decode("utf-8"),
"icon": rune["iconPath"],
}
cdragon_runes.append(rune)
statperks = {
"id": 5000,
"key": "stats",
"name": "stats",
"icon": "",
"slots": [{"runes": cdragon_runes}],
}
body.append(statperks)
for path in body:
for tier, subpath in enumerate(path["slots"]):
Expand Down
76 changes: 14 additions & 62 deletions examples/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,80 +20,32 @@ def print_newest_match(name: str, tagline: str, region: str):
)
# match_history = summoner.match_history

# Load the entire match history by iterating over all its elements so that we know how long it is.
# Unfortunately since we are iterating over the match history and accessing the summoner's champion for each match,
# we need to know what version of the static data the champion should have. To avoid pulling many different
# static data versions, we will instead create a {champion_id -> champion_name} mapping and just access the champion's
# ID from the match data (which it provides directly).
champion_id_to_name_mapping = {
champion.id: champion.name for champion in cass.get_champions(region=region)
}
played_champions = Counter()
for match in match_history:
champion_id = match.participants[summoner].champion.id
champion_name = champion_id_to_name_mapping[champion_id]
played_champions[champion_name] += 1
print("Length of match history:", len(match_history))

# Print the aggregated champion results
print(f"Top 10 champions {account.name_with_tagline} played:")
for champion_name, count in played_champions.most_common(10):
print(champion_name, count)
print()

match = match_history[0]
print("Match ID:", match.id)

p = match.participants[summoner]
print(
"\nSince the match was created from a matchref, we only know one participant:"
)
# print(p.summoner_name, 'playing', p.champion.name)
print(
p.summoner.region,
p.summoner.account_id,
p.summoner_name,
p.summoner.id,
p.champion.id,
)

print("\nNow pull the full match data by iterating over all the participants:")
for p in match.participants:
# print(p.summoner_name, 'playing', p.champion.name)
print(
p.summoner.region,
p.summoner.account_id,
p.summoner_name,
p.summoner.id,
p.champion.id,
p.stats.win,
p.runes.keystone.name,
)

print(
"\nIterate over all the participants again and note that the data is not repulled:"
)
print(f"{p.summoner_name} with ID {p.summoner.id} played {p.champion.name}")
print()
print("Iterate over all the participants again and note the data is not repulled:")
for p in match.participants:
# print(p.summoner_name, 'playing', p.champion.name)
print(
p.summoner.region,
p.summoner.account_id,
p.summoner_name,
p.summoner_id,
p.champion.id,
p.stats.win,
p.runes.keystone.name,
)
print(f"{p.summoner_name} with ID {p.summoner.id} played {p.champion.name}")
print()

print("\nBlue team won?", match.blue_team.win)
print("Blue team won?", match.blue_team.win)
print("Red team won?", match.red_team.win)
print()

print("Participants on blue team:")
for p in match.blue_team.participants:
print(p.summoner_name, p.champion.name)
print(f"{p.summoner_name}: {p.champion.name}")
print()

# Print keystone and the stat runes for each player/champion
print("Keystone and stat runes for each player:")
for p in match.participants:
print(p.champion.name, p.runes.keystone.name, *[r.name for r in p.stat_runes])
print(
f"{p.champion.name}: {p.runes.keystone.name}, ({', '.join([r.name for r in p.stat_runes])})"
)


if __name__ == "__main__":
Expand Down

0 comments on commit 55c044e

Please sign in to comment.