Spells.cpp 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496
  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. #include "Spells.h"
  17. #include "../common/ConfigReader.h"
  18. #include "WorldDatabase.h"
  19. #include "../common/Log.h"
  20. #include "Traits/Traits.h"
  21. #include "AltAdvancement/AltAdvancement.h"
  22. #include <cmath>
  23. #include "LuaInterface.h"
  24. #include "Rules/Rules.h"
  25. #include <boost/regex.hpp>
  26. extern ConfigReader configReader;
  27. extern WorldDatabase database;
  28. extern MasterTraitList master_trait_list;
  29. extern MasterAAList master_aa_list;
  30. extern MasterSpellList master_spell_list;
  31. extern LuaInterface* lua_interface;
  32. extern MasterSkillList master_skill_list;
  33. extern RuleManager rule_manager;
  34. Spell::Spell(){
  35. spell = new SpellData;
  36. heal_spell = false;
  37. buff_spell = false;
  38. damage_spell = false;
  39. control_spell = false;
  40. offense_spell = false;
  41. copied_spell = false;
  42. }
  43. Spell::Spell(Spell* host_spell, bool unique_spell)
  44. {
  45. std::shared_lock lock(host_spell->MSpellInfo);
  46. copied_spell = true;
  47. spell = new SpellData;
  48. if (host_spell->GetSpellData())
  49. {
  50. if(!unique_spell) {
  51. spell->id = host_spell->GetSpellData()->id;
  52. }
  53. else {
  54. // try inheriting an existing custom spell id, otherwise obtain the new highest number on the spell list
  55. int32 tmpid = lua_interface->GetFreeCustomSpellID();
  56. if (tmpid)
  57. spell->id = tmpid;
  58. else
  59. {
  60. spell->id = master_spell_list.GetNewMaxSpellID();
  61. }
  62. }
  63. spell->inherited_spell_id = host_spell->GetSpellData()->inherited_spell_id;
  64. spell->affect_only_group_members = host_spell->GetSpellData()->affect_only_group_members;
  65. spell->call_frequency = host_spell->GetSpellData()->call_frequency;
  66. spell->can_effect_raid = host_spell->GetSpellData()->can_effect_raid;
  67. spell->casting_flags = host_spell->GetSpellData()->casting_flags;
  68. spell->cast_time = host_spell->GetSpellData()->cast_time;
  69. spell->cast_type = host_spell->GetSpellData()->cast_type;
  70. spell->cast_while_moving = host_spell->GetSpellData()->cast_while_moving;
  71. spell->class_skill = host_spell->GetSpellData()->class_skill;
  72. spell->min_class_skill_req = host_spell->GetSpellData()->min_class_skill_req;
  73. spell->control_effect_type = host_spell->GetSpellData()->control_effect_type;
  74. spell->description = EQ2_16BitString(host_spell->GetSpellData()->description);
  75. spell->det_type = host_spell->GetSpellData()->det_type;
  76. spell->display_spell_tier = host_spell->GetSpellData()->display_spell_tier;
  77. spell->dissonance_req = host_spell->GetSpellData()->dissonance_req;
  78. spell->dissonance_req_percent = host_spell->GetSpellData()->dissonance_req_percent;
  79. spell->dissonance_upkeep = host_spell->GetSpellData()->dissonance_upkeep;
  80. spell->duration1 = host_spell->GetSpellData()->duration1;
  81. spell->duration2 = host_spell->GetSpellData()->duration2;
  82. spell->duration_until_cancel = host_spell->GetSpellData()->duration_until_cancel;
  83. spell->effect_message = string(host_spell->GetSpellData()->effect_message);
  84. spell->fade_message = string(host_spell->GetSpellData()->fade_message);
  85. spell->fade_message_others = string(host_spell->GetSpellData()->fade_message_others);
  86. spell->friendly_spell = host_spell->GetSpellData()->friendly_spell;
  87. spell->group_spell = host_spell->GetSpellData()->group_spell;
  88. spell->hit_bonus = host_spell->GetSpellData()->hit_bonus;
  89. spell->hp_req = host_spell->GetSpellData()->hp_req;
  90. spell->hp_req_percent = host_spell->GetSpellData()->hp_req_percent;
  91. spell->hp_upkeep = host_spell->GetSpellData()->hp_upkeep;
  92. spell->icon = host_spell->GetSpellData()->icon;
  93. spell->icon_backdrop = host_spell->GetSpellData()->icon_backdrop;
  94. spell->icon_heroic_op = host_spell->GetSpellData()->icon_heroic_op;
  95. spell->incurable = host_spell->GetSpellData()->incurable;
  96. spell->interruptable = host_spell->GetSpellData()->interruptable;
  97. spell->is_aa = host_spell->GetSpellData()->is_aa;
  98. spell->is_active = host_spell->GetSpellData()->is_active;
  99. spell->linked_timer = host_spell->GetSpellData()->linked_timer;
  100. spell->lua_script = string(host_spell->GetSpellData()->lua_script);
  101. spell->mastery_skill = host_spell->GetSpellData()->mastery_skill;
  102. spell->max_aoe_targets = host_spell->GetSpellData()->max_aoe_targets;
  103. spell->min_range = host_spell->GetSpellData()->min_range;
  104. spell->name = EQ2_8BitString(host_spell->GetSpellData()->name);
  105. spell->not_maintained = host_spell->GetSpellData()->not_maintained;
  106. spell->num_levels = host_spell->GetSpellData()->num_levels;
  107. spell->persist_through_death = host_spell->GetSpellData()->persist_through_death;
  108. spell->power_by_level = host_spell->GetSpellData()->power_by_level;
  109. spell->power_req = host_spell->GetSpellData()->power_req;
  110. spell->power_req_percent = host_spell->GetSpellData()->power_req_percent;
  111. spell->power_upkeep = host_spell->GetSpellData()->power_upkeep;
  112. spell->radius = host_spell->GetSpellData()->radius;
  113. spell->range = host_spell->GetSpellData()->range;
  114. spell->recast = host_spell->GetSpellData()->recast;
  115. spell->recovery = host_spell->GetSpellData()->recovery;
  116. spell->req_concentration = host_spell->GetSpellData()->req_concentration;
  117. spell->resistibility = host_spell->GetSpellData()->resistibility;
  118. spell->savagery_req = host_spell->GetSpellData()->savagery_req;
  119. spell->savagery_req_percent = host_spell->GetSpellData()->savagery_req_percent;
  120. spell->savagery_upkeep = host_spell->GetSpellData()->savagery_upkeep;
  121. spell->savage_bar = host_spell->GetSpellData()->savage_bar;
  122. spell->savage_bar_slot = host_spell->GetSpellData()->savage_bar_slot;
  123. spell->soe_spell_crc = host_spell->GetSpellData()->soe_spell_crc;
  124. spell->spell_book_type = host_spell->GetSpellData()->spell_book_type;
  125. spell->spell_name_crc = host_spell->GetSpellData()->spell_name_crc;
  126. spell->spell_type = host_spell->GetSpellData()->spell_type;
  127. spell->spell_visual = host_spell->GetSpellData()->spell_visual;
  128. spell->success_message = string(host_spell->GetSpellData()->success_message);
  129. spell->target_type = host_spell->GetSpellData()->target_type;
  130. spell->tier = host_spell->GetSpellData()->tier;
  131. spell->ts_loc_index = host_spell->GetSpellData()->ts_loc_index;
  132. spell->type = host_spell->GetSpellData()->type;
  133. spell->type_group_spell_id = host_spell->GetSpellData()->type_group_spell_id;
  134. spell->can_fizzle = host_spell->GetSpellData()->can_fizzle;
  135. }
  136. heal_spell = host_spell->IsHealSpell();
  137. buff_spell = host_spell->IsBuffSpell();
  138. damage_spell = host_spell->IsDamageSpell();;
  139. control_spell = host_spell->IsControlSpell();
  140. offense_spell = host_spell->IsOffenseSpell();
  141. std::vector<LevelArray*>::iterator itr;
  142. for (itr = host_spell->levels.begin(); itr != host_spell->levels.end(); itr++)
  143. {
  144. LevelArray* lvlArray = *itr;
  145. AddSpellLevel(lvlArray->adventure_class, lvlArray->tradeskill_class, lvlArray->spell_level);
  146. }
  147. std::vector<SpellDisplayEffect*>::iterator sdeitr;
  148. for (sdeitr = host_spell->effects.begin(); sdeitr != host_spell->effects.end(); sdeitr++)
  149. {
  150. SpellDisplayEffect* sde = *sdeitr;
  151. AddSpellEffect(sde->percentage, sde->subbullet, sde->description);
  152. }
  153. vector<LUAData*>::iterator luaitr;
  154. for (luaitr = host_spell->lua_data.begin(); luaitr != host_spell->lua_data.end(); luaitr++) {
  155. LUAData* data = *luaitr;
  156. AddSpellLuaData(data->type, data->int_value, data->int_value2, data->float_value, data->float_value2, data->bool_value, string(data->string_value), string(data->string_value2), string(data->string_helper));
  157. }
  158. }
  159. Spell::Spell(SpellData* in_spell){
  160. spell = in_spell;
  161. heal_spell = false;
  162. buff_spell = false;
  163. damage_spell = false;
  164. control_spell = false;
  165. offense_spell = false;
  166. copied_spell = false;
  167. }
  168. Spell::~Spell(){
  169. vector<LevelArray*>::iterator itr1;
  170. for(itr1=levels.begin();itr1!=levels.end();itr1++) {
  171. safe_delete(*itr1);
  172. }
  173. vector<SpellDisplayEffect*>::iterator itr2;
  174. for(itr2=effects.begin();itr2!=effects.end();itr2++) {
  175. safe_delete(*itr2);
  176. }
  177. vector<LUAData*>::iterator itr3;
  178. for(itr3=lua_data.begin();itr3!=lua_data.end();itr3++) {
  179. safe_delete(*itr3);
  180. }
  181. safe_delete(spell);
  182. }
  183. void Spell::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){
  184. std::unique_lock lock(MSpellInfo);
  185. LUAData* data = new LUAData;
  186. data->type = type;
  187. data->int_value = int_value;
  188. data->int_value2 = int_value2;
  189. data->float_value = float_value;
  190. data->float_value2 = float_value2;
  191. data->bool_value = bool_value;
  192. data->string_value = string_value;
  193. data->string_value2 = string_value2;
  194. data->string_helper = helper;
  195. lua_data.push_back(data);
  196. }
  197. void Spell::AddSpellLuaDataInt(int value, int value2, string helper) {
  198. std::unique_lock lock(MSpellInfo);
  199. LUAData *data = new LUAData;
  200. data->type = 0;
  201. data->int_value = value;
  202. data->int_value2 = value2;
  203. data->float_value = 0;
  204. data->float_value2 = 0;
  205. data->bool_value = false;
  206. data->string_helper = helper;
  207. lua_data.push_back(data);
  208. }
  209. void Spell::AddSpellLuaDataFloat(float value, float value2, string helper) {
  210. std::unique_lock lock(MSpellInfo);
  211. LUAData *data = new LUAData;
  212. data->type = 1;
  213. data->int_value = 0;
  214. data->int_value2 = 0;
  215. data->float_value = value;
  216. data->float_value2 = value2;
  217. data->bool_value = false;
  218. data->string_helper = helper;
  219. lua_data.push_back(data);
  220. }
  221. void Spell::AddSpellLuaDataBool(bool value, string helper) {
  222. std::unique_lock lock(MSpellInfo);
  223. LUAData *data = new LUAData;
  224. data->type = 2;
  225. data->int_value = 0;
  226. data->float_value = 0;
  227. data->bool_value = value;
  228. data->string_helper = helper;
  229. lua_data.push_back(data);
  230. }
  231. void Spell::AddSpellLuaDataString(string value, string value2,string helper) {
  232. std::unique_lock lock(MSpellInfo);
  233. LUAData *data = new LUAData;
  234. data->type = 3;
  235. data->int_value = 0;
  236. data->int_value2 = 0;
  237. data->float_value = 0;
  238. data->float_value2 = 0;
  239. data->bool_value = false;
  240. data->string_value = value;
  241. data->string_value2 = value2;
  242. data->string_helper = helper;
  243. lua_data.push_back(data);
  244. }
  245. int16 Spell::GetLevelRequired(Player* player){
  246. int16 ret = 0xFFFF;
  247. if(!player)
  248. return ret;
  249. LevelArray* level = 0;
  250. vector<LevelArray*>::iterator itr;
  251. for(itr = levels.begin(); itr != levels.end(); itr++){
  252. level = *itr;
  253. if(level && level->adventure_class == player->GetAdventureClass()){
  254. ret = level->spell_level/10;
  255. break;
  256. }
  257. }
  258. return ret;
  259. }
  260. void Spell::SetAAPacketInformation(PacketStruct* packet, AltAdvanceData* data, Client* client, bool display_tier) {
  261. int8 current_tier = client->GetPlayer()->GetSpellTier(spell->id);
  262. Spell* next_spell;
  263. SpellData* spell2;
  264. if (data->maxRank > current_tier) {
  265. next_spell = master_spell_list.GetSpell(spell->id, current_tier + 1);
  266. spell2 = next_spell->GetSpellData();
  267. }
  268. SpellDisplayEffect* effect2;
  269. //next_spell->effects[1]->description;
  270. int xxx = 0;
  271. int16 hp_req = 0;
  272. int16 power_req = 0;
  273. if (current_tier > 0) {
  274. packet->setSubstructDataByName("spell_info", "current_id", spell->id);
  275. packet->setSubstructDataByName("spell_info", "current_icon", spell->icon);
  276. packet->setSubstructDataByName("spell_info", "current_icon2", spell->icon_heroic_op); // fix struct element name eventually
  277. packet->setSubstructDataByName("spell_info", "current_icontype", spell->icon_backdrop); // fix struct element name eventually
  278. if (packet->GetVersion() >= 63119) {
  279. packet->setSubstructDataByName("spell_info", "current_version", 0x04);
  280. packet->setSubstructDataByName("spell_info", "current_sub_version", 0x24);
  281. }
  282. else if (packet->GetVersion() >= 58617) {
  283. packet->setSubstructDataByName("spell_info", "current_version", 0x03);
  284. packet->setSubstructDataByName("spell_info", "current_sub_version", 0x131A);
  285. }
  286. else {
  287. packet->setSubstructDataByName("spell_info", "current_version", 0x00);
  288. packet->setSubstructDataByName("spell_info", "current_sub_version", 0xD9);
  289. }
  290. packet->setSubstructDataByName("spell_info", "current_type", spell->type);
  291. packet->setSubstructDataByName("spell_info", "unknown_MJ1d", 1); //63119 test
  292. packet->setSubstructDataByName("spell_info", "current_class_skill", spell->class_skill);
  293. packet->setSubstructDataByName("spell_info", "current_mastery_skill", spell->mastery_skill);
  294. packet->setSubstructDataByName("spell_info", "duration_flag", spell->duration_until_cancel);
  295. if (client && spell->type != 2) {
  296. sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client->GetPlayer()));
  297. if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
  298. spell_text_color = ARROW_COLOR_WHITE;
  299. spell_text_color -= 6;
  300. if (spell_text_color < 0)
  301. spell_text_color *= -1;
  302. packet->setSubstructDataByName("spell_info", "current_spell_text_color", (xxx == 1 ? 0xFFFFFFFF : spell_text_color));
  303. }
  304. else {
  305. packet->setSubstructDataByName("spell_info", "current_spell_text_color", (xxx == 1 ? 0xFFFFFFFF : 3));
  306. }
  307. packet->setSubstructDataByName("spell_info", "current_spell_text_color", (xxx == 1 ? 0xFFFFFFFF : 3));
  308. packet->setSubstructDataByName("spell_info", "current_tier", (spell->tier));
  309. if (spell->type != 2) {
  310. packet->setArrayLengthByName("current_num_levels", 0);
  311. for (int32 i = 0; i < levels.size(); i++) {
  312. packet->setArrayDataByName("spell_info_aa_adventure_class", levels[i]->adventure_class, i);
  313. packet->setArrayDataByName("spell_info_aa_tradeskill_class", levels[i]->tradeskill_class, i);
  314. packet->setArrayDataByName("spell_info_aa_spell_level", levels[i]->spell_level, i);
  315. }
  316. }
  317. //packet->setSubstructDataByName("spell_info","unknown9", 20);
  318. if (client) {
  319. hp_req = GetHPRequired(client->GetPlayer());
  320. power_req = GetPowerRequired(client->GetPlayer());
  321. // might need version checks around these?
  322. if (client->GetVersion() >= 1193)
  323. {
  324. int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
  325. packet->setSubstructDataByName("spell_info", "current_savagery_req", savagery_req);
  326. packet->setSubstructDataByName("spell_info", "current_savagery_upkeep", spell->savagery_upkeep);
  327. }
  328. if (client->GetVersion() >= 57048)
  329. {
  330. int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
  331. packet->setSubstructDataByName("spell_info", "dissonance_req", dissonance_req);
  332. packet->setSubstructDataByName("spell_info", "dissonance_upkeep", spell->dissonance_upkeep);
  333. }
  334. }
  335. packet->setSubstructDataByName("spell_info", "current_health_req", hp_req);
  336. packet->setSubstructDataByName("spell_info", "current_health_upkeep", spell->hp_upkeep);
  337. packet->setSubstructDataByName("spell_info", "current_power_req", power_req);
  338. packet->setSubstructDataByName("spell_info", "current_power_upkeep", spell->power_upkeep);
  339. packet->setSubstructDataByName("spell_info", "current_req_concentration", spell->req_concentration);
  340. //unknown1 savagery???
  341. packet->setSubstructDataByName("spell_info", "current_cast_time", spell->cast_time);
  342. packet->setSubstructDataByName("spell_info", "current_recovery", spell->recovery);
  343. packet->setSubstructDataByName("spell_info", "current_recast", spell->recast);
  344. packet->setSubstructDataByName("spell_info", "current_radius", spell->radius);
  345. packet->setSubstructDataByName("spell_info", "current_max_aoe_targets", spell->max_aoe_targets);
  346. packet->setSubstructDataByName("spell_info", "current_friendly_spell", spell->friendly_spell);
  347. // rumber of reagents with array
  348. packet->setSubstructArrayLengthByName("spell_info", "current_num_effects", (xxx == 1 ? 0 : effects.size()));
  349. for (int32 i = 0; i < effects.size(); i++) {
  350. packet->setArrayDataByName("current_subbulletflag", effects[i]->subbullet, i);
  351. string effect_message;
  352. if (effects[i]->description.length() > 0) {
  353. effect_message = effects[i]->description;
  354. if (effect_message.find("%LM") < 0xFFFFFFFF) {
  355. int string_index = effect_message.find("%LM");
  356. int data_index = stoi(effect_message.substr(string_index + 3, 2));
  357. float value;
  358. if (lua_data[data_index]->type == 1)
  359. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  360. else
  361. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  362. string strValue = to_string(value);
  363. strValue.erase(strValue.find_last_not_of('0') + 1, std::string::npos);
  364. effect_message.replace(effect_message.find("%LM"), 5, strValue);
  365. }
  366. // Magic damage min
  367. if (effect_message.find("%DML") < 0xFFFFFFFF) {
  368. int string_index = effect_message.find("%DML");
  369. int data_index = stoi(effect_message.substr(string_index + 4, 2));
  370. float value;
  371. if (lua_data[data_index]->type == 1)
  372. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  373. else
  374. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  375. value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  376. string damage = to_string((int)round(value));
  377. effect_message.replace(effect_message.find("%DML"), 6, damage);
  378. }
  379. // Magic damage max
  380. if (effect_message.find("%DMH") < 0xFFFFFFFF) {
  381. int string_index = effect_message.find("%DMH");
  382. int data_index = stoi(effect_message.substr(string_index + 4, 2));
  383. float value;
  384. if (lua_data[data_index]->type == 1)
  385. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  386. else
  387. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  388. value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  389. string damage = to_string((int)round(value));
  390. effect_message.replace(effect_message.find("%DMH"), 6, damage);
  391. }
  392. // level based Magic damage min
  393. if (effect_message.find("%LDML") < 0xFFFFFFFF) {
  394. int string_index = effect_message.find("%LDML");
  395. int data_index = stoi(effect_message.substr(string_index + 5, 2));
  396. float value;
  397. if (lua_data[data_index]->type == 1)
  398. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  399. else
  400. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  401. value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  402. string damage = to_string((int)round(value));
  403. effect_message.replace(effect_message.find("%LDML"), 7, damage);
  404. }
  405. // level based Magic damage max
  406. if (effect_message.find("%LDMH") < 0xFFFFFFFF) {
  407. int string_index = effect_message.find("%LDMH");
  408. int data_index = stoi(effect_message.substr(string_index + 5, 2));
  409. float value;
  410. if (lua_data[data_index]->type == 1)
  411. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  412. else
  413. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  414. value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  415. string damage = to_string((int)round(value));
  416. effect_message.replace(effect_message.find("%LDMH"), 7, damage);
  417. }
  418. //GetZone()->SimpleMessage(CHANNEL_COLOR_SPELL_EFFECT, effect_message.c_str(), victim, 50);
  419. packet->setArrayDataByName("current_effect", effect_message.c_str(), i);
  420. }
  421. packet->setArrayDataByName("current_percentage", effects[i]->percentage, i);
  422. }
  423. if (display_tier == true)
  424. packet->setSubstructDataByName("spell_info", "current_display_spell_tier", 1);// spell2->display_spell_tier);
  425. else
  426. packet->setSubstructDataByName("spell_info", "current_display_spell_tier", 1);// 0);
  427. packet->setSubstructDataByName("spell_info", "current_unknown_1", 1);// 0);
  428. //unkown1_1
  429. packet->setSubstructDataByName("spell_info", "current_minimum_range", spell->min_range);
  430. packet->setSubstructDataByName("spell_info", "current_range", spell->range);
  431. packet->setSubstructDataByName("spell_info", "current_duration_1", spell->duration1);
  432. packet->setSubstructDataByName("spell_info", "current_duration_2", spell->duration2);
  433. packet->setSubstructDataByName("spell_info", "current_duration_flag", spell->duration_until_cancel);
  434. packet->setSubstructDataByName("spell_info", "current_target", spell->target_type);
  435. packet->setSubstructDataByName("spell_info", "current_can_effect_raid", spell->can_effect_raid);
  436. packet->setSubstructDataByName("spell_info", "current_affect_only_group_members", spell->affect_only_group_members);
  437. packet->setSubstructDataByName("spell_info", "current_group_spell", spell->group_spell);
  438. packet->setSubstructDataByName("spell_info", "current_resistibility", spell->resistibility);
  439. packet->setSubstructDataByName("spell_info", "current_name", &(spell->name));
  440. packet->setSubstructDataByName("spell_info", "current_description", &(spell->description));
  441. }
  442. if (current_tier + 1 <= data->maxRank) {
  443. packet->setSubstructDataByName("spell_info", "next_id", spell2->id);
  444. packet->setSubstructDataByName("spell_info", "next_icon", spell2->icon);
  445. packet->setSubstructDataByName("spell_info", "next_icon2", spell2->icon_heroic_op); // fix struct element name eventually
  446. packet->setSubstructDataByName("spell_info", "next_icontype", spell2->icon_backdrop); // fix struct element name eventually
  447. if (packet->GetVersion() >= 63119) {
  448. packet->setSubstructDataByName("spell_info", "next_aa_spell_info2", "version", 0x04);
  449. packet->setSubstructDataByName("spell_info", "next_aa_spell_info2", "sub_version", 0x24);
  450. }
  451. else if (packet->GetVersion() >= 58617) {
  452. packet->setSubstructDataByName("spell_info", "next_version", 0x03);
  453. packet->setSubstructDataByName("spell_info", "next_sub_version", 0x131A);
  454. }
  455. else {
  456. packet->setSubstructDataByName("spell_info", "next_version", 0x00);
  457. packet->setSubstructDataByName("spell_info", "next_sub_version", 0xD9);
  458. }
  459. packet->setSubstructDataByName("spell_info", "next_type", spell2->type);
  460. packet->setSubstructDataByName("spell_info", "next_unknown_MJ1d", 1); //63119 test
  461. packet->setSubstructDataByName("spell_info", "next_class_skill", spell2->class_skill);
  462. packet->setSubstructDataByName("spell_info", "next_mastery_skill", spell2->mastery_skill);
  463. packet->setSubstructDataByName("spell_info", "next_duration_flag", spell2->duration_until_cancel);
  464. if (client && spell->type != 2) {
  465. sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client->GetPlayer()));
  466. if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
  467. spell_text_color = ARROW_COLOR_WHITE;
  468. spell_text_color -= 6;
  469. if (spell_text_color < 0)
  470. spell_text_color *= -1;
  471. packet->setSubstructDataByName("spell_info", "next_spell_text_color", spell_text_color);
  472. }
  473. else
  474. packet->setSubstructDataByName("spell_info", "next_spell_text_color", 3);
  475. if (spell->type != 2) {
  476. packet->setArrayLengthByName("num_levels", levels.size());
  477. for (int32 i = 0; i < levels.size(); i++) {
  478. packet->setArrayDataByName("spell_info_aa_adventure_class2", levels[i]->adventure_class, i);
  479. packet->setArrayDataByName("spell_info_aa_tradeskill_class2", levels[i]->tradeskill_class, i);
  480. packet->setArrayDataByName("spell_info_aa_spell_level2", levels[i]->spell_level, i);
  481. }
  482. }
  483. //packet->setSubstructDataByName("spell_info","unknown9", 20);
  484. hp_req = 0;
  485. power_req = 0;
  486. if (client) {
  487. hp_req = GetHPRequired(client->GetPlayer());
  488. power_req = GetPowerRequired(client->GetPlayer());
  489. // might need version checks around these?
  490. if (client->GetVersion() >= 1193)
  491. {
  492. int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
  493. packet->setSubstructDataByName("spell_info", "next_savagery_req", savagery_req);
  494. packet->setSubstructDataByName("spell_info", "next_savagery_upkeep", spell->savagery_upkeep);
  495. }
  496. if (client->GetVersion() >= 57048)
  497. {
  498. int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
  499. packet->setSubstructDataByName("spell_info", "next_dissonance_req", dissonance_req);
  500. packet->setSubstructDataByName("spell_info", "next_dissonance_upkeep", spell->dissonance_upkeep);
  501. }
  502. }
  503. packet->setSubstructDataByName("spell_info", "next_target", spell->target_type);
  504. packet->setSubstructDataByName("spell_info", "next_recovery", spell->recovery);
  505. packet->setSubstructDataByName("spell_info", "next_health_upkeep", spell->hp_upkeep);
  506. packet->setSubstructDataByName("spell_info", "next_health_req", hp_req);
  507. packet->setSubstructDataByName("spell_info", "next_tier", spell->tier);
  508. packet->setSubstructDataByName("spell_info", "next_power_req", power_req);
  509. packet->setSubstructDataByName("spell_info", "next_power_upkeep", spell->power_upkeep);
  510. packet->setSubstructDataByName("spell_info", "next_cast_time", spell->cast_time);
  511. packet->setSubstructDataByName("spell_info", "next_recast", spell->recast);
  512. packet->setSubstructDataByName("spell_info", "next_radius", spell->radius);
  513. packet->setSubstructDataByName("spell_info", "next_req_concentration", spell->req_concentration);
  514. //packet->setSubstructDataByName("spell_info","req_concentration2", 2);
  515. packet->setSubstructDataByName("spell_info", "next_max_aoe_targets", spell->max_aoe_targets);
  516. packet->setSubstructDataByName("spell_info", "next_friendly_spell", spell->friendly_spell);
  517. packet->setSubstructArrayLengthByName("spell_info", "next_num_effects", next_spell->effects.size());
  518. for (int32 i = 0; i < next_spell->effects.size(); i++) {
  519. packet->setArrayDataByName("next_subbulletflag", next_spell->effects[i]->subbullet, i);
  520. string effect_message;
  521. if (next_spell->effects[i]->description.length() > 0) {
  522. effect_message = next_spell->effects[i]->description;
  523. if (effect_message.find("%LM") < 0xFFFFFFFF) {
  524. int string_index = effect_message.find("%LM");
  525. int data_index = stoi(effect_message.substr(string_index + 3, 2));
  526. float value;
  527. if (next_spell->lua_data[data_index]->type == 1)
  528. value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  529. else
  530. value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  531. string strValue = to_string(value);
  532. strValue.erase(strValue.find_last_not_of('0') + 1, std::string::npos);
  533. effect_message.replace(effect_message.find("%LM"), 5, strValue);
  534. }
  535. // Magic damage min
  536. if (effect_message.find("%DML") < 0xFFFFFFFF) {
  537. int string_index = effect_message.find("%DML");
  538. int data_index = stoi(effect_message.substr(string_index + 4, 2));
  539. float value;
  540. if (next_spell->lua_data[data_index]->type == 1)
  541. value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  542. else
  543. value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  544. value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  545. string damage = to_string((int)round(value));
  546. damage.erase(damage.find_last_not_of('0') + 1, std::string::npos);
  547. effect_message.replace(effect_message.find("%DML"), 6, damage);
  548. }
  549. // Magic damage max
  550. if (effect_message.find("%DMH") < 0xFFFFFFFF) {
  551. int string_index = effect_message.find("%DMH");
  552. int data_index = stoi(effect_message.substr(string_index + 4, 2));
  553. float value;
  554. if (next_spell->lua_data[data_index]->type == 1)
  555. value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  556. else
  557. value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  558. value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  559. string damage = to_string((int)round(value));
  560. damage.erase(damage.find_last_not_of('0') + 1, std::string::npos);
  561. effect_message.replace(effect_message.find("%DMH"), 6, damage);
  562. }
  563. // level based Magic damage min
  564. if (effect_message.find("%LDML") < 0xFFFFFFFF) {
  565. int string_index = effect_message.find("%LDML");
  566. int data_index = stoi(effect_message.substr(string_index + 5, 2));
  567. float value;
  568. if (next_spell->lua_data[data_index]->type == 1)
  569. value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  570. else
  571. value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  572. value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  573. string damage = to_string((int)round(value));
  574. effect_message.replace(effect_message.find("%LDML"), 7, damage);
  575. }
  576. // level based Magic damage max
  577. if (effect_message.find("%LDMH") < 0xFFFFFFFF) {
  578. int string_index = effect_message.find("%LDMH");
  579. int data_index = stoi(effect_message.substr(string_index + 5, 2));
  580. float value;
  581. if (next_spell->lua_data[data_index]->type == 1)
  582. value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  583. else
  584. value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  585. value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  586. string damage = to_string((int)round(value));
  587. effect_message.replace(effect_message.find("%LDMH"), 7, damage);
  588. }
  589. //GetZone()->SimpleMessage(CHANNEL_COLOR_SPELL_EFFECT, effect_message.c_str(), victim, 50);
  590. packet->setArrayDataByName("next_effect", effect_message.c_str(), i);
  591. }
  592. packet->setArrayDataByName("next_percentage", next_spell->effects[i]->percentage, i);
  593. }
  594. if (display_tier == true)
  595. packet->setSubstructDataByName("spell_info", "next_display_spell_tier", 1);// spell->display_spell_tier);
  596. else
  597. packet->setSubstructDataByName("spell_info", "next_display_spell_tier", 1);//0
  598. packet->setSubstructDataByName("spell_info", "next_unknown_1", 1);//0
  599. packet->setSubstructDataByName("spell_info", "next_range", spell2->range);
  600. packet->setSubstructDataByName("spell_info", "next_duration_1", spell2->duration1);
  601. packet->setSubstructDataByName("spell_info", "next_duration_2", spell2->duration2);
  602. packet->setSubstructDataByName("spell_info", "next_can_effect_raid", spell2->can_effect_raid);
  603. packet->setSubstructDataByName("spell_info", "next_affect_only_group_members", spell2->affect_only_group_members);
  604. packet->setSubstructDataByName("spell_info", "next_group_spell", spell2->group_spell);
  605. packet->setSubstructDataByName("spell_info", "next_resistibility", spell2->resistibility);
  606. packet->setSubstructDataByName("spell_info", "next_name", &(spell2->name));
  607. packet->setSubstructDataByName("spell_info", "next_description", &(spell2->description));
  608. }
  609. }
  610. void Spell::SetPacketInformation(PacketStruct* packet, Client* client, bool display_tier) {
  611. packet->setSubstructDataByName("spell_info", "id", spell->id);
  612. packet->setSubstructDataByName("spell_info", "icon", spell->icon);
  613. packet->setSubstructDataByName("spell_info", "icon2", spell->icon_heroic_op); // fix struct element name eventually
  614. packet->setSubstructDataByName("spell_info", "icontype", spell->icon_backdrop); // fix struct element name eventually
  615. if (packet->GetVersion() >= 63119) {
  616. packet->setSubstructDataByName("spell_info", "version", 0x04);
  617. packet->setSubstructDataByName("spell_info", "sub_version", 0x24);
  618. }
  619. else if (packet->GetVersion() >= 60114) {
  620. packet->setSubstructDataByName("spell_info", "version", 0x03);
  621. packet->setSubstructDataByName("spell_info", "sub_version", 4890);
  622. }
  623. else if (packet->GetVersion() <= 546) {
  624. packet->setSubstructDataByName("spell_info", "version", 0x10);
  625. packet->setSubstructDataByName("spell_info", "sub_version", 0x0f);
  626. }
  627. else {
  628. packet->setSubstructDataByName("spell_info", "version", 0x11);
  629. packet->setSubstructDataByName("spell_info", "sub_version", 0x14);
  630. }
  631. packet->setSubstructDataByName("spell_info", "type", spell->type);
  632. packet->setSubstructDataByName("spell_info", "unknown_MJ1d", 1); //63119 test
  633. packet->setSubstructDataByName("spell_info", "class_skill", spell->class_skill);
  634. packet->setSubstructDataByName("spell_info", "min_class_skill_req", spell->min_class_skill_req);
  635. packet->setSubstructDataByName("spell_info", "mastery_skill", spell->mastery_skill);
  636. packet->setSubstructDataByName("spell_info", "duration_flag", spell->duration_until_cancel);
  637. if (client && spell->type != 2) {
  638. sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client->GetPlayer()));
  639. if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
  640. spell_text_color = ARROW_COLOR_WHITE;
  641. spell_text_color -= 6;
  642. if (spell_text_color < 0)
  643. spell_text_color *= -1;
  644. packet->setSubstructDataByName("spell_info", "spell_text_color", spell_text_color);
  645. }
  646. else
  647. packet->setSubstructDataByName("spell_info", "spell_text_color", 3);
  648. if (spell->type != 2) {
  649. packet->setSubstructArrayLengthByName("spell_info", "num_levels", levels.size());
  650. for (int32 i = 0; i < levels.size(); i++) {
  651. packet->setArrayDataByName("adventure_class", levels[i]->adventure_class, i);
  652. packet->setArrayDataByName("tradeskill_class", levels[i]->tradeskill_class, i);
  653. packet->setArrayDataByName("spell_level", levels[i]->spell_level, i);
  654. }
  655. }
  656. packet->setSubstructDataByName("spell_info", "unknown9", 20);
  657. int16 hp_req = 0;
  658. int16 power_req = 0;
  659. if (client) {
  660. hp_req = GetHPRequired(client->GetPlayer());
  661. power_req = GetPowerRequired(client->GetPlayer());
  662. // might need version checks around these?
  663. if (client->GetVersion() >= 1193)
  664. {
  665. int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
  666. packet->setSubstructDataByName("spell_info", "savagery_req", savagery_req);
  667. packet->setSubstructDataByName("spell_info", "savagery_upkeep", spell->savagery_upkeep);
  668. }
  669. if (client->GetVersion() >= 57048)
  670. {
  671. int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
  672. packet->setSubstructDataByName("spell_info", "dissonance_req", dissonance_req);
  673. packet->setSubstructDataByName("spell_info", "dissonance_upkeep", spell->dissonance_upkeep);
  674. }
  675. }
  676. packet->setSubstructDataByName("spell_info", "target", spell->target_type);
  677. packet->setSubstructDataByName("spell_info", "recovery", spell->recovery);
  678. packet->setSubstructDataByName("spell_info", "health_upkeep", spell->hp_upkeep);
  679. packet->setSubstructDataByName("spell_info", "health_req", hp_req);
  680. packet->setSubstructDataByName("spell_info", "tier", spell->tier);
  681. packet->setSubstructDataByName("spell_info", "power_req", power_req);
  682. packet->setSubstructDataByName("spell_info", "power_upkeep", spell->power_upkeep);
  683. if (packet->GetVersion() <= 546) {//cast times are displayed differently on new clients
  684. packet->setSubstructDataByName("spell_info", "cast_time", spell->cast_time/10);
  685. }
  686. else {
  687. packet->setSubstructDataByName("spell_info", "cast_time", spell->cast_time);
  688. }
  689. packet->setSubstructDataByName("spell_info", "recast", spell->recast);
  690. packet->setSubstructDataByName("spell_info", "radius", spell->radius);
  691. packet->setSubstructDataByName("spell_info", "req_concentration", spell->req_concentration);
  692. //packet->setSubstructDataByName("spell_info","req_concentration2", 2);
  693. packet->setSubstructDataByName("spell_info", "max_aoe_targets", spell->max_aoe_targets);
  694. packet->setSubstructDataByName("spell_info", "friendly_spell", spell->friendly_spell);
  695. packet->setSubstructArrayLengthByName("spell_info", "num_effects", effects.size());
  696. for (int32 i = 0; i < effects.size(); i++) {
  697. packet->setArrayDataByName("subbulletflag", effects[i]->subbullet, i);
  698. string effect_message;
  699. if (effects[i]->description.length() > 0) {
  700. effect_message = effects[i]->description;
  701. if (effect_message.find("%LM") < 0xFFFFFFFF) {
  702. int string_index = effect_message.find("%LM");
  703. int data_index = stoi(effect_message.substr(string_index + 3, 2));
  704. float value;
  705. if (lua_data[data_index]->type == 1)
  706. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  707. else
  708. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  709. string strValue = to_string(value);
  710. strValue.erase(strValue.find_last_not_of('0') + 1, std::string::npos);
  711. effect_message.replace(effect_message.find("%LM"), 5, strValue);
  712. }
  713. // Magic damage min
  714. if (effect_message.find("%DML") < 0xFFFFFFFF) {
  715. int string_index = effect_message.find("%DML");
  716. int data_index = stoi(effect_message.substr(string_index + 4, 2));
  717. float value;
  718. if (lua_data[data_index]->type == 1)
  719. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  720. else
  721. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  722. value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  723. string damage = to_string((int)round(value));
  724. effect_message.replace(effect_message.find("%DML"), 6, damage);
  725. }
  726. // Magic damage max
  727. if (effect_message.find("%DMH") < 0xFFFFFFFF) {
  728. int string_index = effect_message.find("%DMH");
  729. int data_index = stoi(effect_message.substr(string_index + 4, 2));
  730. float value;
  731. if (lua_data[data_index]->type == 1)
  732. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  733. else
  734. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  735. value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  736. string damage = to_string((int)round(value));
  737. effect_message.replace(effect_message.find("%DMH"), 6, damage);
  738. }
  739. // level based Magic damage min
  740. if (effect_message.find("%LDML") < 0xFFFFFFFF) {
  741. int string_index = effect_message.find("%LDML");
  742. int data_index = stoi(effect_message.substr(string_index + 5, 2));
  743. float value;
  744. if (lua_data[data_index]->type == 1)
  745. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  746. else
  747. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  748. value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  749. string damage = to_string((int)round(value));
  750. effect_message.replace(effect_message.find("%LDML"), 7, damage);
  751. }
  752. // level based Magic damage max
  753. if (effect_message.find("%LDMH") < 0xFFFFFFFF) {
  754. int string_index = effect_message.find("%LDMH");
  755. int data_index = stoi(effect_message.substr(string_index + 5, 2));
  756. float value;
  757. if (lua_data[data_index]->type == 1)
  758. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  759. else
  760. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  761. value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  762. string damage = to_string((int)round(value));
  763. effect_message.replace(effect_message.find("%LDMH"), 7, damage);
  764. }
  765. boost::regex re("([0-9]{1,10})\\s+\\-\\s+([0-9]{1,10})");
  766. boost::match_results<std::string::const_iterator> base_match;
  767. if (boost::regex_search(effect_message, base_match, re, boost::match_partial)) {
  768. boost::ssub_match match = base_match[0];
  769. std::size_t midPos = match.str().find(" - ");
  770. if(midPos != std::string::npos)
  771. {
  772. int32 minValue = atoul(match.str().substr(0, midPos).c_str());
  773. int32 maxValue = atoul(match.str().substr(midPos+3).c_str());
  774. int32 newMin = minValue;
  775. bool crit = false;
  776. Skill* skill = master_skill_list.GetSkill(spell->mastery_skill);
  777. std::string skillName = "";
  778. if(skill)
  779. skillName = skill->name.data;
  780. if(skillName == "Aggression")
  781. newMin = (int32)client->GetPlayer()->CalculateHateAmount(nullptr, (sint32)minValue);
  782. else if(spell->friendly_spell && skillName == "Ministration")
  783. newMin = (int32)client->GetPlayer()->CalculateHealAmount(nullptr, (sint32)minValue, 0, &crit, true);
  784. else
  785. newMin = (int32)client->GetPlayer()->CalculateDamageAmount(nullptr, (sint32)minValue, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  786. int32 newMax = maxValue;
  787. if(skillName == "Aggression")
  788. newMax = (int32)client->GetPlayer()->CalculateHateAmount(nullptr, (sint32)maxValue);
  789. else if(spell->friendly_spell && skillName == "Ministration")
  790. newMax = (int32)client->GetPlayer()->CalculateHealAmount(nullptr, (sint32)maxValue, 0, &crit, true);
  791. else
  792. newMax = (int32)client->GetPlayer()->CalculateDamageAmount(nullptr, (sint32)maxValue, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
  793. std::string newStr = std::to_string(newMin) + " - " + std::to_string(newMax);
  794. effect_message.replace(effect_message.find(match.str()), match.str().size(), newStr);
  795. }
  796. }
  797. //GetZone()->SimpleMessage(CHANNEL_COLOR_SPELL_EFFECT, effect_message.c_str(), victim, 50);
  798. }
  799. packet->setArrayDataByName("effect", effect_message.c_str(), i);
  800. packet->setArrayDataByName("percentage", effects[i]->percentage, i);
  801. }
  802. if (display_tier == true)
  803. packet->setSubstructDataByName("spell_info", "display_spell_tier", spell->display_spell_tier);
  804. else
  805. packet->setSubstructDataByName("spell_info", "display_spell_tier", 0);
  806. packet->setSubstructDataByName("spell_info", "range", spell->range);
  807. packet->setSubstructDataByName("spell_info", "duration1", spell->duration1);
  808. packet->setSubstructDataByName("spell_info", "duration2", spell->duration2);
  809. packet->setSubstructDataByName("spell_info", "can_effect_raid", spell->can_effect_raid);
  810. packet->setSubstructDataByName("spell_info", "affect_only_group_members", spell->affect_only_group_members);
  811. packet->setSubstructDataByName("spell_info", "group_spell", spell->group_spell);
  812. packet->setSubstructDataByName("spell_info", "resistibility", spell->resistibility);
  813. packet->setSubstructDataByName("spell_info", "name", &(spell->name));
  814. packet->setSubstructDataByName("spell_info", "description", &(spell->description));
  815. //packet->PrintPacket();
  816. }
  817. EQ2Packet* Spell::SerializeSpecialSpell(Client* client, bool display, int8 packet_type, int8 sub_packet_type) {
  818. if (client->GetVersion() <= 283)
  819. return SerializeSpell(client, display, false, packet_type, 0, "WS_ExaminePartialSpellInfo");
  820. return SerializeSpell(client, display, false, packet_type, sub_packet_type, "WS_ExamineSpecialSpellInfo");
  821. }
  822. EQ2Packet* Spell::SerializeAASpell(Client* client, int8 tier, AltAdvanceData* data, bool display, bool trait_display, int8 packet_type, int8 sub_packet_type, const char* struct_name) {
  823. if (!client)
  824. return 0;
  825. int16 version = 1;
  826. if (client)
  827. version = client->GetVersion();
  828. if (!struct_name)
  829. struct_name = "WS_ExamineAASpellInfo";
  830. PacketStruct* packet = configReader.getStruct(struct_name, version);
  831. if (display)
  832. packet->setSubstructDataByName("info_header", "show_name", 1);//1
  833. else
  834. if (!trait_display)
  835. packet->setSubstructDataByName("info_header", "show_popup", 1);//1
  836. else
  837. packet->setSubstructDataByName("info_header", "show_popup", 0);
  838. if (packet_type > 0)
  839. packet->setSubstructDataByName("info_header", "packettype", packet_type * 256 + 0xFE);
  840. else
  841. packet->setSubstructDataByName("info_header", "packettype", 0x4FFE);// 0x45FE GetItemPacketType(version));
  842. //packet->setDataByName("unknown2",5);
  843. //packet->setDataByName("unknown7", 1);
  844. //packet->setDataByName("unknown9", 20);
  845. //packet->setDataByName("unknown10", 1, 2);
  846. if (sub_packet_type == 0)
  847. sub_packet_type = 0x83;
  848. packet->setSubstructDataByName("info_header", "packetsubtype", 4);// sub_packet_type);
  849. packet->setSubstructDataByName("spell_info", "aa_id", data->spellID);
  850. packet->setSubstructDataByName("spell_info", "aa_tab_id", data->group);
  851. packet->setSubstructDataByName("spell_info", "aa_icon", data->icon);
  852. packet->setSubstructDataByName("spell_info", "aa_icon2", data->icon2);
  853. packet->setSubstructDataByName("spell_info", "aa_current_rank", tier); // how to get this info to here?
  854. packet->setSubstructDataByName("spell_info", "aa_max_rank", data->maxRank);
  855. packet->setSubstructDataByName("spell_info", "aa_rank_cost", data->rankCost);
  856. packet->setSubstructDataByName("spell_info", "aa_unknown_2", 20);
  857. packet->setSubstructDataByName("spell_info", "aa_name", &(spell->name));
  858. packet->setSubstructDataByName("spell_info", "aa_description", &(spell->description));
  859. //packet->setDataByName("unknown3",2);
  860. //packet->setDataByName("unknown7", 50);
  861. if (sub_packet_type == 0x81)
  862. SetAAPacketInformation(packet, data, client);
  863. else
  864. SetAAPacketInformation(packet, data, client, true);
  865. packet->setSubstructDataByName("spell_info", "uses_remaining", 0xFFFF);
  866. packet->setSubstructDataByName("spell_info", "damage_remaining", 0xFFFF);
  867. //packet->PrintPacket();
  868. // This adds the second portion to the spell packet. Could be used for bonuses etc.?
  869. string* data1 = packet->serializeString();
  870. uchar* data2 = (uchar*)data1->c_str();
  871. uchar* ptr2 = data2;
  872. int32 size = data1->length();// *2;
  873. ////uchar* data3 = new uchar[size];
  874. ////memcpy(data3, data2, data1->length());
  875. ////uchar* ptr = data3;
  876. ////size -= 17;
  877. ////memcpy(ptr, &size, sizeof(int32));
  878. ////size += 3;
  879. ////ptr += data1->length();
  880. ////ptr2 += 14;
  881. ////memcpy(ptr, ptr2, data1->length() - 14);
  882. EQ2Packet* outapp = new EQ2Packet(OP_ClientCmdMsg, data2, size);
  883. //DumpPacket(outapp);
  884. //safe_delete_array(data3);
  885. safe_delete(packet);
  886. return outapp;
  887. /*PacketStruct* packet = configReader.getStruct("WS_ExamineAASpellInfo", client->GetVersion());
  888. packet->setSubstructDataByName("info_header", "show_name", 0);
  889. packet->setSubstructDataByName("info_header", "show_popup", 0);
  890. packet->setSubstructDataByName("info_header", "packettype", packet_type);
  891. packet->setSubstructDataByName("info_header", "packetsubtype", sub_packet_type);
  892. packet->setSubstructDataByName("Spell_info", "aa_id", data->spellID);
  893. packet->setSubstructDataByName("Spell_info", "aa_tab_id", data->group);
  894. packet->setSubstructDataByName("Spell_info", "aa_icon", data->icon);
  895. packet->setSubstructDataByName("Spell_info", "aa_icon2", data->icon2);
  896. packet->setSubstructDataByName("Spell_info", "current_rank", 0); // how to get this info to here?
  897. packet->setSubstructDataByName("Spell_info", "max_rank", data->maxRank);
  898. packet->setSubstructDataByName("Spell_info", "rank_cost", data->rankCost);
  899. packet->setSubstructDataByName("spell_info", "unknown2", 20);
  900. // Spell info
  901. packet->setSubstructDataByName("spell_info", "id", spell->id);
  902. packet->setSubstructDataByName("spell_info", "icon", spell->icon);
  903. packet->setSubstructDataByName("spell_info", "icon2", spell->icon_heroic_op); // fix struct element name eventually
  904. packet->setSubstructDataByName("spell_info", "icontype", spell->icon_backdrop); // fix struct element name eventually
  905. if (packet->GetVersion() >= 63119) {
  906. packet->setSubstructDataByName("spell_info", "version", 0x04);
  907. packet->setSubstructDataByName("spell_info", "sub_version", 0x24);
  908. }
  909. else if (packet->GetVersion() >= 1193) {
  910. packet->setSubstructDataByName("spell_info", "version", 0x00);
  911. packet->setSubstructDataByName("spell_info", "sub_version", 0xD9);
  912. }
  913. else {
  914. packet->setSubstructDataByName("spell_info", "version", 0x11);
  915. packet->setSubstructDataByName("spell_info", "sub_version", 0x14);
  916. }
  917. packet->setSubstructDataByName("spell_info", "type", spell->type);
  918. packet->setSubstructDataByName("spell_info", "unknown_MJ1d", 1); //63119 test
  919. packet->setSubstructDataByName("spell_info", "class_skill", spell->class_skill);
  920. packet->setSubstructDataByName("spell_info", "mastery_skill", spell->mastery_skill);
  921. packet->setSubstructDataByName("spell_info", "duration_flag", spell->duration_until_cancel);
  922. if (client && spell->type != 2) {
  923. sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client));
  924. if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
  925. spell_text_color = ARROW_COLOR_WHITE;
  926. spell_text_color -= 6;
  927. if (spell_text_color < 0)
  928. spell_text_color *= -1;
  929. packet->setSubstructDataByName("spell_info", "spell_text_color", spell_text_color);
  930. }
  931. else
  932. packet->setSubstructDataByName("spell_info", "spell_text_color", 3);
  933. if (spell->type != 2) {
  934. packet->setSubstructArrayLengthByName("spell_info", "num_levels", levels.size());
  935. for (int32 i = 0; i < levels.size(); i++) {
  936. packet->setArrayDataByName("adventure_class", levels[i]->adventure_class, i);
  937. packet->setArrayDataByName("tradeskill_class", levels[i]->tradeskill_class, i);
  938. packet->setArrayDataByName("spell_level", levels[i]->spell_level, i);
  939. }
  940. }
  941. //packet->setSubstructDataByName("spell_info", "unknown9", 20);
  942. int16 hp_req = 0;
  943. int16 power_req = 0;
  944. if (client) {
  945. hp_req = GetHPRequired(client->GetPlayer());
  946. power_req = GetPowerRequired(client->GetPlayer());
  947. // might need version checks around these?
  948. if (client->GetVersion() >= 1193)
  949. {
  950. int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
  951. packet->setSubstructDataByName("spell_info", "savagery_req", savagery_req);
  952. packet->setSubstructDataByName("spell_info", "savagery_upkeep", spell->savagery_upkeep);
  953. }
  954. if (client->GetVersion() >= 57048)
  955. {
  956. int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
  957. packet->setSubstructDataByName("spell_info", "dissonance_req", dissonance_req);
  958. packet->setSubstructDataByName("spell_info", "dissonance_upkeep", spell->dissonance_upkeep);
  959. }
  960. }
  961. packet->setSubstructDataByName("spell_info", "tier", spell->tier);
  962. packet->setSubstructDataByName("spell_info", "health_req", hp_req);
  963. packet->setSubstructDataByName("spell_info", "health_upkeep", spell->hp_upkeep);
  964. packet->setSubstructDataByName("spell_info", "power_req", power_req);
  965. packet->setSubstructDataByName("spell_info", "power_upkeep", spell->power_upkeep);
  966. packet->setSubstructDataByName("spell_info", "req_concentration", spell->req_concentration);
  967. //packet->setDataByName("req_concentration2", 2);
  968. packet->setSubstructDataByName("spell_info", "cast_time", spell->cast_time);
  969. packet->setSubstructDataByName("spell_info", "recovery", spell->recovery);
  970. packet->setSubstructDataByName("spell_info", "recast", spell->recast);
  971. packet->setSubstructDataByName("spell_info", "radius", spell->radius);
  972. packet->setSubstructDataByName("spell_info", "max_aoe_targets", spell->max_aoe_targets);
  973. packet->setSubstructDataByName("spell_info", "friendly_spell", spell->friendly_spell);
  974. //reageants??
  975. packet->setSubstructArrayLengthByName("spell_info", "num_effects", effects.size());
  976. for (int32 i = 0; i < effects.size(); i++) {
  977. packet->setArrayDataByName("subbulletflag", effects[i]->subbullet, i);
  978. packet->setArrayDataByName("effect", effects[i]->description.c_str(), i);
  979. packet->setArrayDataByName("percentage", effects[i]->percentage, i);
  980. }
  981. //if (display_tier == true)
  982. packet->setSubstructDataByName("spell_info", "display_spell_tier", spell->display_spell_tier);
  983. //else
  984. // packet->setSubstructDataByName("spell_info", "display_spell_tier", 0);
  985. // minimum range??
  986. packet->setSubstructDataByName("spell_info", "range", spell->range);
  987. packet->setSubstructDataByName("spell_info", "duration1", spell->duration1);
  988. packet->setSubstructDataByName("spell_info", "duration2", spell->duration2);
  989. //unknown9 ??
  990. //duration flag??
  991. packet->setSubstructDataByName("spell_info", "target", spell->target_type);
  992. packet->setSubstructDataByName("spell_info", "can_effect_raid", spell->can_effect_raid);
  993. packet->setSubstructDataByName("spell_info", "affect_only_group_members", spell->affect_only_group_members);
  994. packet->setSubstructDataByName("spell_info", "group_spell", spell->group_spell);
  995. packet->setSubstructDataByName("spell_info", "resistibility", spell->resistibility);
  996. //unknown11 ??
  997. //hit_bonus ??
  998. //unknown12 ??
  999. packet->setSubstructDataByName("spell_info", "name", &(spell->name));
  1000. packet->setSubstructDataByName("spell_info", "description", &(spell->description));
  1001. EQ2Packet* packetdata = packet->serialize();
  1002. //EQ2Packet* app = new EQ2Packet(OP_AdventureList, packetdata->pBuffer, packetdata->size);
  1003. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, packetdata->pBuffer, packetdata->size);
  1004. packet->PrintPacket();
  1005. //DumpPacket(app);
  1006. safe_delete(packet);
  1007. safe_delete(data);
  1008. return app;
  1009. */
  1010. }
  1011. EQ2Packet* Spell::SerializeSpell(Client* client, bool display, bool trait_display, int8 packet_type, int8 sub_packet_type, const char* struct_name) {
  1012. int16 version = 1;
  1013. if (client)
  1014. version = client->GetVersion();
  1015. if (!struct_name)
  1016. struct_name = "WS_ExamineSpellInfo";
  1017. if (version <= 546) {
  1018. if (packet_type == 1)
  1019. struct_name = "WS_ExamineEffectInfo";
  1020. else if (!display && version<=283)
  1021. struct_name = "WS_ExaminePartialSpellInfo";
  1022. else
  1023. struct_name = "WS_ExamineSpellInfo";
  1024. }
  1025. PacketStruct* packet = configReader.getStruct(struct_name, version);
  1026. if (display)
  1027. packet->setSubstructDataByName("info_header", "show_name", 1);
  1028. else {
  1029. if (!trait_display)
  1030. packet->setSubstructDataByName("info_header", "show_popup", 1);
  1031. else
  1032. packet->setSubstructDataByName("info_header", "show_popup", 0);
  1033. }
  1034. if (version > 546) {
  1035. if (packet_type > 0)
  1036. packet->setSubstructDataByName("info_header", "packettype", packet_type * 256 + 0xFE);
  1037. else
  1038. packet->setSubstructDataByName("info_header", "packettype", GetItemPacketType(version));
  1039. }
  1040. else {
  1041. if (packet_type == 3 || packet_type == 0)
  1042. packet->setSubstructDataByName("info_header", "packettype", 3); // 0: item, 1: effect, 2: recipe, 3: spell/ability
  1043. else
  1044. packet->setSubstructDataByName("info_header", "packettype", 1);
  1045. }
  1046. //packet->setDataByName("unknown2",5);
  1047. //packet->setDataByName("unknown7", 1);
  1048. //packet->setDataByName("unknown9", 20);
  1049. //packet->setDataByName("unknown10", 1, 2);
  1050. if (sub_packet_type == 0)
  1051. sub_packet_type = 0x83;
  1052. packet->setSubstructDataByName("info_header", "packetsubtype", sub_packet_type);
  1053. //packet->setDataByName("unknown3",2);
  1054. //packet->setDataByName("unknown7", 50);
  1055. if (sub_packet_type == 0x81)
  1056. SetPacketInformation(packet, client);
  1057. else
  1058. SetPacketInformation(packet, client, true);
  1059. packet->setSubstructDataByName("spell_info", "uses_remaining", 0xFFFF);
  1060. packet->setSubstructDataByName("spell_info", "damage_remaining", 0xFFFF);
  1061. //packet->PrintPacket();
  1062. // This adds the second portion to the spell packet. Could be used for bonuses etc.?
  1063. int8 offset = 0;
  1064. if (packet->GetVersion() == 60114) {
  1065. offset = 28;
  1066. }
  1067. else {
  1068. offset = 14;
  1069. }
  1070. EQ2Packet* outapp = 0;
  1071. if (version > 546) {
  1072. string* data1 = packet->serializeString();
  1073. uchar* data2 = (uchar*)data1->c_str();
  1074. uchar* ptr2 = data2;
  1075. int32 size = data1->length() * 2;
  1076. uchar* data3 = new uchar[size];
  1077. memcpy(data3, data2, data1->length());
  1078. uchar* ptr = data3;
  1079. size -= offset + 3;
  1080. memcpy(ptr, &size, sizeof(int32));
  1081. size += 3;
  1082. ptr += data1->length();
  1083. ptr2 += offset;
  1084. memcpy(ptr, ptr2, data1->length() - offset);
  1085. outapp = new EQ2Packet(OP_ClientCmdMsg, data3, size);
  1086. safe_delete_array(data3);
  1087. safe_delete(packet);
  1088. }
  1089. else
  1090. outapp = packet->serialize();
  1091. //DumpPacket(outapp);
  1092. return outapp;
  1093. }
  1094. void Spell::AddSpellEffect(int8 percentage, int8 subbullet, string description){
  1095. std::unique_lock lock(MSpellInfo);
  1096. SpellDisplayEffect* effect = new SpellDisplayEffect;
  1097. effect->description = description;
  1098. effect->subbullet = subbullet;
  1099. effect->percentage = percentage;
  1100. effects.push_back(effect);
  1101. }
  1102. int16 Spell::GetHPRequired(Spawn* spawn){
  1103. int16 hp_req = spell->hp_req;
  1104. if(spawn && spell->hp_req_percent > 0){
  1105. double result = ((double)spell->hp_req_percent/100)*spawn->GetTotalHP();
  1106. if(result >= (((int16)result) + .5))
  1107. result++;
  1108. hp_req = (int16)result;
  1109. }
  1110. return hp_req;
  1111. }
  1112. int16 Spell::GetPowerRequired(Spawn* spawn){
  1113. int16 power_req;
  1114. if (spell->power_by_level == true) {
  1115. power_req =round( (spell->power_req) * spawn->GetLevel());
  1116. }
  1117. else {
  1118. power_req = round(spell->power_req);
  1119. }
  1120. if(spawn && spell->power_req_percent > 0){
  1121. double result = ((double)spell->power_req_percent/100)*spawn->GetTotalPower();
  1122. if(result >= (((int16)result) + .5))
  1123. result++;
  1124. power_req = (int16)result;
  1125. }
  1126. if(spawn && spawn->IsPlayer()) {
  1127. int32 ministry_skill_id = rule_manager.GetGlobalRule(R_Spells, MinistrationSkillID)->GetInt32();
  1128. if(spell->mastery_skill == ministry_skill_id) { // ministration offers a power reduction
  1129. Skill* skill = ((Player*)spawn)->GetSkillByID(spell->mastery_skill, false);
  1130. if(skill) {
  1131. float ministry_reduction_percent = rule_manager.GetGlobalRule(R_Spells, MinistrationPowerReductionMax)->GetFloat();
  1132. if(ministry_reduction_percent <= 0.0f)
  1133. ministry_reduction_percent = 15.0f;
  1134. int32 ministration_skill_reduce = rule_manager.GetGlobalRule(R_Spells, MinistrationPowerReductionSkill)->GetInt32();
  1135. if(ministration_skill_reduce < 1)
  1136. ministration_skill_reduce = 25;
  1137. float item_stat_bonus = 0.0f;
  1138. int32 item_stat = master_item_list.GetItemStatIDByName(::ToLower(skill->name.data));
  1139. if(item_stat != 0xFFFFFFFF) {
  1140. item_stat_bonus = ((Entity*)spawn)->GetStat(item_stat);
  1141. }
  1142. float reduction = (skill->current_val + item_stat_bonus) / ministration_skill_reduce;
  1143. if(reduction > ministry_reduction_percent)
  1144. reduction = ministry_reduction_percent;
  1145. int16 power_to_reduce = (int16)(float)(power_req * (ministry_reduction_percent/100.0f)) * (reduction / ministry_reduction_percent);
  1146. if(power_to_reduce > power_req) {
  1147. power_req = 0;
  1148. }
  1149. else {
  1150. power_req = power_req - power_to_reduce;
  1151. }
  1152. }
  1153. }
  1154. float power_reduction = ((Entity*)spawn)->GetStat(ITEM_STAT_POWER_COST_REDUCTION);
  1155. if(power_reduction > 0.0f) {
  1156. int16 power_to_reduce = (int16)(float)(power_req * (power_reduction/100.0f));
  1157. if(power_to_reduce > power_req) {
  1158. power_req = 0;
  1159. }
  1160. else {
  1161. power_req = power_req - power_to_reduce;
  1162. }
  1163. }
  1164. }
  1165. return power_req;
  1166. }
  1167. int16 Spell::GetSavageryRequired(Spawn* spawn){
  1168. int16 savagery_req = spell->savagery_req;
  1169. if(spawn && spell->savagery_req_percent > 0){
  1170. double result = ((double)spell->savagery_req_percent/100)*spawn->GetTotalSavagery();
  1171. if(result >= (((int16)result) + .5))
  1172. result++;
  1173. savagery_req = (int16)result;
  1174. }
  1175. return savagery_req;
  1176. }
  1177. int16 Spell::GetDissonanceRequired(Spawn* spawn){
  1178. int16 dissonance_req = spell->dissonance_req;
  1179. if(spawn && spell->dissonance_req_percent > 0){
  1180. double result = ((double)spell->dissonance_req_percent/100)*spawn->GetTotalDissonance();
  1181. if(result >= (((int16)result) + .5))
  1182. result++;
  1183. dissonance_req = (int16)result;
  1184. }
  1185. return dissonance_req;
  1186. }
  1187. int32 Spell::GetSpellDuration(){
  1188. if(spell->duration1 == spell->duration2)
  1189. return spell->duration1;
  1190. int32 difference = 0;
  1191. int32 lower = 0;
  1192. if(spell->duration2 > spell->duration1){
  1193. difference = spell->duration2 - spell->duration1;
  1194. lower = spell->duration1;
  1195. }
  1196. else{
  1197. difference = spell->duration1 - spell->duration2;
  1198. lower = spell->duration2;
  1199. }
  1200. int32 duration = (rand()%difference) + lower;
  1201. return duration;
  1202. }
  1203. const char* Spell::GetName(){
  1204. return spell->name.data.c_str();
  1205. }
  1206. const char* Spell::GetDescription(){
  1207. return spell->description.data.c_str();
  1208. }
  1209. void Spell::AddSpellLevel(int8 adventure_class, int8 tradeskill_class, int16 level){
  1210. std::unique_lock lock(MSpellInfo);
  1211. LevelArray* lvl = new LevelArray;
  1212. lvl->adventure_class = adventure_class;
  1213. lvl->tradeskill_class = tradeskill_class;
  1214. lvl->spell_level = level;
  1215. levels.push_back(lvl);
  1216. }
  1217. int32 Spell::GetSpellID(){
  1218. if (spell)
  1219. return spell->id;
  1220. return 0;
  1221. }
  1222. int8 Spell::GetSpellTier(){
  1223. if (spell)
  1224. return spell->tier;
  1225. return 0;
  1226. }
  1227. vector<LUAData*>* Spell::GetLUAData(){
  1228. return &lua_data;
  1229. }
  1230. SpellData* Spell::GetSpellData(){
  1231. return spell;
  1232. }
  1233. bool Spell::GetSpellData(lua_State* state, std::string field)
  1234. {
  1235. if (!lua_interface)
  1236. return false;
  1237. bool valSet = false;
  1238. if (field == "spell_book_type")
  1239. {
  1240. lua_interface->SetInt32Value(state, GetSpellData()->spell_book_type);
  1241. valSet = true;
  1242. }
  1243. else if (field == "icon")
  1244. {
  1245. lua_interface->SetSInt32Value(state, GetSpellData()->icon);
  1246. valSet = true;
  1247. }
  1248. else if (field == "icon_heroic_op")
  1249. {
  1250. lua_interface->SetInt32Value(state, GetSpellData()->icon_heroic_op);
  1251. valSet = true;
  1252. }
  1253. else if (field == "icon_backdrop")
  1254. {
  1255. lua_interface->SetInt32Value(state, GetSpellData()->icon_backdrop);
  1256. valSet = true;
  1257. }
  1258. else if (field == "type")
  1259. {
  1260. lua_interface->SetInt32Value(state, GetSpellData()->type);
  1261. valSet = true;
  1262. }
  1263. else if (field == "class_skill")
  1264. {
  1265. lua_interface->SetInt32Value(state, GetSpellData()->class_skill);
  1266. valSet = true;
  1267. }
  1268. else if (field == "min_class_skill_req")
  1269. {
  1270. lua_interface->SetInt32Value(state, GetSpellData()->min_class_skill_req);
  1271. valSet = true;
  1272. }
  1273. else if (field == "mastery_skill")
  1274. {
  1275. lua_interface->SetInt32Value(state, GetSpellData()->mastery_skill);
  1276. valSet = true;
  1277. }
  1278. else if (field == "ts_loc_index")
  1279. {
  1280. lua_interface->SetSInt32Value(state, GetSpellData()->ts_loc_index);
  1281. valSet = true;
  1282. }
  1283. else if (field == "num_levels")
  1284. {
  1285. lua_interface->SetSInt32Value(state, GetSpellData()->num_levels);
  1286. valSet = true;
  1287. }
  1288. else if (field == "tier")
  1289. {
  1290. lua_interface->SetSInt32Value(state, GetSpellData()->tier);
  1291. valSet = true;
  1292. }
  1293. else if (field == "hp_req")
  1294. {
  1295. lua_interface->SetSInt32Value(state, GetSpellData()->hp_req);
  1296. valSet = true;
  1297. }
  1298. else if (field == "hp_upkeep")
  1299. {
  1300. lua_interface->SetSInt32Value(state, GetSpellData()->hp_upkeep);
  1301. valSet = true;
  1302. }
  1303. else if (field == "power_req")
  1304. {
  1305. lua_interface->SetFloatValue(state, GetSpellData()->power_req);
  1306. valSet = true;
  1307. }
  1308. else if (field == "power_by_level")
  1309. {
  1310. lua_interface->SetBooleanValue(state, GetSpellData()->power_by_level);
  1311. valSet = true;
  1312. }
  1313. else if (field == "power_upkeep")
  1314. {
  1315. lua_interface->SetSInt32Value(state, GetSpellData()->power_upkeep);
  1316. valSet = true;
  1317. }
  1318. else if (field == "savagery_req")
  1319. {
  1320. lua_interface->SetSInt32Value(state, GetSpellData()->savagery_req);
  1321. valSet = true;
  1322. }
  1323. else if (field == "savagery_upkeep")
  1324. {
  1325. lua_interface->SetSInt32Value(state, GetSpellData()->savagery_upkeep);
  1326. valSet = true;
  1327. }
  1328. else if (field == "dissonance_req")
  1329. {
  1330. lua_interface->SetSInt32Value(state, GetSpellData()->dissonance_req);
  1331. valSet = true;
  1332. }
  1333. else if (field == "dissonance_upkeep")
  1334. {
  1335. lua_interface->SetSInt32Value(state, GetSpellData()->dissonance_upkeep);
  1336. valSet = true;
  1337. }
  1338. else if (field == "target_type")
  1339. {
  1340. lua_interface->SetSInt32Value(state, GetSpellData()->target_type);
  1341. valSet = true;
  1342. }
  1343. else if (field == "cast_time")
  1344. {
  1345. lua_interface->SetSInt32Value(state, GetSpellData()->cast_time);
  1346. valSet = true;
  1347. }
  1348. else if (field == "recovery")
  1349. {
  1350. lua_interface->SetFloatValue(state, GetSpellData()->recovery);
  1351. valSet = true;
  1352. }
  1353. else if (field == "recast")
  1354. {
  1355. lua_interface->SetFloatValue(state, GetSpellData()->recast);
  1356. valSet = true;
  1357. }
  1358. else if (field == "linked_timer")
  1359. {
  1360. lua_interface->SetSInt32Value(state, GetSpellData()->linked_timer);
  1361. valSet = true;
  1362. }
  1363. else if (field == "radius")
  1364. {
  1365. lua_interface->SetFloatValue(state, GetSpellData()->radius);
  1366. valSet = true;
  1367. }
  1368. else if (field == "max_aoe_targets")
  1369. {
  1370. lua_interface->SetSInt32Value(state, GetSpellData()->max_aoe_targets);
  1371. valSet = true;
  1372. }
  1373. else if (field == "friendly_spell")
  1374. {
  1375. lua_interface->SetSInt32Value(state, GetSpellData()->friendly_spell);
  1376. valSet = true;
  1377. }
  1378. else if (field == "req_concentration")
  1379. {
  1380. lua_interface->SetSInt32Value(state, GetSpellData()->req_concentration);
  1381. valSet = true;
  1382. }
  1383. else if (field == "range")
  1384. {
  1385. lua_interface->SetFloatValue(state, GetSpellData()->range);
  1386. valSet = true;
  1387. }
  1388. else if (field == "duration1")
  1389. {
  1390. lua_interface->SetSInt32Value(state, GetSpellData()->duration1);
  1391. valSet = true;
  1392. }
  1393. else if (field == "duration2")
  1394. {
  1395. lua_interface->SetSInt32Value(state, GetSpellData()->duration2);
  1396. valSet = true;
  1397. }
  1398. else if (field == "resistibility")
  1399. {
  1400. lua_interface->SetFloatValue(state, GetSpellData()->resistibility);
  1401. valSet = true;
  1402. }
  1403. else if (field == "duration_until_cancel")
  1404. {
  1405. lua_interface->SetBooleanValue(state, GetSpellData()->duration_until_cancel);
  1406. valSet = true;
  1407. }
  1408. else if (field == "power_req_percent")
  1409. {
  1410. lua_interface->SetSInt32Value(state, GetSpellData()->power_req_percent);
  1411. valSet = true;
  1412. }
  1413. else if (field == "hp_req_percent")
  1414. {
  1415. lua_interface->SetSInt32Value(state, GetSpellData()->hp_req_percent);
  1416. valSet = true;
  1417. }
  1418. else if (field == "savagery_req_percent")
  1419. {
  1420. lua_interface->SetSInt32Value(state, GetSpellData()->savagery_req_percent);
  1421. valSet = true;
  1422. }
  1423. else if (field == "dissonance_req_percent")
  1424. {
  1425. lua_interface->SetSInt32Value(state, GetSpellData()->dissonance_req_percent);
  1426. valSet = true;
  1427. }
  1428. else if (field == "name")
  1429. {
  1430. lua_interface->SetStringValue(state, GetSpellData()->name.data.c_str());
  1431. valSet = true;
  1432. }
  1433. else if (field == "description")
  1434. {
  1435. lua_interface->SetStringValue(state, GetSpellData()->description.data.c_str());
  1436. valSet = true;
  1437. }
  1438. else if (field == "success_message")
  1439. {
  1440. lua_interface->SetStringValue(state, GetSpellData()->success_message.c_str());
  1441. valSet = true;
  1442. }
  1443. else if (field == "fade_message")
  1444. {
  1445. lua_interface->SetStringValue(state, GetSpellData()->fade_message.c_str());
  1446. valSet = true;
  1447. }
  1448. else if (field == "fade_message_others")
  1449. {
  1450. lua_interface->SetStringValue(state, GetSpellData()->fade_message_others.c_str());
  1451. valSet = true;
  1452. }
  1453. else if (field == "cast_type")
  1454. {
  1455. lua_interface->SetSInt32Value(state, GetSpellData()->cast_type);
  1456. valSet = true;
  1457. }
  1458. else if (field == "lua_script")
  1459. {
  1460. lua_interface->SetStringValue(state, GetSpellData()->lua_script.c_str());
  1461. valSet = true;
  1462. }
  1463. else if (field == "interruptable")
  1464. {
  1465. lua_interface->SetBooleanValue(state, GetSpellData()->interruptable);
  1466. valSet = true;
  1467. }
  1468. else if (field == "spell_visual")
  1469. {
  1470. lua_interface->SetSInt32Value(state, GetSpellData()->spell_visual);
  1471. valSet = true;
  1472. }
  1473. else if (field == "effect_message")
  1474. {
  1475. lua_interface->SetStringValue(state, GetSpellData()->effect_message.c_str());
  1476. valSet = true;
  1477. }
  1478. else if (field == "min_range")
  1479. {
  1480. lua_interface->SetFloatValue(state, GetSpellData()->min_range);
  1481. valSet = true;
  1482. }
  1483. else if (field == "can_effect_raid")
  1484. {
  1485. lua_interface->SetSInt32Value(state, GetSpellData()->can_effect_raid);
  1486. valSet = true;
  1487. }
  1488. else if (field == "affect_only_group_members")
  1489. {
  1490. lua_interface->SetSInt32Value(state, GetSpellData()->affect_only_group_members);
  1491. valSet = true;
  1492. }
  1493. else if (field == "group_spell")
  1494. {
  1495. lua_interface->SetSInt32Value(state, GetSpellData()->group_spell);
  1496. valSet = true;
  1497. }
  1498. else if (field == "hit_bonus")
  1499. {
  1500. lua_interface->SetFloatValue(state, GetSpellData()->hit_bonus);
  1501. valSet = true;
  1502. }
  1503. else if (field == "display_spell_tier")
  1504. {
  1505. lua_interface->SetSInt32Value(state, GetSpellData()->display_spell_tier);
  1506. valSet = true;
  1507. }
  1508. else if (field == "is_active")
  1509. {
  1510. lua_interface->SetSInt32Value(state, GetSpellData()->is_active);
  1511. valSet = true;
  1512. }
  1513. else if (field == "det_type")
  1514. {
  1515. lua_interface->SetSInt32Value(state, GetSpellData()->det_type);
  1516. valSet = true;
  1517. }
  1518. else if (field == "incurable")
  1519. {
  1520. lua_interface->SetBooleanValue(state, GetSpellData()->incurable);
  1521. valSet = true;
  1522. }
  1523. else if (field == "control_effect_type")
  1524. {
  1525. lua_interface->SetSInt32Value(state, GetSpellData()->control_effect_type);
  1526. valSet = true;
  1527. }
  1528. else if (field == "casting_flags")
  1529. {
  1530. lua_interface->SetSInt32Value(state, GetSpellData()->casting_flags);
  1531. valSet = true;
  1532. }
  1533. else if (field == "cast_while_moving")
  1534. {
  1535. lua_interface->SetBooleanValue(state, GetSpellData()->cast_while_moving);
  1536. valSet = true;
  1537. }
  1538. else if (field == "persist_through_death")
  1539. {
  1540. lua_interface->SetBooleanValue(state, GetSpellData()->persist_through_death);
  1541. valSet = true;
  1542. }
  1543. else if (field == "not_maintained")
  1544. {
  1545. lua_interface->SetBooleanValue(state, GetSpellData()->not_maintained);
  1546. valSet = true;
  1547. }
  1548. else if (field == "is_aa")
  1549. {
  1550. lua_interface->SetBooleanValue(state, GetSpellData()->is_aa);
  1551. valSet = true;
  1552. }
  1553. else if (field == "savage_bar")
  1554. {
  1555. lua_interface->SetSInt32Value(state, GetSpellData()->savage_bar);
  1556. valSet = true;
  1557. }
  1558. else if (field == "savage_bar_slot")
  1559. {
  1560. lua_interface->SetSInt32Value(state, GetSpellData()->savage_bar_slot);
  1561. valSet = true;
  1562. }
  1563. else if (field == "soe_spell_crc")
  1564. {
  1565. lua_interface->SetSInt32Value(state, GetSpellData()->soe_spell_crc);
  1566. valSet = true;
  1567. }
  1568. else if (field == "spell_type")
  1569. {
  1570. lua_interface->SetSInt32Value(state, GetSpellData()->spell_type);
  1571. valSet = true;
  1572. }
  1573. else if (field == "spell_name_crc")
  1574. {
  1575. lua_interface->SetSInt32Value(state, GetSpellData()->spell_name_crc);
  1576. valSet = true;
  1577. }
  1578. else if (field == "type_group_spell_id")
  1579. {
  1580. lua_interface->SetSInt32Value(state, GetSpellData()->type_group_spell_id);
  1581. valSet = true;
  1582. }
  1583. else if (field == "can_fizzle")
  1584. {
  1585. lua_interface->SetBooleanValue(state, GetSpellData()->can_fizzle);
  1586. valSet = true;
  1587. }
  1588. return valSet;
  1589. }
  1590. bool Spell::SetSpellData(lua_State* state, std::string field, int8 fieldArg)
  1591. {
  1592. if (!lua_interface)
  1593. return false;
  1594. bool valSet = false;
  1595. if (field == "spell_book_type")
  1596. {
  1597. int32 spell_book_type = lua_interface->GetInt32Value(state, fieldArg);
  1598. GetSpellData()->spell_book_type = spell_book_type;
  1599. valSet = true;
  1600. }
  1601. else if (field == "icon")
  1602. {
  1603. sint16 icon = lua_interface->GetSInt32Value(state, fieldArg);
  1604. GetSpellData()->icon = icon;
  1605. valSet = true;
  1606. }
  1607. else if (field == "icon_heroic_op")
  1608. {
  1609. int16 icon_heroic_op = lua_interface->GetInt16Value(state, fieldArg);
  1610. GetSpellData()->icon_heroic_op = icon_heroic_op;
  1611. valSet = true;
  1612. }
  1613. else if (field == "icon_backdrop")
  1614. {
  1615. int16 icon_backdrop = lua_interface->GetInt16Value(state, fieldArg);
  1616. GetSpellData()->icon_backdrop = icon_backdrop;
  1617. valSet = true;
  1618. }
  1619. else if (field == "type")
  1620. {
  1621. int16 type = lua_interface->GetInt16Value(state, fieldArg);
  1622. GetSpellData()->type = type;
  1623. valSet = true;
  1624. }
  1625. else if (field == "class_skill")
  1626. {
  1627. int32 class_skill = lua_interface->GetInt32Value(state, fieldArg);
  1628. GetSpellData()->class_skill = class_skill;
  1629. valSet = true;
  1630. }
  1631. else if (field == "min_class_skill_req")
  1632. {
  1633. int16 min_class_skill_req = lua_interface->GetInt16Value(state, fieldArg);
  1634. GetSpellData()->min_class_skill_req = min_class_skill_req;
  1635. valSet = true;
  1636. }
  1637. else if (field == "mastery_skill")
  1638. {
  1639. int32 mastery_skill = lua_interface->GetInt32Value(state, fieldArg);
  1640. GetSpellData()->mastery_skill = mastery_skill;
  1641. valSet = true;
  1642. }
  1643. else if (field == "ts_loc_index")
  1644. {
  1645. int8 ts_loc_index = lua_interface->GetInt8Value(state, fieldArg);
  1646. GetSpellData()->ts_loc_index = ts_loc_index;
  1647. valSet = true;
  1648. }
  1649. else if (field == "num_levels")
  1650. {
  1651. int8 num_levels = lua_interface->GetInt8Value(state, fieldArg);
  1652. GetSpellData()->num_levels = num_levels;
  1653. valSet = true;
  1654. }
  1655. else if (field == "tier")
  1656. {
  1657. int8 tier = lua_interface->GetInt8Value(state, fieldArg);
  1658. GetSpellData()->tier = tier;
  1659. valSet = true;
  1660. }
  1661. else if (field == "hp_req")
  1662. {
  1663. int16 hp_req = lua_interface->GetInt16Value(state, fieldArg);
  1664. GetSpellData()->hp_req = hp_req;
  1665. valSet = true;
  1666. }
  1667. else if (field == "hp_upkeep")
  1668. {
  1669. int16 hp_upkeep = lua_interface->GetInt16Value(state, fieldArg);
  1670. GetSpellData()->hp_upkeep = hp_upkeep;
  1671. valSet = true;
  1672. }
  1673. else if (field == "power_req")
  1674. {
  1675. float power_req = lua_interface->GetFloatValue(state, fieldArg);
  1676. GetSpellData()->power_req = power_req;
  1677. valSet = true;
  1678. }
  1679. else if (field == "power_by_level")
  1680. {
  1681. bool power_by_level = lua_interface->GetBooleanValue(state, fieldArg);
  1682. GetSpellData()->power_by_level = power_by_level;
  1683. valSet = true;
  1684. }
  1685. else if (field == "power_upkeep")
  1686. {
  1687. int16 power_upkeep = lua_interface->GetInt16Value(state, fieldArg);
  1688. GetSpellData()->power_upkeep = power_upkeep;
  1689. valSet = true;
  1690. }
  1691. else if (field == "savagery_req")
  1692. {
  1693. int16 savagery_req = lua_interface->GetInt16Value(state, fieldArg);
  1694. GetSpellData()->savagery_req = savagery_req;
  1695. valSet = true;
  1696. }
  1697. else if (field == "savagery_upkeep")
  1698. {
  1699. int16 savagery_upkeep = lua_interface->GetInt16Value(state, fieldArg);
  1700. GetSpellData()->savagery_upkeep = savagery_upkeep;
  1701. valSet = true;
  1702. }
  1703. else if (field == "dissonance_req")
  1704. {
  1705. int16 dissonance_req = lua_interface->GetInt16Value(state, fieldArg);
  1706. GetSpellData()->dissonance_req = dissonance_req;
  1707. valSet = true;
  1708. }
  1709. else if (field == "dissonance_upkeep")
  1710. {
  1711. int16 dissonance_upkeep = lua_interface->GetInt16Value(state, fieldArg);
  1712. GetSpellData()->dissonance_upkeep = dissonance_upkeep;
  1713. valSet = true;
  1714. }
  1715. else if (field == "target_type")
  1716. {
  1717. int16 target_type = lua_interface->GetInt8Value(state, fieldArg);
  1718. GetSpellData()->target_type = target_type;
  1719. valSet = true;
  1720. }
  1721. else if (field == "cast_time")
  1722. {
  1723. int16 cast_time = lua_interface->GetInt16Value(state, fieldArg);
  1724. GetSpellData()->cast_time = cast_time;
  1725. valSet = true;
  1726. }
  1727. else if (field == "recovery")
  1728. {
  1729. float recovery = lua_interface->GetFloatValue(state, fieldArg);
  1730. GetSpellData()->recovery = recovery;
  1731. valSet = true;
  1732. }
  1733. else if (field == "recast")
  1734. {
  1735. float recast = lua_interface->GetFloatValue(state, fieldArg);
  1736. GetSpellData()->recast = recast;
  1737. valSet = true;
  1738. }
  1739. else if (field == "linked_timer")
  1740. {
  1741. int32 linked_timer = lua_interface->GetInt32Value(state, fieldArg);
  1742. GetSpellData()->linked_timer = linked_timer;
  1743. valSet = true;
  1744. }
  1745. else if (field == "radius")
  1746. {
  1747. float radius = lua_interface->GetFloatValue(state, fieldArg);
  1748. GetSpellData()->radius = radius;
  1749. valSet = true;
  1750. }
  1751. else if (field == "max_aoe_targets")
  1752. {
  1753. int16 max_aoe_targets = lua_interface->GetInt16Value(state, fieldArg);
  1754. GetSpellData()->max_aoe_targets = max_aoe_targets;
  1755. valSet = true;
  1756. }
  1757. else if (field == "friendly_spell")
  1758. {
  1759. int8 friendly_spell = lua_interface->GetInt8Value(state, fieldArg);
  1760. GetSpellData()->friendly_spell = friendly_spell;
  1761. valSet = true;
  1762. }
  1763. else if (field == "req_concentration")
  1764. {
  1765. int16 req_concentration = lua_interface->GetInt16Value(state, fieldArg);
  1766. GetSpellData()->req_concentration = req_concentration;
  1767. valSet = true;
  1768. }
  1769. else if (field == "range")
  1770. {
  1771. float range = lua_interface->GetFloatValue(state, fieldArg);
  1772. GetSpellData()->range = range;
  1773. valSet = true;
  1774. }
  1775. else if (field == "duration1")
  1776. {
  1777. sint32 duration = lua_interface->GetSInt32Value(state, fieldArg);
  1778. GetSpellData()->duration1 = duration;
  1779. valSet = true;
  1780. }
  1781. else if (field == "duration2")
  1782. {
  1783. sint32 duration = lua_interface->GetSInt32Value(state, fieldArg);
  1784. GetSpellData()->duration2 = duration;
  1785. valSet = true;
  1786. }
  1787. else if (field == "resistibility")
  1788. {
  1789. float resistibility = lua_interface->GetFloatValue(state, fieldArg);
  1790. GetSpellData()->resistibility = resistibility;
  1791. valSet = true;
  1792. }
  1793. else if (field == "duration_until_cancel")
  1794. {
  1795. bool duration_until_cancel = lua_interface->GetBooleanValue(state, fieldArg);
  1796. GetSpellData()->duration_until_cancel = duration_until_cancel;
  1797. valSet = true;
  1798. }
  1799. else if (field == "power_req_percent")
  1800. {
  1801. int8 power_req_percent = lua_interface->GetInt8Value(state, fieldArg);
  1802. GetSpellData()->power_req_percent = power_req_percent;
  1803. valSet = true;
  1804. }
  1805. else if (field == "hp_req_percent")
  1806. {
  1807. int8 hp_req_percent = lua_interface->GetInt8Value(state, fieldArg);
  1808. GetSpellData()->hp_req_percent = hp_req_percent;
  1809. valSet = true;
  1810. }
  1811. else if (field == "savagery_req_percent")
  1812. {
  1813. int8 savagery_req_percent = lua_interface->GetInt8Value(state, fieldArg);
  1814. GetSpellData()->savagery_req_percent = savagery_req_percent;
  1815. valSet = true;
  1816. }
  1817. else if (field == "dissonance_req_percent")
  1818. {
  1819. int8 dissonance_req_percent = lua_interface->GetInt8Value(state, fieldArg);
  1820. GetSpellData()->dissonance_req_percent = dissonance_req_percent;
  1821. valSet = true;
  1822. }
  1823. else if (field == "name")
  1824. {
  1825. string name = lua_interface->GetStringValue(state, fieldArg);
  1826. GetSpellData()->name.data = name;
  1827. valSet = true;
  1828. }
  1829. else if (field == "description")
  1830. {
  1831. string description = lua_interface->GetStringValue(state, fieldArg);
  1832. GetSpellData()->description.data = description;
  1833. valSet = true;
  1834. }
  1835. else if (field == "success_message")
  1836. {
  1837. string success_message = lua_interface->GetStringValue(state, fieldArg);
  1838. GetSpellData()->success_message = success_message;
  1839. valSet = true;
  1840. }
  1841. else if (field == "fade_message")
  1842. {
  1843. string fade_message = lua_interface->GetStringValue(state, fieldArg);
  1844. GetSpellData()->fade_message = fade_message;
  1845. valSet = true;
  1846. }
  1847. else if (field == "fade_message_others")
  1848. {
  1849. string fade_message_others = lua_interface->GetStringValue(state, fieldArg);
  1850. GetSpellData()->fade_message_others = fade_message_others;
  1851. valSet = true;
  1852. }
  1853. else if (field == "cast_type")
  1854. {
  1855. int8 cast_type = lua_interface->GetInt8Value(state, fieldArg);
  1856. GetSpellData()->cast_type = cast_type;
  1857. valSet = true;
  1858. }
  1859. else if (field == "cast_type")
  1860. {
  1861. int32 call_frequency = lua_interface->GetInt32Value(state, fieldArg);
  1862. GetSpellData()->call_frequency = call_frequency;
  1863. valSet = true;
  1864. }
  1865. else if (field == "interruptable")
  1866. {
  1867. bool interruptable = lua_interface->GetBooleanValue(state, fieldArg);
  1868. GetSpellData()->interruptable = interruptable;
  1869. valSet = true;
  1870. }
  1871. else if (field == "spell_visual")
  1872. {
  1873. int32 spell_visual = lua_interface->GetInt32Value(state, fieldArg);
  1874. GetSpellData()->spell_visual = spell_visual;
  1875. valSet = true;
  1876. }
  1877. else if (field == "effect_message")
  1878. {
  1879. string effect_message = lua_interface->GetStringValue(state, fieldArg);
  1880. GetSpellData()->effect_message = effect_message;
  1881. valSet = true;
  1882. }
  1883. else if (field == "min_range")
  1884. {
  1885. float min_range = lua_interface->GetFloatValue(state, fieldArg);
  1886. GetSpellData()->min_range = min_range;
  1887. valSet = true;
  1888. }
  1889. else if (field == "can_effect_raid")
  1890. {
  1891. int8 can_effect_raid = lua_interface->GetInt8Value(state, fieldArg);
  1892. GetSpellData()->can_effect_raid = can_effect_raid;
  1893. valSet = true;
  1894. }
  1895. else if (field == "affect_only_group_members")
  1896. {
  1897. int8 affect_only_group_members = lua_interface->GetInt8Value(state, fieldArg);
  1898. GetSpellData()->affect_only_group_members = affect_only_group_members;
  1899. valSet = true;
  1900. }
  1901. else if (field == "group_spell")
  1902. {
  1903. int8 group_spell = lua_interface->GetInt8Value(state, fieldArg);
  1904. GetSpellData()->group_spell = group_spell;
  1905. valSet = true;
  1906. }
  1907. else if (field == "hit_bonus")
  1908. {
  1909. float hit_bonus = lua_interface->GetFloatValue(state, fieldArg);
  1910. GetSpellData()->hit_bonus = hit_bonus;
  1911. valSet = true;
  1912. }
  1913. else if (field == "display_spell_tier")
  1914. {
  1915. int8 display_spell_tier = lua_interface->GetInt8Value(state, fieldArg);
  1916. GetSpellData()->display_spell_tier = display_spell_tier;
  1917. valSet = true;
  1918. }
  1919. else if (field == "is_active")
  1920. {
  1921. int8 is_active = lua_interface->GetInt8Value(state, fieldArg);
  1922. GetSpellData()->is_active = is_active;
  1923. valSet = true;
  1924. }
  1925. else if (field == "det_type")
  1926. {
  1927. int8 det_type = lua_interface->GetInt8Value(state, fieldArg);
  1928. GetSpellData()->det_type = det_type;
  1929. valSet = true;
  1930. }
  1931. else if (field == "incurable")
  1932. {
  1933. bool incurable = lua_interface->GetBooleanValue(state, fieldArg);
  1934. GetSpellData()->incurable = incurable;
  1935. valSet = true;
  1936. }
  1937. else if (field == "control_effect_type")
  1938. {
  1939. int8 control_effect_type = lua_interface->GetInt8Value(state, fieldArg);
  1940. GetSpellData()->control_effect_type = control_effect_type;
  1941. valSet = true;
  1942. }
  1943. else if (field == "casting_flags")
  1944. {
  1945. int32 casting_flags = lua_interface->GetInt32Value(state, fieldArg);
  1946. GetSpellData()->casting_flags = casting_flags;
  1947. valSet = true;
  1948. }
  1949. else if (field == "cast_while_moving")
  1950. {
  1951. bool cast_while_moving = lua_interface->GetBooleanValue(state, fieldArg);
  1952. GetSpellData()->cast_while_moving = cast_while_moving;
  1953. valSet = true;
  1954. }
  1955. else if (field == "persist_through_death")
  1956. {
  1957. bool persist_through_death = lua_interface->GetBooleanValue(state, fieldArg);
  1958. GetSpellData()->persist_through_death = persist_through_death;
  1959. valSet = true;
  1960. }
  1961. else if (field == "not_maintained")
  1962. {
  1963. bool not_maintained = lua_interface->GetBooleanValue(state, fieldArg);
  1964. GetSpellData()->not_maintained = not_maintained;
  1965. valSet = true;
  1966. }
  1967. else if (field == "is_aa")
  1968. {
  1969. bool is_aa = lua_interface->GetBooleanValue(state, fieldArg);
  1970. GetSpellData()->is_aa = is_aa;
  1971. valSet = true;
  1972. }
  1973. else if (field == "savage_bar")
  1974. {
  1975. int8 savage_bar = lua_interface->GetInt8Value(state, fieldArg);
  1976. GetSpellData()->savage_bar = savage_bar;
  1977. valSet = true;
  1978. }
  1979. else if (field == "spell_type")
  1980. {
  1981. int8 spell_type = lua_interface->GetInt8Value(state, fieldArg);
  1982. GetSpellData()->spell_type = spell_type;
  1983. valSet = true;
  1984. }
  1985. else if (field == "type_group_spell_id")
  1986. {
  1987. sint32 type_group_spell_id = lua_interface->GetSInt32Value(state, fieldArg);
  1988. GetSpellData()->type_group_spell_id = type_group_spell_id;
  1989. valSet = true;
  1990. }
  1991. else if (field == "can_fizzle")
  1992. {
  1993. bool can_fizzle = lua_interface->GetBooleanValue(state, fieldArg);
  1994. GetSpellData()->can_fizzle = can_fizzle;
  1995. valSet = true;
  1996. }
  1997. return valSet;
  1998. }
  1999. int16 Spell::GetSpellIcon(){
  2000. if (spell)
  2001. return spell->icon;
  2002. return 0;
  2003. }
  2004. int16 Spell::GetSpellIconBackdrop(){
  2005. if (spell)
  2006. return spell->icon_backdrop;
  2007. return 0;
  2008. }
  2009. int16 Spell::GetSpellIconHeroicOp(){
  2010. if (spell)
  2011. return spell->icon_heroic_op;
  2012. return 0;
  2013. }
  2014. bool Spell::IsHealSpell(){
  2015. return heal_spell;
  2016. }
  2017. bool Spell::IsBuffSpell(){
  2018. return buff_spell;
  2019. }
  2020. bool Spell::IsDamageSpell(){
  2021. return damage_spell;
  2022. }
  2023. bool Spell::IsControlSpell(){
  2024. return control_spell;
  2025. }
  2026. bool Spell::IsOffenseSpell() {
  2027. return offense_spell;
  2028. }
  2029. bool Spell::IsCopiedSpell() {
  2030. return copied_spell;
  2031. }
  2032. void Spell::ModifyCastTime(Entity* caster){
  2033. int16 cast_time = spell->cast_time;
  2034. float cast_speed = caster->GetInfoStruct()->get_casting_speed();
  2035. if (cast_time > 0){
  2036. if (cast_speed > 0) // casting speed can only reduce up to half a cast time
  2037. spell->cast_time *= max((float) 0.5, (float) (1 / (1 + (cast_speed * .01))));
  2038. else if (cast_speed < 0) // not sure if casting speed debuff is capped on live or not, capping at 1.5 * the normal rate for now
  2039. spell->cast_time *= min((float) 1.5, (float) (1 + (1 - (1 / (1 + (cast_speed * -.01))))));
  2040. }
  2041. }
  2042. vector <SpellDisplayEffect*>* Spell::GetSpellEffects(){
  2043. std::shared_lock lock(MSpellInfo);
  2044. vector <SpellDisplayEffect*>* ret = &effects;
  2045. return ret;
  2046. }
  2047. vector <LevelArray*>* Spell::GetSpellLevels(){
  2048. std::shared_lock lock(MSpellInfo);
  2049. vector <LevelArray*>* ret = &levels;
  2050. return ret;
  2051. }
  2052. bool Spell::ScribeAllowed(Player* player){
  2053. std::shared_lock lock(MSpellInfo);
  2054. bool ret = false;
  2055. if(player){
  2056. for(int32 i=0;!ret && i<levels.size();i++){
  2057. int16 mylevel = player->GetLevel();
  2058. int16 spelllevels = levels[i]->spell_level;
  2059. bool advlev = player->GetAdventureClass() == levels[i]->adventure_class;
  2060. bool tslev = player->GetTradeskillClass() == levels[i]->tradeskill_class;
  2061. bool levelmatch = player->GetLevel() >= levels[i]->spell_level;
  2062. if((player->GetAdventureClass() == levels[i]->adventure_class || player->GetTradeskillClass() == levels[i]->tradeskill_class) && player->GetLevel() >= levels[i]->spell_level/10)
  2063. ret = true;
  2064. }
  2065. }
  2066. return ret;
  2067. }
  2068. MasterSpellList::MasterSpellList(){
  2069. max_spell_id = 0;
  2070. MMasterSpellList.SetName("MasterSpellList::MMasterSpellList");
  2071. }
  2072. MasterSpellList::~MasterSpellList(){
  2073. DestroySpells();
  2074. }
  2075. void MasterSpellList::DestroySpells(){
  2076. spell_errors.clear();
  2077. MMasterSpellList.lock();
  2078. map<int32, map<int32, Spell*> >::iterator iter;
  2079. map<int32, Spell*>::iterator iter2;
  2080. for(iter = spell_list.begin();iter != spell_list.end(); iter++){
  2081. for(iter2 = iter->second.begin();iter2 != iter->second.end(); iter2++){
  2082. safe_delete(iter2->second);
  2083. }
  2084. }
  2085. spell_list.clear();
  2086. for(int i=0;i<MAX_CLASSES;i++) {
  2087. class_spell_list[i].clear();
  2088. }
  2089. MMasterSpellList.unlock();
  2090. }
  2091. void MasterSpellList::AddSpell(int32 id, int8 tier, Spell* spell){
  2092. MMasterSpellList.lock();
  2093. spell_list[id][tier] = spell;
  2094. vector<LevelArray*>* levels = spell->GetSpellLevels();
  2095. LevelArray* level = 0;
  2096. vector<LevelArray*>::iterator level_itr;
  2097. for(level_itr = levels->begin(); level_itr != levels->end(); level_itr++){
  2098. level = *level_itr;
  2099. if(level->adventure_class && level->adventure_class < MAX_CLASSES){
  2100. class_spell_list[level->adventure_class][id][tier] = spell;
  2101. }
  2102. if(level->tradeskill_class && level->tradeskill_class < MAX_CLASSES) {
  2103. class_spell_list[level->tradeskill_class][id][tier] = spell;
  2104. }
  2105. }
  2106. spell_name_map[spell->GetName()] = spell;
  2107. spell_soecrc_map[spell->GetSpellData()->soe_spell_crc] = spell;
  2108. if (id > max_spell_id)
  2109. max_spell_id = id;
  2110. MMasterSpellList.unlock();
  2111. }
  2112. Spell* MasterSpellList::GetSpell(int32 id, int8 tier){
  2113. if (spell_list.count(id) > 0 && spell_list[id].count(tier) > 0)
  2114. return spell_list[id][tier];
  2115. else if (spell_list.count(id) > 0 && tier == 0 && spell_list[id].count(1) > 0)
  2116. return spell_list[id][1];
  2117. return 0;
  2118. }
  2119. Spell* MasterSpellList::GetSpellByName(const char* name){
  2120. if(spell_name_map.count(name) > 0)
  2121. return spell_name_map[name];
  2122. return 0;
  2123. }
  2124. Spell* MasterSpellList::GetSpellByCRC(int32 spell_crc){
  2125. if(spell_soecrc_map.count(spell_crc) > 0)
  2126. return spell_soecrc_map[spell_crc];
  2127. return 0;
  2128. }
  2129. EQ2Packet* MasterSpellList::GetSpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type){
  2130. Spell* spell = GetSpell(id, tier);
  2131. // if we can't find it on the master spell list, see if it is a custom spell
  2132. if (!spell)
  2133. {
  2134. lua_interface->FindCustomSpellLock();
  2135. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2136. EQ2Packet* pack = 0;
  2137. if (tmpSpell)
  2138. {
  2139. spell = tmpSpell->spell;
  2140. pack = spell->SerializeSpell(client, display, packet_type);
  2141. }
  2142. lua_interface->FindCustomSpellUnlock();
  2143. return pack;
  2144. }
  2145. if(spell)
  2146. return spell->SerializeSpell(client, display, packet_type);
  2147. return 0;
  2148. }
  2149. EQ2Packet* MasterSpellList::GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2150. Spell* spell = GetSpell(id, (tier == 0 ? 1 : tier));
  2151. // if we can't find it on the master spell list, see if it is a custom spell
  2152. if (!spell)
  2153. {
  2154. lua_interface->FindCustomSpellLock();
  2155. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2156. EQ2Packet* pack = 0;
  2157. if (tmpSpell)
  2158. {
  2159. spell = tmpSpell->spell;
  2160. // TODO: this isn't a tested thing yet... need to add custom spells to alt advancement?
  2161. AltAdvanceData* data = master_aa_list.GetAltAdvancement(id);
  2162. if(data)
  2163. pack = spell->SerializeAASpell(client, tier, data, display, false, packet_type);
  2164. }
  2165. lua_interface->FindCustomSpellUnlock();
  2166. return pack;
  2167. }
  2168. //Spell* spell2= GetSpell(id, (tier +1));
  2169. AltAdvanceData* data = master_aa_list.GetAltAdvancement(id);
  2170. if (spell)
  2171. return spell->SerializeAASpell(client,tier, data, display,false, packet_type);
  2172. return 0;
  2173. }
  2174. EQ2Packet* MasterSpellList::GetSpecialSpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type){
  2175. Spell* spell = GetSpell(id, tier);
  2176. // if we can't find it on the master spell list, see if it is a custom spell
  2177. if (!spell)
  2178. {
  2179. lua_interface->FindCustomSpellLock();
  2180. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2181. EQ2Packet* pack = 0;
  2182. if (tmpSpell)
  2183. {
  2184. spell = tmpSpell->spell;
  2185. pack = spell->SerializeSpecialSpell(client, display, packet_type, 0x81);
  2186. }
  2187. lua_interface->FindCustomSpellUnlock();
  2188. return pack;
  2189. }
  2190. if(spell)
  2191. return spell->SerializeSpecialSpell(client, display, packet_type, 0x81);
  2192. return 0;
  2193. }
  2194. vector<Spell*>* MasterSpellList::GetSpellListByAdventureClass(int8 class_id, int16 max_level, int8 max_tier){
  2195. vector<Spell*>* ret = new vector<Spell*>;
  2196. if(class_id >= MAX_CLASSES) {
  2197. return ret;
  2198. }
  2199. Spell* spell = 0;
  2200. vector<LevelArray*>* levels = 0;
  2201. LevelArray* level = 0;
  2202. vector<LevelArray*>::iterator level_itr;
  2203. MMasterSpellList.lock();
  2204. map<int32, map<int32, Spell*> >::iterator iter;
  2205. map<int32, Spell*>::iterator iter2;
  2206. max_level *= 10; //convert to client level format, which is 10 times higher
  2207. for(iter = class_spell_list[class_id].begin();iter != class_spell_list[class_id].end(); iter++){
  2208. for(iter2 = iter->second.begin();iter2 != iter->second.end(); iter2++){
  2209. spell = iter2->second;
  2210. if(iter2->first <= max_tier && spell && spell->GetSpellData()->given_by_type != GivenByType::GivenBy_SpellScroll &&
  2211. spell->GetSpellData()->given_by_type != GivenByType::GivenBy_TradeskillClass){
  2212. levels = spell->GetSpellLevels();
  2213. for(level_itr = levels->begin(); level_itr != levels->end(); level_itr++){
  2214. level = *level_itr;
  2215. if(level->spell_level <= max_level && level->adventure_class == class_id){
  2216. ret->push_back(spell);
  2217. break;
  2218. }
  2219. }
  2220. }
  2221. }
  2222. }
  2223. MMasterSpellList.unlock();
  2224. return ret;
  2225. }
  2226. vector<Spell*>* MasterSpellList::GetSpellListByTradeskillClass(int8 class_id, int16 max_level, int8 max_tier){
  2227. vector<Spell*>* ret = new vector<Spell*>;
  2228. if(class_id >= MAX_CLASSES) {
  2229. return ret;
  2230. }
  2231. Spell* spell = 0;
  2232. vector<LevelArray*>* levels = 0;
  2233. LevelArray* level = 0;
  2234. vector<LevelArray*>::iterator level_itr;
  2235. MMasterSpellList.lock();
  2236. map<int32, map<int32, Spell*> >::iterator iter;
  2237. map<int32, Spell*>::iterator iter2;
  2238. for(iter = class_spell_list[class_id].begin();iter != class_spell_list[class_id].end(); iter++){
  2239. for(iter2 = iter->second.begin();iter2 != iter->second.end(); iter2++){
  2240. spell = iter2->second;
  2241. if(iter2->first <= max_tier && spell && spell->GetSpellData()->given_by_type == GivenByType::GivenBy_TradeskillClass){
  2242. levels = spell->GetSpellLevels();
  2243. for(level_itr = levels->begin(); level_itr != levels->end(); level_itr++){
  2244. level = *level_itr;
  2245. if(level->spell_level <= max_level && level->tradeskill_class == class_id){
  2246. ret->push_back(spell);
  2247. break;
  2248. }
  2249. }
  2250. }
  2251. }
  2252. }
  2253. MMasterSpellList.unlock();
  2254. return ret;
  2255. }
  2256. void MasterSpellList::Reload(){
  2257. master_trait_list.DestroyTraits();
  2258. DestroySpells();
  2259. database.LoadSpells();
  2260. database.LoadSpellErrors();
  2261. database.LoadTraits();
  2262. }
  2263. int16 MasterSpellList::GetSpellErrorValue(int16 version, int8 error_index) {
  2264. version = GetClosestVersion(version);
  2265. if (spell_errors[version].count(error_index) == 0) {
  2266. LogWrite(SPELL__ERROR, 0, "Spells", "No spell error entry. (version = %i, error_index = %i)", version, error_index);
  2267. // 1 will give the client a pop up message of "Cannot cast" and a chat message of "[BUG] Cannot cast. Unknown failure casting spell."
  2268. return 1;
  2269. }
  2270. return spell_errors[version][error_index];
  2271. }
  2272. void MasterSpellList::AddSpellError(int16 version, int8 error_index, int16 error_value) {
  2273. if (spell_errors[version].count(error_index) == 0)
  2274. spell_errors[version][error_index] = error_value;
  2275. }
  2276. int16 MasterSpellList::GetClosestVersion(int16 version) {
  2277. int16 ret = 0;
  2278. map<int16, map<int8, int16> >::iterator itr;
  2279. // Get the closest version in the list that is less then or equal to the given version
  2280. for (itr = spell_errors.begin(); itr != spell_errors.end(); itr++) {
  2281. if (itr->first <= version) {
  2282. if (itr->first > ret)
  2283. ret = itr->first;
  2284. }
  2285. }
  2286. return ret;
  2287. }
  2288. bool Spell::CastWhileStunned(){
  2289. return (spell->casting_flags & CASTING_FLAG_STUNNED) == CASTING_FLAG_STUNNED;
  2290. }
  2291. bool Spell::CastWhileMezzed(){
  2292. return (spell->casting_flags & CASTING_FLAG_MEZZED) == CASTING_FLAG_MEZZED;
  2293. }
  2294. bool Spell::CastWhileStifled(){
  2295. return (spell->casting_flags & CASTING_FLAG_STIFLED) == CASTING_FLAG_STIFLED;
  2296. }
  2297. bool Spell::CastWhileFeared(){
  2298. return (spell->casting_flags & CASTING_FLAG_FEARED) == CASTING_FLAG_FEARED;
  2299. }