def test_door_pair(self): loc1 = Location("room1", "room one") loc2 = Location("room2", "room two") key = Key("key") door_one_two = Door("two", loc2, "door to room two", locked=True, opened=False) door_two_one = door_one_two.reverse_door("one", loc1, "door to room one", reverse_open_msg="door one open", reverse_close_msg="door one close", this_open_msg="door two open", this_close_msg="door two close") loc1.add_exits([door_one_two]) loc2.add_exits([door_two_one]) door_one_two.key_code = 555 key.key_for(door_one_two) pubsub1 = PubsubCollector() pubsub2 = PubsubCollector() loc1.get_wiretap().subscribe(pubsub1) loc2.get_wiretap().subscribe(pubsub2) self.assertTrue(door_two_one.locked) self.assertFalse(door_two_one.opened) lucy = Living("lucy", "f") door_two_one.unlock(lucy, item=key) self.assertFalse(door_one_two.locked) door_two_one.open(lucy) self.assertTrue(door_one_two.opened) pubsub.sync() self.assertEqual(["door one open"], pubsub1.messages) self.assertEqual([], pubsub2.messages) door_one_two.close(lucy) door_one_two.lock(lucy, item=key) self.assertTrue(door_two_one.locked) self.assertFalse(door_two_one.opened) pubsub1.clear() pubsub2.clear() pubsub.sync() self.assertEqual([], pubsub1.messages) self.assertEqual(["door two close"], pubsub2.messages)
def test_door_pair(self): loc1 = Location("room1", "room one") loc2 = Location("room2", "room two") key = Key("key") door_one_two = Door("two", loc2, "door to room two", locked=True, opened=False) door_two_one = door_one_two.reverse_door( "one", loc1, "door to room one", reverse_open_msg="door one open", reverse_close_msg="door one close", this_open_msg="door two open", this_close_msg="door two close") loc1.add_exits([door_one_two]) loc2.add_exits([door_two_one]) door_one_two.key_code = 555 key.key_for(door_one_two) pubsub1 = PubsubCollector() pubsub2 = PubsubCollector() loc1.get_wiretap().subscribe(pubsub1) loc2.get_wiretap().subscribe(pubsub2) self.assertTrue(door_two_one.locked) self.assertFalse(door_two_one.opened) lucy = Living("lucy", "f") door_two_one.unlock(lucy, item=key) self.assertFalse(door_one_two.locked) door_two_one.open(lucy) self.assertTrue(door_one_two.opened) pubsub.sync() self.assertEqual(["door one open"], pubsub1.messages) self.assertEqual([], pubsub2.messages) door_one_two.close(lucy) door_one_two.lock(lucy, item=key) self.assertTrue(door_two_one.locked) self.assertFalse(door_two_one.opened) pubsub1.clear() pubsub2.clear() pubsub.sync() self.assertEqual([], pubsub1.messages) self.assertEqual(["door two close"], pubsub2.messages)
def rat_kick(self, ctx): rat = self.location.search_living("rat") if rat: self.do_socialize("kick rat") rat.do_socialize("recoil") direction = rat.select_random_move() if direction: rat.tell_others("{Title} runs away towards the door!") rat.move(direction.target, self) mud_context.driver.defer(2, self.rat_scream, "smile at " + self.name) customer = James( "James", "m", title="Sir James", description="Sir James is trying to sell something, it looks like a lamp.") lamp.add_extradesc({ "lamp" }, "The lamp looks quite old, but otherwise is rather unremarkable. There is something weird going on with the cord though!" ) lamp.add_extradesc({ "cord" }, "Even when the lamp doesn't move, the power cord keeps snaking around as if it were alive. How odd." ) customer.insert(lamp, customer) shop.insert(customer, shop) shop.get_wiretap().subscribe(customer)
class James(NPC, Listener): """The customer trying to sell a Lamp, and helpful as rat deterrent.""" def pubsub_event(self, topicname, event): if topicname[0] == "wiretap-location": if "Rat arrives" in event[1]: mud_context.driver.defer(2, self.rat_scream, "frown") mud_context.driver.defer(4, self.rat_kick) def rat_scream(self, action, ctx): shopkeeper.do_socialize(action) def rat_kick(self, ctx): rat = self.location.search_living("rat") if rat: self.do_socialize("kick rat") rat.do_socialize("recoil") direction = rat.select_random_move() if direction: rat.tell_others("{Title} runs away towards the door!") rat.move(direction.target, self) mud_context.driver.defer(2, self.rat_scream, "smile at " + self.name) customer = James("James", "m", title="Sir James", description="Sir James is trying to sell something, it looks like a lamp.") lamp.add_extradesc({"lamp"}, "The lamp looks quite old, but otherwise is rather unremarkable. There is something weird going on with the cord though!") lamp.add_extradesc({"cord"}, "Even when the lamp doesn't move, the power cord keeps snaking around as if it were alive. How odd.") customer.insert(lamp, customer) shop.insert(customer, shop) shop.get_wiretap().subscribe(customer)