1. /*
  2. * Copyright (C) 2008-2011 TrinityCore <http://www.trinitycore.org/>
  3. * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef TRINITYCORE_CREATURE_H
  19. #define TRINITYCORE_CREATURE_H
  20. #include "Common.h"
  21. #include "Unit.h"
  22. #include "UpdateMask.h"
  23. #include "ItemPrototype.h"
  24. #include "LootMgr.h"
  25. #include "DatabaseEnv.h"
  26. #include "Cell.h"
  27. #include <list>
  28. struct SpellEntry;
  29. class CreatureAI;
  30. class Quest;
  31. class Player;
  32. class WorldSession;
  33. class CreatureGroup;
  34. enum CreatureFlagsExtra
  35. {
  36. CREATURE_FLAG_EXTRA_INSTANCE_BIND = 0x00000001, // creature kill bind instance with killer and killer's group
  37. CREATURE_FLAG_EXTRA_CIVILIAN = 0x00000002, // not aggro (ignore faction/reputation hostility)
  38. CREATURE_FLAG_EXTRA_NO_PARRY = 0x00000004, // creature can't parry
  39. CREATURE_FLAG_EXTRA_NO_PARRY_HASTEN = 0x00000008, // creature can't counter-attack at parry
  40. CREATURE_FLAG_EXTRA_NO_BLOCK = 0x00000010, // creature can't block
  41. CREATURE_FLAG_EXTRA_NO_CRUSH = 0x00000020, // creature can't do crush attacks
  42. CREATURE_FLAG_EXTRA_NO_XP_AT_KILL = 0x00000040, // creature kill not provide XP
  43. CREATURE_FLAG_EXTRA_TRIGGER = 0x00000080, // trigger creature
  44. CREATURE_FLAG_EXTRA_NO_TAUNT = 0x00000100, // creature is immune to taunt auras and effect attack me
  45. CREATURE_FLAG_EXTRA_WORLDEVENT = 0x00004000, // custom flag for world event creatures (left room for merging)
  46. CREATURE_FLAG_EXTRA_GUARD = 0x00008000, // Creature is guard
  47. CREATURE_FLAG_EXTRA_NO_CRIT = 0x00020000, // creature can't do critical strikes
  48. CREATURE_FLAG_EXTRA_NO_SKILLGAIN = 0x00040000, // creature won't increase weapon skills
  49. CREATURE_FLAG_EXTRA_TAUNT_DIMINISH = 0x00080000, // Taunt is a subject to diminishing returns on this creautre
  50. CREATURE_FLAG_EXTRA_ALL_DIMINISH = 0x00100000, // Creature is subject to all diminishing returns as player are
  51. CREATURE_FLAG_EXTRA_DUNGEON_BOSS = 0x10000000, // creature is a dungeon boss (SET DYNAMICALLY, DO NOT ADD IN DB)
  52. };
  53. #define CREATURE_FLAG_EXTRA_DB_ALLOWED (CREATURE_FLAG_EXTRA_INSTANCE_BIND | CREATURE_FLAG_EXTRA_CIVILIAN | \
  54. CREATURE_FLAG_EXTRA_NO_PARRY | CREATURE_FLAG_EXTRA_NO_PARRY_HASTEN | CREATURE_FLAG_EXTRA_NO_BLOCK | \
  55. CREATURE_FLAG_EXTRA_NO_CRUSH | CREATURE_FLAG_EXTRA_NO_XP_AT_KILL | CREATURE_FLAG_EXTRA_TRIGGER | \
  56. CREATURE_FLAG_EXTRA_NO_TAUNT | CREATURE_FLAG_EXTRA_WORLDEVENT | CREATURE_FLAG_EXTRA_NO_CRIT | \
  57. CREATURE_FLAG_EXTRA_NO_SKILLGAIN | CREATURE_FLAG_EXTRA_TAUNT_DIMINISH | CREATURE_FLAG_EXTRA_ALL_DIMINISH | \
  58. CREATURE_FLAG_EXTRA_GUARD)
  59. // GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push,N), also any gcc version not support it at some platform
  60. #if defined(__GNUC__)
  61. #pragma pack(1)
  62. #else
  63. #pragma pack(push,1)
  64. #endif
  65. #define MAX_KILL_CREDIT 2
  66. #define CREATURE_REGEN_INTERVAL 2 * IN_MILLISECONDS
  67. #define MAX_CREATURE_QUEST_ITEMS 6
  68. // from `creature_template` table
  69. struct CreatureInfo
  70. {
  71. uint32 Entry;
  72. uint32 DifficultyEntry[MAX_DIFFICULTY - 1];
  73. uint32 KillCredit[MAX_KILL_CREDIT];
  74. uint32 Modelid1;
  75. uint32 Modelid2;
  76. uint32 Modelid3;
  77. uint32 Modelid4;
  78. char* Name;
  79. char* SubName;
  80. char* IconName;
  81. uint32 GossipMenuId;
  82. uint8 minlevel;
  83. uint8 maxlevel;
  84. uint32 expansion;
  85. uint32 faction_A;
  86. uint32 faction_H;
  87. uint32 npcflag;
  88. float speed_walk;
  89. float speed_run;
  90. float scale;
  91. uint32 rank;
  92. float mindmg;
  93. float maxdmg;
  94. uint32 dmgschool;
  95. uint32 attackpower;
  96. float dmg_multiplier;
  97. uint32 baseattacktime;
  98. uint32 rangeattacktime;
  99. uint32 unit_class; // enum Classes. Note only 4 classes are known for creatures.
  100. uint32 unit_flags; // enum UnitFlags mask values
  101. uint32 dynamicflags;
  102. uint32 family; // enum CreatureFamily values (optional)
  103. uint32 trainer_type;
  104. uint32 trainer_spell;
  105. uint32 trainer_class;
  106. uint32 trainer_race;
  107. float minrangedmg;
  108. float maxrangedmg;
  109. uint32 rangedattackpower;
  110. uint32 type; // enum CreatureType values
  111. uint32 type_flags; // enum CreatureTypeFlags mask values
  112. uint32 lootid;
  113. uint32 pickpocketLootId;
  114. uint32 SkinLootId;
  115. int32 resistance1;
  116. int32 resistance2;
  117. int32 resistance3;
  118. int32 resistance4;
  119. int32 resistance5;
  120. int32 resistance6;
  121. uint32 spells[CREATURE_MAX_SPELLS];
  122. uint32 PetSpellDataId;
  123. uint32 VehicleId;
  124. uint32 mingold;
  125. uint32 maxgold;
  126. char const* AIName;
  127. uint32 MovementType;
  128. uint32 InhabitType;
  129. float ModHealth;
  130. float ModMana;
  131. float ModArmor;
  132. bool RacialLeader;
  133. uint32 questItems[MAX_CREATURE_QUEST_ITEMS];
  134. uint32 movementId;
  135. bool RegenHealth;
  136. uint32 equipmentId;
  137. uint32 MechanicImmuneMask;
  138. uint32 flags_extra;
  139. uint32 ScriptID;
  140. uint32 GetRandomValidModelId() const;
  141. uint32 GetFirstValidModelId() const;
  142. // helpers
  143. SkillType GetRequiredLootSkill() const
  144. {
  145. if (type_flags & CREATURE_TYPEFLAGS_HERBLOOT)
  146. return SKILL_HERBALISM;
  147. else if (type_flags & CREATURE_TYPEFLAGS_MININGLOOT)
  148. return SKILL_MINING;
  149. else if (type_flags & CREATURE_TYPEFLAGS_ENGINEERLOOT)
  150. return SKILL_ENGINERING;
  151. else
  152. return SKILL_SKINNING; // normal case
  153. }
  154. bool isTameable(bool exotic) const
  155. {
  156. if (type != CREATURE_TYPE_BEAST || family == 0 || (type_flags & CREATURE_TYPEFLAGS_TAMEABLE) == 0)
  157. return false;
  158. // if can tame exotic then can tame any temable
  159. return exotic || (type_flags & CREATURE_TYPEFLAGS_EXOTIC) == 0;
  160. }
  161. };
  162. // Represents max amount of expansions.
  163. // TODO: Add MAX_EXPANSION constant.
  164. #define MAX_CREATURE_BASE_HP 3
  165. // Defines base stats for creatures (used to calculate HP/mana/armor).
  166. struct CreatureBaseStats
  167. {
  168. uint32 BaseHealth[MAX_CREATURE_BASE_HP];
  169. uint32 BaseMana;
  170. uint32 BaseArmor;
  171. // Helpers
  172. uint32 GenerateHealth(CreatureInfo const* info) const
  173. {
  174. return uint32((BaseHealth[info->expansion] * info->ModHealth) + 0.5f);
  175. }
  176. uint32 GenerateMana(CreatureInfo const* info) const
  177. {
  178. // Mana can be 0.
  179. if (!BaseMana)
  180. return 0;
  181. return uint32((BaseMana * info->ModMana) + 0.5f);
  182. }
  183. uint32 GenerateArmor(CreatureInfo const* info) const
  184. {
  185. return uint32((BaseArmor * info->ModArmor) + 0.5f);
  186. }
  187. static CreatureBaseStats const* GetBaseStats(uint8 level, uint8 unitClass);
  188. };
  189. typedef UNORDERED_MAP<uint16, CreatureBaseStats> CreatureBaseStatsMap;
  190. struct CreatureLocale
  191. {
  192. StringVector Name;
  193. StringVector SubName;
  194. };
  195. struct GossipMenuItemsLocale
  196. {
  197. StringVector OptionText;
  198. StringVector BoxText;
  199. };
  200. struct PointOfInterestLocale
  201. {
  202. StringVector IconName;
  203. };
  204. struct EquipmentInfo
  205. {
  206. uint32 entry;
  207. uint32 equipentry[3];
  208. };
  209. // from `creature` table
  210. struct CreatureData
  211. {
  212. explicit CreatureData() : dbData(true) {}
  213. uint32 id; // entry in creature_template
  214. uint16 mapid;
  215. uint16 phaseMask;
  216. uint32 displayid;
  217. int32 equipmentId;
  218. float posX;
  219. float posY;
  220. float posZ;
  221. float orientation;
  222. uint32 spawntimesecs;
  223. float spawndist;
  224. uint32 currentwaypoint;
  225. uint32 curhealth;
  226. uint32 curmana;
  227. bool is_dead;
  228. uint8 movementType;
  229. uint8 spawnMask;
  230. uint32 npcflag;
  231. uint32 unit_flags; // enum UnitFlags mask values
  232. uint32 dynamicflags;
  233. bool dbData;
  234. };
  235. struct CreatureDataAddonAura
  236. {
  237. uint32 spell_id;
  238. uint8 effectMask;
  239. };
  240. // from `creature_addon` table
  241. struct CreatureDataAddon
  242. {
  243. uint32 guidOrEntry;
  244. uint32 path_id;
  245. uint32 mount;
  246. uint32 bytes1;
  247. uint32 bytes2;
  248. uint32 emote;
  249. CreatureDataAddonAura const* auras; // loaded as char* "spell1 eff1 spell2 eff2 ... "
  250. };
  251. struct CreatureModelInfo
  252. {
  253. uint32 modelid;
  254. float bounding_radius;
  255. float combat_reach;
  256. uint8 gender;
  257. uint32 modelid_other_gender;
  258. };
  259. enum InhabitTypeValues
  260. {
  261. INHABIT_GROUND = 1,
  262. INHABIT_WATER = 2,
  263. INHABIT_AIR = 4,
  264. INHABIT_ANYWHERE = INHABIT_GROUND | INHABIT_WATER | INHABIT_AIR
  265. };
  266. // Enums used by StringTextData::Type (CreatureEventAI)
  267. enum ChatType
  268. {
  269. CHAT_TYPE_SAY = 0,
  270. CHAT_TYPE_YELL = 1,
  271. CHAT_TYPE_TEXT_EMOTE = 2,
  272. CHAT_TYPE_BOSS_EMOTE = 3,
  273. CHAT_TYPE_WHISPER = 4,
  274. CHAT_TYPE_BOSS_WHISPER = 5,
  275. CHAT_TYPE_ZONE_YELL = 6,
  276. CHAT_TYPE_END = 255
  277. };
  278. // GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform
  279. #if defined(__GNUC__)
  280. #pragma pack()
  281. #else
  282. #pragma pack(pop)
  283. #endif
  284. // Vendors
  285. struct VendorItem
  286. {
  287. VendorItem(uint32 _item, int32 _maxcount, uint32 _incrtime, uint32 _ExtendedCost)
  288. : item(_item), maxcount(_maxcount), incrtime(_incrtime), ExtendedCost(_ExtendedCost) {}
  289. uint32 item;
  290. uint32 maxcount; // 0 for infinity item amount
  291. uint32 incrtime; // time for restore items amount if maxcount != 0
  292. uint32 ExtendedCost;
  293. //helpers
  294. bool IsGoldRequired(ItemPrototype const* pProto) const { return pProto->Flags2 & ITEM_FLAGS_EXTRA_EXT_COST_REQUIRES_GOLD || !ExtendedCost; }
  295. };
  296. typedef std::vector<VendorItem*> VendorItemList;
  297. struct VendorItemData
  298. {
  299. VendorItemList m_items;
  300. VendorItem* GetItem(uint32 slot) const
  301. {
  302. if (slot >= m_items.size()) return NULL;
  303. return m_items[slot];
  304. }
  305. bool Empty() const { return m_items.empty(); }
  306. uint8 GetItemCount() const { return m_items.size(); }
  307. void AddItem(uint32 item, int32 maxcount, uint32 ptime, uint32 ExtendedCost)
  308. {
  309. m_items.push_back(new VendorItem(item, maxcount, ptime, ExtendedCost));
  310. }
  311. bool RemoveItem(uint32 item_id);
  312. VendorItem const* FindItemCostPair(uint32 item_id, uint32 extendedCost) const;
  313. void Clear()
  314. {
  315. for (VendorItemList::const_iterator itr = m_items.begin(); itr != m_items.end(); ++itr)
  316. delete (*itr);
  317. m_items.clear();
  318. }
  319. };
  320. struct VendorItemCount
  321. {
  322. explicit VendorItemCount(uint32 _item, uint32 _count)
  323. : itemId(_item), count(_count), lastIncrementTime(time(NULL)) {}
  324. uint32 itemId;
  325. uint32 count;
  326. time_t lastIncrementTime;
  327. };
  328. typedef std::list<VendorItemCount> VendorItemCounts;
  329. struct TrainerSpell
  330. {
  331. TrainerSpell() : spell(0), spellCost(0), reqSkill(0), reqSkillValue(0), reqLevel(0)
  332. {
  333. for (uint8 i = 0; i < MAX_SPELL_EFFECTS ; ++i)
  334. learnedSpell[i] = 0;
  335. }
  336. uint32 spell;
  337. uint32 spellCost;
  338. uint32 reqSkill;
  339. uint32 reqSkillValue;
  340. uint32 reqLevel;
  341. uint32 learnedSpell[3];
  342. // helpers
  343. bool IsCastable() const { return learnedSpell[0] != spell; }
  344. };
  345. typedef UNORDERED_MAP<uint32 /*spellid*/, TrainerSpell> TrainerSpellMap;
  346. struct TrainerSpellData
  347. {
  348. TrainerSpellData() : trainerType(0) {}
  349. ~TrainerSpellData() { spellList.clear(); }
  350. TrainerSpellMap spellList;
  351. uint32 trainerType; // trainer type based at trainer spells, can be different from creature_template value.
  352. // req. for correct show non-prof. trainers like weaponmaster, allowed values 0 and 2.
  353. TrainerSpell const* Find(uint32 spell_id) const;
  354. };
  355. typedef std::map<uint32,time_t> CreatureSpellCooldowns;
  356. // max different by z coordinate for creature aggro reaction
  357. #define CREATURE_Z_ATTACK_RANGE 3
  358. #define MAX_VENDOR_ITEMS 150 // Limitation in 3.x.x item count in SMSG_LIST_INVENTORY
  359. class Creature : public Unit, public GridObject<Creature>
  360. {
  361. public:
  362. explicit Creature();
  363. virtual ~Creature();
  364. void AddToWorld();
  365. void RemoveFromWorld();
  366. void DisappearAndDie();
  367. bool Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 vehId, uint32 team, float x, float y, float z, float ang, const CreatureData *data = NULL);
  368. bool LoadCreaturesAddon(bool reload = false);
  369. void SelectLevel(const CreatureInfo *cinfo);
  370. void LoadEquipment(uint32 equip_entry, bool force=false);
  371. uint32 GetDBTableGUIDLow() const { return m_DBTableGuid; }
  372. char const* GetSubName() const { return GetCreatureInfo()->SubName; }
  373. void Update(uint32 time); // overwrited Unit::Update
  374. void GetRespawnCoord(float &x, float &y, float &z, float* ori = NULL, float* dist =NULL) const;
  375. uint32 GetEquipmentId() const { return GetCreatureInfo()->equipmentId; }
  376. void SetCorpseDelay(uint32 delay) { m_corpseDelay = delay; }
  377. bool isRacialLeader() const { return GetCreatureInfo()->RacialLeader; }
  378. bool isCivilian() const { return GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_CIVILIAN; }
  379. bool isTrigger() const { return GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER; }
  380. bool isGuard() const { return GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_GUARD; }
  381. bool canWalk() const { return GetCreatureInfo()->InhabitType & INHABIT_GROUND; }
  382. bool canSwim() const { return GetCreatureInfo()->InhabitType & INHABIT_WATER; }
  383. //bool canFly() const { return GetCreatureInfo()->InhabitType & INHABIT_AIR; }
  384. void SetReactState(ReactStates st) { m_reactState = st; }
  385. ReactStates GetReactState() { return m_reactState; }
  386. bool HasReactState(ReactStates state) const { return (m_reactState == state); }
  387. void InitializeReactState()
  388. {
  389. if (isTotem() || isTrigger() || GetCreatureType() == CREATURE_TYPE_CRITTER || isSpiritService())
  390. SetReactState(REACT_PASSIVE);
  391. else
  392. SetReactState(REACT_AGGRESSIVE);
  393. /*else if (isCivilian())
  394. SetReactState(REACT_DEFENSIVE);*/;
  395. }
  396. ///// TODO RENAME THIS!!!!!
  397. bool isCanTrainingOf(Player* player, bool msg) const;
  398. bool isCanInteractWithBattleMaster(Player* player, bool msg) const;
  399. bool isCanTrainingAndResetTalentsOf(Player* pPlayer) const;
  400. bool canCreatureAttack(Unit const *pVictim, bool force = true) const;
  401. bool IsImmunedToSpell(SpellEntry const* spellInfo);
  402. // redefine Unit::IsImmunedToSpell
  403. bool IsImmunedToSpellEffect(SpellEntry const* spellInfo, uint32 index) const;
  404. // redefine Unit::IsImmunedToSpellEffect
  405. bool isElite() const
  406. {
  407. if (isPet())
  408. return false;
  409. uint32 rank = GetCreatureInfo()->rank;
  410. return rank != CREATURE_ELITE_NORMAL && rank != CREATURE_ELITE_RARE;
  411. }
  412. bool isWorldBoss() const
  413. {
  414. if (isPet())
  415. return false;
  416. return GetCreatureInfo()->rank == CREATURE_ELITE_WORLDBOSS;
  417. }
  418. bool IsDungeonBoss() const;
  419. uint8 getLevelForTarget(WorldObject const* target) const; // overwrite Unit::getLevelForTarget for boss level support
  420. bool IsInEvadeMode() const { return HasUnitState(UNIT_STAT_EVADE); }
  421. bool AIM_Initialize(CreatureAI* ai = NULL);
  422. void Motion_Initialize();
  423. void AI_SendMoveToPacket(float x, float y, float z, uint32 time, uint32 MovementFlags, uint8 type);
  424. CreatureAI * AI() const { return (CreatureAI*)i_AI; }
  425. uint32 GetShieldBlockValue() const //dunno mob block value
  426. {
  427. return (getLevel()/2 + uint32(GetStat(STAT_STRENGTH)/20));
  428. }
  429. SpellSchoolMask GetMeleeDamageSchoolMask() const { return m_meleeDamageSchoolMask; }
  430. void SetMeleeDamageSchool(SpellSchools school) { m_meleeDamageSchoolMask = SpellSchoolMask(1 << school); }
  431. void _AddCreatureSpellCooldown(uint32 spell_id, time_t end_time);
  432. void _AddCreatureCategoryCooldown(uint32 category, time_t apply_time);
  433. void AddCreatureSpellCooldown(uint32 spellid);
  434. bool HasSpellCooldown(uint32 spell_id) const;
  435. bool HasCategoryCooldown(uint32 spell_id) const;
  436. bool HasSpell(uint32 spellID) const;
  437. bool UpdateEntry(uint32 entry, uint32 team=ALLIANCE, const CreatureData* data=NULL);
  438. bool UpdateStats(Stats stat);
  439. bool UpdateAllStats();
  440. void UpdateResistances(uint32 school);
  441. void UpdateArmor();
  442. void UpdateMaxHealth();
  443. void UpdateMaxPower(Powers power);
  444. void UpdateAttackPowerAndDamage(bool ranged = false);
  445. void UpdateDamagePhysical(WeaponAttackType attType);
  446. uint32 GetCurrentEquipmentId() { return m_equipmentId; }
  447. void SetCurrentEquipmentId(uint32 entry) { m_equipmentId = entry; }
  448. float GetSpellDamageMod(int32 Rank);
  449. VendorItemData const* GetVendorItems() const;
  450. uint32 GetVendorItemCurrentCount(VendorItem const* vItem);
  451. uint32 UpdateVendorItemCurrentCount(VendorItem const* vItem, uint32 used_count);
  452. TrainerSpellData const* GetTrainerSpells() const;
  453. CreatureInfo const *GetCreatureInfo() const { return m_creatureInfo; }
  454. CreatureData const *GetCreatureData() const { return m_creatureData; }
  455. CreatureDataAddon const* GetCreatureAddon() const;
  456. std::string GetAIName() const;
  457. std::string GetScriptName() const;
  458. uint32 GetScriptId() const;
  459. void Say(int32 textId, uint32 language, uint64 TargetGuid) { MonsterSay(textId,language,TargetGuid); }
  460. void Yell(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYell(textId,language,TargetGuid); }
  461. void TextEmote(int32 textId, uint64 TargetGuid, bool IsBossEmote = false) { MonsterTextEmote(textId,TargetGuid,IsBossEmote); }
  462. void Whisper(int32 textId, uint64 receiver, bool IsBossWhisper = false) { MonsterWhisper(textId,receiver,IsBossWhisper); }
  463. void YellToZone(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYellToZone(textId,language,TargetGuid); }
  464. // override WorldObject function for proper name localization
  465. const char* GetNameForLocaleIdx(LocaleConstant locale_idx) const;
  466. void setDeathState(DeathState s); // override virtual Unit::setDeathState
  467. bool FallGround();
  468. bool LoadFromDB(uint32 guid, Map *map);
  469. void SaveToDB();
  470. // overriden in Pet
  471. virtual void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
  472. virtual void DeleteFromDB(); // overriden in Pet
  473. Loot loot;
  474. bool lootForPickPocketed;
  475. bool lootForBody;
  476. Player *GetLootRecipient() const;
  477. Group *GetLootRecipientGroup() const;
  478. bool hasLootRecipient() const { return m_lootRecipient || m_lootRecipientGroup; }
  479. bool isTappedBy(Player *player) const; // return true if the creature is tapped by the player or a member of his party.
  480. void SetLootRecipient (Unit* unit);
  481. void AllLootRemovedFromCorpse();
  482. uint16 GetLootMode() { return m_LootMode; }
  483. bool HasLootMode(uint16 lootMode) { return m_LootMode & lootMode; }
  484. void SetLootMode(uint16 lootMode) { m_LootMode = lootMode; }
  485. void AddLootMode(uint16 lootMode) { m_LootMode |= lootMode; }
  486. void RemoveLootMode(uint16 lootMode) { m_LootMode &= ~lootMode; }
  487. void ResetLootMode() { m_LootMode = LOOT_MODE_DEFAULT; }
  488. SpellEntry const *reachWithSpellAttack(Unit *pVictim);
  489. SpellEntry const *reachWithSpellCure(Unit *pVictim);
  490. uint32 m_spells[CREATURE_MAX_SPELLS];
  491. CreatureSpellCooldowns m_CreatureSpellCooldowns;
  492. CreatureSpellCooldowns m_CreatureCategoryCooldowns;
  493. bool canStartAttack(Unit const* u, bool force) const;
  494. float GetAttackDistance(Unit const* pl) const;
  495. void SendAIReaction(AiReaction reactionType);
  496. Unit* SelectNearestTarget(float dist = 0) const;
  497. Unit* SelectNearestTargetInAttackDistance(float dist = 0) const;
  498. void DoFleeToGetAssistance();
  499. void CallForHelp(float fRadius);
  500. void CallAssistance();
  501. void SetNoCallAssistance(bool val) { m_AlreadyCallAssistance = val; }
  502. void SetNoSearchAssistance(bool val) { m_AlreadySearchedAssistance = val; }
  503. bool HasSearchedAssistance() { return m_AlreadySearchedAssistance; }
  504. bool CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction = true) const;
  505. bool _IsTargetAcceptable(const Unit* target) const;
  506. MovementGeneratorType GetDefaultMovementType() const { return m_defaultMovementType; }
  507. void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; }
  508. // for use only in LoadHelper, Map::Add Map::CreatureCellRelocation
  509. Cell const& GetCurrentCell() const { return m_currentCell; }
  510. void SetCurrentCell(Cell const& cell) { m_currentCell = cell; }
  511. void RemoveCorpse(bool setSpawnTime = true);
  512. bool isDeadByDefault() const { return m_isDeadByDefault; };
  513. void ForcedDespawn(uint32 timeMSToDespawn = 0);
  514. void DespawnOrUnsummon(uint32 msTimeToDespawn = 0);
  515. time_t const& GetRespawnTime() const { return m_respawnTime; }
  516. time_t GetRespawnTimeEx() const;
  517. void SetRespawnTime(uint32 respawn) { m_respawnTime = respawn ? time(NULL) + respawn : 0; }
  518. void Respawn(bool force = false);
  519. void SaveRespawnTime();
  520. uint32 GetRespawnDelay() const { return m_respawnDelay; }
  521. void SetRespawnDelay(uint32 delay) { m_respawnDelay = delay; }
  522. float GetRespawnRadius() const { return m_respawnradius; }
  523. void SetRespawnRadius(float dist) { m_respawnradius = dist; }
  524. uint32 m_groupLootTimer; // (msecs)timer used for group loot
  525. uint32 lootingGroupLowGUID; // used to find group which is looting corpse
  526. void SendZoneUnderAttackMessage(Player* attacker);
  527. void SetInCombatWithZone();
  528. bool hasQuest(uint32 quest_id) const;
  529. bool hasInvolvedQuest(uint32 quest_id) const;
  530. bool isRegeneratingHealth() { return m_regenHealth; }
  531. void setRegeneratingHealth(bool state) { m_regenHealth = state; }
  532. virtual uint8 GetPetAutoSpellSize() const { return MAX_SPELL_CHARM; }
  533. virtual uint32 GetPetAutoSpellOnPos(uint8 pos) const
  534. {
  535. if (pos >= MAX_SPELL_CHARM || m_charmInfo->GetCharmSpell(pos)->GetType() != ACT_ENABLED)
  536. return 0;
  537. else
  538. return m_charmInfo->GetCharmSpell(pos)->GetAction();
  539. }
  540. void SetHomePosition(float x, float y, float z, float o) { m_homePosition.Relocate(x, y, z, o); }
  541. void SetHomePosition(const Position &pos) { m_homePosition.Relocate(pos); }
  542. void GetHomePosition(float &x, float &y, float &z, float &ori) { m_homePosition.GetPosition(x, y, z, ori); }
  543. Position GetHomePosition() { return m_homePosition; }
  544. uint32 GetWaypointPath(){return m_path_id;}
  545. void LoadPath(uint32 pathid) { m_path_id = pathid; }
  546. uint32 GetCurrentWaypointID(){return m_waypointID;}
  547. void UpdateWaypointID(uint32 wpID){m_waypointID = wpID;}
  548. void SearchFormation();
  549. CreatureGroup *GetFormation() {return m_formation;}
  550. void SetFormation(CreatureGroup *formation) {m_formation = formation;}
  551. Unit *SelectVictim();
  552. void SetDeadByDefault (bool death_state) {m_isDeadByDefault = death_state;}
  553. void SetDisableReputationGain(bool disable) { DisableReputationGain = disable; }
  554. bool IsReputationGainDisabled() { return DisableReputationGain; }
  555. bool IsDamageEnoughForLootingAndReward() const { return m_PlayerDamageReq == 0; }
  556. void LowerPlayerDamageReq(uint32 unDamage)
  557. {
  558. if (m_PlayerDamageReq)
  559. m_PlayerDamageReq > unDamage ? m_PlayerDamageReq -= unDamage : m_PlayerDamageReq = 0;
  560. }
  561. void ResetPlayerDamageReq() { m_PlayerDamageReq = GetHealth() / 2; }
  562. uint32 m_PlayerDamageReq;
  563. void SetOriginalEntry(uint32 entry) { m_originalEntry = entry; }
  564. static float _GetDamageMod(int32 Rank);
  565. float m_SightDistance, m_CombatDistance;
  566. void SetGUIDTransport(uint32 guid) { guid_transport=guid; }
  567. uint32 GetGUIDTransport() { return guid_transport; }
  568. void FarTeleportTo(Map* map, float X, float Y, float Z, float O);
  569. protected:
  570. bool CreateFromProto(uint32 guidlow, uint32 Entry, uint32 vehId, uint32 team, const CreatureData *data = NULL);
  571. bool InitEntry(uint32 entry, uint32 team=ALLIANCE, const CreatureData* data=NULL);
  572. // vendor items
  573. VendorItemCounts m_vendorItemCounts;
  574. static float _GetHealthMod(int32 Rank);
  575. uint32 m_lootMoney;
  576. uint64 m_lootRecipient;
  577. uint32 m_lootRecipientGroup;
  578. /// Timers
  579. time_t m_corpseRemoveTime; // (msecs)timer for death or corpse disappearance
  580. time_t m_respawnTime; // (secs) time of next respawn
  581. uint32 m_respawnDelay; // (secs) delay between corpse disappearance and respawning
  582. uint32 m_corpseDelay; // (secs) delay between death and corpse disappearance
  583. float m_respawnradius;
  584. ReactStates m_reactState; // for AI, not charmInfo
  585. void RegenerateMana();
  586. void RegenerateHealth();
  587. void Regenerate(Powers power);
  588. MovementGeneratorType m_defaultMovementType;
  589. Cell m_currentCell; // store current cell where creature listed
  590. uint32 m_DBTableGuid; ///< For new or temporary creatures is 0 for saved it is lowguid
  591. uint32 m_equipmentId;
  592. bool m_AlreadyCallAssistance;
  593. bool m_AlreadySearchedAssistance;
  594. bool m_regenHealth;
  595. bool m_AI_locked;
  596. bool m_isDeadByDefault;
  597. SpellSchoolMask m_meleeDamageSchoolMask;
  598. uint32 m_originalEntry;
  599. Position m_homePosition;
  600. bool DisableReputationGain;
  601. CreatureInfo const* m_creatureInfo; // in difficulty mode > 0 can different from ObjectMgr::GetCreatureTemplate(GetEntry())
  602. CreatureData const* m_creatureData;
  603. uint16 m_LootMode; // bitmask, default LOOT_MODE_DEFAULT, determines what loot will be lootable
  604. uint32 guid_transport;
  605. bool isVisibleForInState(WorldObject const* seer) const;
  606. bool canSeeAlways(WorldObject const* obj) const;
  607. private:
  608. //WaypointMovementGenerator vars
  609. uint32 m_waypointID;
  610. uint32 m_path_id;
  611. //Formation var
  612. CreatureGroup *m_formation;
  613. bool TriggerJustRespawned;
  614. };
  615. class AssistDelayEvent : public BasicEvent
  616. {
  617. public:
  618. AssistDelayEvent(const uint64& victim, Unit& owner) : BasicEvent(), m_victim(victim), m_owner(owner) {}
  619. bool Execute(uint64 e_time, uint32 p_time);
  620. void AddAssistant(const uint64& guid) { m_assistants.push_back(guid); }
  621. private:
  622. AssistDelayEvent();
  623. uint64 m_victim;
  624. std::list<uint64> m_assistants;
  625. Unit& m_owner;
  626. };
  627. class ForcedDespawnDelayEvent : public BasicEvent
  628. {
  629. public:
  630. ForcedDespawnDelayEvent(Creature& owner) : BasicEvent(), m_owner(owner) {}
  631. bool Execute(uint64 e_time, uint32 p_time);
  632. private:
  633. Creature& m_owner;
  634. };
  635. #endif