def do_drool(self, ctx: util.Context) -> None: if random.random() < 0.3: self.location.tell("%s drools. Yuck." % lang.capital(self.title)) else: target = random.choice(list(self.location.livings)) if target is self: self.location.tell("%s drools on %sself." % (lang.capital(self.title), self.objective)) else: title = lang.capital(self.title) self.location.tell("%s drools on %s." % (title, target.title), specific_targets={target}, specific_target_msg="%s drools on you." % title)
def do_moan(self, ctx: util.Context) -> None: if random.random() < 0.3: self.location.tell("%s moans. better (run)." % lang.capital(self.title)) else: target = random.choice(list(self.location.livings)) if target is self: self.location.tell("%s grabs onto %sself." % (lang.capital(self.title), self.objective)) else: title = lang.capital(self.title) self.location.tell("%s moans on %s." % (title, target.title), specific_targets={target}, specific_target_msg="%s grabs onto you." % title)
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))
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))
def heartbeat(self, ctx): # note: this village idiot NPC uses a heartbeat mechanism to drool at certain moments. # This is less efficient than using a deferred (as the town crier NPC does) because # the driver has to call all heartbeats every tick even though they do nothing yet. # It's here for example sake. self.beats_before_drool -= 1 if self.beats_before_drool <= 0: self.beats_before_drool = random.randint(10, 20) target = random.choice(list(self.location.livings)) if target is self: self.location.tell("%s drools on %sself." % (lang.capital(self.title), self.objective)) else: title = lang.capital(self.title) self.location.tell("%s drools on %s." % (title, target.title), specific_targets=[target], specific_target_msg="%s drools on you." % title)
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)
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
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
def do_whizz(self, ctx: util.Context) -> None: rand = random.random() if rand < 0.14: self.do_socialize("twitch erra") elif rand < 0.28: self.do_socialize("rotate random") elif rand < 0.40: self.location.tell("%s hums softly." % lang.capital(self.title))
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))
def insert(self, item, actor): """NPC have a bit nicer refuse message when giving items to them.""" if not self.aggressive or actor is self or actor is not None and "wizard" in actor.privileges: super(NPC, self).insert(item, self) else: if self.aggressive and item is not "english paper": raise ActionRefused("%s doesn't want %s." % (lang.capital(self.title), item.title)) else: self.aggressive = False
def insert(self, item, actor): """NPC have a bit nicer refuse message when giving items to them.""" if item is english_paper: super(NPC, self).insert(item, self) actor.story_completed() actor.tell_later(""" Mr. Bushel takes your English paper with a look of surprise. "Well, better late than never, I suppose." You take your seat. For the first time in weeks, you won't be in detention all afternoon.""") else: raise ActionRefused("{} doesn't want {}.".format(lang.capital(self.title), item.title))
def do_purr(self, ctx): if random.random() > 0.5: self.location.tell("%s purrs happily." % capital(self.title)) else: self.location.tell("%s yawns sleepily." % capital(self.title)) ctx.driver.defer(random.randint(5, 20), self.do_purr)
def testCapital(self): self.assertEqual("", lang.capital("")) self.assertEqual("X", lang.capital("x")) self.assertEqual("Xyz AbC", lang.capital("xyz AbC"))
def do_purr(self, driver): if random.random() > 0.5: self.location.tell("%s purrs happily." % capital(self.title)) else: self.location.tell("%s yawns sleepily." % capital(self.title)) driver.defer(random.randint(5, 20), self, self.do_purr)
def do_purr(self, ctx: Context) -> None: if random.random() > 0.7: self.location.tell("%s purrs happily." % capital(self.title)) else: self.location.tell("%s yawns sleepily." % capital(self.title))
def description(self) -> str: if self.search_item("pills", include_location=False): return "%s looks scared, and clenches a small bottle in %s hands." % ( lang.capital(self.subjective), self.possessive) return "%s looks scared." % self.subjective
def description(self) -> str: if self.search_item("pills", include_location=False): return "%s looks scared, and clenches a small bottle in %s hands." % (lang.capital(self.subjective), self.possessive) return "%s looks scared." % self.subjective
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))
def do_birdaction(self, ctx: Context) -> None: if random.random() > 0.7: self.location.tell("%s chirps." % capital(self.title)) else: self.location.tell("%s flys around the room." % capital(self.title))
def description(self) -> str: if self.search_item("ammo", include_location=False): return "%s looks at you and shows you a box of ammo in %s hands." % (lang.capital(self.subjective), self.possessive) return "%s a creepy old man with wares." % self.subjective