Spells.cpp 89 KB

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