]> jfr.im git - irc/gameservirc.git/blob - gameserv/c_forest.cpp
df681627ba79a8fbc7c9f0e85a59417f426e2623
[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 int eventnum = rand() % 100;
62 Player *p = source->stats;
63 p->forest_fights--;
64
65 notice(s_GameServ, u, "You search the forest for something to kill...");
66
67 if (eventnum >= 25)
68 {
69 p->fight = new Monster(monsters[p->level - 1][num]);
70 notice(s_GameServ, u, "You have found \ 2%s\ 2!", p->fight->name);
71 p->fight->hp = p->fight->maxhp;
72
73 p->battle = NULL; // Just to make sure
74 p->master = NULL; // Just to make sure
75 display_monster(u);
76 }
77 else if (eventnum < 25 && eventnum >= 15) // 10%
78 {
79 notice(s_GameServ, u, "In your path lies a beautiful fountain from which flows the crystal waters of life.");
80 notice(s_GameServ, u, "You wet your lips on the cool blue waters and feel rejuvenated");
81 p->forest_fights += 10;
82 p->hp = p->maxhp;
83 }
84 else if (eventnum < 15) // 15 % for the wishing well
85 {
86 notice(s_GameServ, u, "You come upon a pure green emerald studded magic wishing well.");
87 if (p->gold == 0)
88 {
89 notice(s_GameServ, u, "Too bad you're broke. Guess you won't be having any wishes answered today.");
90 return;
91 }
92 notice(s_GameServ, u, "You throw one of your gold pieces into the well and it vanishes into a puff of white smoke.");
93 notice(s_GameServ, u, "In an instant, the puff of smoke materializes into a gnome.");
94 notice(s_GameServ, u, "The gnome is holding something in his hand motioning for you to come closer.");
95 notice(s_GameServ, u, "It is a wand! The gnome is waving it through the air towards you!");
96 // 5% for each wishing well chance
97 if (eventnum < 5) // forest fights
98 {
99 notice(s_GameServ, u, "EXTRA FOREST FIGHTS!!");
100 p->forest_fights += (rand() % 11) + 5;
101 }
102 else if (eventnum < 10)
103 {
104 notice(s_GameServ, u, "A SACK OF GOLD!");
105 p->gold += (rand() % 1000) * (p->level + (rand() % 10));
106 }
107 else
108 {
109 notice(s_GameServ, u, "Time seems to stand still for a moment.");
110 notice(s_GameServ, u, "EXTRA EXPERIENCE POINTS");
111 p->exp += (rand() % 100) * (p->level + rand() % 10);
112 }
113 }
114 }
115 else if (is_fighting(u))
116 {
117 notice(s_GameServ, u, "You want to fight two monsters at once?");
118 }
119 }
120
121 }
122
123 Monster *getNewMonster(Monster *m)
124 {
125 if (!m)
126 return NULL;
127
128 Monster *newguy;
129 newguy = new Monster;
130
131 if (m->name)
132 {
133 newguy->name = new char[strlen(m->name)];
134 strcpy(newguy->name, m->name);
135 }
136 if (m->weapon)
137 {
138 newguy->weapon = new char[strlen(m->weapon)];
139 strcpy(newguy->weapon, m->weapon);
140 }
141 if (m->death)
142 {
143 newguy->death = new char[strlen(m->death)];
144 strcpy(newguy->death, m->death);
145 }
146
147 newguy->strength = m->strength;
148 newguy->gold = m->gold;
149 newguy->exp = m->exp;
150 newguy->hp = m->hp;
151 newguy->maxhp = m->maxhp;
152 return newguy;
153 }