9
3

NPC_AI.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 __NPC_AI_H__
  17. #define __NPC_AI_H__
  18. #include "NPC.h"
  19. #include <vector>
  20. #include <map>
  21. using namespace std;
  22. class Brain {
  23. public:
  24. Brain(NPC* npc);
  25. virtual ~Brain();
  26. /// <summary>The main loop for the brain. This will do all the AI work</summary>
  27. virtual void Think();
  28. /* Timer related functions */
  29. /// <summary>Gets the time between calls to Think()</summary>
  30. /// <returns>Time in miliseconds between calls to Think()</returns>
  31. int16 Tick() { return m_tick; }
  32. /// <summary>Sets the time between calls to Think()</summary>
  33. /// <param name="time">Time in miliseconds</param>
  34. void SetTick(int16 time) { m_tick = time; }
  35. /// <summary>Gets the timestamp of the last call to Think()</summary>
  36. /// <returns>Timestamp of the last call to Think()</returns>
  37. int32 LastTick() { return m_lastTick; }
  38. /// <summary>Sets the last tick to the given time</summary>
  39. /// <param name="time">The time to set the last tick to</param>
  40. void SetLastTick(int32 time) { m_lastTick = time; }
  41. /* Hate related functions */
  42. /// <summary>Gets the amount of hate this npc has towards the given entity</summary>
  43. /// <param name="entity">The entity to check</param>
  44. /// <returns>The amount of hate towards the given entity</returns>
  45. sint32 GetHate(Entity* entity);
  46. /// <summary>Add hate for the given entity to this NPC</summary>
  47. /// <param name="entity">The entity we are adding to this NPC's hate list</param>
  48. /// <param name="hate">The amount of hate to add</param>
  49. virtual void AddHate(Entity* entity, sint32 hate);
  50. /// <summary>Completely clears the hate list for this npc</summary>
  51. void ClearHate();
  52. /// <summary>Removes the given entity from this NPC's hate list</summary>
  53. /// <param name="entity">Entity to remove from this NPC's hate list</param>
  54. void ClearHate(Entity* entity);
  55. /// <summary>Get the entity this NPC hates the most</summary>
  56. /// <returns>The entity this NPC hates the most</returns>
  57. Entity* GetMostHated();
  58. /// <summary>Gets a percentage of hate owned by the given entity</summary>
  59. /// <param name="entity">Entity to get the percentage for</param>
  60. /// <returns>Percentage of hate as a sint8</returns>
  61. sint8 GetHatePercentage(Entity* entity);
  62. ///<summary>Gets a list of all the entities in the hate list</summary>
  63. vector<Entity*>* GetHateList();
  64. /* Combat related functions */
  65. /// <summary></summary>
  66. /// <param name=""></param>
  67. /// <param name=""></param>
  68. virtual bool ProcessSpell(Entity* target, float distance);
  69. /// <summary></summary>
  70. /// <returns>True if a buff starts casting</returns>
  71. bool CheckBuffs();
  72. /// <summary>Has the NPC make a melee attack</summary>
  73. /// <param name="target">The target to attack</param>
  74. /// <param name="distance">The current distance from the target</param>
  75. void ProcessMelee(Entity* target, float distance);
  76. /* Encounter related functions */
  77. /// <summary>Adds the given entity and its group and raid members to the encounter list</summary>
  78. /// <param name="entity">Entity we are adding to the encounter list</param>
  79. void AddToEncounter(Entity* entity);
  80. /// <summary>Checks to see if the given entity can loot the corpse</summary>
  81. /// <param name="entity">Entity trying to loot</param>
  82. /// <returns>True if the entity can loot</returns>
  83. bool CheckLootAllowed(Entity* entity);
  84. /// <summary>Gets the size of the encounter list</summary>
  85. /// <returns>The size of the list as an int8</returns>
  86. int8 GetEncounterSize();
  87. /// <summary>Clears the encounter list</summary>
  88. void ClearEncounter();
  89. /// <summary>Gets a copy of the encounter list</summary>
  90. /// <returns>A copy of the encounter list as a vector<Entity*>*</returns>
  91. vector<int32>* GetEncounter();
  92. /// <summary>Checks to see if a player is in the encounter</summary>
  93. /// <returns>True if the encounter list contains a player</returns>
  94. bool PlayerInEncounter() { return m_playerInEncounter; }
  95. /* Helper functions*/
  96. /// <summary>Gets the NPC this brain controls</summary>
  97. /// <returns>The NPC this brain controls</returns>
  98. NPC* GetBody() { return m_body; }
  99. /// <summary>Checks to see if the NPC can cast</summary>
  100. /// <returns>True if the NPC can cast</returns>
  101. bool HasRecovered();
  102. /// <summary>Tells the NPC to move closer to the given target</summary>
  103. /// <param name="target">The target to move closer to</param>
  104. void MoveCloser(Entity* target);
  105. protected:
  106. // m_body = the npc this brain controls
  107. NPC* m_body;
  108. // m_spellRecovery = time stamp for when the npc can cast again
  109. int32 m_spellRecovery;
  110. private:
  111. // MHateList = mutex to lock and unlock the hate list
  112. Mutex MHateList;
  113. // m_hatelist = the list that stores all the hate,
  114. // entity is the entity this npc hates and the int32 is the value for how much we hate the entity
  115. map<int32, sint32> m_hatelist;
  116. // m_lastTick = the last time we ran this brain
  117. int32 m_lastTick;
  118. // m_tick = the amount of time between Think() calls in milliseconds
  119. int16 m_tick;
  120. // m_encounter = list of players (entities) that will get a reward (xp/loot) for killing this npc
  121. vector<int32> m_encounter;
  122. // MEncounter = mutex to lock and unlock the encounter list
  123. Mutex MEncounter;
  124. //m_playerInEncounter = true if a player is added to the encounter
  125. bool m_playerInEncounter;
  126. };
  127. // Extension of the default brain for combat pets
  128. class CombatPetBrain : public Brain {
  129. public:
  130. CombatPetBrain(NPC* body);
  131. virtual ~CombatPetBrain();
  132. void Think();
  133. };
  134. class NonCombatPetBrain : public Brain {
  135. public:
  136. NonCombatPetBrain(NPC* body);
  137. virtual ~NonCombatPetBrain();
  138. void Think();
  139. };
  140. class BlankBrain : public Brain {
  141. public:
  142. BlankBrain(NPC* body);
  143. virtual ~BlankBrain();
  144. void Think();
  145. };
  146. class LuaBrain : public Brain {
  147. public:
  148. LuaBrain(NPC* body);
  149. virtual ~LuaBrain();
  150. void Think();
  151. };
  152. class DumbFirePetBrain : public Brain {
  153. public:
  154. DumbFirePetBrain(NPC* body, Entity* target, int32 expire_time);
  155. virtual ~DumbFirePetBrain();
  156. void Think();
  157. void AddHate(Entity* entity, sint32 hate);
  158. private:
  159. int32 m_expireTime;
  160. };
  161. #endif