-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.py
80 lines (58 loc) · 2.68 KB
/
stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from gcsim_names import good_to_gcsim_stats
from static import stats_data
class Stats:
__slots__ = stats_data.ATTRIBUTE_LIST
def __init__(self, **kwargs):
for attribute in stats_data.ATTRIBUTE_LIST:
setattr(self, attribute, kwargs.get(attribute, 0))
@classmethod
def by_stats_count(cls, quality=1, rarity_reference=5, **kwargs):
stats = {key: Stats.sub_stat(key, value, quality, rarity_reference) for key, value in kwargs.items()}
return cls(**stats)
@classmethod
def by_artifact_main_stat(cls, stat_key, level):
stats = cls()
stats[stat_key] += Stats.main_stat(stat_key, level)
return stats
@classmethod
def by_artifact_sub_stat(cls, stat_key, quant=1, quality=1, rarity_reference=5):
stats = cls()
stats[stat_key] += Stats.sub_stat(stat_key, quant, quality, rarity_reference)
return stats
@staticmethod
def main_stat(stat_key, level):
return stats_data.main_stat(stat_key, level=level)
@staticmethod
def sub_stat(stat_key, quant=1, quality=1, rarity_reference=5):
return quant * quality * stats_data.sub_stat(stat_key, rarity=rarity_reference)
def to_gcsim_text(self):
text = ' '.join(['{key}={value:.2f}'.format(key=good_to_gcsim_stats[attribute], value=value)
for attribute, value in self.items()])
return text
def calculate_power(self, rarity_reference=5):
power = 0
for key, sub_stat in self.items():
power += sub_stat / stats_data.sub_stat(key, rarity=rarity_reference)
return power
def to_json(self):
return {slot: self[slot] for slot in self.__slots__ if self[slot] > 0}
def __str__(self):
return self.to_gcsim_text()
def __getitem__(self, item):
return getattr(self, item)
def __setitem__(self, key, value):
return setattr(self, key, value)
def __add__(self, other):
new_stats = {attribute: self[attribute] + other[attribute] for attribute in stats_data.ATTRIBUTE_LIST}
return Stats(**new_stats)
def __sub__(self, other):
new_stats = {attribute: self[attribute] - other[attribute] for attribute in stats_data.ATTRIBUTE_LIST}
return Stats(**new_stats)
def __iter__(self):
yield from self.keys()
def keys(self):
return iter([attribute for attribute in stats_data.ATTRIBUTE_LIST if self[attribute] > 0])
def values(self):
return iter([self[attribute] for attribute in stats_data.ATTRIBUTE_LIST if self[attribute] > 0])
def items(self):
return iter([(attribute, self[attribute]) for attribute in stats_data.ATTRIBUTE_LIST if self[attribute] > 0])