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