Spells.cpp 82 KB

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