Wrote a fix for the Python path detection issue, uses multiple registry sources now
[craw.git] / script / item_rule.py
blob7181dded337efdb0f6489f675b980c48cdf65475
1 import item_handler, types
2 from item_groups import item_groups
4 class item_rule:
5 def __init__(self, item_type = None, group = None, quality = None, ethereal = None, sockets = None, level = None):
6 quality = item_rule.listify(quality)
7 sockets = item_rule.listify(sockets)
8 self.item_type = item_type
9 self.group = group
10 self.quality = quality
11 self.ethereal = ethereal
12 self.sockets = sockets
13 self.level = level
15 self.debug_mode = False
17 @staticmethod
18 def listify(input):
19 if type(input) == types.IntType:
20 return [input]
21 else:
22 return input
24 def debug(self, text):
25 if self.debug_mode:
26 print text
28 def applies_to(self, item):
29 if self.group != None:
30 try:
31 item_types = item_groups[self.group]
32 except KeyError:
33 print 'Unable to find item group "%s"' % self.group
34 return False
36 if item.type not in item_types:
37 self.debug('Group rejection for %s: "%s" (%s)' % (item.type, self.group, item_types))
38 return False
40 elif self.item_type != None and self.item_type != item.type:
41 self.debug('Type rejection: %s != %s' % (self.item_type, item.type))
42 return False
44 if self.quality != None and item.quality not in self.quality:
45 self.debug('Quality rejection: %s not in %s' % (item.quality, self.quality))
46 return False
48 elif self.ethereal != None and self.ethereal != item.ethereal:
49 self.debug('Ethereal rejection: %s != %s' % (self.ethereal, item.ethereal))
50 return False
52 elif self.sockets != None and item.sockets not in self.sockets:
53 self.debug('Socket rejection: %d not in %s' % (item.sockets, self.sockets))
54 return False
56 elif self.level != None and item.level < self.level:
57 self.debug('Level rejection: %d < %d' % (item.level, self.level))
58 return False
60 self.debug('Item rule success')
62 return True