NPC.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __EQ2_NPC__
  17. #define __EQ2_NPC__
  18. #include <atomic>
  19. #include "Entity.h"
  20. #include "MutexMap.h"
  21. #define AI_STRATEGY_BALANCED 1
  22. #define AI_STRATEGY_OFFENSIVE 2
  23. #define AI_STRATEGY_DEFENSIVE 3
  24. // Randomize Appearances
  25. #define RANDOMIZE_GENDER 1
  26. #define RANDOMIZE_RACE 2
  27. #define RANDOMIZE_MODEL_TYPE 4
  28. // Randomize appearance id (spawn_npcs table values)
  29. #define RANDOMIZE_FACIAL_HAIR_TYPE 8 // was RANDOMIZE_FACIAL_HAIR
  30. #define RANDOMIZE_HAIR_TYPE 16 // was RANDOMIZE_HAIR
  31. //#define RANDOMIZE_LEGS_TYPE 32 // spare!
  32. #define RANDOMIZE_WING_TYPE 64
  33. // Randomize parameters (npc_appearances, sInt values)
  34. #define RANDOMIZE_CHEEK_TYPE 128
  35. #define RANDOMIZE_CHIN_TYPE 256
  36. #define RANDOMIZE_EAR_TYPE 512
  37. #define RANDOMIZE_EYE_BROW_TYPE 1024
  38. #define RANDOMIZE_EYE_TYPE 2048
  39. #define RANDOMIZE_LIP_TYPE 4096
  40. #define RANDOMIZE_NOSE_TYPE 8192
  41. // Randomize colors/hues (npc_appearances, RGB values)
  42. #define RANDOMIZE_EYE_COLOR 16384
  43. #define RANDOMIZE_HAIR_COLOR1 32768
  44. #define RANDOMIZE_HAIR_COLOR2 65536
  45. #define RANDOMIZE_HAIR_HIGHLIGHT 131072
  46. #define RANDOMIZE_HAIR_FACE_COLOR 262144 // was RANDOMIZE_FACIAL_HAIR_COLOR
  47. #define RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR 524288
  48. #define RANDOMIZE_HAIR_TYPE_COLOR 1048576 // was RANDOMIZE_HAIR_COLOR
  49. #define RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR 2097152
  50. #define RANDOMIZE_SKIN_COLOR 4194304
  51. #define RANDOMIZE_WING_COLOR1 8388608
  52. #define RANDOMIZE_WING_COLOR2 16777216
  53. // All Flags On: 33554431
  54. #define PET_TYPE_COMBAT 1
  55. #define PET_TYPE_CHARMED 2
  56. #define PET_TYPE_DEITY 3
  57. #define PET_TYPE_COSMETIC 4
  58. #define PET_TYPE_DUMBFIRE 5
  59. enum CAST_TYPE {
  60. CAST_ON_SPAWN=0,
  61. CAST_ON_AGGRO=1,
  62. MAX_CAST_TYPES=2
  63. };
  64. class Brain;
  65. class NPCSpell {
  66. public:
  67. NPCSpell() {
  68. }
  69. NPCSpell(NPCSpell* inherit) {
  70. list_id = inherit->list_id;
  71. spell_id = inherit->spell_id;
  72. tier = inherit->tier;
  73. cast_on_spawn = inherit->cast_on_spawn;
  74. cast_on_initial_aggro = inherit->cast_on_initial_aggro;
  75. }
  76. int32 list_id;
  77. int32 spell_id;
  78. int8 tier;
  79. bool cast_on_spawn;
  80. bool cast_on_initial_aggro;
  81. };
  82. class NPC : public Entity {
  83. public:
  84. NPC();
  85. NPC(NPC* old_npc);
  86. virtual ~NPC();
  87. void Initialize();
  88. EQ2Packet* serialize(Player* player, int16 version);
  89. void SetAppearanceID(int32 id){ appearance_id = id; }
  90. int32 GetAppearanceID(){ return appearance_id; }
  91. bool IsNPC(){ return true; }
  92. void StartRunback(bool reset_hp_on_runback = false);
  93. void InCombat(bool val);
  94. bool HandleUse(Client* client, string type);
  95. void SetRandomize(int32 value) {appearance.randomize = value;}
  96. void AddRandomize(sint32 value) {appearance.randomize += value;}
  97. int32 GetRandomize() {return appearance.randomize;}
  98. bool CheckSameAppearance(string name, int16 id);
  99. void Randomize(NPC* npc, int32 flags);
  100. Skill* GetSkillByName(const char* name, bool check_update = false);
  101. Skill* GetSkillByID(int32 id, bool check_update = false);
  102. int8 GetAttackType();
  103. void SetAIStrategy(int8 strategy);
  104. int8 GetAIStrategy();
  105. void SetPrimarySpellList(int32 id);
  106. int32 GetPrimarySpellList();
  107. void SetSecondarySpellList(int32 id);
  108. int32 GetSecondarySpellList();
  109. void SetPrimarySkillList(int32 id);
  110. int32 GetPrimarySkillList();
  111. void SetSecondarySkillList(int32 id);
  112. int32 GetSecondarySkillList();
  113. void SetEquipmentListID(int32 id);
  114. int32 GetEquipmentListID();
  115. Spell* GetNextSpell(Spawn* target, float distance);
  116. virtual Spell* GetNextBuffSpell(Spawn* target = 0);
  117. void SetAggroRadius(float radius, bool overrideBaseValue = false);
  118. float GetAggroRadius();
  119. float GetBaseAggroRadius() { return base_aggro_radius; }
  120. void SetCastPercentage(int8 percentage);
  121. int8 GetCastPercentage();
  122. void SetSkills(map<string, Skill*>* in_skills);
  123. void SetSpells(vector<NPCSpell*>* in_spells);
  124. void SetRunbackLocation(float x, float y, float z, int32 gridid, bool set_hp_runback = false);
  125. MovementLocation* GetRunbackLocation();
  126. float GetRunbackDistance();
  127. void Runback(float distance=0.0f, bool stopFollowing = true);
  128. void ClearRunback();
  129. virtual bool PauseMovement(int32 period_of_time_ms);
  130. virtual bool IsPauseMovementTimerActive();
  131. void AddSkillBonus(int32 spell_id, int32 skill_id, float value);
  132. virtual void RemoveSkillBonus(int32 spell_id);
  133. virtual void SetZone(ZoneServer* zone, int32 version=0);
  134. void SetMaxPetLevel(int8 val) { m_petMaxLevel = val; }
  135. int8 GetMaxPetLevel() { return m_petMaxLevel; }
  136. void ProcessCombat();
  137. /// <summary>Sets the brain this NPC should use</summary>
  138. /// <param name="brain">The brain this npc should use</param>
  139. void SetBrain(Brain* brain);
  140. /// <summary>Gets the current brain this NPC uses</summary>
  141. /// <returns>The Brain this NPC uses</returns>
  142. ::Brain* Brain() { return m_brain; }
  143. bool m_runningBack;
  144. sint16 m_runbackHeadingDir1;
  145. sint16 m_runbackHeadingDir2;
  146. int32 GetShardID() { return m_ShardID; }
  147. void SetShardID(int32 shardid) { m_ShardID = shardid; }
  148. int32 GetShardCharID() { return m_ShardCharID; }
  149. void SetShardCharID(int32 charid) { m_ShardCharID = charid; }
  150. sint64 GetShardCreatedTimestamp() { return m_ShardCreatedTimestamp; }
  151. void SetShardCreatedTimestamp(sint64 timestamp) { m_ShardCreatedTimestamp = timestamp; }
  152. bool HasSpells() { return has_spells; }
  153. std::atomic<bool> m_call_runback;
  154. std::atomic<bool> cast_on_aggro_completed;
  155. private:
  156. MovementLocation* runback;
  157. int8 cast_percentage;
  158. float aggro_radius;
  159. float base_aggro_radius;
  160. Spell* GetNextSpell(float distance, int8 type);
  161. map<string, Skill*>* skills;
  162. vector<NPCSpell*>* spells;
  163. vector<NPCSpell*> cast_on_spells[CAST_TYPE::MAX_CAST_TYPES];
  164. int32 primary_spell_list;
  165. int32 secondary_spell_list;
  166. int32 primary_skill_list;
  167. int32 secondary_skill_list;
  168. int32 equipment_list_id;
  169. int8 attack_type;
  170. int8 ai_strategy;
  171. int32 appearance_id;
  172. int32 npc_id;
  173. MutexMap<int32, SkillBonus*> skill_bonus_list;
  174. int8 m_petMaxLevel;
  175. // Because I named the get function Brain() as well we need to use '::' to specify we are refering to
  176. // the brain class and not the function defined above
  177. ::Brain* m_brain;
  178. Mutex MBrain;
  179. int32 m_ShardID;
  180. int32 m_ShardCharID;
  181. sint64 m_ShardCreatedTimestamp;
  182. bool has_spells;
  183. };
  184. #endif