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