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