Spells.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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_SPELLS__
  17. #define __EQ2_SPELLS__
  18. #include <map>
  19. #include <vector>
  20. #include <mutex>
  21. #include <shared_mutex>
  22. #include "../common/types.h"
  23. #include "../common/EQPacket.h"
  24. #include "../common/MiscFunctions.h"
  25. #include "client.h"
  26. #include "classes.h"
  27. #include "../common/Mutex.h"
  28. #include "AltAdvancement/AltAdvancement.h"
  29. #include "../LUA/lua.hpp"
  30. #define SPELL_TARGET_SELF 0
  31. #define SPELL_TARGET_ENEMY 1
  32. #define SPELL_TARGET_GROUP_AE 2
  33. #define SPELL_TARGET_CASTER_PET 3
  34. #define SPELL_TARGET_ENEMY_PET 4
  35. #define SPELL_TARGET_ENEMY_CORPSE 5
  36. #define SPELL_TARGET_GROUP_CORPSE 6
  37. #define SPELL_TARGET_NONE 7
  38. #define SPELL_TARGET_RAID_AE 8
  39. #define SPELL_TARGET_OTHER_GROUP_AE 9
  40. #define SPELL_BOOK_TYPE_SPELL 0
  41. #define SPELL_BOOK_TYPE_COMBAT_ART 1
  42. #define SPELL_BOOK_TYPE_ABILITY 2
  43. #define SPELL_BOOK_TYPE_TRADESKILL 3
  44. #define SPELL_BOOK_TYPE_NOT_SHOWN 4
  45. #define SPELL_CAST_TYPE_NORMAL 0
  46. #define SPELL_CAST_TYPE_TOGGLE 1
  47. #define SPELL_ERROR_NOT_ENOUGH_KNOWLEDGE 1
  48. #define SPELL_ERROR_INTERRUPTED 2
  49. #define SPELL_ERROR_TAKE_EFFECT_MOREPOWERFUL 3
  50. #define SPELL_ERROR_TAKE_EFFECT_SAMESPELL 4
  51. #define SPELL_ERROR_CANNOT_CAST_DEAD 5
  52. #define SPELL_ERROR_NOT_ALIVE 6
  53. #define SPELL_ERROR_NOT_DEAD 7
  54. #define SPELL_ERROR_CANNOT_CAST_SITTING 8
  55. #define SPELL_ERROR_CANNOT_CAST_UNCON 9
  56. #define SPELL_ERROR_ALREADY_CASTING 10
  57. #define SPELL_ERROR_RECOVERING 11
  58. #define SPELL_ERROR_NON_COMBAT_ONLY 12
  59. #define SPELL_ERROR_CANNOT_CAST_STUNNED 13
  60. #define SPELL_ERROR_CANNOT_CAST_STIFFLED 14
  61. #define SPELL_ERROR_CANNOT_CAST_CHARMED 15
  62. #define SPELL_ERROR_NOT_WHILE_MOUNTED 16
  63. #define SPELL_ERROR_NOT_WHILE_FLYING 17
  64. #define SPELL_ERROR_NOT_WHILE_CLIMBING 18
  65. #define SPELL_ERROR_NOT_READY 19
  66. #define SPELL_ERROR_CANT_SEE_TARGET 20
  67. #define SPELL_ERROR_INCORRECT_STANCE 21
  68. #define SPELL_ERROR_CANNOT_CAST_FEIGNDEATH 22
  69. #define SPELL_ERROR_INVENTORY_FULL 23
  70. #define SPELL_ERROR_NOT_ENOUGH_COIN 24
  71. #define SPELL_ERROR_NOT_ALLOWED_HERE 25
  72. #define SPELL_ERROR_NOT_WHILE_CRAFTING 26
  73. #define SPELL_ERROR_ONLY_WHEN_CRAFTING 27
  74. #define SPELL_ERROR_ITEM_NOT_ATTUNED 28
  75. #define SPELL_ERROR_ITEM_WORN_OUT 29
  76. #define SPELL_ERROR_MUST_EQUIP_WEAPON 30
  77. #define SPELL_ERROR_WEAPON_BROKEN 31
  78. #define SPELL_ERROR_CANNOT_CAST_FEARED 32
  79. #define SPELL_ERROR_TARGET_IMMUNE_HOSTILE 33
  80. #define SPELL_ERROR_TARGET_IMMUNE_BENEFICIAL 34
  81. #define SPELL_ERROR_NO_TAUNT_SPELLS 35
  82. #define SPELL_ERROR_CANNOT_USE_IN_BATTLEGROUNDS 36
  83. #define SPELL_ERROR_CANNOT_PREPARE 37
  84. #define SPELL_ERROR_NO_ELIGIBLE_TARGET 38
  85. #define SPELL_ERROR_NO_TARGETS_IN_RANGE 39
  86. #define SPELL_ERROR_TOO_CLOSE 40
  87. #define SPELL_ERROR_TOO_FAR_AWAY 41
  88. #define SPELL_ERROR_TARGET_TOO_WEAK 42
  89. #define SPELL_ERROR_TARGET_TOO_POWERFUL 43
  90. #define SPELL_ERROR_WONT_WORK_ON_TARGET 44
  91. #define SPELL_ERROR_TARGET_INVULNERABLE 45
  92. #define SPELL_ERROR_TARGET_IMMUNE 46
  93. #define SPELL_ERROR_TARGET_ENGAGED 47
  94. #define SPELL_ERROR_TARGET_NOT_GROUPED 48
  95. #define SPELL_ERROR_TARGET_IN_USE 49
  96. #define SPELL_ERROR_TARGET_GROUP_HAS_SPELL 50
  97. #define SPELL_ERROR_TARGET_ALREADY_ENGAGED 51
  98. #define SPELL_ERROR_CANNOT_ENGAGE 52
  99. #define SPELL_ERROR_NOT_A_FRIEND 53
  100. #define SPELL_ERROR_NOT_AN_ENEMY 54
  101. #define SPELL_ERROR_TARGET_INVENTORY_FULL 55
  102. #define SPELL_ERROR_FINISH_DUELING_FIRST 56
  103. #define SPELL_ERROR_ILLEGAL_TARGET_ATTACK 57
  104. #define SPELL_ERROR_NOT_WHILE_MENTORING_PVP 58
  105. #define SPELL_ERROR_NOT_WHILE_MENTORING_BENEFICIAL 59
  106. #define SPELL_ERROR_ILLEGAL_TARGET_HEAL_OUTSIDE_LEVEL_RANGE 60
  107. #define SPELL_ERROR_NOTHING_TO_CURE 61
  108. #define SPELL_ERROR_NOT_ENOUGH_POWER 62
  109. #define SPELL_ERROR_NOT_ENOUGH_HEALTH 63
  110. #define SPELL_ERROR_NOT_ENOUGH_CONC 64
  111. #define SPELL_ERROR_MISSING_COMPONENT 65
  112. #define SPELL_ERROR_OUT_OF_CHARGES 66
  113. #define SPELL_ERROR_LACK_AMMO 67
  114. #define SPELL_ERROR_NO_RANGED_EQUIPPED 68
  115. #define SPELL_ERROR_RANGED_NEEDS_REPAIR 69
  116. #define SPELL_ERROR_LACK_WEAPON_TYPE 70
  117. #define SPELL_ERROR_NOT_ENOUGH_SAVAGERY 71
  118. #define SPELL_ERROR_ALREADY_PREPARED 72
  119. #define SPELL_ERROR_ALREADY_HAVE_SPELL 73
  120. #define SPELL_ERROR_NOT_SMART_ENOUGH 74 // "You lack the intellectual capacity to prepare another spell."
  121. #define SPELL_ERROR_NO_HOSTILE_SPELLS 75
  122. #define SPELL_ERROR_NO_BENEFICIAL_SPELLS 76
  123. #define SPELL_ERROR_CANNOT_MOUNT_NOW_SITTING 77
  124. #define SPELL_ERROR_CANNOT_MOUNT_NOW_DEAD 78
  125. #define SPELL_ERROR_CANNOT_MOUNT_NOW_CLIMBING 79
  126. #define SPELL_ERROR_CANNOT_MOUNT_NOW_FORM 80
  127. #define SPELL_ERROR_CANNOT_MOUNT_NOW_WATER_TO_DEEP 81
  128. #define SPELL_ERROR_ALREADY_CAST 82
  129. #define SPELL_ERROR_LOTTERY_IN_PROGRESS 83
  130. #define SPELL_ERROR_NOT_IN_PVP 84
  131. #define SPELL_ERROR_NOT_ENOUGH_DISSONANCE 85
  132. #define SPELL_ERROR_NOT_CANNOT_CAST_BUG_UNKNOWN_FAILURE 86
  133. #define SPELL_ERROR_NOT_CANNOT_CAST_BUG_SPELL_TEMPLATE 87
  134. #define SPELL_ERROR_NOT_PREPARED_BUG 88
  135. #define SPELL_ERROR_NOT_CANNOT_CAST_BUG_NO_GAME_WORLD 89
  136. #define SPELL_ERROR_NOT_CANNOT_CAST_BUG_NO_OWNER 90
  137. #define SPELL_ERROR_NOT_CANNOT_CAST_BUG_OWNER_TYPE 91
  138. #define SPELL_ERROR_NOT_CANNOT_CAST_BUG_NO_CASTER 92
  139. #define SPELL_ERROR_NO_RESPONSE_10 93
  140. #define SPELL_ERROR_BUG_PARTIAL_INTERUPT 94
  141. #define SPELL_ERROR_NO_RESPONSE_15 95
  142. #define SPELL_ERROR_BUG_TARGET_RESISTED 96
  143. #define SPELL_ERROR_BUG_TARGET_REFLECTED 97
  144. #define SPELL_ERROR_NO_RESPONSE_18 98
  145. #define SPELL_ERROR_NO_RESPONSE_35 99
  146. #define SPELL_ERROR_BUG_UNKNOWN_43 100
  147. #define SPELL_ERROR_BUG_UNKNOWN_44 101
  148. #define SPELL_ERROR_BUG_UNKNOWN_47 102
  149. #define SPELL_ERROR_TARGET_IMMUNE_HEALED_WITH_REPAIRS 103
  150. #define SPELL_ERROR_NOT_WHILE_MENTORING 104
  151. #define SPELL_ERROR_BUG_NO_EFFECTS_LANDED 105
  152. #define SPELL_ERROR_TOO_MUCH_DISSONANCE 106
  153. #define SPELL_ERROR_BUG_INVALID_SPELL_INDEX 107
  154. #define SPELL_ERROR_CANNOT_CAST_NOT_FOUND_95 108
  155. #define SPELL_ERROR_BUG_CONTAINMENT_TYPE 109
  156. #define SPELL_ERROR_BUG_SLOT_FULL 110
  157. #define SPELL_ERROR_CANNOT_CAST_NO_SPELL_101 111
  158. #define SPELL_ERROR_RECOVERING_ITEM_ABILITY 112
  159. #define SPELL_ERROR_NO_RESPONSE_110 113
  160. #define SPELL_ERROR_ALREADY_CAST_ON_TARGET 114
  161. #define CASTING_FLAG_MEZZED 1
  162. #define CASTING_FLAG_STIFLED 2
  163. #define CASTING_FLAG_STUNNED 4
  164. #define CASTING_FLAG_FEARED 8
  165. // Spell type is for AI so code knows what a spell is
  166. #define SPELL_TYPE_UNSET 1
  167. #define SPELL_TYPE_DD 2
  168. #define SPELL_TYPE_DOT 3
  169. #define SPELL_TYPE_HEAL 4
  170. #define SPELL_TYPE_HOT_WARD 5
  171. #define SPELL_TYPE_DEBUFF 6
  172. #define SPELL_TYPE_BUFF 7
  173. #define SPELL_TYPE_COMBATBUFF 8
  174. #define SPELL_TYPE_TAUNT 9
  175. #define SPELL_TYPE_DETAUNT 10
  176. #define SPELL_TYPE_REZ 11
  177. #define SPELL_TYPE_CURE 12
  178. #define SPELL_TYPE_FOOD 13
  179. #define SPELL_TYPE_DRINK 14
  180. #define SPELL_TYPE_ROOT 15
  181. #define SPELL_TYPE_SNARE 16
  182. #define SPELL_TYPE_ALLGROUPTARGETS 17
  183. struct LUAData{
  184. int8 type;
  185. sint32 int_value;
  186. bool bool_value;
  187. float float_value;
  188. string string_value;
  189. string string_value2;
  190. sint32 int_value2;
  191. float float_value2;
  192. string string_helper;
  193. };
  194. struct SpellScriptTimer {
  195. LuaSpell* spell;
  196. string customFunction;
  197. int32 time;
  198. int32 caster;
  199. int32 target;
  200. bool deleteWhenDone;
  201. };
  202. struct LevelArray{
  203. int8 adventure_class;
  204. int8 tradeskill_class;
  205. int16 spell_level;
  206. };
  207. struct SpellDisplayEffect{
  208. int8 percentage;
  209. int8 subbullet;
  210. string description;
  211. };
  212. enum GivenByType {
  213. GivenBy_Unset = 0,
  214. GivenBy_TradeskillClass = 1,
  215. GivenBy_SpellScroll = 2,
  216. GivenBy_AltAdvancement = 3,
  217. GivenBy_Race = 4,
  218. GivenBy_RacialInnate = 5,
  219. GivenBy_RacialTradition = 6,
  220. GivenBy_Class = 7,
  221. GivenBy_CharacterTrait = 8,
  222. GivenBy_FocusAbility = 9,
  223. GivenBy_ClassTraining = 10,
  224. GivenBy_WarderSpell = 11
  225. };
  226. struct SpellData{
  227. int32 spell_book_type;
  228. int32 id;
  229. int32 inherited_spell_id;
  230. sint16 icon;
  231. int16 icon_heroic_op;
  232. int16 icon_backdrop;
  233. int16 type;
  234. int32 class_skill;
  235. int16 min_class_skill_req;
  236. int32 mastery_skill;
  237. int8 ts_loc_index;
  238. int8 num_levels;
  239. int8 tier;
  240. int16 hp_req;
  241. int16 hp_upkeep;
  242. float power_req;
  243. bool power_by_level;
  244. int16 power_upkeep;
  245. int16 savagery_req;
  246. int16 savagery_upkeep;
  247. int16 dissonance_req;
  248. int16 dissonance_upkeep;
  249. int8 target_type;
  250. int16 cast_time;
  251. float recovery;
  252. float recast;
  253. int32 linked_timer;
  254. float radius;
  255. int16 max_aoe_targets;
  256. int8 friendly_spell;
  257. int16 req_concentration;
  258. float range;
  259. int32 duration1;
  260. int32 duration2;
  261. float resistibility;
  262. bool duration_until_cancel;
  263. int8 power_req_percent;
  264. int8 hp_req_percent;
  265. int8 savagery_req_percent;
  266. int8 dissonance_req_percent;
  267. EQ2_8BitString name;
  268. EQ2_16BitString description;
  269. string success_message;
  270. string fade_message;
  271. string fade_message_others;
  272. int8 cast_type;
  273. string lua_script;
  274. int32 call_frequency;
  275. bool interruptable;
  276. int32 spell_visual;
  277. string effect_message;
  278. float min_range;
  279. int8 can_effect_raid;
  280. int8 affect_only_group_members;
  281. int8 group_spell;
  282. float hit_bonus;
  283. int8 display_spell_tier;
  284. int8 is_active;
  285. int8 det_type;
  286. bool incurable;
  287. int8 control_effect_type;
  288. int32 casting_flags;
  289. bool cast_while_moving;
  290. bool persist_through_death;
  291. bool not_maintained;
  292. bool is_aa;
  293. int8 savage_bar;
  294. int8 savage_bar_slot;
  295. int32 soe_spell_crc;
  296. int8 spell_type;
  297. int32 spell_name_crc;
  298. sint32 type_group_spell_id;
  299. bool can_fizzle;
  300. EQ2_8BitString given_by;
  301. GivenByType given_by_type;
  302. };
  303. class Spell{
  304. public:
  305. ~Spell();
  306. Spell();
  307. Spell(SpellData* in_spell);
  308. Spell(Spell* host_spell, bool unique_spell = true);
  309. EQ2Packet* SerializeSpell(Client* client, bool display, bool trait_display = false, int8 packet_type = 0, int8 sub_packet_type = 0, const char* struct_name = 0);
  310. EQ2Packet* SerializeSpecialSpell(Client* client, bool display, int8 packet_type = 0, int8 sub_packet_type = 0);
  311. EQ2Packet* SerializeAASpell(Client* client,int8 tier, AltAdvanceData* data, bool display, bool trait_display = false, int8 packet_type = 0, int8 sub_packet_type = 0, const char* struct_name = 0);
  312. void AddSpellLevel(int8 adventure_class, int8 tradeskill_class, int16 level);
  313. void AddSpellEffect(int8 percentage, int8 subbullet, string description);
  314. void AddSpellLuaData(int8 type, int int_value, int int_value2, float float_value, float float_value2, bool bool_value, string string_value,string string_value2, string helper);
  315. void AddSpellLuaDataInt(int value, int value2, string helper);
  316. void AddSpellLuaDataFloat(float value, float value2, string helper);
  317. void AddSpellLuaDataBool(bool value, string helper);
  318. void AddSpellLuaDataString(string value, string value2, string helper);
  319. int32 GetSpellID();
  320. void SetPacketInformation(PacketStruct* packet, Client* client = 0, bool display_tier = false);
  321. void SetAAPacketInformation(PacketStruct* packet, AltAdvanceData* data, Client* client = 0, bool display_tier = false);
  322. int8 GetSpellTier();
  323. int32 GetSpellDuration();
  324. int16 GetSpellIcon();
  325. int16 GetSpellIconBackdrop();
  326. int16 GetSpellIconHeroicOp();
  327. int16 GetLevelRequired(Player* player);
  328. int16 GetHPRequired(Spawn* spawn);
  329. int16 GetPowerRequired(Spawn* spawn);
  330. int16 GetSavageryRequired(Spawn* spawn);
  331. int16 GetDissonanceRequired(Spawn* spawn);
  332. SpellData* GetSpellData();
  333. bool GetSpellData(lua_State* state, std::string field);
  334. bool SetSpellData(lua_State* state, std::string field, int8 fieldArg);
  335. bool ScribeAllowed(Player* player);
  336. vector<LUAData*>* GetLUAData();
  337. vector <LevelArray*>* GetSpellLevels();
  338. vector <SpellDisplayEffect*>* GetSpellEffects();
  339. const char* GetName();
  340. const char* GetDescription();
  341. bool IsHealSpell();
  342. bool IsBuffSpell();
  343. bool IsDamageSpell();
  344. bool IsControlSpell();
  345. bool IsOffenseSpell();
  346. bool IsCopiedSpell();
  347. void ModifyCastTime(Entity* caster);
  348. bool CastWhileStunned();
  349. bool CastWhileMezzed();
  350. bool CastWhileStifled();
  351. bool CastWhileFeared();
  352. bool GetStayLocked() { return stay_locked; }
  353. void StayLocked(bool val) { stay_locked = val; }
  354. vector<SpellDisplayEffect*> effects;
  355. vector<LUAData*> lua_data;
  356. mutable std::shared_mutex MSpellInfo;
  357. private:
  358. bool stay_locked = false;
  359. bool heal_spell;
  360. bool buff_spell;
  361. bool damage_spell;
  362. bool control_spell;
  363. bool offense_spell;
  364. bool copied_spell;
  365. SpellData* spell;
  366. //vector<SpellDisplayEffect*> effects;
  367. vector <LevelArray*> levels;
  368. };
  369. class MasterSpellList{
  370. public:
  371. MasterSpellList();
  372. ~MasterSpellList();
  373. void DestroySpells();
  374. map<string, Spell*> spell_name_map;
  375. map<int32, map<int32, Spell* > > spell_list;
  376. map<int32, map<int32, Spell* > > class_spell_list[MAX_CLASSES];
  377. map<int32, Spell*> spell_soecrc_map;
  378. Spell* GetSpell(int32 id, int8 tier);
  379. vector<Spell*>* GetSpellListByAdventureClass(int8 class_id, int16 max_level, int8 max_tier);
  380. vector<Spell*>* GetSpellListByTradeskillClass(int8 class_id, int16 max_level, int8 max_tier);
  381. Spell* GetSpellByName(const char* name);
  382. Spell* GetSpellByCRC(int32 spell_crc);
  383. void Reload();
  384. EQ2Packet* GetSpellPacket(int32 id, int8 tier, Client* client = 0, bool display = false, int8 packet_type = 0);
  385. EQ2Packet* GetAASpellPacket(int32 id, int8 group, Client* client, bool display, int8 packet_type);
  386. EQ2Packet* GetSpecialSpellPacket(int32 id, int8 tier, Client* client = 0, bool display = false, int8 packet_type = 0);
  387. void AddSpell(int32 id, int8 tier, Spell* spell);
  388. Mutex MMasterSpellList;
  389. /// <summary>Gets the correct spell error value for the given version</summary>
  390. /// <param name='version'>Client version</param>
  391. /// <param name='error_index'>ID of the error</param>
  392. /// <returns>The int16 value for the given error and version</returns>
  393. int16 GetSpellErrorValue(int16 version, int8 error_index);
  394. /// <summary>Adds a spell error to the list</summary>
  395. /// <param name='version'>Client version for the error</param>
  396. /// <param name='error_index'>ID for the error</param>
  397. /// <param name='error_value'>Value for the error</param>
  398. void AddSpellError(int16 version, int8 error_index, int16 error_value);
  399. int32 GetNewMaxSpellID() {
  400. int32 id = 0;
  401. MMasterSpellList.lock();
  402. max_spell_id++;
  403. id = max_spell_id;
  404. MMasterSpellList.unlock();
  405. return id;
  406. }
  407. private:
  408. /// <summary>Helper function that gets the closest version in the spell_errors map that is less then or equal to the given version</summary>
  409. /// <param name='version'>Client version</param>
  410. /// <returns>int16 version that is closest to the given version</returns>
  411. int16 GetClosestVersion(int16 version);
  412. // map <version, map<error_index, error_value> >
  413. map<int16, map<int8, int16> > spell_errors;
  414. int32 max_spell_id;
  415. };
  416. #endif