Spells.cpp 88 KB

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