9
3

SpellProcess.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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_SPELL_PROCESS__
  17. #define __EQ2_SPELL_PROCESS__
  18. #include "client.h"
  19. #include "Spells.h"
  20. #include "zoneserver.h"
  21. #include "LuaInterface.h"
  22. #include "MutexMap.h"
  23. #include "MutexList.h"
  24. #include "World.h"
  25. #include "HeroicOp/HeroicOp.h"
  26. #define MODIFY_HEALTH 1
  27. #define MODIFY_FOCUS 2
  28. #define MODIFY_DEFENSE 3
  29. #define MODIFY_POWER 4
  30. #define MODIFY_SPEED 5
  31. #define MODIFY_INT 6
  32. #define MODIFY_WIS 7
  33. #define MODIFY_STR 8
  34. #define MODIFY_AGI 9
  35. #define MODIFY_STA 10
  36. #define MODIFY_COLD_RESIST 11
  37. #define MODIFY_HEAT_RESIST 12
  38. #define MODIFY_DISEASE_RESIST 13
  39. #define MODIFY_POISON_RESIST 14
  40. #define MODIFY_MAGIC_RESIST 15
  41. #define MODIFY_MENTAL_RESIST 16
  42. #define MODIFY_DIVINE_RESIST 17
  43. #define MODIFY_ATTACK 18
  44. #define MODIFY_MITIGATION 19
  45. #define MODIFY_AVOIDANCE 20
  46. #define MODIFY_CONCENTRATION 21
  47. #define MODIFY_EXP 22
  48. #define MODIFY_FACTION 23
  49. #define CHANGE_SIZE 24
  50. #define CHANGE_RACE 25
  51. #define CHANGE_LOCATION 26
  52. #define CHANGE_ZONE 27
  53. #define CHANGE_PREFIX_TITLE 28
  54. #define CHANGE_DEITY 29
  55. #define CHANGE_LAST_NAME 30
  56. #define MODIFY_HASTE 31
  57. #define MODIFY_SKILL 32
  58. #define CHANGE_TARGET 33
  59. #define CHANGE_LEVEL 34
  60. #define MODIFY_SPELL_CAST_TIME 35
  61. #define MODIFY_SPELL_POWER_REQ 36
  62. #define MODIFY_SPELL_HEALTH_REQ 37
  63. #define MODIFY_SPELL_RECOVERY 38
  64. #define MODIFY_SPELL_RECAST_TIME 39
  65. #define MODIFY_SPELL_RADIUS 40
  66. #define MODIFY_SPELL_AOE_TARGETS 41
  67. #define MODIFY_SPELL_RANGE 42
  68. #define MODIFY_SPELL_DURATION 43
  69. #define MODIFY_SPELL_RESISTIBILITY 44
  70. #define MODIFY_DAMAGE 45
  71. #define MODIFY_DELAY 46
  72. #define MODIFY_TRADESKILL_EXP 47
  73. #define ADD_MOUNT 48
  74. #define REMOVE_MOUNT 49
  75. #define MODIFY_SPELL_CRIT_CHANCE 50
  76. #define MODIFY_CRIT_CHANCE 51
  77. #define SUMMON_ITEM 52
  78. #define MODIFY_JUMP 53
  79. #define MODIFY_FALL_SPEED 54
  80. #define INFLICT_DAMAGE 55
  81. #define ADD_DOT 56
  82. #define REMOVE_DOT 57
  83. #define HEAL_TARGET 58
  84. #define HEAL_AOE 59
  85. #define INFLICT_AOE_DAMAGE 60
  86. #define HEAL_GROUP_AOE 61
  87. #define ADD_AOE_DOT 62
  88. #define REMOVE_AOE_DOT 63
  89. #define ADD_HOT 64
  90. #define REMOVE_HOT 65
  91. #define MODIFY_AGGRO_RANGE 66
  92. #define BLIND_TARGET 67
  93. #define UNBLIND_TARGET 68
  94. #define KILL_TARGET 69
  95. #define RESURRECT_TARGET 70
  96. #define CHANGE_SUFFIX_TITLE 71
  97. #define SUMMON_PET 72
  98. #define MODIFY_HATE 73
  99. #define ADD_REACTIVE_HEAL 74
  100. #define MODIFY_POWER_REGEN 75
  101. #define MODIFY_HP_REGEN 76
  102. #define FEIGN_DEATH 77
  103. #define MODIFY_VISION 78
  104. #define INVISIBILITY 79
  105. #define CHARM_TARGET 80
  106. #define MODIFY_TRADESKILL_DURABILITY 81
  107. #define MODIFY_TRADESKILL_PROGRESS 82
  108. #define ACTIVE_SPELL_NORMAL 0
  109. #define ACTIVE_SPELL_ADD 1
  110. #define ACTIVE_SPELL_REMOVE 2
  111. #define GET_VALUE_BAD_VALUE 0xFFFFFFFF
  112. struct InterruptStruct{
  113. Spawn* interrupted;
  114. Spawn* target;
  115. LuaSpell* spell;
  116. int16 error_code;
  117. };
  118. struct CastTimer{
  119. Client* caster;
  120. EntityCommand* entity_command;
  121. LuaSpell* spell;
  122. Timer* timer;
  123. ZoneServer* zone;
  124. bool delete_timer;
  125. };
  126. struct CastSpell{
  127. Entity* caster;
  128. Spawn* target;
  129. int32 spell_id;
  130. ZoneServer* zone;
  131. };
  132. struct RecastTimer{
  133. Entity* caster;
  134. Client* client;
  135. Spell* spell;
  136. Timer* timer;
  137. };
  138. /// <summary> Handles all spell casts for a zone, only 1 SpellProcess per zone </summary>
  139. class SpellProcess{
  140. public:
  141. SpellProcess();
  142. ~SpellProcess();
  143. /// <summary>Remove all spells from the SpellProcess </summary>
  144. void RemoveAllSpells();
  145. /// <summary>Main loop, handles everything (interupts, cast time, recast, ...) </summary>
  146. void Process();
  147. /// <summary>Interrupts the caster (creates the InterruptStruct and adds it to a list)</summary>
  148. /// <param name='caster'>Entity being interrupted</param>
  149. /// <param name='interruptor'>Spawn that interrupted the caster</param>
  150. /// <param name='error_code'>The error code</param>
  151. /// <param name='cancel'>Bool if the spell was cancelled not interrupted</param>
  152. void Interrupted(Entity* caster, Spawn* interruptor, int16 error_code, bool cancel = false, bool from_movement = false);
  153. /// <summary>Does all the checks and actually casts the spell</summary>
  154. /// <param name='zone'>The current ZoneServer</param>
  155. /// <param name='spell'>The Spell to cast</param>
  156. /// <param name='caster'>The Entity casting the spell</param>
  157. /// <param name='target'>The target(Spawn) of the spell</param>
  158. /// <param name='lock'>??? not currently used</param>
  159. /// <param name='harvest_spell'>Is this a harvest spell?</param>
  160. void ProcessSpell(ZoneServer* zone, Spell* spell, Entity* caster, Spawn* target = 0, bool lock = true, bool harvest_spell = false);
  161. /// <summary>Cast an EntityCommand (right click menu)</summary>
  162. /// <param name='zone'>The current ZoneServer</param>
  163. /// <param name='entity_command'>the EntityCommand to cast</param>
  164. /// <param name='caster'>The Entity casting the EntityCommand</param>
  165. /// <param name='target'>The target(Spawn*) of the EntityCommand</param>
  166. /// <param name='lock'>??? not currently used</param>
  167. void ProcessEntityCommand(ZoneServer* zone, EntityCommand* entity_command, Entity* caster, Spawn* target, bool lock = true);
  168. /// <summary>Checks to see if the caster has enough power and takes it</summary>
  169. /// <param name='spell'>LuaSpell to check and take power for (LuaSpell contains the caster)</param>
  170. /// <returns>True if caster had enough power</returns>
  171. bool TakePower(LuaSpell* spell);
  172. /// <summary>Check to see if the caster has enough power to cast the spell</summary>
  173. /// <param name='spell'>LuaSpell to check (LuaSpell contains the caster)</param>
  174. /// <returns>True if the caster has enough power</returns>
  175. bool CheckPower(LuaSpell* spell);
  176. /// <summary>Check to see if the caster has enough hp and take it</summary>
  177. /// <param name='spell'>LuaSpell to check and take hp for (LuaSpell contains the caster)</param>
  178. /// <returns>True if the caster had enough hp</returns>
  179. bool TakeHP(LuaSpell* spell);
  180. /// <summary>Check to see if the caster has enough hp to cast the spell</summary>
  181. /// <param name='spell'>LuaSpell to check (LuaSpell contains the caster)</param>
  182. /// <returns>True if the caster had enough hp</returns>
  183. bool CheckHP(LuaSpell* spell);
  184. /// <summary>Check to see if the caster has enough concentration available to cast the spell</summary>
  185. /// <param name='spell'>LuaSpell to check (LuaSpell contains the caster)</param>
  186. /// <returns>True if the caster has enough concentration</returns>
  187. bool CheckConcentration(LuaSpell* spell);
  188. bool CheckSavagery(LuaSpell* spell);
  189. bool TakeSavagery(LuaSpell* spell);
  190. bool CheckDissonance(LuaSpell* spell);
  191. bool AddDissonance(LuaSpell* spell);
  192. /// <summary>Check to see if the caster has enough concentration available and add to the casters concentration</summary>
  193. /// <param name='spell'>LuaSpell to check (LuaSpell contains the caster)</param>
  194. /// <returns>True of the caster had enough concentration</returns>
  195. bool AddConcentration(LuaSpell* spell);
  196. /// <summary>Cast the spell, calls ProcessSpell for the given LuaSpell, as well as sends the messages for the spells and calls the casted on function in the targets spawn script</summary>
  197. /// <param name='spell'>LuaSpell to cast</param>
  198. /// <param name='passive'>Is this a passive spell being cast?</param>
  199. /// <returns>True if the spell was casted</returns>
  200. bool CastProcessedSpell(LuaSpell* spell, bool passive = false);
  201. /// <summary>Cast the EntityCommand, calls ProcessEntityCommand for the given EntityCommand, as well as sends the messages for the command and calls the casted on function in the targets spawn script</summary>
  202. /// <param name='entity_command'>EntityCommand to cast</param>
  203. /// <param name='client'>Client casting the entity command</param>
  204. /// <returns>True if the spell was casted</returns>
  205. bool CastProcessedEntityCommand(EntityCommand* entity_command, Client* client);
  206. /// <summary>Sends the start cast packet for the given client</summary>
  207. /// <param name='spell'>LuaSpell being cast</param>
  208. /// <param name='client'>The client casting the spell</param>
  209. void SendStartCast(LuaSpell* spell, Client* client);
  210. /// <summary>Send finish cast packet and take power/hp or add conc, also checks for quest updates</summary>
  211. /// <param name='spell'>LuaSpell that just finished casting</param>
  212. /// <param name='client'>Client that just finished casting, null if not a player</param>
  213. void SendFinishedCast(LuaSpell* spell, Client* client);
  214. /// <summary>Locks all the spells for the given client (shades them all gray)</summary>
  215. /// <param name='client'>Client to lock the spells for</param>
  216. void LockAllSpells(Client* client);
  217. /// <summary>Unlock all the spells for the given client</summary>
  218. /// <param name='client'>Client to unlock the spells for</param>
  219. void UnlockAllSpells(Client* client);
  220. /// <summary>Unlock a single spell for the given client</summary>
  221. /// <param name='client'>The client to unlock the spell for</param>
  222. /// <param name='spell'>The spell to unlock</param>
  223. void UnlockSpell(Client* client, Spell* spell);
  224. /// <summary>Remove the given spell for the given caster from the SpellProcess</summary>
  225. /// <param name='caster'>The spawn to remove the spell for</param>
  226. /// <param name='spell'>The spell to remove</param>
  227. bool DeleteCasterSpell(Spawn* caster, Spell* spell);
  228. /// <summary>Remove the given spell from the ZpellProcess</summary>
  229. /// <param name='spell'>LuaSpell to remove</param>
  230. bool DeleteCasterSpell(LuaSpell* spell);
  231. /// <summary>Interrupt the spell</summary>
  232. /// <param name='interrupt'>InterruptStruct that contains all the info</param>
  233. void CheckInterrupt(InterruptStruct* interrupt);
  234. /// <summary>Removes the timers for the given spawn</summary>
  235. /// <param name='spawn'>Spawn to remove the timers for</param>
  236. /// <param name='remove_all'>Remove all timers (cast, recast, active, queue, interrupted)? If false only cast timers are removed</param>
  237. void RemoveSpellTimersFromSpawn(Spawn* spawn, bool remove_all = false, bool delete_recast = true);
  238. /// <summary>Sets the recast timer for the spell </summary>
  239. /// <param name='spell'>The spell to set the recast for</param>
  240. /// <param name='caster'>The entity to set the recast for</param>
  241. /// <param name='timer_override'>Change the recast timer of the spell</param>
  242. /// <param name='check_linked_timers'>Set the recast on all other spells the player has with the same timer</param>
  243. void CheckRecast(Spell* spell, Entity* caster, float timer_override = 0, bool check_linked_timers = true);
  244. /// <summary>Add a spell to the queue for the player</summary>
  245. /// <param name='spell'>Spell to add</param>
  246. /// <param name='caster'>Entity's queue to add the spell to, if not a player function does nothing</param>
  247. void AddSpellToQueue(Spell* spell, Entity* caster);
  248. /// <summary>Removes a spell from the queue for the player</summary>
  249. /// <param name='spell'>Spell to remove from the queue</param>
  250. /// <param name='caster'>Entity's queue to remove the spell from, if not a player function does nothing</param>
  251. void RemoveSpellFromQueue(Spell* spell, Entity* caster);
  252. /// <summary>Clear the queue, or clear only hostile spells from the queue</summary>
  253. /// <param name='caster'>Entity to clear the queue for, if not player function does nothing</param>
  254. /// <param name='hostile_only'>Set to true to only remove hostile spells, default is false</param>
  255. void RemoveSpellFromQueue(Entity* caster, bool hostile_only = false);
  256. /// <summary>Clear the queue for the given caster</summary>
  257. /// <param name='caster'>Entity to clear the queue for, is not player function does nothing</param>
  258. void CheckSpellQueue(Entity* caster);
  259. /// <summary>Check the given enities queue for the spell, if found remove, if not found add</summary>
  260. /// <param name='spell'>Spell to check for</param>
  261. /// <param name='caster'>Entity's queue to check, if not player function does nothing</param>
  262. void CheckSpellQueue(Spell* spell, Entity* caster);
  263. /// <summary>Checks to see if the entity can cast the spell </summary>
  264. /// <param name='spell'>The spell being cast</param>
  265. /// <param name='caster'>The entity casting the spell </param>
  266. bool IsReady(Spell* spell, Entity* caster);
  267. /// <summary>Send the spell book update packet to the given client</summary>
  268. /// <param name='client'>Client to send the packet to</param>
  269. void SendSpellBookUpdate(Client* client);
  270. /// <summary>Gets the target of the currently casting spell for the given entity</summary>
  271. /// <param name='caster'>Entity whos spell we are checking</param>
  272. /// <returns>Spawn* - the spells target</returns>
  273. Spawn* GetSpellTarget(Entity* caster);
  274. /// <summary>Gets the currently casting spell for the given entity</summary>
  275. /// <param name='caster'>Entity to get the spell for</param>
  276. /// <returns>Spell* for the currently casting spell</returns>
  277. Spell* GetSpell(Entity* caster);
  278. /// <summary>Gets the currently casting LuaSpell for the given entity</summary>
  279. /// <param name='caster'>Entity to get the LuaSpell for</param>
  280. /// <returns>LuaSpell* for the currently casting spell</returns>
  281. LuaSpell* GetLuaSpell(Entity* caster);
  282. /// <summary>Gets the targets for the spell and adds them to the LuaSpell targets array</summary>
  283. /// <param name='luaspell'>LuaSpell to get the targets for</param>
  284. static void GetSpellTargets(LuaSpell* luaspell);
  285. /// <summary>Gets targets for a true aoe spell (not an encounter ae) and adds them to the LuaSpell targets array</summary>
  286. /// <param name='luaspell'>LuaSpell to get the targets for</param>
  287. static void GetSpellTargetsTrueAOE(LuaSpell* luaspell);
  288. /// <summary>Applies or removes passive spells, bypasses the spell queue and treats the spell as an insta cast spell</summary>
  289. /// <param name='spell'>The passive spell to apply or remove</param>
  290. /// <param name='caster'>The Entity to apply or remove the passive spell to</param>
  291. /// <param name='remove'>Tells the function to remove the spell effects of this passive, default is false</param>
  292. bool CastPassives(Spell* spell, Entity* caster, bool remove = false);
  293. /// <summary>Adds a spell script timer to the list</summary>
  294. /// <param name='timer'>Timer to add</param>
  295. void AddSpellScriptTimer(SpellScriptTimer* timer);
  296. /// <summary>Removes a spell script timer from the list</summary>
  297. /// <param name='timer'>Timer to remove</param>
  298. void RemoveSpellScriptTimer(SpellScriptTimer* timer);
  299. /// <summary>Checks the spell script timers</summary>
  300. void CheckSpellScriptTimers();
  301. /// <summary>Checks to see if the list has the spell</summary>
  302. bool SpellScriptTimersHasSpell(LuaSpell* spell);
  303. void ClearSpellScriptTimerList();
  304. MutexList<LuaSpell*>* GetActiveSpells() { return &active_spells; }
  305. void RemoveTargetFromSpell(LuaSpell* spell, Spawn* target);
  306. void CheckRemoveTargetFromSpell(LuaSpell* spell, bool allow_delete = true);
  307. /// <summary>Adds a solo HO to the SpellProcess</summary>
  308. /// <param name='client'>The client who is starting the HO</param>
  309. /// <param name='ho'>The HO that is being started</param>
  310. bool AddHO(Client* client, HeroicOP* ho);
  311. /// <summary>Adds a group HO to the SpellProcess</summary>
  312. /// <param name='group_id'>ID of the group that is starting the HO</param>
  313. /// <param name='ho'>The HO that is being started</param>
  314. bool AddHO(int32 group_id, HeroicOP* ho);
  315. /// <summary>Stops the HO that targets the given spawn</summary>
  316. /// <param name='spawn_id'>ID of the spawn targeted by the HO we want to stop</param>
  317. void KillHOBySpawnID(int32 spawn_id);
  318. void AddSpellCancel(LuaSpell* spell);
  319. private:
  320. /// <summary>Sends the spell data to the lua script</summary>
  321. /// <param name='spell'>LuaSpell to call the lua script for</param>
  322. /// <param name='first_cast'>No clue, not currently used</param>
  323. /// <returns>True if the spell script was called successfully</returns>
  324. bool ProcessSpell(LuaSpell* spell, bool first_cast = true, const char* function = 0, SpellScriptTimer* timer = 0);
  325. Mutex MSpellProcess;
  326. MutexMap<Entity*,Spell*> spell_que;
  327. MutexList<LuaSpell*> active_spells;
  328. MutexList<CastTimer*> cast_timers;
  329. MutexList<InterruptStruct*>interrupt_list;
  330. MutexList<RecastTimer*> recast_timers;
  331. int32 last_checked_time;
  332. vector<SpellScriptTimer*> m_spellScriptList;
  333. Mutex MSpellScriptTimers;
  334. map<LuaSpell*, vector<Spawn*>*> remove_target_list;
  335. Mutex MRemoveTargetList;
  336. vector<LuaSpell*> SpellCancelList;
  337. Mutex MSpellCancelList;
  338. Mutex MSoloHO;
  339. Mutex MGroupHO;
  340. map<Client*, HeroicOP*> m_soloHO;
  341. map<int32, HeroicOP*> m_groupHO;
  342. };
  343. #endif