-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpellManager.cpp
209 lines (172 loc) · 5.77 KB
/
SpellManager.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
// --------------------------------------------------------------------------------------------------------------------------------
// DEMISERL
// Copyright 2014 Corremn
//
// $LastChangedBy$
// $LastChangedDate$
// $LastChangedRevision$
// $HeadURL: $
// --------------------------------------------------------------------------------------------------------------------------------
#include "WorldBuilder.h"
#include "CastSpell.h"
int SpellManager::Initialise(void)
{
CreateSpell(spFlyingWeapon);
CreateSpell(spSlowEnemies);
CreateSpell(spRepelMissiles);
CreateSpell(spTeleport);
CreateSpell(spDragonFire);
return 1;
}
void SpellManager::CreateSpell(eSpellList type)
{
SpellBase s;
if (s.CreateSpell(type))
all_spells.push_back(s);
}
int SpellManager::CallSpellRoutine(MonsterData* caster, int spell) //call spell from list;
{
//GetSpell from caster spell list
if (caster->spellList.size() == 0)
{
//throw std::exception("Cant cast spell");
return 0;
}
MONSTERSPELLLIST::iterator sp;
int i = 0;
for (sp = caster->spellList.begin(); sp != caster->spellList.end(); sp++, i++)
{
if (spell == i)
return CastSpell(caster, (*sp)->GetSpell());
}
currentSpell = spNone;
//throw std::exception("Cant cast spell");
return 0;
}
int SpellManager::AddMonsterSpell(MonsterData* caster, eSpellList spell)
{
SPELLLIST::iterator sp;
// check spell exists
for (sp = all_spells.begin(); sp != all_spells.end(); sp++)
{
if (sp->GetSpell() == spell)
{
bool allreadyHasit = false;
for (MONSTERSPELLLIST::iterator it = caster->spellList.begin(); it != caster->spellList.end(); it++)
{
if ((*it)->GetSpell() == spell)
allreadyHasit = true;
}
if (!allreadyHasit)
caster->spellList.push_back(&(*sp));
}
}
return 1;
}
SpellBase* SpellManager::GetMonsterSpell(MonsterData*caster, int random_spell)
{
MONSTERSPELLLIST::iterator sp;
int i = 0;
for (sp = caster->spellList.begin(); sp != caster->spellList.end(); sp++, i++)
{
if (i == random_spell)
return (*sp);
}
return NULL;
}
int SpellManager::CastSpell(MonsterData* caster, int spell)
{
CastMagic s;
switch (spell)
{
case spFlyingWeapon:
if (!caster->isPlayer())
SpellText(caster, "casts magic missile at you");
currentSpell = spFlyingWeapon;
return SELECT_TARGET;
case spSlowEnemies:
if (!caster->isPlayer())
SpellText(caster, "points at you and curses");
s.SlowEnemies(caster); currentSpell = spSlowEnemies;
return NORMAL;
case spRepelMissiles:
if (!caster->isPlayer())
{
if (Random::getInt(2, 0) == 1)
SpellText(caster, "glows blue");
else
SpellText(caster, "glows purple");
}
s.RepelMissiles(caster); currentSpell = spRepelMissiles;
return NORMAL;
case spTeleport:
if (!caster->isPlayer())
SpellText(caster, "blinks");
else
World.getTextManager().newLine("You blink. ");
s.Teleport(caster); currentSpell = spTeleport;
return NORMAL;
case spDragonFire:
if (!caster->isPlayer())
SpellText(caster, "breaths fire at you");
else
World.getTextManager().newLine("You breath fire. ");
currentSpell = spDragonFire;
return SELECT_TARGET;
}
currentSpell = spNone;
return CANCELED; //never get here
}
void SpellManager::SpellText(MonsterData* caster, const char * spell_name)
{
if (caster->isPlayer())
World.getTextManager().newLine("You cast %s. ", spell_name);
else
World.getTextManager().newLine("The %s %s. ", caster->Name().c_str(), spell_name);
}
int SpellManager::CastCurrentSpell(MonsterData* caster, int targetX, int targetY) //target select spells
{
//CastSpellAt(caster,x,y,currentSpell);
CastMagic s;
DungeonLevel* level = World.getDungeonManager().CurrentLevel();
level->HighLightPath(caster->pos.x, caster->pos.y, targetX, targetY);
COORDLIST::iterator it;
for (it = level->show_path.begin(); it != level->show_path.end(); it++)
{
if (!level->IsCellTransparent(it->x, it->y) || level->getCell(it->x, it->y).monsterExists())
{
int ret = 0;
switch (currentSpell)
{
case spFlyingWeapon: ret = s.FlyingWeapon(caster, it->x, it->y); break;
case spSlowEnemies: ret = s.SlowEnemies(caster); break;
case spRepelMissiles: ret = s.RepelMissiles(caster); break;
case spTeleport: ret = s.Teleport(caster); break;
case spDragonFire: ret = s.DragonBreath(caster, it->x, it->y); break;
}
World.getDungeonManager().CurrentLevel()->ClearPath(); //uncomment to remove path from monsters
return ret;
}
}
World.getDungeonManager().CurrentLevel()->ClearPath();
return 0;
}
void SpellManager::PrintSpells()
{
//printf items
#ifdef _DEBUG
std::ofstream ofile;
ofile.open("Debug Files\\spells.txt");
if (!ofile.is_open())
throw std::exception("Could not open spells.txt");
ofile << "Items" << std::endl;
ofile << "Name" << std::endl << std::endl;
SPELLLIST::iterator sp;
for (sp = all_spells.begin(); sp != all_spells.end(); sp++)
{
ofile << sp->Name();
ofile << std::endl;
}
ofile.close();
#endif
}