9
3

Spells.cpp 91 KB

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