#!/usr/bin/env python from random import random from re import split from commands.command import Command from evennia.commands.default.general import NumberedTargetCommand from evennia.commands.default.muxcommand import MuxCommand from evennia.contrib.rpg.rpsystem import send_emote from evennia.utils import iter_to_str, logger from utils.word_list import routput class CmdSay(MuxCommand): """Say something to the characters in the same area. Usage: say phrase say/to char1 [char2 ...], phrase say[/switches] phrase Where switches can be any of the following: - yell : To replace 'says' with 'yells' - scream : To replace 'says' with 'screams' - ask : To replace 'says' with 'asks' - to : Takes one or more characters in the same area, and directs the statement to them. Note that others can still hear the statement (see the 'whisper' command). - adverb : Any adverb-like word that ends in '-ly' is added to the say command, for instance: say/quietly Hi there. Shows as: You quietly say, "Hi there." """ key = "say" aliases = ["speak", "yell", "scream", "ask", "\""] priority = 0 locks = "cmd:all()" rhs_split = ("=") def func(self): """ Implements the new 'say' command with switches. """ def chars_for_self(chars): return [self.caller.search(c).get_display_name(self) for c in split(r"[ ,]+", chars)] def chars_for_others(chars): return [c if c.startswith('/') else '/'+c for c in split(r"[ ,]+", chars)] def chars_list(chars, verb, for_rp=True): char_lst = chars_for_others(chars) if for_rp else chars_for_self(chars) return (' to ' if verb == 'say' else ' ') + \ iter_to_str(char_lst, endsep='and') logger.info(f"CmdSayIt: {self.cmdstring} lhs={self.lhs} switches={self.switches}") if not self.args: self.caller.msg("Say what?") return if self.rhs: speech = self.rhs else: speech = self.args # If speech is empty, stop here if not self.caller.at_pre_say(speech): return adverb = '' for switch in self.switches: if switch.endswith('ly'): adverb = switch + ' ' if 'yell' in self.switches or self.cmdstring == 'yell' or speech.endswith('!'): verb = 'yell' elif 'scream' in self.switches or self.cmdstring == 'scream': verb = 'scream' elif 'ask' in self.switches or self.cmdstring == 'ask' or speech.endswith('?'): verb = 'ask' else: verb = "say" # The `send_emote` is _global_, so if we want to say to 'Bob', # 'You say ...', we have to both send him a message with the # 'You' as well as everyone else with the 'send_emote'. to_whom = chars_list(self.lhs, verb, for_rp=False) if 'to' in self.switches else '' full_speech = f"You {adverb}{verb}{to_whom}, \"{speech}\"" self.caller.msg(full_speech, from_obj=self.caller) targets = [item for item in self.caller.location.contents if item != self.caller] to_whom = chars_list(self.lhs, verb) if 'to' in self.switches else '' full_speech = f"/Me {adverb}{verb}s{to_whom}, \"{speech}\"" send_emote(self.caller, targets, full_speech, msg_type="say", anonymous_add=None) class CmdThink(Command, NumberedTargetCommand): """Think a thought out loud. Usage: think Similar to the 'say' or 'pose' commands, this communicates an inner monologue to other characters in the same area. """ key = "think" aliases = ["thinks", "("] arg_regex = None def func(self): """ Implements the think out loud command. """ if not self.args: self.caller.msg("What do you want to think out loud?") else: thought = self.args.strip() if (self.caller.db.thinking_count or 0) < 3 or random() < 0.4: msg = routput( f"""{self.caller.name} << thinks ^ wonders >> << out loud ^ aloud >> o O ( {thought} ) """ ) else: msg = f"{self.caller.name} . o O ( {thought} )" self.caller.db.thinking_count = (self.caller.db.thinking_count or 0) + 1 self.caller.location.msg_contents(msg) class CmdTake(Command, NumberedTargetCommand): """ Take an object from another character or NPC. Usage: take from Note that only some things can be stolen. For instance, the brass ring from the door knocker. """ key = "take" aliases = ["steal"] rhs_split = ("=", " from ") def func(self): """ Implements the take command. Since this command is designed to work on the object, we operate only on self.obj. """ if not self.args: self.caller.msg("What do you want to take?") elif not self.rhs: self.caller.msg(f"You want to take {self.lhs}, but from whom?") else: self.caller.do_take(self.lhs, self.rhs)