forked from OoTRandomizer/OoT-Randomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Item.py
180 lines (129 loc) · 4.74 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
from ItemList import item_table
class ItemInfo(object):
items = {}
events = {}
bottles = set()
def __init__(self, name='', event=False):
if event:
type = 'Event'
progressive = True
itemID = None
special = None
else:
(type, progressive, itemID, special) = item_table[name]
self.name = name
self.advancement = (progressive == True)
self.priority = (progressive == False)
self.type = type
self.special = special or {}
self.index = itemID
self.price = self.special.get('price')
self.bottle = self.special.get('bottle', False)
@staticmethod
def isBottle(name):
return name in ItemInfo.bottles
for item_name in item_table:
ItemInfo.items[item_name] = ItemInfo(item_name)
if ItemInfo.items[item_name].bottle:
ItemInfo.bottles.add(item_name)
class Item(object):
def __init__(self, name='', world=None, event=False):
self.name = name
self.location = None
self.event = event
if event:
if name not in ItemInfo.events:
ItemInfo.events[name] = ItemInfo(name, event=True)
self.info = ItemInfo.events[name]
else:
self.info = ItemInfo.items[name]
self.price = self.info.special.get('price')
self.world = world
self.looks_like_item = None
self.advancement = self.info.advancement
self.priority = self.info.priority
self.type = self.info.type
self.special = self.info.special
self.index = self.info.index
item_worlds_to_fix = {}
def copy(self, new_world=None):
if new_world is not None and self.world is not None and new_world.id != self.world.id:
new_world = None
new_item = Item(self.name, new_world, self.event)
new_item.price = self.price
if new_world is None and self.world is not None:
Item.item_worlds_to_fix[new_item] = self.world.id
return new_item
@classmethod
def fix_worlds_after_copy(cls, worlds):
items_fixed = []
for item, world_id in cls.item_worlds_to_fix.items():
item.world = worlds[world_id]
items_fixed.append(item)
for item in items_fixed:
del cls.item_worlds_to_fix[item]
@property
def key(self):
return self.smallkey or self.bosskey
@property
def smallkey(self):
return self.type == 'SmallKey' or self.type == 'FortressSmallKey'
@property
def bosskey(self):
return self.type == 'BossKey'
@property
def map(self):
return self.type == 'Map'
@property
def compass(self):
return self.type == 'Compass'
@property
def dungeonitem(self):
return self.smallkey or self.bosskey or self.map or self.compass
@property
def majoritem(self):
if self.type == 'Token':
return self.world.bridge == 'tokens'
if self.type in ('Drop', 'Event', 'Shop', 'DungeonReward') or not self.advancement:
return False
if self.name.startswith('Bombchus') and not self.world.bombchus_in_logic:
return False
if self.map or self.compass:
return False
if self.smallkey and self.world.shuffle_smallkeys in ['dungeon', 'vanilla']:
return False
if self.bosskey and not self.name.endswith('(Ganons Castle)') and self.world.shuffle_bosskeys in ['dungeon', 'vanilla']:
return False
if self.bosskey and self.name.endswith('(Ganons Castle)') and self.world.shuffle_ganon_bosskey in ['dungeon', 'vanilla']:
return False
return True
def __str__(self):
return str(self.__unicode__())
def __unicode__(self):
return '%s' % self.name
def ItemFactory(items, world=None, event=False):
if isinstance(items, str):
if not event and items not in ItemInfo.items:
raise KeyError('Unknown Item: %s' % items)
return Item(items, world, event)
ret = []
for item in items:
if not event and item not in ItemInfo.items:
raise KeyError('Unknown Item: %s' % item)
ret.append(Item(item, world, event))
return ret
def MakeEventItem(name, location):
item = ItemFactory(name, location.world, event=True)
location.world.push_item(location, item)
location.locked = True
if name not in item_table:
location.internal = True
location.world.event_items.add(name)
return item
def IsItem(name):
return name in item_table
def ItemIterator(predicate=lambda loc: True, world=None):
for item_name in item_table:
item = ItemFactory(item_name, world)
if predicate(item):
yield item