Spells.cpp 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  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. extern ConfigReader configReader;
  24. extern WorldDatabase database;
  25. extern MasterTraitList master_trait_list;
  26. extern MasterAAList master_aa_list;
  27. extern MasterSpellList master_spell_list;
  28. Spell::Spell(){
  29. spell = new SpellData;
  30. heal_spell = false;
  31. buff_spell = false;
  32. damage_spell = false;
  33. control_spell = false;
  34. offense_spell = false;
  35. MSpellInfo.SetName("Spell::MSpellInfo");
  36. }
  37. Spell::Spell(SpellData* in_spell){
  38. spell = in_spell;
  39. heal_spell = false;
  40. buff_spell = false;
  41. damage_spell = false;
  42. control_spell = false;
  43. offense_spell = false;
  44. MSpellInfo.SetName("Spell::MSpellInfo");
  45. }
  46. Spell::~Spell(){
  47. vector<LevelArray*>::iterator itr1;
  48. for(itr1=levels.begin();itr1!=levels.end();itr1++) {
  49. safe_delete(*itr1);
  50. }
  51. vector<SpellDisplayEffect*>::iterator itr2;
  52. for(itr2=effects.begin();itr2!=effects.end();itr2++) {
  53. safe_delete(*itr2);
  54. }
  55. vector<LUAData*>::iterator itr3;
  56. for(itr3=lua_data.begin();itr3!=lua_data.end();itr3++) {
  57. safe_delete(*itr3);
  58. }
  59. safe_delete(spell);
  60. }
  61. 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){
  62. LUAData* data = new LUAData;
  63. data->type = type;
  64. data->int_value = int_value;
  65. data->int_value2 = int_value2;
  66. data->float_value = float_value;
  67. data->float_value2 = float_value2;
  68. data->bool_value = bool_value;
  69. data->string_value = string_value;
  70. data->string_value2 = string_value2;
  71. data->string_helper = helper;
  72. MSpellInfo.lock();
  73. lua_data.push_back(data);
  74. MSpellInfo.unlock();
  75. }
  76. void Spell::AddSpellLuaDataInt(int value, int value2, string helper) {
  77. LUAData *data = new LUAData;
  78. data->type = 0;
  79. data->int_value = value;
  80. data->int_value2 = value2;
  81. data->float_value = 0;
  82. data->float_value2 = 0;
  83. data->bool_value = false;
  84. data->string_helper = helper;
  85. MSpellInfo.lock();
  86. lua_data.push_back(data);
  87. MSpellInfo.unlock();
  88. }
  89. void Spell::AddSpellLuaDataFloat(float value, float value2, string helper) {
  90. LUAData *data = new LUAData;
  91. data->type = 1;
  92. data->int_value = 0;
  93. data->int_value2 = 0;
  94. data->float_value = value;
  95. data->float_value2 = value2;
  96. data->bool_value = false;
  97. data->string_helper = helper;
  98. MSpellInfo.lock();
  99. lua_data.push_back(data);
  100. MSpellInfo.unlock();
  101. }
  102. void Spell::AddSpellLuaDataBool(bool value, string helper) {
  103. LUAData *data = new LUAData;
  104. data->type = 2;
  105. data->int_value = 0;
  106. data->float_value = 0;
  107. data->bool_value = value;
  108. data->string_helper = helper;
  109. MSpellInfo.lock();
  110. lua_data.push_back(data);
  111. MSpellInfo.unlock();
  112. }
  113. void Spell::AddSpellLuaDataString(string value, string value2,string helper) {
  114. LUAData *data = new LUAData;
  115. data->type = 3;
  116. data->int_value = 0;
  117. data->int_value2 = 0;
  118. data->float_value = 0;
  119. data->float_value2 = 0;
  120. data->bool_value = false;
  121. data->string_value = value;
  122. data->string_value2 = value2;
  123. data->string_helper = helper;
  124. MSpellInfo.lock();
  125. lua_data.push_back(data);
  126. MSpellInfo.unlock();
  127. }
  128. int16 Spell::GetLevelRequired(Player* player){
  129. int16 ret = 0xFFFF;
  130. if(!player)
  131. return ret;
  132. LevelArray* level = 0;
  133. vector<LevelArray*>::iterator itr;
  134. for(itr = levels.begin(); itr != levels.end(); itr++){
  135. level = *itr;
  136. if(level && level->adventure_class == player->GetAdventureClass()){
  137. ret = level->spell_level/10;
  138. break;
  139. }
  140. }
  141. return ret;
  142. }
  143. void Spell::SetAAPacketInformation(PacketStruct* packet, AltAdvanceData* data, Client* client, bool display_tier) {
  144. int8 current_tier = client->GetPlayer()->GetSpellTier(spell->id);
  145. Spell* next_spell;
  146. SpellData* spell2;
  147. if (data->maxRank > current_tier) {
  148. next_spell = master_spell_list.GetSpell(spell->id, current_tier + 1);
  149. spell2 = next_spell->GetSpellData();
  150. }
  151. SpellDisplayEffect* effect2;
  152. //next_spell->effects[1]->description;
  153. int xxx = 0;
  154. int16 hp_req = 0;
  155. int16 power_req = 0;
  156. if (current_tier > 0) {
  157. packet->setSubstructDataByName("spell_info", "current_id", spell->id);
  158. packet->setSubstructDataByName("spell_info", "current_icon", spell->icon);
  159. packet->setSubstructDataByName("spell_info", "current_icon2", spell->icon_heroic_op); // fix struct element name eventually
  160. packet->setSubstructDataByName("spell_info", "current_icontype", spell->icon_backdrop); // fix struct element name eventually
  161. if (packet->GetVersion() >= 63119) {
  162. packet->setSubstructDataByName("spell_info", "current_version", 0x04);
  163. packet->setSubstructDataByName("spell_info", "current_sub_version", 0x24);
  164. }
  165. else if (packet->GetVersion() >= 58617) {
  166. packet->setSubstructDataByName("spell_info", "current_version", 0x03);
  167. packet->setSubstructDataByName("spell_info", "current_sub_version", 0x131A);
  168. }
  169. else {
  170. packet->setSubstructDataByName("spell_info", "current_version", 0x00);
  171. packet->setSubstructDataByName("spell_info", "current_sub_version", 0xD9);
  172. }
  173. packet->setSubstructDataByName("spell_info", "current_type", spell->type);
  174. packet->setSubstructDataByName("spell_info", "unknown_MJ1d", 1); //63119 test
  175. packet->setSubstructDataByName("spell_info", "current_class_skill", spell->class_skill);
  176. packet->setSubstructDataByName("spell_info", "current_mastery_skill", spell->mastery_skill);
  177. packet->setSubstructDataByName("spell_info", "duration_flag", spell->duration_until_cancel);
  178. if (client && spell->type != 2) {
  179. sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client->GetPlayer()));
  180. if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
  181. spell_text_color = ARROW_COLOR_WHITE;
  182. spell_text_color -= 6;
  183. if (spell_text_color < 0)
  184. spell_text_color *= -1;
  185. packet->setSubstructDataByName("spell_info", "current_spell_text_color", (xxx == 1 ? 0xFFFFFFFF : spell_text_color));
  186. }
  187. else {
  188. packet->setSubstructDataByName("spell_info", "current_spell_text_color", (xxx == 1 ? 0xFFFFFFFF : 3));
  189. }
  190. packet->setSubstructDataByName("spell_info", "current_spell_text_color", (xxx == 1 ? 0xFFFFFFFF : 3));
  191. packet->setSubstructDataByName("spell_info", "current_tier", (spell->tier));
  192. if (spell->type != 2) {
  193. packet->setArrayLengthByName("current_num_levels", 0);
  194. for (int32 i = 0; i < levels.size(); i++) {
  195. packet->setArrayDataByName("spell_info_aa_adventure_class", levels[i]->adventure_class, i);
  196. packet->setArrayDataByName("spell_info_aa_tradeskill_class", levels[i]->tradeskill_class, i);
  197. packet->setArrayDataByName("spell_info_aa_spell_level", levels[i]->spell_level, i);
  198. }
  199. }
  200. //packet->setSubstructDataByName("spell_info","unknown9", 20);
  201. if (client) {
  202. hp_req = GetHPRequired(client->GetPlayer());
  203. power_req = GetPowerRequired(client->GetPlayer());
  204. // might need version checks around these?
  205. if (client->GetVersion() >= 1193)
  206. {
  207. int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
  208. packet->setSubstructDataByName("spell_info", "current_savagery_req", savagery_req);
  209. packet->setSubstructDataByName("spell_info", "current_savagery_upkeep", spell->savagery_upkeep);
  210. }
  211. if (client->GetVersion() >= 57048)
  212. {
  213. int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
  214. packet->setSubstructDataByName("spell_info", "dissonance_req", dissonance_req);
  215. packet->setSubstructDataByName("spell_info", "dissonance_upkeep", spell->dissonance_upkeep);
  216. }
  217. }
  218. packet->setSubstructDataByName("spell_info", "current_health_req", hp_req);
  219. packet->setSubstructDataByName("spell_info", "current_health_upkeep", spell->hp_upkeep);
  220. packet->setSubstructDataByName("spell_info", "current_power_req", power_req);
  221. packet->setSubstructDataByName("spell_info", "current_power_upkeep", spell->power_upkeep);
  222. packet->setSubstructDataByName("spell_info", "current_req_concentration", spell->req_concentration);
  223. //unknown1 savagery???
  224. packet->setSubstructDataByName("spell_info", "current_cast_time", spell->cast_time);
  225. packet->setSubstructDataByName("spell_info", "current_recovery", spell->recovery);
  226. packet->setSubstructDataByName("spell_info", "current_recast", spell->recast);
  227. packet->setSubstructDataByName("spell_info", "current_radius", spell->radius);
  228. packet->setSubstructDataByName("spell_info", "current_max_aoe_targets", spell->max_aoe_targets);
  229. packet->setSubstructDataByName("spell_info", "current_friendly_spell", spell->friendly_spell);
  230. // rumber of reagents with array
  231. packet->setSubstructArrayLengthByName("spell_info", "current_num_effects", (xxx == 1 ? 0 : effects.size()));
  232. for (int32 i = 0; i < effects.size(); i++) {
  233. packet->setArrayDataByName("current_subbulletflag", effects[i]->subbullet, i);
  234. string effect_message;
  235. if (effects[i]->description.length() > 0) {
  236. effect_message = effects[i]->description;
  237. if (effect_message.find("%LM") < 0xFFFFFFFF) {
  238. int string_index = effect_message.find("%LM");
  239. int data_index = stoi(effect_message.substr(string_index + 3, 2));
  240. float value;
  241. if (lua_data[data_index]->type == 1)
  242. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  243. else
  244. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  245. string strValue = to_string(value);
  246. strValue.erase(strValue.find_last_not_of('0') + 1, std::string::npos);
  247. effect_message.replace(effect_message.find("%LM"), 5, strValue);
  248. }
  249. // Magic damage min
  250. if (effect_message.find("%DML") < 0xFFFFFFFF) {
  251. int string_index = effect_message.find("%DML");
  252. int data_index = stoi(effect_message.substr(string_index+4, 2));
  253. float value;
  254. if (lua_data[data_index]->type == 1)
  255. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  256. else
  257. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  258. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  259. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  260. value += mod;
  261. string damage = to_string((int)round(value));
  262. effect_message.replace(effect_message.find("%DML"), 6, damage);
  263. }
  264. // Magic damage max
  265. if (effect_message.find("%DMH") < 0xFFFFFFFF) {
  266. int string_index = effect_message.find("%DMH");
  267. int data_index = stoi(effect_message.substr(string_index+4, 2));
  268. float value;
  269. if (lua_data[data_index]->type == 1)
  270. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  271. else
  272. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  273. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  274. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  275. value += mod;
  276. string damage = to_string((int)round(value));
  277. effect_message.replace(effect_message.find("%DMH"), 6, damage);
  278. }
  279. // level based Magic damage min
  280. if (effect_message.find("%LDML") < 0xFFFFFFFF) {
  281. int string_index = effect_message.find("%LDML");
  282. int data_index = stoi(effect_message.substr(string_index+5, 2));
  283. float value;
  284. if (lua_data[data_index]->type == 1)
  285. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  286. else
  287. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  288. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  289. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  290. value += mod;
  291. string damage = to_string((int)round(value));
  292. effect_message.replace(effect_message.find("%LDML"), 7, damage);
  293. }
  294. // level based Magic damage max
  295. if (effect_message.find("%LDMH") < 0xFFFFFFFF) {
  296. int string_index = effect_message.find("%LDMH");
  297. int data_index = stoi(effect_message.substr(string_index+5, 2));
  298. float value;
  299. if (lua_data[data_index]->type == 1)
  300. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  301. else
  302. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  303. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  304. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  305. value += mod;
  306. string damage = to_string((int)round(value));
  307. effect_message.replace(effect_message.find("%LDMH"), 7, damage);
  308. }
  309. //GetZone()->SimpleMessage(CHANNEL_COLOR_SPELL_EFFECT, effect_message.c_str(), victim, 50);
  310. packet->setArrayDataByName("current_effect", effect_message.c_str(), i);
  311. }
  312. packet->setArrayDataByName("current_percentage", effects[i]->percentage, i);
  313. }
  314. if (display_tier == true)
  315. packet->setSubstructDataByName("spell_info", "current_display_spell_tier", 1);// spell2->display_spell_tier);
  316. else
  317. packet->setSubstructDataByName("spell_info", "current_display_spell_tier", 1);// 0);
  318. packet->setSubstructDataByName("spell_info", "current_unknown_1", 1);// 0);
  319. //unkown1_1
  320. packet->setSubstructDataByName("spell_info", "current_minimum_range", spell->min_range);
  321. packet->setSubstructDataByName("spell_info", "current_range", spell->range);
  322. packet->setSubstructDataByName("spell_info", "current_duration_1", spell->duration1);
  323. packet->setSubstructDataByName("spell_info", "current_duration_2", spell->duration2);
  324. packet->setSubstructDataByName("spell_info", "current_duration_flag", spell->duration_until_cancel);
  325. packet->setSubstructDataByName("spell_info", "current_target", spell->target_type);
  326. packet->setSubstructDataByName("spell_info", "current_can_effect_raid", spell->can_effect_raid);
  327. packet->setSubstructDataByName("spell_info", "current_affect_only_group_members", spell->affect_only_group_members);
  328. packet->setSubstructDataByName("spell_info", "current_group_spell", spell->group_spell);
  329. packet->setSubstructDataByName("spell_info", "current_resistibility", spell->resistibility);
  330. packet->setSubstructDataByName("spell_info", "current_name", &(spell->name));
  331. packet->setSubstructDataByName("spell_info", "current_description", &(spell->description));
  332. }
  333. if (current_tier + 1 <= data->maxRank) {
  334. packet->setSubstructDataByName("spell_info", "next_id", spell2->id);
  335. packet->setSubstructDataByName("spell_info", "next_icon", spell2->icon);
  336. packet->setSubstructDataByName("spell_info", "next_icon2", spell2->icon_heroic_op); // fix struct element name eventually
  337. packet->setSubstructDataByName("spell_info", "next_icontype", spell2->icon_backdrop); // fix struct element name eventually
  338. if (packet->GetVersion() >= 63119) {
  339. packet->setSubstructDataByName("spell_info", "next_aa_spell_info2", "version", 0x04);
  340. packet->setSubstructDataByName("spell_info", "next_aa_spell_info2", "sub_version", 0x24);
  341. }
  342. else if (packet->GetVersion() >= 58617) {
  343. packet->setSubstructDataByName("spell_info", "next_version", 0x03);
  344. packet->setSubstructDataByName("spell_info", "next_sub_version", 0x131A);
  345. }
  346. else {
  347. packet->setSubstructDataByName("spell_info", "next_version", 0x00);
  348. packet->setSubstructDataByName("spell_info", "next_sub_version", 0xD9);
  349. }
  350. packet->setSubstructDataByName("spell_info", "next_type", spell2->type);
  351. packet->setSubstructDataByName("spell_info", "next_unknown_MJ1d", 1); //63119 test
  352. packet->setSubstructDataByName("spell_info", "next_class_skill", spell2->class_skill);
  353. packet->setSubstructDataByName("spell_info", "next_mastery_skill", spell2->mastery_skill);
  354. packet->setSubstructDataByName("spell_info", "next_duration_flag", spell2->duration_until_cancel);
  355. if (client && spell->type != 2) {
  356. sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client->GetPlayer()));
  357. if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
  358. spell_text_color = ARROW_COLOR_WHITE;
  359. spell_text_color -= 6;
  360. if (spell_text_color < 0)
  361. spell_text_color *= -1;
  362. packet->setSubstructDataByName("spell_info", "next_spell_text_color", spell_text_color);
  363. }
  364. else
  365. packet->setSubstructDataByName("spell_info", "next_spell_text_color", 3);
  366. if (spell->type != 2) {
  367. packet->setArrayLengthByName("num_levels", levels.size());
  368. for (int32 i = 0; i < levels.size(); i++) {
  369. packet->setArrayDataByName("spell_info_aa_adventure_class2", levels[i]->adventure_class, i);
  370. packet->setArrayDataByName("spell_info_aa_tradeskill_class2", levels[i]->tradeskill_class, i);
  371. packet->setArrayDataByName("spell_info_aa_spell_level2", levels[i]->spell_level, i);
  372. }
  373. }
  374. //packet->setSubstructDataByName("spell_info","unknown9", 20);
  375. hp_req = 0;
  376. power_req = 0;
  377. if (client) {
  378. hp_req = GetHPRequired(client->GetPlayer());
  379. power_req = GetPowerRequired(client->GetPlayer());
  380. // might need version checks around these?
  381. if (client->GetVersion() >= 1193)
  382. {
  383. int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
  384. packet->setSubstructDataByName("spell_info", "next_savagery_req", savagery_req);
  385. packet->setSubstructDataByName("spell_info", "next_savagery_upkeep", spell->savagery_upkeep);
  386. }
  387. if (client->GetVersion() >= 57048)
  388. {
  389. int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
  390. packet->setSubstructDataByName("spell_info", "next_dissonance_req", dissonance_req);
  391. packet->setSubstructDataByName("spell_info", "next_dissonance_upkeep", spell->dissonance_upkeep);
  392. }
  393. }
  394. packet->setSubstructDataByName("spell_info", "next_target", spell->target_type);
  395. packet->setSubstructDataByName("spell_info", "next_recovery", spell->recovery);
  396. packet->setSubstructDataByName("spell_info", "next_health_upkeep", spell->hp_upkeep);
  397. packet->setSubstructDataByName("spell_info", "next_health_req", hp_req);
  398. packet->setSubstructDataByName("spell_info", "next_tier", spell->tier);
  399. packet->setSubstructDataByName("spell_info", "next_power_req", power_req);
  400. packet->setSubstructDataByName("spell_info", "next_power_upkeep", spell->power_upkeep);
  401. packet->setSubstructDataByName("spell_info", "next_cast_time", spell->cast_time);
  402. packet->setSubstructDataByName("spell_info", "next_recast", spell->recast);
  403. packet->setSubstructDataByName("spell_info", "next_radius", spell->radius);
  404. packet->setSubstructDataByName("spell_info", "next_req_concentration", spell->req_concentration);
  405. //packet->setSubstructDataByName("spell_info","req_concentration2", 2);
  406. packet->setSubstructDataByName("spell_info", "next_max_aoe_targets", spell->max_aoe_targets);
  407. packet->setSubstructDataByName("spell_info", "next_friendly_spell", spell->friendly_spell);
  408. packet->setSubstructArrayLengthByName("spell_info", "next_num_effects", next_spell->effects.size());
  409. for (int32 i = 0; i < next_spell->effects.size(); i++) {
  410. packet->setArrayDataByName("next_subbulletflag", next_spell->effects[i]->subbullet, i);
  411. string effect_message;
  412. if (next_spell->effects[i]->description.length() > 0) {
  413. effect_message = next_spell->effects[i]->description;
  414. if (effect_message.find("%LM") < 0xFFFFFFFF) {
  415. int string_index = effect_message.find("%LM");
  416. int data_index = stoi(effect_message.substr(string_index + 3, 2));
  417. float value;
  418. if (next_spell->lua_data[data_index]->type == 1)
  419. value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  420. else
  421. value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  422. string strValue = to_string(value);
  423. strValue.erase(strValue.find_last_not_of('0') + 1, std::string::npos);
  424. effect_message.replace(effect_message.find("%LM"), 5, strValue);
  425. }
  426. // Magic damage min
  427. if (effect_message.find("%DML") < 0xFFFFFFFF) {
  428. int string_index = effect_message.find("%DML");
  429. int data_index = stoi(effect_message.substr(string_index + 4, 2));
  430. float value;
  431. if (next_spell->lua_data[data_index]->type == 1)
  432. value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  433. else
  434. value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  435. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  436. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  437. value += mod;
  438. string damage = to_string((int)round(value));
  439. damage.erase(damage.find_last_not_of('0') + 1, std::string::npos);
  440. effect_message.replace(effect_message.find("%DML"), 6, damage);
  441. }
  442. // Magic damage max
  443. if (effect_message.find("%DMH") < 0xFFFFFFFF) {
  444. int string_index = effect_message.find("%DMH");
  445. int data_index = stoi(effect_message.substr(string_index + 4, 2));
  446. float value;
  447. if (next_spell->lua_data[data_index]->type == 1)
  448. value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  449. else
  450. value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  451. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  452. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  453. value += mod;
  454. string damage = to_string((int)round(value));
  455. damage.erase(damage.find_last_not_of('0') + 1, std::string::npos);
  456. effect_message.replace(effect_message.find("%DMH"), 6, damage);
  457. }
  458. // level based Magic damage min
  459. if (effect_message.find("%LDML") < 0xFFFFFFFF) {
  460. int string_index = effect_message.find("%LDML");
  461. int data_index = stoi(effect_message.substr(string_index + 5, 2));
  462. float value;
  463. if (next_spell->lua_data[data_index]->type == 1)
  464. value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  465. else
  466. value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  467. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  468. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  469. value += mod;
  470. string damage = to_string((int)round(value));
  471. effect_message.replace(effect_message.find("%LDML"), 7, damage);
  472. }
  473. // level based Magic damage max
  474. if (effect_message.find("%LDMH") < 0xFFFFFFFF) {
  475. int string_index = effect_message.find("%LDMH");
  476. int data_index = stoi(effect_message.substr(string_index + 5, 2));
  477. float value;
  478. if (next_spell->lua_data[data_index]->type == 1)
  479. value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  480. else
  481. value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  482. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  483. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  484. value += mod;
  485. string damage = to_string((int)round(value));
  486. effect_message.replace(effect_message.find("%LDMH"), 7, damage);
  487. }
  488. //GetZone()->SimpleMessage(CHANNEL_COLOR_SPELL_EFFECT, effect_message.c_str(), victim, 50);
  489. packet->setArrayDataByName("next_effect", effect_message.c_str(), i);
  490. }
  491. packet->setArrayDataByName("next_percentage", next_spell->effects[i]->percentage, i);
  492. }
  493. if (display_tier == true)
  494. packet->setSubstructDataByName("spell_info", "next_display_spell_tier", 1);// spell->display_spell_tier);
  495. else
  496. packet->setSubstructDataByName("spell_info", "next_display_spell_tier", 1);//0
  497. packet->setSubstructDataByName("spell_info", "next_unknown_1", 1);//0
  498. packet->setSubstructDataByName("spell_info", "next_range", spell2->range);
  499. packet->setSubstructDataByName("spell_info", "next_duration_1", spell2->duration1);
  500. packet->setSubstructDataByName("spell_info", "next_duration_2", spell2->duration2);
  501. packet->setSubstructDataByName("spell_info", "next_can_effect_raid", spell2->can_effect_raid);
  502. packet->setSubstructDataByName("spell_info", "next_affect_only_group_members", spell2->affect_only_group_members);
  503. packet->setSubstructDataByName("spell_info", "next_group_spell", spell2->group_spell);
  504. packet->setSubstructDataByName("spell_info", "next_resistibility", spell2->resistibility);
  505. packet->setSubstructDataByName("spell_info", "next_name", &(spell2->name));
  506. packet->setSubstructDataByName("spell_info", "next_description", &(spell2->description));
  507. }
  508. }
  509. void Spell::SetPacketInformation(PacketStruct* packet, Client* client, bool display_tier) {
  510. packet->setSubstructDataByName("spell_info", "id", spell->id);
  511. packet->setSubstructDataByName("spell_info", "icon", spell->icon);
  512. packet->setSubstructDataByName("spell_info", "icon2", spell->icon_heroic_op); // fix struct element name eventually
  513. packet->setSubstructDataByName("spell_info", "icontype", spell->icon_backdrop); // fix struct element name eventually
  514. if (packet->GetVersion() >= 63119) {
  515. packet->setSubstructDataByName("spell_info", "version", 0x04);
  516. packet->setSubstructDataByName("spell_info", "sub_version", 0x24);
  517. }
  518. else if (packet->GetVersion() >= 60114) {
  519. packet->setSubstructDataByName("spell_info", "version", 0x03);
  520. packet->setSubstructDataByName("spell_info", "sub_version", 4890);
  521. }
  522. else {
  523. packet->setSubstructDataByName("spell_info", "version", 0x11);
  524. packet->setSubstructDataByName("spell_info", "sub_version", 0x14);
  525. }
  526. packet->setSubstructDataByName("spell_info", "type", spell->type);
  527. packet->setSubstructDataByName("spell_info", "unknown_MJ1d", 1); //63119 test
  528. packet->setSubstructDataByName("spell_info", "class_skill", spell->class_skill);
  529. packet->setSubstructDataByName("spell_info", "mastery_skill", spell->mastery_skill);
  530. packet->setSubstructDataByName("spell_info", "duration_flag", spell->duration_until_cancel);
  531. if (client && spell->type != 2) {
  532. sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client->GetPlayer()));
  533. if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
  534. spell_text_color = ARROW_COLOR_WHITE;
  535. spell_text_color -= 6;
  536. if (spell_text_color < 0)
  537. spell_text_color *= -1;
  538. packet->setSubstructDataByName("spell_info", "spell_text_color", spell_text_color);
  539. }
  540. else
  541. packet->setSubstructDataByName("spell_info", "spell_text_color", 3);
  542. if (spell->type != 2) {
  543. packet->setSubstructArrayLengthByName("spell_info", "num_levels", levels.size());
  544. for (int32 i = 0; i < levels.size(); i++) {
  545. packet->setArrayDataByName("adventure_class", levels[i]->adventure_class, i);
  546. packet->setArrayDataByName("tradeskill_class", levels[i]->tradeskill_class, i);
  547. packet->setArrayDataByName("spell_level", levels[i]->spell_level, i);
  548. }
  549. }
  550. packet->setSubstructDataByName("spell_info", "unknown9", 20);
  551. int16 hp_req = 0;
  552. int16 power_req = 0;
  553. if (client) {
  554. hp_req = GetHPRequired(client->GetPlayer());
  555. power_req = GetPowerRequired(client->GetPlayer());
  556. // might need version checks around these?
  557. if (client->GetVersion() >= 1193)
  558. {
  559. int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
  560. packet->setSubstructDataByName("spell_info", "savagery_req", savagery_req);
  561. packet->setSubstructDataByName("spell_info", "savagery_upkeep", spell->savagery_upkeep);
  562. }
  563. if (client->GetVersion() >= 57048)
  564. {
  565. int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
  566. packet->setSubstructDataByName("spell_info", "dissonance_req", dissonance_req);
  567. packet->setSubstructDataByName("spell_info", "dissonance_upkeep", spell->dissonance_upkeep);
  568. }
  569. }
  570. packet->setSubstructDataByName("spell_info", "target", spell->target_type);
  571. packet->setSubstructDataByName("spell_info", "recovery", spell->recovery);
  572. packet->setSubstructDataByName("spell_info", "health_upkeep", spell->hp_upkeep);
  573. packet->setSubstructDataByName("spell_info", "health_req", hp_req);
  574. packet->setSubstructDataByName("spell_info", "tier", spell->tier);
  575. packet->setSubstructDataByName("spell_info", "power_req", power_req);
  576. packet->setSubstructDataByName("spell_info", "power_upkeep", spell->power_upkeep);
  577. packet->setSubstructDataByName("spell_info", "cast_time", spell->cast_time);
  578. packet->setSubstructDataByName("spell_info", "recast", spell->recast);
  579. packet->setSubstructDataByName("spell_info", "radius", spell->radius);
  580. packet->setSubstructDataByName("spell_info", "req_concentration", spell->req_concentration);
  581. //packet->setSubstructDataByName("spell_info","req_concentration2", 2);
  582. packet->setSubstructDataByName("spell_info", "max_aoe_targets", spell->max_aoe_targets);
  583. packet->setSubstructDataByName("spell_info", "friendly_spell", spell->friendly_spell);
  584. packet->setSubstructArrayLengthByName("spell_info", "num_effects", effects.size());
  585. for (int32 i = 0; i < effects.size(); i++) {
  586. packet->setArrayDataByName("subbulletflag", effects[i]->subbullet, i);
  587. string effect_message;
  588. if (effects[i]->description.length() > 0) {
  589. effect_message = effects[i]->description;
  590. if (effect_message.find("%LM") < 0xFFFFFFFF) {
  591. int string_index = effect_message.find("%LM");
  592. int data_index = stoi(effect_message.substr(string_index + 3, 2));
  593. float value;
  594. if (lua_data[data_index]->type == 1)
  595. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  596. else
  597. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  598. string strValue = to_string(value);
  599. strValue.erase(strValue.find_last_not_of('0') + 1, std::string::npos);
  600. effect_message.replace(effect_message.find("%LM"), 5, strValue);
  601. }
  602. // Magic damage min
  603. if (effect_message.find("%DML") < 0xFFFFFFFF) {
  604. int string_index = effect_message.find("%DML");
  605. int data_index = stoi(effect_message.substr(string_index + 4, 2));
  606. float value;
  607. if (lua_data[data_index]->type == 1)
  608. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  609. else
  610. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  611. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  612. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  613. value += mod;
  614. string damage = to_string((int)round(value));
  615. effect_message.replace(effect_message.find("%DML"), 6, damage);
  616. }
  617. // Magic damage max
  618. if (effect_message.find("%DMH") < 0xFFFFFFFF) {
  619. int string_index = effect_message.find("%DMH");
  620. int data_index = stoi(effect_message.substr(string_index + 4, 2));
  621. float value;
  622. if (lua_data[data_index]->type == 1)
  623. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  624. else
  625. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  626. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  627. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  628. value += mod;
  629. string damage = to_string((int)round(value));
  630. effect_message.replace(effect_message.find("%DMH"), 6, damage);
  631. }
  632. // level based Magic damage min
  633. if (effect_message.find("%LDML") < 0xFFFFFFFF) {
  634. int string_index = effect_message.find("%LDML");
  635. int data_index = stoi(effect_message.substr(string_index + 5, 2));
  636. float value;
  637. if (lua_data[data_index]->type == 1)
  638. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  639. else
  640. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  641. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  642. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  643. value += mod;
  644. string damage = to_string((int)round(value));
  645. effect_message.replace(effect_message.find("%LDML"), 7, damage);
  646. }
  647. // level based Magic damage max
  648. if (effect_message.find("%LDMH") < 0xFFFFFFFF) {
  649. int string_index = effect_message.find("%LDMH");
  650. int data_index = stoi(effect_message.substr(string_index + 5, 2));
  651. float value;
  652. if (lua_data[data_index]->type == 1)
  653. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  654. else
  655. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  656. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  657. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  658. value += mod;
  659. string damage = to_string((int)round(value));
  660. effect_message.replace(effect_message.find("%LDMH"), 7, damage);
  661. }
  662. //GetZone()->SimpleMessage(CHANNEL_COLOR_SPELL_EFFECT, effect_message.c_str(), victim, 50);
  663. }
  664. packet->setArrayDataByName("effect", effect_message.c_str(), i);
  665. packet->setArrayDataByName("percentage", effects[i]->percentage, i);
  666. }
  667. if (display_tier == true)
  668. packet->setSubstructDataByName("spell_info", "display_spell_tier", spell->display_spell_tier);
  669. else
  670. packet->setSubstructDataByName("spell_info", "display_spell_tier", 0);
  671. packet->setSubstructDataByName("spell_info", "range", spell->range);
  672. packet->setSubstructDataByName("spell_info", "duration1", spell->duration1);
  673. packet->setSubstructDataByName("spell_info", "duration2", spell->duration2);
  674. packet->setSubstructDataByName("spell_info", "can_effect_raid", spell->can_effect_raid);
  675. packet->setSubstructDataByName("spell_info", "affect_only_group_members", spell->affect_only_group_members);
  676. packet->setSubstructDataByName("spell_info", "group_spell", spell->group_spell);
  677. packet->setSubstructDataByName("spell_info", "resistibility", spell->resistibility);
  678. packet->setSubstructDataByName("spell_info", "name", &(spell->name));
  679. packet->setSubstructDataByName("spell_info", "description", &(spell->description));
  680. //packet->PrintPacket();
  681. }
  682. EQ2Packet* Spell::SerializeSpecialSpell(Client* client, bool display, int8 packet_type, int8 sub_packet_type){
  683. return SerializeSpell(client, display, false, packet_type, sub_packet_type, "WS_ExamineSpecialSpellInfo");
  684. }
  685. 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){
  686. if (!client)
  687. return 0;
  688. int16 version = 1;
  689. if (client)
  690. version = client->GetVersion();
  691. if (!struct_name)
  692. struct_name = "WS_ExamineAASpellInfo";
  693. PacketStruct* packet = configReader.getStruct(struct_name, version);
  694. if (display)
  695. packet->setSubstructDataByName("info_header", "show_name", 1);//1
  696. else
  697. if (!trait_display)
  698. packet->setSubstructDataByName("info_header", "show_popup", 1);//1
  699. else
  700. packet->setSubstructDataByName("info_header", "show_popup", 0);
  701. if (packet_type > 0)
  702. packet->setSubstructDataByName("info_header", "packettype", packet_type * 256 + 0xFE);
  703. else
  704. packet->setSubstructDataByName("info_header", "packettype", 0x4FFE);// 0x45FE GetItemPacketType(version));
  705. //packet->setDataByName("unknown2",5);
  706. //packet->setDataByName("unknown7", 1);
  707. //packet->setDataByName("unknown9", 20);
  708. //packet->setDataByName("unknown10", 1, 2);
  709. if (sub_packet_type == 0)
  710. sub_packet_type = 0x83;
  711. packet->setSubstructDataByName("info_header", "packetsubtype", 4);// sub_packet_type);
  712. packet->setSubstructDataByName("spell_info", "aa_id", data->spellID);
  713. packet->setSubstructDataByName("spell_info", "aa_tab_id", data->group);
  714. packet->setSubstructDataByName("spell_info", "aa_icon", data->icon);
  715. packet->setSubstructDataByName("spell_info", "aa_icon2", data->icon2);
  716. packet->setSubstructDataByName("spell_info", "aa_current_rank", tier); // how to get this info to here?
  717. packet->setSubstructDataByName("spell_info", "aa_max_rank", data->maxRank);
  718. packet->setSubstructDataByName("spell_info", "aa_rank_cost", data->rankCost);
  719. packet->setSubstructDataByName("spell_info", "aa_unknown_2", 20);
  720. packet->setSubstructDataByName("spell_info", "aa_name", &(spell->name));
  721. packet->setSubstructDataByName("spell_info", "aa_description", &(spell->description));
  722. //packet->setDataByName("unknown3",2);
  723. //packet->setDataByName("unknown7", 50);
  724. if (sub_packet_type == 0x81)
  725. SetAAPacketInformation(packet, data, client);
  726. else
  727. SetAAPacketInformation(packet,data, client, true);
  728. packet->setSubstructDataByName("spell_info", "uses_remaining", 0xFFFF);
  729. packet->setSubstructDataByName("spell_info", "damage_remaining", 0xFFFF);
  730. //packet->PrintPacket();
  731. // This adds the second portion to the spell packet. Could be used for bonuses etc.?
  732. string* data1 = packet->serializeString();
  733. uchar* data2 = (uchar*)data1->c_str();
  734. uchar* ptr2 = data2;
  735. int32 size = data1->length();// *2;
  736. ////uchar* data3 = new uchar[size];
  737. ////memcpy(data3, data2, data1->length());
  738. ////uchar* ptr = data3;
  739. ////size -= 17;
  740. ////memcpy(ptr, &size, sizeof(int32));
  741. ////size += 3;
  742. ////ptr += data1->length();
  743. ////ptr2 += 14;
  744. ////memcpy(ptr, ptr2, data1->length() - 14);
  745. EQ2Packet* outapp = new EQ2Packet(OP_ClientCmdMsg, data2, size);
  746. //DumpPacket(outapp);
  747. //safe_delete_array(data3);
  748. safe_delete(packet);
  749. return outapp;
  750. /*PacketStruct* packet = configReader.getStruct("WS_ExamineAASpellInfo", client->GetVersion());
  751. packet->setSubstructDataByName("info_header", "show_name", 0);
  752. packet->setSubstructDataByName("info_header", "show_popup", 0);
  753. packet->setSubstructDataByName("info_header", "packettype", packet_type);
  754. packet->setSubstructDataByName("info_header", "packetsubtype", sub_packet_type);
  755. packet->setSubstructDataByName("Spell_info", "aa_id", data->spellID);
  756. packet->setSubstructDataByName("Spell_info", "aa_tab_id", data->group);
  757. packet->setSubstructDataByName("Spell_info", "aa_icon", data->icon);
  758. packet->setSubstructDataByName("Spell_info", "aa_icon2", data->icon2);
  759. packet->setSubstructDataByName("Spell_info", "current_rank", 0); // how to get this info to here?
  760. packet->setSubstructDataByName("Spell_info", "max_rank", data->maxRank);
  761. packet->setSubstructDataByName("Spell_info", "rank_cost", data->rankCost);
  762. packet->setSubstructDataByName("spell_info", "unknown2", 20);
  763. // Spell info
  764. packet->setSubstructDataByName("spell_info", "id", spell->id);
  765. packet->setSubstructDataByName("spell_info", "icon", spell->icon);
  766. packet->setSubstructDataByName("spell_info", "icon2", spell->icon_heroic_op); // fix struct element name eventually
  767. packet->setSubstructDataByName("spell_info", "icontype", spell->icon_backdrop); // fix struct element name eventually
  768. if (packet->GetVersion() >= 63119) {
  769. packet->setSubstructDataByName("spell_info", "version", 0x04);
  770. packet->setSubstructDataByName("spell_info", "sub_version", 0x24);
  771. }
  772. else if (packet->GetVersion() >= 1193) {
  773. packet->setSubstructDataByName("spell_info", "version", 0x00);
  774. packet->setSubstructDataByName("spell_info", "sub_version", 0xD9);
  775. }
  776. else {
  777. packet->setSubstructDataByName("spell_info", "version", 0x11);
  778. packet->setSubstructDataByName("spell_info", "sub_version", 0x14);
  779. }
  780. packet->setSubstructDataByName("spell_info", "type", spell->type);
  781. packet->setSubstructDataByName("spell_info", "unknown_MJ1d", 1); //63119 test
  782. packet->setSubstructDataByName("spell_info", "class_skill", spell->class_skill);
  783. packet->setSubstructDataByName("spell_info", "mastery_skill", spell->mastery_skill);
  784. packet->setSubstructDataByName("spell_info", "duration_flag", spell->duration_until_cancel);
  785. if (client && spell->type != 2) {
  786. sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client));
  787. if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
  788. spell_text_color = ARROW_COLOR_WHITE;
  789. spell_text_color -= 6;
  790. if (spell_text_color < 0)
  791. spell_text_color *= -1;
  792. packet->setSubstructDataByName("spell_info", "spell_text_color", spell_text_color);
  793. }
  794. else
  795. packet->setSubstructDataByName("spell_info", "spell_text_color", 3);
  796. if (spell->type != 2) {
  797. packet->setSubstructArrayLengthByName("spell_info", "num_levels", levels.size());
  798. for (int32 i = 0; i < levels.size(); i++) {
  799. packet->setArrayDataByName("adventure_class", levels[i]->adventure_class, i);
  800. packet->setArrayDataByName("tradeskill_class", levels[i]->tradeskill_class, i);
  801. packet->setArrayDataByName("spell_level", levels[i]->spell_level, i);
  802. }
  803. }
  804. //packet->setSubstructDataByName("spell_info", "unknown9", 20);
  805. int16 hp_req = 0;
  806. int16 power_req = 0;
  807. if (client) {
  808. hp_req = GetHPRequired(client->GetPlayer());
  809. power_req = GetPowerRequired(client->GetPlayer());
  810. // might need version checks around these?
  811. if (client->GetVersion() >= 1193)
  812. {
  813. int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
  814. packet->setSubstructDataByName("spell_info", "savagery_req", savagery_req);
  815. packet->setSubstructDataByName("spell_info", "savagery_upkeep", spell->savagery_upkeep);
  816. }
  817. if (client->GetVersion() >= 57048)
  818. {
  819. int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
  820. packet->setSubstructDataByName("spell_info", "dissonance_req", dissonance_req);
  821. packet->setSubstructDataByName("spell_info", "dissonance_upkeep", spell->dissonance_upkeep);
  822. }
  823. }
  824. packet->setSubstructDataByName("spell_info", "tier", spell->tier);
  825. packet->setSubstructDataByName("spell_info", "health_req", hp_req);
  826. packet->setSubstructDataByName("spell_info", "health_upkeep", spell->hp_upkeep);
  827. packet->setSubstructDataByName("spell_info", "power_req", power_req);
  828. packet->setSubstructDataByName("spell_info", "power_upkeep", spell->power_upkeep);
  829. packet->setSubstructDataByName("spell_info", "req_concentration", spell->req_concentration);
  830. //packet->setDataByName("req_concentration2", 2);
  831. packet->setSubstructDataByName("spell_info", "cast_time", spell->cast_time);
  832. packet->setSubstructDataByName("spell_info", "recovery", spell->recovery);
  833. packet->setSubstructDataByName("spell_info", "recast", spell->recast);
  834. packet->setSubstructDataByName("spell_info", "radius", spell->radius);
  835. packet->setSubstructDataByName("spell_info", "max_aoe_targets", spell->max_aoe_targets);
  836. packet->setSubstructDataByName("spell_info", "friendly_spell", spell->friendly_spell);
  837. //reageants??
  838. packet->setSubstructArrayLengthByName("spell_info", "num_effects", effects.size());
  839. for (int32 i = 0; i < effects.size(); i++) {
  840. packet->setArrayDataByName("subbulletflag", effects[i]->subbullet, i);
  841. packet->setArrayDataByName("effect", effects[i]->description.c_str(), i);
  842. packet->setArrayDataByName("percentage", effects[i]->percentage, i);
  843. }
  844. //if (display_tier == true)
  845. packet->setSubstructDataByName("spell_info", "display_spell_tier", spell->display_spell_tier);
  846. //else
  847. // packet->setSubstructDataByName("spell_info", "display_spell_tier", 0);
  848. // minimum range??
  849. packet->setSubstructDataByName("spell_info", "range", spell->range);
  850. packet->setSubstructDataByName("spell_info", "duration1", spell->duration1);
  851. packet->setSubstructDataByName("spell_info", "duration2", spell->duration2);
  852. //unknown9 ??
  853. //duration flag??
  854. packet->setSubstructDataByName("spell_info", "target", spell->target_type);
  855. packet->setSubstructDataByName("spell_info", "can_effect_raid", spell->can_effect_raid);
  856. packet->setSubstructDataByName("spell_info", "affect_only_group_members", spell->affect_only_group_members);
  857. packet->setSubstructDataByName("spell_info", "group_spell", spell->group_spell);
  858. packet->setSubstructDataByName("spell_info", "resistibility", spell->resistibility);
  859. //unknown11 ??
  860. //hit_bonus ??
  861. //unknown12 ??
  862. packet->setSubstructDataByName("spell_info", "name", &(spell->name));
  863. packet->setSubstructDataByName("spell_info", "description", &(spell->description));
  864. EQ2Packet* packetdata = packet->serialize();
  865. //EQ2Packet* app = new EQ2Packet(OP_AdventureList, packetdata->pBuffer, packetdata->size);
  866. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, packetdata->pBuffer, packetdata->size);
  867. packet->PrintPacket();
  868. //DumpPacket(app);
  869. safe_delete(packet);
  870. safe_delete(data);
  871. return app;
  872. */
  873. }
  874. EQ2Packet* Spell::SerializeSpell(Client* client, bool display, bool trait_display, int8 packet_type, int8 sub_packet_type, const char* struct_name){
  875. int16 version = 1;
  876. if(client)
  877. version = client->GetVersion();
  878. if(!struct_name)
  879. struct_name = "WS_ExamineSpellInfo";
  880. PacketStruct* packet = configReader.getStruct(struct_name, version);
  881. if(display)
  882. packet->setSubstructDataByName("info_header", "show_name", 1);
  883. else
  884. if (!trait_display)
  885. packet->setSubstructDataByName("info_header", "show_popup", 1);
  886. else
  887. packet->setSubstructDataByName("info_header", "show_popup", 0);
  888. if(packet_type > 0)
  889. packet->setSubstructDataByName("info_header", "packettype", packet_type*256 + 0xFE);
  890. else
  891. packet->setSubstructDataByName("info_header", "packettype", GetItemPacketType(version));
  892. //packet->setDataByName("unknown2",5);
  893. //packet->setDataByName("unknown7", 1);
  894. //packet->setDataByName("unknown9", 20);
  895. //packet->setDataByName("unknown10", 1, 2);
  896. if(sub_packet_type == 0)
  897. sub_packet_type = 0x83;
  898. packet->setSubstructDataByName("info_header", "packetsubtype", sub_packet_type);
  899. //packet->setDataByName("unknown3",2);
  900. //packet->setDataByName("unknown7", 50);
  901. if(sub_packet_type == 0x81)
  902. SetPacketInformation(packet, client);
  903. else
  904. SetPacketInformation(packet, client, true);
  905. packet->setSubstructDataByName("spell_info", "uses_remaining", 0xFFFF);
  906. packet->setSubstructDataByName("spell_info", "damage_remaining", 0xFFFF);
  907. //packet->PrintPacket();
  908. // This adds the second portion to the spell packet. Could be used for bonuses etc.?
  909. int8 offset = 0;
  910. if (packet->GetVersion() == 60114) {
  911. offset = 28;
  912. }
  913. else {
  914. offset = 14;
  915. }
  916. string* data1 = packet->serializeString();
  917. uchar* data2 = (uchar*)data1->c_str();
  918. uchar* ptr2 = data2;
  919. int32 size = data1->length() * 2;
  920. uchar* data3 = new uchar[size];
  921. memcpy(data3, data2, data1->length());
  922. uchar* ptr = data3;
  923. size -=offset+3;
  924. memcpy(ptr, &size, sizeof(int32));
  925. size +=3;
  926. ptr += data1->length();
  927. ptr2 += offset;
  928. memcpy(ptr, ptr2, data1->length() - offset);
  929. EQ2Packet* outapp = new EQ2Packet(OP_ClientCmdMsg, data3, size);
  930. //DumpPacket(outapp);
  931. safe_delete_array(data3);
  932. safe_delete(packet);
  933. return outapp;
  934. }
  935. void Spell::AddSpellEffect(int8 percentage, int8 subbullet, string description){
  936. SpellDisplayEffect* effect = new SpellDisplayEffect;
  937. effect->description = description;
  938. effect->subbullet = subbullet;
  939. effect->percentage = percentage;
  940. MSpellInfo.lock();
  941. effects.push_back(effect);
  942. MSpellInfo.unlock();
  943. }
  944. int16 Spell::GetHPRequired(Spawn* spawn){
  945. int16 hp_req = spell->hp_req;
  946. if(spawn && spell->hp_req_percent > 0){
  947. double result = ((double)spell->hp_req_percent/100)*spawn->GetTotalHP();
  948. if(result >= (((int16)result) + .5))
  949. result++;
  950. hp_req = (int16)result;
  951. }
  952. return hp_req;
  953. }
  954. int16 Spell::GetPowerRequired(Spawn* spawn){
  955. int16 power_req;
  956. if (spell->power_by_level == true) {
  957. power_req =round( (spell->power_req) * spawn->GetLevel());
  958. }
  959. else {
  960. power_req = round(spell->power_req);
  961. }
  962. if(spawn && spell->power_req_percent > 0){
  963. double result = ((double)spell->power_req_percent/100)*spawn->GetTotalPower();
  964. if(result >= (((int16)result) + .5))
  965. result++;
  966. power_req = (int16)result;
  967. }
  968. return power_req;
  969. }
  970. int16 Spell::GetSavageryRequired(Spawn* spawn){
  971. int16 savagery_req = spell->savagery_req;
  972. if(spawn && spell->savagery_req_percent > 0){
  973. double result = ((double)spell->savagery_req_percent/100)*spawn->GetTotalSavagery();
  974. if(result >= (((int16)result) + .5))
  975. result++;
  976. savagery_req = (int16)result;
  977. }
  978. return savagery_req;
  979. }
  980. int16 Spell::GetDissonanceRequired(Spawn* spawn){
  981. int16 dissonance_req = spell->dissonance_req;
  982. if(spawn && spell->dissonance_req_percent > 0){
  983. double result = ((double)spell->dissonance_req_percent/100)*spawn->GetTotalDissonance();
  984. if(result >= (((int16)result) + .5))
  985. result++;
  986. dissonance_req = (int16)result;
  987. }
  988. return dissonance_req;
  989. }
  990. int32 Spell::GetSpellDuration(){
  991. if(spell->duration1 == spell->duration2)
  992. return spell->duration1;
  993. int32 difference = 0;
  994. int32 lower = 0;
  995. if(spell->duration2 > spell->duration1){
  996. difference = spell->duration2 - spell->duration1;
  997. lower = spell->duration1;
  998. }
  999. else{
  1000. difference = spell->duration1 - spell->duration2;
  1001. lower = spell->duration2;
  1002. }
  1003. int32 duration = (rand()%difference) + lower;
  1004. return duration;
  1005. }
  1006. const char* Spell::GetName(){
  1007. return spell->name.data.c_str();
  1008. }
  1009. const char* Spell::GetDescription(){
  1010. return spell->description.data.c_str();
  1011. }
  1012. void Spell::AddSpellLevel(int8 adventure_class, int8 tradeskill_class, int16 level){
  1013. LevelArray* lvl = new LevelArray;
  1014. lvl->adventure_class = adventure_class;
  1015. lvl->tradeskill_class = tradeskill_class;
  1016. lvl->spell_level = level;
  1017. MSpellInfo.lock();
  1018. levels.push_back(lvl);
  1019. MSpellInfo.unlock();
  1020. }
  1021. int32 Spell::GetSpellID(){
  1022. if (spell)
  1023. return spell->id;
  1024. return 0;
  1025. }
  1026. int8 Spell::GetSpellTier(){
  1027. if (spell)
  1028. return spell->tier;
  1029. return 0;
  1030. }
  1031. vector<LUAData*>* Spell::GetLUAData(){
  1032. return &lua_data;
  1033. }
  1034. SpellData* Spell::GetSpellData(){
  1035. return spell;
  1036. }
  1037. int16 Spell::GetSpellIcon(){
  1038. if (spell)
  1039. return spell->icon;
  1040. return 0;
  1041. }
  1042. int16 Spell::GetSpellIconBackdrop(){
  1043. if (spell)
  1044. return spell->icon_backdrop;
  1045. return 0;
  1046. }
  1047. int16 Spell::GetSpellIconHeroicOp(){
  1048. if (spell)
  1049. return spell->icon_heroic_op;
  1050. return 0;
  1051. }
  1052. bool Spell::IsHealSpell(){
  1053. return heal_spell;
  1054. }
  1055. bool Spell::IsBuffSpell(){
  1056. return buff_spell;
  1057. }
  1058. bool Spell::IsDamageSpell(){
  1059. return damage_spell;
  1060. }
  1061. bool Spell::IsControlSpell(){
  1062. return control_spell;
  1063. }
  1064. bool Spell::IsOffenseSpell(){
  1065. return offense_spell;
  1066. }
  1067. void Spell::ModifyCastTime(Entity* caster){
  1068. int16 cast_time = spell->cast_time;
  1069. float cast_speed = caster->GetInfoStruct()->casting_speed;
  1070. if (cast_time > 0){
  1071. if (cast_speed > 0) // casting speed can only reduce up to half a cast time
  1072. spell->cast_time *= max((float) 0.5, (float) (1 / (1 + (cast_speed * .01))));
  1073. 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
  1074. spell->cast_time *= min((float) 1.5, (float) (1 + (1 - (1 / (1 + (cast_speed * -.01))))));
  1075. }
  1076. }
  1077. vector <SpellDisplayEffect*>* Spell::GetSpellEffects(){
  1078. MSpellInfo.lock();
  1079. vector <SpellDisplayEffect*>* ret = &effects;
  1080. MSpellInfo.unlock();
  1081. return ret;
  1082. }
  1083. vector <LevelArray*>* Spell::GetSpellLevels(){
  1084. MSpellInfo.lock();
  1085. vector <LevelArray*>* ret = &levels;
  1086. MSpellInfo.unlock();
  1087. return ret;
  1088. }
  1089. bool Spell::ScribeAllowed(Player* player){
  1090. bool ret = false;
  1091. if(player){
  1092. MSpellInfo.lock();
  1093. for(int32 i=0;!ret && i<levels.size();i++){
  1094. int16 mylevel = player->GetLevel();
  1095. int16 spelllevels = levels[i]->spell_level;
  1096. bool advlev = player->GetAdventureClass() == levels[i]->adventure_class;
  1097. bool tslev = player->GetTradeskillClass() == levels[i]->tradeskill_class;
  1098. bool levelmatch = player->GetLevel() >= levels[i]->spell_level;
  1099. if((player->GetAdventureClass() == levels[i]->adventure_class || player->GetTradeskillClass() == levels[i]->tradeskill_class) && player->GetLevel() >= levels[i]->spell_level/10)
  1100. ret = true;
  1101. }
  1102. MSpellInfo.unlock();
  1103. }
  1104. return ret;
  1105. }
  1106. MasterSpellList::MasterSpellList(){
  1107. MMasterSpellList.SetName("MasterSpellList::MMasterSpellList");
  1108. }
  1109. MasterSpellList::~MasterSpellList(){
  1110. DestroySpells();
  1111. }
  1112. void MasterSpellList::DestroySpells(){
  1113. spell_errors.clear();
  1114. MMasterSpellList.lock();
  1115. map<int32, map<int32, Spell*> >::iterator iter;
  1116. map<int32, Spell*>::iterator iter2;
  1117. for(iter = spell_list.begin();iter != spell_list.end(); iter++){
  1118. for(iter2 = iter->second.begin();iter2 != iter->second.end(); iter2++){
  1119. safe_delete(iter2->second);
  1120. }
  1121. }
  1122. spell_list.clear();
  1123. MMasterSpellList.unlock();
  1124. }
  1125. void MasterSpellList::AddSpell(int32 id, int8 tier, Spell* spell){
  1126. MMasterSpellList.lock();
  1127. spell_list[id][tier] = spell;
  1128. spell_name_map[spell->GetName()] = spell;
  1129. spell_soecrc_map[spell->GetSpellData()->soe_spell_crc] = spell;
  1130. MMasterSpellList.unlock();
  1131. }
  1132. Spell* MasterSpellList::GetSpell(int32 id, int8 tier){
  1133. if (spell_list.count(id) > 0 && spell_list[id].count(tier) > 0)
  1134. return spell_list[id][tier];
  1135. return 0;
  1136. }
  1137. Spell* MasterSpellList::GetSpellByName(const char* name){
  1138. if(spell_name_map.count(name) > 0)
  1139. return spell_name_map[name];
  1140. return 0;
  1141. }
  1142. Spell* MasterSpellList::GetSpellByCRC(int32 spell_crc){
  1143. if(spell_soecrc_map.count(spell_crc) > 0)
  1144. return spell_soecrc_map[spell_crc];
  1145. return 0;
  1146. }
  1147. EQ2Packet* MasterSpellList::GetSpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type){
  1148. Spell* spell = GetSpell(id, tier);
  1149. if(spell)
  1150. return spell->SerializeSpell(client, display, packet_type);
  1151. return 0;
  1152. }
  1153. EQ2Packet* MasterSpellList::GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  1154. Spell* spell = GetSpell(id, (tier == 0 ? 1 : tier));
  1155. //Spell* spell2= GetSpell(id, (tier +1));
  1156. AltAdvanceData* data = master_aa_list.GetAltAdvancement(id);
  1157. if (spell)
  1158. return spell->SerializeAASpell(client,tier, data, display,false, packet_type);
  1159. return 0;
  1160. }
  1161. EQ2Packet* MasterSpellList::GetSpecialSpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type){
  1162. Spell* spell = GetSpell(id, tier);
  1163. if(spell)
  1164. return spell->SerializeSpecialSpell(client, display, packet_type, 0x81);
  1165. return 0;
  1166. }
  1167. vector<Spell*>* MasterSpellList::GetSpellListByAdventureClass(int8 class_id, int16 max_level, int8 max_tier){
  1168. vector<Spell*>* ret = new vector<Spell*>;
  1169. Spell* spell = 0;
  1170. vector<LevelArray*>* levels = 0;
  1171. LevelArray* level = 0;
  1172. vector<LevelArray*>::iterator level_itr;
  1173. MMasterSpellList.lock();
  1174. map<int32, map<int32, Spell*> >::iterator iter;
  1175. map<int32, Spell*>::iterator iter2;
  1176. max_level *= 10; //convert to client level format, which is 10 times higher
  1177. for(iter = spell_list.begin();iter != spell_list.end(); iter++){
  1178. for(iter2 = iter->second.begin();iter2 != iter->second.end(); iter2++){
  1179. spell = iter2->second;
  1180. if(iter2->first <= max_tier && spell){
  1181. levels = spell->GetSpellLevels();
  1182. for(level_itr = levels->begin(); level_itr != levels->end(); level_itr++){
  1183. level = *level_itr;
  1184. if(level->spell_level <= max_level && level->adventure_class == class_id){
  1185. ret->push_back(spell);
  1186. break;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. }
  1192. MMasterSpellList.unlock();
  1193. return ret;
  1194. }
  1195. vector<Spell*>* MasterSpellList::GetSpellListByTradeskillClass(int8 class_id, int16 max_level, int8 max_tier){
  1196. vector<Spell*>* ret = new vector<Spell*>;
  1197. Spell* spell = 0;
  1198. vector<LevelArray*>* levels = 0;
  1199. LevelArray* level = 0;
  1200. vector<LevelArray*>::iterator level_itr;
  1201. MMasterSpellList.lock();
  1202. map<int32, map<int32, Spell*> >::iterator iter;
  1203. map<int32, Spell*>::iterator iter2;
  1204. for(iter = spell_list.begin();iter != spell_list.end(); iter++){
  1205. for(iter2 = iter->second.begin();iter2 != iter->second.end(); iter2++){
  1206. spell = iter2->second;
  1207. if(iter2->first <= max_tier && spell){
  1208. levels = spell->GetSpellLevels();
  1209. for(level_itr = levels->begin(); level_itr != levels->end(); level_itr++){
  1210. level = *level_itr;
  1211. if(level->spell_level <= max_level && level->tradeskill_class == class_id){
  1212. ret->push_back(spell);
  1213. break;
  1214. }
  1215. }
  1216. }
  1217. }
  1218. }
  1219. MMasterSpellList.unlock();
  1220. return ret;
  1221. }
  1222. void MasterSpellList::Reload(){
  1223. master_trait_list.DestroyTraits();
  1224. DestroySpells();
  1225. database.LoadSpells();
  1226. database.LoadSpellErrors();
  1227. database.LoadTraits();
  1228. }
  1229. int16 MasterSpellList::GetSpellErrorValue(int16 version, int8 error_index) {
  1230. version = GetClosestVersion(version);
  1231. if (spell_errors[version].count(error_index) == 0) {
  1232. LogWrite(SPELL__ERROR, 0, "Spells", "No spell error entry. (version = %i, error_index = %i)", version, error_index);
  1233. // 1 will give the client a pop up message of "Cannot cast" and a chat message of "[BUG] Cannot cast. Unknown failure casting spell."
  1234. return 1;
  1235. }
  1236. return spell_errors[version][error_index];
  1237. }
  1238. void MasterSpellList::AddSpellError(int16 version, int8 error_index, int16 error_value) {
  1239. if (spell_errors[version].count(error_index) == 0)
  1240. spell_errors[version][error_index] = error_value;
  1241. }
  1242. int16 MasterSpellList::GetClosestVersion(int16 version) {
  1243. int16 ret = 0;
  1244. map<int16, map<int8, int16> >::iterator itr;
  1245. // Get the closest version in the list that is less then or equal to the given version
  1246. for (itr = spell_errors.begin(); itr != spell_errors.end(); itr++) {
  1247. if (itr->first <= version) {
  1248. if (itr->first > ret)
  1249. ret = itr->first;
  1250. }
  1251. }
  1252. return ret;
  1253. }
  1254. bool Spell::CastWhileStunned(){
  1255. return (spell->casting_flags & CASTING_FLAG_STUNNED) == CASTING_FLAG_STUNNED;
  1256. }
  1257. bool Spell::CastWhileMezzed(){
  1258. return (spell->casting_flags & CASTING_FLAG_MEZZED) == CASTING_FLAG_MEZZED;
  1259. }
  1260. bool Spell::CastWhileStifled(){
  1261. return (spell->casting_flags & CASTING_FLAG_STIFLED) == CASTING_FLAG_STIFLED;
  1262. }
  1263. bool Spell::CastWhileFeared(){
  1264. return (spell->casting_flags & CASTING_FLAG_FEARED) == CASTING_FLAG_FEARED;
  1265. }