Spells.cpp 89 KB

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