-
Notifications
You must be signed in to change notification settings - Fork 21
/
condition.h
435 lines (347 loc) · 13.9 KB
/
condition.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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
//////////////////////////////////////////////////////////////////////
// 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 2
// 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, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#ifndef __OTSERV_CONDITION_H__
#define __OTSERV_CONDITION_H__
#include "fileloader.h"
#include "enums.h"
#include <list>
#include <vector>
class Creature;
class Player;
class PropStream;
enum ConditionType_t
{
CONDITION_NONE = 0,
CONDITION_POISON = 1,
CONDITION_FIRE = 2,
CONDITION_ENERGY = 4,
CONDITION_BLEEDING = 8,
CONDITION_HASTE = 16,
CONDITION_PARALYZE = 32,
CONDITION_OUTFIT = 64,
CONDITION_INVISIBLE = 128,
CONDITION_LIGHT = 256,
CONDITION_MANASHIELD = 512,
CONDITION_INFIGHT = 1024,
CONDITION_DRUNK = 2048,
CONDITION_EXHAUST_WEAPON = 4096,
CONDITION_REGENERATION = 8192,
CONDITION_SOUL = 16384,
CONDITION_DROWN = 32768,
CONDITION_MUTED = 65536,
CONDITION_ADVERTISINGTICKS = 131072,
CONDITION_YELLTICKS = 262144,
CONDITION_ATTRIBUTES = 524288,
CONDITION_FREEZING = 1048576,
CONDITION_DAZZLED = 2097152,
CONDITION_CURSED = 4194304,
CONDITION_EXHAUST_COMBAT = 8388608,
CONDITION_EXHAUST_HEAL = 16777216,
CONDITION_PACIFIED = 33554432,
CONDITION_SPELLCOOLDOWN = 67108864,
CONDITION_SPELLGROUPCOOLDOWN = 134217728
};
enum ConditionEnd_t
{
CONDITIONEND_CLEANUP,
CONDITIONEND_DEATH,
CONDITIONEND_TICKS,
CONDITIONEND_ABORT
};
enum ConditionAttr_t
{
CONDITIONATTR_TYPE = 1,
CONDITIONATTR_ID = 2,
CONDITIONATTR_TICKS = 3,
CONDITIONATTR_HEALTHTICKS = 4,
CONDITIONATTR_HEALTHGAIN = 5,
CONDITIONATTR_MANATICKS = 6,
CONDITIONATTR_MANAGAIN = 7,
CONDITIONATTR_DELAYED = 8,
CONDITIONATTR_OWNER = 9,
CONDITIONATTR_INTERVALDATA = 10,
CONDITIONATTR_SPEEDDELTA = 11,
CONDITIONATTR_FORMULA_MINA = 12,
CONDITIONATTR_FORMULA_MINB = 13,
CONDITIONATTR_FORMULA_MAXA = 14,
CONDITIONATTR_FORMULA_MAXB = 15,
CONDITIONATTR_LIGHTCOLOR = 16,
CONDITIONATTR_LIGHTLEVEL = 17,
CONDITIONATTR_LIGHTTICKS = 18,
CONDITIONATTR_LIGHTINTERVAL = 19,
CONDITIONATTR_SOULTICKS = 20,
CONDITIONATTR_SOULGAIN = 21,
CONDITIONATTR_SKILLS = 22,
CONDITIONATTR_STATS = 23,
CONDITIONATTR_OUTFIT = 24,
CONDITIONATTR_PERIODDAMAGE = 25,
CONDITIONATTR_ISBUFF = 26,
CONDITIONATTR_SUBID = 27,
//reserved for serialization
CONDITIONATTR_END = 254
};
struct IntervalInfo
{
int32_t timeLeft;
int32_t value;
int32_t interval;
};
class Condition
{
public:
Condition(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff = false, uint32_t _subId = 0);
virtual ~Condition(){}
virtual bool startCondition(Creature* creature);
virtual bool executeCondition(Creature* creature, int32_t interval);
virtual void endCondition(Creature* creature, ConditionEnd_t reason) = 0;
virtual void addCondition(Creature* creature, const Condition* condition) = 0;
virtual uint32_t getIcons() const;
ConditionId_t getId() const {return id;}
uint32_t getSubId() const {return subId;}
virtual Condition* clone() const = 0;
ConditionType_t getType() const {return conditionType;}
int64_t getEndTime() const {return endTime;}
int32_t getTicks() const {return ticks;}
void setTicks(int32_t newTicks);
static Condition* createCondition(ConditionId_t _id, ConditionType_t _type, int32_t ticks, int32_t param = 0, bool _buff = false, uint32_t _subId = 0);
static Condition* createCondition(PropStream& propStream);
virtual bool setParam(ConditionParam_t param, int32_t value);
//serialization
bool unserialize(PropStream& propStream);
virtual bool serialize(PropWriteStream& propWriteStream);
virtual bool unserializeProp(ConditionAttr_t attr, PropStream& propStream);
bool isPersistent() const;
protected:
ConditionId_t id;
uint32_t subId;
int32_t ticks;
int64_t endTime;
ConditionType_t conditionType;
bool isBuff;
virtual bool updateCondition(const Condition* addCondition);
};
class ConditionGeneric: public Condition
{
public:
ConditionGeneric(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff = false, uint32_t _subId = 0);
virtual ~ConditionGeneric(){}
virtual bool startCondition(Creature* creature);
virtual bool executeCondition(Creature* creature, int32_t interval);
virtual void endCondition(Creature* creature, ConditionEnd_t reason);
virtual void addCondition(Creature* creature, const Condition* condition);
virtual uint32_t getIcons() const;
virtual ConditionGeneric* clone() const { return new ConditionGeneric(*this); }
};
class ConditionManaShield : public ConditionGeneric
{
public:
ConditionManaShield(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff = false, uint32_t _subId = 0) : ConditionGeneric(_id, _type, _ticks, _buff, _subId) {}
virtual ~ConditionManaShield() {}
virtual ConditionManaShield* clone() const { return new ConditionManaShield(*this); }
};
class ConditionAttributes : public ConditionGeneric
{
public:
ConditionAttributes(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff = false, uint32_t _subId = 0);
virtual ~ConditionAttributes(){}
virtual bool startCondition(Creature* creature);
virtual bool executeCondition(Creature* creature, int32_t interval);
virtual void endCondition(Creature* creature, ConditionEnd_t reason);
virtual void addCondition(Creature* creature, const Condition* condition);
virtual bool setParam(ConditionParam_t param, int32_t value);
virtual ConditionAttributes* clone() const { return new ConditionAttributes(*this); }
//serialization
virtual bool serialize(PropWriteStream& propWriteStream);
virtual bool unserializeProp(ConditionAttr_t attr, PropStream& propStream);
protected:
int32_t skills[SKILL_LAST + 1];
int32_t skillsPercent[SKILL_LAST + 1];
int32_t stats[STAT_LAST + 1];
int32_t statsPercent[STAT_LAST + 1];
int32_t currentSkill;
int32_t currentStat;
void updatePercentStats(Player* player);
void updateStats(Player* player);
void updatePercentSkills(Player* player);
void updateSkills(Player* player);
};
class ConditionRegeneration : public ConditionGeneric
{
public:
ConditionRegeneration(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff = false, uint32_t _subId = 0);
virtual ~ConditionRegeneration(){}
virtual void addCondition(Creature* creature, const Condition* addCondition);
virtual bool executeCondition(Creature* creature, int32_t interval);
virtual bool setParam(ConditionParam_t param, int32_t value);
virtual ConditionRegeneration* clone() const { return new ConditionRegeneration(*this); }
//serialization
virtual bool serialize(PropWriteStream& propWriteStream);
virtual bool unserializeProp(ConditionAttr_t attr, PropStream& propStream);
protected:
uint32_t internalHealthTicks;
uint32_t internalManaTicks;
uint32_t healthTicks;
uint32_t manaTicks;
uint32_t healthGain;
uint32_t manaGain;
};
class ConditionSoul : public ConditionGeneric
{
public:
ConditionSoul(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff = false, uint32_t _subId = 0);
virtual ~ConditionSoul(){}
virtual void addCondition(Creature* creature, const Condition* addCondition);
virtual bool executeCondition(Creature* creature, int32_t interval);
virtual bool setParam(ConditionParam_t param, int32_t value);
virtual ConditionSoul* clone() const { return new ConditionSoul(*this); }
//serialization
virtual bool serialize(PropWriteStream& propWriteStream);
virtual bool unserializeProp(ConditionAttr_t attr, PropStream& propStream);
protected:
uint32_t internalSoulTicks;
uint32_t soulTicks;
uint32_t soulGain;
};
class ConditionInvisible: public ConditionGeneric
{
public:
ConditionInvisible(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff = false, uint32_t _subId = 0);
virtual ~ConditionInvisible(){}
virtual bool startCondition(Creature* creature);
virtual void endCondition(Creature* creature, ConditionEnd_t reason);
virtual ConditionInvisible* clone() const { return new ConditionInvisible(*this); }
};
class ConditionDamage: public Condition
{
public:
ConditionDamage(ConditionId_t _id, ConditionType_t _type, bool _buff = false, uint32_t _subId = 0);
virtual ~ConditionDamage(){}
static void generateDamageList(int32_t amount, int32_t start, std::list<int32_t>& list);
virtual bool startCondition(Creature* creature);
virtual bool executeCondition(Creature* creature, int32_t interval);
virtual void endCondition(Creature* creature, ConditionEnd_t reason);
virtual void addCondition(Creature* creature, const Condition* condition);
virtual uint32_t getIcons() const;
virtual ConditionDamage* clone() const { return new ConditionDamage(*this); }
virtual bool setParam(ConditionParam_t param, int32_t value);
bool addDamage(int32_t rounds, int32_t time, int32_t value);
bool doForceUpdate() const {return forceUpdate;}
int32_t getTotalDamage() const;
//serialization
virtual bool serialize(PropWriteStream& propWriteStream);
virtual bool unserializeProp(ConditionAttr_t attr, PropStream& propStream);
protected:
int32_t maxDamage;
int32_t minDamage;
int32_t startDamage;
int32_t periodDamage;
int32_t periodDamageTick;
int32_t tickInterval;
bool forceUpdate;
bool delayed;
uint32_t owner;
bool init();
typedef std::list<IntervalInfo> DamageList;
DamageList damageList;
bool getNextDamage(int32_t& damage);
bool doDamage(Creature* creature, int32_t damage);
bool updateCondition(const ConditionDamage* addCondition);
};
class ConditionSpeed: public Condition
{
public:
ConditionSpeed(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff, uint32_t _subId, int32_t changeSpeed);
virtual ~ConditionSpeed(){}
virtual bool startCondition(Creature* creature);
virtual bool executeCondition(Creature* creature, int32_t interval);
virtual void endCondition(Creature* creature, ConditionEnd_t reason);
virtual void addCondition(Creature* creature, const Condition* condition);
virtual uint32_t getIcons() const;
virtual ConditionSpeed* clone() const { return new ConditionSpeed(*this); }
virtual bool setParam(ConditionParam_t param, int32_t value);
void setFormulaVars(float _mina, float _minb, float _maxa, float _maxb);
//serialization
virtual bool serialize(PropWriteStream& propWriteStream);
virtual bool unserializeProp(ConditionAttr_t attr, PropStream& propStream);
protected:
void getFormulaValues(int32_t var, int32_t& min, int32_t& max) const;
int32_t speedDelta;
//formula variables
float mina;
float minb;
float maxa;
float maxb;
};
class ConditionOutfit: public Condition
{
public:
ConditionOutfit(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff = false, uint32_t _subId = 0);
virtual ~ConditionOutfit(){}
virtual bool startCondition(Creature* creature);
virtual bool executeCondition(Creature* creature, int32_t interval);
virtual void endCondition(Creature* creature, ConditionEnd_t reason);
virtual void addCondition(Creature* creature, const Condition* condition);
virtual ConditionOutfit* clone() const { return new ConditionOutfit(*this); }
void addOutfit(Outfit_t outfit);
//serialization
virtual bool serialize(PropWriteStream& propWriteStream);
virtual bool unserializeProp(ConditionAttr_t attr, PropStream& propStream);
protected:
std::vector<Outfit_t> outfits;
void changeOutfit(Creature* creature, int32_t index = -1);
};
class ConditionLight: public Condition
{
public:
ConditionLight(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff, uint32_t _subId, int32_t _lightlevel, int32_t _lightcolor);
virtual ~ConditionLight(){}
virtual bool startCondition(Creature* creature);
virtual bool executeCondition(Creature* creature, int32_t interval);
virtual void endCondition(Creature* creature, ConditionEnd_t reason);
virtual void addCondition(Creature* creature, const Condition* addCondition);
virtual ConditionLight* clone() const { return new ConditionLight(*this); }
virtual bool setParam(ConditionParam_t param, int32_t value);
//serialization
virtual bool serialize(PropWriteStream& propWriteStream);
virtual bool unserializeProp(ConditionAttr_t attr, PropStream& propStream);
protected:
LightInfo lightInfo;
uint32_t internalLightTicks;
uint32_t lightChangeInterval;
};
class ConditionSpellCooldown: public ConditionGeneric
{
public:
ConditionSpellCooldown(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff = false, uint32_t _subId = 0);
virtual ~ConditionSpellCooldown(){}
virtual bool startCondition(Creature* creature);
virtual void addCondition(Creature* creature, const Condition* condition);
virtual ConditionSpellCooldown* clone() const { return new ConditionSpellCooldown(*this); }
};
class ConditionSpellGroupCooldown: public ConditionGeneric
{
public:
ConditionSpellGroupCooldown(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff = false, uint32_t _subId = 0);
virtual ~ConditionSpellGroupCooldown(){}
virtual bool startCondition(Creature* creature);
virtual void addCondition(Creature* creature, const Condition* condition);
virtual ConditionSpellGroupCooldown* clone() const { return new ConditionSpellGroupCooldown(*this); }
};
#endif