Ejemplo n.º 1
0
 def handle_verb(self, parsed: ParseResult, actor: Living) -> bool:
     if parsed.verb == "hack":
         if self in parsed.who_info:
             actor.tell(
                 "It doesn't need to be hacked, you can just type commands on it."
             )
             return True
         elif parsed.who_info:
             raise ActionRefused("You can't hack that.")
         else:
             raise ActionRefused("What do you want to hack?")
     if parsed.verb in ("type", "enter"):
         if parsed.who_info and self not in parsed.who_info:
             raise ActionRefused("You need to type it on the computer.")
         if parsed.message:
             # type "bla bla" on computer (message between quotes)
             action, _, door = parsed.message.partition(" ")
             self.process_typed_command(action, door, actor)
             return True
         args = list(parsed.args)
         if self.name in args:
             args.remove(self.name)
         for name in self.aliases:
             if name in args:
                 args.remove(name)
         if args:
             args.append("")
             self.process_typed_command(args[0], args[1], actor)
             return True
     return False
Ejemplo n.º 2
0
Archivo: npcs.py Proyecto: irmen/Tale
 def handle_verb(self, parsed: ParseResult, actor: Living) -> bool:
     pills = self.search_item("pills", include_location=False)
     if parsed.verb in ("bargain", "haggle"):
         if not parsed.args:
             raise ParseError("For how much money do you want to haggle?")
         if not pills:
             raise ActionRefused("It is no longer available for sale.")
         amount = mud_context.driver.moneyfmt.parse(parsed.args)
         price = mud_context.driver.moneyfmt.display(self.pills_price)
         if amount < self.pills_price / 2:
             actor.tell("%s glares angrily at you and says, \"No way! I want at least half the original price! "
                        "Did't I tell you? They were %s!\"" % (lang.capital(self.title), price))
             raise ActionRefused()
         self.do_buy_pills(actor, pills, amount)
         return True
     if parsed.verb == "buy":
         if not parsed.args:
             raise ParseError("Buy what?")
         if "pills" in parsed.args or "bottle" in parsed.args or "medicine" in parsed.args:
             if not pills:
                 raise ActionRefused("It is no longer available for sale.")
             self.do_buy_pills(actor, pills, self.pills_price)
             return True
         if pills:
             raise ParseError("There's nothing left to buy in the shop, except for the pills the apothecary is holding.")
         else:
             raise ParseError("There's nothing left to buy.")
     return False
Ejemplo n.º 3
0
 def notify_moved(self, source_container: ContainingType,
                  target_container: ContainingType, actor: Living) -> None:
     if isinstance(actor, Player):
         actor.tell(
             "You try to pick up the orb, but as soon as you touch it it ends this game!"
         )
         raise StoryCompleted
Ejemplo n.º 4
0
Archivo: town.py Proyecto: irmen/Tale
 def process_typed_command(self, command: str, doorname: str, actor: Living) -> None:
     if command == "help":
         message = "KNOWN COMMANDS: LOCK, UNLOCK"
     elif command in ("hi", "hello"):
         message = "GREETINGS, PROFESSOR FALKEN."
     elif command in ("unlock", "lock"):
         try:
             door = self.location.exits[doorname]
         except KeyError:
             message = "UNKNOWN DOOR"
         else:
             if not isinstance(door, Door):
                 message = "THAT IS NOT THE NAME OF A DOOR"
             else:
                 if command == "unlock":
                     if door.locked:
                         door.locked = False
                         message = doorname.upper() + " UNLOCKED"
                     else:
                         message = "COMMAND INVALID - DOOR ALREADY UNLOCKED"
                 else:
                     if door.locked:
                         message = "COMMAND INVALID - DOOR ALREADY LOCKED"
                     else:
                         door.locked = True
                         message = doorname.upper() + " LOCKED"
     else:
         message = "INVALID COMMAND"
     actor.tell("The computer beeps quietly. The screen shows: \"%s\"" % message)
Ejemplo n.º 5
0
 def handle_verb(self, parsed: ParseResult, actor: Living) -> bool:
     pills = self.search_item("pills", include_location=False)
     if parsed.verb in ("bargain", "haggle"):
         if not parsed.args:
             raise ParseError("For how much money do you want to haggle?")
         if not pills:
             raise ActionRefused("It is no longer available for sale.")
         amount = mud_context.driver.moneyfmt.parse(parsed.args)
         price = mud_context.driver.moneyfmt.display(self.pills_price)
         if amount < self.pills_price / 2:
             actor.tell(
                 "%s glares angrily at you and says, \"No way! I want at least half the original price! "
                 "Did't I tell you? They were %s!\"" %
                 (lang.capital(self.title), price))
             raise ActionRefused()
         self.do_buy_pills(actor, pills, amount)
         return True
     if parsed.verb == "buy":
         if not parsed.args:
             raise ParseError("Buy what?")
         if "pills" in parsed.args or "bottle" in parsed.args or "medicine" in parsed.args:
             if not pills:
                 raise ActionRefused("It is no longer available for sale.")
             self.do_buy_pills(actor, pills, self.pills_price)
             return True
         if pills:
             raise ParseError(
                 "There's nothing left to buy in the shop, except for the pills the apothecary is holding."
             )
         else:
             raise ParseError("There's nothing left to buy.")
     return False
Ejemplo n.º 6
0
Archivo: town.py Proyecto: irmen/Tale
 def handle_verb(self, parsed: ParseResult, actor: Living) -> bool:
     if parsed.verb == "hack":
         if self in parsed.who_info:
             actor.tell("It doesn't need to be hacked, you can just type commands on it.")
             return True
         elif parsed.who_info:
             raise ActionRefused("You can't hack that.")
         else:
             raise ActionRefused("What do you want to hack?")
     if parsed.verb in ("type", "enter"):
         if parsed.who_info and self not in parsed.who_info:
             raise ActionRefused("You need to type it on the computer.")
         if parsed.message:
             # type "bla bla" on computer (message between quotes)
             action, _, door = parsed.message.partition(" ")
             self.process_typed_command(action, door, actor)
             return True
         args = list(parsed.args)
         if self.name in args:
             args.remove(self.name)
         for name in self.aliases:
             if name in args:
                 args.remove(name)
         if args:
             args.append("")
             self.process_typed_command(args[0], args[1], actor)
             return True
     return False
Ejemplo n.º 7
0
 def process_typed_command(self, command: str, doorname: str,
                           actor: Living) -> None:
     if command == "help":
         message = "KNOWN COMMANDS: LOCK, UNLOCK"
     elif command in ("hi", "hello"):
         message = "GREETINGS, PROFESSOR FALKEN."
     elif command in ("unlock", "lock"):
         try:
             door = self.location.exits[doorname]
         except KeyError:
             message = "UNKNOWN DOOR"
         else:
             if not isinstance(door, Door):
                 message = "THAT IS NOT THE NAME OF A DOOR"
             else:
                 if command == "unlock":
                     if door.locked:
                         door.locked = False
                         message = doorname.upper() + " UNLOCKED"
                     else:
                         message = "COMMAND INVALID - DOOR ALREADY UNLOCKED"
                 else:
                     if door.locked:
                         message = "COMMAND INVALID - DOOR ALREADY LOCKED"
                     else:
                         door.locked = True
                         message = doorname.upper() + " LOCKED"
     else:
         message = "INVALID COMMAND"
     actor.tell("The computer beeps quietly. The screen shows: \"%s\"" %
                message)
Ejemplo n.º 8
0
 def test_tell(self):
     julie = Living("julie", "f", race="human")
     tap = julie.get_wiretap()
     collector = PubsubCollector()
     tap.subscribe(collector)
     julie.tell("msg1", "msg2")
     julie.tell("msg3", "msg4", ignored_arg=42)
     self.assertEqual(["msg1", "msg2", "msg3", "msg4"], collector.messages)
Ejemplo n.º 9
0
 def test_tell(self):
     julie = Living("julie", "f", race="human")
     tap = julie.get_wiretap()
     collector = PubsubCollector()
     tap.subscribe(collector)
     julie.tell("msg1", "msg2")
     julie.tell("msg3", "msg4", ignored_arg=42)
     pubsub.sync()
     self.assertEqual(["msg1 msg2", "msg3 msg4"], collector.messages)
Ejemplo n.º 10
0
Archivo: npcs.py Proyecto: irmen/Tale
 def do_buy_pills(self, actor: Living, pills: Item, price: float) -> None:
     if actor.money < price:
         raise ActionRefused("You don't have enough money!")
     actor.money -= price
     self.money += price
     pills.move(actor, self)
     price_str = mud_context.driver.moneyfmt.display(price)
     actor.tell("After handing %s the %s, %s gives you the %s." % (self.objective, price_str, self.subjective, pills.title))
     self.tell_others("{Actor} says: \"Here's your medicine, now get out of here!\"")
Ejemplo n.º 11
0
 def do_buy_ammo(self, actor: Living, ammo: Item, price: float) -> None:
     if actor.money < price:
         raise ActionRefused("You don't have enough money!")
     actor.money -= price
     self.money += price
     ammo.move(actor, self)
     price_str = mud_context.driver.moneyfmt.display(price)
     actor.tell("After handing %s the %s, %s gives you the %s." % (self.objective, price_str, self.subjective, ammo.title))
     self.tell_others("{Actor} says: \"Here's your ammo, now get out of here!\"")
Ejemplo n.º 12
0
 def notify_action(self, parsed: ParseResult, actor: Living) -> None:
     if actor is self or parsed.verb in self.verbs:
         return  # avoid reacting to ourselves, or reacting to verbs we already have a handler for
     if parsed.verb in ("hello", "hi"):
         self.process_typed_command("hello", "", actor)
     elif parsed.verb in ("say", "yell"):
         if "hi" in parsed.args or "hello" in parsed.args:
             self.process_typed_command("hello", "", actor)
         else:
             actor.tell("The computer beeps quietly. The screen shows: "
                        "\"I CAN'T HEAR YOU. PLEASE TYPE COMMANDS INSTEAD OF SPEAKING.\"  How odd.")
Ejemplo n.º 13
0
Archivo: npcs.py Proyecto: irmen/Tale
 def notify_action(self, parsed: ParseResult, actor: Living) -> None:
     if actor is self or parsed.verb in self.verbs:
         return  # avoid reacting to ourselves, or reacting to verbs we already have a handler for
     # react on mentioning the medicine
     if "medicine" in parsed.unparsed or "pills" in parsed.unparsed or "bottle" in parsed.unparsed:
         if self.search_item("pills", include_location=False):  # do we still have the pills?
             price = mud_context.driver.moneyfmt.display(self.pills_price)
             self.tell_others("{Actor} clenches the bottle %s's holding even tighter. %s says: "
                              "\"You won't get them for free! They will cost you %s!\""
                              % (self.subjective, lang.capital(self.subjective), price))
         else:
             self.tell_others("{Actor} says: \"Good luck with it!\"")
     if random.random() < 0.5:
         actor.tell("%s glares at you." % lang.capital(self.title))
Ejemplo n.º 14
0
 def notify_action(self, parsed: ParseResult, actor: Living) -> None:
     if actor is self or parsed.verb in self.verbs:
         return  # avoid reacting to ourselves, or reacting to verbs we already have a handler for
     # react on mentioning the medicine
     if "bullets" in parsed.unparsed or "ammo" in parsed.unparsed:
         if self.search_item("ammo", include_location=False):  # do we still have the ammo?
             price = mud_context.driver.moneyfmt.display(self.ammo_price)
             self.tell_others("{Actor} clenches bof of %s's holding even tighter. %s says: "
                              "\"You won't get them for free! They will cost you %s!\""
                              % (self.subjective, lang.capital(self.subjective), price))
         else:
             self.tell_others("{Actor} says: \"Good luck with it!\"")
     if random.random() < 0.5:
         actor.tell("%s glares at you." % lang.capital(self.title))
Ejemplo n.º 15
0
 def handle_verb(self, parsed: ParseResult, actor: Living) -> bool:
     if parsed.verb == "list":
         pets = self.get_pets()
         actor.tell("Available pets at the moment are:", end=True)
         txt = ["<ul>  pet            <dim>|</><ul> price     </>"]
         for i, (pet, price) in enumerate(pets.items(), start=1):
             txt.append("  %-15s  %s" % (pet.name, mud_context.driver.moneyfmt.display(price)))
         actor.tell("\n".join(txt), format=False)
         return True
     elif parsed.verb == "buy":
         if not parsed.args:
             raise ActionRefused("Buy which pet? Don't forget to name it as well (optional).")
         pets = self.get_pets()
         for pet, price in pets.items():
             if pet.name == parsed.args[0].lower():
                 pet = make_mob(pet.circle_vnum, type(pet))
                 if price > actor.money:
                     raise ActionRefused("You can't afford that pet.")
                 if len(parsed.args) == 2:
                     name = parsed.args[1].lower()
                     pet.title = "%s %s" % (pet.name, lang.capital(name))
                     pet.description += " A small sign on a chain around the neck says 'My name is %s'." % lang.capital(name)
                     pet.aliases.add(pet.name)
                     pet.name = name
                 pet.following = actor   # @todo make pet charmed as well (see circle doc/src)
                 pet.is_pet = True
                 actor.money -= price
                 actor.tell_others("{Actor} buys %s as a pet." % pet.title)
                 actor.tell("You paid %s and received %s as your new pet. Happy times!"
                            % (mud_context.driver.moneyfmt.display(price), pet.title))
                 pet.move(actor.location, pet)
                 return True
         raise ActionRefused("There is no such pet!")
     else:
         return super().handle_verb(parsed, actor)
Ejemplo n.º 16
0
 def handle_verb(self, parsed: ParseResult, actor: Living) -> bool:
     if parsed.verb == "list":
         pets = self.get_pets()
         actor.tell("Available pets at the moment are:", end=True)
         txt = ["<ul>  pet            <dim>|</><ul> price     </>"]
         for i, (pet, price) in enumerate(pets.items(), start=1):
             txt.append("  %-15s  %s" % (pet.name, mud_context.driver.moneyfmt.display(price)))
         actor.tell("\n".join(txt), format=False)
         return True
     elif parsed.verb == "buy":
         if not parsed.args:
             raise ActionRefused("Buy which pet? Don't forget to name it as well (optional).")
         pets = self.get_pets()
         for pet, price in pets.items():
             if pet.name == parsed.args[0].lower():
                 pet = make_mob(pet.circle_vnum, type(pet))
                 if price > actor.money:
                     raise ActionRefused("You can't afford that pet.")
                 if len(parsed.args) == 2:
                     name = parsed.args[1].lower()
                     pet.title = "%s %s" % (pet.name, lang.capital(name))
                     pet.description += " A small sign on a chain around the neck says 'My name is %s'." % lang.capital(name)
                     pet.aliases.add(pet.name)
                     pet.name = name
                 pet.following = actor   # @todo make pet charmed as well (see circle doc/src)
                 pet.is_pet = True
                 actor.money -= price
                 actor.tell_others("{Actor} buys %s as a pet." % pet.title)
                 actor.tell("You paid %s and received %s as your new pet. Happy times!"
                            % (mud_context.driver.moneyfmt.display(price), pet.title))
                 pet.move(actor.location, pet)
                 return True
         raise ActionRefused("There is no such pet!")
     else:
         return super().handle_verb(parsed, actor)
Ejemplo n.º 17
0
 def test_wiretap(self):
     attic = Location("Attic", "A dark attic.")
     player = Player("fritz", "m")
     io = ConsoleIo(None)
     io.supports_smartquotes = False
     pc = PlayerConnection(player, io)
     player.set_screen_sizes(0, 100)
     julie = Living("julie", "f")
     julie.move(attic)
     player.move(attic)
     julie.tell("message for julie")
     attic.tell("message for room")
     self.assertEqual(["message for room\n"],
                      player.test_get_output_paragraphs())
     with self.assertRaises(ActionRefused):
         player.create_wiretap(julie)
     player.privileges = {"wizard"}
     player.create_wiretap(julie)
     player.create_wiretap(attic)
     julie.tell("message for julie")
     attic.tell("message for room")
     pubsub.sync()
     output = pc.get_output()
     self.assertTrue(
         "[wiretapped from `Attic': message for room]" in output)
     self.assertTrue(
         "[wiretapped from `julie': message for julie]" in output)
     self.assertTrue(
         "[wiretapped from `julie': message for room]" in output)
     self.assertTrue("message for room " in output)
     # test removing the wiretaps
     player.clear_wiretaps()
     import gc
     gc.collect()
     julie.tell("message for julie")
     attic.tell("message for room")
     self.assertEqual(["message for room\n"],
                      player.test_get_output_paragraphs())
Ejemplo n.º 18
0
Archivo: town.py Proyecto: irmen/Tale
 def read(self, actor: Living) -> None:
     actor.tell(self.screen_text())
Ejemplo n.º 19
0
 def allow_passage(self, actor: Living) -> None:
     if "wizard" in actor.privileges:
         actor.tell("You pass through the force-field.", end=True)
     else:
         raise ActionRefused(
             "You can't go that way, the force-field is impenetrable.")
Ejemplo n.º 20
0
Archivo: town.py Proyecto: irmen/Tale
 def allow_passage(self, actor: Living) -> None:
     if "wizard" in actor.privileges:
         actor.tell("You pass through the force-field.", end=True)
     else:
         raise ActionRefused("You can't go that way, the force-field is impenetrable.")
Ejemplo n.º 21
0
 def read(self, actor: Living) -> None:
     actor.tell(self.screen_text())