-
Notifications
You must be signed in to change notification settings - Fork 1
/
item.py
88 lines (67 loc) · 1.99 KB
/
item.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
class Item:
def __init__(self, unique_id, template):
"""Initializes item data"""
self.uuid = unique_id
self.id = template["id"]
self.name = template["name"]
self.sprite_filename = template["sprite_filename"]
self.bulk = template["bulk"]
self.weight = template["weight"]
self.x = 0.0
self.y = 0.0
self.owner = None
self.redraw = True
def __eq__(self, other):
if isinstance(other, Item):
return self.uuid == other.uuid
else:
return False
def init_for_sim(self, **kwargs):
self.x = kwargs["x"] + 0.5
self.y = kwargs["y"] + 0.5
self.owner = None
def get_uuid(self):
return self.uuid
def get_template_id(self):
return self.id
def get_x(self):
return self.x
def set_x(self, x):
self.x = x
def get_y(self):
return self.y
def set_y(self, y):
self.y = y
def get_cell_x(self):
return int(self.x)
def get_cell_y(self):
return int(self.y)
def get_within_cell_x(self):
return self.x - int(self.x)
def get_within_cell_y(self):
return self.y - int(self.y)
def get_name(self):
return self.name
def get_sprite_filename(self):
return self.sprite_filename
def get_draw_data(self):
"""Get draw data"""
return {
"uuid": self.uuid,
"x": self.get_cell_x(),
"y": self.get_cell_y(),
"name": self.name,
"redraw": self.redraw,
"sprite_filename": self.sprite_filename,
"sprite_type": "item"
}
def take_item(self, owner):
"""Assigns owner that has taken item"""
self.owner = owner
def drop_item(self):
"""De-assigns owner that has dropped item"""
self.owner = None
def get_redraw(self):
return self.redraw
def set_redraw(self, redraw):
self.redraw = redraw