]> jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
Initial revision
[irc/gameservirc.git] / gameserv / gameserv.cpp
1 #include "sockhelp.h"
2 #include "aClient.h"
3 #include "list.h"
4 #include "extern.h"
5 #include <cctype>
6 #include <fstream.h>
7
8 List<aClient> players;
9 Monster monsters[5][12];
10
11 // Database functions
12 int save_gs_dbase();
13 int load_gs_dbase();
14
15 // String functions
16 #undef strtok
17 char *strtok(char *str, const char *delim);
18 int stricmp(const char *s1, const char *s2);
19 int strnicmp(const char *s1, const char *s2, size_t len);
20 // String Functions
21
22 // GameServ Booleans
23 bool is_playing(char *u);
24 bool has_started(char *u);
25 bool is_fighting(char *u);
26 bool isnt_fighting(char *u);
27 bool player_fight(char *u);
28 bool master_fight(char *u);
29 // GameServ Booleans
30
31
32 void display_monster(char *u);
33 void display_players(char *u);
34 long int chartoint(char ch);
35 int isstringnum(char *num);
36 long int pow (int x, int y);
37 long int stringtoint(char *number);
38
39 char *spaces(int len, char *seperator);
40 void init_masters();
41 void refresh(aClient *ni);
42 void refreshall();
43 void reset(aClient *ni);
44 void init_monsters();
45
46 void do_list(char *u);
47 void do_register(char *u);
48 void do_identify(char *u);
49 void do_play(char *u);
50 void do_quitg(char *u);
51 void do_reset(char *u);
52 void do_fight(char *u);
53 void do_store(char *u);
54 void do_heal(char *u);
55 void do_bank(char *u);
56 void do_attack(char *u);
57 void do_run(char *u);
58 void do_visit(char *u);
59 void do_stats(char *u);
60 void see_mystic(char *u);
61
62 void showstats(const char *u, const char *nick);
63
64 #define WNA 16
65 char *weapons[WNA] = { "Fists", "Stick", "Dagger", "Quarterstaff", "Short Sword",
66 "Long Sword", "Silver Spear", "Battle Axe", "The Ragnarok",
67 "Chain Saw", "Poison Sword", "Flame Sword", "Earth Hammer",
68 "Light Saber", "Masamune", "Mystical Sword"};
69
70 char *armors[WNA] = { "Nothing", "Clothes", "Leather Vest", "Chain Mail", "Plate Armor",
71 "Full Body Armor", "Magic Mail", "Graphite Suit", "Steel Suit",
72 "Force Field", "Armor of Light", "Mythril Vest", "DemiGod Armor",
73 "Hades' Cloak", "Dragon Scales", "Mystical Armor"};
74
75 int prices[WNA - 1] = {200, 1000, 3000, 10000, 30000, 100000, 150000, 200000, 400000,
76 1000000, 4000000, 10000000, 40000000, 100000000, 400000000};
77 int webonus[WNA] = {0, 10, 15, 25, 35, 45, 65, 85, 125, 185, 255, 355, 505, 805, 1205, 1805};
78 int arbonus[WNA] = {0, 1, 3, 10, 15, 25, 35, 50, 75, 100, 150, 225, 300, 400, 600, 1000};
79
80 int hpbonus[11] = {10, 15, 20, 30, 50, 75, 125, 185, 250, 350, 550};
81 int strbonus[11] = {5, 7, 10, 12, 20, 35, 50, 75, 110, 150, 200};
82 int defbonus[11] = {2, 3, 5, 10, 15, 22, 35, 60, 80, 120, 150};
83
84
85 void gameserv(char *source, char *buf)
86 {
87 char *cmd, input[1024];
88 cmd = strtok(buf, " ");
89
90 source++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
91 cmd++; // Get rid of that : at the beginning of the :text (command)
92
93 cout << "Source: " << source << "\ncmd: " << cmd << endl;
94 if (strnicmp(cmd, ":\1PING", 6) == 0)
95 {
96 char *timestamp;
97 timestamp = strtok(NULL, "\1");
98 notice(s_GameServ, source, "\1PING %s\1", timestamp);
99 } else if (stricmp(cmd, ":\1VERSION\1") == 0) {
100 notice(s_GameServ, source, "\1VERSION GameServ v1.0b\1");
101 } else if (stricmp(cmd, "SEARCH") == 0) {
102 cmd = strtok(NULL, " ");
103
104 if (!cmd)
105 notice(s_GameServ, source, "SYNTAX: /msg %S SEARCH FOREST");
106 else
107 do_forest(source);
108 } else if (stricmp(cmd, "FIGHT") == 0) {
109 do_fight(source);
110 } else if (stricmp(cmd, "ATTACK") == 0) {
111 do_attack(source);
112 } else if (stricmp(cmd, "HEAL") == 0) {
113 do_heal(source);
114 } else if (stricmp(cmd, "PRINT") == 0) {
115 cout << "Printing Clients List: " << endl;
116 clients.print();
117 cout << "Printing Player List: " << endl;
118 players.print();
119 } else if (stricmp(cmd, "LIST") == 0) {
120 do_list(source);
121 } else if (stricmp(cmd, "REGISTER") == 0) {
122 do_register(source);
123 } else if (stricmp(cmd, "IDENTIFY") == 0) {
124 do_identify(source);
125 } else if (stricmp(cmd, "HELP") == 0) {
126 } else if (stricmp(cmd, "STATS") == 0) {
127 do_stats(source);
128 } else if (stricmp(cmd, "SHUTDOWN") == 0) {
129 //save_gs_dbase();
130 raw("SQUIT %s :leaving", servername);
131 } else if (stricmp(cmd, "SAVE") == 0) {
132 save_gs_dbase();
133 } else if (stricmp(cmd, "LOAD") == 0) {
134 load_gs_dbase();
135 } else if (stricmp(cmd, "RAW") == 0) {
136 char *rest = strtok(NULL, "");
137 raw(rest);
138 }
139
140 source--; // Bring the : back so we don't leak memory
141 cmd--; // Same thing :)
142 }
143
144 int stricmp(const char *s1, const char *s2)
145 {
146 register int c;
147
148 while ((c = tolower(*s1)) == tolower(*s2)) {
149 if (c == 0)
150 return 0;
151 s1++;
152 s2++;
153 }
154 if (c < tolower(*s2))
155 return -1;
156 return 1;
157 }
158
159 void showstats(const char *u, const char *nick)
160 {
161 aClient *ni, *sender = find(u);
162 char *buf;
163 buf = new char[50];
164 char *space;
165
166
167 cout << "\n\nu: " << u << "\nnick: " << nick << endl;
168 if (!(ni = findbynick(nick)))
169 {
170 notice(s_GameServ, u, "%s not found", nick);
171 }
172 else if (ni->stats)
173 {
174
175 notice(s_GameServ, sender->getNick(), "Stats for %s:", ni->stats->name);
176
177 sprintf(buf, "Experience: %ld", ni->stats->exp);
178 space = spaces(strlen(buf), " ");
179 notice(s_GameServ, sender->getNick(), "%s%sLevel: %d", buf, space,
180 ni->stats->level);
181 delete space;
182
183 sprintf(buf, "Gold: %ld", ni->stats->gold);
184 space = spaces(strlen(buf), " ");
185 notice(s_GameServ, sender->getNick(), "%s%sGold in Bank: %ld", buf, space, ni->stats->bank);
186 delete space;
187
188 notice(s_GameServ, sender->getNick(), "Health Points: %d of %d", ni->stats->hp,
189 ni->stats->maxhp);
190
191 sprintf(buf, "Strength: %d", ni->stats->strength + webonus[ni->stats->weapon]);
192 space = spaces(strlen(buf), " ");
193 notice(s_GameServ, sender->getNick(), "%s%sDefense: %d",
194 buf, space, ni->stats->defense + arbonus[ni->stats->armor]);
195 delete space;
196
197 sprintf(buf, "Armor: %s", armors[ni->stats->armor]);
198 space = spaces(strlen(buf), " ");
199 notice(s_GameServ, sender->getNick(), "%s%sWeapon: %s", buf, space,
200 weapons[ni->stats->weapon]);
201 delete space;
202
203 sprintf(buf, "Forest Fights: %d", ni->stats->forest_fights);
204 space = spaces(strlen(buf), " ");
205 notice(s_GameServ, sender->getNick(), "%s%sPlayer Fights: %d", buf, space, ni->stats->player_fights);
206 delete space;
207 }
208 delete buf;
209
210 }
211
212 char *spaces(int len, char *seperator)
213 {
214 char *final;
215 final = new char[40];
216 int y;
217 strcpy(final, seperator);
218 for (y = 0; y < 40 - len; y++)
219 strcat(final, seperator);
220 return final;
221 }
222
223 void raw(const char *fmt, ...)
224 {
225 va_list args;
226 char *input;
227 const char *t = fmt;
228 input = new char[1024];
229 va_start(args, fmt);
230 memset(input, 0, sizeof(input)); // Initialize to NULL
231 for (; *t; t++)
232 {
233 if (*t == '%')
234 {
235 switch(*++t) {
236 case 'd': sprintf(input, "%s%d", input, va_arg(args, int)); break;
237 case 's': sprintf(input, "%s%s", input, va_arg(args, char *)); break;
238 case 'S': sprintf(input, "%s%s", input, s_GameServ); break;
239 case 'l':
240 if (*++t == 'd')
241 sprintf(input, "%s%ld", input, va_arg(args, long int)); break;
242 }
243 }
244 else
245 {
246 sprintf(input, "%s%c", input, *t);
247 }
248
249 }
250 sprintf(input, "%s%s", input, "\r\n");
251 cout << "input: " << input << flush;
252 sock_puts(sock, input);
253 delete input;
254 va_end(args);
255 }
256 /* Send a NOTICE from the given source to the given nick. */
257
258 void notice(const char *source, const char *dest, const char *fmt, ...)
259 {
260 va_list args;
261 char *input;
262 const char *t = fmt;
263 input = new char[1024];
264 va_start(args, fmt);
265 if (dest[0] == ':')
266 {
267 dest++;
268 sprintf(input, ":%s NOTICE %s :", source, dest);
269 dest--;
270 }
271 else
272 sprintf(input, ":%s NOTICE %s :", source, dest);
273
274 for (; *t; t++)
275 {
276 if (*t == '%')
277 {
278 switch(*++t) {
279 case 'd': sprintf(input, "%s%d", input, va_arg(args, int)); break;
280 case 's': sprintf(input, "%s%s", input, va_arg(args, char *)); break;
281 case 'S': sprintf(input, "%s%s", input, s_GameServ); break;
282 case 'l':
283 if (*++t == 'd')
284 sprintf(input, "%s%ld", input, va_arg(args, long int)); break;
285 }
286 }
287 else
288 {
289 sprintf(input, "%s%c", input, *t);
290 }
291
292 }
293 sprintf(input, "%s%s", input, "\r\n");
294 cout << "input: " << input << flush;
295 sock_puts(sock, input);
296 delete input;
297 va_end(args);
298 }
299
300
301 int strnicmp(const char *s1, const char *s2, size_t len)
302 {
303 register int c;
304
305 if (!len)
306 return 0;
307 while ((c = tolower(*s1)) == tolower(*s2) && len > 0) {
308 if (c == 0 || --len == 0)
309 return 0;
310 s1++;
311 s2++;
312 }
313 if (c < tolower(*s2))
314 return -1;
315 return 1;
316 }
317
318 char *strtok(char *str, const char *delim)
319 {
320 static char *current = NULL;
321 char *ret;
322
323 if (str)
324 current = str;
325 if (!current)
326 return NULL;
327 current += strspn(current, delim);
328 ret = *current ? current : NULL;
329 current += strcspn(current, delim);
330 if (!*current)
331 current = NULL;
332 else
333 *current++ = 0;
334 return ret;
335 }
336
337 void do_list(char *u)
338 {
339 ListNode<aClient> *temp;
340 temp = players.First();
341 if (!players.isEmpty())
342 {
343 notice(s_GameServ, u, "People Playing:");
344 while(temp)
345 {
346 notice(s_GameServ, u, "IRC: %s Game: %s", temp->getData()->getNick(), temp->getData()->stats->name);
347 temp = temp->Next();
348 }
349 notice(s_GameServ, u, "End of List");
350 }
351 else
352 notice(s_GameServ, u, "No one is playing");
353 }
354 void do_register(char *u)
355 {
356 char *password;
357 aClient *user;
358 password = strtok(NULL, " ");
359
360 if (!password)
361 {
362 notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER PASSWORD");
363 }
364 else if (user = find(u))
365 {
366 if (!user->stats)
367 {
368 user->stats = new Player(user);
369 user->stats->started = 1;
370 user->stats->user = user; // Set the backwards pointer
371 players.insertAtBack(user);
372 }
373 else
374 {
375 notice(s_GameServ, u, "Already registered. Contact a %S admin for help.");
376 }
377 }
378 }
379
380 void do_identify(char *u)
381 {
382 char *password;
383 aClient *user;
384 password = strtok(NULL, " ");
385
386 if (!password)
387 {
388 notice(s_GameServ, u, "SYNTAX: /msg %S IDENTIFY PASSWORD");
389 }
390 else if (stricmp(password, "TEST") != 0)
391 {
392 notice(s_GameServ, u, "Password incorrect");
393 }
394 else if (user = find(u))
395 {
396 if (!user->stats)
397 {
398 user->stats = new Player(user);
399 user->stats->started = 1;
400 players.insertAtBack(user);
401 notice(s_GameServ, u, "Password Accepted. Identified.");
402 }
403 else
404 {
405 notice(s_GameServ, u, "Already identified. Contact a %S admin for help.");
406 }
407 }
408 }
409
410 void do_stats(char *u)
411 {
412 char *nick;
413 aClient *source;
414
415 nick = strtok(NULL, " ");
416 source = find(u);
417
418 if (!nick)
419 showstats(u, source->getNick());
420 else
421 showstats(u, nick);
422 }
423
424 void init_monsters()
425 {
426 // Hard coded for now - Kain
427 monsters[0][0].name = "Slime";
428 monsters[0][0].weapon = "Acid Goo";
429 monsters[0][0].strength = 6;
430 monsters[0][0].gold = 50;
431 monsters[0][0].exp = 3;
432 monsters[0][0].maxhp = 9;
433 monsters[0][0].death = "The slime oozes into nothing... you clean the acid goo off of your weapon";
434
435 monsters[0][1].name = "Ghost";
436 monsters[0][1].weapon = "Cold Breath";
437 monsters[0][1].strength = 8;
438 monsters[0][1].gold = 100;
439 monsters[0][1].exp = 10;
440 monsters[0][1].maxhp = 10;
441 monsters[0][1].death = "You feel a chill as the spirit leaves the realm.";
442
443 monsters[0][2].name = "Ugly Rodent";
444 monsters[0][2].weapon = "Sharp Teeth";
445 monsters[0][2].strength = 9;
446 monsters[0][2].gold = 75;
447 monsters[0][2].exp = 8;
448 monsters[0][2].maxhp = 13;
449 monsters[0][2].death = "You stomp on the Ugly Rodent's remains for a finishing blow.";
450
451 monsters[0][3].name = "Whart Hog";
452 monsters[0][3].weapon = "Tusks";
453 monsters[0][3].strength = 10;
454 monsters[0][3].gold = 80;
455 monsters[0][3].exp = 6;
456 monsters[0][3].maxhp = 10;
457 monsters[0][3].death = "You cook and eat the hog for good measure!";
458
459 monsters[0][4].name = "Pesky Kid";
460 monsters[0][4].weapon = "Slingshot";
461 monsters[0][4].strength = 8;
462 monsters[0][4].gold = 30;
463 monsters[0][4].exp = 4;
464 monsters[0][4].maxhp = 6;
465 monsters[0][4].death = "You take his slingshot and snap the band, sending the kid crying home to mom!";
466
467 monsters[0][5].name = "Playground Bully";
468 monsters[0][5].weapon = "Painful Noogie";
469 monsters[0][5].strength = 11;
470 monsters[0][5].gold = 44;
471 monsters[0][5].exp = 6;
472 monsters[0][5].maxhp = 10;
473 monsters[0][5].death = "You give him an indian burn, and punt him across the schoolyard!";
474
475 monsters[0][6].name = "Small Imp";
476 monsters[0][6].weapon = "Dagger";
477 monsters[0][6].strength = 6;
478 monsters[0][6].gold = 64;
479 monsters[0][6].exp = 10;
480 monsters[0][6].maxhp = 10;
481 monsters[0][6].death = "You can't help but laugh as he stumbles and falls onto his own dagger!";
482
483 monsters[0][7].name = "Little Monkey";
484 monsters[0][7].weapon = "Monkey Wrench";
485 monsters[0][7].strength = 6;
486 monsters[0][7].gold = 53;
487 monsters[0][7].exp = 9;
488 monsters[0][7].maxhp = 9;
489 monsters[0][7].death = "You want to cook it, but you just can't think of eating something that looks so human!";
490
491 monsters[0][8].name = "Grub Worm";
492 monsters[0][8].weapon = "Minor Nudge";
493 monsters[0][8].strength = 2;
494 monsters[0][8].gold = 10;
495 monsters[0][8].exp = 3;
496 monsters[0][8].maxhp = 3;
497 monsters[0][8].death = "You decide to save the poor little fella for your next fishing trip.";
498
499 monsters[0][9].name = "Drakee";
500 monsters[0][9].weapon = "Tail Slap";
501 monsters[0][9].strength = 5;
502 monsters[0][9].gold = 22;
503 monsters[0][9].exp = 7;
504 monsters[0][9].maxhp = 5;
505 monsters[0][9].death = "You pull the little Drakee by its tale and slam it down on a dry stump!";
506
507 monsters[0][10].name = "Fat Slob";
508 monsters[0][10].weapon = "Smelly Breath";
509 monsters[0][10].strength = 6;
510 monsters[0][10].gold = 40;
511 monsters[0][10].exp = 10;
512 monsters[0][10].maxhp = 7;
513 monsters[0][10].death = "You kick his stomach for fun, and are thrown back by the spring of it all!";
514
515 monsters[0][11].name = "Lost Warrior";
516 monsters[0][11].weapon = "Long Sword";
517 monsters[0][11].strength = 10;
518 monsters[0][11].gold = 250;
519 monsters[0][11].exp = 19;
520 monsters[0][11].maxhp = 15;
521 monsters[0][11].death = "You give him a proper burial in respect for the dead warrior.";
522
523 monsters[1][0].name = "Lost Warrior's Cousin Larry";
524 monsters[1][0].weapon = "Wood Axe";
525 monsters[1][0].strength = 19;
526 monsters[1][0].gold = 134;
527 monsters[1][0].exp = 24;
528 monsters[1][0].maxhp = 30;
529 monsters[1][0].death = "He was pretty pissed you killed his cousin, but he seems to have suffered the same fate!";
530
531 monsters[1][1].name = "Sandman";
532 monsters[1][1].weapon = "Sleeping Dust";
533 monsters[1][1].strength = 25;
534 monsters[1][1].gold = 80;
535 monsters[1][1].exp = 6;
536 monsters[1][1].maxhp = 27;
537 monsters[1][1].death = "You put the sandman to his final sleep.";
538
539 monsters[1][2].name = "Dirty Transvestite";
540 monsters[1][2].weapon = "Stiletto Heel";
541 monsters[1][2].strength = 21;
542 monsters[1][2].gold = 160;
543 monsters[1][2].exp = 12;
544 monsters[1][2].maxhp = 25;
545 monsters[1][2].death = "You shudder at the thought of ever mistaking this for a woman!";
546
547 monsters[1][3].name = "Goblin Gardener";
548 monsters[1][3].weapon = "Garden Spade";
549 monsters[1][3].strength = 18;
550 monsters[1][3].gold = 130;
551 monsters[1][3].exp = 8;
552 monsters[1][3].maxhp = 20;
553 monsters[1][3].death = "You trample on his garden after slaying him... that felt good!";
554
555 monsters[1][4].name = "Evil Elf";
556 monsters[1][4].weapon = "Elvish Bow";
557 monsters[1][4].strength = 23;
558 monsters[1][4].gold = 136;
559 monsters[1][4].exp = 13;
560 monsters[1][4].maxhp = 24;
561 monsters[1][4].death = "Elves are usually nice you thought... hmm.";
562
563 monsters[1][5].name = "Viking Warrior";
564 monsters[1][5].weapon = "Broad Sword";
565 monsters[1][5].strength = 21;
566 monsters[1][5].gold = 330;
567 monsters[1][5].exp = 20;
568 monsters[1][5].maxhp = 18;
569 monsters[1][5].death = "You heard vikings were big, but not THAT big you thought.";
570
571 monsters[1][6].name = "Wicked Witch";
572 monsters[1][6].weapon = "Cackling Laugh";
573 monsters[1][6].strength = 20;
574 monsters[1][6].gold = 130;
575 monsters[1][6].exp = 20;
576 monsters[1][6].maxhp = 26;
577 monsters[1][6].death = "Just for kicks, you splash some water on her and watch her melt.";
578
579 monsters[1][7].name = "Vampire Bat";
580 monsters[1][7].weapon = "Blood Sucking Fangs";
581 monsters[1][7].strength = 18;
582 monsters[1][7].gold = 125;
583 monsters[1][7].exp = 21;
584 monsters[1][7].maxhp = 29;
585 monsters[1][7].death = "You fry up the bat and eat it... needs garlic.";
586
587 monsters[1][8].name = "Thorn Bush";
588 monsters[1][8].weapon = "101 Thorns";
589 monsters[1][8].strength = 16;
590 monsters[1][8].gold = 94;
591 monsters[1][8].exp = 15;
592 monsters[1][8].maxhp = 25;
593 monsters[1][8].death = "You set the bush ablaze and roast some marshmallows.";
594
595 monsters[1][9].name = "Barbarian";
596 monsters[1][9].weapon = "Heavy Sword";
597 monsters[1][9].strength = 29;
598 monsters[1][9].gold = 250;
599 monsters[1][9].exp = 25;
600 monsters[1][9].maxhp = 30;
601 monsters[1][9].death = "You listen to him moan as he falls over dead.";
602
603 monsters[1][10].name = "Crypt Rat";
604 monsters[1][10].weapon = "Stinging Bite";
605 monsters[1][10].strength = 25;
606 monsters[1][10].gold = 119;
607 monsters[1][10].exp = 20;
608 monsters[1][10].maxhp = 26;
609 monsters[1][10].death = "You squash the little rodent for fear that it might not be dead.";
610
611 monsters[1][11].name = "Small Orc";
612 monsters[1][11].weapon = "blade";
613 monsters[1][11].strength = 28;
614 monsters[1][11].gold = 300;
615 monsters[1][11].exp = 30;
616 monsters[1][11].maxhp = 36;
617 monsters[1][11].death = "It's an ugly one, and it would've grown up to be a terror...";
618
619 monsters[2][0].name = "Teferi";
620 monsters[2][0].weapon = "Puzzle Box";
621 monsters[2][0].strength = 29;
622 monsters[2][0].gold = 380;
623 monsters[2][0].exp = 18;
624 monsters[2][0].maxhp = 29;
625 monsters[2][0].death = "It was a puzzling experience.";
626
627 monsters[2][1].name = "Spineless Thug";
628 monsters[2][1].weapon = "Spiked Bat";
629 monsters[2][1].strength = 37;
630 monsters[2][1].gold = 384;
631 monsters[2][1].exp = 27;
632 monsters[2][1].maxhp = 32;
633 monsters[2][1].death = "See you at the crossroads!";
634
635 monsters[2][2].name = "Pyromaniac";
636 monsters[2][2].weapon = "Pyrotechnics";
637 monsters[2][2].strength = 29;
638 monsters[2][2].gold = 563;
639 monsters[2][2].exp = 22;
640 monsters[2][2].maxhp = 45;
641 monsters[2][2].death = "He chants FIRE FIRE as he falls to the ground... a burning heap of flesh.";
642
643 monsters[2][3].name = "Evil Enchantress";
644 monsters[2][3].weapon = "Deadly Spell";
645 monsters[2][3].strength = 50;
646 monsters[2][3].gold = 830;
647 monsters[2][3].exp = 35;
648 monsters[2][3].maxhp = 35;
649 monsters[2][3].death = "She looked just about as good as she fought.";
650
651 monsters[2][4].name = "Killer Leprechaun";
652 monsters[2][4].weapon = "Gold Rush";
653 monsters[2][4].strength = 35;
654 monsters[2][4].gold = 1300;
655 monsters[2][4].exp = 30;
656 monsters[2][4].maxhp = 37;
657 monsters[2][4].death = "You steal his pot of gold... that's a lot of money!";
658
659 monsters[2][5].name = "Avalanche Rider";
660 monsters[2][5].weapon = "Huge Snowball";
661 monsters[2][5].strength = 32;
662 monsters[2][5].gold = 700;
663 monsters[2][5].exp = 32;
664 monsters[2][5].maxhp = 38;
665 monsters[2][5].death = "You take his snowboard and snap it in two!";
666
667 monsters[2][6].name = "Blundering Idiot";
668 monsters[2][6].weapon = "Stupidity";
669 monsters[2][6].strength = 14;
670 monsters[2][6].gold = 700;
671 monsters[2][6].exp = 20;
672 monsters[2][6].maxhp = 29;
673 monsters[2][6].death = "Now there's one person you don't feel sorry for killing!";
674
675 monsters[2][7].name = "Militant Anarchist";
676 monsters[2][7].weapon = "Molotov Cocktail";
677 monsters[2][7].strength = 33;
678 monsters[2][7].gold = 245;
679 monsters[2][7].exp = 45;
680 monsters[2][7].maxhp = 32;
681 monsters[2][7].death = "Order has been restored for now...";
682
683 monsters[2][8].name = "Scathe Zombies";
684 monsters[2][8].weapon = "Death Grip";
685 monsters[2][8].strength = 38;
686 monsters[2][8].gold = 763;
687 monsters[2][8].exp = 15;
688 monsters[2][8].maxhp = 45;
689 monsters[2][8].death = "That was perhaps the scariest experience of your life.";
690
691 monsters[2][9].name = "Spitting Llama";
692 monsters[2][9].weapon = "Spit Spray";
693 monsters[2][9].strength = 48;
694 monsters[2][9].gold = 638;
695 monsters[2][9].exp = 28;
696 monsters[2][9].maxhp = 34;
697 monsters[2][9].death = "You wipe the spit off your face and fling it back at the Llama.";
698
699 monsters[2][10].name = "Juggalo";
700 monsters[2][10].weapon = "Clown Axe";
701 monsters[2][10].strength = 60;
702 monsters[2][10].gold = 650;
703 monsters[2][10].exp = 30;
704 monsters[2][10].maxhp = 29;
705 monsters[2][10].death = "What is a Juggalo? I don't know!";
706
707 monsters[2][11].name = "The Boogie Man";
708 monsters[2][11].weapon = "Striking Fear";
709 monsters[2][11].strength = 46;
710 monsters[2][11].gold = 600;
711 monsters[2][11].exp = 35;
712 monsters[2][11].maxhp = 27;
713 monsters[2][11].death = "He's scared you for the very last time!";
714
715 monsters[3][0].name = "Living Fire";
716 monsters[3][0].weapon = "Scorching Wind";
717 monsters[3][0].strength = 55;
718 monsters[3][0].gold = 1100;
719 monsters[3][0].exp = 36;
720 monsters[3][0].maxhp = 55;
721 monsters[3][0].death = "You extinguish the Living Flame once and for all!";
722
723 monsters[3][1].name = "Raging Orc";
724 monsters[3][1].weapon = "Orcish Artillary";
725 monsters[3][1].strength = 89;
726 monsters[3][1].gold = 900;
727 monsters[3][1].exp = 25;
728 monsters[3][1].maxhp = 50;
729 monsters[3][1].death = "This orc was a bit tougher than you remembered!";
730
731 monsters[3][2].name = "Huge Tarantula";
732 monsters[3][2].weapon = "Tangling Web";
733 monsters[3][2].strength = 59;
734 monsters[3][2].gold = 1000;
735 monsters[3][2].exp = 35;
736 monsters[3][2].maxhp = 60;
737 monsters[3][2].death = "You're glad you overcame your arachniphobia so soon!";
738
739 monsters[3][3].name = "Rabid Wolf";
740 monsters[3][3].weapon = "Cujo Bite";
741 monsters[3][3].strength = 40;
742 monsters[3][3].gold = 1200;
743 monsters[3][3].exp = 47;
744 monsters[3][3].maxhp = 76;
745 monsters[3][3].death = "The mutt falls over dead as white foam drips from its deadly canines...";
746
747 monsters[3][4].name = "Goblin Fighter";
748 monsters[3][4].weapon = "Morning Star";
749 monsters[3][4].strength = 38;
750 monsters[3][4].gold = 700;
751 monsters[3][4].exp = 30;
752 monsters[3][4].maxhp = 75;
753 monsters[3][4].death = "He almost caught you with his chain mace, but you sliced off his head.";
754
755 monsters[3][5].name = "Grizzly Bear";
756 monsters[3][5].weapon = "Razor Claws";
757 monsters[3][5].strength = 68;
758 monsters[3][5].gold = 1747;
759 monsters[3][5].exp = 81;
760 monsters[3][5].maxhp = 51;
761 monsters[3][5].death = "It almost got you this time... better be careful";
762
763 monsters[3][6].name = "Skeleton Man";
764 monsters[3][6].weapon = "Leg Bone";
765 monsters[3][6].strength = 70;
766 monsters[3][6].gold = 597;
767 monsters[3][6].exp = 57;
768 monsters[3][6].maxhp = 60;
769 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!";
770
771 monsters[3][7].name = "Young Werewolf";
772 monsters[3][7].weapon = "Howling Bites";
773 monsters[3][7].strength = 75;
774 monsters[3][7].gold = 1742;
775 monsters[3][7].exp = 65;
776 monsters[3][7].maxhp = 42;
777 monsters[3][7].death = "You scatter the wolf's body parts in hopes he will stay dead!";
778
779 monsters[3][8].name = "Dark Infantry";
780 monsters[3][8].weapon = "Flesh Reaper";
781 monsters[3][8].strength = 69;
782 monsters[3][8].gold = 870;
783 monsters[3][8].exp = 43;
784 monsters[3][8].maxhp = 65;
785 monsters[3][8].death = "Light has prevailed this time... but it's only so long before you meet again.";
786
787 monsters[3][9].name = "Erie Spirit";
788 monsters[3][9].weapon = "Deadly Grin";
789 monsters[3][9].strength = 63;
790 monsters[3][9].gold = 1300;
791 monsters[3][9].exp = 32;
792 monsters[3][9].maxhp = 50;
793 monsters[3][9].death = "His cousin the ghost was a little bit easier.";
794
795 monsters[3][10].name = "Gollum";
796 monsters[3][10].weapon = "Precious Treasure";
797 monsters[3][10].strength = 66;
798 monsters[3][10].gold = 1492;
799 monsters[3][10].exp = 73;
800 monsters[3][10].maxhp = 54;
801 monsters[3][10].death = "Gollum screams out \"MY PRECIOUS\" as his small body falls limp from your blow.";
802
803 monsters[3][11].name = "Rock Fighter";
804 monsters[3][11].weapon = "Small Boulders";
805 monsters[3][11].strength = 87;
806 monsters[3][11].gold = 1742;
807 monsters[3][11].exp = 99;
808 monsters[3][11].maxhp = 65;
809 monsters[3][11].death = "You dodge his last rock, and counter with a low blow, cutting off his legs.";
810
811
812 monsters[4][0].name = "Giant Sphinx";
813 monsters[4][0].weapon = "Ancient Curse";
814 monsters[4][0].strength = 120;
815 monsters[4][0].gold = 1000;
816 monsters[4][0].exp = 100;
817 monsters[4][0].maxhp = 80;
818 monsters[4][0].death = "You look in awe at the great wonder, collapsed at your feet!";
819
820 monsters[4][1].name = "Giant Ogre";
821 monsters[4][1].weapon = "Big Log";
822 monsters[4][1].strength = 130;
823 monsters[4][1].gold = 857;
824 monsters[4][1].exp = 175;
825 monsters[4][1].maxhp = 100;
826 monsters[4][1].death = "Your witz outmatched the ogres brawn... big dumb thing.";
827
828 monsters[4][2].name = "Massive Cockroach";
829 monsters[4][2].weapon = "Piercing Hiss";
830 monsters[4][2].strength = 125;
831 monsters[4][2].gold = 700;
832 monsters[4][2].exp = 150;
833 monsters[4][2].maxhp = 112;
834 monsters[4][2].death = "Where's the exterminator when you need one?";
835
836 monsters[4][3].name = "Big Venomous Snake";
837 monsters[4][3].weapon = "Poison Fangs";
838 monsters[4][3].strength = 140;
839 monsters[4][3].gold = 900;
840 monsters[4][3].exp = 175;
841 monsters[4][3].maxhp = 126;
842 monsters[4][3].death = "After killing this beast you check for puncture marks... you find none, luckily.";
843
844 monsters[4][4].name = "Lizard Man";
845 monsters[4][4].weapon = "Deadly Jaws";
846 monsters[4][4].strength = 145;
847 monsters[4][4].gold = 1250;
848 monsters[4][4].exp = 175;
849 monsters[4][4].maxhp = 150;
850 monsters[4][4].death = "His scales made for tough armor, and his jaws for a tougher opponent!";
851
852 monsters[4][5].name = "Face Dancer";
853 monsters[4][5].weapon = "Illusion Scyth";
854 monsters[4][5].strength = 138;
855 monsters[4][5].gold = 1603;
856 monsters[4][5].exp = 198;
857 monsters[4][5].maxhp = 173;
858 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!";
859
860 monsters[4][6].name = "Darklord Longbow Archer";
861 monsters[4][6].weapon = "Deadly Bow and Arrows";
862 monsters[4][6].strength = 145;
863 monsters[4][6].gold = 1569;
864 monsters[4][6].exp = 243;
865 monsters[4][6].maxhp = 170;
866 monsters[4][6].death = "Your face turns white with horror after you realize you just met the devil's protector!";
867
868 monsters[4][7].name = "Hell's Paladin";
869 monsters[4][7].weapon = "Sword of Hellfire";
870 monsters[4][7].strength = 200;
871 monsters[4][7].gold = 2191;
872 monsters[4][7].exp = 254;
873 monsters[4][7].maxhp = 175;
874 monsters[4][7].death = "This is starting to get tough you think. Do you really want to go to level 12?";
875
876 monsters[4][8].name = "The Unknown Soldier";
877 monsters[4][8].weapon = "Soul Torture";
878 monsters[4][8].strength = 175;
879 monsters[4][8].gold = 1890;
880 monsters[4][8].exp = 200;
881 monsters[4][8].maxhp = 180;
882 monsters[4][8].death = "Who was that? Where was he from? And what was that weapon??";
883
884 monsters[4][9].name = "Undead Cult Leader";
885 monsters[4][9].weapon = "Lance of Deceit";
886 monsters[4][9].strength = 180;
887 monsters[4][9].gold = 1792;
888 monsters[4][9].exp = 195;
889 monsters[4][9].maxhp = 190;
890 monsters[4][9].death = "His words fall on deaf ears... this is one cult you will NOT be part of!";
891
892 monsters[4][10].name = "Water Serpent";
893 monsters[4][10].weapon = "Forked Tongue";
894 monsters[4][10].strength = 150;
895 monsters[4][10].gold = 1500;
896 monsters[4][10].exp = 176;
897 monsters[4][10].maxhp = 220;
898 monsters[4][10].death = "The serpent squeals as you cut off its head!";
899
900 monsters[4][11].name = "Silverback Gorilla";
901 monsters[4][11].weapon = "Deadly Banana Peel";
902 monsters[4][11].strength = 160;
903 monsters[4][11].gold = 1300;
904 monsters[4][11].exp = 150;
905 monsters[4][11].maxhp = 178;
906 monsters[4][11].death = "Was that gorilla or guerilla?";
907 }
908
909 void display_monster(char *u)
910 {
911 if (is_playing(u))
912 {
913 aClient *user = find(u);
914 Player *ni = user->stats;
915
916 notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", ni->hp);
917 notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", ni->fight->name, ni->fight->hp);
918 notice(s_GameServ, u, "Here are your commands:");
919 notice(s_GameServ, u, "/msg %S attack");
920 notice(s_GameServ, u, "/msg %S run");
921 notice(s_GameServ, u, "What will you do?");
922 }
923 }
924
925 void display_players(char *u)
926 {
927 if (is_playing(u))
928 {
929 aClient *ni = find(u);
930
931 aClient *battle = ni->stats->battle;
932
933 notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", ni->stats->hp);
934 notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", battle->getNick(),
935 battle->stats->hp);
936
937 notice(s_GameServ, u, "Here are your commands:");
938 notice(s_GameServ, u, "/msg %s attack", s_GameServ);
939 notice(s_GameServ, u, "/msg %s run", s_GameServ);
940 notice(s_GameServ, u, "What will you do?");
941 }
942 }
943
944
945 bool is_playing(char *u)
946 {
947 aClient *user;
948 if (!(user = find(u)))
949 {
950 return false;
951 }
952 else
953 {
954 return user->stats != NULL;
955 }
956 }
957
958 bool is_fighting(char *u)
959 {
960 aClient *user;
961
962 if (!(user = find(u)))
963 {
964 return false;
965 }
966 else if (user->stats)
967 {
968 return user->stats->fight != NULL || user->stats->battle != NULL
969 || user->stats->master != NULL;
970 }
971 else
972 return false;
973 }
974
975 bool player_fight(char *u)
976 {
977 aClient *user;
978
979 if (!(user = find(u)))
980 return false;
981 else if (user->stats)
982 return user->stats->battle != NULL;
983 else
984 return false;
985 }
986
987 bool master_fight(char *u)
988 {
989 aClient *user;
990
991 if (!(user = find(u)))
992 return false;
993 else if (user->stats)
994 return user->stats->master != NULL;
995 else
996 return false;
997 }
998
999 bool isnt_fighting(char *u)
1000 {
1001 return !is_fighting(u);
1002 }
1003
1004 void do_fight(char *u)
1005 {
1006 aClient *ni, *battle;
1007
1008 char *nick = strtok(NULL, " ");
1009
1010 if (!nick)
1011 {
1012 notice(s_GameServ, u, "SYNTAX: /msg %S FIGHT PLAYER");
1013 }
1014 else if (!(ni = find(u)))
1015 {
1016 return;
1017 }
1018 else if (!(battle = find(nick)))
1019 {
1020 notice(s_GameServ, u, "You can't attack %s while they aren't playing!", nick);
1021 }
1022 else if (!is_playing(u))
1023 {
1024 notice(s_GameServ, u, "You are not playing!");
1025 }
1026 /*
1027 * Offline fighting not implemented yet.
1028 * else if (!(fight = finduser(nick)))
1029 * {
1030 * ni->stats->battle = battle;
1031 * battle->battle = ni;
1032 * ni->yourturn = 1;
1033 * battle->yourturn = 0;
1034 * notice(s_GameServ, u, "You decide to fight %s while they're not online!",
1035 * battle->getNick());
1036 * display_players(u);
1037 * }
1038 */
1039 else if (is_playing(u) && is_playing(nick))
1040 {
1041 // Set your battle pointer to the other player
1042 ni->stats->battle = battle;
1043
1044 // Set the other player's battle pointer to you
1045 battle->stats->battle = ni;
1046
1047 // The initiator gets the first move (perhaps this should be 50/50)
1048 ni->stats->yourturn = 1;
1049 battle->stats->yourturn = 0;
1050
1051 // Initiate Battle sequence!
1052 notice(s_GameServ, u, "You challenge %s to an online duel!", battle->getNick());
1053 notice(s_GameServ, battle->getNick(), "%s has challenged you to an online duel!", u);
1054 notice(s_GameServ, battle->getNick(), "%s gets to go first because he initiated!", u);
1055 notice(s_GameServ, battle->getNick(), "Please wait while %s decides what to do.", u);
1056 display_players(u);
1057 }
1058 }
1059
1060 void do_attack(char *u)
1061 {
1062 int hit, mhit;
1063 aClient *ni, *battle; // The player and perhaps the player they're fighting
1064 Monster *fight; // The monster they may be fighting
1065
1066 if (!(ni = find(u)))
1067 {
1068 notice(s_GameServ, u, "You're not playing!");
1069 return;
1070 }
1071 else if (!ni->stats->fight && !ni->stats->battle && !ni->stats->master)
1072 {
1073 notice(s_GameServ, u, "You're not in battle!");
1074 return;
1075 }
1076 else
1077 {
1078 if (!ni->stats->master) // This is not a master fight
1079 fight = ni->stats->fight; // Monster Could be NULL
1080 else // This IS a master fight
1081 fight = ni->stats->master; // Master Could be NULL
1082
1083 battle = ni->stats->battle; // Player Could be NULL
1084
1085 // One has to be !NULL based on the previous else if
1086 // We wouldn't be here if they were all NULL
1087 }
1088
1089 if (!player_fight(u))
1090 {
1091 // Player's Hit
1092 hit = ((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
1093 (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2));
1094
1095 // Opponent's Hit
1096 mhit = (fight->strength / 2) +
1097 (rand() % (fight->strength / 2) - (ni->stats->defense +
1098 arbonus[ni->stats->armor]));
1099 }
1100 else
1101 {
1102 // Opponent's Hit
1103 mhit = (((battle->stats->strength + webonus[battle->stats->weapon]) / 2) +
1104 (rand() % ((battle->stats->strength + webonus[battle->stats->weapon])) / 2) -
1105 (ni->stats->defense + arbonus[ni->stats->armor]));
1106
1107 // Player's Hit
1108 hit = (((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
1109 (rand() % ((ni->stats->strength + webonus[ni->stats->weapon])) / 2) -
1110 (battle->stats->defense + arbonus[battle->stats->armor]));
1111 }
1112
1113 if (!player_fight(u))
1114 {
1115 if (hit > 0)
1116 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", fight->name, hit);
1117 else
1118 notice(s_GameServ, u, "You miss \1f%s\1f completely!", fight->name);
1119
1120 if (hit >= fight->hp)
1121 {
1122 if (master_fight(u))
1123 notice(s_GameServ, u, "You have bested %s!", fight->name);
1124 else
1125 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", fight->name);
1126
1127 notice(s_GameServ, u, "%s", fight->death);
1128 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%d\ 2 gold!",
1129 fight->exp, fight->gold);
1130
1131 // If your new experience (or gold) will be greater than 2 billion,
1132 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1133 // This could be a problem with overflowing out of the sign bit.
1134 // Unsigned long int maybe? Leave it for now.
1135 ni->stats->exp = ( (ni->stats->exp + fight->exp) > 2000000000 ? 2000000000 :
1136 ni->stats->exp + fight->exp);
1137 ni->stats->gold = (ni->stats->gold + fight->gold > 2000000000 ? 2000000000 :
1138 ni->stats->gold + fight->gold);
1139 ni->stats->fight = NULL; // They're dead so remove the pointer
1140
1141 if (master_fight(u))
1142 {
1143 notice(s_GameServ, u, "You are now level %d!", ni->stats->level + 1);
1144 notice(s_GameServ, u, "You gain %d Strength, and %d Defense points!",
1145 strbonus[ni->stats->level - 1], defbonus[ni->stats->level - 1]);
1146
1147 // Increase your level
1148 ni->stats->level++;
1149
1150 // Increase your maximum hit points
1151 ni->stats->maxhp += hpbonus[ni->stats->level - 1];
1152
1153 // Heal the player by setting hp to their max
1154 ni->stats->hp = ni->stats->maxhp;
1155
1156 // Add to your strength
1157 ni->stats->strength += strbonus[ni->stats->level - 1];
1158
1159 // Add to your defensive power
1160 ni->stats->defense += defbonus[ni->stats->level - 1];
1161
1162 // Clear the pointer for your master
1163 ni->stats->master = NULL;
1164 }
1165 return;
1166 }
1167 else
1168 {
1169 if (hit > 0)
1170 fight->hp -= hit;
1171 if (mhit > 0)
1172 {
1173 notice(s_GameServ, u, "\1f%s\1f hits you with their \1f%s\1f for \ 2%d\ 2 damage!",
1174 fight->name, fight->weapon, mhit);
1175 }
1176 else if (mhit <= 0)
1177 notice(s_GameServ, u, "%s completely misses you!", fight->name);
1178
1179 if (mhit >= ni->stats->hp)
1180 {
1181 if (!master_fight(u))
1182 {
1183 notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight->name);
1184 notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\
1185 "of your experience!");
1186 ni->stats->gold = 0;
1187 ni->stats->exp -= (long int)(ni->stats->exp * .10);
1188 ni->stats->fight = NULL;
1189 return;
1190 }
1191 else
1192 {
1193 notice(s_GameServ, u, "%s has bested you! You will have to wait "\
1194 "until tomorrow to try again", ni->stats->master->name);
1195 ni->stats->fight = NULL;
1196 ni->stats->master = NULL;
1197 return;
1198 }
1199 }
1200 else
1201 {
1202 if (mhit > 0)
1203 ni->stats->hp -= mhit;
1204 display_monster(u);
1205 return;
1206 }
1207 }
1208 }
1209 else if (player_fight(u))
1210 {
1211 /* Offline fighting not available yet
1212 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1213 {
1214 if (hit > 0)
1215 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->nick, hit);
1216 else
1217 notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->nick);
1218 if (hit >= battle->stats->hp)
1219 {
1220 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->nick);
1221 * notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!",
1222 (long int)(battle->stats->exp * .10), battle->stats->gold);
1223 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1224 {
1225 ni->stats->exp += (long int)(battle->stats->exp * .10);
1226 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1227 }
1228 * else
1229 {
1230 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1231 ni->stats->exp = 2000000000;
1232 }
1233
1234 if (2000000000 - ni->stats->gold > battle->stats->gold)
1235 {
1236 * ni->stats->gold += battle->stats->gold;
1237 battle->stats->gold = 0;
1238 }
1239 else
1240 {
1241 battle->stats->gold = 2000000000 - ni->stats->gold;
1242 ni->stats->gold = 2000000000;
1243 }
1244 * ni->stats->battle->stats->alive = 0;
1245 ni->stats->battle->battle = NULL;
1246 ni->stats->battle = NULL;
1247 return;
1248 }
1249 else
1250 {
1251 if (hit > 0)
1252 * battle->stats->hp -= hit;
1253 if (mhit > 0)
1254 {
1255 notice(s_GameServ, u, "\1f%s\1f hits you with their \1f%s\1f for \ 2%d\ 2 damage!",
1256 battle->nick, weapons[battle->stats->weapon], mhit);
1257 }
1258 else if (mhit <= 0)
1259 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1260 *
1261 if (mhit >= ni->stats->hp)
1262 {
1263 notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", battle->nick);
1264 if (2000000000 - battle->stats->gold > ni->stats->gold)
1265 {
1266 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1267 battle->stats->gold += ni->stats->gold;
1268 * ni->stats->gold = 0;
1269 }
1270 else
1271 {
1272 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1273 battle->nick);
1274 ni->stats->gold -= (2000000000 - battle->stats->gold);
1275 notice(s_GameServ, u, "You were left dead with %d gold.",
1276 * (long int)ni->stats->gold);
1277 battle->stats->gold = 2000000000;
1278 }
1279 ni->stats->battle->battle = NULL;
1280 ni->stats->battle = NULL;
1281 ni->stats->alive = 0;
1282 return;
1283 }
1284 * else
1285 {
1286 if (mhit > 0)
1287 ni->stats->hp -= mhit;
1288 display_players(u);
1289 return;
1290 }
1291 }
1292 }
1293 * end offline fighting */
1294
1295 if (is_playing(battle->getNick()))
1296 {
1297 if (ni->stats->yourturn == 0)
1298 {
1299 notice(s_GameServ, u, "Please wait until %s decides what to do!",
1300 battle->getNick());
1301 return;
1302 }
1303 if (hit > 0)
1304 {
1305 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->getNick(), hit);
1306
1307 notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\
1308 "\ 2%d\ 2 damage!", u, weapons[ni->stats->weapon],
1309 hit);
1310 ni->stats->yourturn = 0;
1311 battle->stats->yourturn = 1;
1312 display_players(battle->getNick());
1313 }
1314 else
1315 {
1316 notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->getNick());
1317 notice(s_GameServ, battle->getNick(), "%s misses you completely!", u);
1318 ni->stats->yourturn = 0;
1319 battle->stats->yourturn = 1;
1320 display_players(battle->getNick());
1321 }
1322 if (hit >= battle->stats->hp)
1323 {
1324 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->getNick());
1325 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!",
1326 (long int)(battle->stats->exp * .10), battle->stats->gold);
1327 notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!", u);
1328 battle->stats->hp = 0;
1329 battle->stats->alive = 0;
1330
1331 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1332 {
1333 ni->stats->exp += (long int)(battle->stats->exp * .10);
1334 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1335 }
1336 else
1337 {
1338 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1339 ni->stats->exp = 2000000000;
1340 }
1341
1342 if (2000000000 - ni->stats->gold > battle->stats->gold)
1343 {
1344 notice(s_GameServ, battle->getNick(), "You lose ten percent of experience and "\
1345 "all gold on hand!");
1346 ni->stats->gold += battle->stats->gold;
1347 battle->stats->gold = 0;
1348 }
1349 else
1350 {
1351 battle->stats->gold = 2000000000 - ni->stats->gold;
1352 notice(s_GameServ, battle->getNick(), "You lose ten percent of your experience!");
1353
1354 notice(s_GameServ, battle->getNick(), "However, %s could not carry all of your "\
1355 "gold.", u);
1356
1357 notice(s_GameServ, battle->getNick(), "Luckily, you still have \ 2%ld\ 2 gold "\
1358 "left. All is not lost!", battle->stats->gold);
1359
1360 ni->stats->gold = 2000000000;
1361 }
1362 battle->stats->battle = NULL;
1363 ni->stats->battle = NULL;
1364 return;
1365 }
1366 else
1367 {
1368 if (hit > 0)
1369 battle->stats->hp -= hit;
1370 //display_players(battle->getNick());
1371 ni->stats->yourturn = 0;
1372 battle->stats->yourturn = 1;
1373 notice(s_GameServ, u, "Please wait while %s decides what to do!",
1374 battle->getNick());
1375
1376 return;
1377 }
1378 }
1379 }
1380 }
1381 void do_heal(char *u)
1382 {
1383 aClient *ni;
1384 char *amount = strtok(NULL, " ");
1385 int price, num;
1386
1387 if (!amount)
1388 {
1389 notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}");
1390 }
1391 else if (!(ni = find(u)) || !ni->stats)
1392 {
1393 notice(s_GameServ, u, "You aren't playing!");
1394 }
1395 else if (is_fighting(u))
1396 {
1397 notice(s_GameServ, u, "You can't heal in battle!");
1398 }
1399 else if (ni->stats->hp >= ni->stats->maxhp)
1400 {
1401 notice(s_GameServ, u, "You don't need healing!");
1402 }
1403 else if (stricmp(amount, "ALL") == 0)
1404 {
1405 price = ni->stats->level * 3;
1406 if (ni->stats->gold < (ni->stats->maxhp - ni->stats->hp) * price)
1407 {
1408 notice(s_GameServ, u, "Healing \ 2%d\ 2 points for \ 2%d\ 2 gold per point.",
1409 (long int)ni->stats->gold/price, price);
1410 ni->stats->hp += ni->stats->gold / price;
1411 ni->stats->gold %= price;
1412 }
1413 else
1414 {
1415 notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\
1416 "per point.", price);
1417 notice(s_GameServ, u, "\ 2%d\ 2 points healed. HP at MAX!",
1418 (ni->stats->maxhp - ni->stats->hp));
1419 ni->stats->gold -= price * (ni->stats->maxhp - ni->stats->hp);
1420 ni->stats->hp = ni->stats->maxhp;
1421 }
1422 }
1423 else if (isstringnum(amount))
1424 {
1425 num = stringtoint(amount);
1426 price = ni->stats->level * 3;
1427 if (ni->stats->gold < price * num)
1428 {
1429 notice(s_GameServ, u, "You only have enough gold to heal \ 2%d\ 2 points!",
1430 (long int)ni->stats->gold/price);
1431 }
1432 else if (num <= ni->stats->maxhp - ni->stats->hp)
1433 {
1434 notice(s_GameServ, u, "Healing \ 2%d\ 2 points at \ 2%d\ 2 gold per point.",
1435 num, price);
1436 ni->stats->hp += num;
1437 ni->stats->gold -= num * price;
1438 }
1439 else if (num > ni->stats->maxhp - ni->stats->hp)
1440 {
1441 notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\
1442 "per point.", price);
1443 notice(s_GameServ, u, "\ 2%d\ 2 points healed. HP at MAX!",
1444 (ni->stats->maxhp - ni->stats->hp));
1445 ni->stats->gold -= price * (ni->stats->maxhp - ni->stats->hp);
1446 ni->stats->hp = ni->stats->maxhp;
1447 }
1448 }
1449 else if (amount[0] == '-')
1450 notice(s_GameServ, u, "You trying to cheat?");
1451 else
1452 notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}");
1453 }
1454
1455 int isstringnum(char *num)
1456 {
1457 int x;
1458 for (x = 0; x < strlen(num); x++)
1459 {
1460 if ((int)num[x] < 48 || (int)num[x] > 57)
1461 return 0;
1462 }
1463 return 1;
1464 }
1465
1466 long int stringtoint(char *number)
1467 {
1468 long int x, len = strlen(number), sum = 0;
1469 if (len == 1)
1470 return chartoint(number[0]);
1471 sum += chartoint(number[len - 1]);
1472 for (x = len - 2; x >= 0; x--)
1473 {
1474 sum += chartoint(number[x]) * pow(10, abs(x - len + 1));
1475 }
1476 return sum;
1477 }
1478
1479 long int pow(int x, int y)
1480 {
1481 long int value = 0;
1482 int count = 0;
1483 value += x;
1484
1485 if (x != 0 && y != 0)
1486 {
1487 for (count = 1; count <= y - 1; count++)
1488 value *= x;
1489 }
1490 else
1491 return 1;
1492 return value;
1493 }
1494
1495 long int chartoint(char ch)
1496 {
1497 switch(ch)
1498 {
1499 case '0':
1500 return 0;
1501 break;
1502 case '1':
1503 return 1;
1504 case '2':
1505 return 2;
1506 case '3':
1507 return 3;
1508 case '4':
1509 return 4;
1510 case '5':
1511 return 5;
1512 case '6':
1513 return 6;
1514 case '7':
1515 return 7;
1516 case '8':
1517 return 8;
1518 case '9':
1519 return 9;
1520 case '\n':
1521 break;
1522 default:
1523 return -1;
1524 }
1525 return -1;
1526 }
1527
1528 int save_gs_dbase()
1529 {
1530 ListNode<aClient> *ptr = players.First();
1531 Player *it;
1532 ofstream outfile;
1533
1534 outfile.open(playerdata);
1535
1536 if (!outfile)
1537 {
1538 cerr << "Error opening " << playerdata << endl;
1539 return 0;
1540 }
1541
1542 while(ptr)
1543 {
1544 it = ptr->getData()->stats;
1545 outfile << it->name << ' ' << it->level << ' ' << it->exp << ' ' << it->gold << ' ' << it->bank << ' '
1546 << it->hp << ' ' << it->maxhp << ' ' << it->strength << ' ' << it->defense << ' '
1547 << it->armor << ' ' << it->weapon << ' ' << (it->alive ? "alive" : "dead") << ' '
1548 << it->forest_fights << ' ' << it->player_fights << endl;
1549 ptr = ptr->Next();
1550 }
1551 outfile.close();
1552 }
1553
1554 int load_gs_dbase()
1555 {
1556 ifstream infile;
1557 aClient *temp;
1558 Player *p;
1559 char *alive, *tempname, *buf;
1560 buf = new char[1023];
1561
1562 infile.open(playerdata);
1563
1564 if (infile.fail())
1565 {
1566 cerr << "Error opening " << playerdata << endl;
1567 return 0;
1568 }
1569
1570 while (infile.getline(buf, 1024, '\n'))
1571 {
1572 temp = new aClient;
1573 tempname = strtok(buf, " ");
1574 temp->stats = new Player(tempname);
1575 p = temp->stats;
1576
1577 //Kain 1 1 0 500 10 10 0 0 1 1 alive 100 3
1578 p->level = stringtoint(strtok(NULL, " "));
1579 p->exp = stringtoint(strtok(NULL, " "));
1580 p->gold = stringtoint(strtok(NULL, " "));
1581 p->bank = stringtoint(strtok(NULL, " "));
1582 p->hp = stringtoint(strtok(NULL, " "));
1583 p->maxhp = stringtoint(strtok(NULL, " "));
1584 p->strength = stringtoint(strtok(NULL, " "));
1585 p->defense = stringtoint(strtok(NULL, " "));
1586 p->armor = stringtoint(strtok(NULL, " "));
1587 p->weapon = stringtoint(strtok(NULL, " "));
1588 alive = strtok(NULL, " ");
1589 p->alive = (stricmp(alive, "ALIVE") == 0 ? true : false);
1590 p->forest_fights = stringtoint(strtok(NULL, " "));
1591 p->player_fights = stringtoint(strtok(NULL, " "));
1592 temp->setNick("NULL");
1593
1594 printf("%s %d %ld %ld %ld %d %d %d %d %d %d %s %d %d\n", p->name, p->level, p->exp, p->gold, p->bank, p->hp, p->maxhp, p->strength, p->defense, p->armor, p->weapon, alive, p->forest_fights, p->player_fights);
1595 players.insertAtBack(temp);
1596 delete temp;
1597 }
1598 delete buf;
1599 }
1600