TrinityCore
Creature.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITYCORE_CREATURE_H
19#define TRINITYCORE_CREATURE_H
20
21#include "Unit.h"
22#include "Common.h"
23#include "CreatureData.h"
24#include "DatabaseEnvFwd.h"
25#include "Duration.h"
26#include "GridObject.h"
27#include "MapObject.h"
28#include <list>
29
30class CreatureAI;
31class CreatureGroup;
32class Quest;
33class Player;
34class SpellInfo;
35class WorldSession;
36struct Loot;
37
39
41{
42 VendorItemCount(uint32 _item, uint32 _count);
43
47};
48
49typedef std::list<VendorItemCount> VendorItemCounts;
50
51// max different by z coordinate for creature aggro reaction
52#define CREATURE_Z_ATTACK_RANGE 3
53
54#define MAX_VENDOR_ITEMS 150 // Limitation in 4.x.x item count in SMSG_LIST_INVENTORY
55
57{
58 None = 0,
59 Empty = 1
60};
61
63static constexpr size_t CREATURE_TAPPERS_SOFT_CAP = 5;
64
65//used for handling non-repeatable random texts
66typedef std::vector<uint8> CreatureTextRepeatIds;
67typedef std::unordered_map<uint8, CreatureTextRepeatIds> CreatureTextRepeatGroup;
68
69class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public MapObject
70{
71 public:
72 explicit Creature(bool isWorldObject = false);
74
75 void AddToWorld() override;
76 void RemoveFromWorld() override;
77
78 float GetNativeObjectScale() const override;
79 void SetObjectScale(float scale) override;
80 void SetDisplayId(uint32 displayId, bool setNative = false) override;
81 void SetDisplayFromModel(uint32 modelIdx);
82
83 void DisappearAndDie() { ForcedDespawn(0); }
84
85 bool Create(ObjectGuid::LowType guidlow, Map* map, uint32 entry, Position const& pos, CreatureData const* data, uint32 vehId, bool dynamic = false);
86
87 static Creature* CreateCreature(uint32 entry, Map* map, Position const& pos, uint32 vehId = 0);
88 static Creature* CreateCreatureFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap = true, bool allowDuplicate = false);
89
90 bool LoadCreaturesAddon();
91 void LoadCreaturesSparringHealth();
92 void SelectLevel();
93 void UpdateLevelDependantStats();
94 void SelectWildBattlePetLevel();
95 void LoadEquipment(int8 id = 1, bool force = false);
96 void SetSpawnHealth();
97 void LoadTemplateRoot();
98 bool IsTemplateRooted() const { return _staticFlags.HasFlag(CREATURE_STATIC_FLAG_SESSILE); }
99 void SetTemplateRooted(bool rooted);
100
101 ObjectGuid::LowType GetSpawnId() const { return m_spawnId; }
102
103 void Update(uint32 time) override; // overwrited Unit::Update
104 void GetRespawnPosition(float &x, float &y, float &z, float* ori = nullptr, float* dist = nullptr) const;
105 bool IsSpawnedOnTransport() const { return m_creatureData && m_creatureData->mapId != GetMapId(); }
106
107 void SetCorpseDelay(uint32 delay, bool ignoreCorpseDecayRatio = false)
108 {
109 m_corpseDelay = delay;
110 if (ignoreCorpseDecayRatio)
111 m_ignoreCorpseDecayRatio = true;
112 }
113 uint32 GetCorpseDelay() const { return m_corpseDelay; }
114 bool IsRacialLeader() const { return GetCreatureTemplate()->RacialLeader; }
115 bool IsCivilian() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_CIVILIAN) != 0; }
116 bool IsTrigger() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER) != 0; }
117 bool IsGuard() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_GUARD) != 0; }
118
119 void InitializeMovementFlags();
120 void UpdateMovementFlags();
121
122 CreatureMovementData const& GetMovementTemplate() const;
123 bool CanWalk() const { return GetMovementTemplate().IsGroundAllowed(); }
124 bool CanSwim() const override;
125 bool CanEnterWater() const override;
126 bool CanFly() const override { return GetMovementTemplate().IsFlightAllowed() || IsFlying(); }
127 bool CanHover() const { return GetMovementTemplate().Ground == CreatureGroundMovementType::Hover || IsHovering(); }
128
129 MovementGeneratorType GetDefaultMovementType() const override { return m_defaultMovementType; }
130 void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; }
131
132 CreatureClassifications GetCreatureClassification() const { return GetCreatureTemplate()->Classification; }
133 bool HasClassification(CreatureClassifications classification) const { return GetCreatureTemplate()->Classification == classification; }
134
135 bool IsDungeonBoss() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_DUNGEON_BOSS) != 0; }
136 bool IsAffectedByDiminishingReturns() const override { return Unit::IsAffectedByDiminishingReturns() || (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_ALL_DIMINISH) != 0; }
137
138 Unit* SelectVictim();
139
140 void SetReactState(ReactStates st) { m_reactState = st; }
141 ReactStates GetReactState() const { return m_reactState; }
142 bool HasReactState(ReactStates state) const { return (m_reactState == state); }
143 void InitializeReactState();
144
147 void SetImmuneToAll(bool apply) override { Unit::SetImmuneToAll(apply, HasReactState(REACT_PASSIVE)); }
148 using Unit::IsImmuneToPC;
150 void SetImmuneToPC(bool apply) override { Unit::SetImmuneToPC(apply, HasReactState(REACT_PASSIVE)); }
153 void SetImmuneToNPC(bool apply) override { Unit::SetImmuneToNPC(apply, HasReactState(REACT_PASSIVE)); }
154
155 void SetUnkillable(bool unkillable) { _staticFlags.ApplyFlag(CREATURE_STATIC_FLAG_UNKILLABLE, unkillable); }
156
158 bool isCanInteractWithBattleMaster(Player* player, bool msg) const;
159 bool CanResetTalents(Player* player) const;
160 bool CanCreatureAttack(Unit const* victim, bool force = true) const;
161 void LoadTemplateImmunities(int32 creatureImmunitiesId);
162 bool IsImmunedToSpellEffect(SpellInfo const* spellInfo, SpellEffectInfo const& spellEffectInfo, WorldObject const* caster, bool requireImmunityPurgesEffectAttribute = false) const override;
163 bool IsElite() const;
164 bool isWorldBoss() const;
165
166 bool HasScalableLevels() const;
167 void ApplyLevelScaling();
168 uint8 GetLevelForTarget(WorldObject const* target) const override;
169
170 uint64 GetMaxHealthByLevel(uint8 level) const;
171 float GetHealthMultiplierForTarget(WorldObject const* target) const override;
172
173 float GetBaseDamageForLevel(uint8 level) const;
174 float GetDamageMultiplierForTarget(WorldObject const* target) const override;
175
176 float GetBaseArmorForLevel(uint8 level) const;
177 float GetArmorMultiplierForTarget(WorldObject const* target) const override;
178
180 bool IsEvadingAttacks() const { return IsInEvadeMode() || CanNotReachTarget(); }
181
182 bool AIM_Destroy();
183 bool AIM_Create(CreatureAI* ai = nullptr);
184 bool AIM_Initialize(CreatureAI* ai = nullptr);
185 void Motion_Initialize();
186
187 CreatureAI* AI() const { return reinterpret_cast<CreatureAI*>(GetAI()); }
188
189 SpellSchoolMask GetMeleeDamageSchoolMask(WeaponAttackType /*attackType*/ = BASE_ATTACK) const override { return m_meleeDamageSchoolMask; }
190 void SetMeleeDamageSchool(SpellSchools school) { m_meleeDamageSchoolMask = SpellSchoolMask(1 << school); }
191 bool CanMelee() const { return !_staticFlags.HasFlag(CREATURE_STATIC_FLAG_NO_MELEE); }
192 void SetCanMelee(bool canMelee) { _staticFlags.ApplyFlag(CREATURE_STATIC_FLAG_NO_MELEE, !canMelee); }
194
195 bool HasSpell(uint32 spellID) const override;
196
197 bool UpdateEntry(uint32 entry, CreatureData const* data = nullptr, bool updateLevel = true);
198
199 int32 GetCreatePowerValue(Powers power) const override;
200 bool UpdateStats(Stats stat) override;
201 bool UpdateAllStats() override;
202 void UpdateArmor() override;
203 void UpdateMaxHealth() override;
204 void UpdateMaxPower(Powers power) override;
205 uint32 GetPowerIndex(Powers power) const override;
206 void UpdateAttackPowerAndDamage(bool ranged = false) override;
207 void CalculateMinMaxDamage(WeaponAttackType attType, bool normalized, bool addTotalPct, float& minDamage, float& maxDamage) const override;
208
209 void SetCanDualWield(bool value) override;
210 int8 GetOriginalEquipmentId() const { return m_originalEquipmentId; }
211 uint8 GetCurrentEquipmentId() const { return m_equipmentId; }
212 void SetCurrentEquipmentId(uint8 id) { m_equipmentId = id; }
213
214 float GetSpellDamageMod(CreatureClassifications classification) const;
215
216 VendorItemData const* GetVendorItems() const;
217 uint32 GetVendorItemCurrentCount(VendorItem const* vItem);
218 uint32 UpdateVendorItemCurrentCount(VendorItem const* vItem, uint32 used_count);
219
220 CreatureTemplate const* GetCreatureTemplate() const { return m_creatureInfo; }
221 CreatureData const* GetCreatureData() const { return m_creatureData; }
222 CreatureDifficulty const* GetCreatureDifficulty() const { return m_creatureDifficulty; }
223 CreatureAddon const* GetCreatureAddon() const;
224
225 std::string const& GetAIName() const;
226 std::string GetScriptName() const;
227 uint32 GetScriptId() const;
228 bool HasStringId(std::string_view id) const;
229 void SetScriptStringId(std::string id);
230 std::array<std::string_view, 3> const& GetStringIds() const { return m_stringIds; }
231
232 // override WorldObject function for proper name localization
233 std::string GetNameForLocaleIdx(LocaleConstant locale) const override;
234
235 void setDeathState(DeathState s) override; // override virtual Unit::setDeathState
236
237 bool LoadFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap, bool allowDuplicate);
238 void SaveToDB();
239 // overriden in Pet
240 virtual void SaveToDB(uint32 mapid, std::vector<Difficulty> const& spawnDifficulties);
241 static bool DeleteFromDB(ObjectGuid::LowType spawnId);
242
243 bool CanHaveLoot() const { return !_staticFlags.HasFlag(CREATURE_STATIC_FLAG_NO_LOOT); }
244 void SetCanHaveLoot(bool canHaveLoot) { _staticFlags.ApplyFlag(CREATURE_STATIC_FLAG_NO_LOOT, !canHaveLoot); }
245 uint32 GetLootId() const;
246 void SetLootId(Optional<uint32> lootId);
247 std::unique_ptr<Loot> m_loot;
248 std::unordered_map<ObjectGuid, std::unique_ptr<Loot>> m_personalLoot;
249 void StartPickPocketRefillTimer();
250 void ResetPickPocketRefillTimer() { _pickpocketLootRestore = 0; }
251 bool CanGeneratePickPocketLoot() const;
252 GuidUnorderedSet const& GetTapList() const { return m_tapList; }
253 void SetTapList(GuidUnorderedSet tapList) { m_tapList = std::move(tapList); }
254 bool hasLootRecipient() const { return !m_tapList.empty(); }
255 bool IsTapListNotClearedOnEvade() const { return m_dontClearTapListOnEvade; }
256 void SetDontClearTapListOnEvade(bool dontClear);
257 bool isTappedBy(Player const* player) const; // return true if the creature is tapped by the player or a member of his party.
258 Loot* GetLootForPlayer(Player const* player) const override;
259 bool IsFullyLooted() const;
260 bool IsSkinnedBy(Player const* player) const;
261
262 void SetTappedBy(Unit const* unit, bool withGroup = true);
263 void AllLootRemovedFromCorpse();
264
265 uint16 GetLootMode() const { return m_LootMode; }
266 bool HasLootMode(uint16 lootMode) const { return (m_LootMode & lootMode) != 0; }
267 void SetLootMode(uint16 lootMode) { m_LootMode = lootMode; }
268 void AddLootMode(uint16 lootMode) { m_LootMode |= lootMode; }
269 void RemoveLootMode(uint16 lootMode) { m_LootMode &= ~lootMode; }
270 void ResetLootMode() { m_LootMode = LOOT_MODE_DEFAULT; }
271
273
274 bool CanStartAttack(Unit const* u, bool force) const;
275 float GetAttackDistance(Unit const* player) const;
276 float GetAggroRange(Unit const* target) const;
277
278 void SendAIReaction(AiReaction reactionType);
279
280 Unit* SelectNearestTarget(float dist = 0, bool playerOnly = false) const;
281 Unit* SelectNearestTargetInAttackDistance(float dist = 0) const;
282 Unit* SelectNearestHostileUnitInAggroRange(bool useLOS = false, bool ignoreCivilians = false) const;
283
284 void DoFleeToGetAssistance();
285 void CallForHelp(float fRadius);
286 void CallAssistance();
287 void SetNoCallAssistance(bool val) { m_AlreadyCallAssistance = val; }
288 void SetNoSearchAssistance(bool val) { m_AlreadySearchedAssistance = val; }
289 bool HasSearchedAssistance() const { return m_AlreadySearchedAssistance; }
290 bool CanAssistTo(Unit const* u, Unit const* enemy, bool checkfaction = true) const;
291 bool _IsTargetAcceptable(Unit const* target) const;
292 bool CanIgnoreFeignDeath() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_IGNORE_FEIGN_DEATH) != 0; }
293
294 void RemoveCorpse(bool setSpawnTime = true, bool destroyForNearbyPlayers = true);
295
296 void DespawnOrUnsummon(Milliseconds timeToDespawn = 0s, Seconds forceRespawnTime = 0s);
297
298 time_t const& GetRespawnTime() const { return m_respawnTime; }
299 time_t GetRespawnTimeEx() const;
300 void SetRespawnTime(uint32 respawn);
301 void Respawn(bool force = false);
302 void SaveRespawnTime(uint32 forceDelay = 0);
303
304 uint32 GetRespawnDelay() const { return m_respawnDelay; }
305 void SetRespawnDelay(uint32 delay) { m_respawnDelay = delay; }
306
307 float GetWanderDistance() const { return m_wanderDistance; }
308 void SetWanderDistance(float dist) { m_wanderDistance = dist; }
309
310 void DoImmediateBoundaryCheck() { m_boundaryCheckTime = 0; }
311 uint32 GetCombatPulseDelay() const { return m_combatPulseDelay; }
312 void SetCombatPulseDelay(uint32 delay) // (secs) interval at which the creature pulses the entire zone into combat (only works in dungeons)
313 {
314 m_combatPulseDelay = delay;
315 if (m_combatPulseTime == 0 || m_combatPulseTime > delay)
316 m_combatPulseTime = delay;
317 }
318
319 void SendZoneUnderAttackMessage(Player* attacker);
320
321 bool hasQuest(uint32 quest_id) const override;
322 bool hasInvolvedQuest(uint32 quest_id) const override;
323
324 bool CanRegenerateHealth() const { return !_staticFlags.HasFlag(CREATURE_STATIC_FLAG_5_NO_HEALTH_REGEN) && _regenerateHealth; }
325 void SetRegenerateHealth(bool value) { _staticFlags.ApplyFlag(CREATURE_STATIC_FLAG_5_NO_HEALTH_REGEN, !value); }
326 virtual uint8 GetPetAutoSpellSize() const;
327 virtual uint32 GetPetAutoSpellOnPos(uint8 pos) const;
328 float GetPetChaseDistance() const;
329
330 void SetCannotReachTarget(bool cannotReach);
331 bool CanNotReachTarget() const { return m_cannotReachTarget; }
332
333 void SetHomePosition(float x, float y, float z, float o) { m_homePosition.Relocate(x, y, z, o); }
334 void SetHomePosition(Position const& pos) { m_homePosition.Relocate(pos); }
335 void GetHomePosition(float& x, float& y, float& z, float& ori) const { m_homePosition.GetPosition(x, y, z, ori); }
336 Position const& GetHomePosition() const { return m_homePosition; }
337
338 void SetTransportHomePosition(float x, float y, float z, float o) { m_transportHomePosition.Relocate(x, y, z, o); }
339 void SetTransportHomePosition(Position const& pos) { m_transportHomePosition.Relocate(pos); }
340 void GetTransportHomePosition(float& x, float& y, float& z, float& ori) const { m_transportHomePosition.GetPosition(x, y, z, ori); }
341 Position const& GetTransportHomePosition() const { return m_transportHomePosition; }
342
343 uint32 GetWaypointPathId() const { return _waypointPathId; }
344 void LoadPath(uint32 pathid) { _waypointPathId = pathid; }
345
346 // nodeId, pathId
347 std::pair<uint32, uint32> GetCurrentWaypointInfo() const { return _currentWaypointNodeInfo; }
348 void UpdateCurrentWaypointInfo(uint32 nodeId, uint32 pathId) { _currentWaypointNodeInfo = { nodeId, pathId }; }
349
350 bool IsReturningHome() const;
351
352 void SearchFormation();
353 CreatureGroup* GetFormation() { return m_formation; }
354 void SetFormation(CreatureGroup* formation) { m_formation = formation; }
355 bool IsFormationLeader() const;
356 void SignalFormationMovement();
357 bool IsFormationLeaderMoveAllowed() const;
358
359 void SetDisableReputationGain(bool disable) { DisableReputationGain = disable; }
360 bool IsReputationGainDisabled() const { return DisableReputationGain; }
361 void LowerPlayerDamageReq(uint64 unDamage);
362 void ResetPlayerDamageReq() { m_PlayerDamageReq = GetHealth() / 2; }
364
365 uint32 GetOriginalEntry() const { return m_originalEntry; }
366 void SetOriginalEntry(uint32 entry) { m_originalEntry = entry; }
367
368 // There's many places not ready for dynamic spawns. This allows them to live on for now.
369 void SetRespawnCompatibilityMode(bool mode = true) { m_respawnCompatibilityMode = mode; }
370 bool GetRespawnCompatibilityMode() const { return m_respawnCompatibilityMode; }
371
372 static float GetDamageMod(CreatureClassifications classification);
373
374 float m_SightDistance, m_CombatDistance;
375
376 bool m_isTempWorldObject; //true when possessed
377
378 // Handling caster facing during spellcast
379 void SetTarget(ObjectGuid const& guid) override;
380 void DoNotReacquireSpellFocusTarget();
381 void SetSpellFocus(Spell const* focusSpell, WorldObject const* target);
382 bool HasSpellFocus(Spell const* focusSpell = nullptr) const override;
383 void ReleaseSpellFocus(Spell const* focusSpell = nullptr, bool withDelay = true);
384
385 bool IsMovementPreventedByCasting() const override;
386
387 // Part of Evade mechanics
388 time_t GetLastDamagedTime() const { return _lastDamagedTime; }
389 void SetLastDamagedTime(time_t val) { _lastDamagedTime = val; }
390
391 CreatureTextRepeatIds GetTextRepeatGroup(uint8 textGroup);
392 void SetTextRepeatId(uint8 textGroup, uint8 id);
393 void ClearTextRepeatGroup(uint8 textGroup);
394 bool IsEscorted() const;
395
396 bool CanGiveExperience() const;
397 void SetCanGiveExperience(bool xpEnabled) { _staticFlags.ApplyFlag(CREATURE_STATIC_FLAG_NO_XP, !xpEnabled); }
398
399 bool IsEngaged() const override;
400 void AtEngage(Unit* target) override;
401 void AtDisengage() override;
402
403 bool IsThreatFeedbackDisabled() const { return _staticFlags.HasFlag(CREATURE_STATIC_FLAG_3_NO_THREAT_FEEDBACK); }
404 void SetNoThreatFeedback(bool noThreatFeedback) { _staticFlags.ApplyFlag(CREATURE_STATIC_FLAG_3_NO_THREAT_FEEDBACK, noThreatFeedback); }
405
406 void OverrideSparringHealthPct(std::vector<float> const& healthPct);
407 float GetSparringHealthPct() const { return _sparringHealthPct; }
408 uint32 CalculateDamageForSparring(Unit* attacker, uint32 damage);
409 bool ShouldFakeDamageFrom(Unit* attacker);
410
412 {
413 return !_isMissingCanSwimFlagOutOfCombat;
414 }
415 void RefreshCanSwimFlag(bool recheck = false);
416
417 std::string GetDebugInfo() const override;
418
419 void ExitVehicle(Position const* exitPosition = nullptr) override;
420
421 bool HasFlag(CreatureStaticFlags flag) const { return _staticFlags.HasFlag(flag); }
422 bool HasFlag(CreatureStaticFlags2 flag) const { return _staticFlags.HasFlag(flag); }
423 bool HasFlag(CreatureStaticFlags3 flag) const { return _staticFlags.HasFlag(flag); }
424 bool HasFlag(CreatureStaticFlags4 flag) const { return _staticFlags.HasFlag(flag); }
425 bool HasFlag(CreatureStaticFlags5 flag) const { return _staticFlags.HasFlag(flag); }
426 bool HasFlag(CreatureStaticFlags6 flag) const { return _staticFlags.HasFlag(flag); }
427 bool HasFlag(CreatureStaticFlags7 flag) const { return _staticFlags.HasFlag(flag); }
428 bool HasFlag(CreatureStaticFlags8 flag) const { return _staticFlags.HasFlag(flag); }
429
430 uint32 GetGossipMenuId() const;
431 void SetGossipMenuId(uint32 gossipMenuId);
432
433 uint32 GetTrainerId() const;
434 void SetTrainerId(Optional<uint32> trainerId);
435
436 void SummonGraveyardTeleporter();
437
438 void InitializeInteractSpellId();
439 void SetInteractSpellId(int32 interactSpellId) { SetUpdateFieldValue(m_values.ModifyValue(&Unit::m_unitData).ModifyValue(&UF::UnitData::InteractSpellID), interactSpellId); }
440
441 protected:
442 bool CreateFromProto(ObjectGuid::LowType guidlow, uint32 entry, CreatureData const* data = nullptr, uint32 vehId = 0);
443 bool InitEntry(uint32 entry, CreatureData const* data = nullptr);
444
445 // vendor items
447
448 static float GetHealthMod(CreatureClassifications classification);
449
452
455 time_t m_corpseRemoveTime; // (msecs)timer for death or corpse disappearance
456 time_t m_respawnTime; // (secs) time of next respawn
457 uint32 m_respawnDelay; // (secs) delay between corpse disappearance and respawning
458 uint32 m_corpseDelay; // (secs) delay between death and corpse disappearance
461 uint32 m_boundaryCheckTime; // (msecs) remaining time for next evade boundary check
462 uint32 m_combatPulseTime; // (msecs) remaining time for next zone-in-combat pulse
463 uint32 m_combatPulseDelay; // (secs) how often the creature puts the entire zone in combat (only works in dungeons)
464
465 ReactStates m_reactState; // for AI, not charmInfo
466 void RegenerateHealth();
467 void Regenerate(Powers power);
472
477
480
483
485
489 std::array<std::string_view, 3> m_stringIds;
491
493 uint16 m_LootMode; // Bitmask (default: LOOT_MODE_DEFAULT) that determines what loot will be lootable
494
495 bool IsInvisibleDueToDespawn(WorldObject const* seer) const override;
496 bool CanAlwaysSee(WorldObject const* obj) const override;
497
498 private:
499 void ForcedDespawn(uint32 timeMSToDespawn = 0, Seconds forceRespawnTimer = 0s);
500 bool CheckNoGrayAggroConfig(uint32 playerLevel, uint32 creatureLevel) const; // No aggro from gray creatures
501
502 // Waypoint path
504 std::pair<uint32/*nodeId*/, uint32/*pathId*/> _currentWaypointNodeInfo;
505
506 // Formation var
510
511 /* Spell focus system */
512 void ReacquireSpellFocusTarget();
513 struct
514 {
515 ::Spell const* Spell = nullptr;
516 uint32 Delay = 0; // ms until the creature's target should snap back (0 = no snapback scheduled)
517 ObjectGuid Target; // the creature's "real" target while casting
518 float Orientation = 0.0f; // the creature's "real" orientation while casting
519 } _spellFocusInfo;
520
521 time_t _lastDamagedTime; // Part of Evade mechanics
523
524 void ApplyAllStaticFlags(CreatureStaticFlagsHolder const& flags);
525
527
528 // Regenerate health
529 bool _regenerateHealth; // Set on creation
530
532
537};
538
540{
541 public:
542 AssistDelayEvent(ObjectGuid victim, Unit& owner) : BasicEvent(), m_victim(victim), m_owner(owner) { }
543
544 bool Execute(uint64 e_time, uint32 p_time) override;
545 void AddAssistant(ObjectGuid guid) { m_assistants.push_back(guid); }
546 private:
548
552};
553
555{
556 public:
557 ForcedDespawnDelayEvent(Creature& owner, Seconds respawnTimer) : BasicEvent(), m_owner(owner), m_respawnTimer(respawnTimer) { }
558 bool Execute(uint64 e_time, uint32 p_time) override;
559
560 private:
563};
564
565#endif
LocaleConstant
Definition: Common.h:48
@ CREATURE_FLAG_EXTRA_DUNGEON_BOSS
Definition: CreatureData.h:362
@ CREATURE_FLAG_EXTRA_TRIGGER
Definition: CreatureData.h:341
@ CREATURE_FLAG_EXTRA_IGNORE_FEIGN_DEATH
Definition: CreatureData.h:350
@ CREATURE_FLAG_EXTRA_CIVILIAN
Definition: CreatureData.h:335
@ CREATURE_FLAG_EXTRA_GUARD
Definition: CreatureData.h:349
@ CREATURE_FLAG_EXTRA_ALL_DIMINISH
Definition: CreatureData.h:354
CreatureStaticFlags
Definition: CreatureData.h:37
@ CREATURE_STATIC_FLAG_NO_XP
Definition: CreatureData.h:39
@ CREATURE_STATIC_FLAG_UNKILLABLE
Definition: CreatureData.h:41
@ CREATURE_STATIC_FLAG_SESSILE
Definition: CreatureData.h:46
@ CREATURE_STATIC_FLAG_NO_MELEE
Definition: CreatureData.h:58
@ CREATURE_STATIC_FLAG_NO_LOOT
Definition: CreatureData.h:40
CreatureStaticFlags4
Definition: CreatureData.h:151
@ CREATURE_STATIC_FLAG_4_IGNORE_LOS_WHEN_CASTING_ON_ME
Definition: CreatureData.h:165
CreatureStaticFlags6
Definition: CreatureData.h:227
CreatureStaticFlags5
Definition: CreatureData.h:189
@ CREATURE_STATIC_FLAG_5_NO_HEALTH_REGEN
Definition: CreatureData.h:217
CreatureStaticFlags8
Definition: CreatureData.h:283
CreatureStaticFlags7
Definition: CreatureData.h:265
CreatureStaticFlags3
Definition: CreatureData.h:113
@ CREATURE_STATIC_FLAG_3_NO_THREAT_FEEDBACK
Definition: CreatureData.h:129
CreatureStaticFlags2
Definition: CreatureData.h:75
const uint32 MAX_CREATURE_SPELLS
Definition: CreatureData.h:443
VendorInventoryReason
Definition: Creature.h:57
std::vector< uint8 > CreatureTextRepeatIds
Definition: Creature.h:66
std::list< VendorItemCount > VendorItemCounts
Definition: Creature.h:49
std::unordered_map< uint8, CreatureTextRepeatIds > CreatureTextRepeatGroup
Definition: Creature.h:67
static constexpr uint8 WILD_BATTLE_PET_DEFAULT_LEVEL
Definition: Creature.h:62
static constexpr size_t CREATURE_TAPPERS_SOFT_CAP
Definition: Creature.h:63
#define TC_GAME_API
Definition: Define.h:124
uint8_t uint8
Definition: Define.h:145
int8_t int8
Definition: Define.h:141
int32_t int32
Definition: Define.h:139
uint64_t uint64
Definition: Define.h:142
uint16_t uint16
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:143
uint16 flags
Definition: DisableMgr.cpp:49
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition: Duration.h:32
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition: Duration.h:29
MovementGeneratorType
std::list< ObjectGuid > GuidList
Definition: ObjectGuid.h:392
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition: ObjectGuid.h:394
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
static void SaveToDB(QuestPool const &pool, CharacterDatabaseTransaction trans)
Definition: QuestPools.cpp:50
SpellSchoolMask
AiReaction
WeaponAttackType
@ BASE_ATTACK
Powers
@ LOOT_MODE_DEFAULT
Definition: SharedDefines.h:77
Stats
CreatureClassifications
SpellSchools
ReactStates
Definition: UnitDefines.h:505
@ REACT_PASSIVE
Definition: UnitDefines.h:506
DeathState
Definition: Unit.h:240
@ UNIT_STATE_EVADE
Definition: Unit.h:272
Unit & m_owner
Definition: Creature.h:551
ObjectGuid m_victim
Definition: Creature.h:549
AssistDelayEvent(ObjectGuid victim, Unit &owner)
Definition: Creature.h:542
void AddAssistant(ObjectGuid guid)
Definition: Creature.h:545
GuidList m_assistants
Definition: Creature.h:550
bool HasClassification(CreatureClassifications classification) const
Definition: Creature.h:133
time_t _pickpocketLootRestore
Timers.
Definition: Creature.h:454
bool CanMelee() const
Definition: Creature.h:191
void SetCombatPulseDelay(uint32 delay)
Definition: Creature.h:312
VendorItemCounts m_vendorItemCounts
Definition: Creature.h:446
time_t const & GetRespawnTime() const
Definition: Creature.h:298
void SetHomePosition(float x, float y, float z, float o)
Definition: Creature.h:333
bool IsTapListNotClearedOnEvade() const
Definition: Creature.h:255
float m_wanderDistance
Definition: Creature.h:460
void SetNoSearchAssistance(bool val)
Definition: Creature.h:288
void RemoveLootMode(uint16 lootMode)
Definition: Creature.h:269
void SetUnkillable(bool unkillable)
Definition: Creature.h:155
CreatureDifficulty const * m_creatureDifficulty
Definition: Creature.h:488
bool HasLootMode(uint16 lootMode) const
Definition: Creature.h:266
int8 GetOriginalEquipmentId() const
Definition: Creature.h:210
bool IsTrigger() const
Definition: Creature.h:116
void SetHomePosition(Position const &pos)
Definition: Creature.h:334
void ResetLootMode()
Definition: Creature.h:270
void DoImmediateBoundaryCheck()
Definition: Creature.h:310
CreatureTextRepeatGroup m_textRepeat
Definition: Creature.h:522
float _sparringHealthPct
Definition: Creature.h:536
bool _regenerateHealth
Definition: Creature.h:529
CreatureStaticFlagsHolder _staticFlags
Definition: Creature.h:526
bool IsDungeonBoss() const
Definition: Creature.h:135
SpellSchoolMask m_meleeDamageSchoolMask
Definition: Creature.h:478
Optional< uint32 > m_lootId
Definition: Creature.h:492
int8 m_originalEquipmentId
Definition: Creature.h:471
bool GetRespawnCompatibilityMode() const
Definition: Creature.h:370
void SetDisableReputationGain(bool disable)
Definition: Creature.h:359
ObjectGuid::LowType m_spawnId
For new or temporary creatures is 0 for saved it is lowguid.
Definition: Creature.h:469
std::unique_ptr< Loot > m_loot
Definition: Creature.h:247
CreatureDifficulty const * GetCreatureDifficulty() const
Definition: Creature.h:222
Position m_transportHomePosition
Definition: Creature.h:482
CreatureClassifications GetCreatureClassification() const
Definition: Creature.h:132
uint16 GetLootMode() const
Definition: Creature.h:265
bool IsCivilian() const
Definition: Creature.h:115
void SetImmuneToPC(bool apply) override
Definition: Creature.h:150
bool IsReputationGainDisabled() const
Definition: Creature.h:360
float GetSparringHealthPct() const
Definition: Creature.h:407
bool HasCanSwimFlagOutOfCombat() const
Definition: Creature.h:411
bool IsTemplateRooted() const
Definition: Creature.h:98
bool CanIgnoreLineOfSightWhenCastingOnMe() const
Definition: Creature.h:193
Optional< std::string > m_scriptStringId
Definition: Creature.h:490
bool m_cannotReachTarget
Definition: Creature.h:475
bool m_respawnCompatibilityMode
Definition: Creature.h:509
bool CanWalk() const
Definition: Creature.h:123
std::unordered_map< ObjectGuid, std::unique_ptr< Loot > > m_personalLoot
Definition: Creature.h:248
CreatureTemplate const * m_creatureInfo
Definition: Creature.h:486
bool IsSpawnedOnTransport() const
Definition: Creature.h:105
bool CanFly() const override
Definition: Creature.h:126
void GetHomePosition(float &x, float &y, float &z, float &ori) const
Definition: Creature.h:335
Position const & GetHomePosition() const
Definition: Creature.h:336
void SetLastDamagedTime(time_t val)
Definition: Creature.h:389
bool IsEvadingAttacks() const
Definition: Creature.h:180
bool HasReactState(ReactStates state) const
Definition: Creature.h:142
bool m_triggerJustAppeared
Definition: Creature.h:508
void SetCanGiveExperience(bool xpEnabled)
Definition: Creature.h:397
void GetTransportHomePosition(float &x, float &y, float &z, float &ori) const
Definition: Creature.h:340
uint32 GetOriginalEntry() const
Definition: Creature.h:365
bool IsThreatFeedbackDisabled() const
Definition: Creature.h:403
MovementGeneratorType m_defaultMovementType
Definition: Creature.h:468
bool CanHaveLoot() const
Definition: Creature.h:243
void SetReactState(ReactStates st)
Definition: Creature.h:140
GuidUnorderedSet const & GetTapList() const
Definition: Creature.h:252
bool CanHover() const
Definition: Creature.h:127
uint32 _waypointPathId
Definition: Creature.h:503
void ResetPlayerDamageReq()
Definition: Creature.h:362
int32 _creatureImmunitiesId
Definition: Creature.h:533
std::pair< uint32, uint32 > _currentWaypointNodeInfo
Definition: Creature.h:504
bool hasLootRecipient() const
Definition: Creature.h:254
void SetRespawnCompatibilityMode(bool mode=true)
Definition: Creature.h:369
void SetCurrentEquipmentId(uint8 id)
Definition: Creature.h:212
void SetRespawnDelay(uint32 delay)
Definition: Creature.h:305
bool HasFlag(CreatureStaticFlags7 flag) const
Definition: Creature.h:427
uint32 m_cannotReachTimer
Definition: Creature.h:476
uint32 m_respawnDelay
Definition: Creature.h:457
time_t m_corpseRemoveTime
Definition: Creature.h:455
uint32 m_combatPulseDelay
Definition: Creature.h:463
void UpdateCurrentWaypointInfo(uint32 nodeId, uint32 pathId)
Definition: Creature.h:348
time_t m_respawnTime
Definition: Creature.h:456
uint32 _gossipMenuId
Definition: Creature.h:534
void SetRegenerateHealth(bool value)
Definition: Creature.h:325
bool HasFlag(CreatureStaticFlags3 flag) const
Definition: Creature.h:423
CreatureData const * m_creatureData
Definition: Creature.h:487
float m_CombatDistance
Definition: Creature.h:374
SpellSchoolMask GetMeleeDamageSchoolMask(WeaponAttackType=BASE_ATTACK) const override
Definition: Creature.h:189
bool HasFlag(CreatureStaticFlags2 flag) const
Definition: Creature.h:422
uint16 m_LootMode
Definition: Creature.h:493
uint32 m_boundaryCheckTime
Definition: Creature.h:461
Position m_homePosition
Definition: Creature.h:481
uint32 GetWaypointPathId() const
Definition: Creature.h:343
CreatureData const * GetCreatureData() const
Definition: Creature.h:221
std::pair< uint32, uint32 > GetCurrentWaypointInfo() const
Definition: Creature.h:347
bool CanIgnoreFeignDeath() const
Definition: Creature.h:292
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:101
bool CanNotReachTarget() const
Definition: Creature.h:331
bool m_AlreadyCallAssistance
Definition: Creature.h:473
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:220
uint32 GetRespawnDelay() const
Definition: Creature.h:304
Position const & GetTransportHomePosition() const
Definition: Creature.h:341
bool CanRegenerateHealth() const
Definition: Creature.h:324
bool DisableReputationGain
Definition: Creature.h:484
CreatureGroup * m_formation
Definition: Creature.h:507
void SetInteractSpellId(int32 interactSpellId)
Definition: Creature.h:439
bool HasSearchedAssistance() const
Definition: Creature.h:289
void SetTransportHomePosition(Position const &pos)
Definition: Creature.h:339
uint32 m_corpseDelay
Definition: Creature.h:458
bool HasFlag(CreatureStaticFlags4 flag) const
Definition: Creature.h:424
bool HasFlag(CreatureStaticFlags6 flag) const
Definition: Creature.h:426
std::array< std::string_view, 3 > m_stringIds
Definition: Creature.h:489
void SetCanHaveLoot(bool canHaveLoot)
Definition: Creature.h:244
void SetNoThreatFeedback(bool noThreatFeedback)
Definition: Creature.h:404
void SetImmuneToNPC(bool apply) override
Definition: Creature.h:153
uint8 m_equipmentId
Definition: Creature.h:470
std::array< std::string_view, 3 > const & GetStringIds() const
Definition: Creature.h:230
CreatureGroup * GetFormation()
Definition: Creature.h:353
bool m_AlreadySearchedAssistance
Definition: Creature.h:474
uint32 GetCorpseDelay() const
Definition: Creature.h:113
GuidUnorderedSet m_tapList
Definition: Creature.h:450
bool m_dontClearTapListOnEvade
Definition: Creature.h:451
uint32 m_originalEntry
Definition: Creature.h:479
void SetImmuneToAll(bool apply) override
Definition: Creature.h:147
bool HasFlag(CreatureStaticFlags8 flag) const
Definition: Creature.h:428
bool m_isTempWorldObject
Definition: Creature.h:376
void AddLootMode(uint16 lootMode)
Definition: Creature.h:268
ObjectGuid Target
Definition: Creature.h:517
ReactStates m_reactState
Definition: Creature.h:465
time_t _lastDamagedTime
Definition: Creature.h:521
ReactStates GetReactState() const
Definition: Creature.h:141
void SetTransportHomePosition(float x, float y, float z, float o)
Definition: Creature.h:338
void SetWanderDistance(float dist)
Definition: Creature.h:308
time_t GetLastDamagedTime() const
Definition: Creature.h:388
MovementGeneratorType GetDefaultMovementType() const override
Definition: Creature.h:129
Optional< uint32 > _trainerId
Definition: Creature.h:535
bool HasFlag(CreatureStaticFlags flag) const
Definition: Creature.h:421
uint8 GetCurrentEquipmentId() const
Definition: Creature.h:211
void SetFormation(CreatureGroup *formation)
Definition: Creature.h:354
void SetCorpseDelay(uint32 delay, bool ignoreCorpseDecayRatio=false)
Definition: Creature.h:107
uint32 GetCombatPulseDelay() const
Definition: Creature.h:311
void SetMeleeDamageSchool(SpellSchools school)
Definition: Creature.h:190
float GetWanderDistance() const
Definition: Creature.h:307
void ResetPickPocketRefillTimer()
Definition: Creature.h:250
void SetNoCallAssistance(bool val)
Definition: Creature.h:287
bool IsAffectedByDiminishingReturns() const override
Definition: Creature.h:136
bool IsRacialLeader() const
Definition: Creature.h:114
bool m_ignoreCorpseDecayRatio
Definition: Creature.h:459
bool HasFlag(CreatureStaticFlags5 flag) const
Definition: Creature.h:425
bool IsInEvadeMode() const
Definition: Creature.h:179
bool IsGuard() const
Definition: Creature.h:117
CreatureAI * AI() const
Definition: Creature.h:187
void SetCanMelee(bool canMelee)
Definition: Creature.h:192
void SetLootMode(uint16 lootMode)
Definition: Creature.h:267
void SetDefaultMovementType(MovementGeneratorType mgt)
Definition: Creature.h:130
void LoadPath(uint32 pathid)
Definition: Creature.h:344
void SetTapList(GuidUnorderedSet tapList)
Definition: Creature.h:253
void SetOriginalEntry(uint32 entry)
Definition: Creature.h:366
bool _isMissingCanSwimFlagOutOfCombat
Definition: Creature.h:531
void DisappearAndDie()
Definition: Creature.h:83
uint32 m_combatPulseTime
Definition: Creature.h:462
uint64 m_PlayerDamageReq
Definition: Creature.h:363
Seconds const m_respawnTimer
Definition: Creature.h:562
ForcedDespawnDelayEvent(Creature &owner, Seconds respawnTimer)
Definition: Creature.h:557
Definition: Map.h:187
uint64 LowType
Definition: ObjectGuid.h:276
virtual bool hasQuest(uint32) const
Definition: Object.h:191
void SetUpdateFieldValue(UF::UpdateFieldSetter< T > setter, typename UF::UpdateFieldSetter< T >::value_type value)
Definition: Object.h:272
virtual Loot * GetLootForPlayer(Player const *player) const
Definition: Object.h:264
virtual void SetObjectScale(float scale)
Definition: Object.h:164
virtual bool hasInvolvedQuest(uint32) const
Definition: Object.h:192
Definition: Spell.h:254
Definition: Unit.h:622
void SetImmuneToAll(bool apply, bool keepCombat)
Definition: Unit.cpp:8061
void SetImmuneToPC(bool apply, bool keepCombat)
Definition: Unit.cpp:8074
virtual bool IsMovementPreventedByCasting() const
Definition: Unit.cpp:3116
virtual int32 GetCreatePowerValue(Powers power) const
Definition: StatSystem.cpp:89
void AddToWorld() override
Definition: Unit.cpp:9539
virtual float GetArmorMultiplierForTarget(WorldObject const *) const
Definition: Unit.h:792
virtual void SetCanDualWield(bool value)
Definition: Unit.h:688
UF::UpdateField< UF::UnitData, 0, TYPEID_UNIT > m_unitData
Definition: Unit.h:1791
virtual bool UpdateAllStats()=0
virtual void AtEngage(Unit *)
Definition: Unit.h:1905
virtual void UpdateAttackPowerAndDamage(bool ranged=false)=0
virtual void AtDisengage()
Definition: Unit.h:1906
std::string GetDebugInfo() const override
Definition: Unit.cpp:13656
void SetImmuneToNPC(bool apply, bool keepCombat)
Definition: Unit.cpp:8097
UnitAI * GetAI() const
Definition: Unit.h:655
virtual bool HasSpell(uint32) const
Definition: Unit.h:1055
virtual bool IsAffectedByDiminishingReturns() const
Definition: Unit.h:673
bool IsImmuneToNPC() const
Definition: Unit.h:1028
virtual bool CanEnterWater() const =0
virtual bool IsImmunedToSpellEffect(SpellInfo const *spellInfo, SpellEffectInfo const &spellEffectInfo, WorldObject const *caster, bool requireImmunityPurgesEffectAttribute=false) const
Definition: Unit.cpp:7535
bool IsImmuneToAll() const
Definition: Unit.h:1022
virtual void UpdateArmor()=0
bool IsHovering() const
Definition: Unit.h:1123
virtual float GetDamageMultiplierForTarget(WorldObject const *) const
Definition: Unit.h:791
virtual void UpdateMaxPower(Powers power)=0
uint64 GetHealth() const
Definition: Unit.h:771
virtual bool UpdateStats(Stats stat)=0
uint8 GetLevelForTarget(WorldObject const *) const override
Definition: Unit.h:742
virtual void CalculateMinMaxDamage(WeaponAttackType attType, bool normalized, bool addTotalPct, float &minDamage, float &maxDamage) const =0
virtual void SetTarget(ObjectGuid const &)=0
virtual uint32 GetPowerIndex(Powers power) const =0
virtual float GetHealthMultiplierForTarget(WorldObject const *) const
Definition: Unit.h:790
bool HasUnitState(const uint32 f) const
Definition: Unit.h:727
virtual void Update(uint32 time) override
Definition: Unit.cpp:418
virtual bool CanSwim() const
Definition: Unit.cpp:12236
virtual float GetNativeObjectScale() const
Definition: Unit.h:1550
void RemoveFromWorld() override
Definition: Unit.cpp:9547
virtual void UpdateMaxHealth()=0
virtual bool HasSpellFocus(Spell const *=nullptr) const
Definition: Unit.h:1435
virtual void setDeathState(DeathState s)
Definition: Unit.cpp:8565
bool IsFlying() const
Definition: Unit.h:1719
virtual bool IsEngaged() const
Definition: Unit.h:1014
bool IsImmuneToPC() const
Definition: Unit.h:1025
virtual void SetDisplayId(uint32 displayId, bool setNative=false)
Definition: Unit.cpp:10082
virtual void ExitVehicle(Position const *exitPosition=nullptr)
Definition: Unit.cpp:12127
uint32 GetMapId() const
Definition: Position.h:185
virtual bool IsInvisibleDueToDespawn(WorldObject const *seer) const
Definition: Object.h:802
std::string GetNameForLocaleIdx(LocaleConstant) const override
Definition: Object.h:539
virtual bool CanAlwaysSee(WorldObject const *) const
Definition: Object.h:799
Player session in the World.
Definition: WorldSession.h:962
void apply(T *val)
Definition: ByteConverter.h:41
Definition: wmo.h:163
Definition: Loot.h:281
UpdateField< int32, 96, 114 > InteractSpellID
Definition: UpdateFields.h:378
time_t lastIncrementTime
Definition: Creature.h:46
uint32 itemId
Definition: Creature.h:44
VendorItemCount(uint32 _item, uint32 _count)
Definition: Creature.cpp:82
uint32 count
Definition: Creature.h:45