-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitems.py
More file actions
83 lines (66 loc) · 2.54 KB
/
items.py
File metadata and controls
83 lines (66 loc) · 2.54 KB
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
import json
import os
import data
from constants import SC_EMOJI, UP_ARROW_EMOJI
items = []
class Item():
def __init__(self, item_dict):
self.name = item_dict["name"]
self.cost = item_dict.get("cost", None)
self.emoji = item_dict["emoji"]
self.description = item_dict["description"]
self.aliases = item_dict["aliases"]
self.shop_item = item_dict.get("shop_item", False)
self.type = item_dict.get("type", "standard")
self.boost_bonus = item_dict.get("boost", {}).get("bonus", None)
self.boost_max_bonus = item_dict.get("boost", {}).get("max_bonus", None)
self.boost_category = item_dict.get("boost", {}).get("category", None)
def can_be_in_shop(self):
return self.shop_item
def has_value(self):
return not self.cost is None
def is_booster(self):
return not self.boost_bonus is None
def get_shop_string(self):
# Brackets combine the multiple lines into one
return (
f'{self.emoji} **{self.name}** ─ {SC_EMOJI}{self.cost}' +
(f' ─ {UP_ARROW_EMOJI}**{self.boost_category.capitalize()}**' if self.boost_category else '') +
f'\n{self.description}\n\n'
)
def import_items():
global items
items = []
items_data = data.get_items()
for i in items_data:
items.append(Item(i))
def get_by_name(name):
global items
for i in items:
if name.lower() == i.name.lower() or name.lower() in i.aliases:
return i
return None
def get_player_boost(player_id, *categories):
"""Get a player boost for a specific category.
An output of 0 means a 0% bonus, 1 means an 100% boost.
"""
boost = 0
for name, amount in data.get_data(player_id, "inv", default_val={}).items():
item = get_by_name(name)
if item.is_booster():
if item.boost_category in categories:
boost += get_boost_from_item_amount(item, amount)
return boost
def get_boost_from_item_amount(item, amount):
"""Get the amount of boost a player gets from a specific item."""
if not item.is_booster():
return 0
boost = min(amount * item.boost_bonus, item.boost_max_bonus)
return boost
def get_player_boost_from_item(player_id, item):
"""Get the amount of boost a player gets from a specific item."""
if not item.is_booster():
return 0
amount = data.get_data(player_id, "inv", item.name, default_val=0)
boost = min(amount * item.boost_bonus, item.boost_max_bonus)
return boost