-
Notifications
You must be signed in to change notification settings - Fork 0
/
combat.h
365 lines (296 loc) · 10.6 KB
/
combat.h
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
////////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
////////////////////////////////////////////////////////////////////////
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////
#ifndef __COMBAT__
#define __COMBAT__
#include "otsystem.h"
#include "baseevents.h"
#include "condition.h"
#include "map.h"
class Condition;
class Creature;
class Position;
class Item;
//for luascript callback
class ValueCallback : public CallBack
{
public:
ValueCallback(formulaType_t _type) {type = _type;}
void getMinMaxValues(Player* player, int32_t& min, int32_t& max, bool useCharges) const;
protected:
formulaType_t type;
};
class TileCallback : public CallBack
{
public:
TileCallback() {}
void onTileCombat(Creature* creature, Tile* tile) const;
protected:
formulaType_t type;
};
class TargetCallback : public CallBack
{
public:
TargetCallback() {}
void onTargetCombat(Creature* creature, Creature* target) const;
protected:
formulaType_t type;
};
struct CombatEffects
{
CombatEffects(bool _show): show(_show)
{
color = TEXTCOLOR_UNKNOWN;
distance = SHOOT_EFFECT_NONE;
impact = MAGIC_EFFECT_NONE;
hit = MAGIC_EFFECT_UNKNOWN;
}
CombatEffects()
{
color = TEXTCOLOR_UNKNOWN;
distance = SHOOT_EFFECT_NONE;
impact = MAGIC_EFFECT_NONE;
hit = MAGIC_EFFECT_UNKNOWN;
show = true;
}
MagicEffect_t impact, hit;
ShootEffect_t distance;
TextColor_t color;
bool show;
};
struct CombatParams
{
CombatParams()
{
blockedByArmor = blockedByShield = targetCasterOrTopMost = targetPlayersOrSummons = differentAreaDamage = false;
isAggressive = useCharges = true;
dispelType = CONDITION_NONE;
combatType = COMBAT_NONE;
itemId = 0;
targetCallback = NULL;
valueCallback = NULL;
tileCallback = NULL;
}
bool blockedByArmor, blockedByShield, targetCasterOrTopMost, targetPlayersOrSummons, differentAreaDamage, useCharges, isAggressive;
ConditionType_t dispelType;
CombatType_t combatType;
uint32_t itemId;
TargetCallback* targetCallback;
ValueCallback* valueCallback;
TileCallback* tileCallback;
CombatEffects effects;
std::list<const Condition*> conditionList;
};
struct Combat2Var
{
int32_t minChange, maxChange, change;
Combat2Var() {minChange = maxChange = change = 0;}
};
typedef bool (*COMBATFUNC)(Creature*, Creature*, const CombatParams&, void*);
class MatrixArea
{
public:
MatrixArea(uint32_t _rows, uint32_t _cols)
{
centerX = centerY = 0;
rows = _rows;
cols = _cols;
data_ = new bool*[rows];
for(uint32_t row = 0; row < rows; ++row)
{
data_[row] = new bool[cols];
for(uint32_t col = 0; col < cols; ++col)
data_[row][col] = 0;
}
}
MatrixArea(const MatrixArea& rhs)
{
centerX = rhs.centerX;
centerY = rhs.centerY;
rows = rhs.rows;
cols = rhs.cols;
data_ = new bool*[rows];
for(uint32_t row = 0; row < rows; ++row)
{
data_[row] = new bool[cols];
for(uint32_t col = 0; col < cols; ++col)
data_[row][col] = rhs.data_[row][col];
}
}
virtual ~MatrixArea()
{
for(uint32_t row = 0; row < rows; ++row)
delete[] data_[row];
delete[] data_;
}
void setValue(uint32_t row, uint32_t col, bool value) const {data_[row][col] = value;}
bool getValue(uint32_t row, uint32_t col) const {return data_[row][col];}
void setCenter(uint16_t y, uint16_t x) {centerX = x; centerY = y;}
void getCenter(uint16_t& y, uint16_t& x) const {x = centerX; y = centerY;}
size_t getRows() const {return rows;}
size_t getCols() const {return cols;}
inline const bool* operator[](uint32_t i) const { return data_[i]; }
inline bool* operator[](uint32_t i) { return data_[i]; }
protected:
uint16_t centerX, centerY;
uint32_t rows, cols;
bool** data_;
};
typedef std::map<Direction, MatrixArea* > CombatAreas;
class CombatArea
{
public:
CombatArea() {hasExtArea = false;}
virtual ~CombatArea() {clear();}
CombatArea(const CombatArea& rhs);
ReturnValue doCombat(Creature* attacker, const Position& pos, const Combat& combat) const;
bool getList(const Position& centerPos, const Position& targetPos, std::list<Tile*>& list) const;
void setupArea(const std::list<uint32_t>& list, uint32_t rows);
void setupArea(int32_t length, int32_t spread);
void setupArea(int32_t radius);
void setupExtArea(const std::list<uint32_t>& list, uint32_t rows);
void clear();
protected:
enum MatrixOperation_t
{
MATRIXOPERATION_COPY,
MATRIXOPERATION_MIRROR,
MATRIXOPERATION_FLIP,
MATRIXOPERATION_ROTATE90,
MATRIXOPERATION_ROTATE180,
MATRIXOPERATION_ROTATE270,
};
MatrixArea* createArea(const std::list<uint32_t>& list, uint32_t rows);
void copyArea(const MatrixArea* input, MatrixArea* output, MatrixOperation_t op) const;
MatrixArea* getArea(const Position& centerPos, const Position& targetPos) const
{
int32_t dx = targetPos.x - centerPos.x, dy = targetPos.y - centerPos.y;
Direction dir = NORTH;
if(dx < 0)
dir = WEST;
else if(dx > 0)
dir = EAST;
else if(dy < 0)
dir = NORTH;
else
dir = SOUTH;
if(hasExtArea)
{
if(dx < 0 && dy < 0)
dir = NORTHWEST;
else if(dx > 0 && dy < 0)
dir = NORTHEAST;
else if(dx < 0 && dy > 0)
dir = SOUTHWEST;
else if(dx > 0 && dy > 0)
dir = SOUTHEAST;
}
CombatAreas::const_iterator it = areas.find(dir);
if(it != areas.end())
return it->second;
return NULL;
}
CombatAreas areas;
bool hasExtArea;
};
class Combat
{
public:
Combat();
virtual ~Combat();
static void doCombatHealth(Creature* caster, Creature* target,
int32_t minChange, int32_t maxChange, const CombatParams& params);
static void doCombatHealth(Creature* caster, const Position& pos,
const CombatArea* area, int32_t minChange, int32_t maxChange, const CombatParams& params);
static void doCombatMana(Creature* caster, Creature* target,
int32_t minChange, int32_t maxChange, const CombatParams& params);
static void doCombatMana(Creature* caster, const Position& pos,
const CombatArea* area, int32_t minChange, int32_t maxChange, const CombatParams& params);
static void doCombatCondition(Creature* caster, Creature* target,
const CombatParams& params);
static void doCombatCondition(Creature* caster, const Position& pos,
const CombatArea* area, const CombatParams& params);
static void doCombatDispel(Creature* caster, Creature* target,
const CombatParams& params);
static void doCombatDispel(Creature* caster, const Position& pos,
const CombatArea* area, const CombatParams& params);
static void getCombatArea(const Position& centerPos, const Position& targetPos,
const CombatArea* area, std::list<Tile*>& list);
static bool isInPvpZone(const Creature* attacker, const Creature* target);
static bool isProtected(Player* attacker, Player* target);
static CombatType_t ConditionToDamageType(ConditionType_t type);
static ConditionType_t DamageToConditionType(CombatType_t type);
static ReturnValue canTargetCreature(const Player* attacker, const Creature* target);
static ReturnValue canDoCombat(const Creature* caster, const Tile* tile, bool isAggressive);
static ReturnValue canDoCombat(const Creature* attacker, const Creature* target);
static void postCombatEffects(Creature* caster, const Position& pos, const CombatParams& params);
static void addDistanceEffect(Creature* caster, const Position& fromPos, const Position& toPos, ShootEffect_t effect);
void doCombat(Creature* caster, Creature* target) const;
void doCombat(Creature* caster, const Position& pos) const;
bool setCallback(CallBackParam_t key);
CallBack* getCallback(CallBackParam_t key);
void setArea(CombatArea* _area)
{
if(area)
delete area;
area = _area;
}
bool hasArea() const {return area != NULL;}
bool setParam(CombatParam_t param, uint32_t value);
void setCondition(const Condition* _condition) {params.conditionList.push_back(_condition);}
void setPlayerCombatValues(formulaType_t _type, double _mina, double _minb, double _maxa,
double _maxb, double _minl, double _maxl, double _minm, double _maxm, int32_t _minc,
int32_t _maxc);
void postCombatEffects(Creature* caster, const Position& pos) const
{Combat::postCombatEffects(caster, pos, params);}
protected:
static void doCombatDefault(Creature* caster, Creature* target, const CombatParams& params);
static void CombatFunc(Creature* caster, const Position& pos,
const CombatArea* area, const CombatParams& params, COMBATFUNC func, void* data);
static bool CombatHealthFunc(Creature* caster, Creature* target, const CombatParams& params, void* data);
static bool CombatManaFunc(Creature* caster, Creature* target, const CombatParams& params, void* data);
static bool CombatConditionFunc(Creature* caster, Creature* target, const CombatParams& params, void* data);
static bool CombatDispelFunc(Creature* caster, Creature* target, const CombatParams& params, void* data);
static bool CombatNullFunc(Creature* caster, Creature* target, const CombatParams& params, void* data);
static void combatTileEffects(const SpectatorVec& list, Creature* caster, Tile* tile, const CombatParams& params);
bool getMinMaxValues(Creature* creature, Creature* target, int32_t& min, int32_t& max) const;
//configureable
CombatParams params;
//formula variables
formulaType_t formulaType;
double mina, minb, maxa, maxb, minl, maxl, minm, maxm;
int32_t minc, maxc;
CombatArea* area;
};
class MagicField : public Item
{
public:
MagicField(uint16_t _type) : Item(_type) {createTime = OTSYS_TIME();}
virtual ~MagicField() {}
virtual MagicField* getMagicField() {return this;}
virtual const MagicField* getMagicField() const {return this;}
virtual bool isBlocking(const Creature* creature) const;
bool isReplaceable() const {return Item::items[getID()].replaceable;}
CombatType_t getCombatType() const
{
const ItemType& it = items[getID()];
return it.combatType;
}
void onStepInField(Creature* creature, bool purposeful = true);
private:
uint64_t createTime;
};
#endif