]> jfr.im git - irc/gameservirc.git/blob - gameserv/c_forest.cpp
Added a lot of functionality. Added player flags and save/load them in the players...
[irc/gameservirc.git] / gameserv / c_forest.cpp
1 #include "sockhelp.h"
2 #include "aClient.h"
3 #include "list.h"
4 #include "extern.h"
5 #include <cctype>
6
7 void do_forest(char *u);
8 Monster *getNewMonster(Monster *m);
9 void deleteMonster(Monster *m);
10
11 void forest(char *source, char *buf)
12 {
13 char *cmd = strtok(buf, " ");
14
15 if (cmd[0] == ':')
16 cmd++;
17 if (source[0] == ':')
18 source++;
19
20 if (stricmp(cmd, "SEARCH") == 0)
21 {
22 do_forest(source);
23 } else if (stricmp(cmd, "ATTACK") == 0) {
24 do_attack(source);
25 } else if (stricmp(cmd, "RUN") == 0) {
26 do_run(source);
27 } else if (stricmp(cmd, "HEAL") == 0) {
28 do_heal(source);
29 }
30
31 source--;
32 }
33
34 void do_forest(char *u)
35 {
36 aClient *source;
37
38 int num = rand() % 12;
39
40
41 if (!(source = find(u)) || !source->stats)
42 {
43 notice(s_GameServ, u, "You must be playing the game to search the forest!");
44 return;
45 }
46 else if (!is_alive(source))
47 {
48 notice(s_GameServ, u, "You are dead. Wait until tomorrow to search the forest some more.");
49 return;
50 }
51 else
52 {
53 if (source->stats->forest_fights <= 0)
54 {
55 notice(s_GameServ, u, "You are out of forest fights for the day. Wait "\
56 "till tomorrow!");
57 return;
58 }
59 else if (!is_fighting(u))
60 {
61 Player *p = source->stats;
62 p->forest_fights--;
63 p->fight = new Monster(monsters[p->level - 1][num]);
64 notice(s_GameServ, u, "You search the forest for something to kill...");
65 notice(s_GameServ, u, "You have found \ 2%s\ 2!", p->fight->name);
66 p->fight->hp = p->fight->maxhp;
67
68 p->battle = NULL; // Just to make sure
69 p->master = NULL; // Just to make sure
70 display_monster(u);
71 }
72 else if (is_fighting(u))
73 {
74 notice(s_GameServ, u, "You want to fight two monsters at once?");
75 }
76 }
77
78 }
79
80 Monster *getNewMonster(Monster *m)
81 {
82 if (!m)
83 return NULL;
84
85 Monster *newguy;
86 newguy = new Monster;
87
88 if (m->name)
89 {
90 newguy->name = new char[strlen(m->name)];
91 strcpy(newguy->name, m->name);
92 }
93 if (m->weapon)
94 {
95 newguy->weapon = new char[strlen(m->weapon)];
96 strcpy(newguy->weapon, m->weapon);
97 }
98 if (m->death)
99 {
100 newguy->death = new char[strlen(m->death)];
101 strcpy(newguy->death, m->death);
102 }
103
104 newguy->strength = m->strength;
105 newguy->gold = m->gold;
106 newguy->exp = m->exp;
107 newguy->hp = m->hp;
108 newguy->maxhp = m->maxhp;
109 return newguy;
110 }