-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinventory.py
109 lines (89 loc) · 3.05 KB
/
inventory.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
98
99
100
101
102
103
104
105
106
107
108
109
from config import *
from utils import *
import weapons
from collections import defaultdict
class Item():
def __init__(self, use):
# @param use: fcn reference
self.use = use
self.count = 1
class Ability():
# same as an Item but
def __init__(self, use):
# @param use: fcn reference
self.use = use
self.count = 1
class Inventory():
def __init__(self, parent):
self.parent = parent
self.items = {} # default item count: 0
self.hotkeys = {}
def add_item(self, item):
print("Adding item: {}".format(item.name))
if item.name in self.items:
self.items[item.name].count += 1
else:
self.items[item.name] = item
def use_item(self, name):
if name in self.items:
item = self.items[name]
if item.count > 0:
item.use(self.parent)
item.count -= 1
def set_hotkey(self, key, name):
self.hotkeys[key] = name
def has_item(self, name):
if name not in self.items or self.items[name].count < 1:
return False
else:
return True
class Potion(Item):
# potion
def __init__(self, amount):
# @param parent: gameObject who carries this item
# @param amount: amount to heal parent by
super().__init__(self.use_fcn)
self.amount = amount
self.name = "Potion"
def use_fcn(self, parent):
# increase parent's health by amount, but no more than max health
val = np.min([parent.attacker.health + self.amount, parent.attacker.max_health])
parent.attacker.health = val
print(parent.objectType+" used potion")
# play sound
pass
class GoldKey(Item):
# potion
def __init__(self, door_id):
# @param parent: gameObject who carries this item
# @param amount: amount to heal parent by
super().__init__(self.use_fcn)
self.door_id = door_id
self.name = "GoldKey"
def use_fcn(self, parent):
print(parent.objectType+" used {}".format(self.name))
# find doors within reach
rect = parent.reach_rect.convert_to_pygame_rect()
gos = get_game_objects()
go_tree = DATA["game_object_tree"]
hits = go_tree.hit(rect)
gos = {go.id: go for go in hits}
for id in gos:
go = gos[id]
if not hasattr(go, "door_id"):
continue
# if id matches, unlock the door by destroying the GO
if self.door_id == go.door_id:
MESSAGES.put(make_del_msg(go))
class Boss1Weapon1(Item):
def __init__(self):
super().__init__(self.use_fcn)
self.name = "Boss1Weapon1"
def use_fcn(self, parent):
parent.attacker.change_weapon(weapons.ballOnChainFCT)
class Boss1Weapon2(Item):
def __init__(self):
super().__init__(self.use_fcn)
self.name = "Boss1Weapon2"
def use_fcn(self, parent):
parent.attacker.change_weapon(weapons.spreadShotBoss1Phase3)