-
Notifications
You must be signed in to change notification settings - Fork 1
/
EffectManager.cpp
327 lines (280 loc) · 10.2 KB
/
EffectManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
// --------------------------------------------------------------------------------------------------------------------------------
// DEMISERL
// Copyright 2014 Corremn
//
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
// $HeadURL: $
// --------------------------------------------------------------------------------------------------------------------------------
#include "WorldBuilder.h"
#include ".\effectmanager.h"
EffectManager::EffectManager(void)
{
}
EffectManager::~EffectManager(void)
{
}
int EffectManager::RunEffect(MonsterData *monster, eEffect effect, int strength)
{
if (strength == 0)
return 0;
int ret = 0;
switch (effect)
{
case no_effect: break;
case poisoned: return RunPoison(monster, strength); break;
case repelMissiles:
ret = TestEffect(monster, effect, strength);
if (monster->isPlayer())
{
if (ret == REDUCED)
World.getTextManager().newLine("Your glow fades slightly. ");
else if (ret == REMOVED)
World.getTextManager().newLine("You stop glowing. ");
}
else if (monster->isSeen() && ret == REMOVED)
World.getTextManager().newLine("The %s stops glowing. ", monster->monster.name.c_str());
break;
case diseased:
ret = TestEffect(monster, effect, strength);
if (monster->isPlayer())
{
if (ret == REDUCED)
World.getTextManager().newLine("You feel healthier. ");
else if (ret == REMOVED)
World.getTextManager().newLine("You feel better. ");
}
else if (monster->isSeen() && ret == REMOVED)
World.getTextManager().newLine("The %s looks better. ", monster->monster.name.c_str());
break;
case slowed:
ret = TestEffect(monster, effect, strength);
if (monster->isPlayer())
{
if (ret == REDUCED)
World.getTextManager().newLine("You speed up slightly. ");
else if (ret == REMOVED)
World.getTextManager().newLine("You speed up. ");
}
else if (monster->isSeen() && ret == REMOVED)
World.getTextManager().newLine("The %s speeds up. ", monster->monster.name.c_str());
break;
case paralysis:
ret = TestEffect(monster, effect, strength);
if (monster->isPlayer())
{
if (ret == REDUCED)
World.getTextManager().newLine("You feel movement. ");
else if (ret == REMOVED)
World.getTextManager().newLine("You can move again. ");
}
else if (monster->isSeen() && ret == REMOVED)
World.getTextManager().newLine("The %s can move again. ", monster->monster.name.c_str());
break;
case teleportitus: ret = TestEffect(monster, effect, strength);
if (ret != REMOVED)
RunTeleport(monster, strength);
if (monster->isPlayer())
{
//if(ret == REDUCED)
// World.getTextManager().newLine("You feel more stable. ");
if (ret == REMOVED)
World.getTextManager().newLine("Your feel stable. ");
}
else if (monster->isSeen() && ret == REMOVED)
World.getTextManager().newLine("The %s looks stable. ", monster->monster.name.c_str());
break;
case confused:
ret = TestEffect(monster, effect, strength);
if (monster->isPlayer())
{
if (ret == REDUCED)
World.getTextManager().newLine("You feel less confused. ");
else if (ret == REMOVED)
World.getTextManager().newLine("Your head clears. ");
}
else if (monster->isSeen() && ret == REMOVED)
World.getTextManager().newLine("The %s looks normal. ", monster->monster.name.c_str());
break;
}
return ret;
}
int EffectManager::TestGetEffect(MonsterData *monster, eBrandType brand, int strength)
{
int monster_resistance = 0;
if (monster->monster.hasResistance()) //get natural resistance
{
monster_resistance = monster->monster.GetResistance(brand);
//resList.push_back(monster_resistance);
}
int found_all = 0;
ITEMLIST::iterator it;
//do //search through equipment
//{
int highest_res = monster_resistance;
for (it = monster->inventory.begin(); it != monster->inventory.end(); it++)
{
int res = it->GetResistance(brand);
if (res > highest_res)
highest_res = res;
}
//}while (!found_all);
//float modifier = 1-(highest_res)*0.3f;
//new_damage = (int)((damage* modifier)+.5f);
int hit = Random::getInt(10, 0);
int avoid = Random::getInt(10, 0);
if (hit*(strength) > avoid*(highest_res + 1) && !Random::getInt(3, 0)) //+33% chance to tone it down
return 1;
return 0;
}
void EffectManager::AddBrandEffect(MonsterData *monster, eBrandType brand, int strength)
{
switch (brand)
{
case bPoison: monster->monster.AddEffect(poisoned, strength); break;
case bParalysis: monster->monster.AddEffect(paralysis, strength); break;
if(monster->isPlayer())
World.getTextManager().newLine("You are paralysed. ");
else if(monster->isSeen())
World.getTextManager().newLine("The %s is paralysed. ",monster->monster.name.c_str());;
break;
}
}
void EffectManager::AddOtherEffect(MonsterData *monster, eEffect effect, int strength) //spell/potion/scroll
{
monster->monster.AddEffect(effect, strength);
/*switch(effect)
{
case bPoison: monster->monster.AddEffect(poisoned,strength);
break;
}*/
}
int EffectManager::TestEffect(MonsterData *monster, eEffect effect, int strength)
{
int ret = NO_CHANGE;
//get Resistance
int resistance = monster->monster.GetResistance(EquivalentResistance(effect));
//determine reducement
int chance = Random::getInt(10, 0);
if (chance < resistance + 1)//10% chance reduction + 10% for each resistance point - 0= 10%
{
monster->monster.ReduceEffect(effect, 1);
ret = REDUCED;
}
//determine effect
if (monster->monster.GetEffect(effect) == 0)
ret = REMOVED;
return ret;
}
int EffectManager::RunSlowed(MonsterData *monster, int strength)
{
//get Resistance
int resistance = monster->monster.GetResistance(bSlow);
//determine reducement
int chance = Random::getInt(10, 0);
if (chance < resistance + 1)//10% chance reduction + 10% for each resistance point - 0= 10%
{
if (monster->isPlayer())
World.getTextManager().newLine("You speed up slightly. ");
monster->monster.ReduceEffect(slowed, 1);
}
//determine effect
if (monster->monster.GetEffect(slowed) > 0)
{
// nothing for slowed
return 1;
}
else
{
if (monster->isPlayer())
World.getTextManager().newLine("You speed up. ");
else if (monster->isSeen())
World.getTextManager().newLine("The %s speeds up. ", monster->monster.name.c_str());
return 0;
}
}
int EffectManager::RunPoison(MonsterData *monster, int strength)
{
unsigned char c1 = monster->monster.color1;
unsigned char c2 = monster->monster.color2;
unsigned char c3 = monster->monster.color3;
monster->monster.setColour(0, 255, 0);
World.RenderScene();
Sleep(20);
monster->monster.setColour(c1, c2, c3);
World.RenderScene();
//get Resistance
int resistance = monster->monster.GetResistance(EquivalentResistance(poisoned));
//determine reducement
int chance = Random::getInt(10, 0);
if (chance < resistance + 1)//10% chance reduction + 10% for each resistance point - 0= 10%
{
monster->monster.ReduceEffect(poisoned, 1);
if (monster->isPlayer())
World.getTextManager().newLine("You feel less poisoned. ");
return REDUCED;
}
//determine effect
if (monster->monster.GetEffect(poisoned) > 0)
{
int damage = Random::getInt(10, 0);
if (damage > resistance + 5) //50% take damage + 10% for each resistance point
{
monster->monster.stamina--;
if (monster->isPlayer())
{
World.getTextManager().newLine("You are poisoned. ");
World.getDeathMessage().SetDeathMessage("became immune to poison the moment he died of it. ");
}
else if (monster->isSeen())
World.getTextManager().newLine("The %s is poisoned. ", monster->monster.name.c_str());
}
}
else
{
if (monster->isPlayer())
World.getTextManager().newLine("You are no longer poisoned. ");
else if (monster->isSeen())
World.getTextManager().newLine("The %s recovers. ", monster->monster.name.c_str());
return REMOVED;
}
return NO_CHANGE;
}
void EffectManager::RunTeleport(MonsterData *monster, int strength)
{
int resistance = monster->monster.GetResistance(EquivalentResistance(teleportitus));
int chance = Random::getInt(100, 0) + strength * 2;
if (chance > 98)
{
int range = 10 * strength;
//Teleport(monster,range);
}
}
eBrandType EffectManager::EquivalentResistance(eEffect effect)
{
switch (effect)
{
case poisoned: return bPoison;
case diseased: return bDisease;
case slowed: return bSlow;
case paralysis: return bParalysis;
case teleportitus: return bDisplacment;
case confused: return bConfusion;
default: return bNone;
}
}
const std::string EffectManager::EffectName(eEffect effect)
{
switch (effect)
{
case poisoned: return "Posioned";
case diseased: return "Diseased";
case slowed: return "Slowed";
case paralysis: return "Paralysed";
case teleportitus: return "Teleports";
case confused: return "Confused";
case repelMissiles: return "Repel Missiles";
default: return "Error";
}
}