示例#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
示例#2
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)
示例#3
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
示例#4
0
 def allow_give_item(self, item: Item, actor: Optional[Living]) -> None:
     if item.name == "pills":
         self.do_socialize(
             "say \"Keep the bottle with you, I'll ask when I need it. Let us just leave from this place!\""
         )
         raise ActionRefused()
     else:
         raise ActionRefused("%s doesn't want %s." %
                             (lang.capital(self.title), item.title))
示例#5
0
 def handle_verb(self, parsed: ParseResult, actor: Living) -> bool:
     if parsed.verb in ("drive", "open", "enter", "sit", "use", "start"):
         if not parsed.args:
             raise ParseError("%s what?" % parsed.verb)
         if "yellow" not in parsed.args and "convertible" not in parsed.args:
             if "car" in parsed.args or "engine" in parsed.args:
                 raise ActionRefused("Most of the cars are locked. You should look for one that isn't.")
             raise ActionRefused("You cannot do that.")
         # check if Peter is with you
         if not self.search_living("Peter"):
             raise ActionRefused("Surely you wouldn't leave the town without your friend Peter! "
                                 "You should find him and get out here together!")
         # player drives the yellow car away from here together with her friend Peter, and thus the story ends!
         actor.tell_text_file(mud_context.resources["messages/completion_success.txt"])  # type: ignore
         raise StoryCompleted
     return False
示例#6
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!\"")
示例#7
0
文件: __init__.py 项目: zaghaghi/Tale
def go_cvnum(player: Player, parsed: ParseResult, ctx: util.Context) -> None:
    """Go to a specific circlemud room, given by its circle-vnum."""
    if len(parsed.args) != 1:
        raise ParseError("You have to give the rooms' circle-vnum.")
    vnum = int(parsed.args[0])
    try:
        room = make_location(vnum)
    except KeyError:
        raise ActionRefused("No room with that circle-vnum exists.")
    teleport_to(player, room)
示例#8
0
 def move(self,
          target: ContainingType,
          actor: Living = None,
          *,
          silent: bool = False,
          is_player: bool = False,
          verb: str = "move",
          direction_names: Sequence[str] = None) -> None:
     if self.contained_in is actor and "wizard" not in actor.privileges:
         raise ActionRefused(
             "The gem is cursed! It sticks to your hand, you can't get rid of it!"
         )
     super().move(target, actor, verb=verb)
示例#9
0
文件: __init__.py 项目: skirtap/Tale
def go_vnum(player, parsed, ctx):
    """Go to a specific circlemud room, given by its vnum."""
    if len(parsed.args) != 1:
        raise ParseError("You have to give the rooms' vnum.")
    vnum = int(parsed.args[0])
    try:
        room = make_location(vnum)
    except KeyError:
        raise ActionRefused("No room with that vnum exists.")
    player.tell("Teleporting to room", room, "...")
    player.tell("\n")
    player.move(room, actor=player)
    player.look()
示例#10
0
    def handle_verb(self, parsed: ParseResult, actor: Living) -> bool:
        ammo = self.search_item("ammo", include_location=False)

        if parsed.verb == "buy":
            if not parsed.args:
                raise ParseError("Buy what?")
            if "ammo" in parsed.args or "bullets" in parsed.args:
                if not ammo:
                    raise ActionRefused("It is no longer available for sale.")
                self.do_buy_ammo(actor, ammo, self.ammo_price)
                return True
            if ammo:
                raise ParseError("The trader has ammo for your gun.")
            else:
                raise ParseError("There's nothing left to buy.")
        return False
示例#11
0
文件: __init__.py 项目: zaghaghi/Tale
def show_cvnum(player: Player, parsed: ParseResult, ctx: util.Context) -> None:
    """Show the circle-vnum of a location (.) or an object/living,
    or when you provide a circle-vnum as arg, show the object(s) with that circle-vnum."""
    if not parsed.args:
        raise ParseError("From what should I show the circle-vnum?")
    name = parsed.args[0]
    obj = None  # type: Union[Location, Living, Item, Exit]
    if name == ".":
        obj = player.location
    elif parsed.who_info:
        obj = parsed.who_1
    else:
        try:
            vnum = int(parsed.args[0])
        except ValueError as x:
            raise ActionRefused(str(x))
        objects = []   # type: List[Union[Location, Living, Item, Exit]]
        try:
            objects.append(make_item(vnum))
        except KeyError:
            pass
        try:
            objects.append(make_location(vnum))
        except KeyError:
            pass
        try:
            objects.append(make_mob(vnum))
        except KeyError:
            pass
        player.tell("Objects with circle-vnum %d:" % vnum + " " + (lang.join(str(o) for o in objects) or "none"))
        return
    try:
        vnum = obj.circle_vnum
        player.tell("Circle-Vnum of %s = %d." % (obj, vnum))
    except AttributeError:
        player.tell(str(obj) + " has no circle-vnum.")
示例#12
0
文件: __init__.py 项目: skirtap/Tale
def show_vnum(player, parsed, ctx):
    """Show the vnum of a location (.) or an object/living,
    or when you provide a vnum as arg, show the object(s) with that vnum."""
    if not parsed.args:
        raise ParseError("From what should I show the vnum?")
    name = parsed.args[0]
    if name == ".":
        obj = player.location
    elif parsed.who_order:
        obj = parsed.who_order[0]
    else:
        try:
            vnum = int(parsed.args[0])
        except ValueError as x:
            raise ActionRefused(str(x))
        objects = []
        try:
            objects.append(make_item(vnum))
        except KeyError:
            pass
        try:
            objects.append(make_location(vnum))
        except KeyError:
            pass
        try:
            objects.append(make_mob(vnum))
        except KeyError:
            pass
        player.tell("Objects with vnum %d:" % vnum,
                    lang.join(str(o) for o in objects))
        return
    try:
        vnum = obj.vnum
        player.tell("Vnum of %s = %d." % (obj, vnum))
    except AttributeError:
        player.tell(obj, "has no vnum.")
示例#13
0
 def insert(self, item: Union[Living, Item],
            actor: Optional[Living]) -> None:
     raise ActionRefused(
         "No matter how hard you try, you can't fit %s in the box." %
         item.title)
示例#14
0
 def remove(self, item: Union[Living, Item],
            actor: Optional[Living]) -> None:
     raise ActionRefused(
         "The box is cursed! You can't take anything out of it!")
示例#15
0
 def allow_item_move(self, actor: Living, verb: str = "move") -> None:
     raise ActionRefused("You can't %s the computer." % verb)
示例#16
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.")