]> jfr.im git - irc/gameservirc.git/blob - gameserv/c_forest.cpp
added items to the tavern.dat, added the filename option to the config file
[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 "flags.h"
6 #include <cctype>
7
8 void do_forest(char *u);
9 Monster *getNewMonster(Monster *m);
10 void deleteMonster(Monster *m);
11
12 void forest(char *source, char *buf)
13 {
14 char *cmd = strtok(buf, " ");
15
16 if (cmd[0] == ':')
17 cmd++;
18 if (source[0] == ':')
19 source++;
20
21 if (stricmp(cmd, "SEARCH") == 0)
22 {
23 do_forest(source);
24 } else if (stricmp(cmd, "ATTACK") == 0) {
25 do_attack(source);
26 } else if (stricmp(cmd, "RUN") == 0) {
27 do_run(source);
28 } else if (stricmp(cmd, "HEAL") == 0) {
29 do_heal(source);
30 }
31
32 source--;
33 }
34
35 void do_forest(char *u)
36 {
37 aClient *source;
38
39 if (!(source = find(u)))
40 {
41 notice(s_GameServ, u, "Fatal Error in do_forest. Contact a %S admin for help.");
42 return;
43 }
44 else if (!is_playing(source))
45 {
46 notice(s_GameServ, u, "You must be playing the game to search the forest!");
47 return;
48 }
49 Player *p = source->stats;
50
51 if (!isAlive(p))
52 {
53 notice(s_GameServ, u, "You are dead. Wait until tomorrow to search the forest some more.");
54 return;
55 }
56 else
57 {
58 updateTS(source->stats);
59 if (p->forest_fights <= 0)
60 {
61 notice(s_GameServ, u, "You are out of forest fights for the day. Wait "\
62 "till tomorrow!");
63 return;
64 }
65 else if (!is_fighting(source))
66 {
67 int eventnum = rand() % 100;
68 p->forest_fights--;
69
70 notice(s_GameServ, u, "You search the forest for something to kill...");
71
72 // 88% of forest searching turns up a monster
73 if (eventnum >= 12)
74 {
75 p->fight = new Monster(levels[p->level - 1].randomMonster());
76 notice(s_GameServ, u, "You have found \ 2%s\ 2!", p->fight->name.c_str());
77 if (p->fight->hp < p->fight->maxhp)
78 p->fight->hp = p->fight->maxhp;
79
80 p->battle = NULL; // Just to make sure
81 p->master = NULL; // Just to make sure
82 display_monster(u);
83 }
84 /*
85 else if (eventnum < 12 && eventnum >= 10) // 2% for finding potions
86 {
87 notice(s_GameServ, u, "Fortune smiles upon thee!");
88
89 eventnum = 1 + rand() % 4;
90 switch(eventnum)
91 {
92 case 1:
93 notice(s_GameServ, u,
94 "You have found an HP Potion!");
95 p->inventory.incHP();
96 break;
97 case 2:
98 notice(s_GameServ, u,
99 "You have found a Strength Potion!");
100 p->inventory.incStrength();
101 break;
102 case 3:
103 notice(s_GameServ, u,
104 "You have found a Defense Potion!");
105 p->inventory.incDefense();
106 break;
107 case 4:
108 notice(s_GameServ, u,
109 "You have found a Healing Potion!");
110 p->inventory.incHealing();
111 break;
112 }
113 }
114 */
115 else if (eventnum < 10 && eventnum >= 5) // 5% for the fountain
116 {
117 if (p->hp < p->maxhp)
118 {
119 notice(s_GameServ, u, "In your path lies a beautiful fountain from which flows the crystal waters of life.");
120 notice(s_GameServ, u, "You wet your lips on the cool blue waters and feel rejuvenated");
121 p->hp = p->maxhp;
122 }
123 else
124 {
125 notice(s_GameServ, u, "In your path lies a beautiful fountain from which flows the crystal waters of life.");
126 notice(s_GameServ, u, "You are not thirsty, though, and you don't need healing. Best to leave this for the next warrior");
127 p->forest_fights++;
128 }
129 }
130 else if (eventnum < 5) // 5 % for the wishing well
131 {
132 notice(s_GameServ, u, "You come upon a pure green emerald studded magic wishing well.");
133 if (p->gold == 0)
134 {
135 notice(s_GameServ, u, "Too bad you're broke. Guess you won't be having any wishes answered today.");
136 p->forest_fights++;
137 return;
138 }
139 long newstats;
140 notice(s_GameServ, u, "You throw one of your gold pieces into the well and it vanishes into a puff of white smoke.");
141 notice(s_GameServ, u, "In an instant, the puff of smoke materializes into a gnome.");
142 notice(s_GameServ, u, "The gnome is holding something in his hand motioning for you to come closer.");
143 notice(s_GameServ, u, "It is a wand! The gnome is waving it through the air towards you!");
144 // 2% for each wishing well chance except for forest fights
145 if (eventnum < 1) // forest fights
146 {
147 newstats = (rand() % 11) + 5;
148 notice(s_GameServ, u, "%ld EXTRA FOREST FIGHTS!!",
149 newstats);
150 p->forest_fights += newstats;
151 }
152 else if (eventnum < 3)
153 {
154 newstats = levels[p->level - 1].getStrength().random();
155 notice(s_GameServ, u, "A SACK WITH %ld GOLD!", newstats);
156 p->gold += newstats;
157 }
158 else
159 {
160 newstats = levels[p->level - 1].getExp().random();
161 notice(s_GameServ, u, "Time seems to stand still for a moment.");
162 notice(s_GameServ, u, " %ld EXTRA EXPERIENCE POINTS", newstats);
163 p->exp += newstats;
164 }
165 }
166 }
167 else if (is_fighting(u))
168 {
169 notice(s_GameServ, u, "You want to fight two monsters at once?");
170 }
171 }
172
173 }
174
175 Monster *getNewMonster(Monster *m)
176 {
177 if (!m)
178 return NULL;
179
180 Monster *newguy;
181 newguy = new Monster;
182 newguy->name = m->name;
183 newguy->weapon = m->weapon;
184 newguy->death = m->death;
185 newguy->strength = m->strength;
186 newguy->gold = m->gold;
187 newguy->exp = m->exp;
188 newguy->hp = m->hp;
189 newguy->maxhp = m->maxhp;
190 return newguy;
191 }