-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathitems.py
97 lines (85 loc) · 3.32 KB
/
items.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from typing import Optional
from pss_api import PSSApi
import cloudpickle as pickle
import os
class Items:
PRICE_CORRECTIONS = {
"Starburst Bulwark": 700,
"Immensity Gauntlet": 700,
"Rocket Pig": 600,
"King Husky": 600,
}
def __init__(self, data_path, api: PSSApi):
self._filename = os.path.join(data_path, "items", f"df")
self._api = api
self._items: Optional[Items] = None
async def setup(self):
if os.path.exists(self._filename):
with open(self._filename, "rb") as infile:
self._items = pickle.load(infile)
else:
self._items = await self._api.get_items()
os.makedirs(os.path.dirname(self._filename), exist_ok=True)
with open(self._filename, "wb") as outfile:
pickle.dump(self._items, outfile)
def get_design_id_by_name(self, name: str) -> Optional[int]:
try:
return int(self._items[self._items["ItemDesignName"] == name].iloc[0]['ItemDesignId'])
except:
return None
def get_name_by_design_id(self, design_id: int) -> Optional[str]:
try:
return self._items[self._items["ItemDesignId"] == design_id].iloc[0]['ItemDesignName']
except:
return None
def get_market_price(self, design_id: int) -> Optional[int]:
name = self.get_name_by_design_id(design_id)
if name is None:
return None
else:
if name in self.PRICE_CORRECTIONS:
return self.PRICE_CORRECTIONS[name]
else:
try:
return self._items[self._items["ItemDesignId"] == design_id].iloc[0]["MarketPrice"]
except:
return None
def get_rarity(self, design_id: int) -> Optional[str]:
name = self.get_name_by_design_id(design_id)
if name is None:
return None
else:
try:
return self._items[self._items["ItemDesignId"] == design_id].iloc[0]["Rarity"]
except:
return None
def get_subtype(self, design_id: int) -> Optional[str]:
name = self.get_name_by_design_id(design_id)
if name is None:
return None
else:
try:
return self._items[self._items["ItemDesignId"] == design_id].iloc[0]["ItemSubType"]
except:
return None
def get_main_stat(self, design_id: int):
name = self.get_name_by_design_id(design_id)
if name is None:
return None
else:
try:
return self._items[self._items["ItemDesignId"] == design_id].iloc[0]["EnhancementType"]
except:
return None
def item_can_have_substats(self, design_id: int) -> Optional[str]:
rarity = self.get_rarity(design_id)
subtype = self.get_subtype(design_id)
return "Equipment" in subtype and rarity in ("Hero", "Special", "Legendary")
def get_enhancement(self, design_id: int) -> (Optional[str], Optional[float]):
row = self._items[self._items["ItemDesignId"] == design_id].iloc[0]
type = row.EnhancementType
if 'None' in type:
return None, None
else:
value = float(row.EnhancementValue)
return type, value