Spells.cpp 87 KB

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