Skip to content

Commit

Permalink
🐛 Fix game data
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Jun 19, 2024
1 parent 79bff6a commit 1b9e9f0
Show file tree
Hide file tree
Showing 7 changed files with 2,307 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from httpx import get

url = "https://raw.githubusercontent.com/fribbels/hsr-optimizer/main/src/data/character_promotions.json"
url = "https://raw.githubusercontent.com/PaiGramTeam/hsr-optimizer/main/src/data/game_data.json"


def get_content() -> str:
Expand All @@ -10,7 +10,7 @@ def get_content() -> str:

def save_content(content: str) -> None:
with open(
"../src/starrailrelicscore/data/character_promotions.json",
"../src/starrailrelicscore/data/game_data.json",
"w",
encoding="utf-8",
) as file:
Expand Down
4 changes: 2 additions & 2 deletions compiler/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from get_metadata import main as get_metadata
from get_character_promotions import main as get_character_promotions
from get_game_data import main as get_game_data
from get_relic_config import main as get_relic_config


def main():
get_metadata()
get_character_promotions()
get_game_data()
get_relic_config()


Expand Down
10 changes: 4 additions & 6 deletions src/starrailrelicscore/client/relic_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@
class RelicScorer:
@staticmethod
def get_scaling(character_id: int) -> Dict[Stats, float]:
level80_stats = character_data.get_character_data(character_id)["promotions"][
80
]
base_stats = character_data.get_character_data(character_id)["stats"]
return {
Stats.HP_P: 64.8 / 43.2,
Stats.ATK_P: 64.8 / 43.2,
Stats.DEF_P: 64.8 / 54,
Stats.HP: 1 / (level80_stats[Stats.HP] * 2 * 0.01) * (64.8 / 43.2),
Stats.ATK: 1 / (level80_stats[Stats.ATK] * 2 * 0.01) * (64.8 / 43.2),
Stats.DEF: 1 / (level80_stats[Stats.DEF] * 2 * 0.01) * (64.8 / 54),
Stats.HP: 1 / (base_stats[Stats.HP] * 2 * 0.01) * (64.8 / 43.2),
Stats.ATK: 1 / (base_stats[Stats.ATK] * 2 * 0.01) * (64.8 / 43.2),
Stats.DEF: 1 / (base_stats[Stats.DEF] * 2 * 0.01) * (64.8 / 54),
Stats.CR: 64.8 / 32.4,
Stats.CD: 64.8 / 64.8,
Stats.OHB: 64.8 / 34.5,
Expand Down
43 changes: 5 additions & 38 deletions src/starrailrelicscore/data/character_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,16 @@
class CharacterData:
def __init__(self):
self.CHARACTER_DATA = {}
self.load_promotions_data()
self.load_game_data()

def load_promotions_data(self):
def load_game_data(self):
with open(
os.path.join(PATH, "character_promotions.json"), "r", encoding="utf-8"
os.path.join(PATH, "game_data.json"), "r", encoding="utf-8"
) as f:
data = json.load(f)
for character_id, promotions in data.items():
for character_id, _character_data in data["characters"].items():
cid = int(character_id)
if cid not in self.CHARACTER_DATA:
self.CHARACTER_DATA[cid] = {}
self.CHARACTER_DATA[cid]["promotions"] = self.parse_base_stats_by_level(
promotions
)

@staticmethod
def parse_base_stats_by_level(promotions):
base = {}
for i in range(1, 81):
value_index = (i // 10) - 1
if i <= 20:
value_index = 0
if i > 79:
value_index = 6

stat_scaling = promotions["values"][value_index]

base[i] = {
Stats.HP: stat_scaling["hp"]["base"]
+ stat_scaling["hp"]["step"] * (i - 1),
Stats.ATK: stat_scaling["atk"]["base"]
+ stat_scaling["atk"]["step"] * (i - 1),
Stats.CR: stat_scaling["crit_rate"]["base"]
+ stat_scaling["crit_rate"]["step"] * (i - 1),
Stats.CD: stat_scaling["crit_dmg"]["base"]
+ stat_scaling["crit_dmg"]["step"] * (i - 1),
Stats.DEF: stat_scaling["def"]["base"]
+ stat_scaling["def"]["step"] * (i - 1),
Stats.SPD: stat_scaling["spd"]["base"]
+ stat_scaling["spd"]["step"] * (i - 1),
}

return base
self.CHARACTER_DATA[cid] = _character_data

def get_character_data(self, character_id: int) -> "CHARACTER_CH_DATA_TYPE":
return self.CHARACTER_DATA.get(character_id)
Expand Down
1 change: 0 additions & 1 deletion src/starrailrelicscore/data/character_promotions.json

This file was deleted.

Loading

0 comments on commit 1b9e9f0

Please sign in to comment.