Spells.cpp 83 KB

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