def checkKeyMatch(self, key): """ Check to see if the given key matches this object's lock. Raise a error.Failure if it does not. Override this method to implement different key-matching mechanisms; by default, I will check that one of the key's lockTypes is in my list of lockTypes. """ if not reflect.isinst(key, Key): error.Failure("That's not a key.") for type in key.lockTypes: if type in self.lockTypes: return error.Failure(key, " doesn't seem to fit.")
def verb_close(self, sentence): "I'm afraid I can't do that, dave." perp = sentence.subject() if not self.isOpen: error.Failure("It's already closed.") self.close(actor=perp) perp.hears("You close ", self, '.')
def verb_open(self, sentence): "Open the pod-bay doors, hal." perp = sentence.subject() if self.isOpen: error.Failure("It's already open.") self.open(actor=perp) perp.hears("You open ", self, '.')
def remove(self, actor): """ Remove a piece of clothing. """ self._remove(actor) if self.wearer: wearer = self.wearer clothes = self.wearer.clothing for location in self.clothing_slots: cloth = clothes[location][-1] if cloth is not self: raise error.Failure("You'd have to remove ", cloth, " first.") for location in self.clothing_slots: clothes[location].pop() self.component = 0 self.wearer = None wearer.describe('clothing', clothing_descript(wearer))
def checkLock(self): "raise an appropriate exception if this is locked." if self.locked: error.Failure(self, " is locked.")
def verb_close(self, sentence): sentence.shouldOnlyHave('') if not self.isOpen: error.Failure("It's already closed.") else: self.action_Close(sentence.subject)
def verb_open(self, sentence): sentence.shouldOnlyHave('') if self.isOpen: error.Failure("It's already open.") else: self.action_Open(sentence.subject)
def verb_put_in(self, sentence): sentence.shouldOnlyHave('', 'in') if self.isOpen: sentence.directObject().move(self.contents, sentence.subject) else: error.Failure("It's closed.")
def _open(self, actor): if not actor.wizbit: error.Failure(self, " just doesn't seem to budge.")
def verb_remove(self, sentence): if sentence.subject is not self.wearer: error.Failure("You're not wearing that.") self.remove(sentence.subject)
def verb_wear(self, sentence): if self.wearer: error.Failure("That's already being worn.") self.wear(sentence.subject)