Spells.cpp 89 KB

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