Spells.cpp 85 KB

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