/
say.c
256 lines (235 loc) · 10.8 KB
/
say.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//******************************************************************************
// Copyright (c) 2019 - Allen Cummings, RealmsMUD, All rights reserved. See
// the accompanying LICENSE file for details.
//*****************************************************************************
inherit "/lib/commands/baseCommand.c";
/////////////////////////////////////////////////////////////////////////////
public nomask void reset(int arg)
{
if (!arg)
{
CommandType = "Social";
addCommandTemplate("say [-v(erb|) ##Verb##] [-a(dverb|) ##Adverb##] "
"[-l(anguage|) ##Language##] [-t(arget|) ##Target##] [.*]");
addCommandTemplate("' [-v(erb|) ##Verb##] [-a(dverb|) ##Adverb##] "
"[-l(anguage|) ##Language##] [-t(arget|) ##Target##] [.*]");
}
}
/////////////////////////////////////////////////////////////////////////////
private nomask object getDictionary()
{
return load_object("/lib/dictionaries/languageDictionary.c");
}
/////////////////////////////////////////////////////////////////////////////
private nomask void speakMessage(string message, string messageTemplate,
object initiator, object target, string language)
{
message = regreplace(message, "(say|') *(.*)", "\\2", 1);
// This annoying loop handles the fact that everyone has different
// setting for color.
if (environment(initiator))
{
object configuration = load_object("/lib/dictionaries/configurationDictionary.c");
object *characters = filter(all_inventory(environment(initiator)),
(: $1->isRealizationOfLiving() :));
foreach(object person in characters)
{
if (person && objectp(person))
{
string newMessage = message;
if (language)
{
newMessage = getDictionary()->applyLanguageSkillToReceivedMessage(language, message,
person, initiator);
}
string parsedMessage = regreplace(messageTemplate, "##Message##", newMessage);
if (person == initiator)
{
parsedMessage = parseTemplate(parsedMessage, "initiator", initiator,
target);
}
else if (person == target)
{
parsedMessage = parseTemplate(parsedMessage, "target",
initiator, target);
}
else
{
parsedMessage = parseTemplate(parsedMessage, "other",
initiator, target);
}
if (!person->blocked(initiator))
{
tell_object(person, configuration->decorate(
format(parsedMessage, 78), "message", "say",
person->colorConfiguration()));
}
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
public nomask int execute(string command, object initiator)
{
int ret = 0;
string messageTemplate = "##InitiatorName## ##Adverb##"
"##Infinitive::verb####TargetPreposition####TargetName##"
"##LanguagePreposition####Language##, `##Message##'";
if (canExecuteCommand(command))
{
ret = 1;
object targetObj = 0;
string language = 0;
if (sizeof(regexp(({ command }), "-v(erb)* [A-Za-z]+")))
{
string verb = regreplace(command, ".*-v(erb)* ([A-Za-z]+) .*", "\\2", 1);
command = regreplace(command, "-v(erb)* ([A-Za-z]+)", "", 1);
messageTemplate = regreplace(messageTemplate, "::verb", "::" + verb);
}
else
{
messageTemplate = regreplace(messageTemplate, "::verb", "::say");
}
if (sizeof(regexp(({ command }), "-a(dverb)* [A-Za-z]+")))
{
string adverb = regreplace(command, ".*-a(dverb)* ([A-Za-z]+) .*", "\\2 ", 1);
command = regreplace(command, "-a(dverb)* ([A-Za-z]+)", "", 1);
messageTemplate = regreplace(messageTemplate, "##Adverb##", adverb);
}
else
{
messageTemplate = regreplace(messageTemplate, "##Adverb##", "");
}
if (sizeof(regexp(({ command }), "-t(arget)* '*[A-Za-z]+")))
{
string target = regreplace(command, ".*-t(arget)* ([A-Za-z]+|'[^']+') .*", "\\2", 1);
target = regreplace(target, "'([^']+)'", "\\1", 1);
targetObj = present(target, environment(initiator));
command = regreplace(command, "-t(arget)* ([A-Za-z]+)", "", 1);
command = regreplace(command, "-t(arget)* ('[A-Za-z ]+')", "", 1);
if (!targetObj)
{
messageTemplate = regreplace(messageTemplate, "##TargetName##", target);
}
messageTemplate = regreplace(messageTemplate, "##TargetPreposition##", " to ");
}
else
{
messageTemplate = regreplace(messageTemplate, "##TargetName##", "");
messageTemplate = regreplace(messageTemplate, "##TargetPreposition##", "");
}
if (sizeof(regexp(({ command }), "-l(anguage)* (high elven|[A-Za-z]+)")))
{
language = regreplace(command, ".*-l(anguage)* (high elven|[A-Za-z]+) .*", "\\2", 1);
command = regreplace(command, "-l(anguage)* (high elven|[A-Za-z]+)", "", 1);
messageTemplate = regreplace(messageTemplate, "##Language##",
getDictionary()->getSpokenLanguage(language, initiator));
messageTemplate = regreplace(messageTemplate, "##LanguagePreposition##", " in ");
}
else
{
messageTemplate = regreplace(messageTemplate, "##Language##", "");
messageTemplate = regreplace(messageTemplate, "##LanguagePreposition##", "");
}
// This will kill the other flags
if (sizeof(regexp(({ command }), "(say|') -[A-Za-z]+")))
{
string flag = regreplace(command, "(say|') (-[A-Za-z]+).*", "\\2", 1);
tell_object(initiator, sprintf("Command failed: The '%s' flag is not valid.\n", flag));
}
else
{
speakMessage(command, messageTemplate, initiator, targetObj, language);
}
}
return ret;
}
/////////////////////////////////////////////////////////////////////////////
protected string wildcardMeaning(string colorConfiguration)
{
return "\x1b[0;31;1m<Message to speak>\x1b[0m";
}
/////////////////////////////////////////////////////////////////////////////
protected string synopsis(string displayCommand, string colorConfiguration)
{
return "Send a message to everyone in your environment";
}
/////////////////////////////////////////////////////////////////////////////
protected string flagInformation(string flag, string colorConfiguration)
{
string ret = "";
string parsedFlag = regreplace(flag, "[^-]*(-[a-zA-Z]+).*", "\\1");
switch (parsedFlag)
{
case "-v":
{
ret = "This option will replace the verb displayed as part of "
"the 'say' message. For example:\n\t\x1b[0;37m> say -v grumble "
"I'm grumpy!\n\t\x1b[0;32mYou grumble, `I'm grumpy!'\x1b[0m\n"
"\x1b[0;36mOthers users would then see:\n"
"\t\x1b[0;32mBob grumbles, `I'm grumpy!'\x1b[0m\n";
break;
}
case "-a":
{
ret = "This option will add an adverb to "
"the 'say' message. For example:\n\t\x1b[0;37m> say -a sarcastically "
"You're my hero!\n\t\x1b[0;32mYou sarcastically say, `You're my hero!'\x1b[0m\n"
"\x1b[0;36mOthers users would then see:\n"
"\t\x1b[0;32mBob sarcastically says, `You're my hero!'\x1b[0m\n";
break;
}
case "-l":
{
ret = "This option will translate the message you wish to say into "
"the given language - or at least attempt to do so. Your skill "
"in the target language will determine whether or not it is "
"translated appropriately or becomes gibberish. Those in the "
"environment will then use their skill to translate the message "
"back to English. For example if you have no skill in a "
"language, you might see:\n\t\x1b[0;37m> say -l orcish "
"I should say something nice.\n\t\x1b[0;32mYou say in complete "
"gibberish, `Blarg nukuleve zog forgla bup'\n"
"\x1b[0;36mOthers users would see:\n"
"\t\x1b[0;32mBob says in complete gibberish, `Blarg nukuleve zog "
"forgla bup'\n\x1b[0;36mMeanwhile, if you do know a language you might "
"see:\n\t\x1b[0;37m> say -l elven I should say something nice."
"\n\t\x1b[0;32mYou say in elven, `I should say something nice.'\n"
"\x1b[0;36mOthers users that have a high skill in elven would see:"
"\n\t\x1b[0;32mBob says in elven, `I should say something nice.'\n"
"\x1b[0;36mOthers users that have no skill in elven would see:"
"\n\t\x1b[0;32mBob says in elven, `Naur wu simildin welana loomen'\n"
"\x1b[0;36mIt is important to note that knowledge of a language is "
"a range and, so too, is one's ability to speak and translate "
"it. You will go from being able to speak/understand nothing "
"to brokenly speaking or partially understanding all the way "
"through being completely fluent.\x1b[0;36m\n";
break;
}
case "-t":
{
ret = "This option will allow you to speak a message to a specific "
"target. For example:\n\t\x1b[0;37m> say -t Fred "
"Hi Fred!\n\t\x1b[0;32mYou say to Fred, `Hi Fred!'\x1b[0m\n"
"\x1b[0;36mFred would then see:\n"
"\t\x1b[0;32mBob says to you, `Hi Fred!'\x1b[0m\n"
"\x1b[0;36mOthers users would then see:\n"
"\t\x1b[0;32mBob says to Fred, `Hi Fred!'\x1b[0m\n";
break;
}
}
return format(ret, 72);
}
/////////////////////////////////////////////////////////////////////////////
protected string description(string displayCommand, string colorConfiguration)
{
return format("Say allows a player to display a message to all players "
"located in the same room where he or she is standing. The character ' "
"can be used as an abbreviation for say to save time. Interactions "
"with players can be blocked using the 'block player' setting.", 78);
}
/////////////////////////////////////////////////////////////////////////////
protected string notes(string displayCommand, string colorConfiguration)
{
return "See also: tell, whisper, reply, shout, and set";
}