Spells.cpp 86 KB

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