def __init__(self): super(self.__class__, self).__init__(Wearable) self.slots = Cube(Slot) for n in SLOTS: sl = Slot(n, SLOTS[n]) #print sl self.slots.add(sl)
class Doll(Cube): def __init__(self): super(self.__class__, self).__init__(Wearable) self.slots = Cube(Slot) for n in SLOTS: sl = Slot(n, SLOTS[n]) #print sl self.slots.add(sl) #for s in self.slots.elements: #print s.name #for n in MSLOTS: #self.slots.add(MultiSlot(n)) #self.slots.add(slot_Ring()) #TODO: Ring Slots def regInv(self, inv): self.inv = inv inv.onAdd = self._inv_onAdd inv.refresh() def wear(self, item): if item.check(self.hero): slot = self.slots.itemBy('name', item.slot_name) if slot.add(item): self.addTrig(item, 'onHero') return self.elements else: #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #slot.has_item=False #self.removeTrig(slot.item,'onHero') #del slot.item #return item.wear() #print 'ooops' self.error = '<item> [%s] can`t wear. Slot is full.' % item return False #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! else: self.error = '<item> [%s] can`t wear. Check failed' % item return False def unwear(self, item): slot = self.slots.itemBy('name', item.slot_name) slot.has_item = False self.removeTrig(item, 'onHero') del slot.item return self.elements def onAdd(self, item): item.unwear = lambda: self.unwear(item) item.effect(self.hero) def onRemove(self, item): item.unEffect(self.hero) del item.unwear def _inv_onAdd(self, item): item.drop = lambda: self.inv.removeTrig(item, 'inInv') if issubclass(item.__class__, Wearable): item.wear = lambda: self.wear(item)