Spells.cpp 78 KB

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