9
3

NPC.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. required_hp_ratio = inherit->required_hp_ratio;
  76. }
  77. int32 list_id;
  78. int32 spell_id;
  79. int8 tier;
  80. bool cast_on_spawn;
  81. bool cast_on_initial_aggro;
  82. sint8 required_hp_ratio;
  83. };
  84. class NPC : public Entity {
  85. public:
  86. NPC();
  87. NPC(NPC* old_npc);
  88. virtual ~NPC();
  89. void Initialize();
  90. EQ2Packet* serialize(Player* player, int16 version);
  91. void SetAppearanceID(int32 id){ appearance_id = id; }
  92. int32 GetAppearanceID(){ return appearance_id; }
  93. bool IsNPC(){ return true; }
  94. void StartRunback(bool reset_hp_on_runback = false);
  95. void InCombat(bool val);
  96. bool HandleUse(Client* client, string type);
  97. void SetRandomize(int32 value) {appearance.randomize = value;}
  98. void AddRandomize(sint32 value) {appearance.randomize += value;}
  99. int32 GetRandomize() {return appearance.randomize;}
  100. bool CheckSameAppearance(string name, int16 id);
  101. void Randomize(NPC* npc, int32 flags);
  102. Skill* GetSkillByName(const char* name, bool check_update = false);
  103. Skill* GetSkillByID(int32 id, bool check_update = false);
  104. int8 GetAttackType();
  105. void SetAIStrategy(int8 strategy);
  106. int8 GetAIStrategy();
  107. void SetPrimarySpellList(int32 id);
  108. int32 GetPrimarySpellList();
  109. void SetSecondarySpellList(int32 id);
  110. int32 GetSecondarySpellList();
  111. void SetPrimarySkillList(int32 id);
  112. int32 GetPrimarySkillList();
  113. void SetSecondarySkillList(int32 id);
  114. int32 GetSecondarySkillList();
  115. void SetEquipmentListID(int32 id);
  116. int32 GetEquipmentListID();
  117. Spell* GetNextSpell(Spawn* target, float distance);
  118. virtual Spell* GetNextBuffSpell(Spawn* target = 0);
  119. void SetAggroRadius(float radius, bool overrideBaseValue = false);
  120. float GetAggroRadius();
  121. float GetBaseAggroRadius() { return base_aggro_radius; }
  122. void SetCastPercentage(int8 percentage);
  123. int8 GetCastPercentage();
  124. void SetSkills(map<string, Skill*>* in_skills);
  125. void SetSpells(vector<NPCSpell*>* in_spells);
  126. void SetRunbackLocation(float x, float y, float z, int32 gridid, bool set_hp_runback = false);
  127. MovementLocation* GetRunbackLocation();
  128. float GetRunbackDistance();
  129. void Runback(float distance=0.0f, bool stopFollowing = true);
  130. void ClearRunback();
  131. virtual bool PauseMovement(int32 period_of_time_ms);
  132. virtual bool IsPauseMovementTimerActive();
  133. void AddSkillBonus(int32 spell_id, int32 skill_id, float value);
  134. virtual void RemoveSkillBonus(int32 spell_id);
  135. virtual void SetZone(ZoneServer* zone, int32 version=0);
  136. void SetMaxPetLevel(int8 val) { m_petMaxLevel = val; }
  137. int8 GetMaxPetLevel() { return m_petMaxLevel; }
  138. void ProcessCombat();
  139. /// <summary>Sets the brain this NPC should use</summary>
  140. /// <param name="brain">The brain this npc should use</param>
  141. void SetBrain(Brain* brain);
  142. /// <summary>Gets the current brain this NPC uses</summary>
  143. /// <returns>The Brain this NPC uses</returns>
  144. ::Brain* Brain() { return m_brain; }
  145. bool m_runningBack;
  146. sint16 m_runbackHeadingDir1;
  147. sint16 m_runbackHeadingDir2;
  148. int32 GetShardID() { return m_ShardID; }
  149. void SetShardID(int32 shardid) { m_ShardID = shardid; }
  150. int32 GetShardCharID() { return m_ShardCharID; }
  151. void SetShardCharID(int32 charid) { m_ShardCharID = charid; }
  152. sint64 GetShardCreatedTimestamp() { return m_ShardCreatedTimestamp; }
  153. void SetShardCreatedTimestamp(sint64 timestamp) { m_ShardCreatedTimestamp = timestamp; }
  154. bool HasSpells() { return has_spells; }
  155. std::atomic<bool> m_call_runback;
  156. std::atomic<bool> cast_on_aggro_completed;
  157. private:
  158. MovementLocation* runback;
  159. int8 cast_percentage;
  160. float aggro_radius;
  161. float base_aggro_radius;
  162. Spell* GetNextSpell(float distance, int8 type);
  163. map<string, Skill*>* skills;
  164. vector<NPCSpell*>* spells;
  165. vector<NPCSpell*> cast_on_spells[CAST_TYPE::MAX_CAST_TYPES];
  166. int32 primary_spell_list;
  167. int32 secondary_spell_list;
  168. int32 primary_skill_list;
  169. int32 secondary_skill_list;
  170. int32 equipment_list_id;
  171. int8 attack_type;
  172. int8 ai_strategy;
  173. int32 appearance_id;
  174. int32 npc_id;
  175. MutexMap<int32, SkillBonus*> skill_bonus_list;
  176. int8 m_petMaxLevel;
  177. // Because I named the get function Brain() as well we need to use '::' to specify we are refering to
  178. // the brain class and not the function defined above
  179. ::Brain* m_brain;
  180. Mutex MBrain;
  181. int32 m_ShardID;
  182. int32 m_ShardCharID;
  183. sint64 m_ShardCreatedTimestamp;
  184. bool has_spells;
  185. };
  186. #endif