9
3

Spells.cpp 93 KB

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