123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430 |
- /*
- EQ2Emulator: Everquest II Server Emulator
- Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
- This file is part of EQ2Emulator.
- EQ2Emulator is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- EQ2Emulator is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "Spells.h"
- #include "../common/ConfigReader.h"
- #include "WorldDatabase.h"
- #include "../common/Log.h"
- #include "Traits/Traits.h"
- #include "AltAdvancement/AltAdvancement.h"
- #include <cmath>
- #include "LuaInterface.h"
- #include <boost/regex.hpp>
- extern ConfigReader configReader;
- extern WorldDatabase database;
- extern MasterTraitList master_trait_list;
- extern MasterAAList master_aa_list;
- extern MasterSpellList master_spell_list;
- extern LuaInterface* lua_interface;
- extern MasterSkillList master_skill_list;
- Spell::Spell(){
- spell = new SpellData;
- heal_spell = false;
- buff_spell = false;
- damage_spell = false;
- control_spell = false;
- offense_spell = false;
- copied_spell = false;
- MSpellInfo.SetName("Spell::MSpellInfo");
- }
- Spell::Spell(Spell* host_spell)
- {
- copied_spell = true;
- spell = new SpellData;
- if (host_spell->GetSpellData())
- {
- // try inheriting an existing custom spell id, otherwise obtain the new highest number on the spell list
- int32 tmpid = lua_interface->GetFreeCustomSpellID();
- if (tmpid)
- spell->id = tmpid;
- else
- {
- spell->id = master_spell_list.GetNewMaxSpellID();
- }
- spell->affect_only_group_members = host_spell->GetSpellData()->affect_only_group_members;
- spell->call_frequency = host_spell->GetSpellData()->call_frequency;
- spell->can_effect_raid = host_spell->GetSpellData()->can_effect_raid;
- spell->casting_flags = host_spell->GetSpellData()->casting_flags;
- spell->cast_time = host_spell->GetSpellData()->cast_time;
- spell->cast_type = host_spell->GetSpellData()->cast_type;
- spell->cast_while_moving = host_spell->GetSpellData()->cast_while_moving;
- spell->class_skill = host_spell->GetSpellData()->class_skill;
- spell->min_class_skill_req = host_spell->GetSpellData()->min_class_skill_req;
- spell->control_effect_type = host_spell->GetSpellData()->control_effect_type;
- spell->description = EQ2_16BitString(host_spell->GetSpellData()->description);
- spell->det_type = host_spell->GetSpellData()->det_type;
- spell->display_spell_tier = host_spell->GetSpellData()->display_spell_tier;
- spell->dissonance_req = host_spell->GetSpellData()->dissonance_req;
- spell->dissonance_req_percent = host_spell->GetSpellData()->dissonance_req_percent;
- spell->dissonance_upkeep = host_spell->GetSpellData()->dissonance_upkeep;
- spell->duration1 = host_spell->GetSpellData()->duration1;
- spell->duration2 = host_spell->GetSpellData()->duration2;
- spell->duration_until_cancel = host_spell->GetSpellData()->duration_until_cancel;
- spell->effect_message = string(host_spell->GetSpellData()->effect_message);
- spell->fade_message = string(host_spell->GetSpellData()->fade_message);
- spell->fade_message_others = string(host_spell->GetSpellData()->fade_message_others);
- spell->friendly_spell = host_spell->GetSpellData()->friendly_spell;
- spell->group_spell = host_spell->GetSpellData()->group_spell;
- spell->hit_bonus = host_spell->GetSpellData()->hit_bonus;
- spell->hp_req = host_spell->GetSpellData()->hp_req;
- spell->hp_req_percent = host_spell->GetSpellData()->hp_req_percent;
- spell->hp_upkeep = host_spell->GetSpellData()->hp_upkeep;
- spell->icon = host_spell->GetSpellData()->icon;
- spell->icon_backdrop = host_spell->GetSpellData()->icon_backdrop;
- spell->icon_heroic_op = host_spell->GetSpellData()->icon_heroic_op;
- spell->incurable = host_spell->GetSpellData()->incurable;
- spell->interruptable = host_spell->GetSpellData()->interruptable;
- spell->is_aa = host_spell->GetSpellData()->is_aa;
- spell->is_active = host_spell->GetSpellData()->is_active;
- spell->linked_timer = host_spell->GetSpellData()->linked_timer;
- spell->lua_script = string(host_spell->GetSpellData()->lua_script);
- spell->mastery_skill = host_spell->GetSpellData()->mastery_skill;
- spell->max_aoe_targets = host_spell->GetSpellData()->max_aoe_targets;
- spell->min_range = host_spell->GetSpellData()->min_range;
- spell->name = EQ2_8BitString(host_spell->GetSpellData()->name);
- spell->not_maintained = host_spell->GetSpellData()->not_maintained;
- spell->num_levels = host_spell->GetSpellData()->num_levels;
- spell->persist_through_death = host_spell->GetSpellData()->persist_through_death;
- spell->power_by_level = host_spell->GetSpellData()->power_by_level;
- spell->power_req = host_spell->GetSpellData()->power_req;
- spell->power_req_percent = host_spell->GetSpellData()->power_req_percent;
- spell->power_upkeep = host_spell->GetSpellData()->power_upkeep;
- spell->radius = host_spell->GetSpellData()->radius;
- spell->range = host_spell->GetSpellData()->range;
- spell->recast = host_spell->GetSpellData()->recast;
- spell->recovery = host_spell->GetSpellData()->recovery;
- spell->req_concentration = host_spell->GetSpellData()->req_concentration;
- spell->resistibility = host_spell->GetSpellData()->resistibility;
- spell->savagery_req = host_spell->GetSpellData()->savagery_req;
- spell->savagery_req_percent = host_spell->GetSpellData()->savagery_req_percent;
- spell->savagery_upkeep = host_spell->GetSpellData()->savagery_upkeep;
- spell->savage_bar = host_spell->GetSpellData()->savage_bar;
- spell->savage_bar_slot = host_spell->GetSpellData()->savage_bar_slot;
- spell->soe_spell_crc = host_spell->GetSpellData()->soe_spell_crc;
- spell->spell_book_type = host_spell->GetSpellData()->spell_book_type;
- spell->spell_name_crc = host_spell->GetSpellData()->spell_name_crc;
- spell->spell_type = host_spell->GetSpellData()->spell_type;
- spell->spell_visual = host_spell->GetSpellData()->spell_visual;
- spell->success_message = string(host_spell->GetSpellData()->success_message);
- spell->target_type = host_spell->GetSpellData()->target_type;
- spell->tier = host_spell->GetSpellData()->tier;
- spell->ts_loc_index = host_spell->GetSpellData()->ts_loc_index;
- spell->type = host_spell->GetSpellData()->type;
- spell->type_group_spell_id = host_spell->GetSpellData()->type_group_spell_id;
- spell->can_fizzle = host_spell->GetSpellData()->can_fizzle;
- }
- heal_spell = host_spell->IsHealSpell();
- buff_spell = host_spell->IsBuffSpell();
- damage_spell = host_spell->IsDamageSpell();;
- control_spell = host_spell->IsControlSpell();
- offense_spell = host_spell->IsOffenseSpell();
- host_spell->LockSpellInfo();
- std::vector<LevelArray*>::iterator itr;
- for (itr = host_spell->levels.begin(); itr != host_spell->levels.end(); itr++)
- {
- LevelArray* lvlArray = *itr;
- AddSpellLevel(lvlArray->adventure_class, lvlArray->tradeskill_class, lvlArray->spell_level);
- }
- std::vector<SpellDisplayEffect*>::iterator sdeitr;
- for (sdeitr = host_spell->effects.begin(); sdeitr != host_spell->effects.end(); sdeitr++)
- {
- SpellDisplayEffect* sde = *sdeitr;
- AddSpellEffect(sde->percentage, sde->subbullet, sde->description);
- }
- vector<LUAData*>::iterator luaitr;
- for (luaitr = host_spell->lua_data.begin(); luaitr != host_spell->lua_data.end(); luaitr++) {
- LUAData* data = *luaitr;
- AddSpellLuaData(data->type, data->int_value, data->int_value2, data->float_value, data->float_value2, data->bool_value, string(data->string_value), string(data->string_value2), string(data->string_helper));
- }
- host_spell->UnlockSpellInfo();
- MSpellInfo.SetName("Spell::MSpellInfo");
- }
- Spell::Spell(SpellData* in_spell){
- spell = in_spell;
- heal_spell = false;
- buff_spell = false;
- damage_spell = false;
- control_spell = false;
- offense_spell = false;
- copied_spell = false;
- MSpellInfo.SetName("Spell::MSpellInfo");
- }
- Spell::~Spell(){
- vector<LevelArray*>::iterator itr1;
- for(itr1=levels.begin();itr1!=levels.end();itr1++) {
- safe_delete(*itr1);
- }
- vector<SpellDisplayEffect*>::iterator itr2;
- for(itr2=effects.begin();itr2!=effects.end();itr2++) {
- safe_delete(*itr2);
- }
- vector<LUAData*>::iterator itr3;
- for(itr3=lua_data.begin();itr3!=lua_data.end();itr3++) {
- safe_delete(*itr3);
- }
- safe_delete(spell);
- }
- 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){
- LUAData* data = new LUAData;
- data->type = type;
- data->int_value = int_value;
- data->int_value2 = int_value2;
- data->float_value = float_value;
- data->float_value2 = float_value2;
- data->bool_value = bool_value;
- data->string_value = string_value;
- data->string_value2 = string_value2;
- data->string_helper = helper;
- MSpellInfo.lock();
- lua_data.push_back(data);
- MSpellInfo.unlock();
- }
- void Spell::AddSpellLuaDataInt(int value, int value2, string helper) {
- LUAData *data = new LUAData;
- data->type = 0;
- data->int_value = value;
- data->int_value2 = value2;
- data->float_value = 0;
- data->float_value2 = 0;
- data->bool_value = false;
- data->string_helper = helper;
- MSpellInfo.lock();
- lua_data.push_back(data);
- MSpellInfo.unlock();
- }
- void Spell::AddSpellLuaDataFloat(float value, float value2, string helper) {
- LUAData *data = new LUAData;
- data->type = 1;
- data->int_value = 0;
- data->int_value2 = 0;
- data->float_value = value;
- data->float_value2 = value2;
- data->bool_value = false;
- data->string_helper = helper;
- MSpellInfo.lock();
- lua_data.push_back(data);
- MSpellInfo.unlock();
- }
- void Spell::AddSpellLuaDataBool(bool value, string helper) {
- LUAData *data = new LUAData;
- data->type = 2;
- data->int_value = 0;
- data->float_value = 0;
- data->bool_value = value;
- data->string_helper = helper;
- MSpellInfo.lock();
- lua_data.push_back(data);
- MSpellInfo.unlock();
- }
- void Spell::AddSpellLuaDataString(string value, string value2,string helper) {
- LUAData *data = new LUAData;
- data->type = 3;
- data->int_value = 0;
- data->int_value2 = 0;
- data->float_value = 0;
- data->float_value2 = 0;
- data->bool_value = false;
- data->string_value = value;
- data->string_value2 = value2;
- data->string_helper = helper;
- MSpellInfo.lock();
- lua_data.push_back(data);
- MSpellInfo.unlock();
- }
- int16 Spell::GetLevelRequired(Player* player){
- int16 ret = 0xFFFF;
- if(!player)
- return ret;
- LevelArray* level = 0;
- vector<LevelArray*>::iterator itr;
- for(itr = levels.begin(); itr != levels.end(); itr++){
- level = *itr;
- if(level && level->adventure_class == player->GetAdventureClass()){
- ret = level->spell_level/10;
- break;
- }
- }
- return ret;
- }
- void Spell::SetAAPacketInformation(PacketStruct* packet, AltAdvanceData* data, Client* client, bool display_tier) {
- int8 current_tier = client->GetPlayer()->GetSpellTier(spell->id);
- Spell* next_spell;
- SpellData* spell2;
- if (data->maxRank > current_tier) {
- next_spell = master_spell_list.GetSpell(spell->id, current_tier + 1);
- spell2 = next_spell->GetSpellData();
- }
- SpellDisplayEffect* effect2;
- //next_spell->effects[1]->description;
- int xxx = 0;
- int16 hp_req = 0;
- int16 power_req = 0;
- if (current_tier > 0) {
- packet->setSubstructDataByName("spell_info", "current_id", spell->id);
- packet->setSubstructDataByName("spell_info", "current_icon", spell->icon);
- packet->setSubstructDataByName("spell_info", "current_icon2", spell->icon_heroic_op); // fix struct element name eventually
- packet->setSubstructDataByName("spell_info", "current_icontype", spell->icon_backdrop); // fix struct element name eventually
- if (packet->GetVersion() >= 63119) {
- packet->setSubstructDataByName("spell_info", "current_version", 0x04);
- packet->setSubstructDataByName("spell_info", "current_sub_version", 0x24);
- }
- else if (packet->GetVersion() >= 58617) {
- packet->setSubstructDataByName("spell_info", "current_version", 0x03);
- packet->setSubstructDataByName("spell_info", "current_sub_version", 0x131A);
- }
- else {
- packet->setSubstructDataByName("spell_info", "current_version", 0x00);
- packet->setSubstructDataByName("spell_info", "current_sub_version", 0xD9);
- }
- packet->setSubstructDataByName("spell_info", "current_type", spell->type);
- packet->setSubstructDataByName("spell_info", "unknown_MJ1d", 1); //63119 test
- packet->setSubstructDataByName("spell_info", "current_class_skill", spell->class_skill);
- packet->setSubstructDataByName("spell_info", "current_mastery_skill", spell->mastery_skill);
- packet->setSubstructDataByName("spell_info", "duration_flag", spell->duration_until_cancel);
- if (client && spell->type != 2) {
- sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client->GetPlayer()));
- if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
- spell_text_color = ARROW_COLOR_WHITE;
- spell_text_color -= 6;
- if (spell_text_color < 0)
- spell_text_color *= -1;
- packet->setSubstructDataByName("spell_info", "current_spell_text_color", (xxx == 1 ? 0xFFFFFFFF : spell_text_color));
- }
- else {
- packet->setSubstructDataByName("spell_info", "current_spell_text_color", (xxx == 1 ? 0xFFFFFFFF : 3));
- }
- packet->setSubstructDataByName("spell_info", "current_spell_text_color", (xxx == 1 ? 0xFFFFFFFF : 3));
- packet->setSubstructDataByName("spell_info", "current_tier", (spell->tier));
- if (spell->type != 2) {
- packet->setArrayLengthByName("current_num_levels", 0);
- for (int32 i = 0; i < levels.size(); i++) {
- packet->setArrayDataByName("spell_info_aa_adventure_class", levels[i]->adventure_class, i);
- packet->setArrayDataByName("spell_info_aa_tradeskill_class", levels[i]->tradeskill_class, i);
- packet->setArrayDataByName("spell_info_aa_spell_level", levels[i]->spell_level, i);
- }
- }
- //packet->setSubstructDataByName("spell_info","unknown9", 20);
- if (client) {
- hp_req = GetHPRequired(client->GetPlayer());
- power_req = GetPowerRequired(client->GetPlayer());
- // might need version checks around these?
- if (client->GetVersion() >= 1193)
- {
- int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
- packet->setSubstructDataByName("spell_info", "current_savagery_req", savagery_req);
- packet->setSubstructDataByName("spell_info", "current_savagery_upkeep", spell->savagery_upkeep);
- }
- if (client->GetVersion() >= 57048)
- {
- int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
- packet->setSubstructDataByName("spell_info", "dissonance_req", dissonance_req);
- packet->setSubstructDataByName("spell_info", "dissonance_upkeep", spell->dissonance_upkeep);
- }
- }
- packet->setSubstructDataByName("spell_info", "current_health_req", hp_req);
- packet->setSubstructDataByName("spell_info", "current_health_upkeep", spell->hp_upkeep);
- packet->setSubstructDataByName("spell_info", "current_power_req", power_req);
- packet->setSubstructDataByName("spell_info", "current_power_upkeep", spell->power_upkeep);
- packet->setSubstructDataByName("spell_info", "current_req_concentration", spell->req_concentration);
- //unknown1 savagery???
- packet->setSubstructDataByName("spell_info", "current_cast_time", spell->cast_time);
- packet->setSubstructDataByName("spell_info", "current_recovery", spell->recovery);
- packet->setSubstructDataByName("spell_info", "current_recast", spell->recast);
- packet->setSubstructDataByName("spell_info", "current_radius", spell->radius);
- packet->setSubstructDataByName("spell_info", "current_max_aoe_targets", spell->max_aoe_targets);
- packet->setSubstructDataByName("spell_info", "current_friendly_spell", spell->friendly_spell);
- // rumber of reagents with array
- packet->setSubstructArrayLengthByName("spell_info", "current_num_effects", (xxx == 1 ? 0 : effects.size()));
- for (int32 i = 0; i < effects.size(); i++) {
- packet->setArrayDataByName("current_subbulletflag", effects[i]->subbullet, i);
- string effect_message;
- if (effects[i]->description.length() > 0) {
- effect_message = effects[i]->description;
- if (effect_message.find("%LM") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%LM");
- int data_index = stoi(effect_message.substr(string_index + 3, 2));
- float value;
- if (lua_data[data_index]->type == 1)
- value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
- string strValue = to_string(value);
- strValue.erase(strValue.find_last_not_of('0') + 1, std::string::npos);
- effect_message.replace(effect_message.find("%LM"), 5, strValue);
- }
- // Magic damage min
- if (effect_message.find("%DML") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%DML");
- int data_index = stoi(effect_message.substr(string_index + 4, 2));
- float value;
- if (lua_data[data_index]->type == 1)
- value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
- value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
- string damage = to_string((int)round(value));
- effect_message.replace(effect_message.find("%DML"), 6, damage);
- }
- // Magic damage max
- if (effect_message.find("%DMH") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%DMH");
- int data_index = stoi(effect_message.substr(string_index + 4, 2));
- float value;
- if (lua_data[data_index]->type == 1)
- value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
-
- value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
- string damage = to_string((int)round(value));
- effect_message.replace(effect_message.find("%DMH"), 6, damage);
- }
- // level based Magic damage min
- if (effect_message.find("%LDML") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%LDML");
- int data_index = stoi(effect_message.substr(string_index + 5, 2));
- float value;
- if (lua_data[data_index]->type == 1)
- value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
-
- value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
- string damage = to_string((int)round(value));
- effect_message.replace(effect_message.find("%LDML"), 7, damage);
- }
- // level based Magic damage max
- if (effect_message.find("%LDMH") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%LDMH");
- int data_index = stoi(effect_message.substr(string_index + 5, 2));
- float value;
- if (lua_data[data_index]->type == 1)
- value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
-
- value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
- string damage = to_string((int)round(value));
- effect_message.replace(effect_message.find("%LDMH"), 7, damage);
- }
- //GetZone()->SimpleMessage(CHANNEL_COLOR_SPELL_EFFECT, effect_message.c_str(), victim, 50);
- packet->setArrayDataByName("current_effect", effect_message.c_str(), i);
- }
- packet->setArrayDataByName("current_percentage", effects[i]->percentage, i);
- }
- if (display_tier == true)
- packet->setSubstructDataByName("spell_info", "current_display_spell_tier", 1);// spell2->display_spell_tier);
- else
- packet->setSubstructDataByName("spell_info", "current_display_spell_tier", 1);// 0);
- packet->setSubstructDataByName("spell_info", "current_unknown_1", 1);// 0);
- //unkown1_1
- packet->setSubstructDataByName("spell_info", "current_minimum_range", spell->min_range);
- packet->setSubstructDataByName("spell_info", "current_range", spell->range);
- packet->setSubstructDataByName("spell_info", "current_duration_1", spell->duration1);
- packet->setSubstructDataByName("spell_info", "current_duration_2", spell->duration2);
- packet->setSubstructDataByName("spell_info", "current_duration_flag", spell->duration_until_cancel);
- packet->setSubstructDataByName("spell_info", "current_target", spell->target_type);
- packet->setSubstructDataByName("spell_info", "current_can_effect_raid", spell->can_effect_raid);
- packet->setSubstructDataByName("spell_info", "current_affect_only_group_members", spell->affect_only_group_members);
- packet->setSubstructDataByName("spell_info", "current_group_spell", spell->group_spell);
- packet->setSubstructDataByName("spell_info", "current_resistibility", spell->resistibility);
- packet->setSubstructDataByName("spell_info", "current_name", &(spell->name));
- packet->setSubstructDataByName("spell_info", "current_description", &(spell->description));
- }
- if (current_tier + 1 <= data->maxRank) {
- packet->setSubstructDataByName("spell_info", "next_id", spell2->id);
- packet->setSubstructDataByName("spell_info", "next_icon", spell2->icon);
- packet->setSubstructDataByName("spell_info", "next_icon2", spell2->icon_heroic_op); // fix struct element name eventually
- packet->setSubstructDataByName("spell_info", "next_icontype", spell2->icon_backdrop); // fix struct element name eventually
- if (packet->GetVersion() >= 63119) {
- packet->setSubstructDataByName("spell_info", "next_aa_spell_info2", "version", 0x04);
- packet->setSubstructDataByName("spell_info", "next_aa_spell_info2", "sub_version", 0x24);
- }
- else if (packet->GetVersion() >= 58617) {
- packet->setSubstructDataByName("spell_info", "next_version", 0x03);
- packet->setSubstructDataByName("spell_info", "next_sub_version", 0x131A);
- }
- else {
- packet->setSubstructDataByName("spell_info", "next_version", 0x00);
- packet->setSubstructDataByName("spell_info", "next_sub_version", 0xD9);
- }
- packet->setSubstructDataByName("spell_info", "next_type", spell2->type);
- packet->setSubstructDataByName("spell_info", "next_unknown_MJ1d", 1); //63119 test
- packet->setSubstructDataByName("spell_info", "next_class_skill", spell2->class_skill);
- packet->setSubstructDataByName("spell_info", "next_mastery_skill", spell2->mastery_skill);
- packet->setSubstructDataByName("spell_info", "next_duration_flag", spell2->duration_until_cancel);
- if (client && spell->type != 2) {
- sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client->GetPlayer()));
- if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
- spell_text_color = ARROW_COLOR_WHITE;
- spell_text_color -= 6;
- if (spell_text_color < 0)
- spell_text_color *= -1;
- packet->setSubstructDataByName("spell_info", "next_spell_text_color", spell_text_color);
- }
- else
- packet->setSubstructDataByName("spell_info", "next_spell_text_color", 3);
- if (spell->type != 2) {
- packet->setArrayLengthByName("num_levels", levels.size());
- for (int32 i = 0; i < levels.size(); i++) {
- packet->setArrayDataByName("spell_info_aa_adventure_class2", levels[i]->adventure_class, i);
- packet->setArrayDataByName("spell_info_aa_tradeskill_class2", levels[i]->tradeskill_class, i);
- packet->setArrayDataByName("spell_info_aa_spell_level2", levels[i]->spell_level, i);
- }
- }
- //packet->setSubstructDataByName("spell_info","unknown9", 20);
- hp_req = 0;
- power_req = 0;
- if (client) {
- hp_req = GetHPRequired(client->GetPlayer());
- power_req = GetPowerRequired(client->GetPlayer());
- // might need version checks around these?
- if (client->GetVersion() >= 1193)
- {
- int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
- packet->setSubstructDataByName("spell_info", "next_savagery_req", savagery_req);
- packet->setSubstructDataByName("spell_info", "next_savagery_upkeep", spell->savagery_upkeep);
- }
- if (client->GetVersion() >= 57048)
- {
- int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
- packet->setSubstructDataByName("spell_info", "next_dissonance_req", dissonance_req);
- packet->setSubstructDataByName("spell_info", "next_dissonance_upkeep", spell->dissonance_upkeep);
- }
- }
- packet->setSubstructDataByName("spell_info", "next_target", spell->target_type);
- packet->setSubstructDataByName("spell_info", "next_recovery", spell->recovery);
- packet->setSubstructDataByName("spell_info", "next_health_upkeep", spell->hp_upkeep);
- packet->setSubstructDataByName("spell_info", "next_health_req", hp_req);
- packet->setSubstructDataByName("spell_info", "next_tier", spell->tier);
- packet->setSubstructDataByName("spell_info", "next_power_req", power_req);
- packet->setSubstructDataByName("spell_info", "next_power_upkeep", spell->power_upkeep);
- packet->setSubstructDataByName("spell_info", "next_cast_time", spell->cast_time);
- packet->setSubstructDataByName("spell_info", "next_recast", spell->recast);
- packet->setSubstructDataByName("spell_info", "next_radius", spell->radius);
- packet->setSubstructDataByName("spell_info", "next_req_concentration", spell->req_concentration);
- //packet->setSubstructDataByName("spell_info","req_concentration2", 2);
- packet->setSubstructDataByName("spell_info", "next_max_aoe_targets", spell->max_aoe_targets);
- packet->setSubstructDataByName("spell_info", "next_friendly_spell", spell->friendly_spell);
- packet->setSubstructArrayLengthByName("spell_info", "next_num_effects", next_spell->effects.size());
- for (int32 i = 0; i < next_spell->effects.size(); i++) {
- packet->setArrayDataByName("next_subbulletflag", next_spell->effects[i]->subbullet, i);
- string effect_message;
- if (next_spell->effects[i]->description.length() > 0) {
- effect_message = next_spell->effects[i]->description;
- if (effect_message.find("%LM") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%LM");
- int data_index = stoi(effect_message.substr(string_index + 3, 2));
- float value;
- if (next_spell->lua_data[data_index]->type == 1)
- value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
- string strValue = to_string(value);
- strValue.erase(strValue.find_last_not_of('0') + 1, std::string::npos);
- effect_message.replace(effect_message.find("%LM"), 5, strValue);
- }
- // Magic damage min
- if (effect_message.find("%DML") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%DML");
- int data_index = stoi(effect_message.substr(string_index + 4, 2));
- float value;
- if (next_spell->lua_data[data_index]->type == 1)
- value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
-
- value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
- string damage = to_string((int)round(value));
- damage.erase(damage.find_last_not_of('0') + 1, std::string::npos);
- effect_message.replace(effect_message.find("%DML"), 6, damage);
- }
- // Magic damage max
- if (effect_message.find("%DMH") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%DMH");
- int data_index = stoi(effect_message.substr(string_index + 4, 2));
- float value;
- if (next_spell->lua_data[data_index]->type == 1)
- value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
-
- value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
- string damage = to_string((int)round(value));
- damage.erase(damage.find_last_not_of('0') + 1, std::string::npos);
- effect_message.replace(effect_message.find("%DMH"), 6, damage);
- }
- // level based Magic damage min
- if (effect_message.find("%LDML") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%LDML");
- int data_index = stoi(effect_message.substr(string_index + 5, 2));
- float value;
- if (next_spell->lua_data[data_index]->type == 1)
- value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
-
- value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
- string damage = to_string((int)round(value));
- effect_message.replace(effect_message.find("%LDML"), 7, damage);
- }
- // level based Magic damage max
- if (effect_message.find("%LDMH") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%LDMH");
- int data_index = stoi(effect_message.substr(string_index + 5, 2));
- float value;
- if (next_spell->lua_data[data_index]->type == 1)
- value = next_spell->lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = next_spell->lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
-
- value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
- string damage = to_string((int)round(value));
- effect_message.replace(effect_message.find("%LDMH"), 7, damage);
- }
- //GetZone()->SimpleMessage(CHANNEL_COLOR_SPELL_EFFECT, effect_message.c_str(), victim, 50);
- packet->setArrayDataByName("next_effect", effect_message.c_str(), i);
- }
- packet->setArrayDataByName("next_percentage", next_spell->effects[i]->percentage, i);
- }
- if (display_tier == true)
- packet->setSubstructDataByName("spell_info", "next_display_spell_tier", 1);// spell->display_spell_tier);
- else
- packet->setSubstructDataByName("spell_info", "next_display_spell_tier", 1);//0
- packet->setSubstructDataByName("spell_info", "next_unknown_1", 1);//0
- packet->setSubstructDataByName("spell_info", "next_range", spell2->range);
- packet->setSubstructDataByName("spell_info", "next_duration_1", spell2->duration1);
- packet->setSubstructDataByName("spell_info", "next_duration_2", spell2->duration2);
- packet->setSubstructDataByName("spell_info", "next_can_effect_raid", spell2->can_effect_raid);
- packet->setSubstructDataByName("spell_info", "next_affect_only_group_members", spell2->affect_only_group_members);
- packet->setSubstructDataByName("spell_info", "next_group_spell", spell2->group_spell);
- packet->setSubstructDataByName("spell_info", "next_resistibility", spell2->resistibility);
- packet->setSubstructDataByName("spell_info", "next_name", &(spell2->name));
- packet->setSubstructDataByName("spell_info", "next_description", &(spell2->description));
- }
- }
- void Spell::SetPacketInformation(PacketStruct* packet, Client* client, bool display_tier) {
- packet->setSubstructDataByName("spell_info", "id", spell->id);
- packet->setSubstructDataByName("spell_info", "icon", spell->icon);
- packet->setSubstructDataByName("spell_info", "icon2", spell->icon_heroic_op); // fix struct element name eventually
- packet->setSubstructDataByName("spell_info", "icontype", spell->icon_backdrop); // fix struct element name eventually
- if (packet->GetVersion() >= 63119) {
- packet->setSubstructDataByName("spell_info", "version", 0x04);
- packet->setSubstructDataByName("spell_info", "sub_version", 0x24);
- }
- else if (packet->GetVersion() >= 60114) {
- packet->setSubstructDataByName("spell_info", "version", 0x03);
- packet->setSubstructDataByName("spell_info", "sub_version", 4890);
- }
- else if (packet->GetVersion() <= 546) {
- packet->setSubstructDataByName("spell_info", "version", 0x10);
- packet->setSubstructDataByName("spell_info", "sub_version", 0x0f);
- }
- else {
- packet->setSubstructDataByName("spell_info", "version", 0x11);
- packet->setSubstructDataByName("spell_info", "sub_version", 0x14);
- }
- packet->setSubstructDataByName("spell_info", "type", spell->type);
- packet->setSubstructDataByName("spell_info", "unknown_MJ1d", 1); //63119 test
- packet->setSubstructDataByName("spell_info", "class_skill", spell->class_skill);
- packet->setSubstructDataByName("spell_info", "min_class_skill_req", spell->min_class_skill_req);
- packet->setSubstructDataByName("spell_info", "mastery_skill", spell->mastery_skill);
- packet->setSubstructDataByName("spell_info", "duration_flag", spell->duration_until_cancel);
- if (client && spell->type != 2) {
- sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client->GetPlayer()));
- if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
- spell_text_color = ARROW_COLOR_WHITE;
- spell_text_color -= 6;
- if (spell_text_color < 0)
- spell_text_color *= -1;
- packet->setSubstructDataByName("spell_info", "spell_text_color", spell_text_color);
- }
- else
- packet->setSubstructDataByName("spell_info", "spell_text_color", 3);
- if (spell->type != 2) {
- packet->setSubstructArrayLengthByName("spell_info", "num_levels", levels.size());
- for (int32 i = 0; i < levels.size(); i++) {
- packet->setArrayDataByName("adventure_class", levels[i]->adventure_class, i);
- packet->setArrayDataByName("tradeskill_class", levels[i]->tradeskill_class, i);
- packet->setArrayDataByName("spell_level", levels[i]->spell_level, i);
- }
- }
- packet->setSubstructDataByName("spell_info", "unknown9", 20);
- int16 hp_req = 0;
- int16 power_req = 0;
- if (client) {
- hp_req = GetHPRequired(client->GetPlayer());
- power_req = GetPowerRequired(client->GetPlayer());
- // might need version checks around these?
- if (client->GetVersion() >= 1193)
- {
- int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
- packet->setSubstructDataByName("spell_info", "savagery_req", savagery_req);
- packet->setSubstructDataByName("spell_info", "savagery_upkeep", spell->savagery_upkeep);
- }
- if (client->GetVersion() >= 57048)
- {
- int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
- packet->setSubstructDataByName("spell_info", "dissonance_req", dissonance_req);
- packet->setSubstructDataByName("spell_info", "dissonance_upkeep", spell->dissonance_upkeep);
- }
- }
- packet->setSubstructDataByName("spell_info", "target", spell->target_type);
- packet->setSubstructDataByName("spell_info", "recovery", spell->recovery);
- packet->setSubstructDataByName("spell_info", "health_upkeep", spell->hp_upkeep);
- packet->setSubstructDataByName("spell_info", "health_req", hp_req);
- packet->setSubstructDataByName("spell_info", "tier", spell->tier);
- packet->setSubstructDataByName("spell_info", "power_req", power_req);
- packet->setSubstructDataByName("spell_info", "power_upkeep", spell->power_upkeep);
- if (packet->GetVersion() <= 546) {//cast times are displayed differently on new clients
- packet->setSubstructDataByName("spell_info", "cast_time", spell->cast_time/10);
- }
- else {
- packet->setSubstructDataByName("spell_info", "cast_time", spell->cast_time);
- }
- packet->setSubstructDataByName("spell_info", "recast", spell->recast);
- packet->setSubstructDataByName("spell_info", "radius", spell->radius);
- packet->setSubstructDataByName("spell_info", "req_concentration", spell->req_concentration);
- //packet->setSubstructDataByName("spell_info","req_concentration2", 2);
- packet->setSubstructDataByName("spell_info", "max_aoe_targets", spell->max_aoe_targets);
- packet->setSubstructDataByName("spell_info", "friendly_spell", spell->friendly_spell);
- packet->setSubstructArrayLengthByName("spell_info", "num_effects", effects.size());
- for (int32 i = 0; i < effects.size(); i++) {
- packet->setArrayDataByName("subbulletflag", effects[i]->subbullet, i);
- string effect_message;
- if (effects[i]->description.length() > 0) {
- effect_message = effects[i]->description;
- if (effect_message.find("%LM") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%LM");
- int data_index = stoi(effect_message.substr(string_index + 3, 2));
- float value;
- if (lua_data[data_index]->type == 1)
- value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
- string strValue = to_string(value);
- strValue.erase(strValue.find_last_not_of('0') + 1, std::string::npos);
- effect_message.replace(effect_message.find("%LM"), 5, strValue);
- }
- // Magic damage min
- if (effect_message.find("%DML") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%DML");
- int data_index = stoi(effect_message.substr(string_index + 4, 2));
- float value;
- if (lua_data[data_index]->type == 1)
- value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
-
- value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
- string damage = to_string((int)round(value));
- effect_message.replace(effect_message.find("%DML"), 6, damage);
- }
- // Magic damage max
- if (effect_message.find("%DMH") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%DMH");
- int data_index = stoi(effect_message.substr(string_index + 4, 2));
- float value;
- if (lua_data[data_index]->type == 1)
- value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
-
- value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
- string damage = to_string((int)round(value));
- effect_message.replace(effect_message.find("%DMH"), 6, damage);
- }
- // level based Magic damage min
- if (effect_message.find("%LDML") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%LDML");
- int data_index = stoi(effect_message.substr(string_index + 5, 2));
- float value;
- if (lua_data[data_index]->type == 1)
- value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
- value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
- string damage = to_string((int)round(value));
- effect_message.replace(effect_message.find("%LDML"), 7, damage);
- }
- // level based Magic damage max
- if (effect_message.find("%LDMH") < 0xFFFFFFFF) {
- int string_index = effect_message.find("%LDMH");
- int data_index = stoi(effect_message.substr(string_index + 5, 2));
- float value;
- if (lua_data[data_index]->type == 1)
- value = lua_data[data_index]->float_value * client->GetPlayer()->GetLevel();
- else
- value = lua_data[data_index]->int_value * client->GetPlayer()->GetLevel();
-
- value = client->GetPlayer()->CalculateDamageAmount(nullptr, value, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
- string damage = to_string((int)round(value));
- effect_message.replace(effect_message.find("%LDMH"), 7, damage);
- }
- boost::regex re("([0-9]{1,10})\\s+\\-\\s+([0-9]{1,10})");
- boost::match_results<std::string::const_iterator> base_match;
- if (boost::regex_search(effect_message, base_match, re, boost::match_partial)) {
- boost::ssub_match match = base_match[0];
- std::size_t midPos = match.str().find(" - ");
- if(midPos != std::string::npos)
- {
- int32 minValue = atoul(match.str().substr(0, midPos).c_str());
- int32 maxValue = atoul(match.str().substr(midPos+3).c_str());
- int32 newMin = minValue;
-
- bool crit = false;
- Skill* skill = master_skill_list.GetSkill(spell->mastery_skill);
- std::string skillName = "";
-
- if(skill)
- skillName = skill->name.data;
- if(skillName == "Aggression")
- newMin = (int32)client->GetPlayer()->CalculateHateAmount(nullptr, (sint32)minValue);
- else if(spell->friendly_spell && skillName == "Ministration")
- newMin = (int32)client->GetPlayer()->CalculateHealAmount(nullptr, (sint32)minValue, 0, &crit, true);
- else
- newMin = (int32)client->GetPlayer()->CalculateDamageAmount(nullptr, (sint32)minValue, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
-
- int32 newMax = maxValue;
- if(skillName == "Aggression")
- newMax = (int32)client->GetPlayer()->CalculateHateAmount(nullptr, (sint32)maxValue);
- else if(spell->friendly_spell && skillName == "Ministration")
- newMax = (int32)client->GetPlayer()->CalculateHealAmount(nullptr, (sint32)maxValue, 0, &crit, true);
- else
- newMax = (int32)client->GetPlayer()->CalculateDamageAmount(nullptr, (sint32)maxValue, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, spell->type, spell->target_type);
-
- std::string newStr = std::to_string(newMin) + " - " + std::to_string(newMax);
- effect_message.replace(effect_message.find(match.str()), match.str().size(), newStr);
- }
- }
- //GetZone()->SimpleMessage(CHANNEL_COLOR_SPELL_EFFECT, effect_message.c_str(), victim, 50);
- }
- packet->setArrayDataByName("effect", effect_message.c_str(), i);
- packet->setArrayDataByName("percentage", effects[i]->percentage, i);
- }
- if (display_tier == true)
- packet->setSubstructDataByName("spell_info", "display_spell_tier", spell->display_spell_tier);
- else
- packet->setSubstructDataByName("spell_info", "display_spell_tier", 0);
- packet->setSubstructDataByName("spell_info", "range", spell->range);
- packet->setSubstructDataByName("spell_info", "duration1", spell->duration1);
- packet->setSubstructDataByName("spell_info", "duration2", spell->duration2);
- packet->setSubstructDataByName("spell_info", "can_effect_raid", spell->can_effect_raid);
- packet->setSubstructDataByName("spell_info", "affect_only_group_members", spell->affect_only_group_members);
- packet->setSubstructDataByName("spell_info", "group_spell", spell->group_spell);
- packet->setSubstructDataByName("spell_info", "resistibility", spell->resistibility);
- packet->setSubstructDataByName("spell_info", "name", &(spell->name));
- packet->setSubstructDataByName("spell_info", "description", &(spell->description));
- //packet->PrintPacket();
- }
- EQ2Packet* Spell::SerializeSpecialSpell(Client* client, bool display, int8 packet_type, int8 sub_packet_type) {
- if (client->GetVersion() <= 283)
- return SerializeSpell(client, display, false, packet_type, 0, "WS_ExaminePartialSpellInfo");
- return SerializeSpell(client, display, false, packet_type, sub_packet_type, "WS_ExamineSpecialSpellInfo");
- }
- 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) {
- if (!client)
- return 0;
- int16 version = 1;
- if (client)
- version = client->GetVersion();
- if (!struct_name)
- struct_name = "WS_ExamineAASpellInfo";
- PacketStruct* packet = configReader.getStruct(struct_name, version);
- if (display)
- packet->setSubstructDataByName("info_header", "show_name", 1);//1
- else
- if (!trait_display)
- packet->setSubstructDataByName("info_header", "show_popup", 1);//1
- else
- packet->setSubstructDataByName("info_header", "show_popup", 0);
- if (packet_type > 0)
- packet->setSubstructDataByName("info_header", "packettype", packet_type * 256 + 0xFE);
- else
- packet->setSubstructDataByName("info_header", "packettype", 0x4FFE);// 0x45FE GetItemPacketType(version));
- //packet->setDataByName("unknown2",5);
- //packet->setDataByName("unknown7", 1);
- //packet->setDataByName("unknown9", 20);
- //packet->setDataByName("unknown10", 1, 2);
- if (sub_packet_type == 0)
- sub_packet_type = 0x83;
- packet->setSubstructDataByName("info_header", "packetsubtype", 4);// sub_packet_type);
- packet->setSubstructDataByName("spell_info", "aa_id", data->spellID);
- packet->setSubstructDataByName("spell_info", "aa_tab_id", data->group);
- packet->setSubstructDataByName("spell_info", "aa_icon", data->icon);
- packet->setSubstructDataByName("spell_info", "aa_icon2", data->icon2);
- packet->setSubstructDataByName("spell_info", "aa_current_rank", tier); // how to get this info to here?
- packet->setSubstructDataByName("spell_info", "aa_max_rank", data->maxRank);
- packet->setSubstructDataByName("spell_info", "aa_rank_cost", data->rankCost);
- packet->setSubstructDataByName("spell_info", "aa_unknown_2", 20);
- packet->setSubstructDataByName("spell_info", "aa_name", &(spell->name));
- packet->setSubstructDataByName("spell_info", "aa_description", &(spell->description));
- //packet->setDataByName("unknown3",2);
- //packet->setDataByName("unknown7", 50);
- if (sub_packet_type == 0x81)
- SetAAPacketInformation(packet, data, client);
- else
- SetAAPacketInformation(packet, data, client, true);
- packet->setSubstructDataByName("spell_info", "uses_remaining", 0xFFFF);
- packet->setSubstructDataByName("spell_info", "damage_remaining", 0xFFFF);
- //packet->PrintPacket();
- // This adds the second portion to the spell packet. Could be used for bonuses etc.?
- string* data1 = packet->serializeString();
- uchar* data2 = (uchar*)data1->c_str();
- uchar* ptr2 = data2;
- int32 size = data1->length();// *2;
- ////uchar* data3 = new uchar[size];
- ////memcpy(data3, data2, data1->length());
- ////uchar* ptr = data3;
- ////size -= 17;
- ////memcpy(ptr, &size, sizeof(int32));
- ////size += 3;
- ////ptr += data1->length();
- ////ptr2 += 14;
- ////memcpy(ptr, ptr2, data1->length() - 14);
- EQ2Packet* outapp = new EQ2Packet(OP_ClientCmdMsg, data2, size);
- //DumpPacket(outapp);
- //safe_delete_array(data3);
- safe_delete(packet);
- return outapp;
- /*PacketStruct* packet = configReader.getStruct("WS_ExamineAASpellInfo", client->GetVersion());
- packet->setSubstructDataByName("info_header", "show_name", 0);
- packet->setSubstructDataByName("info_header", "show_popup", 0);
- packet->setSubstructDataByName("info_header", "packettype", packet_type);
- packet->setSubstructDataByName("info_header", "packetsubtype", sub_packet_type);
- packet->setSubstructDataByName("Spell_info", "aa_id", data->spellID);
- packet->setSubstructDataByName("Spell_info", "aa_tab_id", data->group);
- packet->setSubstructDataByName("Spell_info", "aa_icon", data->icon);
- packet->setSubstructDataByName("Spell_info", "aa_icon2", data->icon2);
- packet->setSubstructDataByName("Spell_info", "current_rank", 0); // how to get this info to here?
- packet->setSubstructDataByName("Spell_info", "max_rank", data->maxRank);
- packet->setSubstructDataByName("Spell_info", "rank_cost", data->rankCost);
- packet->setSubstructDataByName("spell_info", "unknown2", 20);
- // Spell info
- packet->setSubstructDataByName("spell_info", "id", spell->id);
- packet->setSubstructDataByName("spell_info", "icon", spell->icon);
- packet->setSubstructDataByName("spell_info", "icon2", spell->icon_heroic_op); // fix struct element name eventually
- packet->setSubstructDataByName("spell_info", "icontype", spell->icon_backdrop); // fix struct element name eventually
- if (packet->GetVersion() >= 63119) {
- packet->setSubstructDataByName("spell_info", "version", 0x04);
- packet->setSubstructDataByName("spell_info", "sub_version", 0x24);
- }
- else if (packet->GetVersion() >= 1193) {
- packet->setSubstructDataByName("spell_info", "version", 0x00);
- packet->setSubstructDataByName("spell_info", "sub_version", 0xD9);
- }
- else {
- packet->setSubstructDataByName("spell_info", "version", 0x11);
- packet->setSubstructDataByName("spell_info", "sub_version", 0x14);
- }
- packet->setSubstructDataByName("spell_info", "type", spell->type);
- packet->setSubstructDataByName("spell_info", "unknown_MJ1d", 1); //63119 test
- packet->setSubstructDataByName("spell_info", "class_skill", spell->class_skill);
- packet->setSubstructDataByName("spell_info", "mastery_skill", spell->mastery_skill);
- packet->setSubstructDataByName("spell_info", "duration_flag", spell->duration_until_cancel);
- if (client && spell->type != 2) {
- sint8 spell_text_color = client->GetPlayer()->GetArrowColor(GetLevelRequired(client));
- if (spell_text_color != ARROW_COLOR_WHITE && spell_text_color != ARROW_COLOR_RED && spell_text_color != ARROW_COLOR_GRAY)
- spell_text_color = ARROW_COLOR_WHITE;
- spell_text_color -= 6;
- if (spell_text_color < 0)
- spell_text_color *= -1;
- packet->setSubstructDataByName("spell_info", "spell_text_color", spell_text_color);
- }
- else
- packet->setSubstructDataByName("spell_info", "spell_text_color", 3);
- if (spell->type != 2) {
- packet->setSubstructArrayLengthByName("spell_info", "num_levels", levels.size());
- for (int32 i = 0; i < levels.size(); i++) {
- packet->setArrayDataByName("adventure_class", levels[i]->adventure_class, i);
- packet->setArrayDataByName("tradeskill_class", levels[i]->tradeskill_class, i);
- packet->setArrayDataByName("spell_level", levels[i]->spell_level, i);
- }
- }
- //packet->setSubstructDataByName("spell_info", "unknown9", 20);
- int16 hp_req = 0;
- int16 power_req = 0;
- if (client) {
- hp_req = GetHPRequired(client->GetPlayer());
- power_req = GetPowerRequired(client->GetPlayer());
- // might need version checks around these?
- if (client->GetVersion() >= 1193)
- {
- int16 savagery_req = GetSavageryRequired(client->GetPlayer()); // dunno why we need to do this
- packet->setSubstructDataByName("spell_info", "savagery_req", savagery_req);
- packet->setSubstructDataByName("spell_info", "savagery_upkeep", spell->savagery_upkeep);
- }
- if (client->GetVersion() >= 57048)
- {
- int16 dissonance_req = GetDissonanceRequired(client->GetPlayer()); // dunno why we need to do this
- packet->setSubstructDataByName("spell_info", "dissonance_req", dissonance_req);
- packet->setSubstructDataByName("spell_info", "dissonance_upkeep", spell->dissonance_upkeep);
- }
- }
- packet->setSubstructDataByName("spell_info", "tier", spell->tier);
- packet->setSubstructDataByName("spell_info", "health_req", hp_req);
- packet->setSubstructDataByName("spell_info", "health_upkeep", spell->hp_upkeep);
- packet->setSubstructDataByName("spell_info", "power_req", power_req);
- packet->setSubstructDataByName("spell_info", "power_upkeep", spell->power_upkeep);
- packet->setSubstructDataByName("spell_info", "req_concentration", spell->req_concentration);
- //packet->setDataByName("req_concentration2", 2);
- packet->setSubstructDataByName("spell_info", "cast_time", spell->cast_time);
- packet->setSubstructDataByName("spell_info", "recovery", spell->recovery);
- packet->setSubstructDataByName("spell_info", "recast", spell->recast);
- packet->setSubstructDataByName("spell_info", "radius", spell->radius);
- packet->setSubstructDataByName("spell_info", "max_aoe_targets", spell->max_aoe_targets);
- packet->setSubstructDataByName("spell_info", "friendly_spell", spell->friendly_spell);
- //reageants??
- packet->setSubstructArrayLengthByName("spell_info", "num_effects", effects.size());
- for (int32 i = 0; i < effects.size(); i++) {
- packet->setArrayDataByName("subbulletflag", effects[i]->subbullet, i);
- packet->setArrayDataByName("effect", effects[i]->description.c_str(), i);
- packet->setArrayDataByName("percentage", effects[i]->percentage, i);
- }
- //if (display_tier == true)
- packet->setSubstructDataByName("spell_info", "display_spell_tier", spell->display_spell_tier);
- //else
- // packet->setSubstructDataByName("spell_info", "display_spell_tier", 0);
- // minimum range??
- packet->setSubstructDataByName("spell_info", "range", spell->range);
- packet->setSubstructDataByName("spell_info", "duration1", spell->duration1);
- packet->setSubstructDataByName("spell_info", "duration2", spell->duration2);
- //unknown9 ??
- //duration flag??
- packet->setSubstructDataByName("spell_info", "target", spell->target_type);
- packet->setSubstructDataByName("spell_info", "can_effect_raid", spell->can_effect_raid);
- packet->setSubstructDataByName("spell_info", "affect_only_group_members", spell->affect_only_group_members);
- packet->setSubstructDataByName("spell_info", "group_spell", spell->group_spell);
- packet->setSubstructDataByName("spell_info", "resistibility", spell->resistibility);
- //unknown11 ??
- //hit_bonus ??
- //unknown12 ??
- packet->setSubstructDataByName("spell_info", "name", &(spell->name));
- packet->setSubstructDataByName("spell_info", "description", &(spell->description));
- EQ2Packet* packetdata = packet->serialize();
- //EQ2Packet* app = new EQ2Packet(OP_AdventureList, packetdata->pBuffer, packetdata->size);
- EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, packetdata->pBuffer, packetdata->size);
- packet->PrintPacket();
- //DumpPacket(app);
- safe_delete(packet);
- safe_delete(data);
- return app;
- */
- }
- EQ2Packet* Spell::SerializeSpell(Client* client, bool display, bool trait_display, int8 packet_type, int8 sub_packet_type, const char* struct_name) {
- int16 version = 1;
- if (client)
- version = client->GetVersion();
- if (!struct_name)
- struct_name = "WS_ExamineSpellInfo";
- if (version <= 546) {
- if (packet_type == 1)
- struct_name = "WS_ExamineEffectInfo";
- else if (!display && version<=283)
- struct_name = "WS_ExaminePartialSpellInfo";
- else
- struct_name = "WS_ExamineSpellInfo";
- }
- PacketStruct* packet = configReader.getStruct(struct_name, version);
- if (display)
- packet->setSubstructDataByName("info_header", "show_name", 1);
- else {
- if (!trait_display)
- packet->setSubstructDataByName("info_header", "show_popup", 1);
- else
- packet->setSubstructDataByName("info_header", "show_popup", 0);
- }
- if (version > 546) {
- if (packet_type > 0)
- packet->setSubstructDataByName("info_header", "packettype", packet_type * 256 + 0xFE);
- else
- packet->setSubstructDataByName("info_header", "packettype", GetItemPacketType(version));
- }
- else {
- if (packet_type == 3 || packet_type == 0)
- packet->setSubstructDataByName("info_header", "packettype", 3); // 0: item, 1: effect, 2: recipe, 3: spell/ability
- else
- packet->setSubstructDataByName("info_header", "packettype", 1);
- }
- //packet->setDataByName("unknown2",5);
- //packet->setDataByName("unknown7", 1);
- //packet->setDataByName("unknown9", 20);
- //packet->setDataByName("unknown10", 1, 2);
- if (sub_packet_type == 0)
- sub_packet_type = 0x83;
- packet->setSubstructDataByName("info_header", "packetsubtype", sub_packet_type);
- //packet->setDataByName("unknown3",2);
- //packet->setDataByName("unknown7", 50);
- if (sub_packet_type == 0x81)
- SetPacketInformation(packet, client);
- else
- SetPacketInformation(packet, client, true);
- packet->setSubstructDataByName("spell_info", "uses_remaining", 0xFFFF);
- packet->setSubstructDataByName("spell_info", "damage_remaining", 0xFFFF);
- //packet->PrintPacket();
- // This adds the second portion to the spell packet. Could be used for bonuses etc.?
- int8 offset = 0;
- if (packet->GetVersion() == 60114) {
- offset = 28;
- }
- else {
- offset = 14;
- }
- EQ2Packet* outapp = 0;
- if (version > 546) {
- string* data1 = packet->serializeString();
- uchar* data2 = (uchar*)data1->c_str();
- uchar* ptr2 = data2;
- int32 size = data1->length() * 2;
- uchar* data3 = new uchar[size];
- memcpy(data3, data2, data1->length());
- uchar* ptr = data3;
- size -= offset + 3;
- memcpy(ptr, &size, sizeof(int32));
- size += 3;
- ptr += data1->length();
- ptr2 += offset;
- memcpy(ptr, ptr2, data1->length() - offset);
- outapp = new EQ2Packet(OP_ClientCmdMsg, data3, size);
- safe_delete_array(data3);
- safe_delete(packet);
- }
- else
- outapp = packet->serialize();
- //DumpPacket(outapp);
- return outapp;
- }
- void Spell::AddSpellEffect(int8 percentage, int8 subbullet, string description){
- SpellDisplayEffect* effect = new SpellDisplayEffect;
- effect->description = description;
- effect->subbullet = subbullet;
- effect->percentage = percentage;
- MSpellInfo.lock();
- effects.push_back(effect);
- MSpellInfo.unlock();
- }
- int16 Spell::GetHPRequired(Spawn* spawn){
- int16 hp_req = spell->hp_req;
- if(spawn && spell->hp_req_percent > 0){
- double result = ((double)spell->hp_req_percent/100)*spawn->GetTotalHP();
- if(result >= (((int16)result) + .5))
- result++;
- hp_req = (int16)result;
- }
- return hp_req;
- }
- int16 Spell::GetPowerRequired(Spawn* spawn){
- int16 power_req;
- if (spell->power_by_level == true) {
- power_req =round( (spell->power_req) * spawn->GetLevel());
- }
- else {
- power_req = round(spell->power_req);
- }
- if(spawn && spell->power_req_percent > 0){
- double result = ((double)spell->power_req_percent/100)*spawn->GetTotalPower();
- if(result >= (((int16)result) + .5))
- result++;
- power_req = (int16)result;
- }
- return power_req;
- }
- int16 Spell::GetSavageryRequired(Spawn* spawn){
- int16 savagery_req = spell->savagery_req;
- if(spawn && spell->savagery_req_percent > 0){
- double result = ((double)spell->savagery_req_percent/100)*spawn->GetTotalSavagery();
- if(result >= (((int16)result) + .5))
- result++;
- savagery_req = (int16)result;
- }
- return savagery_req;
- }
- int16 Spell::GetDissonanceRequired(Spawn* spawn){
- int16 dissonance_req = spell->dissonance_req;
- if(spawn && spell->dissonance_req_percent > 0){
- double result = ((double)spell->dissonance_req_percent/100)*spawn->GetTotalDissonance();
- if(result >= (((int16)result) + .5))
- result++;
- dissonance_req = (int16)result;
- }
- return dissonance_req;
- }
- int32 Spell::GetSpellDuration(){
- if(spell->duration1 == spell->duration2)
- return spell->duration1;
- int32 difference = 0;
- int32 lower = 0;
- if(spell->duration2 > spell->duration1){
- difference = spell->duration2 - spell->duration1;
- lower = spell->duration1;
- }
- else{
- difference = spell->duration1 - spell->duration2;
- lower = spell->duration2;
- }
- int32 duration = (rand()%difference) + lower;
- return duration;
- }
- const char* Spell::GetName(){
- return spell->name.data.c_str();
- }
- const char* Spell::GetDescription(){
- return spell->description.data.c_str();
- }
- void Spell::AddSpellLevel(int8 adventure_class, int8 tradeskill_class, int16 level){
- LevelArray* lvl = new LevelArray;
- lvl->adventure_class = adventure_class;
- lvl->tradeskill_class = tradeskill_class;
- lvl->spell_level = level;
- MSpellInfo.lock();
- levels.push_back(lvl);
- MSpellInfo.unlock();
- }
- int32 Spell::GetSpellID(){
- if (spell)
- return spell->id;
- return 0;
- }
- int8 Spell::GetSpellTier(){
- if (spell)
- return spell->tier;
- return 0;
- }
- vector<LUAData*>* Spell::GetLUAData(){
- return &lua_data;
- }
- SpellData* Spell::GetSpellData(){
- return spell;
- }
- bool Spell::GetSpellData(lua_State* state, std::string field)
- {
- if (!lua_interface)
- return false;
- bool valSet = false;
- if (field == "spell_book_type")
- {
- lua_interface->SetInt32Value(state, GetSpellData()->spell_book_type);
- valSet = true;
- }
- else if (field == "icon")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->icon);
- valSet = true;
- }
- else if (field == "icon_heroic_op")
- {
- lua_interface->SetInt32Value(state, GetSpellData()->icon_heroic_op);
- valSet = true;
- }
- else if (field == "icon_backdrop")
- {
- lua_interface->SetInt32Value(state, GetSpellData()->icon_backdrop);
- valSet = true;
- }
- else if (field == "type")
- {
- lua_interface->SetInt32Value(state, GetSpellData()->type);
- valSet = true;
- }
- else if (field == "class_skill")
- {
- lua_interface->SetInt32Value(state, GetSpellData()->class_skill);
- valSet = true;
- }
- else if (field == "min_class_skill_req")
- {
- lua_interface->SetInt32Value(state, GetSpellData()->min_class_skill_req);
- valSet = true;
- }
- else if (field == "mastery_skill")
- {
- lua_interface->SetInt32Value(state, GetSpellData()->mastery_skill);
- valSet = true;
- }
- else if (field == "ts_loc_index")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->ts_loc_index);
- valSet = true;
- }
- else if (field == "num_levels")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->num_levels);
- valSet = true;
- }
- else if (field == "tier")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->tier);
- valSet = true;
- }
- else if (field == "hp_req")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->hp_req);
- valSet = true;
- }
- else if (field == "hp_upkeep")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->hp_upkeep);
- valSet = true;
- }
- else if (field == "power_req")
- {
- lua_interface->SetFloatValue(state, GetSpellData()->power_req);
- valSet = true;
- }
- else if (field == "power_by_level")
- {
- lua_interface->SetBooleanValue(state, GetSpellData()->power_by_level);
- valSet = true;
- }
- else if (field == "power_upkeep")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->power_upkeep);
- valSet = true;
- }
- else if (field == "savagery_req")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->savagery_req);
- valSet = true;
- }
- else if (field == "savagery_upkeep")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->savagery_upkeep);
- valSet = true;
- }
- else if (field == "dissonance_req")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->dissonance_req);
- valSet = true;
- }
- else if (field == "dissonance_upkeep")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->dissonance_upkeep);
- valSet = true;
- }
- else if (field == "target_type")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->target_type);
- valSet = true;
- }
- else if (field == "cast_time")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->cast_time);
- valSet = true;
- }
- else if (field == "recovery")
- {
- lua_interface->SetFloatValue(state, GetSpellData()->recovery);
- valSet = true;
- }
- else if (field == "recast")
- {
- lua_interface->SetFloatValue(state, GetSpellData()->recast);
- valSet = true;
- }
- else if (field == "linked_timer")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->linked_timer);
- valSet = true;
- }
- else if (field == "radius")
- {
- lua_interface->SetFloatValue(state, GetSpellData()->radius);
- valSet = true;
- }
- else if (field == "max_aoe_targets")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->max_aoe_targets);
- valSet = true;
- }
- else if (field == "friendly_spell")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->friendly_spell);
- valSet = true;
- }
- else if (field == "req_concentration")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->req_concentration);
- valSet = true;
- }
- else if (field == "range")
- {
- lua_interface->SetFloatValue(state, GetSpellData()->range);
- valSet = true;
- }
- else if (field == "duration1")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->duration1);
- valSet = true;
- }
- else if (field == "duration2")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->duration2);
- valSet = true;
- }
- else if (field == "resistibility")
- {
- lua_interface->SetFloatValue(state, GetSpellData()->resistibility);
- valSet = true;
- }
- else if (field == "duration_until_cancel")
- {
- lua_interface->SetBooleanValue(state, GetSpellData()->duration_until_cancel);
- valSet = true;
- }
- else if (field == "power_req_percent")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->power_req_percent);
- valSet = true;
- }
- else if (field == "hp_req_percent")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->hp_req_percent);
- valSet = true;
- }
- else if (field == "savagery_req_percent")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->savagery_req_percent);
- valSet = true;
- }
- else if (field == "dissonance_req_percent")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->dissonance_req_percent);
- valSet = true;
- }
- else if (field == "name")
- {
- lua_interface->SetStringValue(state, GetSpellData()->name.data.c_str());
- valSet = true;
- }
- else if (field == "description")
- {
- lua_interface->SetStringValue(state, GetSpellData()->description.data.c_str());
- valSet = true;
- }
- else if (field == "success_message")
- {
- lua_interface->SetStringValue(state, GetSpellData()->success_message.c_str());
- valSet = true;
- }
- else if (field == "fade_message")
- {
- lua_interface->SetStringValue(state, GetSpellData()->fade_message.c_str());
- valSet = true;
- }
- else if (field == "fade_message_others")
- {
- lua_interface->SetStringValue(state, GetSpellData()->fade_message_others.c_str());
- valSet = true;
- }
- else if (field == "cast_type")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->cast_type);
- valSet = true;
- }
- else if (field == "lua_script")
- {
- lua_interface->SetStringValue(state, GetSpellData()->lua_script.c_str());
- valSet = true;
- }
- else if (field == "interruptable")
- {
- lua_interface->SetBooleanValue(state, GetSpellData()->interruptable);
- valSet = true;
- }
- else if (field == "spell_visual")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->spell_visual);
- valSet = true;
- }
- else if (field == "effect_message")
- {
- lua_interface->SetStringValue(state, GetSpellData()->effect_message.c_str());
- valSet = true;
- }
- else if (field == "min_range")
- {
- lua_interface->SetFloatValue(state, GetSpellData()->min_range);
- valSet = true;
- }
- else if (field == "can_effect_raid")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->can_effect_raid);
- valSet = true;
- }
- else if (field == "affect_only_group_members")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->affect_only_group_members);
- valSet = true;
- }
- else if (field == "group_spell")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->group_spell);
- valSet = true;
- }
- else if (field == "hit_bonus")
- {
- lua_interface->SetFloatValue(state, GetSpellData()->hit_bonus);
- valSet = true;
- }
- else if (field == "display_spell_tier")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->display_spell_tier);
- valSet = true;
- }
- else if (field == "is_active")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->is_active);
- valSet = true;
- }
- else if (field == "det_type")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->det_type);
- valSet = true;
- }
- else if (field == "incurable")
- {
- lua_interface->SetBooleanValue(state, GetSpellData()->incurable);
- valSet = true;
- }
- else if (field == "control_effect_type")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->control_effect_type);
- valSet = true;
- }
- else if (field == "casting_flags")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->casting_flags);
- valSet = true;
- }
- else if (field == "cast_while_moving")
- {
- lua_interface->SetBooleanValue(state, GetSpellData()->cast_while_moving);
- valSet = true;
- }
- else if (field == "persist_through_death")
- {
- lua_interface->SetBooleanValue(state, GetSpellData()->persist_through_death);
- valSet = true;
- }
- else if (field == "not_maintained")
- {
- lua_interface->SetBooleanValue(state, GetSpellData()->not_maintained);
- valSet = true;
- }
- else if (field == "is_aa")
- {
- lua_interface->SetBooleanValue(state, GetSpellData()->is_aa);
- valSet = true;
- }
- else if (field == "savage_bar")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->savage_bar);
- valSet = true;
- }
- else if (field == "savage_bar_slot")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->savage_bar_slot);
- valSet = true;
- }
- else if (field == "soe_spell_crc")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->soe_spell_crc);
- valSet = true;
- }
- else if (field == "spell_type")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->spell_type);
- valSet = true;
- }
- else if (field == "spell_name_crc")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->spell_name_crc);
- valSet = true;
- }
- else if (field == "type_group_spell_id")
- {
- lua_interface->SetSInt32Value(state, GetSpellData()->type_group_spell_id);
- valSet = true;
- }
- else if (field == "can_fizzle")
- {
- lua_interface->SetBooleanValue(state, GetSpellData()->can_fizzle);
- valSet = true;
- }
- return valSet;
- }
- bool Spell::SetSpellData(lua_State* state, std::string field, int8 fieldArg)
- {
- if (!lua_interface)
- return false;
- bool valSet = false;
- if (field == "spell_book_type")
- {
- int32 spell_book_type = lua_interface->GetInt32Value(state, fieldArg);
- GetSpellData()->spell_book_type = spell_book_type;
- valSet = true;
- }
- else if (field == "icon")
- {
- sint16 icon = lua_interface->GetSInt32Value(state, fieldArg);
- GetSpellData()->icon = icon;
- valSet = true;
- }
- else if (field == "icon_heroic_op")
- {
- int16 icon_heroic_op = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->icon_heroic_op = icon_heroic_op;
- valSet = true;
- }
- else if (field == "icon_backdrop")
- {
- int16 icon_backdrop = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->icon_backdrop = icon_backdrop;
- valSet = true;
- }
- else if (field == "type")
- {
- int16 type = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->type = type;
- valSet = true;
- }
- else if (field == "class_skill")
- {
- int32 class_skill = lua_interface->GetInt32Value(state, fieldArg);
- GetSpellData()->class_skill = class_skill;
- valSet = true;
- }
- else if (field == "min_class_skill_req")
- {
- int16 min_class_skill_req = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->min_class_skill_req = min_class_skill_req;
- valSet = true;
- }
- else if (field == "mastery_skill")
- {
- int32 mastery_skill = lua_interface->GetInt32Value(state, fieldArg);
- GetSpellData()->mastery_skill = mastery_skill;
- valSet = true;
- }
- else if (field == "ts_loc_index")
- {
- int8 ts_loc_index = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->ts_loc_index = ts_loc_index;
- valSet = true;
- }
- else if (field == "num_levels")
- {
- int8 num_levels = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->num_levels = num_levels;
- valSet = true;
- }
- else if (field == "tier")
- {
- int8 tier = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->tier = tier;
- valSet = true;
- }
- else if (field == "hp_req")
- {
- int16 hp_req = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->hp_req = hp_req;
- valSet = true;
- }
- else if (field == "hp_upkeep")
- {
- int16 hp_upkeep = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->hp_upkeep = hp_upkeep;
- valSet = true;
- }
- else if (field == "power_req")
- {
- float power_req = lua_interface->GetFloatValue(state, fieldArg);
- GetSpellData()->power_req = power_req;
- valSet = true;
- }
- else if (field == "power_by_level")
- {
- bool power_by_level = lua_interface->GetBooleanValue(state, fieldArg);
- GetSpellData()->power_by_level = power_by_level;
- valSet = true;
- }
- else if (field == "power_upkeep")
- {
- int16 power_upkeep = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->power_upkeep = power_upkeep;
- valSet = true;
- }
- else if (field == "savagery_req")
- {
- int16 savagery_req = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->savagery_req = savagery_req;
- valSet = true;
- }
- else if (field == "savagery_upkeep")
- {
- int16 savagery_upkeep = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->savagery_upkeep = savagery_upkeep;
- valSet = true;
- }
- else if (field == "dissonance_req")
- {
- int16 dissonance_req = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->dissonance_req = dissonance_req;
- valSet = true;
- }
- else if (field == "dissonance_upkeep")
- {
- int16 dissonance_upkeep = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->dissonance_upkeep = dissonance_upkeep;
- valSet = true;
- }
- else if (field == "target_type")
- {
- int16 target_type = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->target_type = target_type;
- valSet = true;
- }
- else if (field == "cast_time")
- {
- int16 cast_time = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->cast_time = cast_time;
- valSet = true;
- }
- else if (field == "recovery")
- {
- float recovery = lua_interface->GetFloatValue(state, fieldArg);
- GetSpellData()->recovery = recovery;
- valSet = true;
- }
- else if (field == "recast")
- {
- float recast = lua_interface->GetFloatValue(state, fieldArg);
- GetSpellData()->recast = recast;
- valSet = true;
- }
- else if (field == "linked_timer")
- {
- int32 linked_timer = lua_interface->GetInt32Value(state, fieldArg);
- GetSpellData()->linked_timer = linked_timer;
- valSet = true;
- }
- else if (field == "radius")
- {
- float radius = lua_interface->GetFloatValue(state, fieldArg);
- GetSpellData()->radius = radius;
- valSet = true;
- }
- else if (field == "max_aoe_targets")
- {
- int16 max_aoe_targets = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->max_aoe_targets = max_aoe_targets;
- valSet = true;
- }
- else if (field == "friendly_spell")
- {
- int8 friendly_spell = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->friendly_spell = friendly_spell;
- valSet = true;
- }
- else if (field == "req_concentration")
- {
- int16 req_concentration = lua_interface->GetInt16Value(state, fieldArg);
- GetSpellData()->req_concentration = req_concentration;
- valSet = true;
- }
- else if (field == "range")
- {
- float range = lua_interface->GetFloatValue(state, fieldArg);
- GetSpellData()->range = range;
- valSet = true;
- }
- else if (field == "duration1")
- {
- sint32 duration = lua_interface->GetSInt32Value(state, fieldArg);
- GetSpellData()->duration1 = duration;
- valSet = true;
- }
- else if (field == "duration2")
- {
- sint32 duration = lua_interface->GetSInt32Value(state, fieldArg);
- GetSpellData()->duration2 = duration;
- valSet = true;
- }
- else if (field == "resistibility")
- {
- float resistibility = lua_interface->GetFloatValue(state, fieldArg);
- GetSpellData()->resistibility = resistibility;
- valSet = true;
- }
- else if (field == "duration_until_cancel")
- {
- bool duration_until_cancel = lua_interface->GetBooleanValue(state, fieldArg);
- GetSpellData()->duration_until_cancel = duration_until_cancel;
- valSet = true;
- }
- else if (field == "power_req_percent")
- {
- int8 power_req_percent = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->power_req_percent = power_req_percent;
- valSet = true;
- }
- else if (field == "hp_req_percent")
- {
- int8 hp_req_percent = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->hp_req_percent = hp_req_percent;
- valSet = true;
- }
- else if (field == "savagery_req_percent")
- {
- int8 savagery_req_percent = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->savagery_req_percent = savagery_req_percent;
- valSet = true;
- }
- else if (field == "dissonance_req_percent")
- {
- int8 dissonance_req_percent = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->dissonance_req_percent = dissonance_req_percent;
- valSet = true;
- }
- else if (field == "name")
- {
- string name = lua_interface->GetStringValue(state, fieldArg);
- GetSpellData()->name.data = name;
- valSet = true;
- }
- else if (field == "description")
- {
- string description = lua_interface->GetStringValue(state, fieldArg);
- GetSpellData()->description.data = description;
- valSet = true;
- }
- else if (field == "success_message")
- {
- string success_message = lua_interface->GetStringValue(state, fieldArg);
- GetSpellData()->success_message = success_message;
- valSet = true;
- }
- else if (field == "fade_message")
- {
- string fade_message = lua_interface->GetStringValue(state, fieldArg);
- GetSpellData()->fade_message = fade_message;
- valSet = true;
- }
- else if (field == "fade_message_others")
- {
- string fade_message_others = lua_interface->GetStringValue(state, fieldArg);
- GetSpellData()->fade_message_others = fade_message_others;
- valSet = true;
- }
- else if (field == "cast_type")
- {
- int8 cast_type = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->cast_type = cast_type;
- valSet = true;
- }
- else if (field == "cast_type")
- {
- int32 call_frequency = lua_interface->GetInt32Value(state, fieldArg);
- GetSpellData()->call_frequency = call_frequency;
- valSet = true;
- }
- else if (field == "interruptable")
- {
- bool interruptable = lua_interface->GetBooleanValue(state, fieldArg);
- GetSpellData()->interruptable = interruptable;
- valSet = true;
- }
- else if (field == "spell_visual")
- {
- int32 spell_visual = lua_interface->GetInt32Value(state, fieldArg);
- GetSpellData()->spell_visual = spell_visual;
- valSet = true;
- }
- else if (field == "effect_message")
- {
- string effect_message = lua_interface->GetStringValue(state, fieldArg);
- GetSpellData()->effect_message = effect_message;
- valSet = true;
- }
- else if (field == "min_range")
- {
- float min_range = lua_interface->GetFloatValue(state, fieldArg);
- GetSpellData()->min_range = min_range;
- valSet = true;
- }
- else if (field == "can_effect_raid")
- {
- int8 can_effect_raid = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->can_effect_raid = can_effect_raid;
- valSet = true;
- }
- else if (field == "affect_only_group_members")
- {
- int8 affect_only_group_members = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->affect_only_group_members = affect_only_group_members;
- valSet = true;
- }
- else if (field == "group_spell")
- {
- int8 group_spell = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->group_spell = group_spell;
- valSet = true;
- }
- else if (field == "hit_bonus")
- {
- float hit_bonus = lua_interface->GetFloatValue(state, fieldArg);
- GetSpellData()->hit_bonus = hit_bonus;
- valSet = true;
- }
- else if (field == "display_spell_tier")
- {
- int8 display_spell_tier = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->display_spell_tier = display_spell_tier;
- valSet = true;
- }
- else if (field == "is_active")
- {
- int8 is_active = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->is_active = is_active;
- valSet = true;
- }
- else if (field == "det_type")
- {
- int8 det_type = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->det_type = det_type;
- valSet = true;
- }
- else if (field == "incurable")
- {
- bool incurable = lua_interface->GetBooleanValue(state, fieldArg);
- GetSpellData()->incurable = incurable;
- valSet = true;
- }
- else if (field == "control_effect_type")
- {
- int8 control_effect_type = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->control_effect_type = control_effect_type;
- valSet = true;
- }
- else if (field == "casting_flags")
- {
- int32 casting_flags = lua_interface->GetInt32Value(state, fieldArg);
- GetSpellData()->casting_flags = casting_flags;
- valSet = true;
- }
- else if (field == "cast_while_moving")
- {
- bool cast_while_moving = lua_interface->GetBooleanValue(state, fieldArg);
- GetSpellData()->cast_while_moving = cast_while_moving;
- valSet = true;
- }
- else if (field == "persist_through_death")
- {
- bool persist_through_death = lua_interface->GetBooleanValue(state, fieldArg);
- GetSpellData()->persist_through_death = persist_through_death;
- valSet = true;
- }
- else if (field == "not_maintained")
- {
- bool not_maintained = lua_interface->GetBooleanValue(state, fieldArg);
- GetSpellData()->not_maintained = not_maintained;
- valSet = true;
- }
- else if (field == "is_aa")
- {
- bool is_aa = lua_interface->GetBooleanValue(state, fieldArg);
- GetSpellData()->is_aa = is_aa;
- valSet = true;
- }
- else if (field == "savage_bar")
- {
- int8 savage_bar = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->savage_bar = savage_bar;
- valSet = true;
- }
- else if (field == "spell_type")
- {
- int8 spell_type = lua_interface->GetInt8Value(state, fieldArg);
- GetSpellData()->spell_type = spell_type;
- valSet = true;
- }
- else if (field == "type_group_spell_id")
- {
- sint32 type_group_spell_id = lua_interface->GetSInt32Value(state, fieldArg);
- GetSpellData()->type_group_spell_id = type_group_spell_id;
- valSet = true;
- }
- else if (field == "can_fizzle")
- {
- bool can_fizzle = lua_interface->GetBooleanValue(state, fieldArg);
- GetSpellData()->can_fizzle = can_fizzle;
- valSet = true;
- }
- return valSet;
- }
- int16 Spell::GetSpellIcon(){
- if (spell)
- return spell->icon;
- return 0;
- }
- int16 Spell::GetSpellIconBackdrop(){
- if (spell)
- return spell->icon_backdrop;
- return 0;
- }
- int16 Spell::GetSpellIconHeroicOp(){
- if (spell)
- return spell->icon_heroic_op;
- return 0;
- }
- bool Spell::IsHealSpell(){
- return heal_spell;
- }
- bool Spell::IsBuffSpell(){
- return buff_spell;
- }
- bool Spell::IsDamageSpell(){
- return damage_spell;
- }
- bool Spell::IsControlSpell(){
- return control_spell;
- }
- bool Spell::IsOffenseSpell() {
- return offense_spell;
- }
- bool Spell::IsCopiedSpell() {
- return copied_spell;
- }
- void Spell::ModifyCastTime(Entity* caster){
- int16 cast_time = spell->cast_time;
- float cast_speed = caster->GetInfoStruct()->get_casting_speed();
- if (cast_time > 0){
- if (cast_speed > 0) // casting speed can only reduce up to half a cast time
- spell->cast_time *= max((float) 0.5, (float) (1 / (1 + (cast_speed * .01))));
- 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
- spell->cast_time *= min((float) 1.5, (float) (1 + (1 - (1 / (1 + (cast_speed * -.01))))));
- }
- }
- vector <SpellDisplayEffect*>* Spell::GetSpellEffects(){
- MSpellInfo.lock();
- vector <SpellDisplayEffect*>* ret = &effects;
- MSpellInfo.unlock();
- return ret;
- }
- vector <LevelArray*>* Spell::GetSpellLevels(){
- MSpellInfo.lock();
- vector <LevelArray*>* ret = &levels;
- MSpellInfo.unlock();
- return ret;
- }
- bool Spell::ScribeAllowed(Player* player){
- bool ret = false;
- if(player){
- MSpellInfo.lock();
- for(int32 i=0;!ret && i<levels.size();i++){
- int16 mylevel = player->GetLevel();
- int16 spelllevels = levels[i]->spell_level;
- bool advlev = player->GetAdventureClass() == levels[i]->adventure_class;
- bool tslev = player->GetTradeskillClass() == levels[i]->tradeskill_class;
- bool levelmatch = player->GetLevel() >= levels[i]->spell_level;
- if((player->GetAdventureClass() == levels[i]->adventure_class || player->GetTradeskillClass() == levels[i]->tradeskill_class) && player->GetLevel() >= levels[i]->spell_level/10)
- ret = true;
- }
- MSpellInfo.unlock();
- }
- return ret;
- }
- MasterSpellList::MasterSpellList(){
- max_spell_id = 0;
- MMasterSpellList.SetName("MasterSpellList::MMasterSpellList");
- }
- MasterSpellList::~MasterSpellList(){
- DestroySpells();
- }
- void MasterSpellList::DestroySpells(){
- spell_errors.clear();
- MMasterSpellList.lock();
- map<int32, map<int32, Spell*> >::iterator iter;
- map<int32, Spell*>::iterator iter2;
- for(iter = spell_list.begin();iter != spell_list.end(); iter++){
- for(iter2 = iter->second.begin();iter2 != iter->second.end(); iter2++){
- safe_delete(iter2->second);
- }
- }
- spell_list.clear();
- MMasterSpellList.unlock();
- }
- void MasterSpellList::AddSpell(int32 id, int8 tier, Spell* spell){
- MMasterSpellList.lock();
- spell_list[id][tier] = spell;
- spell_name_map[spell->GetName()] = spell;
- spell_soecrc_map[spell->GetSpellData()->soe_spell_crc] = spell;
- if (id > max_spell_id)
- max_spell_id = id;
- MMasterSpellList.unlock();
- }
- Spell* MasterSpellList::GetSpell(int32 id, int8 tier){
- if (spell_list.count(id) > 0 && spell_list[id].count(tier) > 0)
- return spell_list[id][tier];
- else if (spell_list.count(id) > 0 && tier == 0 && spell_list[id].count(1) > 0)
- return spell_list[id][1];
- return 0;
- }
- Spell* MasterSpellList::GetSpellByName(const char* name){
- if(spell_name_map.count(name) > 0)
- return spell_name_map[name];
- return 0;
- }
- Spell* MasterSpellList::GetSpellByCRC(int32 spell_crc){
- if(spell_soecrc_map.count(spell_crc) > 0)
- return spell_soecrc_map[spell_crc];
- return 0;
- }
- EQ2Packet* MasterSpellList::GetSpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type){
- Spell* spell = GetSpell(id, tier);
- // if we can't find it on the master spell list, see if it is a custom spell
- if (!spell)
- {
- lua_interface->FindCustomSpellLock();
- LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
- EQ2Packet* pack = 0;
- if (tmpSpell)
- {
- spell = tmpSpell->spell;
- pack = spell->SerializeSpell(client, display, packet_type);
- }
- lua_interface->FindCustomSpellUnlock();
- return pack;
- }
- if(spell)
- return spell->SerializeSpell(client, display, packet_type);
- return 0;
- }
- EQ2Packet* MasterSpellList::GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
- Spell* spell = GetSpell(id, (tier == 0 ? 1 : tier));
- // if we can't find it on the master spell list, see if it is a custom spell
- if (!spell)
- {
- lua_interface->FindCustomSpellLock();
- LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
- EQ2Packet* pack = 0;
- if (tmpSpell)
- {
- spell = tmpSpell->spell;
- // TODO: this isn't a tested thing yet... need to add custom spells to alt advancement?
- AltAdvanceData* data = master_aa_list.GetAltAdvancement(id);
- if(data)
- pack = spell->SerializeAASpell(client, tier, data, display, false, packet_type);
- }
- lua_interface->FindCustomSpellUnlock();
- return pack;
- }
- //Spell* spell2= GetSpell(id, (tier +1));
- AltAdvanceData* data = master_aa_list.GetAltAdvancement(id);
- if (spell)
- return spell->SerializeAASpell(client,tier, data, display,false, packet_type);
- return 0;
- }
- EQ2Packet* MasterSpellList::GetSpecialSpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type){
- Spell* spell = GetSpell(id, tier);
- // if we can't find it on the master spell list, see if it is a custom spell
- if (!spell)
- {
- lua_interface->FindCustomSpellLock();
- LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
- EQ2Packet* pack = 0;
- if (tmpSpell)
- {
- spell = tmpSpell->spell;
- pack = spell->SerializeSpecialSpell(client, display, packet_type, 0x81);
- }
- lua_interface->FindCustomSpellUnlock();
- return pack;
- }
- if(spell)
- return spell->SerializeSpecialSpell(client, display, packet_type, 0x81);
- return 0;
- }
- vector<Spell*>* MasterSpellList::GetSpellListByAdventureClass(int8 class_id, int16 max_level, int8 max_tier){
- vector<Spell*>* ret = new vector<Spell*>;
- Spell* spell = 0;
- vector<LevelArray*>* levels = 0;
- LevelArray* level = 0;
- vector<LevelArray*>::iterator level_itr;
- MMasterSpellList.lock();
- map<int32, map<int32, Spell*> >::iterator iter;
- map<int32, Spell*>::iterator iter2;
- max_level *= 10; //convert to client level format, which is 10 times higher
- for(iter = spell_list.begin();iter != spell_list.end(); iter++){
- for(iter2 = iter->second.begin();iter2 != iter->second.end(); iter2++){
- spell = iter2->second;
- if(iter2->first <= max_tier && spell){
- levels = spell->GetSpellLevels();
- for(level_itr = levels->begin(); level_itr != levels->end(); level_itr++){
- level = *level_itr;
- if(level->spell_level <= max_level && level->adventure_class == class_id){
- ret->push_back(spell);
- break;
- }
- }
- }
- }
- }
- MMasterSpellList.unlock();
- return ret;
- }
- vector<Spell*>* MasterSpellList::GetSpellListByTradeskillClass(int8 class_id, int16 max_level, int8 max_tier){
- vector<Spell*>* ret = new vector<Spell*>;
- Spell* spell = 0;
- vector<LevelArray*>* levels = 0;
- LevelArray* level = 0;
- vector<LevelArray*>::iterator level_itr;
- MMasterSpellList.lock();
- map<int32, map<int32, Spell*> >::iterator iter;
- map<int32, Spell*>::iterator iter2;
- for(iter = spell_list.begin();iter != spell_list.end(); iter++){
- for(iter2 = iter->second.begin();iter2 != iter->second.end(); iter2++){
- spell = iter2->second;
- if(iter2->first <= max_tier && spell){
- levels = spell->GetSpellLevels();
- for(level_itr = levels->begin(); level_itr != levels->end(); level_itr++){
- level = *level_itr;
- if(level->spell_level <= max_level && level->tradeskill_class == class_id){
- ret->push_back(spell);
- break;
- }
- }
- }
- }
- }
- MMasterSpellList.unlock();
- return ret;
- }
- void MasterSpellList::Reload(){
- master_trait_list.DestroyTraits();
- DestroySpells();
- database.LoadSpells();
- database.LoadSpellErrors();
- database.LoadTraits();
- }
- int16 MasterSpellList::GetSpellErrorValue(int16 version, int8 error_index) {
- version = GetClosestVersion(version);
- if (spell_errors[version].count(error_index) == 0) {
- LogWrite(SPELL__ERROR, 0, "Spells", "No spell error entry. (version = %i, error_index = %i)", version, error_index);
- // 1 will give the client a pop up message of "Cannot cast" and a chat message of "[BUG] Cannot cast. Unknown failure casting spell."
- return 1;
- }
- return spell_errors[version][error_index];
- }
- void MasterSpellList::AddSpellError(int16 version, int8 error_index, int16 error_value) {
- if (spell_errors[version].count(error_index) == 0)
- spell_errors[version][error_index] = error_value;
- }
- int16 MasterSpellList::GetClosestVersion(int16 version) {
- int16 ret = 0;
- map<int16, map<int8, int16> >::iterator itr;
- // Get the closest version in the list that is less then or equal to the given version
- for (itr = spell_errors.begin(); itr != spell_errors.end(); itr++) {
- if (itr->first <= version) {
- if (itr->first > ret)
- ret = itr->first;
- }
- }
- return ret;
- }
- bool Spell::CastWhileStunned(){
- return (spell->casting_flags & CASTING_FLAG_STUNNED) == CASTING_FLAG_STUNNED;
- }
- bool Spell::CastWhileMezzed(){
- return (spell->casting_flags & CASTING_FLAG_MEZZED) == CASTING_FLAG_MEZZED;
- }
- bool Spell::CastWhileStifled(){
- return (spell->casting_flags & CASTING_FLAG_STIFLED) == CASTING_FLAG_STIFLED;
- }
- bool Spell::CastWhileFeared(){
- return (spell->casting_flags & CASTING_FLAG_FEARED) == CASTING_FLAG_FEARED;
- }
|