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