-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmonster.h
288 lines (238 loc) · 8.38 KB
/
monster.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
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2019 Mark Samman <mark.samman@gmail.com>
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef FS_MONSTER_H_9F5EEFE64314418CA7DA41D1B9409DD0
#define FS_MONSTER_H_9F5EEFE64314418CA7DA41D1B9409DD0
#include "tile.h"
#include "monsters.h"
class Creature;
class Game;
class Spawn;
using CreatureHashSet = std::unordered_set<Creature*>;
using CreatureList = std::list<Creature*>;
enum TargetSearchType_t {
TARGETSEARCH_DEFAULT,
TARGETSEARCH_RANDOM,
TARGETSEARCH_ATTACKRANGE,
TARGETSEARCH_NEAREST,
};
class Monster final : public Creature
{
public:
static Monster* createMonster(const std::string& name);
static int32_t despawnRange;
static int32_t despawnRadius;
explicit Monster(MonsterType* mType);
~Monster();
// non-copyable
Monster(const Monster&) = delete;
Monster& operator=(const Monster&) = delete;
Monster* getMonster() override {
return this;
}
const Monster* getMonster() const override {
return this;
}
void setID() override {
if (id == 0) {
id = monsterAutoID++;
}
}
void removeList() override;
void addList() override;
const std::string& getName() const override {
return mType->name;
}
const std::string& getNameDescription() const override {
return mType->nameDescription;
}
std::string getDescription(int32_t) const override {
const Monster* monster = this->getMonster();
if (monster && monster->getLevel() > 0) {
return strDescription + ", level " + std::to_string(level) + '.';
} else {
return strDescription + '.';
}
}
CreatureType_t getType() const override {
return CREATURETYPE_MONSTER;
}
const Position& getMasterPos() const {
return masterPos;
}
void setMasterPos(Position pos) {
masterPos = pos;
}
RaceType_t getRace() const override {
return mType->info.race;
}
int32_t getArmor() const override {
return mType->info.armor;
}
int32_t getDefense() const override {
return mType->info.defense;
}
bool isPushable() const override {
return mType->info.pushable && baseSpeed != 0;
}
bool isAttackable() const override {
return mType->info.isAttackable;
}
bool canPushItems() const;
bool canPushCreatures() const {
return mType->info.canPushCreatures;
}
bool isHostile() const {
return mType->info.isHostile;
}
bool isBlockable() const {
return mType->info.isBlockable;
}
bool canSee(const Position& pos) const override;
bool canSeeInvisibility() const override {
return isImmune(CONDITION_INVISIBLE);
}
uint32_t getManaCost() const {
return mType->info.manaCost;
}
void setSpawn(Spawn* spawn) {
this->spawn = spawn;
}
bool canWalkOnFieldType(CombatType_t combatType) const;
int32_t getLevel() const {
return level;
}
void onAttackedCreatureDisappear(bool isLogout) override;
void onCreatureAppear(Creature* creature, bool isLogin) override;
void onRemoveCreature(Creature* creature, bool isLogout) override;
void onCreatureMove(Creature* creature, const Tile* newTile, const Position& newPos, const Tile* oldTile, const Position& oldPos, bool teleport) override;
void onCreatureSay(Creature* creature, SpeakClasses type, const std::string& text) override;
void drainHealth(Creature* attacker, int32_t damage) override;
void changeHealth(int32_t healthChange, bool sendHealthChange = true) override;
void onWalk() override;
bool getNextStep(Direction& direction, uint32_t& flags) override;
void onFollowCreatureComplete(const Creature* creature) override;
void onThink(uint32_t interval) override;
bool challengeCreature(Creature* creature) override;
void setNormalCreatureLight() override;
bool getCombatValues(int32_t& min, int32_t& max) override;
void doAttacking(uint32_t interval) override;
bool hasExtraSwing() override {
return lastMeleeAttack == 0;
}
bool searchTarget(TargetSearchType_t searchType = TARGETSEARCH_DEFAULT);
bool selectTarget(Creature* creature);
const CreatureList& getTargetList() const {
return targetList;
}
const CreatureHashSet& getFriendList() const {
return friendList;
}
bool isTarget(const Creature* creature) const;
bool isFleeing() const {
return !isSummon() && getHealth() <= mType->info.runAwayHealth && targetExetaCooldown <= 0;
}
bool getDistanceStep(const Position& targetPos, Direction& direction, bool flee = false);
bool isTargetNearby() const {
return stepDuration >= 1;
}
bool isIgnoringFieldDamage() const {
return ignoreFieldDamage;
}
BlockType_t blockHit(Creature* attacker, CombatType_t combatType, int32_t& damage,
bool checkDefense = false, bool checkArmor = false, bool field = false, bool ignoreResistances = false) override;
static uint32_t monsterAutoID;
private:
CreatureHashSet friendList;
CreatureList targetList;
std::string strDescription;
MonsterType* mType;
Spawn* spawn = nullptr;
int64_t lastMeleeAttack = 0;
uint32_t attackTicks = 0;
uint32_t targetTicks = 0;
uint32_t targetChangeTicks = 0;
uint32_t defenseTicks = 0;
uint32_t yellTicks = 0;
int32_t minCombatValue = 0;
int32_t maxCombatValue = 0;
int32_t targetChangeCooldown = 0;
int32_t targetExetaCooldown = 0;
int32_t stepDuration = 0;
Position masterPos;
bool isIdle = true;
bool isMasterInRange = false;
bool randomStepping = false;
bool ignoreFieldDamage = false;
void onCreatureEnter(Creature* creature);
void onCreatureLeave(Creature* creature);
void onCreatureFound(Creature* creature, bool pushFront = false);
void updateLookDirection();
void addFriend(Creature* creature);
void removeFriend(Creature* creature);
void addTarget(Creature* creature, bool pushFront = false);
void removeTarget(Creature* creature);
void updateTargetList();
void clearTargetList();
void clearFriendList();
void death(Creature* lastHitCreature) override;
Item* getCorpse(Creature* lastHitCreature, Creature* mostDamageCreature) override;
void setIdle(bool idle);
void updateIdleStatus();
bool getIdleStatus() const {
return isIdle;
}
void onAddCondition(ConditionType_t type) override;
void onEndCondition(ConditionType_t type) override;
bool canUseAttack(const Position& pos, const Creature* target) const;
bool canUseSpell(const Position& pos, const Position& targetPos,
const spellBlock_t& sb, uint32_t interval, bool& inRange, bool& resetTicks);
bool getRandomStep(const Position& creaturePos, Direction& direction) const;
bool getDanceStep(const Position& creaturePos, Direction& direction,
bool keepAttack = true, bool keepDistance = true);
bool isInSpawnRange(const Position& pos) const;
bool canWalkTo(Position pos, Direction direction) const;
static bool pushItem(Item* item);
static void pushItems(Tile* tile);
static bool pushCreature(Creature* creature);
static void pushCreatures(Tile* tile);
void onThinkTarget(uint32_t interval);
void onThinkYell(uint32_t interval);
void onThinkDefense(uint32_t interval);
bool isFriend(const Creature* creature) const;
bool isOpponent(const Creature* creature) const;
uint64_t getLostExperience() const override {
return skillLoss ? mType->info.experience : 0;
}
uint16_t getLookCorpse() const override {
return mType->info.lookcorpse;
}
void dropLoot(Container* corpse, Creature* lastHitCreature) override;
uint32_t getDamageImmunities() const override {
return mType->info.damageImmunities;
}
uint32_t getConditionImmunities() const override {
return mType->info.conditionImmunities;
}
void getPathSearchParams(const Creature* creature, FindPathParams& fpp) const override;
bool useCacheMap() const override {
return !randomStepping;
}
friend class LuaScriptInterface;
};
#endif