blob: 44aec2b9c6df174f5d2714a09a473c214c5d38df [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// explorer.c -- Tool zur FP-Verwaltung
4//
5// $Id: explorer.c 8357 2013-02-09 11:16:14Z Zesstra $
6
7inherit "/std/secure_thing";
Zesstraf4471b32018-11-08 23:54:53 +01008protected functions virtual inherit "/std/util/path";
MG Mud User88f12472016-06-24 23:31:02 +02009
10#include <properties.h>
11#include <exploration.h>
12#include <wizlevels.h>
13
Zesstraf4471b32018-11-08 23:54:53 +010014protected void create()
MG Mud User88f12472016-06-24 23:31:02 +020015{
Zesstraf4471b32018-11-08 23:54:53 +010016 if (!clonep(this_object())) {
17 set_next_reset(-1);
18 return;
19 }
MG Mud User88f12472016-06-24 23:31:02 +020020 ::create();
21 SetProp(P_SHORT, "Der Erforscher");
22 SetProp(P_NAME, "Erforscher");
23 SetProp(P_GENDER, MALE);
24 SetProp(P_LONG, "Dies ist der beruehmte Erforscher des MorgenGrauens. Er\n"
25 +"stellt folgende Befehle zur Verfuegung:\n"
26 +" epadd <was>: <bonus> <typ> <keys>\n"
27 +" epchange <was>: <wie> <neu>\n"
28 +" epdel <was>\n"
29 +" epinfo <was>\n"
30 +" epcount <spielername> - Anzahl der EPs des Spielers\n"
31 +" epscan <spielername> [filenamenpattern] - Zeige dessen EPs gefiltert an\n"
32 +" eppladd <spielername> <ep-anzahl> - Gib ihm ep-anzahl EPs (zufaellig)\n"
33 +" eppldel <spielername> <ep-anzahl> - Loesche ihm ep-anzahl EPs (zufael.)\n"
34 +" epplset <spielername> <ep-nummer> - Setze ihm EP ep-nummer\n"
35 +" epplclr <spielername> <ep-nummer> - Loesche ihm EP ep-nummer\n"
36 +"Dabei bedeutet:\n"
37 +"<was> - Das Objekt (eine ID bei Objekten in der Naehe, hier oder\n"
38 +" here fuer den aktuellen Raum, oder ein Dateiname)\n"
39 +"<bonus> - n fuer normale EPs, b fuer Bonus-EPs (z.B. Para-EPs)\n"
40 +"<typ> - detail, rdetail, exit/ausgang, cmd/befehl/kommando, info, pub, misc,\n"
41 +" smell/geruch, sound/noise, taste/touch\n"
42 +"<key> - Liste der Schluesselwoerter, mit Kommata getrennt\n"
43 +"<wie> - obj, key, bonus oder typ 1\n"
44 +"<neu> - Je nach <wie>; siehe <was>, <key>, <typ>\n"
45 );
46 SetProp(P_NODROP, 1);
47 SetProp(P_NEVERDROP, 1);
48 SetProp(P_AUTOLOADOBJ,1);
49 AddId(({"explorer","erforscher"}));
50
51 AddCmd(({"epadd"}), "add");
52 AddCmd(({"epchange"}), "change");
53 AddCmd(({"epdel"}), "del");
54 AddCmd(({"epinfo"}), "info");
55 AddCmd(({"epcount"}), "epcount");
56 AddCmd(({"epscan"}), "epscan");
57 AddCmd(({"eppladd"}), "eppladd");
58 AddCmd(({"eppldel"}), "eppldel");
59 AddCmd(({"epplset"}), "epplset");
60 AddCmd(({"epplclr"}), "epplclr");
61}
62
63static string strArr(string *s)
64{
65 string ret;
66 int i;
67
68 ret = ("\"" + s[<1] + "\"");
69 for (i=sizeof(s)-2; i>=0; i--)
70 ret += (", \""+s[i]+"\"");
71
72 return ret;
73}
74
75static int getType(string s)
76{
77 switch(s[0..2]) {
78 case "det":
79 return EP_DETAIL;
80 case "rde":
81 return EP_RDET;
82 case "aus":
83 case "exi":
84 return EP_EXIT;
85 case "cmd":
86 case "bef":
87 case "kom":
88 return EP_CMD;
89 case "inf":
90 return EP_INFO;
91 case "pub":
92 return EP_PUB;
93 case "mis":
94 case "ver":
95 return EP_MISC;
96 case "sme":
97 case "ger":
98 return EP_SMELL;
99 case "sou":
100 case "noi":
101 return EP_SOUND;
102 case "tas":
103 case "tou":
104 return EP_TOUCH;
105 }
106 return -1;
107}
108
109static object getOb(string str)
110{
111 object ob;
112
113 if (str == "hier" || str == "here" )
114 return environment(this_player());
115
116 ob = present(str, environment(this_player()));
117 if (!ob)
118 ob = present(str, this_player());
119
120 if (!ob) {
Zesstraf4471b32018-11-08 23:54:53 +0100121 // Pfadexpansion fuer die UID vom aktuellen Benutzer.
122 str = normalize_path(str, getuid(this_interactive()||this_player()), 1);
123 catch(load_object(str));
MG Mud User88f12472016-06-24 23:31:02 +0200124 ob = find_object(str);
125 }
126 return ob;
127}
128
129static string *getKeys(string str)
130{
131 int i;
132 string *t1, *t2;
133
134 t1 = regexplode(str, ", *");
135 for (t2 = ({}), i=sizeof(t1)-1; i>=0; i-=2)
136 t2 = ({ t1[i] }) + t2;
137 return t2;
138}
139
140static string errMsg(int code)
141{
142 if (code >= 0 || code < EPERR_INVALID_ARG)
143 return "Unbekannter Fehler";
144
145 code = -(code+1);
146 return ({ "Du bist kein Erzmagier", "Ungueltiges Objekt",
147 "Objekt steht nicht in der Liste", "Ungueltiges Argument"})[code];
148}
149
150static int add(string str)
151{
152 string was, t, k, *keys, b;
153 int type, bonus;
154 object ob;
155
156 if( !ARCH_SECURITY ) {
157 notify_fail("Du bist kein Erzmagier!\n");
158 return 0;
159 }
160 notify_fail("Syntax: epadd <was>: <typ>\n");
161 if (!(str = this_player()->_unparsed_args()))
162 return 0;
163
164 if (sscanf(str, "%s: %s %s %s", was, b, t, k) !=4)
165 return 0;
166
167 if (!(ob = getOb(was))) {
168 printf("Kann '%s' nicht finden!\n", was);
169 return 1;
170 }
171 if ((type = getType(t)) < 0) {
172 write("Ungueltiger Typ!\n");
173 return 1;
174 }
175 if (b=="n") bonus=0; else if (b=="b") bonus=1;
176 else {
177 write("Ungueltige Bonusart!\n");
178 return 1;
179 }
180 keys = getKeys(k);
181
182 type = EPMASTER->AddEPObject(ob, keys, type, bonus);
183 if (type < 0)
184 printf("Fehler: %s\n", errMsg(type));
185 return 1;
186}
187
188static int change(string str)
189{
190 string was, wie, neu;
191 object ob;
192 int type;
193 mixed new;
194
195 if( !ARCH_SECURITY ) {
196 notify_fail("Du bist kein Erzmagier!\n");
197 return 0;
198 }
199
200 notify_fail("Syntax: epchange <was>: <wie> <neu>\n");
201 if (!(str = this_player()->_unparsed_args()))
202 return 0;
203
204 if (sscanf(str, "%s: %s %s", was, wie, neu) != 3)
205 return 0;
206
207 if (!(ob = getOb(was))) {
208 printf( "Kann '%s' nicht finden!\n", was);
209 return 1;
210 }
211 switch(wie[0..2]) {
212 case "obj":
213 type = CHANGE_OB;
214 new = getOb(neu);
215 if (!new) {
216 printf( "Kann '%s' nicht finden!\n", neu);
217 return 1;
218 }
219 break;
220 case "key":
221 type = CHANGE_KEY;
222 new = getKeys(neu);
223 break;
224 case "typ":
225 type = CHANGE_TYPE;
226 if ((new = getType(neu)) < 0) {
227 write("Ungueltiger Typ!\n");
228 return 1;
229 }
230 break;
231 case "bon":
232 type = CHANGE_BONUS;
233 if (neu=="n") new=0; else if (neu=="b") new=1;
234 else {
235 write("Ungueltige Bonusart!\n");
236 return 1;
237 }
238 break;
239 default:
240 write("Das laesst sich nicht aendern...\n");
241 return 1;
242 break;
243 }
244 type = EPMASTER->ChangeEPObject( ob, type, new );
245 if (type < 0)
246 printf("Fehler: %s\n",errMsg(type));
247
248 return 1;
249}
250
251static int del(string str)
252{
253 object ob;
254 int ret;
255
256 if( !ARCH_SECURITY ) {
257 notify_fail("Du bist kein Erzmagier!\n");
258 return 0;
259 }
260 if (!str) {
261 notify_fail("Syntax: epdel <was>\n");
262 return 0;
263 }
264 if (!(ob = getOb(str))) {
265 write("Kann das Objekt nicht finden!\n");
266 return 1;
267 }
268 ret = EPMASTER->RemoveEPObject(ob);
269 if (ret < 0)
270 printf("Fehler: %s\n", errMsg(ret));
271
272 return 1;
273}
274
275static int info(string str)
276{
277 object ob;
278 mixed info;
279
280 if( !ARCH_SECURITY ) {
281 notify_fail("Du bist kein Erzmagier!\n");
282 return 0;
283 }
284
285 if (!str) {
286 notify_fail("Syntax: epinfo <was>\n");
287 return 0;
288 }
289
290 if (!(ob = getOb(str))) {
291 write("Das finde ich leider nicht...\n");
292 return 1;
293 }
294 if (!(info = EPMASTER->QueryEPObject(ob)))
295 write ("Das Objekt ist nicht eingetragen!\n");
296 else
297 printf("Nummer: %d\nBonus: %d\nTyp: %s\nSchluessel: %s\n",
298 info[MPOS_NUM],
299 info[MPOS_TYPE+1],
300 ({ "Detail", "Ausgang", "Kommando", "Info", "Misc", "ReadDetail",
301 "Kneipe", "Geruch", "Geraeusch", "Tastdetail"})[info[MPOS_TYPE]],
302 strArr(info[MPOS_KEY] ));
303
304 return 1;
305}
306
307static object find_playerob( string name ) {
308 return find_player(name)||find_netdead(name);
309}
310
311static int epcount( string str ) {
312 object pl,epm;
313
314 if( !ARCH_SECURITY ) {
315 notify_fail("Du bist kein Erzmagier!\n");
316 return 0;
317 }
318
319 if (!str || str=="") {
320 notify_fail("Syntax: epcount <spielername>\n");
321 return 0;
322 }
323
324 printf( "%s hat %d von %d FPs. (Durchschnitt = %d)\n",
325 capitalize(str),
326 EPMASTER->QueryExplorationPoints(str),
327 EPMASTER->QueryMaxEP(),
328 EPMASTER->QueryAverage()
329 );
330 return 1;
331}
332
333static int epscan( string str ) {
334 object pl;
335 int erg;
336 string *astr;
337
338 if( !ARCH_SECURITY ) {
339 notify_fail("Du bist kein Erzmagier!\n");
340 return 0;
341 }
342
343 if (!str || str=="") {
344 notify_fail("Syntax: epscan <spielername> [Teil des Filenamens]\n");
345 return 0;
346 }
347
348 astr=old_explode(this_player()->_unparsed_args()," ");
349
350 if (sizeof(astr)<2)
351 erg = EPMASTER->ShowPlayerEPs(astr[0]);
352 else
353 erg = EPMASTER->ShowPlayerEPs(astr[0],astr[1]);
354 if (erg < 0)
355 printf("Fehler: %s\n",errMsg(erg));
356 return 1;
357}
358
359static eppldel( string str ) {
360 string player, rest;
361 int epnum;
362 object tmp;
363
364 if( !ARCH_SECURITY ) {
365 notify_fail("Du bist kein Erzmagier!\n");
366 return 0;
367 }
368
369 notify_fail( "eppldel <spieler> <anzahl_eps> <grund>\n" );
370 if( !str || sscanf( str, "%s %d %s", player, epnum, rest )<2 )
371 return 0;
372
373 if( epnum <= 0 ) {
374 write( "Anzahl der FPs <= 0 ?\n" );
375 return 1;
376 }
377 if( !rest || rest=="" ) {
378 write( "Bitte Grund angeben!\n" );
379 return 1;
380 }
381
382 printf( "%O %O %O\n", epnum, player, secure_level() );
383 epnum = "/secure/explorationmaster"->RemoveFP( epnum, player, rest );
384 printf( "Ergebnis (abgezogene EPs) = %O\n", epnum );
385 return 1;
386
387}
388
389static eppladd( string str ) {
390 string player, rest;
391 int epnum;
392 object pl,tmp;
393
394 if( !ARCH_SECURITY ) {
395 notify_fail("Du bist kein Erzmagier!\n");
396 return 0;
397 }
398
399 notify_fail( "eppladd <spieler> <anzahl_eps>\n" );
400 if( !str || sscanf( str, "%s %d", player, epnum )<2 )
401 return 0;
402
403 if( epnum <= 0 ) {
404 write( "Anzahl der FPs <= 0 ?\n" );
405 return 1;
406 }
407
408 epnum = "/secure/explorationmaster"->AddFP( epnum, player );
409 printf( "Ergebnis (hinzugefuegte FPs) = %O\n", epnum );
410 return 1;
411
412}
413
414static epplset( string str ) {
415 string player, rest;
416 int epnum;
417 object pl,tmp;
418
419 if( !ARCH_SECURITY ) {
420 notify_fail("Du bist kein Erzmagier!\n");
421 return 0;
422 }
423
424 notify_fail( "epplset <spieler> <ep-nummer>\n" );
425 if( !str || sscanf( str, "%s %d", player, epnum )<2 )
426 return 0;
427
428 epnum = "/secure/explorationmaster"->SetFP( epnum, player );
429 printf( "Ergebnis (gesetzter FP) = %O\n", epnum );
430 return 1;
431}
432
433static epplclr( string str ) {
434 string player, rest;
435 int epnum;
436 object pl,tmp;
437
438 if( !ARCH_SECURITY ) {
439 notify_fail("Du bist kein Erzmagier!\n");
440 return 0;
441 }
442
443 notify_fail( "epplclr <spieler> <ep-nummer>\n" );
444 if( !str || sscanf( str, "%s %d", player, epnum )<2 )
445 return 0;
446
447 epnum = "/secure/explorationmaster"->ClearFP( epnum, player );
448 printf( "Ergebnis (geloeschter FP) = %O\n", epnum );
449 return 1;
450}