Spells.cpp 87 KB

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