]> jfr.im git - irc/gameservirc.git/blame - gameserv/gameserv.cpp
Again, trying to sync the two cvs repositories.
[irc/gameservirc.git] / gameserv / gameserv.cpp
CommitLineData
85ce9d3e 1#include "sockhelp.h"
2#include "aClient.h"
3#include "list.h"
4#include "extern.h"
5#include <cctype>
6#include <fstream.h>
e3c5fe46 7#include <crypt.h>
85ce9d3e 8
9List<aClient> players;
10Monster monsters[5][12];
ad7dfaa0 11Monster masters[12];
85ce9d3e 12
a8fb9757 13// Database functions
85ce9d3e 14int save_gs_dbase();
15int load_gs_dbase();
16
17// String functions
18#undef strtok
19char *strtok(char *str, const char *delim);
20int stricmp(const char *s1, const char *s2);
21int strnicmp(const char *s1, const char *s2, size_t len);
22// String Functions
23
e3c5fe46 24
25/********** Password functions **********/
26
27bool passcmp(char *encrypted, char *plaintext); // Compares an encrypted pass with a plain text one
28
29bool check_password(char *name, char *plaintext); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
30
31/********** Password functions **********/
32
33
34/********** GameServ Booleans **********/
35
36bool is_playing(char *u); // True if the given nickname in the clients list is playing.
37bool has_started(char *u); // True if the given nickname in the clients list has started playing.
38bool is_fighting(char *u); // True if the given nick in the clients list is fighting anything.
39bool isnt_fighting(char *u); // True if the given nick isn't fighting. Same as !is_fighting(u).
40bool player_fight(char *u); // True if the player is fighting another player.
41bool master_fight(char *u); // True if the player is fighting their master.
42
43/********** GameServ Booleans **********/
85ce9d3e 44
45
46void display_monster(char *u);
47void display_players(char *u);
48long int chartoint(char ch);
49int isstringnum(char *num);
50long int pow (int x, int y);
51long int stringtoint(char *number);
52
53char *spaces(int len, char *seperator);
54void init_masters();
55void refresh(aClient *ni);
56void refreshall();
57void reset(aClient *ni);
58void init_monsters();
59
60void do_list(char *u);
61void do_register(char *u);
62void do_identify(char *u);
63void do_play(char *u);
64void do_quitg(char *u);
65void do_reset(char *u);
66void do_fight(char *u);
67void do_store(char *u);
68void do_heal(char *u);
69void do_bank(char *u);
70void do_attack(char *u);
71void do_run(char *u);
72void do_visit(char *u);
73void do_stats(char *u);
74void see_mystic(char *u);
75
76void showstats(const char *u, const char *nick);
77
78#define WNA 16
79char *weapons[WNA] = { "Fists", "Stick", "Dagger", "Quarterstaff", "Short Sword",
80 "Long Sword", "Silver Spear", "Battle Axe", "The Ragnarok",
81 "Chain Saw", "Poison Sword", "Flame Sword", "Earth Hammer",
82 "Light Saber", "Masamune", "Mystical Sword"};
83
84char *armors[WNA] = { "Nothing", "Clothes", "Leather Vest", "Chain Mail", "Plate Armor",
85 "Full Body Armor", "Magic Mail", "Graphite Suit", "Steel Suit",
86 "Force Field", "Armor of Light", "Mythril Vest", "DemiGod Armor",
87 "Hades' Cloak", "Dragon Scales", "Mystical Armor"};
88
89int prices[WNA - 1] = {200, 1000, 3000, 10000, 30000, 100000, 150000, 200000, 400000,
90 1000000, 4000000, 10000000, 40000000, 100000000, 400000000};
91int webonus[WNA] = {0, 10, 15, 25, 35, 45, 65, 85, 125, 185, 255, 355, 505, 805, 1205, 1805};
92int arbonus[WNA] = {0, 1, 3, 10, 15, 25, 35, 50, 75, 100, 150, 225, 300, 400, 600, 1000};
93
94int hpbonus[11] = {10, 15, 20, 30, 50, 75, 125, 185, 250, 350, 550};
95int strbonus[11] = {5, 7, 10, 12, 20, 35, 50, 75, 110, 150, 200};
96int defbonus[11] = {2, 3, 5, 10, 15, 22, 35, 60, 80, 120, 150};
97
98
99void gameserv(char *source, char *buf)
100{
101 char *cmd, input[1024];
102 cmd = strtok(buf, " ");
103
104 source++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
105 cmd++; // Get rid of that : at the beginning of the :text (command)
106
107 cout << "Source: " << source << "\ncmd: " << cmd << endl;
108 if (strnicmp(cmd, ":\1PING", 6) == 0)
109 {
110 char *timestamp;
111 timestamp = strtok(NULL, "\1");
112 notice(s_GameServ, source, "\1PING %s\1", timestamp);
113 } else if (stricmp(cmd, ":\1VERSION\1") == 0) {
114 notice(s_GameServ, source, "\1VERSION GameServ v1.0b\1");
115 } else if (stricmp(cmd, "SEARCH") == 0) {
116 cmd = strtok(NULL, " ");
117
118 if (!cmd)
119 notice(s_GameServ, source, "SYNTAX: /msg %S SEARCH FOREST");
120 else
121 do_forest(source);
122 } else if (stricmp(cmd, "FIGHT") == 0) {
123 do_fight(source);
124 } else if (stricmp(cmd, "ATTACK") == 0) {
125 do_attack(source);
126 } else if (stricmp(cmd, "HEAL") == 0) {
127 do_heal(source);
ad7dfaa0 128 } else if (stricmp(cmd, "STORE") == 0) {
129 do_store(source);
8c126acc 130 } else if (stricmp(cmd, "BANK") == 0) {
131 do_bank(source);
85ce9d3e 132 } else if (stricmp(cmd, "PRINT") == 0) {
133 cout << "Printing Clients List: " << endl;
134 clients.print();
0a1518fa 135 cout << "\nPrinting Player List: " << endl;
85ce9d3e 136 players.print();
137 } else if (stricmp(cmd, "LIST") == 0) {
138 do_list(source);
139 } else if (stricmp(cmd, "REGISTER") == 0) {
140 do_register(source);
141 } else if (stricmp(cmd, "IDENTIFY") == 0) {
142 do_identify(source);
143 } else if (stricmp(cmd, "HELP") == 0) {
144 } else if (stricmp(cmd, "STATS") == 0) {
145 do_stats(source);
146 } else if (stricmp(cmd, "SHUTDOWN") == 0) {
ad7dfaa0 147 save_gs_dbase();
85ce9d3e 148 raw("SQUIT %s :leaving", servername);
149 } else if (stricmp(cmd, "SAVE") == 0) {
150 save_gs_dbase();
151 } else if (stricmp(cmd, "LOAD") == 0) {
152 load_gs_dbase();
153 } else if (stricmp(cmd, "RAW") == 0) {
154 char *rest = strtok(NULL, "");
155 raw(rest);
156 }
157
158 source--; // Bring the : back so we don't leak memory
159 cmd--; // Same thing :)
160}
161
162int stricmp(const char *s1, const char *s2)
163{
164 register int c;
165
166 while ((c = tolower(*s1)) == tolower(*s2)) {
167 if (c == 0)
168 return 0;
169 s1++;
170 s2++;
171 }
172 if (c < tolower(*s2))
173 return -1;
174 return 1;
175}
176
177void showstats(const char *u, const char *nick)
178{
179 aClient *ni, *sender = find(u);
180 char *buf;
181 buf = new char[50];
182 char *space;
183
184
185 cout << "\n\nu: " << u << "\nnick: " << nick << endl;
186 if (!(ni = findbynick(nick)))
187 {
188 notice(s_GameServ, u, "%s not found", nick);
189 }
190 else if (ni->stats)
191 {
192
193 notice(s_GameServ, sender->getNick(), "Stats for %s:", ni->stats->name);
194
195 sprintf(buf, "Experience: %ld", ni->stats->exp);
196 space = spaces(strlen(buf), " ");
197 notice(s_GameServ, sender->getNick(), "%s%sLevel: %d", buf, space,
198 ni->stats->level);
1cf88153 199 delete [] space;
85ce9d3e 200
201 sprintf(buf, "Gold: %ld", ni->stats->gold);
202 space = spaces(strlen(buf), " ");
203 notice(s_GameServ, sender->getNick(), "%s%sGold in Bank: %ld", buf, space, ni->stats->bank);
1cf88153 204 delete [] space;
85ce9d3e 205
206 notice(s_GameServ, sender->getNick(), "Health Points: %d of %d", ni->stats->hp,
207 ni->stats->maxhp);
208
209 sprintf(buf, "Strength: %d", ni->stats->strength + webonus[ni->stats->weapon]);
210 space = spaces(strlen(buf), " ");
211 notice(s_GameServ, sender->getNick(), "%s%sDefense: %d",
212 buf, space, ni->stats->defense + arbonus[ni->stats->armor]);
1cf88153 213 delete [] space;
85ce9d3e 214
215 sprintf(buf, "Armor: %s", armors[ni->stats->armor]);
216 space = spaces(strlen(buf), " ");
217 notice(s_GameServ, sender->getNick(), "%s%sWeapon: %s", buf, space,
218 weapons[ni->stats->weapon]);
1cf88153 219 delete [] space;
85ce9d3e 220
221 sprintf(buf, "Forest Fights: %d", ni->stats->forest_fights);
222 space = spaces(strlen(buf), " ");
223 notice(s_GameServ, sender->getNick(), "%s%sPlayer Fights: %d", buf, space, ni->stats->player_fights);
1cf88153 224 delete [] space;
85ce9d3e 225 }
1cf88153 226 delete [] buf;
85ce9d3e 227
228}
229
230char *spaces(int len, char *seperator)
231{
232 char *final;
233 final = new char[40];
234 int y;
235 strcpy(final, seperator);
236 for (y = 0; y < 40 - len; y++)
237 strcat(final, seperator);
238 return final;
239}
240
241void raw(const char *fmt, ...)
242{
243 va_list args;
244 char *input;
245 const char *t = fmt;
246 input = new char[1024];
247 va_start(args, fmt);
248 memset(input, 0, sizeof(input)); // Initialize to NULL
249 for (; *t; t++)
250 {
251 if (*t == '%')
252 {
253 switch(*++t) {
254 case 'd': sprintf(input, "%s%d", input, va_arg(args, int)); break;
255 case 's': sprintf(input, "%s%s", input, va_arg(args, char *)); break;
256 case 'S': sprintf(input, "%s%s", input, s_GameServ); break;
257 case 'l':
258 if (*++t == 'd')
259 sprintf(input, "%s%ld", input, va_arg(args, long int)); break;
260 }
261 }
262 else
263 {
264 sprintf(input, "%s%c", input, *t);
265 }
266
267 }
268 sprintf(input, "%s%s", input, "\r\n");
269 cout << "input: " << input << flush;
270 sock_puts(sock, input);
1cf88153 271 delete [] input;
85ce9d3e 272 va_end(args);
273}
274/* Send a NOTICE from the given source to the given nick. */
275
276void notice(const char *source, const char *dest, const char *fmt, ...)
277{
278 va_list args;
279 char *input;
280 const char *t = fmt;
281 input = new char[1024];
282 va_start(args, fmt);
283 if (dest[0] == ':')
284 {
285 dest++;
286 sprintf(input, ":%s NOTICE %s :", source, dest);
287 dest--;
288 }
289 else
290 sprintf(input, ":%s NOTICE %s :", source, dest);
291
292 for (; *t; t++)
293 {
294 if (*t == '%')
295 {
296 switch(*++t) {
297 case 'd': sprintf(input, "%s%d", input, va_arg(args, int)); break;
298 case 's': sprintf(input, "%s%s", input, va_arg(args, char *)); break;
299 case 'S': sprintf(input, "%s%s", input, s_GameServ); break;
300 case 'l':
301 if (*++t == 'd')
302 sprintf(input, "%s%ld", input, va_arg(args, long int)); break;
303 }
304 }
305 else
306 {
307 sprintf(input, "%s%c", input, *t);
308 }
309
310 }
311 sprintf(input, "%s%s", input, "\r\n");
312 cout << "input: " << input << flush;
313 sock_puts(sock, input);
1cf88153 314 delete [] input;
85ce9d3e 315va_end(args);
316}
317
318
319int strnicmp(const char *s1, const char *s2, size_t len)
320{
321 register int c;
322
323 if (!len)
324 return 0;
325 while ((c = tolower(*s1)) == tolower(*s2) && len > 0) {
326 if (c == 0 || --len == 0)
327 return 0;
328 s1++;
329 s2++;
330 }
331 if (c < tolower(*s2))
332 return -1;
333 return 1;
334}
335
336char *strtok(char *str, const char *delim)
337{
338 static char *current = NULL;
339 char *ret;
340
341 if (str)
342 current = str;
343 if (!current)
344 return NULL;
345 current += strspn(current, delim);
346 ret = *current ? current : NULL;
347 current += strcspn(current, delim);
348 if (!*current)
349 current = NULL;
350 else
351 *current++ = 0;
352 return ret;
353}
354
355void do_list(char *u)
356{
357 ListNode<aClient> *temp;
358 temp = players.First();
359 if (!players.isEmpty())
360 {
361 notice(s_GameServ, u, "People Playing:");
362 while(temp)
363 {
364 notice(s_GameServ, u, "IRC: %s Game: %s", temp->getData()->getNick(), temp->getData()->stats->name);
365 temp = temp->Next();
366 }
367 notice(s_GameServ, u, "End of List");
368 }
369 else
370 notice(s_GameServ, u, "No one is playing");
371}
372void do_register(char *u)
373{
374 char *password;
375 aClient *user;
376 password = strtok(NULL, " ");
377
e3c5fe46 378 static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
379 static char salt[3];
380
381 salt[0] = saltChars[rand() % strlen(saltChars)];
382 salt[1] = saltChars[rand() % strlen(saltChars)];
383 salt[3] = '\0';
384
85ce9d3e 385 if (!password)
386 {
387 notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER PASSWORD");
388 }
389 else if (user = find(u))
390 {
391 if (!user->stats)
392 {
393 user->stats = new Player(user);
394 user->stats->started = 1;
395 user->stats->user = user; // Set the backwards pointer
e3c5fe46 396 strcpy(user->stats->password, crypt(password, salt));
85ce9d3e 397 players.insertAtBack(user);
398 }
399 else
400 {
401 notice(s_GameServ, u, "Already registered. Contact a %S admin for help.");
402 }
403 }
404}
405
406void do_identify(char *u)
407{
0a1518fa 408 char *password, *name;
409 aClient *user, *p;
410 name = strtok(NULL, " ");
85ce9d3e 411 password = strtok(NULL, " ");
cdc9a6db 412
0a1518fa 413 if (!password || !name)
85ce9d3e 414 {
0a1518fa 415 notice(s_GameServ, u, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD");
85ce9d3e 416 }
0a1518fa 417 else if (!(p = findplayer(name)) || !p->stats)
418 notice(s_GameServ, u, "Player %s not found", name);
419 else if (!check_password(name, password))
85ce9d3e 420 {
0a1518fa 421 notice(s_GameServ, u, "Password incorrect");
85ce9d3e 422 }
0a1518fa 423 else if (user = find(u))
85ce9d3e 424 {
425 if (!user->stats)
426 {
1cf88153 427 ListNode<aClient> *temp;
428 temp = players.Find(p);
429 if (!temp)
430 {
431 notice(s_GameServ, u, "Fatal error. Contact %S Admin. Buf: %s",
432 strtok(NULL, ""));
433 return;
434 }
cdc9a6db 435 user->stats = new Player(p->stats->name);
436 cout << "Setting data for identified" << endl;
1cf88153 437 user->stats->setData(p->stats);
cdc9a6db 438 cout << "Player Identified" << endl << flush;
439
440 temp->setPtr(user);
441
442 notice(s_GameServ, u, "Password Accepted. Identified.");
1cf88153 443
85ce9d3e 444 }
445 else
446 {
447 notice(s_GameServ, u, "Already identified. Contact a %S admin for help.");
448 }
449 }
450}
451
452void do_stats(char *u)
453{
454 char *nick;
455 aClient *source;
456
457 nick = strtok(NULL, " ");
458 source = find(u);
459
460 if (!nick)
461 showstats(u, source->getNick());
462 else
463 showstats(u, nick);
464}
ad7dfaa0 465void init_masters()
466{
467 masters[0].name = "Old Bones";
468 masters[0].weapon = "Dull Sword Cane";
469 masters[0].strength = 30;
470 masters[0].gold = 0;
471 masters[0].exp = 0;
472 masters[0].maxhp = 30;
473 masters[0].death = "You have done well my student, but the road is long. Use your new strength with humility and honor as you progress in levels!";
474
475 masters[1].name = "Master Chang";
476 masters[1].weapon = "Nanchaku";
477 masters[1].strength = 57;
478 masters[1].gold = 0;
479 masters[1].exp = 0;
480 masters[1].maxhp = 40;
481 masters[1].death = "You try to make out what Master Chang is saying, but the only thing you catch is something about a grasshopper.";
482
483 masters[2].name = "Chuck Norris";
484 masters[2].weapon = "Ranger Kick";
485 masters[2].strength = 85;
486 masters[2].gold = 0;
487 masters[2].exp = 0;
488 masters[2].maxhp = 70;
489 masters[2].death = "Be strong, and keep your goals in site. Drink milk, and don't do drugs. One day you may be fighting next to me as a Texas Ranger YEEHAW!";
490
491
492 masters[3].name = "Mr. Miagi";
493 masters[3].weapon = "Petrified Bonsai";
494 masters[3].strength = 100;
495 masters[3].gold = 0;
496 masters[3].exp = 0;
497 masters[3].maxhp = 120;
498 masters[3].death = "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!";
499
500 masters[4].name = "Jackie Chan";
501 masters[4].weapon = "Drunken Boxing";
502 masters[4].strength = 125;
503 masters[4].maxhp = 200;
504 masters[4].gold = 0;
505 masters[4].exp = 0;
506 masters[4].death = "I like to let people talk who like to talk... it's easier to find out how full of it they really are!";
507
508 masters[5].name = "Jet Li";
509 masters[5].weapon = "Motorcycle";
510 masters[5].strength = 150;
511 masters[5].maxhp = 400;
512 masters[5].gold = 0;
513 masters[5].exp = 0;
514 masters[5].death = "Failure is a fuel for excuses. It's the doing the do, that makes the making.";
515
516
517 masters[6].name = "Muhammad Ali";
518 masters[6].weapon = "Quick Jab";
519 masters[6].strength = 175;
520 masters[6].maxhp = 600;
521 masters[6].gold = 0;
522 masters[6].exp = 0;
523 masters[6].death = "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up.";
524
525 masters[7].name = "Li Mu Bai";
526 masters[7].weapon = "Green Destiny";
527 masters[7].strength = 200;
528 masters[7].maxhp = 800;
529 masters[7].gold = 0;
530 masters[7].exp = 0;
531 masters[7].death = "No growth without resistance. No action without reaction. No desire without restraint.";
532
533
534 masters[8].name = "Jimmy Wang Yu";
535 masters[8].weapon = "Flying Guillotine";
536 masters[8].strength = 275;
537 masters[8].maxhp = 1200;
538 masters[8].gold = 0;
539 masters[8].exp = 0;
540 masters[8].death = "You have beaten the one armed boxer. Proceed with caution!";
541
542 masters[9].name = "Wong Fei Hung";
543 masters[9].weapon = "Drunken Boxing";
544 masters[9].strength = 350;
545 masters[9].maxhp = 1800;
546 masters[9].gold = 0;
547 masters[9].exp = 0;
548 masters[9].death = "";
549
550 masters[10].name = "Bruce Lee";
551 masters[10].strength = 575;
552 masters[10].maxhp = 2500;
553 masters[10].gold = 0;
554 masters[10].exp = 0;
555 masters[10].death = "You must learn to concentrate. It is like a finger pointing away to the moon... DONT concentrate on the finger, or you will miss all the heavenly glory.";
556}
85ce9d3e 557
558void init_monsters()
559{
560 // Hard coded for now - Kain
561 monsters[0][0].name = "Slime";
562 monsters[0][0].weapon = "Acid Goo";
563 monsters[0][0].strength = 6;
564 monsters[0][0].gold = 50;
565 monsters[0][0].exp = 3;
566 monsters[0][0].maxhp = 9;
567 monsters[0][0].death = "The slime oozes into nothing... you clean the acid goo off of your weapon";
568
569 monsters[0][1].name = "Ghost";
570 monsters[0][1].weapon = "Cold Breath";
571 monsters[0][1].strength = 8;
572 monsters[0][1].gold = 100;
573 monsters[0][1].exp = 10;
574 monsters[0][1].maxhp = 10;
575 monsters[0][1].death = "You feel a chill as the spirit leaves the realm.";
576
577 monsters[0][2].name = "Ugly Rodent";
578 monsters[0][2].weapon = "Sharp Teeth";
579 monsters[0][2].strength = 9;
580 monsters[0][2].gold = 75;
581 monsters[0][2].exp = 8;
582 monsters[0][2].maxhp = 13;
583 monsters[0][2].death = "You stomp on the Ugly Rodent's remains for a finishing blow.";
584
585 monsters[0][3].name = "Whart Hog";
586 monsters[0][3].weapon = "Tusks";
587 monsters[0][3].strength = 10;
588 monsters[0][3].gold = 80;
589 monsters[0][3].exp = 6;
590 monsters[0][3].maxhp = 10;
591 monsters[0][3].death = "You cook and eat the hog for good measure!";
592
593 monsters[0][4].name = "Pesky Kid";
594 monsters[0][4].weapon = "Slingshot";
595 monsters[0][4].strength = 8;
596 monsters[0][4].gold = 30;
597 monsters[0][4].exp = 4;
598 monsters[0][4].maxhp = 6;
599 monsters[0][4].death = "You take his slingshot and snap the band, sending the kid crying home to mom!";
600
601 monsters[0][5].name = "Playground Bully";
602 monsters[0][5].weapon = "Painful Noogie";
603 monsters[0][5].strength = 11;
604 monsters[0][5].gold = 44;
605 monsters[0][5].exp = 6;
606 monsters[0][5].maxhp = 10;
607 monsters[0][5].death = "You give him an indian burn, and punt him across the schoolyard!";
608
609 monsters[0][6].name = "Small Imp";
610 monsters[0][6].weapon = "Dagger";
611 monsters[0][6].strength = 6;
612 monsters[0][6].gold = 64;
613 monsters[0][6].exp = 10;
614 monsters[0][6].maxhp = 10;
615 monsters[0][6].death = "You can't help but laugh as he stumbles and falls onto his own dagger!";
616
617 monsters[0][7].name = "Little Monkey";
618 monsters[0][7].weapon = "Monkey Wrench";
619 monsters[0][7].strength = 6;
620 monsters[0][7].gold = 53;
621 monsters[0][7].exp = 9;
622 monsters[0][7].maxhp = 9;
623 monsters[0][7].death = "You want to cook it, but you just can't think of eating something that looks so human!";
624
625 monsters[0][8].name = "Grub Worm";
626 monsters[0][8].weapon = "Minor Nudge";
627 monsters[0][8].strength = 2;
628 monsters[0][8].gold = 10;
629 monsters[0][8].exp = 3;
630 monsters[0][8].maxhp = 3;
631 monsters[0][8].death = "You decide to save the poor little fella for your next fishing trip.";
632
633 monsters[0][9].name = "Drakee";
634 monsters[0][9].weapon = "Tail Slap";
635 monsters[0][9].strength = 5;
636 monsters[0][9].gold = 22;
637 monsters[0][9].exp = 7;
638 monsters[0][9].maxhp = 5;
639 monsters[0][9].death = "You pull the little Drakee by its tale and slam it down on a dry stump!";
640
641 monsters[0][10].name = "Fat Slob";
642 monsters[0][10].weapon = "Smelly Breath";
643 monsters[0][10].strength = 6;
644 monsters[0][10].gold = 40;
645 monsters[0][10].exp = 10;
646 monsters[0][10].maxhp = 7;
647 monsters[0][10].death = "You kick his stomach for fun, and are thrown back by the spring of it all!";
648
649 monsters[0][11].name = "Lost Warrior";
650 monsters[0][11].weapon = "Long Sword";
651 monsters[0][11].strength = 10;
652 monsters[0][11].gold = 250;
653 monsters[0][11].exp = 19;
654 monsters[0][11].maxhp = 15;
655 monsters[0][11].death = "You give him a proper burial in respect for the dead warrior.";
656
657 monsters[1][0].name = "Lost Warrior's Cousin Larry";
658 monsters[1][0].weapon = "Wood Axe";
659 monsters[1][0].strength = 19;
660 monsters[1][0].gold = 134;
661 monsters[1][0].exp = 24;
662 monsters[1][0].maxhp = 30;
663 monsters[1][0].death = "He was pretty pissed you killed his cousin, but he seems to have suffered the same fate!";
664
665 monsters[1][1].name = "Sandman";
666 monsters[1][1].weapon = "Sleeping Dust";
667 monsters[1][1].strength = 25;
668 monsters[1][1].gold = 80;
669 monsters[1][1].exp = 6;
670 monsters[1][1].maxhp = 27;
671 monsters[1][1].death = "You put the sandman to his final sleep.";
672
673 monsters[1][2].name = "Dirty Transvestite";
674 monsters[1][2].weapon = "Stiletto Heel";
675 monsters[1][2].strength = 21;
676 monsters[1][2].gold = 160;
677 monsters[1][2].exp = 12;
678 monsters[1][2].maxhp = 25;
679 monsters[1][2].death = "You shudder at the thought of ever mistaking this for a woman!";
680
681 monsters[1][3].name = "Goblin Gardener";
682 monsters[1][3].weapon = "Garden Spade";
683 monsters[1][3].strength = 18;
684 monsters[1][3].gold = 130;
685 monsters[1][3].exp = 8;
686 monsters[1][3].maxhp = 20;
687 monsters[1][3].death = "You trample on his garden after slaying him... that felt good!";
688
689 monsters[1][4].name = "Evil Elf";
690 monsters[1][4].weapon = "Elvish Bow";
691 monsters[1][4].strength = 23;
692 monsters[1][4].gold = 136;
693 monsters[1][4].exp = 13;
694 monsters[1][4].maxhp = 24;
695 monsters[1][4].death = "Elves are usually nice you thought... hmm.";
696
697 monsters[1][5].name = "Viking Warrior";
698 monsters[1][5].weapon = "Broad Sword";
699 monsters[1][5].strength = 21;
700 monsters[1][5].gold = 330;
701 monsters[1][5].exp = 20;
702 monsters[1][5].maxhp = 18;
703 monsters[1][5].death = "You heard vikings were big, but not THAT big you thought.";
704
705 monsters[1][6].name = "Wicked Witch";
706 monsters[1][6].weapon = "Cackling Laugh";
707 monsters[1][6].strength = 20;
708 monsters[1][6].gold = 130;
709 monsters[1][6].exp = 20;
710 monsters[1][6].maxhp = 26;
711 monsters[1][6].death = "Just for kicks, you splash some water on her and watch her melt.";
712
713 monsters[1][7].name = "Vampire Bat";
714 monsters[1][7].weapon = "Blood Sucking Fangs";
715 monsters[1][7].strength = 18;
716 monsters[1][7].gold = 125;
717 monsters[1][7].exp = 21;
718 monsters[1][7].maxhp = 29;
719 monsters[1][7].death = "You fry up the bat and eat it... needs garlic.";
720
721 monsters[1][8].name = "Thorn Bush";
722 monsters[1][8].weapon = "101 Thorns";
723 monsters[1][8].strength = 16;
724 monsters[1][8].gold = 94;
725 monsters[1][8].exp = 15;
726 monsters[1][8].maxhp = 25;
727 monsters[1][8].death = "You set the bush ablaze and roast some marshmallows.";
728
729 monsters[1][9].name = "Barbarian";
730 monsters[1][9].weapon = "Heavy Sword";
731 monsters[1][9].strength = 29;
732 monsters[1][9].gold = 250;
733 monsters[1][9].exp = 25;
734 monsters[1][9].maxhp = 30;
735 monsters[1][9].death = "You listen to him moan as he falls over dead.";
736
737 monsters[1][10].name = "Crypt Rat";
738 monsters[1][10].weapon = "Stinging Bite";
739 monsters[1][10].strength = 25;
740 monsters[1][10].gold = 119;
741 monsters[1][10].exp = 20;
742 monsters[1][10].maxhp = 26;
743 monsters[1][10].death = "You squash the little rodent for fear that it might not be dead.";
744
745 monsters[1][11].name = "Small Orc";
746 monsters[1][11].weapon = "blade";
747 monsters[1][11].strength = 28;
748 monsters[1][11].gold = 300;
749 monsters[1][11].exp = 30;
750 monsters[1][11].maxhp = 36;
751 monsters[1][11].death = "It's an ugly one, and it would've grown up to be a terror...";
752
753 monsters[2][0].name = "Teferi";
754 monsters[2][0].weapon = "Puzzle Box";
755 monsters[2][0].strength = 29;
756 monsters[2][0].gold = 380;
757 monsters[2][0].exp = 18;
758 monsters[2][0].maxhp = 29;
759 monsters[2][0].death = "It was a puzzling experience.";
760
761 monsters[2][1].name = "Spineless Thug";
762 monsters[2][1].weapon = "Spiked Bat";
763 monsters[2][1].strength = 37;
764 monsters[2][1].gold = 384;
765 monsters[2][1].exp = 27;
766 monsters[2][1].maxhp = 32;
767 monsters[2][1].death = "See you at the crossroads!";
768
769 monsters[2][2].name = "Pyromaniac";
770 monsters[2][2].weapon = "Pyrotechnics";
771 monsters[2][2].strength = 29;
772 monsters[2][2].gold = 563;
773 monsters[2][2].exp = 22;
774 monsters[2][2].maxhp = 45;
775 monsters[2][2].death = "He chants FIRE FIRE as he falls to the ground... a burning heap of flesh.";
776
777 monsters[2][3].name = "Evil Enchantress";
778 monsters[2][3].weapon = "Deadly Spell";
779 monsters[2][3].strength = 50;
780 monsters[2][3].gold = 830;
781 monsters[2][3].exp = 35;
782 monsters[2][3].maxhp = 35;
783 monsters[2][3].death = "She looked just about as good as she fought.";
784
785 monsters[2][4].name = "Killer Leprechaun";
786 monsters[2][4].weapon = "Gold Rush";
787 monsters[2][4].strength = 35;
788 monsters[2][4].gold = 1300;
789 monsters[2][4].exp = 30;
790 monsters[2][4].maxhp = 37;
791 monsters[2][4].death = "You steal his pot of gold... that's a lot of money!";
792
793 monsters[2][5].name = "Avalanche Rider";
794 monsters[2][5].weapon = "Huge Snowball";
795 monsters[2][5].strength = 32;
796 monsters[2][5].gold = 700;
797 monsters[2][5].exp = 32;
798 monsters[2][5].maxhp = 38;
799 monsters[2][5].death = "You take his snowboard and snap it in two!";
800
801 monsters[2][6].name = "Blundering Idiot";
802 monsters[2][6].weapon = "Stupidity";
803 monsters[2][6].strength = 14;
804 monsters[2][6].gold = 700;
805 monsters[2][6].exp = 20;
806 monsters[2][6].maxhp = 29;
807 monsters[2][6].death = "Now there's one person you don't feel sorry for killing!";
808
809 monsters[2][7].name = "Militant Anarchist";
810 monsters[2][7].weapon = "Molotov Cocktail";
811 monsters[2][7].strength = 33;
812 monsters[2][7].gold = 245;
813 monsters[2][7].exp = 45;
814 monsters[2][7].maxhp = 32;
815 monsters[2][7].death = "Order has been restored for now...";
816
817 monsters[2][8].name = "Scathe Zombies";
818 monsters[2][8].weapon = "Death Grip";
819 monsters[2][8].strength = 38;
820 monsters[2][8].gold = 763;
821 monsters[2][8].exp = 15;
822 monsters[2][8].maxhp = 45;
823 monsters[2][8].death = "That was perhaps the scariest experience of your life.";
824
825 monsters[2][9].name = "Spitting Llama";
826 monsters[2][9].weapon = "Spit Spray";
827 monsters[2][9].strength = 48;
828 monsters[2][9].gold = 638;
829 monsters[2][9].exp = 28;
830 monsters[2][9].maxhp = 34;
831 monsters[2][9].death = "You wipe the spit off your face and fling it back at the Llama.";
832
833 monsters[2][10].name = "Juggalo";
834 monsters[2][10].weapon = "Clown Axe";
835 monsters[2][10].strength = 60;
836 monsters[2][10].gold = 650;
837 monsters[2][10].exp = 30;
838 monsters[2][10].maxhp = 29;
839 monsters[2][10].death = "What is a Juggalo? I don't know!";
840
841 monsters[2][11].name = "The Boogie Man";
842 monsters[2][11].weapon = "Striking Fear";
843 monsters[2][11].strength = 46;
844 monsters[2][11].gold = 600;
845 monsters[2][11].exp = 35;
846 monsters[2][11].maxhp = 27;
847 monsters[2][11].death = "He's scared you for the very last time!";
848
849 monsters[3][0].name = "Living Fire";
850 monsters[3][0].weapon = "Scorching Wind";
851 monsters[3][0].strength = 55;
852 monsters[3][0].gold = 1100;
853 monsters[3][0].exp = 36;
854 monsters[3][0].maxhp = 55;
855 monsters[3][0].death = "You extinguish the Living Flame once and for all!";
856
857 monsters[3][1].name = "Raging Orc";
858 monsters[3][1].weapon = "Orcish Artillary";
859 monsters[3][1].strength = 89;
860 monsters[3][1].gold = 900;
861 monsters[3][1].exp = 25;
862 monsters[3][1].maxhp = 50;
863 monsters[3][1].death = "This orc was a bit tougher than you remembered!";
864
865 monsters[3][2].name = "Huge Tarantula";
866 monsters[3][2].weapon = "Tangling Web";
867 monsters[3][2].strength = 59;
868 monsters[3][2].gold = 1000;
869 monsters[3][2].exp = 35;
870 monsters[3][2].maxhp = 60;
871 monsters[3][2].death = "You're glad you overcame your arachniphobia so soon!";
872
873 monsters[3][3].name = "Rabid Wolf";
874 monsters[3][3].weapon = "Cujo Bite";
875 monsters[3][3].strength = 40;
876 monsters[3][3].gold = 1200;
877 monsters[3][3].exp = 47;
878 monsters[3][3].maxhp = 76;
879 monsters[3][3].death = "The mutt falls over dead as white foam drips from its deadly canines...";
880
881 monsters[3][4].name = "Goblin Fighter";
882 monsters[3][4].weapon = "Morning Star";
883 monsters[3][4].strength = 38;
884 monsters[3][4].gold = 700;
885 monsters[3][4].exp = 30;
886 monsters[3][4].maxhp = 75;
887 monsters[3][4].death = "He almost caught you with his chain mace, but you sliced off his head.";
888
889 monsters[3][5].name = "Grizzly Bear";
890 monsters[3][5].weapon = "Razor Claws";
891 monsters[3][5].strength = 68;
892 monsters[3][5].gold = 1747;
893 monsters[3][5].exp = 81;
894 monsters[3][5].maxhp = 51;
895 monsters[3][5].death = "It almost got you this time... better be careful";
896
897 monsters[3][6].name = "Skeleton Man";
898 monsters[3][6].weapon = "Leg Bone";
899 monsters[3][6].strength = 70;
900 monsters[3][6].gold = 597;
901 monsters[3][6].exp = 57;
902 monsters[3][6].maxhp = 60;
903 monsters[3][6].death = "As a finisher, you wind up with the broad side of your weapon and hit his skull off for a home run!";
904
905 monsters[3][7].name = "Young Werewolf";
906 monsters[3][7].weapon = "Howling Bites";
907 monsters[3][7].strength = 75;
908 monsters[3][7].gold = 1742;
909 monsters[3][7].exp = 65;
910 monsters[3][7].maxhp = 42;
911 monsters[3][7].death = "You scatter the wolf's body parts in hopes he will stay dead!";
912
913 monsters[3][8].name = "Dark Infantry";
914 monsters[3][8].weapon = "Flesh Reaper";
915 monsters[3][8].strength = 69;
916 monsters[3][8].gold = 870;
917 monsters[3][8].exp = 43;
918 monsters[3][8].maxhp = 65;
919 monsters[3][8].death = "Light has prevailed this time... but it's only so long before you meet again.";
920
921 monsters[3][9].name = "Erie Spirit";
922 monsters[3][9].weapon = "Deadly Grin";
923 monsters[3][9].strength = 63;
924 monsters[3][9].gold = 1300;
925 monsters[3][9].exp = 32;
926 monsters[3][9].maxhp = 50;
927 monsters[3][9].death = "His cousin the ghost was a little bit easier.";
928
929 monsters[3][10].name = "Gollum";
930 monsters[3][10].weapon = "Precious Treasure";
931 monsters[3][10].strength = 66;
932 monsters[3][10].gold = 1492;
933 monsters[3][10].exp = 73;
934 monsters[3][10].maxhp = 54;
935 monsters[3][10].death = "Gollum screams out \"MY PRECIOUS\" as his small body falls limp from your blow.";
936
937 monsters[3][11].name = "Rock Fighter";
938 monsters[3][11].weapon = "Small Boulders";
939 monsters[3][11].strength = 87;
940 monsters[3][11].gold = 1742;
941 monsters[3][11].exp = 99;
942 monsters[3][11].maxhp = 65;
943 monsters[3][11].death = "You dodge his last rock, and counter with a low blow, cutting off his legs.";
944
945
946 monsters[4][0].name = "Giant Sphinx";
947 monsters[4][0].weapon = "Ancient Curse";
948 monsters[4][0].strength = 120;
949 monsters[4][0].gold = 1000;
950 monsters[4][0].exp = 100;
951 monsters[4][0].maxhp = 80;
952 monsters[4][0].death = "You look in awe at the great wonder, collapsed at your feet!";
953
954 monsters[4][1].name = "Giant Ogre";
955 monsters[4][1].weapon = "Big Log";
956 monsters[4][1].strength = 130;
957 monsters[4][1].gold = 857;
958 monsters[4][1].exp = 175;
959 monsters[4][1].maxhp = 100;
960 monsters[4][1].death = "Your witz outmatched the ogres brawn... big dumb thing.";
961
962 monsters[4][2].name = "Massive Cockroach";
963 monsters[4][2].weapon = "Piercing Hiss";
964 monsters[4][2].strength = 125;
965 monsters[4][2].gold = 700;
966 monsters[4][2].exp = 150;
967 monsters[4][2].maxhp = 112;
968 monsters[4][2].death = "Where's the exterminator when you need one?";
969
970 monsters[4][3].name = "Big Venomous Snake";
971 monsters[4][3].weapon = "Poison Fangs";
972 monsters[4][3].strength = 140;
973 monsters[4][3].gold = 900;
974 monsters[4][3].exp = 175;
975 monsters[4][3].maxhp = 126;
976 monsters[4][3].death = "After killing this beast you check for puncture marks... you find none, luckily.";
977
978 monsters[4][4].name = "Lizard Man";
979 monsters[4][4].weapon = "Deadly Jaws";
980 monsters[4][4].strength = 145;
981 monsters[4][4].gold = 1250;
982 monsters[4][4].exp = 175;
983 monsters[4][4].maxhp = 150;
984 monsters[4][4].death = "His scales made for tough armor, and his jaws for a tougher opponent!";
985
986 monsters[4][5].name = "Face Dancer";
987 monsters[4][5].weapon = "Illusion Scyth";
988 monsters[4][5].strength = 138;
989 monsters[4][5].gold = 1603;
990 monsters[4][5].exp = 198;
991 monsters[4][5].maxhp = 173;
992 monsters[4][5].death = "His carcus takes the shape of many things before it dies. His true form is so repulsive, you know why he changed faces so much!";
993
994 monsters[4][6].name = "Darklord Longbow Archer";
995 monsters[4][6].weapon = "Deadly Bow and Arrows";
996 monsters[4][6].strength = 145;
997 monsters[4][6].gold = 1569;
998 monsters[4][6].exp = 243;
999 monsters[4][6].maxhp = 170;
1000 monsters[4][6].death = "Your face turns white with horror after you realize you just met the devil's protector!";
1001
1002 monsters[4][7].name = "Hell's Paladin";
1003 monsters[4][7].weapon = "Sword of Hellfire";
1004 monsters[4][7].strength = 200;
1005 monsters[4][7].gold = 2191;
1006 monsters[4][7].exp = 254;
1007 monsters[4][7].maxhp = 175;
1008 monsters[4][7].death = "This is starting to get tough you think. Do you really want to go to level 12?";
1009
1010 monsters[4][8].name = "The Unknown Soldier";
1011 monsters[4][8].weapon = "Soul Torture";
1012 monsters[4][8].strength = 175;
1013 monsters[4][8].gold = 1890;
1014 monsters[4][8].exp = 200;
1015 monsters[4][8].maxhp = 180;
1016 monsters[4][8].death = "Who was that? Where was he from? And what was that weapon??";
1017
1018 monsters[4][9].name = "Undead Cult Leader";
1019 monsters[4][9].weapon = "Lance of Deceit";
1020 monsters[4][9].strength = 180;
1021 monsters[4][9].gold = 1792;
1022 monsters[4][9].exp = 195;
1023 monsters[4][9].maxhp = 190;
1024 monsters[4][9].death = "His words fall on deaf ears... this is one cult you will NOT be part of!";
1025
1026 monsters[4][10].name = "Water Serpent";
1027 monsters[4][10].weapon = "Forked Tongue";
1028 monsters[4][10].strength = 150;
1029 monsters[4][10].gold = 1500;
1030 monsters[4][10].exp = 176;
1031 monsters[4][10].maxhp = 220;
1032 monsters[4][10].death = "The serpent squeals as you cut off its head!";
1033
1034 monsters[4][11].name = "Silverback Gorilla";
1035 monsters[4][11].weapon = "Deadly Banana Peel";
1036 monsters[4][11].strength = 160;
1037 monsters[4][11].gold = 1300;
1038 monsters[4][11].exp = 150;
1039 monsters[4][11].maxhp = 178;
1040 monsters[4][11].death = "Was that gorilla or guerilla?";
1041}
1042
1043void display_monster(char *u)
1044{
1045 if (is_playing(u))
1046 {
1047 aClient *user = find(u);
1048 Player *ni = user->stats;
1049
1050 notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", ni->hp);
1051 notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", ni->fight->name, ni->fight->hp);
1052 notice(s_GameServ, u, "Here are your commands:");
1053 notice(s_GameServ, u, "/msg %S attack");
1054 notice(s_GameServ, u, "/msg %S run");
1055 notice(s_GameServ, u, "What will you do?");
1056 }
1057}
1058
1059void display_players(char *u)
1060{
1061 if (is_playing(u))
1062 {
1063 aClient *ni = find(u);
1064
1065 aClient *battle = ni->stats->battle;
1066
1067 notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", ni->stats->hp);
1068 notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", battle->getNick(),
1069 battle->stats->hp);
1070
1071 notice(s_GameServ, u, "Here are your commands:");
1072 notice(s_GameServ, u, "/msg %s attack", s_GameServ);
1073 notice(s_GameServ, u, "/msg %s run", s_GameServ);
1074 notice(s_GameServ, u, "What will you do?");
1075 }
1076}
1077
1078
1079bool is_playing(char *u)
1080{
1081 aClient *user;
1082 if (!(user = find(u)))
1083 {
1084 return false;
1085 }
1086 else
1087 {
1088 return user->stats != NULL;
1089 }
1090}
1091
1092bool is_fighting(char *u)
1093{
1094 aClient *user;
1095
1096 if (!(user = find(u)))
1097 {
1098 return false;
1099 }
1100 else if (user->stats)
1101 {
1102 return user->stats->fight != NULL || user->stats->battle != NULL
1103 || user->stats->master != NULL;
1104 }
1105 else
1106 return false;
1107}
1108
1109bool player_fight(char *u)
1110{
1111 aClient *user;
1112
1113 if (!(user = find(u)))
1114 return false;
1115 else if (user->stats)
1116 return user->stats->battle != NULL;
1117 else
1118 return false;
1119}
1120
1121bool master_fight(char *u)
1122{
1123 aClient *user;
1124
1125 if (!(user = find(u)))
1126 return false;
1127 else if (user->stats)
1128 return user->stats->master != NULL;
1129 else
1130 return false;
1131}
1132
1133bool isnt_fighting(char *u)
1134{
1135 return !is_fighting(u);
1136}
1137
1138void do_fight(char *u)
1139{
1140 aClient *ni, *battle;
1141
1142 char *nick = strtok(NULL, " ");
1143
1144 if (!nick)
1145 {
1146 notice(s_GameServ, u, "SYNTAX: /msg %S FIGHT PLAYER");
1147 }
1148 else if (!(ni = find(u)))
1149 {
1150 return;
1151 }
1152 else if (!(battle = find(nick)))
1153 {
1154 notice(s_GameServ, u, "You can't attack %s while they aren't playing!", nick);
1155 }
1156 else if (!is_playing(u))
1157 {
1158 notice(s_GameServ, u, "You are not playing!");
1159 }
1160/*
1161 * Offline fighting not implemented yet.
1162 * else if (!(fight = finduser(nick)))
1163 * {
1164 * ni->stats->battle = battle;
1165 * battle->battle = ni;
1166 * ni->yourturn = 1;
1167 * battle->yourturn = 0;
1168 * notice(s_GameServ, u, "You decide to fight %s while they're not online!",
1169 * battle->getNick());
1170 * display_players(u);
1171 * }
1172 */
1173 else if (is_playing(u) && is_playing(nick))
1174 {
1175 // Set your battle pointer to the other player
1176 ni->stats->battle = battle;
1177
1178 // Set the other player's battle pointer to you
1179 battle->stats->battle = ni;
1180
1181 // The initiator gets the first move (perhaps this should be 50/50)
1182 ni->stats->yourturn = 1;
1183 battle->stats->yourturn = 0;
1184
1185 // Initiate Battle sequence!
1186 notice(s_GameServ, u, "You challenge %s to an online duel!", battle->getNick());
1187 notice(s_GameServ, battle->getNick(), "%s has challenged you to an online duel!", u);
1188 notice(s_GameServ, battle->getNick(), "%s gets to go first because he initiated!", u);
1189 notice(s_GameServ, battle->getNick(), "Please wait while %s decides what to do.", u);
1190 display_players(u);
1191 }
1192}
1193
1194void do_attack(char *u)
1195{
1196 int hit, mhit;
1197 aClient *ni, *battle; // The player and perhaps the player they're fighting
1198 Monster *fight; // The monster they may be fighting
1199
1200 if (!(ni = find(u)))
1201 {
1202 notice(s_GameServ, u, "You're not playing!");
1203 return;
1204 }
1205 else if (!ni->stats->fight && !ni->stats->battle && !ni->stats->master)
1206 {
1207 notice(s_GameServ, u, "You're not in battle!");
1208 return;
1209 }
1210 else
1211 {
1212 if (!ni->stats->master) // This is not a master fight
1213 fight = ni->stats->fight; // Monster Could be NULL
1214 else // This IS a master fight
1215 fight = ni->stats->master; // Master Could be NULL
1216
1217 battle = ni->stats->battle; // Player Could be NULL
1218
1219 // One has to be !NULL based on the previous else if
1220 // We wouldn't be here if they were all NULL
1221 }
1222
1223 if (!player_fight(u))
1224 {
1225 // Player's Hit
1226 hit = ((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
1227 (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2));
1228
1229 // Opponent's Hit
1230 mhit = (fight->strength / 2) +
1231 (rand() % (fight->strength / 2) - (ni->stats->defense +
1232 arbonus[ni->stats->armor]));
1233 }
1234 else
1235 {
1236 // Opponent's Hit
1237 mhit = (((battle->stats->strength + webonus[battle->stats->weapon]) / 2) +
1238 (rand() % ((battle->stats->strength + webonus[battle->stats->weapon])) / 2) -
1239 (ni->stats->defense + arbonus[ni->stats->armor]));
1240
1241 // Player's Hit
1242 hit = (((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
1243 (rand() % ((ni->stats->strength + webonus[ni->stats->weapon])) / 2) -
1244 (battle->stats->defense + arbonus[battle->stats->armor]));
1245 }
1246
1247 if (!player_fight(u))
1248 {
1249 if (hit > 0)
1250 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", fight->name, hit);
1251 else
1252 notice(s_GameServ, u, "You miss \1f%s\1f completely!", fight->name);
1253
1254 if (hit >= fight->hp)
1255 {
1256 if (master_fight(u))
1257 notice(s_GameServ, u, "You have bested %s!", fight->name);
1258 else
1259 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", fight->name);
1260
1261 notice(s_GameServ, u, "%s", fight->death);
1262 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%d\ 2 gold!",
1263 fight->exp, fight->gold);
1264
1265 // If your new experience (or gold) will be greater than 2 billion,
1266 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1267 // This could be a problem with overflowing out of the sign bit.
1268 // Unsigned long int maybe? Leave it for now.
1269 ni->stats->exp = ( (ni->stats->exp + fight->exp) > 2000000000 ? 2000000000 :
1270 ni->stats->exp + fight->exp);
1271 ni->stats->gold = (ni->stats->gold + fight->gold > 2000000000 ? 2000000000 :
1272 ni->stats->gold + fight->gold);
1273 ni->stats->fight = NULL; // They're dead so remove the pointer
1274
1275 if (master_fight(u))
1276 {
1277 notice(s_GameServ, u, "You are now level %d!", ni->stats->level + 1);
1278 notice(s_GameServ, u, "You gain %d Strength, and %d Defense points!",
1279 strbonus[ni->stats->level - 1], defbonus[ni->stats->level - 1]);
1280
1281 // Increase your level
1282 ni->stats->level++;
1283
1284 // Increase your maximum hit points
1285 ni->stats->maxhp += hpbonus[ni->stats->level - 1];
1286
1287 // Heal the player by setting hp to their max
1288 ni->stats->hp = ni->stats->maxhp;
1289
1290 // Add to your strength
1291 ni->stats->strength += strbonus[ni->stats->level - 1];
1292
1293 // Add to your defensive power
1294 ni->stats->defense += defbonus[ni->stats->level - 1];
1295
1296 // Clear the pointer for your master
1297 ni->stats->master = NULL;
1298 }
1299 return;
1300 }
1301 else
1302 {
1303 if (hit > 0)
1304 fight->hp -= hit;
1305 if (mhit > 0)
1306 {
1307 notice(s_GameServ, u, "\1f%s\1f hits you with their \1f%s\1f for \ 2%d\ 2 damage!",
1308 fight->name, fight->weapon, mhit);
1309 }
1310 else if (mhit <= 0)
1311 notice(s_GameServ, u, "%s completely misses you!", fight->name);
1312
1313 if (mhit >= ni->stats->hp)
1314 {
1315 if (!master_fight(u))
1316 {
1317 notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight->name);
1318 notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\
1319 "of your experience!");
1320 ni->stats->gold = 0;
1321 ni->stats->exp -= (long int)(ni->stats->exp * .10);
1322 ni->stats->fight = NULL;
1323 return;
1324 }
1325 else
1326 {
1327 notice(s_GameServ, u, "%s has bested you! You will have to wait "\
1328 "until tomorrow to try again", ni->stats->master->name);
1329 ni->stats->fight = NULL;
1330 ni->stats->master = NULL;
1331 return;
1332 }
1333 }
1334 else
1335 {
1336 if (mhit > 0)
1337 ni->stats->hp -= mhit;
1338 display_monster(u);
1339 return;
1340 }
1341 }
1342 }
1343 else if (player_fight(u))
1344 {
1345/* Offline fighting not available yet
1346 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1347 {
1348 if (hit > 0)
1349 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->nick, hit);
1350 else
1351 notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->nick);
1352 if (hit >= battle->stats->hp)
1353 {
1354 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->nick);
1355* notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!",
1356 (long int)(battle->stats->exp * .10), battle->stats->gold);
1357 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1358 {
1359 ni->stats->exp += (long int)(battle->stats->exp * .10);
1360 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1361 }
1362* else
1363 {
1364 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1365 ni->stats->exp = 2000000000;
1366 }
1367
1368 if (2000000000 - ni->stats->gold > battle->stats->gold)
1369 {
1370* ni->stats->gold += battle->stats->gold;
1371 battle->stats->gold = 0;
1372 }
1373 else
1374 {
1375 battle->stats->gold = 2000000000 - ni->stats->gold;
1376 ni->stats->gold = 2000000000;
1377 }
1378* ni->stats->battle->stats->alive = 0;
1379 ni->stats->battle->battle = NULL;
1380 ni->stats->battle = NULL;
1381 return;
1382 }
1383 else
1384 {
1385 if (hit > 0)
1386* battle->stats->hp -= hit;
1387 if (mhit > 0)
1388 {
1389 notice(s_GameServ, u, "\1f%s\1f hits you with their \1f%s\1f for \ 2%d\ 2 damage!",
1390 battle->nick, weapons[battle->stats->weapon], mhit);
1391 }
1392 else if (mhit <= 0)
1393 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1394*
1395 if (mhit >= ni->stats->hp)
1396 {
1397 notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", battle->nick);
1398 if (2000000000 - battle->stats->gold > ni->stats->gold)
1399 {
1400 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1401 battle->stats->gold += ni->stats->gold;
1402* ni->stats->gold = 0;
1403 }
1404 else
1405 {
1406 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1407 battle->nick);
1408 ni->stats->gold -= (2000000000 - battle->stats->gold);
1409 notice(s_GameServ, u, "You were left dead with %d gold.",
1410* (long int)ni->stats->gold);
1411 battle->stats->gold = 2000000000;
1412 }
1413 ni->stats->battle->battle = NULL;
1414 ni->stats->battle = NULL;
1415 ni->stats->alive = 0;
1416 return;
1417 }
1418* else
1419 {
1420 if (mhit > 0)
1421 ni->stats->hp -= mhit;
1422 display_players(u);
1423 return;
1424 }
1425 }
1426 }
1427* end offline fighting */
1428
1429 if (is_playing(battle->getNick()))
1430 {
1431 if (ni->stats->yourturn == 0)
1432 {
1433 notice(s_GameServ, u, "Please wait until %s decides what to do!",
1434 battle->getNick());
1435 return;
1436 }
1437 if (hit > 0)
1438 {
1439 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->getNick(), hit);
1440
1441 notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\
1442 "\ 2%d\ 2 damage!", u, weapons[ni->stats->weapon],
1443 hit);
1444 ni->stats->yourturn = 0;
1445 battle->stats->yourturn = 1;
1446 display_players(battle->getNick());
1447 }
1448 else
1449 {
1450 notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->getNick());
1451 notice(s_GameServ, battle->getNick(), "%s misses you completely!", u);
1452 ni->stats->yourturn = 0;
1453 battle->stats->yourturn = 1;
1454 display_players(battle->getNick());
1455 }
1456 if (hit >= battle->stats->hp)
1457 {
1458 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->getNick());
1459 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!",
1460 (long int)(battle->stats->exp * .10), battle->stats->gold);
1461 notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!", u);
1462 battle->stats->hp = 0;
1463 battle->stats->alive = 0;
1464
1465 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1466 {
1467 ni->stats->exp += (long int)(battle->stats->exp * .10);
1468 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1469 }
1470 else
1471 {
1472 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1473 ni->stats->exp = 2000000000;
1474 }
1475
1476 if (2000000000 - ni->stats->gold > battle->stats->gold)
1477 {
1478 notice(s_GameServ, battle->getNick(), "You lose ten percent of experience and "\
1479 "all gold on hand!");
1480 ni->stats->gold += battle->stats->gold;
1481 battle->stats->gold = 0;
1482 }
1483 else
1484 {
1485 battle->stats->gold = 2000000000 - ni->stats->gold;
1486 notice(s_GameServ, battle->getNick(), "You lose ten percent of your experience!");
1487
1488 notice(s_GameServ, battle->getNick(), "However, %s could not carry all of your "\
1489 "gold.", u);
1490
1491 notice(s_GameServ, battle->getNick(), "Luckily, you still have \ 2%ld\ 2 gold "\
1492 "left. All is not lost!", battle->stats->gold);
1493
1494 ni->stats->gold = 2000000000;
1495 }
1496 battle->stats->battle = NULL;
1497 ni->stats->battle = NULL;
1498 return;
1499 }
1500 else
1501 {
1502 if (hit > 0)
1503 battle->stats->hp -= hit;
1504 //display_players(battle->getNick());
1505 ni->stats->yourturn = 0;
1506 battle->stats->yourturn = 1;
1507 notice(s_GameServ, u, "Please wait while %s decides what to do!",
1508 battle->getNick());
1509
1510 return;
1511 }
1512 }
1513 }
1514}
1515void do_heal(char *u)
1516{
1517 aClient *ni;
1518 char *amount = strtok(NULL, " ");
1519 int price, num;
1520
1521 if (!amount)
1522 {
1523 notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}");
1524 }
1525 else if (!(ni = find(u)) || !ni->stats)
1526 {
1527 notice(s_GameServ, u, "You aren't playing!");
1528 }
1529 else if (is_fighting(u))
1530 {
1531 notice(s_GameServ, u, "You can't heal in battle!");
1532 }
1533 else if (ni->stats->hp >= ni->stats->maxhp)
1534 {
1535 notice(s_GameServ, u, "You don't need healing!");
1536 }
1537 else if (stricmp(amount, "ALL") == 0)
1538 {
1539 price = ni->stats->level * 3;
1540 if (ni->stats->gold < (ni->stats->maxhp - ni->stats->hp) * price)
1541 {
1542 notice(s_GameServ, u, "Healing \ 2%d\ 2 points for \ 2%d\ 2 gold per point.",
1543 (long int)ni->stats->gold/price, price);
1544 ni->stats->hp += ni->stats->gold / price;
1545 ni->stats->gold %= price;
1546 }
1547 else
1548 {
1549 notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\
1550 "per point.", price);
ad7dfaa0 1551 notice(s_GameServ, u, "\ 2%d\ 2 points healed for \ 2%ld\ 2 gold. HP at MAX!",
1552 (ni->stats->maxhp - ni->stats->hp),
1553 (price * (ni->stats->maxhp - ni->stats->hp)) );
85ce9d3e 1554 ni->stats->gold -= price * (ni->stats->maxhp - ni->stats->hp);
1555 ni->stats->hp = ni->stats->maxhp;
1556 }
1557 }
1558 else if (isstringnum(amount))
1559 {
1560 num = stringtoint(amount);
1561 price = ni->stats->level * 3;
1562 if (ni->stats->gold < price * num)
1563 {
1564 notice(s_GameServ, u, "You only have enough gold to heal \ 2%d\ 2 points!",
1565 (long int)ni->stats->gold/price);
1566 }
1567 else if (num <= ni->stats->maxhp - ni->stats->hp)
1568 {
1569 notice(s_GameServ, u, "Healing \ 2%d\ 2 points at \ 2%d\ 2 gold per point.",
1570 num, price);
1571 ni->stats->hp += num;
1572 ni->stats->gold -= num * price;
1573 }
1574 else if (num > ni->stats->maxhp - ni->stats->hp)
1575 {
1576 notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\
1577 "per point.", price);
1578 notice(s_GameServ, u, "\ 2%d\ 2 points healed. HP at MAX!",
1579 (ni->stats->maxhp - ni->stats->hp));
1580 ni->stats->gold -= price * (ni->stats->maxhp - ni->stats->hp);
1581 ni->stats->hp = ni->stats->maxhp;
1582 }
1583 }
1584 else if (amount[0] == '-')
1585 notice(s_GameServ, u, "You trying to cheat?");
1586 else
1587 notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}");
1588}
1589
1590int isstringnum(char *num)
1591{
1592 int x;
1593 for (x = 0; x < strlen(num); x++)
1594 {
1595 if ((int)num[x] < 48 || (int)num[x] > 57)
1596 return 0;
1597 }
1598return 1;
1599}
1600
1601long int stringtoint(char *number)
1602{
8c126acc 1603 cout << "stringtoint: " << number << endl;
85ce9d3e 1604 long int x, len = strlen(number), sum = 0;
1605 if (len == 1)
1606 return chartoint(number[0]);
1607 sum += chartoint(number[len - 1]);
1608 for (x = len - 2; x >= 0; x--)
1609 {
8c126acc 1610 cout << "Adding: " << chartoint(number[x]) * pow(10, abs(x - len + 1)) <<
1611 endl;
85ce9d3e 1612 sum += chartoint(number[x]) * pow(10, abs(x - len + 1));
1613 }
1614 return sum;
1615}
1616
1617long int pow(int x, int y)
1618{
1619 long int value = 0;
1620 int count = 0;
1621 value += x;
1622
1623 if (x != 0 && y != 0)
1624 {
1625 for (count = 1; count <= y - 1; count++)
1626 value *= x;
1627 }
1628 else
1629 return 1;
1630return value;
1631}
1632
1633long int chartoint(char ch)
1634{
8c126acc 1635 if (int(ch) >= 48 && int(ch) <= 57)
1636 return int(ch) - 48;
1637 else
1638 return 0;
85ce9d3e 1639}
1640
1641int save_gs_dbase()
1642{
1643 ListNode<aClient> *ptr = players.First();
1644 Player *it;
1645 ofstream outfile;
1646
1647 outfile.open(playerdata);
1648
1649 if (!outfile)
1650 {
1651 cerr << "Error opening " << playerdata << endl;
1652 return 0;
1653 }
1654
1655 while(ptr)
1656 {
1657 it = ptr->getData()->stats;
1658 outfile << it->name << ' ' << it->level << ' ' << it->exp << ' ' << it->gold << ' ' << it->bank << ' '
1659 << it->hp << ' ' << it->maxhp << ' ' << it->strength << ' ' << it->defense << ' '
1660 << it->armor << ' ' << it->weapon << ' ' << (it->alive ? "alive" : "dead") << ' '
e3c5fe46 1661 << it->forest_fights << ' ' << it->player_fights << ' '
1662 << it->password << endl;
85ce9d3e 1663 ptr = ptr->Next();
1664 }
1665outfile.close();
1666}
1667
1668int load_gs_dbase()
1669{
1670 ifstream infile;
1671 aClient *temp;
1672 Player *p;
e3c5fe46 1673 char *alive, *tempname, *buf, *password;
85ce9d3e 1674 buf = new char[1023];
1675
1676 infile.open(playerdata);
1677
1678 if (infile.fail())
1679 {
1680 cerr << "Error opening " << playerdata << endl;
1681 return 0;
1682 }
1683
1684 while (infile.getline(buf, 1024, '\n'))
1685 {
cbf6551f 1686 cout << "temp = new aClient;" << endl << flush;
85ce9d3e 1687 temp = new aClient;
cbf6551f 1688 cout << "tempname = strtok(buf, " ");" << endl << flush;
85ce9d3e 1689 tempname = strtok(buf, " ");
cbf6551f 1690
1691 cout << "temp->stats = new Player(tempname);" << endl << flush;
1692
85ce9d3e 1693 temp->stats = new Player(tempname);
cbf6551f 1694
1695 cout << "p = temp->stats;" << endl << flush;
85ce9d3e 1696 p = temp->stats;
1697
1698 //Kain 1 1 0 500 10 10 0 0 1 1 alive 100 3
1699 p->level = stringtoint(strtok(NULL, " "));
1700 p->exp = stringtoint(strtok(NULL, " "));
1701 p->gold = stringtoint(strtok(NULL, " "));
1702 p->bank = stringtoint(strtok(NULL, " "));
1703 p->hp = stringtoint(strtok(NULL, " "));
1704 p->maxhp = stringtoint(strtok(NULL, " "));
1705 p->strength = stringtoint(strtok(NULL, " "));
1706 p->defense = stringtoint(strtok(NULL, " "));
1707 p->armor = stringtoint(strtok(NULL, " "));
1708 p->weapon = stringtoint(strtok(NULL, " "));
1709 alive = strtok(NULL, " ");
1710 p->alive = (stricmp(alive, "ALIVE") == 0 ? true : false);
1711 p->forest_fights = stringtoint(strtok(NULL, " "));
1712 p->player_fights = stringtoint(strtok(NULL, " "));
e3c5fe46 1713 password = strtok(NULL, " ");
1714 strcpy(p->password, password);
85ce9d3e 1715 temp->setNick("NULL");
1716
e3c5fe46 1717 printf("%s %d %ld %ld %ld %d %d %d %d %d %d %s %d %d %s\n", p->name, p->level,
1718 p->exp, p->gold, p->bank, p->hp, p->maxhp, p->strength, p->defense, p->armor, p->weapon,
1719 alive, p->forest_fights, p->player_fights, p->password);
1720
cbf6551f 1721 cout << "Inserting " << temp->stats->name << " at back of list" << endl;
85ce9d3e 1722 players.insertAtBack(temp);
cbf6551f 1723 cout << temp->stats->name << " Inserted, now deleting" << endl;
85ce9d3e 1724 delete temp;
cbf6551f 1725 cout << "Deleted" << endl;
85ce9d3e 1726 }
1cf88153 1727delete [] buf;
85ce9d3e 1728}
1729
e3c5fe46 1730bool passcmp(char *encrypted, char *plaintext)
1731{
1732 char salt[3];
cdc9a6db 1733 char *plaintext2, *plainToencrypt;
1734 bool same = false;
1735
1736 plaintext2 = new char[strlen(encrypted) + strlen(plaintext)]; // Extra
1737 strcpy(plaintext2, plaintext);
1738
e3c5fe46 1739 salt[0] = encrypted[0];
1740 salt[1] = encrypted[1];
1741 salt[3] = '\0';
cdc9a6db 1742
1743 plainToencrypt = crypt(plaintext2, salt);
1744
1745 same = (strcmp((const char *)encrypted, plainToencrypt) == 0 ? true : false);
1746
1747 delete []plaintext2;
1748
1749 return same;
e3c5fe46 1750}
1751
1752bool check_password(char *name, char *plaintext)
1753{
0a1518fa 1754 aClient *client;
e3c5fe46 1755
0a1518fa 1756 if (!(client = findplayer(name)))
1757 return false;
1758 else
e3c5fe46 1759 {
0a1518fa 1760 return passcmp(client->stats->password, plaintext);
e3c5fe46 1761 }
e3c5fe46 1762}
1cf88153 1763
ad7dfaa0 1764void do_store(char *u)
1765{
1766 char *cmd = strtok(NULL, " ");
1767 char *item = strtok(NULL, " ");
1768 char *num = strtok(NULL, " ");
1769 char *space;
8c126acc 1770 int wep;
1771 aClient *user;
1772 Player *p;
ad7dfaa0 1773
8c126acc 1774 if (!is_playing(u) || !(user = find(u)))
1775 notice(s_GameServ, u, "You must be playing to use the store!");
1776 else if (!cmd || !item)
ad7dfaa0 1777 {
1778 notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
1779 notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2");
1780 notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2");
1781 }
1782 else if (stricmp(cmd, "LIST") == 0)
1783 {
1784 if (stricmp(item, "WEAPONS") == 0)
1785 {
1786 notice(s_GameServ, u, "Welcome to Kain's Armory");
1787 notice(s_GameServ, u, "Here are the weapons we have available for the killing, sire:");
1788 for (int x = 1; x < WNA; x++)
1789 {
1790 space = spaces(strlen(weapons[x]), ".");
1791 notice(s_GameServ, u, "%s%d. %s%s%d",(x < 10 ? " " : ""), x, weapons[x], space, prices[x - 1]);
1792 free(space);
1793 }
1794 notice(s_GameServ, u, "To purchase a weapon, type /msg %S STORE BUY \ 2NUM\ 2.");
1795 notice(s_GameServ, u, "Where num. is the weapon number from the menu above.");
1796
1797 }
1798 else if (stricmp(item, "ARMOR") == 0)
1799 {
1800 notice(s_GameServ, u, "Welcome to Kain's Armory");
1801 notice(s_GameServ, u, "I hope you enjoy the fine armor we have available for your protection:");
1802 for (int x = 1; x < WNA; x++)
1803 {
1804 space = spaces(strlen(armors[x]), ".");
1805 notice(s_GameServ, u, "%s%d. %s%s%d",(x < 10 ? " " : ""), x, armors[x], space, prices[x - 1]);
1806 free(space);
1807 }
1808 notice(s_GameServ, u, "To purchase armor, type /msg %S store buy armor num.");
1809 notice(s_GameServ, u, "Where num. is the armor number from the menu above.");
1810
1811
1812 }
1813 } else if (stricmp(cmd, "BUY") == 0) {
8c126acc 1814 if (!num)
1815 {
1816 notice(s_GameServ, u, "SYNTAX: \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2");
1817 return;
1818 }
1819 else if (!isstringnum(num))
1820 {
1821 notice(s_GameServ, u, "You must specify a number between 1 and %d. Not %s!", WNA - 1, num);
1822 return;
1823 }
1824 if (stricmp(item, "WEAPON") == 0)
1825 {
1826 wep = stringtoint(num);
1827 if (wep >= WNA || wep < 1)
1828 {
1829 notice(s_GameServ, u, "The number %d is out of range. The number you provide must be between 1 and %d.", wep, WNA - 1);
1830 return;
1831 }
1832
1833 p = user->stats;
1834
1835 if (p->weapon != 0)
1836 notice(s_GameServ, u, "You have to sell your %s first!", weapons[p->weapon]);
1837 else if (p->gold < prices[wep - 1])
1838 notice(s_GameServ, u, "You don't have enough gold for %s!", weapons[wep]);
1839 else
1840 {
1841 notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", weapons[wep]);
1842 p->weapon = wep;
1843 p->gold -= prices[wep - 1];
1844 }
1845 }
1846 else if (stricmp(item, "ARMOR") == 0)
1847 {
1848 wep = stringtoint(num);
1849 if (wep >= WNA || wep < 1)
1850 {
1851 notice(s_GameServ, u, "The number %d is out of range. The number you provide must be between 1 and %d.", wep, WNA - 1);
1852 return;
1853 }
1854
1855 p = user->stats;
1856
1857 if (p->armor != 0)
1858 notice(s_GameServ, u, "You have to sell your %s first!", armors[p->armor]);
1859 else if (p->gold < prices[wep - 1])
1860 notice(s_GameServ, u, "You don't have enough gold for %s!", armors[wep]);
1861 else
1862 {
1863 notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", armors[wep]);
1864 p->armor = wep;
1865 p->gold -= prices[wep - 1];
1866 }
1867 }
1868 }
1869 else if (stricmp(cmd, "SELL" ) == 0)
1870 {
1871 p = user->stats;
1872
1873 if (stricmp(item, "WEAPON") == 0)
1874 {
1875 if (p->weapon == 0)
1876 {
1877 notice(s_GameServ, u, "You want me to chop off your hands?");
1878 return;
1879 }
1880 else if (p->gold == 2000000000)
1881 {
1882 notice(s_GameServ, u, "You have enough gold. I'll just take that off your hands, sire.");
1883 p->weapon = 0;
1884 }
1885 else if (2000000000 - p->gold < (prices[p->weapon - 1] / 2))
1886 {
1887 notice(s_GameServ, u, "Thank you for your business! You now have as much gold as you can carry.");
1888 notice(s_GameServ, u, "However, you have no weapon... can I interest you in the %s?", weapons[WNA - 1]);
1889 p->gold = 2000000000;
1890 p->weapon = 0;
1891 }
1892 else
1893 {
1894 notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no weapon!", (prices[p->weapon - 1] / 2));
1895 p->gold += (prices[p->weapon - 1] / 2);
1896 p->weapon = 0;
1897 }
1898 }
1899 else if (stricmp(item, "ARMOR") == 0)
1900 {
1901 p = user->stats;
1902
1903 if (p->armor == 0)
1904 {
1905 notice(s_GameServ, u, "I don't think you can be any more naked...");
1906 return;
1907 }
1908 if (p->gold == 2000000000)
1909 {
1910 notice(s_GameServ, u, "You have enough gold. I'll just take that off your hands, sire.");
1911 p->armor = 0;
1912 }
1913 else if (2000000000 - p->gold < (prices[p->armor - 1] / 2))
1914 {
1915 notice(s_GameServ, u, "Thank you for your business! You now have as much gold as you can carry.");
1916 notice(s_GameServ, u, "However, you have no armor... can I interest you in %s?", armors[WNA - 1]);
1917 p->gold = 2000000000;
1918 p->armor = 0;
1919 }
1920 else
1921 {
1922 notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no armor!",
1923 (prices[p->armor - 1] / 2));
1924
1925 p->gold += (prices[p->armor - 1] / 2);
1926 p->armor = 0;
1927 }
1928 }
1929 else
1930 {
1931 notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
1932 notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2");
1933 notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2");
1934 }
1935 }
1936}
1937
1938void do_bank(char *u)
1939{
1940 char *cmd = strtok(NULL, " ");
1941 char *amount = strtok(NULL, " ");
1942 char *nick = strtok(NULL, " ");
1943
1944 aClient *user;
1945 Player *p;
1946
1947 if (!cmd || !amount || (stricmp(cmd, "TRANSFER") == 0 && !nick))
1948 {
1949 notice(s_GameServ, u, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}");
1950 return;
1951 }
1952 else if (!is_playing(u) || !(user = find(u)))
1953 {
1954 notice(s_GameServ, u, "You must be playing to use the bank!");
1955 return;
ad7dfaa0 1956 }
8c126acc 1957 else if (!isstringnum(amount) && stricmp(amount, "ALL") != 0)
1958 {
1959 notice(s_GameServ, u, "I don't know how to convert alphabet letters into currency, sire!");
1960 return;
1961 }
1962
1963 p = user->stats;
1964
1965 if (stricmp(cmd, "DEPOSIT") == 0)
1966 {
1967 if (p->bank == 2000000000)
1968 {
1969 notice(s_GameServ, u, "Your bank account is full, sire!");
1970 return;
1971 }
1972 else if (stricmp(amount, "ALL") == 0)
1973 {
1974 if (2000000000 - p->bank < p->gold)
1975 {
1976 notice(s_GameServ, u, "You don't have enough room for all of your gold.");
1977 notice(s_GameServ, u, "Depositing %ld gold into your account", (2000000000 - p->bank));
1978 p->gold -= (2000000000 - p->bank);
1979 p->bank = 2000000000;
1980 }
1981 else
1982 {
1983 notice(s_GameServ, u, "Depositing %ld gold into your account!", p->gold);
1984 p->bank += p->gold;
1985 p->gold = 0;
1986 }
1987 }
1988 else if (stringtoint(amount) > p->gold)
1989 {
1990 notice(s_GameServ, u, "Sire, you only have %ld gold!", p->gold);
1991 return;
1992 }
1993 else
1994 {
1995 if (2000000000 - p->bank < stringtoint(amount))
1996 {
1997 notice(s_GameServ, u, "You don't have room in your account for that much.");
1998 notice(s_GameServ, u, "Capping off your account with %ld gold!", (2000000000 - p->bank));
1999 p->gold -= (2000000000 - p->bank);
2000 p->bank = 2000000000;
2001 }
2002 else
2003 {
2004 notice(s_GameServ, u, "Depositing %d gold into your account!", stringtoint(amount));
2005 p->bank += stringtoint(amount);
2006 p->gold -= stringtoint(amount);
2007 }
2008 }
2009 }
2010 else if (stricmp(cmd, "WITHDRAW") == 0)
2011 {
2012 if (p->gold == 2000000000)
2013 {
2014 notice(s_GameServ, u, "You cannot carry any more gold, sire!");
2015 return;
2016 }
2017 else if (stricmp(amount, "ALL") == 0)
2018 {
2019 if (2000000000 - p->gold < p->bank)
2020 {
2021 notice(s_GameServ, u, "You don't have enough room to carry all that gold.");
2022 notice(s_GameServ, u, "Withdrawing %ld gold from your account", (2000000000 - p->gold));
2023 p->bank -= (2000000000 - p->gold);
2024 p->gold = 2000000000;
2025 }
2026 else
2027 {
2028 notice(s_GameServ, u, "Withdrawing %ld gold from your account!", p->bank);
2029 p->gold += p->bank;
2030 p->bank = 0;
2031 }
2032 }
2033 else if (stringtoint(amount) > p->bank)
2034 {
2035 notice(s_GameServ, u, "Sire, you only have %ld gold in the bank!", p->bank);
2036 return;
2037 }
2038 else
2039 {
2040 if (2000000000 - p->gold < stringtoint(amount))
2041 {
2042 notice(s_GameServ, u, "You don't enough have room to carry that much gold!");
2043 notice(s_GameServ, u, "You fill your pockets with %ld gold!",
2044 (2000000000 - p->gold));
2045 p->bank -= (2000000000 - p->gold);
2046 p->gold = 2000000000;
2047 }
2048 else
2049 {
2050 notice(s_GameServ, u, "Withdrawing %d gold from your account!", stringtoint(amount));
2051 p->gold += stringtoint(amount);
2052 p->bank -= stringtoint(amount);
2053 }
2054 }
2055 }
2056
ad7dfaa0 2057}