Spells.h 14 KB

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