Spells.cpp 85 KB

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