9
3

Spells.cpp 89 KB

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