9
3

Spells.cpp 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422
  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 if (packet->GetVersion() <= 546) {
  523. packet->setSubstructDataByName("spell_info", "version", 0x10);
  524. packet->setSubstructDataByName("spell_info", "sub_version", 0x0f);
  525. }
  526. else {
  527. packet->setSubstructDataByName("spell_info", "version", 0x11);
  528. packet->setSubstructDataByName("spell_info", "sub_version", 0x14);
  529. }
  530. packet->setSubstructDataByName("spell_info", "type", spell->type);
  531. packet->setSubstructDataByName("spell_info", "unknown_MJ1d", 1); //63119 test
  532. packet->setSubstructDataByName("spell_info", "class_skill", spell->class_skill);
  533. packet->setSubstructDataByName("spell_info", "mastery_skill", spell->mastery_skill);
  534. packet->setSubstructDataByName("spell_info", "duration_flag", spell->duration_until_cancel);
  535. if (client && spell->type != 2) {
  536. sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client->GetPlayer()));
  537. if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
  538. spell_text_color = ARROW_COLOR_WHITE;
  539. spell_text_color -= 6;
  540. if (spell_text_color < 0)
  541. spell_text_color *= -1;
  542. packet->setSubstructDataByName("spell_info", "spell_text_color", spell_text_color);
  543. }
  544. else
  545. packet->setSubstructDataByName("spell_info", "spell_text_color", 3);
  546. if (spell->type != 2) {
  547. packet->setSubstructArrayLengthByName("spell_info", "num_levels", levels.size());
  548. for (int32 i = 0; i < levels.size(); i++) {
  549. packet->setArrayDataByName("adventure_class", levels[i]->adventure_class, i);
  550. packet->setArrayDataByName("tradeskill_class", levels[i]->tradeskill_class, i);
  551. packet->setArrayDataByName("spell_level", levels[i]->spell_level, i);
  552. }
  553. }
  554. packet->setSubstructDataByName("spell_info", "unknown9", 20);
  555. int16 hp_req = 0;
  556. int16 power_req = 0;
  557. if (client) {
  558. hp_req = GetHPRequired(client->GetPlayer());
  559. power_req = GetPowerRequired(client->GetPlayer());
  560. // might need version checks around these?
  561. if (client->GetVersion() >= 1193)
  562. {
  563. int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
  564. packet->setSubstructDataByName("spell_info", "savagery_req", savagery_req);
  565. packet->setSubstructDataByName("spell_info", "savagery_upkeep", spell->savagery_upkeep);
  566. }
  567. if (client->GetVersion() >= 57048)
  568. {
  569. int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
  570. packet->setSubstructDataByName("spell_info", "dissonance_req", dissonance_req);
  571. packet->setSubstructDataByName("spell_info", "dissonance_upkeep", spell->dissonance_upkeep);
  572. }
  573. }
  574. packet->setSubstructDataByName("spell_info", "target", spell->target_type);
  575. packet->setSubstructDataByName("spell_info", "recovery", spell->recovery);
  576. packet->setSubstructDataByName("spell_info", "health_upkeep", spell->hp_upkeep);
  577. packet->setSubstructDataByName("spell_info", "health_req", hp_req);
  578. packet->setSubstructDataByName("spell_info", "tier", spell->tier);
  579. packet->setSubstructDataByName("spell_info", "power_req", power_req);
  580. packet->setSubstructDataByName("spell_info", "power_upkeep", spell->power_upkeep);
  581. packet->setSubstructDataByName("spell_info", "cast_time", spell->cast_time);
  582. packet->setSubstructDataByName("spell_info", "recast", spell->recast);
  583. packet->setSubstructDataByName("spell_info", "radius", spell->radius);
  584. packet->setSubstructDataByName("spell_info", "req_concentration", spell->req_concentration);
  585. //packet->setSubstructDataByName("spell_info","req_concentration2", 2);
  586. packet->setSubstructDataByName("spell_info", "max_aoe_targets", spell->max_aoe_targets);
  587. packet->setSubstructDataByName("spell_info", "friendly_spell", spell->friendly_spell);
  588. packet->setSubstructArrayLengthByName("spell_info", "num_effects", effects.size());
  589. for (int32 i = 0; i < effects.size(); i++) {
  590. packet->setArrayDataByName("subbulletflag", effects[i]->subbullet, i);
  591. string effect_message;
  592. if (effects[i]->description.length() > 0) {
  593. effect_message = effects[i]->description;
  594. if (effect_message.find("%LM") < 0xFFFFFFFF) {
  595. int string_index = effect_message.find("%LM");
  596. int data_index = stoi(effect_message.substr(string_index + 3, 2));
  597. float value;
  598. if (lua_data[data_index]->type == 1)
  599. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  600. else
  601. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  602. string strValue = to_string(value);
  603. strValue.erase(strValue.find_last_not_of('0') + 1, std::string::npos);
  604. effect_message.replace(effect_message.find("%LM"), 5, strValue);
  605. }
  606. // Magic damage min
  607. if (effect_message.find("%DML") < 0xFFFFFFFF) {
  608. int string_index = effect_message.find("%DML");
  609. int data_index = stoi(effect_message.substr(string_index + 4, 2));
  610. float value;
  611. if (lua_data[data_index]->type == 1)
  612. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  613. else
  614. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  615. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  616. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  617. value += mod;
  618. string damage = to_string((int)round(value));
  619. effect_message.replace(effect_message.find("%DML"), 6, damage);
  620. }
  621. // Magic damage max
  622. if (effect_message.find("%DMH") < 0xFFFFFFFF) {
  623. int string_index = effect_message.find("%DMH");
  624. int data_index = stoi(effect_message.substr(string_index + 4, 2));
  625. float value;
  626. if (lua_data[data_index]->type == 1)
  627. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  628. else
  629. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  630. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  631. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  632. value += mod;
  633. string damage = to_string((int)round(value));
  634. effect_message.replace(effect_message.find("%DMH"), 6, damage);
  635. }
  636. // level based Magic damage min
  637. if (effect_message.find("%LDML") < 0xFFFFFFFF) {
  638. int string_index = effect_message.find("%LDML");
  639. int data_index = stoi(effect_message.substr(string_index + 5, 2));
  640. float value;
  641. if (lua_data[data_index]->type == 1)
  642. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  643. else
  644. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  645. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  646. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  647. value += mod;
  648. string damage = to_string((int)round(value));
  649. effect_message.replace(effect_message.find("%LDML"), 7, damage);
  650. }
  651. // level based Magic damage max
  652. if (effect_message.find("%LDMH") < 0xFFFFFFFF) {
  653. int string_index = effect_message.find("%LDMH");
  654. int data_index = stoi(effect_message.substr(string_index + 5, 2));
  655. float value;
  656. if (lua_data[data_index]->type == 1)
  657. value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
  658. else
  659. value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
  660. value *= ((client->GetPlayer()->GetInfoStruct()->potency / 100) + 1);
  661. int32 mod = (int32)min(client->GetPlayer()->GetInfoStruct()->ability_modifier, (float)(value / 2));
  662. value += mod;
  663. string damage = to_string((int)round(value));
  664. effect_message.replace(effect_message.find("%LDMH"), 7, damage);
  665. }
  666. //GetZone()->SimpleMessage(CHANNEL_COLOR_SPELL_EFFECT, effect_message.c_str(), victim, 50);
  667. }
  668. packet->setArrayDataByName("effect", effect_message.c_str(), i);
  669. packet->setArrayDataByName("percentage", effects[i]->percentage, i);
  670. }
  671. if (display_tier == true)
  672. packet->setSubstructDataByName("spell_info", "display_spell_tier", spell->display_spell_tier);
  673. else
  674. packet->setSubstructDataByName("spell_info", "display_spell_tier", 0);
  675. packet->setSubstructDataByName("spell_info", "range", spell->range);
  676. packet->setSubstructDataByName("spell_info", "duration1", spell->duration1);
  677. packet->setSubstructDataByName("spell_info", "duration2", spell->duration2);
  678. packet->setSubstructDataByName("spell_info", "can_effect_raid", spell->can_effect_raid);
  679. packet->setSubstructDataByName("spell_info", "affect_only_group_members", spell->affect_only_group_members);
  680. packet->setSubstructDataByName("spell_info", "group_spell", spell->group_spell);
  681. packet->setSubstructDataByName("spell_info", "resistibility", spell->resistibility);
  682. packet->setSubstructDataByName("spell_info", "name", &(spell->name));
  683. packet->setSubstructDataByName("spell_info", "description", &(spell->description));
  684. //packet->PrintPacket();
  685. }
  686. EQ2Packet* Spell::SerializeSpecialSpell(Client* client, bool display, int8 packet_type, int8 sub_packet_type) {
  687. if (client->GetVersion() <= 283)
  688. return SerializeSpell(client, display, false, packet_type, 0, "WS_ExaminePartialSpellInfo");
  689. return SerializeSpell(client, display, false, packet_type, sub_packet_type, "WS_ExamineSpecialSpellInfo");
  690. }
  691. 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) {
  692. if (!client)
  693. return 0;
  694. int16 version = 1;
  695. if (client)
  696. version = client->GetVersion();
  697. if (!struct_name)
  698. struct_name = "WS_ExamineAASpellInfo";
  699. PacketStruct* packet = configReader.getStruct(struct_name, version);
  700. if (display)
  701. packet->setSubstructDataByName("info_header", "show_name", 1);//1
  702. else
  703. if (!trait_display)
  704. packet->setSubstructDataByName("info_header", "show_popup", 1);//1
  705. else
  706. packet->setSubstructDataByName("info_header", "show_popup", 0);
  707. if (packet_type > 0)
  708. packet->setSubstructDataByName("info_header", "packettype", packet_type * 256 + 0xFE);
  709. else
  710. packet->setSubstructDataByName("info_header", "packettype", 0x4FFE);// 0x45FE GetItemPacketType(version));
  711. //packet->setDataByName("unknown2",5);
  712. //packet->setDataByName("unknown7", 1);
  713. //packet->setDataByName("unknown9", 20);
  714. //packet->setDataByName("unknown10", 1, 2);
  715. if (sub_packet_type == 0)
  716. sub_packet_type = 0x83;
  717. packet->setSubstructDataByName("info_header", "packetsubtype", 4);// sub_packet_type);
  718. packet->setSubstructDataByName("spell_info", "aa_id", data->spellID);
  719. packet->setSubstructDataByName("spell_info", "aa_tab_id", data->group);
  720. packet->setSubstructDataByName("spell_info", "aa_icon", data->icon);
  721. packet->setSubstructDataByName("spell_info", "aa_icon2", data->icon2);
  722. packet->setSubstructDataByName("spell_info", "aa_current_rank", tier); // how to get this info to here?
  723. packet->setSubstructDataByName("spell_info", "aa_max_rank", data->maxRank);
  724. packet->setSubstructDataByName("spell_info", "aa_rank_cost", data->rankCost);
  725. packet->setSubstructDataByName("spell_info", "aa_unknown_2", 20);
  726. packet->setSubstructDataByName("spell_info", "aa_name", &(spell->name));
  727. packet->setSubstructDataByName("spell_info", "aa_description", &(spell->description));
  728. //packet->setDataByName("unknown3",2);
  729. //packet->setDataByName("unknown7", 50);
  730. if (sub_packet_type == 0x81)
  731. SetAAPacketInformation(packet, data, client);
  732. else
  733. SetAAPacketInformation(packet, data, client, true);
  734. packet->setSubstructDataByName("spell_info", "uses_remaining", 0xFFFF);
  735. packet->setSubstructDataByName("spell_info", "damage_remaining", 0xFFFF);
  736. //packet->PrintPacket();
  737. // This adds the second portion to the spell packet. Could be used for bonuses etc.?
  738. string* data1 = packet->serializeString();
  739. uchar* data2 = (uchar*)data1->c_str();
  740. uchar* ptr2 = data2;
  741. int32 size = data1->length();// *2;
  742. ////uchar* data3 = new uchar[size];
  743. ////memcpy(data3, data2, data1->length());
  744. ////uchar* ptr = data3;
  745. ////size -= 17;
  746. ////memcpy(ptr, &size, sizeof(int32));
  747. ////size += 3;
  748. ////ptr += data1->length();
  749. ////ptr2 += 14;
  750. ////memcpy(ptr, ptr2, data1->length() - 14);
  751. EQ2Packet* outapp = new EQ2Packet(OP_ClientCmdMsg, data2, size);
  752. //DumpPacket(outapp);
  753. //safe_delete_array(data3);
  754. safe_delete(packet);
  755. return outapp;
  756. /*PacketStruct* packet = configReader.getStruct("WS_ExamineAASpellInfo", client->GetVersion());
  757. packet->setSubstructDataByName("info_header", "show_name", 0);
  758. packet->setSubstructDataByName("info_header", "show_popup", 0);
  759. packet->setSubstructDataByName("info_header", "packettype", packet_type);
  760. packet->setSubstructDataByName("info_header", "packetsubtype", sub_packet_type);
  761. packet->setSubstructDataByName("Spell_info", "aa_id", data->spellID);
  762. packet->setSubstructDataByName("Spell_info", "aa_tab_id", data->group);
  763. packet->setSubstructDataByName("Spell_info", "aa_icon", data->icon);
  764. packet->setSubstructDataByName("Spell_info", "aa_icon2", data->icon2);
  765. packet->setSubstructDataByName("Spell_info", "current_rank", 0); // how to get this info to here?
  766. packet->setSubstructDataByName("Spell_info", "max_rank", data->maxRank);
  767. packet->setSubstructDataByName("Spell_info", "rank_cost", data->rankCost);
  768. packet->setSubstructDataByName("spell_info", "unknown2", 20);
  769. // Spell info
  770. packet->setSubstructDataByName("spell_info", "id", spell->id);
  771. packet->setSubstructDataByName("spell_info", "icon", spell->icon);
  772. packet->setSubstructDataByName("spell_info", "icon2", spell->icon_heroic_op); // fix struct element name eventually
  773. packet->setSubstructDataByName("spell_info", "icontype", spell->icon_backdrop); // fix struct element name eventually
  774. if (packet->GetVersion() >= 63119) {
  775. packet->setSubstructDataByName("spell_info", "version", 0x04);
  776. packet->setSubstructDataByName("spell_info", "sub_version", 0x24);
  777. }
  778. else if (packet->GetVersion() >= 1193) {
  779. packet->setSubstructDataByName("spell_info", "version", 0x00);
  780. packet->setSubstructDataByName("spell_info", "sub_version", 0xD9);
  781. }
  782. else {
  783. packet->setSubstructDataByName("spell_info", "version", 0x11);
  784. packet->setSubstructDataByName("spell_info", "sub_version", 0x14);
  785. }
  786. packet->setSubstructDataByName("spell_info", "type", spell->type);
  787. packet->setSubstructDataByName("spell_info", "unknown_MJ1d", 1); //63119 test
  788. packet->setSubstructDataByName("spell_info", "class_skill", spell->class_skill);
  789. packet->setSubstructDataByName("spell_info", "mastery_skill", spell->mastery_skill);
  790. packet->setSubstructDataByName("spell_info", "duration_flag", spell->duration_until_cancel);
  791. if (client && spell->type != 2) {
  792. sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client));
  793. if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
  794. spell_text_color = ARROW_COLOR_WHITE;
  795. spell_text_color -= 6;
  796. if (spell_text_color < 0)
  797. spell_text_color *= -1;
  798. packet->setSubstructDataByName("spell_info", "spell_text_color", spell_text_color);
  799. }
  800. else
  801. packet->setSubstructDataByName("spell_info", "spell_text_color", 3);
  802. if (spell->type != 2) {
  803. packet->setSubstructArrayLengthByName("spell_info", "num_levels", levels.size());
  804. for (int32 i = 0; i < levels.size(); i++) {
  805. packet->setArrayDataByName("adventure_class", levels[i]->adventure_class, i);
  806. packet->setArrayDataByName("tradeskill_class", levels[i]->tradeskill_class, i);
  807. packet->setArrayDataByName("spell_level", levels[i]->spell_level, i);
  808. }
  809. }
  810. //packet->setSubstructDataByName("spell_info", "unknown9", 20);
  811. int16 hp_req = 0;
  812. int16 power_req = 0;
  813. if (client) {
  814. hp_req = GetHPRequired(client->GetPlayer());
  815. power_req = GetPowerRequired(client->GetPlayer());
  816. // might need version checks around these?
  817. if (client->GetVersion() >= 1193)
  818. {
  819. int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
  820. packet->setSubstructDataByName("spell_info", "savagery_req", savagery_req);
  821. packet->setSubstructDataByName("spell_info", "savagery_upkeep", spell->savagery_upkeep);
  822. }
  823. if (client->GetVersion() >= 57048)
  824. {
  825. int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
  826. packet->setSubstructDataByName("spell_info", "dissonance_req", dissonance_req);
  827. packet->setSubstructDataByName("spell_info", "dissonance_upkeep", spell->dissonance_upkeep);
  828. }
  829. }
  830. packet->setSubstructDataByName("spell_info", "tier", spell->tier);
  831. packet->setSubstructDataByName("spell_info", "health_req", hp_req);
  832. packet->setSubstructDataByName("spell_info", "health_upkeep", spell->hp_upkeep);
  833. packet->setSubstructDataByName("spell_info", "power_req", power_req);
  834. packet->setSubstructDataByName("spell_info", "power_upkeep", spell->power_upkeep);
  835. packet->setSubstructDataByName("spell_info", "req_concentration", spell->req_concentration);
  836. //packet->setDataByName("req_concentration2", 2);
  837. packet->setSubstructDataByName("spell_info", "cast_time", spell->cast_time);
  838. packet->setSubstructDataByName("spell_info", "recovery", spell->recovery);
  839. packet->setSubstructDataByName("spell_info", "recast", spell->recast);
  840. packet->setSubstructDataByName("spell_info", "radius", spell->radius);
  841. packet->setSubstructDataByName("spell_info", "max_aoe_targets", spell->max_aoe_targets);
  842. packet->setSubstructDataByName("spell_info", "friendly_spell", spell->friendly_spell);
  843. //reageants??
  844. packet->setSubstructArrayLengthByName("spell_info", "num_effects", effects.size());
  845. for (int32 i = 0; i < effects.size(); i++) {
  846. packet->setArrayDataByName("subbulletflag", effects[i]->subbullet, i);
  847. packet->setArrayDataByName("effect", effects[i]->description.c_str(), i);
  848. packet->setArrayDataByName("percentage", effects[i]->percentage, i);
  849. }
  850. //if (display_tier == true)
  851. packet->setSubstructDataByName("spell_info", "display_spell_tier", spell->display_spell_tier);
  852. //else
  853. // packet->setSubstructDataByName("spell_info", "display_spell_tier", 0);
  854. // minimum range??
  855. packet->setSubstructDataByName("spell_info", "range", spell->range);
  856. packet->setSubstructDataByName("spell_info", "duration1", spell->duration1);
  857. packet->setSubstructDataByName("spell_info", "duration2", spell->duration2);
  858. //unknown9 ??
  859. //duration flag??
  860. packet->setSubstructDataByName("spell_info", "target", spell->target_type);
  861. packet->setSubstructDataByName("spell_info", "can_effect_raid", spell->can_effect_raid);
  862. packet->setSubstructDataByName("spell_info", "affect_only_group_members", spell->affect_only_group_members);
  863. packet->setSubstructDataByName("spell_info", "group_spell", spell->group_spell);
  864. packet->setSubstructDataByName("spell_info", "resistibility", spell->resistibility);
  865. //unknown11 ??
  866. //hit_bonus ??
  867. //unknown12 ??
  868. packet->setSubstructDataByName("spell_info", "name", &(spell->name));
  869. packet->setSubstructDataByName("spell_info", "description", &(spell->description));
  870. EQ2Packet* packetdata = packet->serialize();
  871. //EQ2Packet* app = new EQ2Packet(OP_AdventureList, packetdata->pBuffer, packetdata->size);
  872. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, packetdata->pBuffer, packetdata->size);
  873. packet->PrintPacket();
  874. //DumpPacket(app);
  875. safe_delete(packet);
  876. safe_delete(data);
  877. return app;
  878. */
  879. }
  880. EQ2Packet* Spell::SerializeSpell(Client* client, bool display, bool trait_display, int8 packet_type, int8 sub_packet_type, const char* struct_name) {
  881. int16 version = 1;
  882. if (client)
  883. version = client->GetVersion();
  884. if (!struct_name)
  885. struct_name = "WS_ExamineSpellInfo";
  886. if (version <= 283) {
  887. if (packet_type == 1)
  888. struct_name = "WS_ExamineEffectInfo";
  889. else if (!display)
  890. struct_name = "WS_ExaminePartialSpellInfo";
  891. else
  892. struct_name = "WS_ExamineSpellInfo";
  893. }
  894. PacketStruct* packet = configReader.getStruct(struct_name, version);
  895. if (display)
  896. packet->setSubstructDataByName("info_header", "show_name", 1);
  897. else {
  898. if (!trait_display)
  899. packet->setSubstructDataByName("info_header", "show_popup", 1);
  900. else
  901. packet->setSubstructDataByName("info_header", "show_popup", 0);
  902. }
  903. if (version > 546) {
  904. if (packet_type > 0)
  905. packet->setSubstructDataByName("info_header", "packettype", packet_type * 256 + 0xFE);
  906. else
  907. packet->setSubstructDataByName("info_header", "packettype", GetItemPacketType(version));
  908. }
  909. else {
  910. if (packet_type == 3 || packet_type == 0)
  911. packet->setSubstructDataByName("info_header", "packettype", 3); // 0: item, 1: effect, 2: recipe, 3: spell/ability
  912. else
  913. packet->setSubstructDataByName("info_header", "packettype", 1);
  914. }
  915. //packet->setDataByName("unknown2",5);
  916. //packet->setDataByName("unknown7", 1);
  917. //packet->setDataByName("unknown9", 20);
  918. //packet->setDataByName("unknown10", 1, 2);
  919. if (sub_packet_type == 0)
  920. sub_packet_type = 0x83;
  921. packet->setSubstructDataByName("info_header", "packetsubtype", sub_packet_type);
  922. //packet->setDataByName("unknown3",2);
  923. //packet->setDataByName("unknown7", 50);
  924. if (sub_packet_type == 0x81)
  925. SetPacketInformation(packet, client);
  926. else
  927. SetPacketInformation(packet, client, true);
  928. packet->setSubstructDataByName("spell_info", "uses_remaining", 0xFFFF);
  929. packet->setSubstructDataByName("spell_info", "damage_remaining", 0xFFFF);
  930. //packet->PrintPacket();
  931. // This adds the second portion to the spell packet. Could be used for bonuses etc.?
  932. int8 offset = 0;
  933. if (packet->GetVersion() == 60114) {
  934. offset = 28;
  935. }
  936. else {
  937. offset = 14;
  938. }
  939. EQ2Packet* outapp = 0;
  940. if (version > 546) {
  941. string* data1 = packet->serializeString();
  942. uchar* data2 = (uchar*)data1->c_str();
  943. uchar* ptr2 = data2;
  944. int32 size = data1->length() * 2;
  945. uchar* data3 = new uchar[size];
  946. memcpy(data3, data2, data1->length());
  947. uchar* ptr = data3;
  948. size -= offset + 3;
  949. memcpy(ptr, &size, sizeof(int32));
  950. size += 3;
  951. ptr += data1->length();
  952. ptr2 += offset;
  953. memcpy(ptr, ptr2, data1->length() - offset);
  954. outapp = new EQ2Packet(OP_ClientCmdMsg, data3, size);
  955. safe_delete_array(data3);
  956. safe_delete(packet);
  957. }
  958. else
  959. outapp = packet->serialize();
  960. //DumpPacket(outapp);
  961. return outapp;
  962. }
  963. void Spell::AddSpellEffect(int8 percentage, int8 subbullet, string description){
  964. SpellDisplayEffect* effect = new SpellDisplayEffect;
  965. effect->description = description;
  966. effect->subbullet = subbullet;
  967. effect->percentage = percentage;
  968. MSpellInfo.lock();
  969. effects.push_back(effect);
  970. MSpellInfo.unlock();
  971. }
  972. int16 Spell::GetHPRequired(Spawn* spawn){
  973. int16 hp_req = spell->hp_req;
  974. if(spawn && spell->hp_req_percent > 0){
  975. double result = ((double)spell->hp_req_percent/100)*spawn->GetTotalHP();
  976. if(result >= (((int16)result) + .5))
  977. result++;
  978. hp_req = (int16)result;
  979. }
  980. return hp_req;
  981. }
  982. int16 Spell::GetPowerRequired(Spawn* spawn){
  983. int16 power_req;
  984. if (spell->power_by_level == true) {
  985. power_req =round( (spell->power_req) * spawn->GetLevel());
  986. }
  987. else {
  988. power_req = round(spell->power_req);
  989. }
  990. if(spawn && spell->power_req_percent > 0){
  991. double result = ((double)spell->power_req_percent/100)*spawn->GetTotalPower();
  992. if(result >= (((int16)result) + .5))
  993. result++;
  994. power_req = (int16)result;
  995. }
  996. return power_req;
  997. }
  998. int16 Spell::GetSavageryRequired(Spawn* spawn){
  999. int16 savagery_req = spell->savagery_req;
  1000. if(spawn && spell->savagery_req_percent > 0){
  1001. double result = ((double)spell->savagery_req_percent/100)*spawn->GetTotalSavagery();
  1002. if(result >= (((int16)result) + .5))
  1003. result++;
  1004. savagery_req = (int16)result;
  1005. }
  1006. return savagery_req;
  1007. }
  1008. int16 Spell::GetDissonanceRequired(Spawn* spawn){
  1009. int16 dissonance_req = spell->dissonance_req;
  1010. if(spawn && spell->dissonance_req_percent > 0){
  1011. double result = ((double)spell->dissonance_req_percent/100)*spawn->GetTotalDissonance();
  1012. if(result >= (((int16)result) + .5))
  1013. result++;
  1014. dissonance_req = (int16)result;
  1015. }
  1016. return dissonance_req;
  1017. }
  1018. int32 Spell::GetSpellDuration(){
  1019. if(spell->duration1 == spell->duration2)
  1020. return spell->duration1;
  1021. int32 difference = 0;
  1022. int32 lower = 0;
  1023. if(spell->duration2 > spell->duration1){
  1024. difference = spell->duration2 - spell->duration1;
  1025. lower = spell->duration1;
  1026. }
  1027. else{
  1028. difference = spell->duration1 - spell->duration2;
  1029. lower = spell->duration2;
  1030. }
  1031. int32 duration = (rand()%difference) + lower;
  1032. return duration;
  1033. }
  1034. const char* Spell::GetName(){
  1035. return spell->name.data.c_str();
  1036. }
  1037. const char* Spell::GetDescription(){
  1038. return spell->description.data.c_str();
  1039. }
  1040. void Spell::AddSpellLevel(int8 adventure_class, int8 tradeskill_class, int16 level){
  1041. LevelArray* lvl = new LevelArray;
  1042. lvl->adventure_class = adventure_class;
  1043. lvl->tradeskill_class = tradeskill_class;
  1044. lvl->spell_level = level;
  1045. MSpellInfo.lock();
  1046. levels.push_back(lvl);
  1047. MSpellInfo.unlock();
  1048. }
  1049. int32 Spell::GetSpellID(){
  1050. if (spell)
  1051. return spell->id;
  1052. return 0;
  1053. }
  1054. int8 Spell::GetSpellTier(){
  1055. if (spell)
  1056. return spell->tier;
  1057. return 0;
  1058. }
  1059. vector<LUAData*>* Spell::GetLUAData(){
  1060. return &lua_data;
  1061. }
  1062. SpellData* Spell::GetSpellData(){
  1063. return spell;
  1064. }
  1065. int16 Spell::GetSpellIcon(){
  1066. if (spell)
  1067. return spell->icon;
  1068. return 0;
  1069. }
  1070. int16 Spell::GetSpellIconBackdrop(){
  1071. if (spell)
  1072. return spell->icon_backdrop;
  1073. return 0;
  1074. }
  1075. int16 Spell::GetSpellIconHeroicOp(){
  1076. if (spell)
  1077. return spell->icon_heroic_op;
  1078. return 0;
  1079. }
  1080. bool Spell::IsHealSpell(){
  1081. return heal_spell;
  1082. }
  1083. bool Spell::IsBuffSpell(){
  1084. return buff_spell;
  1085. }
  1086. bool Spell::IsDamageSpell(){
  1087. return damage_spell;
  1088. }
  1089. bool Spell::IsControlSpell(){
  1090. return control_spell;
  1091. }
  1092. bool Spell::IsOffenseSpell(){
  1093. return offense_spell;
  1094. }
  1095. void Spell::ModifyCastTime(Entity* caster){
  1096. int16 cast_time = spell->cast_time;
  1097. float cast_speed = caster->GetInfoStruct()->casting_speed;
  1098. if (cast_time > 0){
  1099. if (cast_speed > 0) // casting speed can only reduce up to half a cast time
  1100. spell->cast_time *= max((float) 0.5, (float) (1 / (1 + (cast_speed * .01))));
  1101. 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
  1102. spell->cast_time *= min((float) 1.5, (float) (1 + (1 - (1 / (1 + (cast_speed * -.01))))));
  1103. }
  1104. }
  1105. vector <SpellDisplayEffect*>* Spell::GetSpellEffects(){
  1106. MSpellInfo.lock();
  1107. vector <SpellDisplayEffect*>* ret = &effects;
  1108. MSpellInfo.unlock();
  1109. return ret;
  1110. }
  1111. vector <LevelArray*>* Spell::GetSpellLevels(){
  1112. MSpellInfo.lock();
  1113. vector <LevelArray*>* ret = &levels;
  1114. MSpellInfo.unlock();
  1115. return ret;
  1116. }
  1117. bool Spell::ScribeAllowed(Player* player){
  1118. bool ret = false;
  1119. if(player){
  1120. MSpellInfo.lock();
  1121. for(int32 i=0;!ret && i<levels.size();i++){
  1122. int16 mylevel = player->GetLevel();
  1123. int16 spelllevels = levels[i]->spell_level;
  1124. bool advlev = player->GetAdventureClass() == levels[i]->adventure_class;
  1125. bool tslev = player->GetTradeskillClass() == levels[i]->tradeskill_class;
  1126. bool levelmatch = player->GetLevel() >= levels[i]->spell_level;
  1127. if((player->GetAdventureClass() == levels[i]->adventure_class || player->GetTradeskillClass() == levels[i]->tradeskill_class) && player->GetLevel() >= levels[i]->spell_level/10)
  1128. ret = true;
  1129. }
  1130. MSpellInfo.unlock();
  1131. }
  1132. return ret;
  1133. }
  1134. MasterSpellList::MasterSpellList(){
  1135. MMasterSpellList.SetName("MasterSpellList::MMasterSpellList");
  1136. }
  1137. MasterSpellList::~MasterSpellList(){
  1138. DestroySpells();
  1139. }
  1140. void MasterSpellList::DestroySpells(){
  1141. spell_errors.clear();
  1142. MMasterSpellList.lock();
  1143. map<int32, map<int32, Spell*> >::iterator iter;
  1144. map<int32, Spell*>::iterator iter2;
  1145. for(iter = spell_list.begin();iter != spell_list.end(); iter++){
  1146. for(iter2 = iter->second.begin();iter2 != iter->second.end(); iter2++){
  1147. safe_delete(iter2->second);
  1148. }
  1149. }
  1150. spell_list.clear();
  1151. MMasterSpellList.unlock();
  1152. }
  1153. void MasterSpellList::AddSpell(int32 id, int8 tier, Spell* spell){
  1154. MMasterSpellList.lock();
  1155. spell_list[id][tier] = spell;
  1156. spell_name_map[spell->GetName()] = spell;
  1157. spell_soecrc_map[spell->GetSpellData()->soe_spell_crc] = spell;
  1158. MMasterSpellList.unlock();
  1159. }
  1160. Spell* MasterSpellList::GetSpell(int32 id, int8 tier){
  1161. if (spell_list.count(id) > 0 && spell_list[id].count(tier) > 0)
  1162. return spell_list[id][tier];
  1163. else if (spell_list.count(id) > 0 && tier == 0 && spell_list[id].count(1) > 0)
  1164. return spell_list[id][1];
  1165. return 0;
  1166. }
  1167. Spell* MasterSpellList::GetSpellByName(const char* name){
  1168. if(spell_name_map.count(name) > 0)
  1169. return spell_name_map[name];
  1170. return 0;
  1171. }
  1172. Spell* MasterSpellList::GetSpellByCRC(int32 spell_crc){
  1173. if(spell_soecrc_map.count(spell_crc) > 0)
  1174. return spell_soecrc_map[spell_crc];
  1175. return 0;
  1176. }
  1177. EQ2Packet* MasterSpellList::GetSpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type){
  1178. Spell* spell = GetSpell(id, tier);
  1179. if(spell)
  1180. return spell->SerializeSpell(client, display, packet_type);
  1181. return 0;
  1182. }
  1183. EQ2Packet* MasterSpellList::GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  1184. Spell* spell = GetSpell(id, (tier == 0 ? 1 : tier));
  1185. //Spell* spell2= GetSpell(id, (tier +1));
  1186. AltAdvanceData* data = master_aa_list.GetAltAdvancement(id);
  1187. if (spell)
  1188. return spell->SerializeAASpell(client,tier, data, display,false, packet_type);
  1189. return 0;
  1190. }
  1191. EQ2Packet* MasterSpellList::GetSpecialSpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type){
  1192. Spell* spell = GetSpell(id, tier);
  1193. if(spell)
  1194. return spell->SerializeSpecialSpell(client, display, packet_type, 0x81);
  1195. return 0;
  1196. }
  1197. vector<Spell*>* MasterSpellList::GetSpellListByAdventureClass(int8 class_id, int16 max_level, int8 max_tier){
  1198. vector<Spell*>* ret = new vector<Spell*>;
  1199. Spell* spell = 0;
  1200. vector<LevelArray*>* levels = 0;
  1201. LevelArray* level = 0;
  1202. vector<LevelArray*>::iterator level_itr;
  1203. MMasterSpellList.lock();
  1204. map<int32, map<int32, Spell*> >::iterator iter;
  1205. map<int32, Spell*>::iterator iter2;
  1206. max_level *= 10; //convert to client level format, which is 10 times higher
  1207. for(iter = spell_list.begin();iter != spell_list.end(); iter++){
  1208. for(iter2 = iter->second.begin();iter2 != iter->second.end(); iter2++){
  1209. spell = iter2->second;
  1210. if(iter2->first <= max_tier && spell){
  1211. levels = spell->GetSpellLevels();
  1212. for(level_itr = levels->begin(); level_itr != levels->end(); level_itr++){
  1213. level = *level_itr;
  1214. if(level->spell_level <= max_level && level->adventure_class == class_id){
  1215. ret->push_back(spell);
  1216. break;
  1217. }
  1218. }
  1219. }
  1220. }
  1221. }
  1222. MMasterSpellList.unlock();
  1223. return ret;
  1224. }
  1225. vector<Spell*>* MasterSpellList::GetSpellListByTradeskillClass(int8 class_id, int16 max_level, int8 max_tier){
  1226. vector<Spell*>* ret = new vector<Spell*>;
  1227. Spell* spell = 0;
  1228. vector<LevelArray*>* levels = 0;
  1229. LevelArray* level = 0;
  1230. vector<LevelArray*>::iterator level_itr;
  1231. MMasterSpellList.lock();
  1232. map<int32, map<int32, Spell*> >::iterator iter;
  1233. map<int32, Spell*>::iterator iter2;
  1234. for(iter = spell_list.begin();iter != spell_list.end(); iter++){
  1235. for(iter2 = iter->second.begin();iter2 != iter->second.end(); iter2++){
  1236. spell = iter2->second;
  1237. if(iter2->first <= max_tier && spell){
  1238. levels = spell->GetSpellLevels();
  1239. for(level_itr = levels->begin(); level_itr != levels->end(); level_itr++){
  1240. level = *level_itr;
  1241. if(level->spell_level <= max_level && level->tradeskill_class == class_id){
  1242. ret->push_back(spell);
  1243. break;
  1244. }
  1245. }
  1246. }
  1247. }
  1248. }
  1249. MMasterSpellList.unlock();
  1250. return ret;
  1251. }
  1252. void MasterSpellList::Reload(){
  1253. master_trait_list.DestroyTraits();
  1254. DestroySpells();
  1255. database.LoadSpells();
  1256. database.LoadSpellErrors();
  1257. database.LoadTraits();
  1258. }
  1259. int16 MasterSpellList::GetSpellErrorValue(int16 version, int8 error_index) {
  1260. version = GetClosestVersion(version);
  1261. if (spell_errors[version].count(error_index) == 0) {
  1262. LogWrite(SPELL__ERROR, 0, "Spells", "No spell error entry. (version = %i, error_index = %i)", version, error_index);
  1263. // 1 will give the client a pop up message of "Cannot cast" and a chat message of "[BUG] Cannot cast. Unknown failure casting spell."
  1264. return 1;
  1265. }
  1266. return spell_errors[version][error_index];
  1267. }
  1268. void MasterSpellList::AddSpellError(int16 version, int8 error_index, int16 error_value) {
  1269. if (spell_errors[version].count(error_index) == 0)
  1270. spell_errors[version][error_index] = error_value;
  1271. }
  1272. int16 MasterSpellList::GetClosestVersion(int16 version) {
  1273. int16 ret = 0;
  1274. map<int16, map<int8, int16> >::iterator itr;
  1275. // Get the closest version in the list that is less then or equal to the given version
  1276. for (itr = spell_errors.begin(); itr != spell_errors.end(); itr++) {
  1277. if (itr->first <= version) {
  1278. if (itr->first > ret)
  1279. ret = itr->first;
  1280. }
  1281. }
  1282. return ret;
  1283. }
  1284. bool Spell::CastWhileStunned(){
  1285. return (spell->casting_flags & CASTING_FLAG_STUNNED) == CASTING_FLAG_STUNNED;
  1286. }
  1287. bool Spell::CastWhileMezzed(){
  1288. return (spell->casting_flags & CASTING_FLAG_MEZZED) == CASTING_FLAG_MEZZED;
  1289. }
  1290. bool Spell::CastWhileStifled(){
  1291. return (spell->casting_flags & CASTING_FLAG_STIFLED) == CASTING_FLAG_STIFLED;
  1292. }
  1293. bool Spell::CastWhileFeared(){
  1294. return (spell->casting_flags & CASTING_FLAG_FEARED) == CASTING_FLAG_FEARED;
  1295. }