9
3

Entity.cpp 143 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "Entity.h"
  17. #include <math.h>
  18. #include "Items/Items.h"
  19. #include "zoneserver.h"
  20. #include "World.h"
  21. #include "../common/Log.h"
  22. #include "Spells.h"
  23. #include "SpellProcess.h"
  24. #include "classes.h"
  25. #include "LuaInterface.h"
  26. #include "ClientPacketFunctions.h"
  27. #include "Skills.h"
  28. #include "Rules/Rules.h"
  29. #include "LuaInterface.h"
  30. extern World world;
  31. extern MasterItemList master_item_list;
  32. extern MasterSpellList master_spell_list;
  33. extern MasterSkillList master_skill_list;
  34. extern RuleManager rule_manager;
  35. extern Classes classes;
  36. extern LuaInterface* lua_interface;
  37. Entity::Entity(){
  38. MapInfoStruct();
  39. max_speed = 6;
  40. base_speed = 0.0f;
  41. last_x = -1;
  42. last_y = -1;
  43. last_z = -1;
  44. last_heading = -1;
  45. regen_hp_rate = 0;
  46. regen_power_rate = 0;
  47. in_combat = false;
  48. casting = false;
  49. //memset(&info_struct, 0, sizeof(InfoStruct));
  50. memset(&features, 0, sizeof(CharFeatures));
  51. memset(&equipment, 0, sizeof(EQ2_Equipment));
  52. pet = 0;
  53. charmedPet = 0;
  54. deityPet = 0;
  55. cosmeticPet = 0;
  56. speed = 0;
  57. speed_multiplier = 1.0f;
  58. m_threatTransfer = 0;
  59. group_member_info = 0;
  60. trade = 0;
  61. deity = 0;
  62. MProcList.SetName("Entity::m_procList");
  63. MDetriments.SetName("Entity::MDetriments");
  64. MMaintainedSpells.SetName("Entity::MMaintainedSpells");
  65. MSpellEffects.SetName("Entity::MSpellEffects");
  66. m_procList.clear();
  67. control_effects.clear();
  68. for (int i = 0; i < CONTROL_MAX_EFFECTS; i++)
  69. control_effects[i] = NULL;
  70. immunities.clear();
  71. info_struct.ResetEffects(this);
  72. MCommandMutex.SetName("Entity::MCommandMutex");
  73. hasSeeInvisSpell = false;
  74. hasSeeHideSpell = false;
  75. owner = 0;
  76. m_petType = 0;
  77. m_petSpellID = 0;
  78. m_petSpellTier = 0;
  79. m_petDismissing = false;
  80. if (!IsPlayer() && GetInfoStruct()->get_max_concentration_base() == 0)
  81. GetInfoStruct()->set_max_concentration_base(5);
  82. }
  83. Entity::~Entity(){
  84. MutexList<BonusValues*>::iterator itr2 = bonus_list.begin();
  85. while(itr2.Next())
  86. safe_delete(itr2.value);
  87. ClearProcs();
  88. safe_delete(m_threatTransfer);
  89. map<int8, MutexList<LuaSpell*>*>::iterator itr3;
  90. for (itr3 = control_effects.begin(); itr3 != control_effects.end(); itr3++)
  91. safe_delete(itr3->second);
  92. control_effects.clear();
  93. map<int8, MutexList<LuaSpell*>*>::iterator itr4;
  94. for (itr4 = immunities.begin(); itr4 != immunities.end(); itr4++)
  95. safe_delete(itr4->second);
  96. immunities.clear();
  97. if(!IsPlayer())
  98. DeleteSpellEffects(true);
  99. safe_delete(m_threatTransfer);
  100. }
  101. void Entity::DeleteSpellEffects(bool removeClient)
  102. {
  103. map<LuaSpell*,bool> deletedPtrs;
  104. for(int i=0;i<45;i++){
  105. if(i<30){
  106. if(GetInfoStruct()->maintained_effects[i].spell_id != 0xFFFFFFFF)
  107. {
  108. if(deletedPtrs.find(GetInfoStruct()->maintained_effects[i].spell) == deletedPtrs.end())
  109. {
  110. deletedPtrs[GetInfoStruct()->maintained_effects[i].spell] = true;
  111. lua_interface->RemoveSpell(GetInfoStruct()->maintained_effects[i].spell, false, removeClient, "", removeClient);
  112. if (IsPlayer())
  113. GetInfoStruct()->maintained_effects[i].icon = 0xFFFF;
  114. }
  115. GetInfoStruct()->maintained_effects[i].spell_id = 0xFFFFFFFF;
  116. GetInfoStruct()->maintained_effects[i].spell = nullptr;
  117. }
  118. }
  119. if(GetInfoStruct()->spell_effects[i].spell_id != 0xFFFFFFFF)
  120. {
  121. if(deletedPtrs.find(GetInfoStruct()->spell_effects[i].spell) == deletedPtrs.end()) {
  122. if(GetInfoStruct()->spell_effects[i].spell && GetInfoStruct()->spell_effects[i].spell->spell &&
  123. GetInfoStruct()->spell_effects[i].spell->spell->GetSpellData()->spell_book_type == SPELL_BOOK_TYPE_NOT_SHOWN) {
  124. deletedPtrs[GetInfoStruct()->spell_effects[i].spell] = true;
  125. lua_interface->RemoveSpell(GetInfoStruct()->spell_effects[i].spell, false, removeClient, "", removeClient);
  126. }
  127. }
  128. GetInfoStruct()->spell_effects[i].spell_id = 0xFFFFFFFF;
  129. GetInfoStruct()->spell_effects[i].spell = nullptr;
  130. }
  131. }
  132. }
  133. void Entity::RemoveSpells(bool unfriendlyOnly)
  134. {
  135. for(int i=0;i<45;i++){
  136. if(i<30){
  137. if(GetInfoStruct()->maintained_effects[i].spell_id != 0xFFFFFFFF)
  138. {
  139. if(!unfriendlyOnly || (unfriendlyOnly && GetInfoStruct()->maintained_effects[i].spell &&
  140. !GetInfoStruct()->maintained_effects[i].spell->spell->GetSpellData()->friendly_spell))
  141. GetZone()->GetSpellProcess()->AddSpellCancel(GetInfoStruct()->maintained_effects[i].spell);
  142. }
  143. }
  144. if(GetInfoStruct()->spell_effects[i].spell_id != 0xFFFFFFFF)
  145. {
  146. if(!unfriendlyOnly || (unfriendlyOnly && GetInfoStruct()->spell_effects[i].spell &&
  147. !GetInfoStruct()->spell_effects[i].spell->spell->GetSpellData()->friendly_spell))
  148. RemoveSpellEffect(GetInfoStruct()->spell_effects[i].spell);
  149. }
  150. }
  151. }
  152. void Entity::MapInfoStruct()
  153. {
  154. /** GETS **/
  155. get_string_funcs["name"] = l::bind(&InfoStruct::get_name, &info_struct);
  156. get_int8_funcs["class1"] = l::bind(&InfoStruct::get_class1, &info_struct);
  157. get_int8_funcs["class2"] = l::bind(&InfoStruct::get_class2, &info_struct);
  158. get_int8_funcs["class3"] = l::bind(&InfoStruct::get_class3, &info_struct);
  159. get_int8_funcs["race"] = l::bind(&InfoStruct::get_race, &info_struct);
  160. get_int8_funcs["gender"] = l::bind(&InfoStruct::get_gender, &info_struct);
  161. get_int16_funcs["level"] = l::bind(&InfoStruct::get_level, &info_struct);
  162. get_int16_funcs["max_level"] = l::bind(&InfoStruct::get_max_level, &info_struct);
  163. get_int16_funcs["effective_level"] = l::bind(&InfoStruct::get_effective_level, &info_struct);
  164. get_int16_funcs["tradeskill_level"] = l::bind(&InfoStruct::get_tradeskill_level, &info_struct);
  165. get_int16_funcs["tradeskill_max_level"] = l::bind(&InfoStruct::get_tradeskill_max_level, &info_struct);
  166. get_int8_funcs["cur_concentration"] = l::bind(&InfoStruct::get_cur_concentration, &info_struct);
  167. get_int8_funcs["max_concentration"] = l::bind(&InfoStruct::get_max_concentration, &info_struct);
  168. get_int8_funcs["max_concentration_base"] = l::bind(&InfoStruct::get_max_concentration_base, &info_struct);
  169. get_int16_funcs["cur_attack"] = l::bind(&InfoStruct::get_cur_attack, &info_struct);
  170. get_int16_funcs["attack_base"] = l::bind(&InfoStruct::get_attack_base, &info_struct);
  171. get_int16_funcs["cur_mitigation"] = l::bind(&InfoStruct::get_cur_mitigation, &info_struct);
  172. get_int16_funcs["max_mitigation"] = l::bind(&InfoStruct::get_max_mitigation, &info_struct);
  173. get_int16_funcs["mitigation_base"] = l::bind(&InfoStruct::get_mitigation_base, &info_struct);
  174. get_int16_funcs["avoidance_display"] = l::bind(&InfoStruct::get_avoidance_display, &info_struct);
  175. get_float_funcs["cur_avoidance"] = l::bind(&InfoStruct::get_cur_avoidance, &info_struct);
  176. get_int16_funcs["base_avoidance_pct"] = l::bind(&InfoStruct::get_base_avoidance_pct, &info_struct);
  177. get_int16_funcs["avoidance_base"] = l::bind(&InfoStruct::get_avoidance_base, &info_struct);
  178. get_int16_funcs["max_avoidance"] = l::bind(&InfoStruct::get_max_avoidance, &info_struct);
  179. get_float_funcs["parry"] = l::bind(&InfoStruct::get_parry, &info_struct);
  180. get_float_funcs["parry_base"] = l::bind(&InfoStruct::get_parry_base, &info_struct);
  181. get_float_funcs["deflection"] = l::bind(&InfoStruct::get_deflection, &info_struct);
  182. get_int16_funcs["deflection_base"] = l::bind(&InfoStruct::get_deflection_base, &info_struct);
  183. get_float_funcs["block"] = l::bind(&InfoStruct::get_block, &info_struct);
  184. get_int16_funcs["block_base"] = l::bind(&InfoStruct::get_block_base, &info_struct);
  185. get_float_funcs["str"] = l::bind(&InfoStruct::get_str, &info_struct);
  186. get_float_funcs["sta"] = l::bind(&InfoStruct::get_sta, &info_struct);
  187. get_float_funcs["agi"] = l::bind(&InfoStruct::get_agi, &info_struct);
  188. get_float_funcs["wis"] = l::bind(&InfoStruct::get_wis, &info_struct);
  189. get_float_funcs["intel"] = l::bind(&InfoStruct::get_intel, &info_struct);
  190. get_float_funcs["str_base"] = l::bind(&InfoStruct::get_str_base, &info_struct);
  191. get_float_funcs["sta_base"] = l::bind(&InfoStruct::get_sta_base, &info_struct);
  192. get_float_funcs["agi_base"] = l::bind(&InfoStruct::get_agi_base, &info_struct);
  193. get_float_funcs["wis_base"] = l::bind(&InfoStruct::get_wis_base, &info_struct);
  194. get_float_funcs["intel_base"] = l::bind(&InfoStruct::get_intel_base, &info_struct);
  195. get_int16_funcs["heat"] = l::bind(&InfoStruct::get_heat, &info_struct);
  196. get_int16_funcs["cold"] = l::bind(&InfoStruct::get_cold, &info_struct);
  197. get_int16_funcs["magic"] = l::bind(&InfoStruct::get_magic, &info_struct);
  198. get_int16_funcs["mental"] = l::bind(&InfoStruct::get_mental, &info_struct);
  199. get_int16_funcs["divine"] = l::bind(&InfoStruct::get_divine, &info_struct);
  200. get_int16_funcs["disease"] = l::bind(&InfoStruct::get_disease, &info_struct);
  201. get_int16_funcs["poison"] = l::bind(&InfoStruct::get_poison, &info_struct);
  202. get_int16_funcs["disease_base"] = l::bind(&InfoStruct::get_disease_base, &info_struct);
  203. get_int16_funcs["cold_base"] = l::bind(&InfoStruct::get_cold_base, &info_struct);
  204. get_int16_funcs["divine_base"] = l::bind(&InfoStruct::get_divine_base, &info_struct);
  205. get_int16_funcs["magic_base"] = l::bind(&InfoStruct::get_magic_base, &info_struct);
  206. get_int16_funcs["mental_base"] = l::bind(&InfoStruct::get_mental_base, &info_struct);
  207. get_int16_funcs["heat_base"] = l::bind(&InfoStruct::get_heat_base, &info_struct);
  208. get_int16_funcs["poison_base"] = l::bind(&InfoStruct::get_poison_base, &info_struct);
  209. get_int16_funcs["elemental_base"] = l::bind(&InfoStruct::get_elemental_base, &info_struct);
  210. get_int16_funcs["noxious_base"] = l::bind(&InfoStruct::get_noxious_base, &info_struct);
  211. get_int16_funcs["arcane_base"] = l::bind(&InfoStruct::get_arcane_base, &info_struct);
  212. get_int32_funcs["coin_copper"] = l::bind(&InfoStruct::get_coin_copper, &info_struct);
  213. get_int32_funcs["coin_silver"] = l::bind(&InfoStruct::get_coin_silver, &info_struct);
  214. get_int32_funcs["coin_gold"] = l::bind(&InfoStruct::get_coin_gold, &info_struct);
  215. get_int32_funcs["coin_plat"] = l::bind(&InfoStruct::get_coin_plat, &info_struct);
  216. get_int32_funcs["bank_coin_copper"] = l::bind(&InfoStruct::get_bank_coin_copper, &info_struct);
  217. get_int32_funcs["bank_coin_silver"] = l::bind(&InfoStruct::get_bank_coin_silver, &info_struct);
  218. get_int32_funcs["bank_coin_gold"] = l::bind(&InfoStruct::get_bank_coin_gold, &info_struct);
  219. get_int32_funcs["bank_coin_plat"] = l::bind(&InfoStruct::get_bank_coin_plat, &info_struct);
  220. get_int32_funcs["status_points"] = l::bind(&InfoStruct::get_status_points, &info_struct);
  221. get_string_funcs["deity"] = l::bind(&InfoStruct::get_deity, &info_struct);
  222. get_int32_funcs["weight"] = l::bind(&InfoStruct::get_weight, &info_struct);
  223. get_int32_funcs["max_weight"] = l::bind(&InfoStruct::get_max_weight, &info_struct);
  224. get_int8_funcs["tradeskill_class1"] = l::bind(&InfoStruct::get_tradeskill_class1, &info_struct);
  225. get_int8_funcs["tradeskill_class2"] = l::bind(&InfoStruct::get_tradeskill_class2, &info_struct);
  226. get_int8_funcs["tradeskill_class3"] = l::bind(&InfoStruct::get_tradeskill_class3, &info_struct);
  227. get_int32_funcs["account_age_base"] = l::bind(&InfoStruct::get_account_age_base, &info_struct);
  228. // int8 account_age_bonus_[19];
  229. get_int16_funcs["absorb"] = l::bind(&InfoStruct::get_absorb, &info_struct);
  230. get_int32_funcs["xp"] = l::bind(&InfoStruct::get_xp, &info_struct);
  231. get_int32_funcs["xp_needed"] = l::bind(&InfoStruct::get_xp_needed, &info_struct);
  232. get_float_funcs["xp_debt"] = l::bind(&InfoStruct::get_xp_debt, &info_struct);
  233. get_int16_funcs["xp_yellow"] = l::bind(&InfoStruct::get_xp_yellow, &info_struct);
  234. get_int16_funcs["xp_yellow_vitality_bar"] = l::bind(&InfoStruct::get_xp_yellow_vitality_bar, &info_struct);
  235. get_int16_funcs["xp_blue_vitality_bar"] = l::bind(&InfoStruct::get_xp_blue_vitality_bar, &info_struct);
  236. get_int16_funcs["xp_blue"] = l::bind(&InfoStruct::get_xp_blue, &info_struct);
  237. get_int32_funcs["ts_xp"] = l::bind(&InfoStruct::get_ts_xp, &info_struct);
  238. get_int32_funcs["ts_xp_needed"] = l::bind(&InfoStruct::get_ts_xp_needed, &info_struct);
  239. get_int16_funcs["tradeskill_exp_yellow"] = l::bind(&InfoStruct::get_tradeskill_exp_yellow, &info_struct);
  240. get_int16_funcs["tradeskill_exp_blue"] = l::bind(&InfoStruct::get_tradeskill_exp_blue, &info_struct);
  241. get_int32_funcs["flags"] = l::bind(&InfoStruct::get_flags, &info_struct);
  242. get_int32_funcs["flags2"] = l::bind(&InfoStruct::get_flags2, &info_struct);
  243. get_float_funcs["xp_vitality"] = l::bind(&InfoStruct::get_xp_vitality, &info_struct);
  244. get_float_funcs["tradeskill_xp_vitality"] = l::bind(&InfoStruct::get_tradeskill_xp_vitality, &info_struct);
  245. get_int16_funcs["mitigation_skill1"] = l::bind(&InfoStruct::get_mitigation_skill1, &info_struct);
  246. get_int16_funcs["mitigation_skill2"] = l::bind(&InfoStruct::get_mitigation_skill2, &info_struct);
  247. get_int16_funcs["mitigation_skill3"] = l::bind(&InfoStruct::get_mitigation_skill3, &info_struct);
  248. get_int16_funcs["mitigation_pve"] = l::bind(&InfoStruct::get_mitigation_pve, &info_struct);
  249. get_int16_funcs["mitigation_pvp"] = l::bind(&InfoStruct::get_mitigation_pvp, &info_struct);
  250. get_float_funcs["ability_modifier"] = l::bind(&InfoStruct::get_ability_modifier, &info_struct);
  251. get_float_funcs["critical_mitigation"] = l::bind(&InfoStruct::get_critical_mitigation, &info_struct);
  252. get_float_funcs["block_chance"] = l::bind(&InfoStruct::get_block_chance, &info_struct);
  253. get_float_funcs["uncontested_parry"] = l::bind(&InfoStruct::get_uncontested_parry, &info_struct);
  254. get_float_funcs["uncontested_block"] = l::bind(&InfoStruct::get_uncontested_block, &info_struct);
  255. get_float_funcs["uncontested_dodge"] = l::bind(&InfoStruct::get_uncontested_dodge, &info_struct);
  256. get_float_funcs["uncontested_riposte"] = l::bind(&InfoStruct::get_uncontested_riposte, &info_struct);
  257. get_float_funcs["crit_chance"] = l::bind(&InfoStruct::get_crit_chance, &info_struct);
  258. get_float_funcs["crit_bonus"] = l::bind(&InfoStruct::get_crit_bonus, &info_struct);
  259. get_float_funcs["potency"] = l::bind(&InfoStruct::get_potency, &info_struct);
  260. get_float_funcs["hate_mod"] = l::bind(&InfoStruct::get_hate_mod, &info_struct);
  261. get_float_funcs["reuse_speed"] = l::bind(&InfoStruct::get_reuse_speed, &info_struct);
  262. get_float_funcs["casting_speed"] = l::bind(&InfoStruct::get_casting_speed, &info_struct);
  263. get_float_funcs["recovery_speed"] = l::bind(&InfoStruct::get_recovery_speed, &info_struct);
  264. get_float_funcs["spell_reuse_speed"] = l::bind(&InfoStruct::get_spell_reuse_speed, &info_struct);
  265. get_float_funcs["spell_multi_attack"] = l::bind(&InfoStruct::get_spell_multi_attack, &info_struct);
  266. get_float_funcs["dps"] = l::bind(&InfoStruct::get_dps, &info_struct);
  267. get_float_funcs["dps_multiplier"] = l::bind(&InfoStruct::get_dps_multiplier, &info_struct);
  268. get_float_funcs["attackspeed"] = l::bind(&InfoStruct::get_attackspeed, &info_struct);
  269. get_float_funcs["haste"] = l::bind(&InfoStruct::get_haste, &info_struct);
  270. get_float_funcs["multi_attack"] = l::bind(&InfoStruct::get_multi_attack, &info_struct);
  271. get_float_funcs["flurry"] = l::bind(&InfoStruct::get_flurry, &info_struct);
  272. get_float_funcs["melee_ae"] = l::bind(&InfoStruct::get_melee_ae, &info_struct);
  273. get_float_funcs["strikethrough"] = l::bind(&InfoStruct::get_strikethrough, &info_struct);
  274. get_float_funcs["accuracy"] = l::bind(&InfoStruct::get_accuracy, &info_struct);
  275. get_float_funcs["offensivespeed"] = l::bind(&InfoStruct::get_offensivespeed, &info_struct);
  276. get_float_funcs["rain"] = l::bind(&InfoStruct::get_rain, &info_struct);
  277. get_float_funcs["wind"] = l::bind(&InfoStruct::get_wind, &info_struct);
  278. get_sint8_funcs["alignment"] = l::bind(&InfoStruct::get_alignment, &info_struct);
  279. get_int32_funcs["pet_id"] = l::bind(&InfoStruct::get_pet_id, &info_struct);
  280. get_string_funcs["pet_name"] = l::bind(&InfoStruct::get_pet_name, &info_struct);
  281. get_float_funcs["pet_health_pct"] = l::bind(&InfoStruct::get_pet_health_pct, &info_struct);
  282. get_float_funcs["pet_power_pct"] = l::bind(&InfoStruct::get_pet_power_pct, &info_struct);
  283. get_int8_funcs["pet_movement"] = l::bind(&InfoStruct::get_pet_movement, &info_struct);
  284. get_int8_funcs["pet_behavior"] = l::bind(&InfoStruct::get_pet_behavior, &info_struct);
  285. get_int32_funcs["vision"] = l::bind(&InfoStruct::get_vision, &info_struct);
  286. get_int8_funcs["breathe_underwater"] = l::bind(&InfoStruct::get_breathe_underwater, &info_struct);
  287. get_string_funcs["biography"] = l::bind(&InfoStruct::get_biography, &info_struct);
  288. get_float_funcs["drunk"] = l::bind(&InfoStruct::get_drunk, &info_struct);
  289. get_sint16_funcs["power_regen"] = l::bind(&InfoStruct::get_power_regen, &info_struct);
  290. get_sint16_funcs["hp_regen"] = l::bind(&InfoStruct::get_hp_regen, &info_struct);
  291. get_int8_funcs["power_regen_override"] = l::bind(&InfoStruct::get_power_regen_override, &info_struct);
  292. get_int8_funcs["hp_regen_override"] = l::bind(&InfoStruct::get_hp_regen_override, &info_struct);
  293. get_int8_funcs["water_type"] = l::bind(&InfoStruct::get_water_type, &info_struct);
  294. get_int8_funcs["flying_type"] = l::bind(&InfoStruct::get_flying_type, &info_struct);
  295. get_int8_funcs["no_interrupt"] = l::bind(&InfoStruct::get_no_interrupt, &info_struct);
  296. get_int8_funcs["interaction_flag"] = l::bind(&InfoStruct::get_interaction_flag, &info_struct);
  297. get_int8_funcs["tag1"] = l::bind(&InfoStruct::get_tag1, &info_struct);
  298. get_int16_funcs["mood"] = l::bind(&InfoStruct::get_mood, &info_struct);
  299. get_int32_funcs["range_last_attack_time"] = l::bind(&InfoStruct::get_range_last_attack_time, &info_struct);
  300. get_int32_funcs["primary_last_attack_time"] = l::bind(&InfoStruct::get_primary_last_attack_time, &info_struct);
  301. get_int32_funcs["secondary_last_attack_time"] = l::bind(&InfoStruct::get_secondary_last_attack_time, &info_struct);
  302. get_int16_funcs["primary_attack_delay"] = l::bind(&InfoStruct::get_primary_attack_delay, &info_struct);
  303. get_int16_funcs["secondary_attack_delay"] = l::bind(&InfoStruct::get_secondary_attack_delay, &info_struct);
  304. get_int16_funcs["ranged_attack_delay"] = l::bind(&InfoStruct::get_ranged_attack_delay, &info_struct);
  305. get_int8_funcs["primary_weapon_type"] = l::bind(&InfoStruct::get_primary_weapon_type, &info_struct);
  306. get_int8_funcs["secondary_weapon_type"] = l::bind(&InfoStruct::get_secondary_weapon_type, &info_struct);
  307. get_int8_funcs["ranged_weapon_type"] = l::bind(&InfoStruct::get_ranged_weapon_type, &info_struct);
  308. get_int32_funcs["primary_weapon_damage_low"] = l::bind(&InfoStruct::get_primary_weapon_damage_low, &info_struct);
  309. get_int32_funcs["primary_weapon_damage_high"] = l::bind(&InfoStruct::get_primary_weapon_damage_high, &info_struct);
  310. get_int32_funcs["secondary_weapon_damage_low"] = l::bind(&InfoStruct::get_secondary_weapon_damage_low, &info_struct);
  311. get_int32_funcs["secondary_weapon_damage_high"] = l::bind(&InfoStruct::get_secondary_weapon_damage_high, &info_struct);
  312. get_int32_funcs["ranged_weapon_damage_low"] = l::bind(&InfoStruct::get_ranged_weapon_damage_low, &info_struct);
  313. get_int32_funcs["ranged_weapon_damage_high"] = l::bind(&InfoStruct::get_ranged_weapon_damage_high, &info_struct);
  314. get_int8_funcs["wield_type"] = l::bind(&InfoStruct::get_wield_type, &info_struct);
  315. get_int8_funcs["attack_type"] = l::bind(&InfoStruct::get_attack_type, &info_struct);
  316. get_int16_funcs["primary_weapon_delay"] = l::bind(&InfoStruct::get_primary_weapon_delay, &info_struct);
  317. get_int16_funcs["secondary_weapon_delay"] = l::bind(&InfoStruct::get_secondary_weapon_delay, &info_struct);
  318. get_int16_funcs["ranged_weapon_delay"] = l::bind(&InfoStruct::get_ranged_weapon_delay, &info_struct);
  319. get_int8_funcs["override_primary_weapon"] = l::bind(&InfoStruct::get_override_primary_weapon, &info_struct);
  320. get_int8_funcs["override_secondary_weapon"] = l::bind(&InfoStruct::get_override_secondary_weapon, &info_struct);
  321. get_int8_funcs["override_ranged_weapon"] = l::bind(&InfoStruct::get_override_ranged_weapon, &info_struct);
  322. get_int8_funcs["friendly_target_npc"] = l::bind(&InfoStruct::get_friendly_target_npc, &info_struct);
  323. get_int32_funcs["last_claim_time"] = l::bind(&InfoStruct::get_last_claim_time, &info_struct);
  324. get_int8_funcs["engaged_encounter"] = l::bind(&InfoStruct::get_engaged_encounter, &info_struct);
  325. get_int8_funcs["first_world_login"] = l::bind(&InfoStruct::get_first_world_login, &info_struct);
  326. get_int8_funcs["reload_player_spells"] = l::bind(&InfoStruct::get_reload_player_spells, &info_struct);
  327. get_int8_funcs["group_loot_method"] = l::bind(&InfoStruct::get_group_loot_method, &info_struct);
  328. get_int8_funcs["group_loot_items_rarity"] = l::bind(&InfoStruct::get_group_loot_items_rarity, &info_struct);
  329. get_int8_funcs["group_auto_split"] = l::bind(&InfoStruct::get_group_auto_split, &info_struct);
  330. get_int8_funcs["group_default_yell"] = l::bind(&InfoStruct::get_group_default_yell, &info_struct);
  331. get_int8_funcs["group_autolock"] = l::bind(&InfoStruct::get_group_autolock, &info_struct);
  332. get_int8_funcs["group_lock_method"] = l::bind(&InfoStruct::get_group_lock_method, &info_struct);
  333. get_int8_funcs["group_solo_autolock"] = l::bind(&InfoStruct::get_group_solo_autolock, &info_struct);
  334. get_int8_funcs["group_auto_loot_method"] = l::bind(&InfoStruct::get_group_auto_loot_method, &info_struct);
  335. get_int8_funcs["assist_auto_attack"] = l::bind(&InfoStruct::get_assist_auto_attack, &info_struct);
  336. get_string_funcs["action_state"] = l::bind(&InfoStruct::get_action_state, &info_struct);
  337. get_string_funcs["combat_action_state"] = l::bind(&InfoStruct::get_combat_action_state, &info_struct);
  338. get_float_funcs["max_spell_reduction"] = l::bind(&InfoStruct::get_max_spell_reduction, &info_struct);
  339. get_int8_funcs["max_spell_reduction_override"] = l::bind(&InfoStruct::get_max_spell_reduction_override, &info_struct);
  340. /** SETS **/
  341. set_string_funcs["name"] = l::bind(&InfoStruct::set_name, &info_struct, l::_1);
  342. set_int8_funcs["class1"] = l::bind(&InfoStruct::set_class1, &info_struct, l::_1);
  343. set_int8_funcs["class2"] = l::bind(&InfoStruct::set_class2, &info_struct, l::_1);
  344. set_int8_funcs["class3"] = l::bind(&InfoStruct::set_class3, &info_struct, l::_1);
  345. set_int8_funcs["race"] = l::bind(&InfoStruct::set_race, &info_struct, l::_1);
  346. set_int8_funcs["gender"] = l::bind(&InfoStruct::set_gender, &info_struct, l::_1);
  347. set_int16_funcs["level"] = l::bind(&InfoStruct::set_level, &info_struct, l::_1);
  348. set_int16_funcs["max_level"] = l::bind(&InfoStruct::set_max_level, &info_struct, l::_1);
  349. set_int16_funcs["effective_level"] = l::bind(&InfoStruct::set_effective_level, &info_struct, l::_1);
  350. set_int16_funcs["tradeskill_level"] = l::bind(&InfoStruct::set_tradeskill_level, &info_struct, l::_1);
  351. set_int16_funcs["tradeskill_max_level"] = l::bind(&InfoStruct::set_tradeskill_max_level, &info_struct, l::_1);
  352. set_int8_funcs["cur_concentration"] = l::bind(&InfoStruct::set_cur_concentration, &info_struct, l::_1);
  353. set_int8_funcs["max_concentration"] = l::bind(&InfoStruct::set_max_concentration, &info_struct, l::_1);
  354. set_int8_funcs["max_concentration_base"] = l::bind(&InfoStruct::set_max_concentration_base, &info_struct, l::_1);
  355. set_int16_funcs["cur_attack"] = l::bind(&InfoStruct::set_cur_attack, &info_struct, l::_1);
  356. set_int16_funcs["attack_base"] = l::bind(&InfoStruct::set_attack_base, &info_struct, l::_1);
  357. set_int16_funcs["cur_mitigation"] = l::bind(&InfoStruct::set_cur_mitigation, &info_struct, l::_1);
  358. set_int16_funcs["max_mitigation"] = l::bind(&InfoStruct::set_max_mitigation, &info_struct, l::_1);
  359. set_int16_funcs["mitigation_base"] = l::bind(&InfoStruct::set_mitigation_base, &info_struct, l::_1);
  360. set_int16_funcs["avoidance_display"] = l::bind(&InfoStruct::set_avoidance_display, &info_struct, l::_1);
  361. set_float_funcs["cur_avoidance"] = l::bind(&InfoStruct::set_cur_avoidance, &info_struct, l::_1);
  362. set_int16_funcs["base_avoidance_pct"] = l::bind(&InfoStruct::set_base_avoidance_pct, &info_struct, l::_1);
  363. set_int16_funcs["avoidance_base"] = l::bind(&InfoStruct::set_avoidance_base, &info_struct, l::_1);
  364. set_int16_funcs["max_avoidance"] = l::bind(&InfoStruct::set_max_avoidance, &info_struct, l::_1);
  365. set_float_funcs["parry"] = l::bind(&InfoStruct::set_parry, &info_struct, l::_1);
  366. set_float_funcs["parry_base"] = l::bind(&InfoStruct::set_parry_base, &info_struct, l::_1);
  367. set_float_funcs["deflection"] = l::bind(&InfoStruct::set_deflection, &info_struct, l::_1);
  368. set_int16_funcs["deflection_base"] = l::bind(&InfoStruct::set_deflection_base, &info_struct, l::_1);
  369. set_float_funcs["block"] = l::bind(&InfoStruct::set_block, &info_struct, l::_1);
  370. set_int16_funcs["block_base"] = l::bind(&InfoStruct::set_block_base, &info_struct, l::_1);
  371. set_float_funcs["str"] = l::bind(&InfoStruct::set_str, &info_struct, l::_1);
  372. set_float_funcs["sta"] = l::bind(&InfoStruct::set_sta, &info_struct, l::_1);
  373. set_float_funcs["agi"] = l::bind(&InfoStruct::set_agi, &info_struct, l::_1);
  374. set_float_funcs["wis"] = l::bind(&InfoStruct::set_wis, &info_struct, l::_1);
  375. set_float_funcs["intel"] = l::bind(&InfoStruct::set_intel, &info_struct, l::_1);
  376. set_float_funcs["str_base"] = l::bind(&InfoStruct::set_str_base, &info_struct, l::_1);
  377. set_float_funcs["sta_base"] = l::bind(&InfoStruct::set_sta_base, &info_struct, l::_1);
  378. set_float_funcs["agi_base"] = l::bind(&InfoStruct::set_agi_base, &info_struct, l::_1);
  379. set_float_funcs["wis_base"] = l::bind(&InfoStruct::set_wis_base, &info_struct, l::_1);
  380. set_float_funcs["intel_base"] = l::bind(&InfoStruct::set_intel_base, &info_struct, l::_1);
  381. set_int16_funcs["heat"] = l::bind(&InfoStruct::set_heat, &info_struct, l::_1);
  382. set_int16_funcs["cold"] = l::bind(&InfoStruct::set_cold, &info_struct, l::_1);
  383. set_int16_funcs["magic"] = l::bind(&InfoStruct::set_magic, &info_struct, l::_1);
  384. set_int16_funcs["mental"] = l::bind(&InfoStruct::set_mental, &info_struct, l::_1);
  385. set_int16_funcs["divine"] = l::bind(&InfoStruct::set_divine, &info_struct, l::_1);
  386. set_int16_funcs["disease"] = l::bind(&InfoStruct::set_disease, &info_struct, l::_1);
  387. set_int16_funcs["poison"] = l::bind(&InfoStruct::set_poison, &info_struct, l::_1);
  388. set_int16_funcs["disease_base"] = l::bind(&InfoStruct::set_disease_base, &info_struct, l::_1);
  389. set_int16_funcs["cold_base"] = l::bind(&InfoStruct::set_cold_base, &info_struct, l::_1);
  390. set_int16_funcs["divine_base"] = l::bind(&InfoStruct::set_divine_base, &info_struct, l::_1);
  391. set_int16_funcs["magic_base"] = l::bind(&InfoStruct::set_magic_base, &info_struct, l::_1);
  392. set_int16_funcs["mental_base"] = l::bind(&InfoStruct::set_mental_base, &info_struct, l::_1);
  393. set_int16_funcs["heat_base"] = l::bind(&InfoStruct::set_heat_base, &info_struct, l::_1);
  394. set_int16_funcs["poison_base"] = l::bind(&InfoStruct::set_poison_base, &info_struct, l::_1);
  395. set_int16_funcs["elemental_base"] = l::bind(&InfoStruct::set_elemental_base, &info_struct, l::_1);
  396. set_int16_funcs["noxious_base"] = l::bind(&InfoStruct::set_noxious_base, &info_struct, l::_1);
  397. set_int16_funcs["arcane_base"] = l::bind(&InfoStruct::set_arcane_base, &info_struct, l::_1);
  398. set_int32_funcs["coin_copper"] = l::bind(&InfoStruct::set_coin_copper, &info_struct, l::_1);
  399. set_int32_funcs["coin_silver"] = l::bind(&InfoStruct::set_coin_silver, &info_struct, l::_1);
  400. set_int32_funcs["coin_gold"] = l::bind(&InfoStruct::set_coin_gold, &info_struct, l::_1);
  401. set_int32_funcs["coin_plat"] = l::bind(&InfoStruct::set_coin_plat, &info_struct, l::_1);
  402. set_int32_funcs["bank_coin_copper"] = l::bind(&InfoStruct::set_bank_coin_copper, &info_struct, l::_1);
  403. set_int32_funcs["bank_coin_silver"] = l::bind(&InfoStruct::set_bank_coin_silver, &info_struct, l::_1);
  404. set_int32_funcs["bank_coin_gold"] = l::bind(&InfoStruct::set_bank_coin_gold, &info_struct, l::_1);
  405. set_int32_funcs["bank_coin_plat"] = l::bind(&InfoStruct::set_bank_coin_plat, &info_struct, l::_1);
  406. set_int32_funcs["status_points"] = l::bind(&InfoStruct::set_status_points, &info_struct, l::_1);
  407. set_string_funcs["deity"] = l::bind(&InfoStruct::set_deity, &info_struct, l::_1);
  408. set_int32_funcs["weight"] = l::bind(&InfoStruct::set_weight, &info_struct, l::_1);
  409. set_int32_funcs["max_weight"] = l::bind(&InfoStruct::set_max_weight, &info_struct, l::_1);
  410. set_int8_funcs["tradeskill_class1"] = l::bind(&InfoStruct::set_tradeskill_class1, &info_struct, l::_1);
  411. set_int8_funcs["tradeskill_class2"] = l::bind(&InfoStruct::set_tradeskill_class2, &info_struct, l::_1);
  412. set_int8_funcs["tradeskill_class3"] = l::bind(&InfoStruct::set_tradeskill_class3, &info_struct, l::_1);
  413. set_int32_funcs["account_age_base"] = l::bind(&InfoStruct::set_account_age_base, &info_struct, l::_1);
  414. // int8 account_age_bonus_[19];
  415. set_int16_funcs["absorb"] = l::bind(&InfoStruct::set_absorb, &info_struct, l::_1);
  416. set_int32_funcs["xp"] = l::bind(&InfoStruct::set_xp, &info_struct, l::_1);
  417. set_int32_funcs["xp_needed"] = l::bind(&InfoStruct::set_xp_needed, &info_struct, l::_1);
  418. set_float_funcs["xp_debt"] = l::bind(&InfoStruct::set_xp_debt, &info_struct, l::_1);
  419. set_int16_funcs["xp_yellow"] = l::bind(&InfoStruct::set_xp_yellow, &info_struct, l::_1);
  420. set_int16_funcs["xp_yellow_vitality_bar"] = l::bind(&InfoStruct::set_xp_yellow_vitality_bar, &info_struct, l::_1);
  421. set_int16_funcs["xp_blue_vitality_bar"] = l::bind(&InfoStruct::set_xp_blue_vitality_bar, &info_struct, l::_1);
  422. set_int16_funcs["xp_blue"] = l::bind(&InfoStruct::set_xp_blue, &info_struct, l::_1);
  423. set_int32_funcs["ts_xp"] = l::bind(&InfoStruct::set_ts_xp, &info_struct, l::_1);
  424. set_int32_funcs["ts_xp_needed"] = l::bind(&InfoStruct::set_ts_xp_needed, &info_struct, l::_1);
  425. set_int16_funcs["tradeskill_exp_yellow"] = l::bind(&InfoStruct::set_tradeskill_exp_yellow, &info_struct, l::_1);
  426. set_int16_funcs["tradeskill_exp_blue"] = l::bind(&InfoStruct::set_tradeskill_exp_blue, &info_struct, l::_1);
  427. set_int32_funcs["flags"] = l::bind(&InfoStruct::set_flags, &info_struct, l::_1);
  428. set_int32_funcs["flags2"] = l::bind(&InfoStruct::set_flags2, &info_struct, l::_1);
  429. set_float_funcs["xp_vitality"] = l::bind(&InfoStruct::set_xp_vitality, &info_struct, l::_1);
  430. set_float_funcs["tradeskill_xp_vitality"] = l::bind(&InfoStruct::set_tradeskill_xp_vitality, &info_struct, l::_1);
  431. set_int16_funcs["mitigation_skill1"] = l::bind(&InfoStruct::set_mitigation_skill1, &info_struct, l::_1);
  432. set_int16_funcs["mitigation_skill2"] = l::bind(&InfoStruct::set_mitigation_skill2, &info_struct, l::_1);
  433. set_int16_funcs["mitigation_skill3"] = l::bind(&InfoStruct::set_mitigation_skill3, &info_struct, l::_1);
  434. set_int16_funcs["mitigation_pve"] = l::bind(&InfoStruct::set_mitigation_pve, &info_struct, l::_1);
  435. set_int16_funcs["mitigation_pvp"] = l::bind(&InfoStruct::set_mitigation_pvp, &info_struct, l::_1);
  436. set_float_funcs["ability_modifier"] = l::bind(&InfoStruct::set_ability_modifier, &info_struct, l::_1);
  437. set_float_funcs["critical_mitigation"] = l::bind(&InfoStruct::set_critical_mitigation, &info_struct, l::_1);
  438. set_float_funcs["block_chance"] = l::bind(&InfoStruct::set_block_chance, &info_struct, l::_1);
  439. set_float_funcs["uncontested_parry"] = l::bind(&InfoStruct::set_uncontested_parry, &info_struct, l::_1);
  440. set_float_funcs["uncontested_block"] = l::bind(&InfoStruct::set_uncontested_block, &info_struct, l::_1);
  441. set_float_funcs["uncontested_dodge"] = l::bind(&InfoStruct::set_uncontested_dodge, &info_struct, l::_1);
  442. set_float_funcs["uncontested_riposte"] = l::bind(&InfoStruct::set_uncontested_riposte, &info_struct, l::_1);
  443. set_float_funcs["crit_chance"] = l::bind(&InfoStruct::set_crit_chance, &info_struct, l::_1);
  444. set_float_funcs["crit_bonus"] = l::bind(&InfoStruct::set_crit_bonus, &info_struct, l::_1);
  445. set_float_funcs["potency"] = l::bind(&InfoStruct::set_potency, &info_struct, l::_1);
  446. set_float_funcs["hate_mod"] = l::bind(&InfoStruct::set_hate_mod, &info_struct, l::_1);
  447. set_float_funcs["reuse_speed"] = l::bind(&InfoStruct::set_reuse_speed, &info_struct, l::_1);
  448. set_float_funcs["casting_speed"] = l::bind(&InfoStruct::set_casting_speed, &info_struct, l::_1);
  449. set_float_funcs["recovery_speed"] = l::bind(&InfoStruct::set_recovery_speed, &info_struct, l::_1);
  450. set_float_funcs["spell_reuse_speed"] = l::bind(&InfoStruct::set_spell_reuse_speed, &info_struct, l::_1);
  451. set_float_funcs["spell_multi_attack"] = l::bind(&InfoStruct::set_spell_multi_attack, &info_struct, l::_1);
  452. set_float_funcs["dps"] = l::bind(&InfoStruct::set_dps, &info_struct, l::_1);
  453. set_float_funcs["dps_multiplier"] = l::bind(&InfoStruct::set_dps_multiplier, &info_struct, l::_1);
  454. set_float_funcs["attackspeed"] = l::bind(&InfoStruct::set_attackspeed, &info_struct, l::_1);
  455. set_float_funcs["haste"] = l::bind(&InfoStruct::set_haste, &info_struct, l::_1);
  456. set_float_funcs["multi_attack"] = l::bind(&InfoStruct::set_multi_attack, &info_struct, l::_1);
  457. set_float_funcs["flurry"] = l::bind(&InfoStruct::set_flurry, &info_struct, l::_1);
  458. set_float_funcs["melee_ae"] = l::bind(&InfoStruct::set_melee_ae, &info_struct, l::_1);
  459. set_float_funcs["strikethrough"] = l::bind(&InfoStruct::set_strikethrough, &info_struct, l::_1);
  460. set_float_funcs["accuracy"] = l::bind(&InfoStruct::set_accuracy, &info_struct, l::_1);
  461. set_float_funcs["offensivespeed"] = l::bind(&InfoStruct::set_offensivespeed, &info_struct, l::_1);
  462. set_float_funcs["rain"] = l::bind(&InfoStruct::set_rain, &info_struct, l::_1);
  463. set_float_funcs["wind"] = l::bind(&InfoStruct::set_wind, &info_struct, l::_1);
  464. set_sint8_funcs["alignment"] = l::bind(&InfoStruct::set_alignment, &info_struct, l::_1);
  465. set_int32_funcs["pet_id"] = l::bind(&InfoStruct::set_pet_id, &info_struct, l::_1);
  466. set_string_funcs["pet_name"] = l::bind(&InfoStruct::set_pet_name, &info_struct, l::_1);
  467. set_float_funcs["pet_health_pct"] = l::bind(&InfoStruct::set_pet_health_pct, &info_struct, l::_1);
  468. set_float_funcs["pet_power_pct"] = l::bind(&InfoStruct::set_pet_power_pct, &info_struct, l::_1);
  469. set_int8_funcs["pet_movement"] = l::bind(&InfoStruct::set_pet_movement, &info_struct, l::_1);
  470. set_int8_funcs["pet_behavior"] = l::bind(&InfoStruct::set_pet_behavior, &info_struct, l::_1);
  471. set_int32_funcs["vision"] = l::bind(&InfoStruct::set_vision, &info_struct, l::_1);
  472. set_int8_funcs["breathe_underwater"] = l::bind(&InfoStruct::set_breathe_underwater, &info_struct, l::_1);
  473. set_string_funcs["biography"] = l::bind(&InfoStruct::set_biography, &info_struct, l::_1);
  474. set_float_funcs["drunk"] = l::bind(&InfoStruct::set_drunk, &info_struct, l::_1);
  475. set_sint16_funcs["power_regen"] = l::bind(&InfoStruct::set_power_regen, &info_struct, l::_1);
  476. set_sint16_funcs["hp_regen"] = l::bind(&InfoStruct::set_hp_regen, &info_struct, l::_1);
  477. set_int8_funcs["power_regen_override"] = l::bind(&InfoStruct::set_power_regen_override, &info_struct, l::_1);
  478. set_int8_funcs["hp_regen_override"] = l::bind(&InfoStruct::set_hp_regen_override, &info_struct, l::_1);
  479. set_int8_funcs["water_type"] = l::bind(&InfoStruct::set_water_type, &info_struct, l::_1);
  480. set_int8_funcs["flying_type"] = l::bind(&InfoStruct::set_flying_type, &info_struct, l::_1);
  481. set_int8_funcs["no_interrupt"] = l::bind(&InfoStruct::set_no_interrupt, &info_struct, l::_1);
  482. set_int8_funcs["interaction_flag"] = l::bind(&InfoStruct::set_interaction_flag, &info_struct, l::_1);
  483. set_int8_funcs["tag1"] = l::bind(&InfoStruct::set_tag1, &info_struct, l::_1);
  484. set_int16_funcs["mood"] = l::bind(&InfoStruct::set_mood, &info_struct, l::_1);
  485. set_int32_funcs["range_last_attack_time"] = l::bind(&InfoStruct::set_range_last_attack_time, &info_struct, l::_1);
  486. set_int32_funcs["primary_last_attack_time"] = l::bind(&InfoStruct::set_primary_last_attack_time, &info_struct, l::_1);
  487. set_int32_funcs["secondary_last_attack_time"] = l::bind(&InfoStruct::set_secondary_last_attack_time, &info_struct, l::_1);
  488. set_int16_funcs["primary_attack_delay"] = l::bind(&InfoStruct::set_primary_attack_delay, &info_struct, l::_1);
  489. set_int16_funcs["secondary_attack_delay"] = l::bind(&InfoStruct::set_secondary_attack_delay, &info_struct, l::_1);
  490. set_int16_funcs["ranged_attack_delay"] = l::bind(&InfoStruct::set_ranged_attack_delay, &info_struct, l::_1);
  491. set_int8_funcs["primary_weapon_type"] = l::bind(&InfoStruct::set_primary_weapon_type, &info_struct, l::_1);
  492. set_int8_funcs["secondary_weapon_type"] = l::bind(&InfoStruct::set_secondary_weapon_type, &info_struct, l::_1);
  493. set_int8_funcs["ranged_weapon_type"] = l::bind(&InfoStruct::set_ranged_weapon_type, &info_struct, l::_1);
  494. set_int32_funcs["primary_weapon_damage_low"] = l::bind(&InfoStruct::set_primary_weapon_damage_low, &info_struct, l::_1);
  495. set_int32_funcs["primary_weapon_damage_high"] = l::bind(&InfoStruct::set_primary_weapon_damage_high, &info_struct, l::_1);
  496. set_int32_funcs["secondary_weapon_damage_low"] = l::bind(&InfoStruct::set_secondary_weapon_damage_low, &info_struct, l::_1);
  497. set_int32_funcs["secondary_weapon_damage_high"] = l::bind(&InfoStruct::set_secondary_weapon_damage_high, &info_struct, l::_1);
  498. set_int32_funcs["ranged_weapon_damage_low"] = l::bind(&InfoStruct::set_ranged_weapon_damage_low, &info_struct, l::_1);
  499. set_int32_funcs["ranged_weapon_damage_high"] = l::bind(&InfoStruct::set_ranged_weapon_damage_high, &info_struct, l::_1);
  500. set_int8_funcs["wield_type"] = l::bind(&InfoStruct::set_wield_type, &info_struct, l::_1);
  501. set_int8_funcs["attack_type"] = l::bind(&InfoStruct::set_attack_type, &info_struct, l::_1);
  502. set_int16_funcs["primary_weapon_delay"] = l::bind(&InfoStruct::set_primary_weapon_delay, &info_struct, l::_1);
  503. set_int16_funcs["secondary_weapon_delay"] = l::bind(&InfoStruct::set_secondary_weapon_delay, &info_struct, l::_1);
  504. set_int16_funcs["ranged_weapon_delay"] = l::bind(&InfoStruct::set_ranged_weapon_delay, &info_struct, l::_1);
  505. set_int8_funcs["override_primary_weapon"] = l::bind(&InfoStruct::set_override_primary_weapon, &info_struct, l::_1);
  506. set_int8_funcs["override_secondary_weapon"] = l::bind(&InfoStruct::set_override_secondary_weapon, &info_struct, l::_1);
  507. set_int8_funcs["override_ranged_weapon"] = l::bind(&InfoStruct::set_override_ranged_weapon, &info_struct, l::_1);
  508. set_int8_funcs["friendly_target_npc"] = l::bind(&InfoStruct::set_friendly_target_npc, &info_struct, l::_1);
  509. set_int32_funcs["last_claim_time"] = l::bind(&InfoStruct::set_last_claim_time, &info_struct, l::_1);
  510. set_int8_funcs["engaged_encounter"] = l::bind(&InfoStruct::set_engaged_encounter, &info_struct, l::_1);
  511. set_int8_funcs["first_world_login"] = l::bind(&InfoStruct::set_first_world_login, &info_struct, l::_1);
  512. set_int8_funcs["reload_player_spells"] = l::bind(&InfoStruct::set_reload_player_spells, &info_struct, l::_1);
  513. set_int8_funcs["group_loot_method"] = l::bind(&InfoStruct::set_group_loot_method, &info_struct, l::_1);
  514. set_int8_funcs["group_loot_items_rarity"] = l::bind(&InfoStruct::set_group_loot_items_rarity, &info_struct, l::_1);
  515. set_int8_funcs["group_auto_split"] = l::bind(&InfoStruct::set_group_auto_split, &info_struct, l::_1);
  516. set_int8_funcs["group_default_yell"] = l::bind(&InfoStruct::set_group_default_yell, &info_struct, l::_1);
  517. set_int8_funcs["group_autolock"] = l::bind(&InfoStruct::set_group_autolock, &info_struct, l::_1);
  518. set_int8_funcs["group_lock_method"] = l::bind(&InfoStruct::set_group_lock_method, &info_struct, l::_1);
  519. set_int8_funcs["group_solo_autolock"] = l::bind(&InfoStruct::set_group_solo_autolock, &info_struct, l::_1);
  520. set_int8_funcs["group_auto_loot_method"] = l::bind(&InfoStruct::set_group_auto_loot_method, &info_struct, l::_1);
  521. set_int8_funcs["assist_auto_attack"] = l::bind(&InfoStruct::set_assist_auto_attack, &info_struct, l::_1);
  522. set_string_funcs["action_state"] = l::bind(&InfoStruct::set_action_state, &info_struct, l::_1);
  523. set_string_funcs["combat_action_state"] = l::bind(&InfoStruct::set_combat_action_state, &info_struct, l::_1);
  524. set_float_funcs["max_spell_reduction"] = l::bind(&InfoStruct::set_max_spell_reduction, &info_struct, l::_1);
  525. set_int8_funcs["max_spell_reduction_override"] = l::bind(&InfoStruct::set_max_spell_reduction_override, &info_struct, l::_1);
  526. }
  527. bool Entity::HasMoved(bool include_heading){
  528. if(GetX() == last_x && GetY() == last_y && GetZ() == last_z && ((!include_heading) || (include_heading && GetHeading() == last_heading)))
  529. return false;
  530. bool ret_val = true;
  531. if(last_x == -1 && last_y == -1 && last_z == -1 && last_heading == -1){
  532. ret_val = false;
  533. }
  534. last_x = GetX();
  535. last_y = GetY();
  536. last_z = GetZ();
  537. last_heading = GetHeading();
  538. return ret_val;
  539. }
  540. int16 Entity::GetStr(){
  541. return GetInfoStruct()->get_str();
  542. }
  543. int16 Entity::GetSta(){
  544. return GetInfoStruct()->get_sta();
  545. }
  546. int16 Entity::GetInt(){
  547. return GetInfoStruct()->get_intel();
  548. }
  549. int16 Entity::GetWis(){
  550. return GetInfoStruct()->get_wis();
  551. }
  552. int16 Entity::GetAgi(){
  553. return GetInfoStruct()->get_agi();
  554. }
  555. int16 Entity::GetPrimaryStat(){
  556. int8 base_class = classes.GetBaseClass(GetAdventureClass());
  557. if (base_class == FIGHTER)
  558. return GetInfoStruct()->get_str();
  559. else if (base_class == PRIEST)
  560. return GetInfoStruct()->get_wis();
  561. else if (base_class == MAGE)
  562. return GetInfoStruct()->get_intel();
  563. else
  564. return GetInfoStruct()->get_agi();
  565. }
  566. int16 Entity::GetHeatResistance(){
  567. return GetInfoStruct()->get_heat();
  568. }
  569. int16 Entity::GetColdResistance(){
  570. return GetInfoStruct()->get_cold();
  571. }
  572. int16 Entity::GetMagicResistance(){
  573. return GetInfoStruct()->get_magic();
  574. }
  575. int16 Entity::GetMentalResistance(){
  576. return GetInfoStruct()->get_mental();
  577. }
  578. int16 Entity::GetDivineResistance(){
  579. return GetInfoStruct()->get_divine();
  580. }
  581. int16 Entity::GetDiseaseResistance(){
  582. return GetInfoStruct()->get_disease();
  583. }
  584. int16 Entity::GetPoisonResistance(){
  585. return GetInfoStruct()->get_poison();
  586. }
  587. int8 Entity::GetConcentrationCurrent() {
  588. return GetInfoStruct()->get_cur_concentration();
  589. }
  590. int8 Entity::GetConcentrationMax() {
  591. return GetInfoStruct()->get_max_concentration();
  592. }
  593. int16 Entity::GetStrBase(){
  594. return GetInfoStruct()->get_str_base();
  595. }
  596. int16 Entity::GetStaBase(){
  597. return GetInfoStruct()->get_sta_base();
  598. }
  599. int16 Entity::GetIntBase(){
  600. return GetInfoStruct()->get_intel_base();
  601. }
  602. int16 Entity::GetWisBase(){
  603. return GetInfoStruct()->get_wis_base();
  604. }
  605. int16 Entity::GetAgiBase(){
  606. return GetInfoStruct()->get_agi_base();
  607. }
  608. int16 Entity::GetHeatResistanceBase(){
  609. return GetInfoStruct()->get_heat_base();
  610. }
  611. int16 Entity::GetColdResistanceBase(){
  612. return GetInfoStruct()->get_cold_base();
  613. }
  614. int16 Entity::GetMagicResistanceBase(){
  615. return GetInfoStruct()->get_magic_base();
  616. }
  617. int16 Entity::GetMentalResistanceBase(){
  618. return GetInfoStruct()->get_mental_base();
  619. }
  620. int16 Entity::GetDivineResistanceBase(){
  621. return GetInfoStruct()->get_divine_base();
  622. }
  623. int16 Entity::GetDiseaseResistanceBase(){
  624. return GetInfoStruct()->get_disease_base();
  625. }
  626. int16 Entity::GetPoisonResistanceBase(){
  627. return GetInfoStruct()->get_poison_base();
  628. }
  629. sint8 Entity::GetAlignment(){
  630. return GetInfoStruct()->get_alignment();
  631. }
  632. bool Entity::IsCasting(){
  633. return casting;
  634. }
  635. void Entity::IsCasting(bool val){
  636. casting = val;
  637. }
  638. int32 Entity::GetRangeLastAttackTime(){
  639. return GetInfoStruct()->get_range_last_attack_time();
  640. }
  641. void Entity::SetRangeLastAttackTime(int32 time){
  642. GetInfoStruct()->set_range_last_attack_time(time);
  643. }
  644. int16 Entity::GetRangeAttackDelay(){
  645. return GetInfoStruct()->get_ranged_attack_delay();
  646. // if(IsPlayer()){
  647. // Item* item = ((Player*)this)->GetEquipmentList()->GetItem(EQ2_RANGE_SLOT);
  648. // if(item && item->IsRanged())
  649. // return item->ranged_info->weapon_info.delay*100;
  650. // }
  651. // return 3000;
  652. }
  653. int32 Entity::GetPrimaryLastAttackTime(){
  654. return GetInfoStruct()->get_primary_last_attack_time();
  655. }
  656. int16 Entity::GetPrimaryAttackDelay(){
  657. return GetInfoStruct()->get_primary_attack_delay();
  658. }
  659. void Entity::SetPrimaryAttackDelay(int16 new_delay){
  660. GetInfoStruct()->set_primary_attack_delay(new_delay);
  661. }
  662. void Entity::SetPrimaryLastAttackTime(int32 new_time){
  663. GetInfoStruct()->set_primary_last_attack_time(new_time);
  664. }
  665. int32 Entity::GetSecondaryLastAttackTime(){
  666. return GetInfoStruct()->get_secondary_last_attack_time();
  667. }
  668. int16 Entity::GetSecondaryAttackDelay(){
  669. return GetInfoStruct()->get_secondary_attack_delay();
  670. }
  671. void Entity::SetSecondaryAttackDelay(int16 new_delay){
  672. GetInfoStruct()->set_secondary_attack_delay(new_delay);
  673. }
  674. void Entity::SetSecondaryLastAttackTime(int32 new_time){
  675. GetInfoStruct()->set_secondary_last_attack_time(new_time);
  676. }
  677. void Entity::GetWeaponDamage(Item* item, int32* low_damage, int32* high_damage) {
  678. if(!low_damage || !high_damage)
  679. return;
  680. int32 selected_low_dmg = item->weapon_info->damage_low3;
  681. int32 selected_high_dmg = item->weapon_info->damage_high3;
  682. if(IsPlayer()) {
  683. float skillMultiplier = rule_manager.GetGlobalRule(R_Player, LevelMasterySkillMultiplier)->GetFloat();
  684. if(skillMultiplier <= 0.0f) {
  685. skillMultiplier = 1.0f;
  686. }
  687. int32 min_level_skill = (int32)((float)item->generic_info.adventure_default_level*skillMultiplier);
  688. int32 rec_level_skill = (int32)((float)item->details.recommended_level*skillMultiplier);
  689. if(min_level_skill > rec_level_skill) {
  690. rec_level_skill = rec_level_skill;
  691. }
  692. Skill* masterySkill = ((Player*)this)->skill_list.GetSkill(item->generic_info.skill_req2);
  693. if(masterySkill) {
  694. LogWrite(PLAYER__ERROR, 0, "Player", "Item has skill %s %u requirement", masterySkill->name.data.c_str(), item->generic_info.skill_req2);
  695. int16 skillID = master_item_list.GetItemStatIDByName(masterySkill->name.data);
  696. int32 skill_chance = (int32)CalculateSkillWithBonus((char*)masterySkill->name.data.c_str(), master_item_list.GetItemStatIDByName(masterySkill->name.data), false);
  697. if(skill_chance >= min_level_skill && skill_chance < rec_level_skill) {
  698. int32 diff_skill = rec_level_skill - skill_chance;
  699. if(diff_skill < 1) {
  700. selected_low_dmg = item->weapon_info->damage_low2;
  701. selected_high_dmg = item->weapon_info->damage_high2;
  702. }
  703. else {
  704. diff_skill += 1;
  705. double logResult = log((double)diff_skill) / skillMultiplier;
  706. if(logResult > 1.0f) {
  707. logResult = .95f;
  708. }
  709. selected_low_dmg = (int32)((double)item->weapon_info->damage_low2 * (1.0 - logResult));
  710. if(selected_low_dmg < item->weapon_info->damage_low3) {
  711. selected_low_dmg = item->weapon_info->damage_low3;
  712. }
  713. selected_high_dmg = (int32)((double)item->weapon_info->damage_high2 * (1.0 - logResult));
  714. if(selected_high_dmg < item->weapon_info->damage_high3) {
  715. selected_high_dmg = item->weapon_info->damage_high3;
  716. }
  717. }
  718. }
  719. else if(skill_chance >= rec_level_skill) {
  720. selected_low_dmg = item->weapon_info->damage_low2;
  721. selected_high_dmg = item->weapon_info->damage_high2;
  722. }
  723. }
  724. }
  725. *low_damage = selected_low_dmg;
  726. *high_damage = selected_high_dmg;
  727. }
  728. void Entity::ChangePrimaryWeapon(){
  729. if(GetInfoStruct()->get_override_primary_weapon()) {
  730. return;
  731. }
  732. int32 str_offset_dmg = GetStrengthDamage();
  733. Item* item = equipment_list.GetItem(EQ2_PRIMARY_SLOT);
  734. if(item && item->details.item_id > 0 && item->IsWeapon()){
  735. int32 selected_low_dmg = item->weapon_info->damage_low3;
  736. int32 selected_high_dmg = item->weapon_info->damage_high3;
  737. GetWeaponDamage(item, &selected_low_dmg, &selected_high_dmg);
  738. GetInfoStruct()->set_primary_weapon_delay(item->weapon_info->delay * 100);
  739. GetInfoStruct()->set_primary_weapon_damage_low(selected_low_dmg + str_offset_dmg);
  740. GetInfoStruct()->set_primary_weapon_damage_high(selected_high_dmg + str_offset_dmg);
  741. GetInfoStruct()->set_primary_weapon_type(item->GetWeaponType());
  742. GetInfoStruct()->set_wield_type(item->weapon_info->wield_type);
  743. }
  744. else{
  745. int16 effective_level = GetInfoStruct()->get_effective_level();
  746. if ( !effective_level )
  747. effective_level = GetLevel();
  748. GetInfoStruct()->set_primary_weapon_delay(2000);
  749. GetInfoStruct()->set_primary_weapon_damage_low((int32)1 + (effective_level * .2) + str_offset_dmg);
  750. GetInfoStruct()->set_primary_weapon_damage_high((int32)(5 + effective_level * (effective_level/5)) + str_offset_dmg);
  751. if(GetInfoStruct()->get_attack_type() > 0) {
  752. GetInfoStruct()->set_primary_weapon_type(GetInfoStruct()->get_attack_type());
  753. }
  754. else {
  755. GetInfoStruct()->set_primary_weapon_type(1);
  756. }
  757. GetInfoStruct()->set_wield_type(2);
  758. }
  759. }
  760. void Entity::ChangeSecondaryWeapon(){
  761. if(GetInfoStruct()->get_override_secondary_weapon()) {
  762. return;
  763. }
  764. int32 str_offset_dmg = GetStrengthDamage();
  765. Item* item = equipment_list.GetItem(EQ2_SECONDARY_SLOT);
  766. if(item && item->details.item_id > 0 && item->IsWeapon()){
  767. int32 selected_low_dmg = item->weapon_info->damage_low3;
  768. int32 selected_high_dmg = item->weapon_info->damage_high3;
  769. GetWeaponDamage(item, &selected_low_dmg, &selected_high_dmg);
  770. GetInfoStruct()->set_secondary_weapon_delay(item->weapon_info->delay * 100);
  771. GetInfoStruct()->set_secondary_weapon_damage_low(selected_low_dmg + str_offset_dmg);
  772. GetInfoStruct()->set_secondary_weapon_damage_high(selected_high_dmg + str_offset_dmg);
  773. GetInfoStruct()->set_secondary_weapon_type(item->GetWeaponType());
  774. }
  775. else{
  776. int16 effective_level = GetInfoStruct()->get_effective_level();
  777. if ( !effective_level )
  778. effective_level = GetLevel();
  779. GetInfoStruct()->set_secondary_weapon_delay(2000);
  780. GetInfoStruct()->set_secondary_weapon_damage_low((int32)(1 + effective_level * .2) + str_offset_dmg);
  781. GetInfoStruct()->set_secondary_weapon_damage_high((int32)(5 + effective_level * (effective_level/6)) + str_offset_dmg);
  782. GetInfoStruct()->set_secondary_weapon_type(1);
  783. }
  784. }
  785. void Entity::ChangeRangedWeapon(){
  786. if(GetInfoStruct()->get_override_ranged_weapon()) {
  787. return;
  788. }
  789. int32 str_offset_dmg = GetStrengthDamage();
  790. Item* item = equipment_list.GetItem(EQ2_RANGE_SLOT);
  791. if(item && item->details.item_id > 0 && item->IsRanged()){
  792. GetInfoStruct()->set_ranged_weapon_delay(item->ranged_info->weapon_info.delay*100);
  793. GetInfoStruct()->set_ranged_weapon_damage_low(item->ranged_info->weapon_info.damage_low3 + str_offset_dmg);
  794. GetInfoStruct()->set_ranged_weapon_damage_high(item->ranged_info->weapon_info.damage_high3 + str_offset_dmg);
  795. GetInfoStruct()->set_ranged_weapon_type(item->GetWeaponType());
  796. }
  797. }
  798. void Entity::UpdateWeapons() {
  799. ChangePrimaryWeapon();
  800. ChangeSecondaryWeapon();
  801. ChangeRangedWeapon();
  802. }
  803. int32 Entity::GetStrengthDamage() {
  804. int32 str_offset = 1;
  805. if(IsNPC()) {
  806. str_offset = rule_manager.GetGlobalRule(R_Combat, StrengthNPC)->GetInt32();
  807. if(str_offset < 1)
  808. str_offset = 1;
  809. }
  810. else {
  811. str_offset = rule_manager.GetGlobalRule(R_Combat, StrengthOther)->GetInt32();
  812. if(str_offset < 1)
  813. str_offset = 1;
  814. }
  815. int32 str_offset_dmg = (int32)((GetInfoStruct()->get_str() / str_offset));
  816. return str_offset_dmg;
  817. }
  818. int32 Entity::GetPrimaryWeaponMinDamage(){
  819. return GetInfoStruct()->get_primary_weapon_damage_low();
  820. }
  821. int32 Entity::GetPrimaryWeaponMaxDamage(){
  822. return GetInfoStruct()->get_primary_weapon_damage_high();
  823. }
  824. int16 Entity::GetPrimaryWeaponDelay(){
  825. return GetInfoStruct()->get_primary_weapon_delay();
  826. }
  827. int16 Entity::GetSecondaryWeaponDelay(){
  828. return GetInfoStruct()->get_secondary_weapon_delay();
  829. }
  830. int32 Entity::GetSecondaryWeaponMinDamage(){
  831. return GetInfoStruct()->get_secondary_weapon_damage_low();
  832. }
  833. int32 Entity::GetSecondaryWeaponMaxDamage(){
  834. return GetInfoStruct()->get_secondary_weapon_damage_high();
  835. }
  836. int8 Entity::GetPrimaryWeaponType(){
  837. return GetInfoStruct()->get_primary_weapon_type();
  838. }
  839. int8 Entity::GetSecondaryWeaponType(){
  840. return GetInfoStruct()->get_secondary_weapon_type();
  841. }
  842. int32 Entity::GetRangedWeaponMinDamage(){
  843. return GetInfoStruct()->get_ranged_weapon_damage_low();
  844. }
  845. int32 Entity::GetRangedWeaponMaxDamage(){
  846. return GetInfoStruct()->get_ranged_weapon_damage_high();
  847. }
  848. int8 Entity::GetRangedWeaponType(){
  849. return GetInfoStruct()->get_ranged_weapon_type();
  850. }
  851. bool Entity::IsDualWield(){
  852. return GetInfoStruct()->get_wield_type() == 1;
  853. }
  854. int8 Entity::GetWieldType(){
  855. return GetInfoStruct()->get_wield_type();
  856. }
  857. int16 Entity::GetRangeWeaponDelay(){
  858. return GetInfoStruct()->get_ranged_weapon_delay();
  859. }
  860. void Entity::SetRangeWeaponDelay(int16 new_delay){
  861. GetInfoStruct()->set_ranged_weapon_delay(new_delay * 100);
  862. }
  863. void Entity::SetRangeAttackDelay(int16 new_delay){
  864. GetInfoStruct()->set_ranged_attack_delay(new_delay);
  865. }
  866. void Entity::SetPrimaryWeaponDelay(int16 new_delay){
  867. GetInfoStruct()->set_primary_weapon_delay(new_delay * 100);
  868. }
  869. void Entity::SetSecondaryWeaponDelay(int16 new_delay){
  870. GetInfoStruct()->set_primary_weapon_delay(new_delay * 100);
  871. }
  872. bool Entity::BehindTarget(Spawn* target){
  873. return BehindSpawn(target, GetX(), GetZ());
  874. }
  875. bool Entity::FlankingTarget(Spawn* target) {
  876. return IsFlankingSpawn(target, GetX(), GetZ());
  877. }
  878. float Entity::GetDodgeChance(){
  879. float ret = 0;
  880. return ret;
  881. }
  882. bool Entity::EngagedInCombat(){
  883. return in_combat;
  884. }
  885. void Entity::InCombat(bool val){
  886. bool changeCombatState = false;
  887. if((in_combat && !val) || (!in_combat && val))
  888. changeCombatState = true;
  889. in_combat = val;
  890. bool update_regen = false;
  891. if(GetInfoStruct()->get_engaged_encounter()) {
  892. if(!IsAggroed() || !IsEngagedInEncounter()) {
  893. GetInfoStruct()->set_engaged_encounter(0);
  894. update_regen = true;
  895. }
  896. }
  897. if(changeCombatState || update_regen)
  898. SetRegenValues((GetInfoStruct()->get_effective_level() > 0) ? GetInfoStruct()->get_effective_level() : GetLevel());
  899. }
  900. void Entity::DoRegenUpdate(){
  901. if(!Alive() || GetHP() == 0)//dead
  902. return;
  903. sint32 hp = GetHP();
  904. sint32 power = GetPower();
  905. if(hp < GetTotalHP()){
  906. sint16 temp = GetInfoStruct()->get_hp_regen();
  907. if((hp + temp) > GetTotalHP())
  908. SetHP(GetTotalHP());
  909. else
  910. SetHP(hp + temp);
  911. }
  912. if(GetPower() < GetTotalPower()){
  913. sint16 temp = GetInfoStruct()->get_power_regen();
  914. if((power + temp) > GetTotalPower())
  915. SetPower(GetTotalPower());
  916. else
  917. SetPower(power + temp);
  918. }
  919. }
  920. void Entity::AddMaintainedSpell(LuaSpell* luaspell){
  921. if (!luaspell)
  922. return;
  923. Spell* spell = luaspell->spell;
  924. MaintainedEffects* effect = GetFreeMaintainedSpellSlot();
  925. if (effect){
  926. MMaintainedSpells.writelock(__FUNCTION__, __LINE__);
  927. effect->spell = luaspell;
  928. effect->spell_id = spell->GetSpellData()->id;
  929. LogWrite(NPC__SPELLS, 5, "NPC", "AddMaintainedSpell Spell ID: %u, Concentration: %u", spell->GetSpellData()->id, spell->GetSpellData()->req_concentration);
  930. effect->conc_used = spell->GetSpellData()->req_concentration;
  931. effect->total_time = spell->GetSpellDuration() / 10;
  932. effect->tier = spell->GetSpellData()->tier;
  933. if (spell->GetSpellData()->duration_until_cancel)
  934. effect->expire_timestamp = 0xFFFFFFFF;
  935. else
  936. effect->expire_timestamp = Timer::GetCurrentTime2() + (spell->GetSpellDuration() * 100);
  937. MMaintainedSpells.releasewritelock(__FUNCTION__, __LINE__);
  938. }
  939. }
  940. void Entity::AddSpellEffect(LuaSpell* luaspell, int32 override_expire_time){
  941. if (!luaspell || !luaspell->caster)
  942. return;
  943. Spell* spell = luaspell->spell;
  944. SpellEffects* old_effect = GetSpellEffect(spell->GetSpellID(), luaspell->caster);
  945. SpellEffects* effect = 0;
  946. if (old_effect){
  947. GetZone()->RemoveTargetFromSpell(old_effect->spell, this);
  948. RemoveSpellEffect(old_effect->spell);
  949. }
  950. LogWrite(SPELL__DEBUG, 0, "Spell", "%s AddSpellEffect %s (%u).", spell->GetName(), GetName(), GetID());
  951. if(!effect)
  952. effect = GetFreeSpellEffectSlot();
  953. if(effect){
  954. MSpellEffects.writelock(__FUNCTION__, __LINE__);
  955. effect->spell = luaspell;
  956. effect->spell_id = spell->GetSpellData()->id;
  957. effect->caster = luaspell->caster;
  958. effect->total_time = spell->GetSpellDuration()/10;
  959. if (spell->GetSpellData()->duration_until_cancel)
  960. effect->expire_timestamp = 0xFFFFFFFF;
  961. else if(override_expire_time)
  962. effect->expire_timestamp = Timer::GetCurrentTime2() + override_expire_time;
  963. else
  964. effect->expire_timestamp = Timer::GetCurrentTime2() + (spell->GetSpellDuration()*100);
  965. effect->icon = spell->GetSpellData()->icon;
  966. effect->icon_backdrop = spell->GetSpellData()->icon_backdrop;
  967. effect->tier = spell->GetSpellTier();
  968. MSpellEffects.releasewritelock(__FUNCTION__, __LINE__);
  969. changed = true;
  970. info_changed = true;
  971. AddChangedZoneSpawn();
  972. if(luaspell->caster && luaspell->caster->IsPlayer() && luaspell->caster != this)
  973. ((Player*)luaspell->caster)->GetClient()->TriggerSpellSave();
  974. }
  975. }
  976. void Entity::RemoveMaintainedSpell(LuaSpell* luaspell){
  977. if (!luaspell)
  978. return;
  979. bool found = false;
  980. MMaintainedSpells.writelock(__FUNCTION__, __LINE__);
  981. for (int i = 0; i<30; i++){
  982. // If we already found the spell then we are bumping all other up one so there are no gaps
  983. // This check needs to be first so found can never be true on the first iteration (i = 0)
  984. if (found) {
  985. GetInfoStruct()->maintained_effects[i].slot_pos = i - 1;
  986. GetInfoStruct()->maintained_effects[i - 1] = GetInfoStruct()->maintained_effects[i];
  987. }
  988. // Compare spells, if we found a match set the found flag
  989. if (GetInfoStruct()->maintained_effects[i].spell == luaspell)
  990. found = true;
  991. }
  992. // if we found the spell in the array then we need to set the last element to empty
  993. if (found) {
  994. memset(&GetInfoStruct()->maintained_effects[29], 0, sizeof(MaintainedEffects));
  995. GetInfoStruct()->maintained_effects[29].spell_id = 0xFFFFFFFF;
  996. GetInfoStruct()->maintained_effects[29].icon = 0xFFFF;
  997. GetInfoStruct()->maintained_effects[29].spell = nullptr;
  998. }
  999. MMaintainedSpells.releasewritelock(__FUNCTION__, __LINE__);
  1000. }
  1001. void Entity::RemoveSpellEffect(LuaSpell* spell) {
  1002. bool found = false;
  1003. MSpellEffects.writelock(__FUNCTION__, __LINE__);
  1004. for(int i=0;i<45;i++) {
  1005. if (found) {
  1006. GetInfoStruct()->spell_effects[i-1] = GetInfoStruct()->spell_effects[i];
  1007. }
  1008. if (GetInfoStruct()->spell_effects[i].spell == spell)
  1009. found = true;
  1010. }
  1011. if (found) {
  1012. LogWrite(SPELL__DEBUG, 0, "Spell", "%s RemoveSpellEffect %s (%u).", spell->spell->GetName(), GetName(), GetID());
  1013. GetZone()->GetSpellProcess()->RemoveTargetFromSpell(spell, this);
  1014. memset(&GetInfoStruct()->spell_effects[44], 0, sizeof(SpellEffects));
  1015. GetInfoStruct()->spell_effects[44].spell_id = 0xFFFFFFFF;
  1016. changed = true;
  1017. info_changed = true;
  1018. AddChangedZoneSpawn();
  1019. if(IsPlayer()) {
  1020. ((Player*)this)->SetCharSheetChanged(true);
  1021. }
  1022. }
  1023. MSpellEffects.releasewritelock(__FUNCTION__, __LINE__);
  1024. }
  1025. MaintainedEffects* Entity::GetFreeMaintainedSpellSlot(){
  1026. MaintainedEffects* ret = 0;
  1027. InfoStruct* info = GetInfoStruct();
  1028. MMaintainedSpells.readlock(__FUNCTION__, __LINE__);
  1029. for (int i = 0; i<NUM_MAINTAINED_EFFECTS; i++){
  1030. if (info->maintained_effects[i].spell_id == 0xFFFFFFFF){
  1031. ret = &info->maintained_effects[i];
  1032. ret->spell_id = 0;
  1033. ret->slot_pos = i;
  1034. break;
  1035. }
  1036. }
  1037. MMaintainedSpells.releasereadlock(__FUNCTION__, __LINE__);
  1038. return ret;
  1039. }
  1040. MaintainedEffects* Entity::GetMaintainedSpell(int32 spell_id){
  1041. MaintainedEffects* ret = 0;
  1042. InfoStruct* info = GetInfoStruct();
  1043. MMaintainedSpells.readlock(__FUNCTION__, __LINE__);
  1044. for (int i = 0; i<NUM_MAINTAINED_EFFECTS; i++){
  1045. if (info->maintained_effects[i].spell_id == spell_id){
  1046. ret = &info->maintained_effects[i];
  1047. break;
  1048. }
  1049. }
  1050. MMaintainedSpells.releasereadlock(__FUNCTION__, __LINE__);
  1051. return ret;
  1052. }
  1053. SpellEffects* Entity::GetFreeSpellEffectSlot(){
  1054. SpellEffects* ret = 0;
  1055. InfoStruct* info = GetInfoStruct();
  1056. MSpellEffects.readlock(__FUNCTION__, __LINE__);
  1057. for(int i=0;i<45;i++){
  1058. if(info->spell_effects[i].spell_id == 0xFFFFFFFF){
  1059. ret = &info->spell_effects[i];
  1060. ret->spell_id = 0;
  1061. break;
  1062. }
  1063. }
  1064. MSpellEffects.releasereadlock(__FUNCTION__, __LINE__);
  1065. return ret;
  1066. }
  1067. SpellEffects* Entity::GetSpellEffect(int32 id, Entity* caster) {
  1068. SpellEffects* ret = 0;
  1069. InfoStruct* info = GetInfoStruct();
  1070. MSpellEffects.readlock(__FUNCTION__, __LINE__);
  1071. for(int i = 0; i < 45; i++) {
  1072. if(info->spell_effects[i].spell_id == id) {
  1073. if (!caster || info->spell_effects[i].caster == caster){
  1074. ret = &info->spell_effects[i];
  1075. break;
  1076. }
  1077. }
  1078. }
  1079. MSpellEffects.releasereadlock(__FUNCTION__, __LINE__);
  1080. return ret;
  1081. }
  1082. SpellEffects* Entity::GetSpellEffectBySpellType(int8 spell_type) {
  1083. SpellEffects* ret = 0;
  1084. InfoStruct* info = GetInfoStruct();
  1085. MSpellEffects.readlock(__FUNCTION__, __LINE__);
  1086. for(int i = 0; i < 45; i++) {
  1087. if(info->spell_effects[i].spell_id != 0xFFFFFFFF && info->spell_effects[i].spell->spell->GetSpellData()->spell_type == spell_type) {
  1088. ret = &info->spell_effects[i];
  1089. break;
  1090. }
  1091. }
  1092. MSpellEffects.releasereadlock(__FUNCTION__, __LINE__);
  1093. return ret;
  1094. }
  1095. SpellEffects* Entity::GetSpellEffectWithLinkedTimer(int32 id, int32 linked_timer, sint32 type_group_spell_id, Entity* caster) {
  1096. SpellEffects* ret = 0;
  1097. InfoStruct* info = GetInfoStruct();
  1098. MSpellEffects.readlock(__FUNCTION__, __LINE__);
  1099. for(int i = 0; i < 45; i++) {
  1100. if(info->spell_effects[i].spell_id != 0xFFFFFFFF)
  1101. {
  1102. if( (info->spell_effects[i].spell_id == id && linked_timer == 0 && type_group_spell_id == 0) ||
  1103. (linked_timer > 0 && info->spell_effects[i].spell->spell->GetSpellData()->linked_timer == linked_timer) ||
  1104. (type_group_spell_id > 0 && info->spell_effects[i].spell->spell->GetSpellData()->type_group_spell_id == type_group_spell_id))
  1105. {
  1106. if (type_group_spell_id >= -1 && (!caster || info->spell_effects[i].caster == caster)){
  1107. ret = &info->spell_effects[i];
  1108. break;
  1109. }
  1110. }
  1111. }
  1112. }
  1113. MSpellEffects.releasereadlock(__FUNCTION__, __LINE__);
  1114. return ret;
  1115. }
  1116. LuaSpell* Entity::HasLinkedTimerID(LuaSpell* spell, Spawn* target, bool stackWithOtherPlayers) {
  1117. if(!spell->spell->GetSpellData()->linked_timer && !spell->spell->GetSpellData()->type_group_spell_id)
  1118. return nullptr;
  1119. LuaSpell* ret = nullptr;
  1120. InfoStruct* info = GetInfoStruct();
  1121. MSpellEffects.readlock(__FUNCTION__, __LINE__);
  1122. //this for loop primarily handles self checks and 'friendly' checks
  1123. for(int i = 0; i < NUM_MAINTAINED_EFFECTS; i++) {
  1124. if(info->maintained_effects[i].spell_id != 0xFFFFFFFF)
  1125. {
  1126. if( ((info->maintained_effects[i].spell_id == spell->spell->GetSpellID() && spell->spell->GetSpellData()->type_group_spell_id >= 0) ||
  1127. (info->maintained_effects[i].spell->spell->GetSpellData()->linked_timer > 0 && info->maintained_effects[i].spell->spell->GetSpellData()->linked_timer == spell->spell->GetSpellData()->linked_timer) ||
  1128. (spell->spell->GetSpellData()->type_group_spell_id > 0 && spell->spell->GetSpellData()->type_group_spell_id == info->maintained_effects[i].spell->spell->GetSpellData()->type_group_spell_id)) &&
  1129. ((spell->spell->GetSpellData()->friendly_spell) ||
  1130. (!spell->spell->GetSpellData()->friendly_spell && spell->spell->GetSpellData()->type_group_spell_id >= -1 && spell->caster == info->maintained_effects[i].spell->caster) ) &&
  1131. (target == nullptr || info->maintained_effects[i].spell->initial_target == target->GetID())) {
  1132. ret = info->maintained_effects[i].spell;
  1133. break;
  1134. }
  1135. }
  1136. }
  1137. MSpellEffects.releasereadlock(__FUNCTION__, __LINE__);
  1138. if(!ret && !stackWithOtherPlayers && target && target->IsEntity())
  1139. {
  1140. SpellEffects* effect = ((Entity*)target)->GetSpellEffectWithLinkedTimer(spell->spell->GetSpellID(), spell->spell->GetSpellData()->linked_timer, spell->spell->GetSpellData()->type_group_spell_id, nullptr);
  1141. if(effect)
  1142. ret = effect->spell;
  1143. }
  1144. return ret;
  1145. }
  1146. InfoStruct* Entity::GetInfoStruct(){
  1147. return &info_struct;
  1148. }
  1149. Skill* Entity::GetSkillByName(const char* name, bool check_update){
  1150. // NPC::GetSkillByName in NPC.cpp exists for NPC's
  1151. // Player::GetSkillByName in Player.cpp exists for Player's
  1152. return 0;
  1153. }
  1154. Skill* Entity::GetSkillByID(int32 id, bool check_update){
  1155. // NPC::GetSkillByID in NPC.cpp exists for NPC's
  1156. // Player::GetSkillByID in Player.cpp exists for Player's
  1157. return 0;
  1158. }
  1159. float Entity::GetMaxSpeed(){
  1160. return max_speed;
  1161. }
  1162. void Entity::SetMaxSpeed(float val){
  1163. max_speed = val;
  1164. }
  1165. float Entity::CalculateSkillStatChance(char* skillName, int16 item_stat, float max_cap, float modifier, bool add_to_skill)
  1166. {
  1167. float skillAndItemsChance = 0.0f;
  1168. float maxBonusCap = (float)GetLevel()*rule_manager.GetGlobalRule(R_Combat, MaxSkillBonusByLevel)->GetFloat();
  1169. Skill* skill = GetSkillByName(skillName, false);
  1170. if(skill){
  1171. MStats.lock();
  1172. float item_chance_or_skill = stats[item_stat];
  1173. MStats.unlock();
  1174. if(item_chance_or_skill > maxBonusCap) {
  1175. item_chance_or_skill = maxBonusCap;
  1176. }
  1177. if(add_to_skill)
  1178. {
  1179. skillAndItemsChance = (((float)skill->current_val+item_chance_or_skill)/10.0f); // do we know 25 is accurate? 10 gives more 'skill' space, most cap at 70% with items
  1180. }
  1181. else
  1182. {
  1183. skillAndItemsChance = ((float)skill->current_val/10.0f); // do we know 25 is accurate? 10 gives more 'skill' space, most cap at 70% with items
  1184. if(modifier > maxBonusCap) {
  1185. modifier = maxBonusCap;
  1186. }
  1187. // take chance percentage and add the item stats % (+1 = 1% or .01f)
  1188. skillAndItemsChance += (skillAndItemsChance*((item_chance_or_skill + modifier)/100.0f));
  1189. }
  1190. }
  1191. if ( max_cap > 0.0f && skillAndItemsChance > max_cap )
  1192. skillAndItemsChance = max_cap;
  1193. return skillAndItemsChance;
  1194. }
  1195. float Entity::CalculateSkillWithBonus(char* skillName, int16 item_stat, bool chance_skill_increase)
  1196. {
  1197. float skillAndItemsChance = 0.0f;
  1198. float maxBonusCap = GetRuleSkillMaxBonus();
  1199. Skill* skill = GetSkillByName(skillName, chance_skill_increase);
  1200. if(skill){
  1201. float item_chance_or_skill = 0.0f;
  1202. if(item_stat != 0xFFFF) {
  1203. MStats.lock();
  1204. item_chance_or_skill = stats[item_stat];
  1205. MStats.unlock();
  1206. }
  1207. if(item_chance_or_skill > maxBonusCap) { // would we be using their effective mentored level or actual level?
  1208. item_chance_or_skill = maxBonusCap;
  1209. }
  1210. skillAndItemsChance = skill->current_val+item_chance_or_skill;
  1211. }
  1212. return skillAndItemsChance;
  1213. }
  1214. float Entity::GetRuleSkillMaxBonus() {
  1215. return (float)GetLevel()*rule_manager.GetGlobalRule(R_Combat, MaxSkillBonusByLevel)->GetFloat();
  1216. }
  1217. void Entity::CalculateBonuses(){
  1218. if(lua_interface->IsLuaSystemReloading())
  1219. return;
  1220. InfoStruct* info = &info_struct;
  1221. int16 effective_level = info->get_effective_level() != 0 ? info->get_effective_level() : GetLevel();
  1222. CalculateMaxReduction();
  1223. info->set_block(info->get_block_base());
  1224. info->set_cur_attack(info->get_attack_base());
  1225. info->set_base_avoidance_pct(info->get_avoidance_base());
  1226. info->set_disease(info->get_disease_base());
  1227. info->set_divine(info->get_divine_base());
  1228. info->set_heat(info->get_heat_base());
  1229. info->set_magic(info->get_magic_base());
  1230. info->set_mental(info->get_mental_base());
  1231. info->set_cold(info->get_cold_base());
  1232. info->set_poison(info->get_poison_base());
  1233. info->set_elemental_base(info->get_heat());
  1234. info->set_noxious_base(info->get_poison());
  1235. info->set_arcane_base(info->get_magic());
  1236. info->set_sta(info->get_sta_base());
  1237. info->set_agi(info->get_agi_base());
  1238. info->set_str(info->get_str_base());
  1239. info->set_wis(info->get_wis_base());
  1240. info->set_intel(info->get_intel_base());
  1241. info->set_ability_modifier(0);
  1242. info->set_critical_mitigation(0);
  1243. info->set_block_chance(0);
  1244. info->set_crit_chance(0);
  1245. info->set_crit_bonus(0);
  1246. info->set_potency(0);
  1247. info->set_hate_mod(0);
  1248. info->set_reuse_speed(0);
  1249. info->set_casting_speed(0);
  1250. info->set_recovery_speed(0);
  1251. info->set_spell_reuse_speed(0);
  1252. info->set_spell_multi_attack(0);
  1253. info->set_dps(0);
  1254. info->set_dps_multiplier(0);
  1255. info->set_haste(0);
  1256. info->set_attackspeed(0);
  1257. info->set_multi_attack(0);
  1258. info->set_flurry(0);
  1259. info->set_melee_ae(0);
  1260. info->set_strikethrough(0);
  1261. info->set_accuracy(0);
  1262. info->set_offensivespeed(0);
  1263. MStats.lock();
  1264. stats.clear();
  1265. MStats.unlock();
  1266. ItemStatsValues* values = equipment_list.CalculateEquipmentBonuses(this);
  1267. CalculateSpellBonuses(values);
  1268. info->set_cur_mitigation(info->get_mitigation_base());
  1269. int32 calc_mit_cap = effective_level * rule_manager.GetGlobalRule(R_Combat, CalculatedMitigationCapLevel)->GetInt32();
  1270. info->set_max_mitigation(calc_mit_cap);
  1271. int16 mit_percent = (int16)(CalculateMitigation() * 1000.0f);
  1272. info->set_mitigation_pve(mit_percent);
  1273. mit_percent = (int16)(CalculateMitigation(DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE,0,0,true) * 1000.0f);
  1274. info->set_mitigation_pvp(mit_percent);
  1275. info->add_sta((float)values->sta);
  1276. info->add_str((float)values->str);
  1277. info->add_agi((float)values->agi);
  1278. info->add_wis((float)values->wis);
  1279. info->add_intel((float)values->int_);
  1280. info->add_disease(values->vs_disease);
  1281. info->add_divine(values->vs_divine);
  1282. info->add_heat(values->vs_heat);
  1283. info->add_magic(values->vs_magic);
  1284. int32 sta_hp_bonus = 0.0;
  1285. int32 prim_power_bonus = 0.0;
  1286. float bonus_mod = 0.0;
  1287. if (IsPlayer()) {
  1288. bonus_mod = CalculateBonusMod();
  1289. sta_hp_bonus = info->get_sta() * bonus_mod;
  1290. prim_power_bonus = GetPrimaryStat() * bonus_mod;
  1291. }
  1292. prim_power_bonus = floor(float(prim_power_bonus));
  1293. sta_hp_bonus = floor(float(sta_hp_bonus));
  1294. SetTotalHP(GetTotalHPBaseInstance() + values->health + sta_hp_bonus);
  1295. SetTotalPower(GetTotalPowerBaseInstance() + values->power + prim_power_bonus);
  1296. if(GetHP() > GetTotalHP())
  1297. SetHP(GetTotalHP());
  1298. if(GetPower() > GetTotalPower())
  1299. SetPower(GetTotalPower());
  1300. info->add_mental(values->vs_mental);
  1301. info->add_poison(values->vs_poison);
  1302. info->set_max_concentration(info->get_max_concentration_base() + values->concentration);
  1303. info->add_cold(values->vs_cold);
  1304. info->add_mitigation_skill1(values->vs_slash);
  1305. info->add_mitigation_skill2(values->vs_pierce);
  1306. info->add_mitigation_skill3(values->vs_crush);
  1307. info->add_ability_modifier(values->ability_modifier);
  1308. info->add_critical_mitigation(values->criticalmitigation);
  1309. info->add_block_chance(values->extrashieldblockchance);
  1310. info->add_crit_chance(values->beneficialcritchance);
  1311. info->add_crit_bonus(values->critbonus);
  1312. info->add_potency(values->potency);
  1313. info->add_hate_mod(values->hategainmod);
  1314. info->add_reuse_speed(values->abilityreusespeed);
  1315. info->add_casting_speed(values->abilitycastingspeed);
  1316. info->add_recovery_speed(values->abilityrecoveryspeed);
  1317. info->add_spell_reuse_speed(values->spellreusespeed);
  1318. info->add_spell_multi_attack(values->spellmultiattackchance);
  1319. info->add_dps(values->dps);
  1320. info->add_dps_multiplier(CalculateDPSMultiplier());
  1321. info->add_haste(values->attackspeed);
  1322. info->add_multi_attack(values->multiattackchance);
  1323. info->add_flurry(values->flurry);
  1324. info->add_melee_ae(values->aeautoattackchance);
  1325. info->add_strikethrough(values->strikethrough);
  1326. info->add_accuracy(values->accuracy);
  1327. info->add_offensivespeed(values->offensivespeed);
  1328. info->add_uncontested_block(values->uncontested_block);
  1329. info->add_uncontested_parry(values->uncontested_parry);
  1330. info->add_uncontested_dodge(values->uncontested_dodge);
  1331. info->add_uncontested_riposte(values->uncontested_riposte);
  1332. info->set_ability_modifier(values->ability_modifier);
  1333. float full_pct_hit = 100.0f;
  1334. MStats.lock();
  1335. float parryStat = stats[ITEM_STAT_PARRY];
  1336. MStats.unlock();
  1337. float parry_pct = CalculateSkillStatChance("Parry", ITEM_STAT_PARRYCHANCE, 70.0f, parryStat);
  1338. parry_pct += parry_pct * (info->get_cur_avoidance()/100.0f);
  1339. if(parry_pct > 70.0f)
  1340. parry_pct = 70.0f;
  1341. info->set_parry(parry_pct);
  1342. full_pct_hit -= parry_pct;
  1343. float block_pct = 0.0f;
  1344. if(GetAdventureClass() != BRAWLER)
  1345. {
  1346. Item* item = equipment_list.GetItem(EQ2_SECONDARY_SLOT);
  1347. if(item && item->details.item_id > 0 && item->IsShield()){
  1348. // if high is set and greater than low use high, otherwise use low
  1349. int16 mitigation = item->armor_info->mitigation_high > item->armor_info->mitigation_low ? item->armor_info->mitigation_high : item->armor_info->mitigation_low;
  1350. // we frankly don't know the formula for Block, only that it uses the 'Protection' of the shield, which is the mitigation_low/mitigation_high in the armor_info
  1351. if(mitigation)
  1352. {
  1353. /*DOF Prima Guide: Shields now have the following base chances
  1354. to block: Tower (10%), Kite (10%), Round
  1355. (5%), Buckler (3%). Your chances to block
  1356. scale up or down based on the con of your
  1357. opponent.*/
  1358. Skill* skill = master_skill_list.GetSkill(item->generic_info.skill_req1);
  1359. float baseBlock = 0.0f;
  1360. if(skill)
  1361. {
  1362. if(skill->short_name.data == "towershield" || skill->short_name.data == "kiteshield")
  1363. baseBlock = 10.0f;
  1364. else if (skill->short_name.data == "roundshield")
  1365. baseBlock = 5.0f;
  1366. else if (skill->short_name.data == "buckler")
  1367. baseBlock = 3.0f;
  1368. }
  1369. if(effective_level > mitigation)
  1370. block_pct = log10f((float)mitigation/((float)effective_level*10.0f));
  1371. else
  1372. block_pct = log10f(((float)effective_level/(float)mitigation)) * log10f(effective_level) * 2.0f;
  1373. if(block_pct < 0.0f)
  1374. block_pct *= -1.0f;
  1375. block_pct += baseBlock;
  1376. block_pct += block_pct * (info->get_cur_avoidance()/100.0f);
  1377. if(block_pct > 70.0f)
  1378. block_pct = 70.0f;
  1379. }
  1380. }
  1381. }
  1382. else
  1383. {
  1384. MStats.lock();
  1385. float deflectionStat = stats[ITEM_STAT_DEFLECTION];
  1386. MStats.unlock();
  1387. block_pct = CalculateSkillStatChance("Deflection", ITEM_STAT_MINIMUMDEFLECTIONCHANCE, 70.0f, deflectionStat+1.0f);
  1388. block_pct += block_pct * (info->get_cur_avoidance()/100.0f);
  1389. }
  1390. float block_actual = 0.0f;
  1391. if(full_pct_hit > 0.0f)
  1392. block_actual = block_pct * (full_pct_hit / 100.0f);
  1393. info->set_block(block_actual);
  1394. full_pct_hit -= block_actual;
  1395. MStats.lock();
  1396. float defenseStat = stats[ITEM_STAT_DEFENSE];
  1397. MStats.unlock();
  1398. float dodge_pct = CalculateSkillStatChance("Defense", ITEM_STAT_DODGECHANCE, 100.0f, defenseStat);
  1399. dodge_pct += dodge_pct * (info->get_cur_avoidance()/100.0f);
  1400. float dodge_actual = 0.0f;
  1401. if(full_pct_hit > 0.0f)
  1402. dodge_actual = dodge_pct * (full_pct_hit / 100.0f) + (log10f(effective_level * GetAgi()) / 100.0f);
  1403. info->set_avoidance_base(dodge_actual);
  1404. float total_avoidance = parry_pct + block_actual + dodge_actual;
  1405. info->set_avoidance_display(total_avoidance);
  1406. SetRegenValues(effective_level);
  1407. CalculateApplyWeight();
  1408. UpdateWeapons();
  1409. safe_delete(values);
  1410. }
  1411. void Entity::CalculateApplyWeight() {
  1412. if (IsPlayer()) {
  1413. int32 prev_weight = GetInfoStruct()->get_weight();
  1414. int32 inv_weight = ((Player*)this)->item_list.GetWeight();
  1415. // calculate coin
  1416. int32 coin_copper = GetInfoStruct()->get_coin_copper();
  1417. int32 coin_silver = GetInfoStruct()->get_coin_silver();
  1418. int32 coin_gold = GetInfoStruct()->get_coin_gold();
  1419. int32 coin_plat = GetInfoStruct()->get_coin_plat();
  1420. float weight_per_stone = rule_manager.GetGlobalRule(R_Player, CoinWeightPerStone)->GetFloat();
  1421. if(weight_per_stone < 0.0f) {
  1422. weight_per_stone = 0.0f;
  1423. }
  1424. double weight_copper = ((double)coin_copper / weight_per_stone);
  1425. double weight_silver = ((double)coin_silver / weight_per_stone);
  1426. double weight_gold = ((double)coin_gold / weight_per_stone);
  1427. double weight_platinum = ((double)coin_plat / weight_per_stone);
  1428. int32 total_weight = (int32)(weight_copper + weight_silver + weight_gold + weight_platinum);
  1429. LogWrite(PLAYER__DEBUG, 0, "Debug", "Coin Weight Calculated to: %u. Weight_Copper: %f, Weight_Silver: %f, Weight_Gold: %f, Weight_Platinum: %f", total_weight, weight_copper, weight_silver, weight_gold, weight_platinum);
  1430. total_weight += (int32)((double)inv_weight / 10.0);
  1431. GetInfoStruct()->set_weight(total_weight);
  1432. SetSpeedMultiplier(GetHighestSnare());
  1433. ((Player*)this)->SetSpeed(GetSpeed());
  1434. if(((Player*)this)->GetClient()) {
  1435. ((Player*)this)->GetClient()->SendControlGhost();
  1436. }
  1437. info_changed = true;
  1438. changed = true;
  1439. AddChangedZoneSpawn();
  1440. ((Player*)this)->SetCharSheetChanged(true);
  1441. }
  1442. int32 max_weight = 0;
  1443. float weight_str_multiplier = rule_manager.GetGlobalRule(R_Player, MaxWeightStrengthMultiplier)->GetFloat();
  1444. int32 base_weight = rule_manager.GetGlobalRule(R_Player, BaseWeight)->GetInt32();
  1445. if(weight_str_multiplier < 0.0f) {
  1446. weight_str_multiplier = 0.0f;
  1447. }
  1448. if(GetInfoStruct()->get_str() <= 0.0f) {
  1449. max_weight = base_weight; // rule for base strength
  1450. }
  1451. else {
  1452. max_weight = (int32)((double)GetInfoStruct()->get_str() * weight_str_multiplier); // rule multipler for strength
  1453. max_weight += base_weight; // rule for base strength
  1454. }
  1455. GetInfoStruct()->set_max_weight(max_weight);
  1456. }
  1457. void Entity::SetRegenValues(int16 effective_level)
  1458. {
  1459. bool classicRegen = rule_manager.GetGlobalRule(R_Spawn, ClassicRegen)->GetBool();
  1460. bool override_ = (IsPlayer() && !GetInfoStruct()->get_engaged_encounter());
  1461. if(!GetInfoStruct()->get_hp_regen_override())
  1462. {
  1463. sint16 regen_hp_rate = 0;
  1464. sint16 temp = 0;
  1465. MStats.lock();
  1466. if(!IsAggroed() || override_)
  1467. {
  1468. if(classicRegen)
  1469. {
  1470. // classic regen only gives OUT OF COMBAT, doesn't combine in+out of combat
  1471. regen_hp_rate = (int)(effective_level*.75)+1;
  1472. temp = regen_hp_rate + stats[ITEM_STAT_HPREGEN];
  1473. temp += stats[ITEM_STAT_HPREGENPPT];
  1474. }
  1475. else
  1476. {
  1477. regen_hp_rate = (int)(effective_level*.75)+(int)(effective_level/10) + 1;
  1478. temp = regen_hp_rate + stats[ITEM_STAT_HPREGEN];
  1479. temp += stats[ITEM_STAT_HPREGENPPT] + stats[ITEM_STAT_COMBATHPREGENPPT];
  1480. }
  1481. }
  1482. else
  1483. {
  1484. regen_hp_rate = (sint16)(effective_level / 10) + 1;
  1485. temp = regen_hp_rate + stats[ITEM_STAT_COMBATHPREGENPPT];
  1486. }
  1487. MStats.unlock();
  1488. GetInfoStruct()->set_hp_regen(temp);
  1489. }
  1490. if(!GetInfoStruct()->get_power_regen_override())
  1491. {
  1492. sint16 regen_power_rate = 0;
  1493. sint16 temp = 0;
  1494. MStats.lock();
  1495. if(!IsAggroed() || override_)
  1496. {
  1497. if(classicRegen)
  1498. {
  1499. regen_power_rate = effective_level + 1;
  1500. temp = regen_power_rate + stats[ITEM_STAT_MANAREGEN];
  1501. temp += stats[ITEM_STAT_MPREGENPPT];
  1502. }
  1503. else
  1504. {
  1505. regen_power_rate = effective_level + (int)(effective_level/10) + 1;
  1506. temp = regen_power_rate + stats[ITEM_STAT_MANAREGEN];
  1507. temp += stats[ITEM_STAT_MPREGENPPT] + stats[ITEM_STAT_COMBATMPREGENPPT];
  1508. }
  1509. }
  1510. else
  1511. {
  1512. regen_power_rate = (sint16)(effective_level / 10) + 1;
  1513. temp = regen_power_rate + stats[ITEM_STAT_COMBATMPREGENPPT];
  1514. }
  1515. MStats.unlock();
  1516. GetInfoStruct()->set_power_regen(temp);
  1517. }
  1518. }
  1519. EquipmentItemList* Entity::GetEquipmentList(){
  1520. return &equipment_list;
  1521. }
  1522. EquipmentItemList* Entity::GetAppearanceEquipmentList(){
  1523. return &appearance_equipment_list;
  1524. }
  1525. void Entity::SetEquipment(Item* item, int8 slot){
  1526. std::lock_guard<std::mutex> lk(MEquipment);
  1527. if(!item && slot < NUM_SLOTS){
  1528. SetInfo(&equipment.equip_id[slot], 0);
  1529. SetInfo(&equipment.color[slot].red, 0);
  1530. SetInfo(&equipment.color[slot].green, 0);
  1531. SetInfo(&equipment.color[slot].blue, 0);
  1532. SetInfo(&equipment.highlight[slot].red, 0);
  1533. SetInfo(&equipment.highlight[slot].green, 0);
  1534. SetInfo(&equipment.highlight[slot].blue, 0);
  1535. }
  1536. else{
  1537. if ( slot >= NUM_SLOTS )
  1538. slot = item->details.slot_id;
  1539. if( slot >= NUM_SLOTS )
  1540. return;
  1541. SetInfo(&equipment.equip_id[slot], item->generic_info.appearance_id);
  1542. SetInfo(&equipment.color[slot].red, item->generic_info.appearance_red);
  1543. SetInfo(&equipment.color[slot].green, item->generic_info.appearance_green);
  1544. SetInfo(&equipment.color[slot].blue, item->generic_info.appearance_blue);
  1545. SetInfo(&equipment.highlight[slot].red, item->generic_info.appearance_highlight_red);
  1546. SetInfo(&equipment.highlight[slot].green, item->generic_info.appearance_highlight_green);
  1547. SetInfo(&equipment.highlight[slot].blue, item->generic_info.appearance_highlight_blue);
  1548. }
  1549. }
  1550. bool Entity::CheckSpellBonusRemoval(LuaSpell* spell, int16 type){
  1551. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  1552. while(itr.Next()){
  1553. if(itr.value->luaspell == spell && itr.value->type == type){
  1554. bonus_list.Remove(itr.value, true);
  1555. return true;
  1556. }
  1557. }
  1558. return false;
  1559. }
  1560. void Entity::AddSpellBonus(LuaSpell* spell, int16 type, float value, int64 class_req, vector<int16> race_req, vector<int16> faction_req){
  1561. CheckSpellBonusRemoval(spell, type);
  1562. BonusValues* bonus = new BonusValues;
  1563. if(spell && spell->spell) {
  1564. bonus->spell_id = spell->spell->GetSpellID();
  1565. }
  1566. else {
  1567. bonus->spell_id = 0;
  1568. }
  1569. bonus->luaspell = spell;
  1570. bonus->type = type;
  1571. bonus->value = value;
  1572. bonus->class_req = class_req;
  1573. bonus->race_req = race_req;
  1574. bonus->faction_req = faction_req;
  1575. bonus->tier = (spell && spell->spell) ? spell->spell->GetSpellTier() : 0;
  1576. bonus_list.Add(bonus);
  1577. if(IsNPC() || IsPlayer())
  1578. CalculateBonuses();
  1579. }
  1580. BonusValues* Entity::GetSpellBonus(int32 spell_id) {
  1581. BonusValues *ret = 0;
  1582. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  1583. while (itr.Next()) {
  1584. if (itr.value->spell_id == spell_id) {
  1585. ret = itr.value;
  1586. break;
  1587. }
  1588. }
  1589. return ret;
  1590. }
  1591. vector<BonusValues*>* Entity::GetAllSpellBonuses(LuaSpell* spell) {
  1592. vector<BonusValues*>* list = new vector<BonusValues*>;
  1593. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  1594. while (itr.Next()) {
  1595. if (itr.value->luaspell == spell)
  1596. list->push_back(itr.value);
  1597. }
  1598. return list;
  1599. }
  1600. void Entity::RemoveSpellBonus(const LuaSpell* spell, bool remove_all){
  1601. // spell can be null!
  1602. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  1603. while(itr.Next()){
  1604. if(itr.value->luaspell == spell || remove_all)
  1605. bonus_list.Remove(itr.value, true);
  1606. }
  1607. if(IsNPC() || IsPlayer())
  1608. CalculateBonuses();
  1609. }
  1610. void Entity::CalculateSpellBonuses(ItemStatsValues* stats){
  1611. if(stats){
  1612. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  1613. vector<BonusValues*> bv;
  1614. //First check if we meet the requirement for each bonus
  1615. bool race_match = false;
  1616. while(itr.Next()) {
  1617. if (itr.value->race_req.size() > 0) {
  1618. for (int8 i = 0; i < itr.value->race_req.size(); i++) {
  1619. if (GetRace() == itr.value->race_req[i]) {
  1620. race_match = true;
  1621. }
  1622. }
  1623. }
  1624. else
  1625. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1626. int64 const class1 = pow(2.0, (GetAdventureClass() - 1));
  1627. int64 const class2 = pow(2.0, (classes.GetSecondaryBaseClass(GetAdventureClass()) - 1));
  1628. int64 const class3 = pow(2.0, (classes.GetBaseClass(GetAdventureClass()) - 1));
  1629. if (itr.value->class_req == 0 || (itr.value->class_req & class1) == class1 || (itr.value->class_req & class2) == class2 || (itr.value->class_req & class3) == class3 && race_match )
  1630. bv.push_back(itr.value);
  1631. }
  1632. //Sort the bonuses by spell id and luaspell
  1633. BonusValues* bonus = nullptr;
  1634. map <int32, map<LuaSpell*, vector<BonusValues*> > > sort;
  1635. for (int8 i = 0; i < bv.size(); i++){
  1636. bonus = bv.at(i);
  1637. sort[bonus->spell_id][bonus->luaspell].push_back(bonus);
  1638. }
  1639. //Now check for the highest tier of each spell id and apply those bonuses
  1640. map<LuaSpell*, vector<BonusValues*> >::iterator tier_itr;
  1641. map <int32, map<LuaSpell*, vector<BonusValues*> > >::iterator sort_itr;
  1642. for (sort_itr = sort.begin(); sort_itr != sort.end(); sort_itr++){
  1643. LuaSpell* key = nullptr;
  1644. sint8 highest_tier = -1;
  1645. //Find the highest tier for this spell id
  1646. for (tier_itr = sort_itr->second.begin(); tier_itr != sort_itr->second.end(); tier_itr++){
  1647. LuaSpell* current_spell = tier_itr->first;
  1648. sint8 current_tier = 0;
  1649. if (current_spell && current_spell->spell && ((current_tier = current_spell->spell->GetSpellTier()) > highest_tier)) {
  1650. highest_tier = current_tier;
  1651. key = current_spell;
  1652. }
  1653. }
  1654. //We've found the highest tier for this spell id, so add the bonuses
  1655. vector<BonusValues*>* final_bonuses = &sort_itr->second[key];
  1656. for (int8 i = 0; i < final_bonuses->size(); i++)
  1657. world.AddBonuses(nullptr, stats, final_bonuses->at(i)->type, final_bonuses->at(i)->value, this);
  1658. }
  1659. }
  1660. }
  1661. void Entity::AddMezSpell(LuaSpell* spell) {
  1662. if (!spell)
  1663. return;
  1664. if (!control_effects[CONTROL_EFFECT_TYPE_MEZ])
  1665. control_effects[CONTROL_EFFECT_TYPE_MEZ] = new MutexList<LuaSpell*>;
  1666. MutexList<LuaSpell*>* mez_spells = control_effects[CONTROL_EFFECT_TYPE_MEZ];
  1667. if (IsPlayer() && !IsStunned() && !IsMezImmune() && mez_spells->size(true) == 0){
  1668. ((Player*)this)->SetPlayerControlFlag(1, 16, true);
  1669. if (!IsRooted())
  1670. ((Player*)this)->SetPlayerControlFlag(1, 8, true);
  1671. if (!IsStifled() && !IsFeared())
  1672. GetZone()->LockAllSpells((Player*)this);
  1673. }
  1674. if (IsNPC() && !IsMezImmune())
  1675. {
  1676. HaltMovement();
  1677. }
  1678. mez_spells->Add(spell);
  1679. }
  1680. void Entity::RemoveMezSpell(LuaSpell* spell) {
  1681. MutexList<LuaSpell*>* mez_spells = control_effects[CONTROL_EFFECT_TYPE_MEZ];
  1682. if (!mez_spells || mez_spells->size(true) == 0)
  1683. return;
  1684. mez_spells->Remove(spell);
  1685. if (mez_spells->size(true) == 0){
  1686. if (IsPlayer() && !IsMezImmune() && !IsStunned()){
  1687. if (!IsStifled() && !IsFeared())
  1688. GetZone()->UnlockAllSpells((Player*)this);
  1689. ((Player*)this)->SetPlayerControlFlag(1, 16, false);
  1690. if (!IsRooted())
  1691. ((Player*)this)->SetPlayerControlFlag(1, 8, false);
  1692. }
  1693. if(!IsPlayer()) {
  1694. GetZone()->movementMgr->StopNavigation((Entity*)this);
  1695. ((Spawn*)this)->StopMovement();
  1696. }
  1697. }
  1698. }
  1699. void Entity::RemoveAllMezSpells() {
  1700. MutexList<LuaSpell*>* mez_spells = control_effects[CONTROL_EFFECT_TYPE_MEZ];
  1701. if (!mez_spells)
  1702. return;
  1703. MutexList<LuaSpell*>::iterator itr = mez_spells->begin();
  1704. while (itr.Next()){
  1705. LuaSpell* spell = itr.value;
  1706. if (!spell)
  1707. continue;
  1708. GetZone()->RemoveTargetFromSpell(spell, this);
  1709. RemoveDetrimentalSpell(spell);
  1710. RemoveSpellEffect(spell);
  1711. if (IsPlayer())
  1712. ((Player*)this)->RemoveSkillBonus(spell->spell->GetSpellID());
  1713. }
  1714. mez_spells->clear();
  1715. if (IsPlayer() && !IsMezImmune() && !IsStunned()){
  1716. if (!IsStifled() && !IsFeared())
  1717. GetZone()->UnlockAllSpells((Player*)this);
  1718. ((Player*)this)->SetPlayerControlFlag(1, 16, false);
  1719. if (!IsRooted())
  1720. ((Player*)this)->SetPlayerControlFlag(1, 8, false);
  1721. }
  1722. }
  1723. void Entity::AddStifleSpell(LuaSpell* spell) {
  1724. if (!spell)
  1725. return;
  1726. if (!control_effects[CONTROL_EFFECT_TYPE_STIFLE])
  1727. control_effects[CONTROL_EFFECT_TYPE_STIFLE] = new MutexList<LuaSpell*>;
  1728. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_STIFLE]->size(true) == 0 && !IsStifleImmune() && !IsMezzedOrStunned())
  1729. GetZone()->LockAllSpells((Player*)this);
  1730. control_effects[CONTROL_EFFECT_TYPE_STIFLE]->Add(spell);
  1731. }
  1732. void Entity::RemoveStifleSpell(LuaSpell* spell) {
  1733. MutexList<LuaSpell*>* stifle_list = control_effects[CONTROL_EFFECT_TYPE_STIFLE];
  1734. if (!stifle_list || stifle_list->size(true) == 0)
  1735. return;
  1736. stifle_list->Remove(spell);
  1737. if (IsPlayer() && stifle_list->size(true) == 0 && !IsStifleImmune() && !IsMezzedOrStunned())
  1738. GetZone()->UnlockAllSpells((Player*)this);
  1739. }
  1740. void Entity::AddDazeSpell(LuaSpell* spell) {
  1741. if (!spell)
  1742. return;
  1743. if (!control_effects[CONTROL_EFFECT_TYPE_DAZE])
  1744. control_effects[CONTROL_EFFECT_TYPE_DAZE] = new MutexList<LuaSpell*>;
  1745. control_effects[CONTROL_EFFECT_TYPE_DAZE]->Add(spell);
  1746. }
  1747. void Entity::RemoveDazeSpell(LuaSpell* spell) {
  1748. MutexList<LuaSpell*>* daze_list = control_effects[CONTROL_EFFECT_TYPE_DAZE];
  1749. if (!daze_list || daze_list->size(true) == 0)
  1750. return;
  1751. daze_list->Remove(spell);
  1752. }
  1753. void Entity::AddStunSpell(LuaSpell* spell) {
  1754. if (!spell)
  1755. return;
  1756. if (!control_effects[CONTROL_EFFECT_TYPE_STUN])
  1757. control_effects[CONTROL_EFFECT_TYPE_STUN] = new MutexList<LuaSpell*>;
  1758. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_STUN]->size(true) == 0 && !IsStunImmune()){
  1759. if (!IsMezzed()){
  1760. ((Player*)this)->SetPlayerControlFlag(1, 16, true);
  1761. if (!IsRooted())
  1762. ((Player*)this)->SetPlayerControlFlag(1, 8, true);
  1763. if (!IsStifled() && !IsFeared())
  1764. GetZone()->LockAllSpells((Player*)this);
  1765. }
  1766. }
  1767. control_effects[CONTROL_EFFECT_TYPE_STUN]->Add(spell);
  1768. }
  1769. void Entity::RemoveStunSpell(LuaSpell* spell) {
  1770. MutexList<LuaSpell*>* stun_list = control_effects[CONTROL_EFFECT_TYPE_STUN];
  1771. if (!stun_list || stun_list->size(true) == 0)
  1772. return;
  1773. stun_list->Remove(spell);
  1774. if (stun_list->size(true) == 0){
  1775. if (IsPlayer() && !IsMezzed() && !IsStunImmune()){
  1776. ((Player*)this)->SetPlayerControlFlag(1, 16, false);
  1777. if (!IsRooted())
  1778. ((Player*)this)->SetPlayerControlFlag(1, 8, false);
  1779. if (!IsStifled() && !IsFeared())
  1780. GetZone()->UnlockAllSpells((Player*)this);
  1781. }
  1782. if(!IsPlayer()) {
  1783. GetZone()->movementMgr->StopNavigation((Entity*)this);
  1784. ((Spawn*)this)->StopMovement();
  1785. }
  1786. }
  1787. }
  1788. void Entity::HideDeityPet(bool val) {
  1789. if (!deityPet)
  1790. return;
  1791. if (val) {
  1792. deityPet->AddAllowAccessSpawn(deityPet);
  1793. GetZone()->HidePrivateSpawn(deityPet);
  1794. }
  1795. else
  1796. deityPet->MakeSpawnPublic();
  1797. }
  1798. void Entity::HideCosmeticPet(bool val) {
  1799. if (!cosmeticPet)
  1800. return;
  1801. if (val) {
  1802. cosmeticPet->AddAllowAccessSpawn(cosmeticPet);
  1803. GetZone()->HidePrivateSpawn(cosmeticPet);
  1804. }
  1805. else
  1806. cosmeticPet->MakeSpawnPublic();
  1807. }
  1808. void Entity::DismissAllPets(bool from_death, bool spawnListLocked)
  1809. {
  1810. DismissPet(GetPet(), from_death, spawnListLocked);
  1811. DismissPet(GetCharmedPet(), from_death, spawnListLocked);
  1812. DismissPet(GetDeityPet(), from_death, spawnListLocked);
  1813. DismissPet(GetCosmeticPet(), from_death, spawnListLocked);
  1814. }
  1815. void Entity::DismissPet(Entity* pet, bool from_death, bool spawnListLocked) {
  1816. if (!pet)
  1817. return;
  1818. Entity* PetOwner = pet->GetOwner();
  1819. if(pet->IsNPC())
  1820. {
  1821. ((NPC*)pet)->SetDismissing(true);
  1822. // Remove the spell maintained spell
  1823. Spell* spell = master_spell_list.GetSpell(pet->GetPetSpellID(), pet->GetPetSpellTier());
  1824. if (spell)
  1825. GetZone()->GetSpellProcess()->DeleteCasterSpell(this, spell, from_death == true ? (string)"pet_death" : (string)"canceled");
  1826. }
  1827. if (pet->GetPetType() == PET_TYPE_CHARMED) {
  1828. if(PetOwner)
  1829. PetOwner->SetCharmedPet(0);
  1830. if (!from_death) {
  1831. // set the pet flag to false, owner to 0, and give the mob its old brain back
  1832. pet->SetPet(false);
  1833. pet->SetOwner(0);
  1834. if(pet->IsNPC())
  1835. ((NPC*)pet)->SetBrain(new Brain((NPC*)pet));
  1836. pet->SetDismissing(false);
  1837. }
  1838. }
  1839. else if (PetOwner && pet->GetPetType() == PET_TYPE_COMBAT)
  1840. PetOwner->SetCombatPet(0);
  1841. else if (PetOwner && pet->GetPetType() == PET_TYPE_DEITY)
  1842. PetOwner->SetDeityPet(0);
  1843. else if (PetOwner && pet->GetPetType() == PET_TYPE_COSMETIC)
  1844. PetOwner->SetCosmeticPet(0);
  1845. // if owner is player and no combat pets left reset the pet info
  1846. if (PetOwner && PetOwner->IsPlayer()) {
  1847. if (!PetOwner->GetPet() && !PetOwner->GetCharmedPet())
  1848. ((Player*)PetOwner)->ResetPetInfo();
  1849. }
  1850. // remove the spawn from the world
  1851. if (!from_death && pet->GetPetType() != PET_TYPE_CHARMED)
  1852. GetZone()->RemoveSpawn(pet);
  1853. }
  1854. float Entity::CalculateBonusMod() {
  1855. int8 level = GetLevel();
  1856. if (level <= 20)
  1857. return 3.0;
  1858. else if (level >= 90)
  1859. return 10.0;
  1860. else
  1861. return (level - 20) * .1 + 3.0;
  1862. }
  1863. float Entity::CalculateDPSMultiplier(){
  1864. float dps = GetInfoStruct()->get_dps();
  1865. if (dps > 0){
  1866. if (dps <= 100)
  1867. return (dps / 100 + 1);
  1868. else if (dps <= 200)
  1869. return (((dps - 100) * .25 + 100) / 100 + 1);
  1870. else if (dps <= 300)
  1871. return (((dps - 200) * .1 + 125) / 100 + 1);
  1872. else if (dps <= 900)
  1873. return (((dps - 300) * .05 + 135) / 100 + 1);
  1874. else
  1875. return (((dps - 900) * .01 + 165) / 100 + 1);
  1876. }
  1877. return 1;
  1878. }
  1879. void Entity::AddWard(int32 spellID, WardInfo* ward) {
  1880. if (m_wardList.count(spellID) == 0) {
  1881. m_wardList[spellID] = ward;
  1882. }
  1883. }
  1884. WardInfo* Entity::GetWard(int32 spellID) {
  1885. WardInfo* ret = 0;
  1886. if (m_wardList.count(spellID) > 0)
  1887. ret = m_wardList[spellID];
  1888. return ret;
  1889. }
  1890. void Entity::RemoveWard(int32 spellID) {
  1891. if (m_wardList.count(spellID) > 0) {
  1892. // Delete the ward info
  1893. safe_delete(m_wardList[spellID]);
  1894. // Remove from the ward list
  1895. m_wardList.erase(spellID);
  1896. }
  1897. }
  1898. int32 Entity::CheckWards(Entity* attacker, int32 damage, int8 damage_type) {
  1899. map<int32, WardInfo*>::iterator itr;
  1900. WardInfo* ward = 0;
  1901. LuaSpell* spell = 0;
  1902. while (m_wardList.size() > 0 && damage > 0) {
  1903. // Get the ward with the lowest base damage
  1904. for (itr = m_wardList.begin(); itr != m_wardList.end(); itr++) {
  1905. if(itr->second->RoundTriggered)
  1906. continue;
  1907. if (!ward || itr->second->BaseDamage < ward->BaseDamage) {
  1908. if ((itr->second->AbsorbAllDamage || itr->second->DamageLeft > 0) &&
  1909. (itr->second->WardType == WARD_TYPE_ALL ||
  1910. (itr->second->WardType == WARD_TYPE_PHYSICAL && damage_type >= DAMAGE_PACKET_DAMAGE_TYPE_SLASH && damage_type <= DAMAGE_PACKET_DAMAGE_TYPE_PIERCE) ||
  1911. (itr->second->WardType == WARD_TYPE_MAGICAL && ((itr->second->DamageType == 0 && damage_type >= DAMAGE_PACKET_DAMAGE_TYPE_PIERCE) || (damage_type >= DAMAGE_PACKET_DAMAGE_TYPE_PIERCE && itr->second->DamageType == damage_type)))))
  1912. ward = itr->second;
  1913. }
  1914. }
  1915. if (!ward)
  1916. break;
  1917. spell = ward->Spell;
  1918. // damage to redirect at the source (like intercept)
  1919. int32 redirectDamage = 0;
  1920. if (ward->RedirectDamagePercent)
  1921. redirectDamage = (int32)(double)damage * ((double)ward->RedirectDamagePercent / 100.0);
  1922. // percentage the spell absorbs of all possible damage
  1923. int32 damageToAbsorb = 0;
  1924. if (ward->DamageAbsorptionPercentage > 0)
  1925. damageToAbsorb = (int32)(double)damage * ((double)ward->DamageAbsorptionPercentage/100.0);
  1926. else
  1927. damageToAbsorb = damage;
  1928. int32 maxDamageAbsorptionAllowed = 0;
  1929. // spells like Divine Aura have caps on health, eg. anything more than 50% damage is not absorbed
  1930. if (ward->DamageAbsorptionMaxHealthPercent > 0)
  1931. maxDamageAbsorptionAllowed = (int32)(double)GetTotalHP() * ((double)ward->DamageAbsorptionMaxHealthPercent / 100.0);
  1932. if (maxDamageAbsorptionAllowed > 0 && damageToAbsorb >= maxDamageAbsorptionAllowed)
  1933. damageToAbsorb = 0; // its over or equal to 50% of the total hp allowed, thus this damage is not absorbed
  1934. int32 baseDamageRemaining = damage - damageToAbsorb;
  1935. bool hasSpellBeenRemoved = false;
  1936. if (ward->AbsorbAllDamage)
  1937. {
  1938. ward->LastAbsorbedDamage = ward->DamageLeft;
  1939. if (!redirectDamage)
  1940. GetZone()->SendHealPacket(ward->Spell->caster, this, HEAL_PACKET_TYPE_ABSORB, damage, spell->spell->GetName());
  1941. damage = 0;
  1942. }
  1943. else if (damageToAbsorb >= ward->DamageLeft) {
  1944. // Damage is greater than or equal to the amount left on the ward
  1945. ward->LastAbsorbedDamage = ward->DamageLeft;
  1946. // remove what damage we can absorb
  1947. damageToAbsorb -= ward->DamageLeft;
  1948. // move back what couldn't be absorbed to the base dmg and apply to the overall damage
  1949. baseDamageRemaining += damageToAbsorb;
  1950. damage = baseDamageRemaining;
  1951. ward->DamageLeft = 0;
  1952. spell->damage_remaining = 0;
  1953. if(!redirectDamage)
  1954. GetZone()->SendHealPacket(spell->caster, this, HEAL_PACKET_TYPE_ABSORB, ward->DamageLeft, spell->spell->GetName());
  1955. if (!ward->keepWard) {
  1956. hasSpellBeenRemoved = true;
  1957. RemoveWard(spell->spell->GetSpellID());
  1958. GetZone()->GetSpellProcess()->DeleteCasterSpell(spell, "purged");
  1959. }
  1960. }
  1961. else {
  1962. ward->LastAbsorbedDamage = damageToAbsorb;
  1963. // Damage is less then the amount left on the ward
  1964. ward->DamageLeft -= damageToAbsorb;
  1965. spell->damage_remaining = ward->DamageLeft;
  1966. if (spell->caster->IsPlayer())
  1967. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  1968. if (!redirectDamage)
  1969. GetZone()->SendHealPacket(ward->Spell->caster, this, HEAL_PACKET_TYPE_ABSORB, damage, spell->spell->GetName());
  1970. // remaining damage not absorbed by percentage must be set
  1971. damage = baseDamageRemaining;
  1972. }
  1973. if (redirectDamage)
  1974. {
  1975. ward->LastRedirectDamage = redirectDamage;
  1976. if (this->IsPlayer())
  1977. {
  1978. Client* client = this->GetClient();
  1979. if(client) {
  1980. client->Message(CHANNEL_COMBAT, "%s intercepted some of the damage intended for you!", spell->caster->GetName());
  1981. }
  1982. }
  1983. if (spell->caster && spell->caster->IsPlayer())
  1984. {
  1985. Client* client = ((Player*)spell->caster)->GetClient();
  1986. if(client) {
  1987. client->Message(CHANNEL_COMBAT, "YOU intercept some of the damage intended for %s!", this->GetName());
  1988. }
  1989. }
  1990. if (attacker && spell->caster)
  1991. attacker->DamageSpawn(spell->caster, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, damage_type, redirectDamage, redirectDamage, 0, 0, false, false, false, false, spell);
  1992. }
  1993. bool shouldRemoveSpell = false;
  1994. ward->HitCount++; // increment hit count
  1995. ward->RoundTriggered = true;
  1996. if (ward->MaxHitCount && spell->num_triggers && spell->caster->GetZone())
  1997. {
  1998. spell->num_triggers--;
  1999. if(spell->caster->IsPlayer()) {
  2000. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, spell->num_triggers, 0);
  2001. }
  2002. }
  2003. if (ward->MaxHitCount && ward->HitCount >= ward->MaxHitCount) // there isn't a max hit requirement with the hit count, so just go based on hit count
  2004. shouldRemoveSpell = true;
  2005. if (shouldRemoveSpell && !hasSpellBeenRemoved)
  2006. {
  2007. RemoveWard(spell->spell->GetSpellID());
  2008. GetZone()->GetSpellProcess()->DeleteCasterSpell(spell, "purged");
  2009. }
  2010. // Reset ward pointer
  2011. ward = 0;
  2012. }
  2013. for (itr = m_wardList.begin(); itr != m_wardList.end(); itr++) {
  2014. itr->second->RoundTriggered = false;
  2015. }
  2016. return damage;
  2017. }
  2018. float Entity::CalculateCastingSpeedMod() {
  2019. float cast_speed = info_struct.get_casting_speed();
  2020. if(cast_speed > 0)
  2021. return 100 * max((float) 0.5, (float) (1 + (1 - (1 / (1 + (cast_speed * .01))))));
  2022. else if (cast_speed < 0)
  2023. return 100 * min((float) 1.5, (float) (1 + (1 - (1 / (1 + (cast_speed * -.01))))));
  2024. return 0;
  2025. }
  2026. float Entity::GetSpeed() {
  2027. float ret = speed > GetBaseSpeed() ? speed : GetBaseSpeed();
  2028. if(IsPlayer()) {
  2029. ret = GetBaseSpeed();
  2030. }
  2031. MStats.lock();
  2032. if ((IsStealthed() || IsInvis()) && stats.count(ITEM_STAT_STEALTHINVISSPEEDMOD)) {
  2033. ret += stats[ITEM_STAT_STEALTHINVISSPEEDMOD];
  2034. }
  2035. if (!GetInfoStruct()->get_engaged_encounter()) {
  2036. if (stats.count(ITEM_STAT_SPEED) && stats.count(ITEM_STAT_MOUNTSPEED)) {
  2037. ret += max(stats[ITEM_STAT_SPEED], stats[ITEM_STAT_MOUNTSPEED]);
  2038. }
  2039. else if (stats.count(ITEM_STAT_SPEED)) {
  2040. ret += stats[ITEM_STAT_SPEED];
  2041. }
  2042. else if (stats.count(ITEM_STAT_MOUNTSPEED)) {
  2043. ret += stats[ITEM_STAT_MOUNTSPEED];
  2044. }
  2045. }
  2046. else if (GetInfoStruct()->get_engaged_encounter()) {
  2047. if (GetMaxSpeed() > 0.0f)
  2048. ret = GetMaxSpeed();
  2049. if (stats.count(ITEM_STAT_OFFENSIVESPEED)) {
  2050. ret += stats[ITEM_STAT_OFFENSIVESPEED];
  2051. }
  2052. }
  2053. MStats.unlock();
  2054. ret *= speed_multiplier;
  2055. return ret;
  2056. }
  2057. float Entity::GetAirSpeed() {
  2058. float ret = speed;
  2059. if (!GetInfoStruct()->get_engaged_encounter())
  2060. ret += stats[ITEM_STAT_MOUNTAIRSPEED];
  2061. ret *= speed_multiplier;
  2062. return ret;
  2063. }
  2064. void Entity::SetThreatTransfer(ThreatTransfer* transfer) {
  2065. safe_delete(m_threatTransfer);
  2066. m_threatTransfer = transfer;
  2067. }
  2068. int8 Entity::GetTraumaCount() {
  2069. return det_count_list[DET_TYPE_TRAUMA];
  2070. }
  2071. int8 Entity::GetArcaneCount() {
  2072. return det_count_list[DET_TYPE_ARCANE];
  2073. }
  2074. int8 Entity::GetNoxiousCount() {
  2075. return det_count_list[DET_TYPE_NOXIOUS];
  2076. }
  2077. int8 Entity::GetElementalCount() {
  2078. return det_count_list[DET_TYPE_ELEMENTAL];
  2079. }
  2080. int8 Entity::GetCurseCount() {
  2081. return det_count_list[DET_TYPE_CURSE];
  2082. }
  2083. Mutex* Entity::GetDetrimentMutex() {
  2084. return &MDetriments;
  2085. }
  2086. Mutex* Entity::GetMaintainedMutex() {
  2087. return &MMaintainedSpells;
  2088. }
  2089. Mutex* Entity::GetSpellEffectMutex() {
  2090. return &MSpellEffects;
  2091. }
  2092. bool Entity::HasCurableDetrimentType(int8 det_type) {
  2093. DetrimentalEffects* det;
  2094. bool ret = false;
  2095. MDetriments.readlock(__FUNCTION__, __LINE__);
  2096. for (int32 i = 0; i < detrimental_spell_effects.size(); i++){
  2097. det = &detrimental_spell_effects.at(i);
  2098. if(det && det->det_type == det_type && !det->incurable){
  2099. ret = true;
  2100. break;
  2101. }
  2102. }
  2103. MDetriments.releasereadlock(__FUNCTION__, __LINE__);
  2104. return ret;
  2105. }
  2106. void Entity::ClearAllDetriments() {
  2107. MDetriments.writelock(__FUNCTION__, __LINE__);
  2108. detrimental_spell_effects.clear();
  2109. det_count_list.clear();
  2110. MDetriments.releasewritelock(__FUNCTION__, __LINE__);
  2111. }
  2112. void Entity::CureDetrimentByType(int8 cure_count, int8 det_type, string cure_name, Entity* caster, int8 cure_level) {
  2113. if (cure_count <= 0 || GetDetTypeCount(det_type) <= 0)
  2114. return;
  2115. vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
  2116. DetrimentalEffects* det;
  2117. vector<LuaSpell*> remove_list;
  2118. LuaSpell* spell = 0;
  2119. vector<LevelArray*>* levels;
  2120. int8 caster_class1 = 0;
  2121. int8 caster_class2 = 0;
  2122. int8 caster_class3 = 0;
  2123. InfoStruct* info_struct = 0;
  2124. bool pass_level_check = false;
  2125. MDetriments.readlock(__FUNCTION__, __LINE__);
  2126. for (int32 i = 0; i<det_list->size(); i++){
  2127. det = &det_list->at(i);
  2128. if (det && det->det_type == det_type && !det->incurable){
  2129. levels = det->spell->spell->GetSpellLevels();
  2130. info_struct = det->caster->GetInfoStruct();
  2131. pass_level_check = false;
  2132. bool has_level_checks = false;
  2133. for (int32 x = 0; x < levels->size(); x++){
  2134. has_level_checks = true;
  2135. // class checks are worthless we can't guarantee the caster is that class
  2136. if (!cure_level || cure_level >= (levels->at(x)->spell_level / 10)){
  2137. pass_level_check = true;
  2138. break;
  2139. }
  2140. }
  2141. if (pass_level_check || !has_level_checks){
  2142. remove_list.push_back(det->spell);
  2143. cure_count--;
  2144. if (cure_count == 0)
  2145. break;
  2146. }
  2147. }
  2148. }
  2149. MDetriments.releasereadlock(__FUNCTION__, __LINE__);
  2150. for (int32 i = 0; i<remove_list.size(); i++){
  2151. spell = remove_list.at(i);
  2152. LogWrite(PLAYER__ERROR, 0, "Debug", "Remove spell %s", remove_list.at(i)->spell->GetName());
  2153. GetZone()->SendDispellPacket(caster, this, cure_name, (string)remove_list.at(i)->spell->GetName(), DISPELL_TYPE_CURE);
  2154. GetZone()->GetSpellProcess()->DeleteCasterSpell(spell, "cured", false, this);
  2155. }
  2156. remove_list.clear();
  2157. }
  2158. void Entity::CureDetrimentByControlEffect(int8 cure_count, int8 control_type, string cure_name, Entity* caster, int8 cure_level) {
  2159. if (cure_count <= 0 || GetDetCount() <= 0)
  2160. return;
  2161. vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
  2162. DetrimentalEffects* det;
  2163. vector<LuaSpell*> remove_list;
  2164. LuaSpell* spell = 0;
  2165. vector<LevelArray*>* levels;
  2166. int8 caster_class1 = 0;
  2167. int8 caster_class2 = 0;
  2168. int8 caster_class3 = 0;
  2169. InfoStruct* info_struct = 0;
  2170. bool pass_level_check = false;
  2171. MDetriments.readlock(__FUNCTION__, __LINE__);
  2172. for (int32 i = 0; i<det_list->size(); i++){
  2173. det = &det_list->at(i);
  2174. if (det && det->control_effect == control_type && !det->incurable){
  2175. levels = det->spell->spell->GetSpellLevels();
  2176. info_struct = det->caster->GetInfoStruct();
  2177. pass_level_check = false;
  2178. for (int32 x = 0; x < levels->size(); x++){
  2179. if (!cure_level || cure_level >= (levels->at(x)->spell_level / 10)){
  2180. pass_level_check = true;
  2181. break;
  2182. }
  2183. }
  2184. if (pass_level_check){
  2185. remove_list.push_back(det->spell);
  2186. cure_count--;
  2187. if (cure_count == 0)
  2188. break;
  2189. }
  2190. }
  2191. }
  2192. MDetriments.releasereadlock(__FUNCTION__, __LINE__);
  2193. for (int32 i = 0; i<remove_list.size(); i++){
  2194. spell = remove_list.at(i);
  2195. GetZone()->SendDispellPacket(caster, this, cure_name, (string)remove_list.at(i)->spell->GetName(), DISPELL_TYPE_CURE);
  2196. if (GetZone())
  2197. GetZone()->RemoveTargetFromSpell(spell, this);
  2198. RemoveSpellEffect(spell);
  2199. RemoveDetrimentalSpell(spell);
  2200. }
  2201. remove_list.clear();
  2202. }
  2203. void Entity::RemoveDetrimentalSpell(LuaSpell* spell) {
  2204. if(!spell || (spell->spell && spell->spell->GetSpellData() && spell->spell->GetSpellData()->det_type == 0))
  2205. return;
  2206. MDetriments.writelock(__FUNCTION__, __LINE__);
  2207. vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
  2208. vector<DetrimentalEffects>::iterator itr;
  2209. for(itr = det_list->begin(); itr != det_list->end(); itr++){
  2210. if((*itr).spell == spell){
  2211. det_count_list[(*itr).det_type]--;
  2212. det_list->erase(itr);
  2213. if(IsPlayer())
  2214. ((Player*)this)->SetCharSheetChanged(true);
  2215. break;
  2216. }
  2217. }
  2218. MDetriments.releasewritelock(__FUNCTION__, __LINE__);
  2219. }
  2220. int8 Entity::GetDetTypeCount(int8 det_type){
  2221. return det_count_list[det_type];
  2222. }
  2223. int8 Entity::GetDetCount() {
  2224. int8 det_count = 0;
  2225. map<int8, int8>::iterator itr;
  2226. for(itr=det_count_list.begin(); itr != det_count_list.end(); itr++)
  2227. det_count += (*itr).second;
  2228. return det_count;
  2229. }
  2230. vector<DetrimentalEffects>* Entity::GetDetrimentalSpellEffects() {
  2231. return &detrimental_spell_effects;
  2232. }
  2233. void Entity::AddDetrimentalSpell(LuaSpell* luaspell, int32 override_expire_timestamp){
  2234. if(!luaspell || !luaspell->caster)
  2235. return;
  2236. Spell* spell = luaspell->spell;
  2237. DetrimentalEffects* det = GetDetrimentalEffect(spell->GetSpellID(), luaspell->caster);
  2238. DetrimentalEffects new_det;
  2239. if(det)
  2240. RemoveDetrimentalSpell(det->spell);
  2241. SpellData* data = spell->GetSpellData();
  2242. if(!data)
  2243. return;
  2244. new_det.caster = luaspell->caster;
  2245. new_det.spell = luaspell;
  2246. if (spell->GetSpellData()->duration_until_cancel)
  2247. new_det.expire_timestamp = 0xFFFFFFFF;
  2248. else if(override_expire_timestamp)
  2249. new_det.expire_timestamp = override_expire_timestamp;
  2250. else
  2251. new_det.expire_timestamp = Timer::GetCurrentTime2() + (spell->GetSpellDuration()*100);
  2252. new_det.icon = data->icon;
  2253. new_det.icon_backdrop = data->icon_backdrop;
  2254. new_det.tier = data->tier;
  2255. new_det.det_type = data->det_type;
  2256. new_det.incurable = data->incurable;
  2257. new_det.spell_id = spell->GetSpellID();
  2258. new_det.control_effect = data->control_effect_type;
  2259. new_det.total_time = spell->GetSpellDuration()/10;
  2260. MDetriments.writelock(__FUNCTION__, __LINE__);
  2261. detrimental_spell_effects.push_back(new_det);
  2262. det_count_list[new_det.det_type]++;
  2263. MDetriments.releasewritelock(__FUNCTION__, __LINE__);
  2264. }
  2265. DetrimentalEffects* Entity::GetDetrimentalEffect(int32 spell_id, Entity* caster){
  2266. vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
  2267. DetrimentalEffects* ret = 0;
  2268. MDetriments.readlock(__FUNCTION__, __LINE__);
  2269. for(int32 i=0; i<det_list->size(); i++){
  2270. if (det_list->at(i).spell_id == spell_id && det_list->at(i).caster == caster)
  2271. ret = &det_list->at(i);
  2272. }
  2273. MDetriments.releasereadlock(__FUNCTION__, __LINE__);
  2274. return ret;
  2275. }
  2276. void Entity::CancelAllStealth() {
  2277. bool did_change = false;
  2278. MutexList<LuaSpell*>* stealth_list = control_effects[CONTROL_EFFECT_TYPE_STEALTH];
  2279. if (stealth_list){
  2280. MutexList<LuaSpell*>::iterator itr = stealth_list->begin();
  2281. while (itr.Next()){
  2282. if (itr.value->caster == this)
  2283. GetZone()->GetSpellProcess()->AddSpellCancel(itr.value);
  2284. else{
  2285. GetZone()->RemoveTargetFromSpell(itr.value, this);
  2286. RemoveSpellEffect(itr.value);
  2287. }
  2288. did_change = true;
  2289. }
  2290. }
  2291. MutexList<LuaSpell*>* invis_list = control_effects[CONTROL_EFFECT_TYPE_INVIS];
  2292. if (invis_list){
  2293. MutexList<LuaSpell*>::iterator invis_itr = invis_list->begin();
  2294. while (invis_itr.Next()){
  2295. if (invis_itr.value->caster == this)
  2296. GetZone()->GetSpellProcess()->AddSpellCancel(invis_itr.value);
  2297. else{
  2298. GetZone()->RemoveTargetFromSpell(invis_itr.value, this);
  2299. RemoveSpellEffect(invis_itr.value);
  2300. }
  2301. did_change = true;
  2302. }
  2303. }
  2304. if (did_change){
  2305. info_changed = true;
  2306. changed = true;
  2307. AddChangedZoneSpawn();
  2308. if (IsPlayer())
  2309. ((Player*)this)->SetCharSheetChanged(true);
  2310. }
  2311. }
  2312. bool Entity::IsStealthed(){
  2313. MutexList<LuaSpell*>* stealth_list = control_effects[CONTROL_EFFECT_TYPE_STEALTH];
  2314. return (!stealth_list || stealth_list->size(true) == 0) == false;
  2315. }
  2316. bool Entity::CanSeeInvis(Entity* target) {
  2317. if (!target)
  2318. return true;
  2319. if (!target->IsStealthed() && !target->IsInvis())
  2320. return true;
  2321. if (target->IsStealthed() && HasSeeHideSpell())
  2322. return true;
  2323. else if (target->IsInvis() && HasSeeInvisSpell())
  2324. return true;
  2325. return false;
  2326. }
  2327. bool Entity::IsInvis(){
  2328. MutexList<LuaSpell*>* invis_list = control_effects[CONTROL_EFFECT_TYPE_INVIS];
  2329. return (!invis_list || invis_list->size(true) == 0) == false;
  2330. }
  2331. void Entity::AddStealthSpell(LuaSpell* spell) {
  2332. if (!spell)
  2333. return;
  2334. if (!control_effects[CONTROL_EFFECT_TYPE_STEALTH])
  2335. control_effects[CONTROL_EFFECT_TYPE_STEALTH] = new MutexList<LuaSpell*>;
  2336. control_effects[CONTROL_EFFECT_TYPE_STEALTH]->Add(spell);
  2337. if (control_effects[CONTROL_EFFECT_TYPE_STEALTH]->size(true) == 1){
  2338. info_changed = true;
  2339. changed = true;
  2340. AddChangedZoneSpawn();
  2341. if (IsPlayer() && ((Player*)this)->GetClient())
  2342. {
  2343. ((Player*)this)->SetCharSheetChanged(true);
  2344. GetZone()->SendAllSpawnsForVisChange(((Player*)this)->GetClient());
  2345. }
  2346. }
  2347. }
  2348. void Entity::AddInvisSpell(LuaSpell* spell) {
  2349. if (!spell)
  2350. return;
  2351. if (!control_effects[CONTROL_EFFECT_TYPE_INVIS])
  2352. control_effects[CONTROL_EFFECT_TYPE_INVIS] = new MutexList<LuaSpell*>;
  2353. control_effects[CONTROL_EFFECT_TYPE_INVIS]->Add(spell);
  2354. if (control_effects[CONTROL_EFFECT_TYPE_INVIS]->size(true) == 1){
  2355. info_changed = true;
  2356. changed = true;
  2357. AddChangedZoneSpawn();
  2358. if (IsPlayer() && ((Player*)this)->GetClient())
  2359. {
  2360. ((Player*)this)->SetCharSheetChanged(true);
  2361. GetZone()->SendAllSpawnsForVisChange(((Player*)this)->GetClient());
  2362. }
  2363. }
  2364. }
  2365. void Entity::RemoveInvisSpell(LuaSpell* spell) {
  2366. MutexList<LuaSpell*>* invis_list = control_effects[CONTROL_EFFECT_TYPE_INVIS];
  2367. if (!invis_list || invis_list->size(true) == 0)
  2368. return;
  2369. invis_list->Remove(spell);
  2370. RemoveSpellEffect(spell);
  2371. if (invis_list->size(true) == 0){
  2372. info_changed = true;
  2373. changed = true;
  2374. AddChangedZoneSpawn();
  2375. if (IsPlayer() && ((Player*)this)->GetClient())
  2376. {
  2377. ((Player*)this)->SetCharSheetChanged(true);
  2378. GetZone()->SendAllSpawnsForVisChange(((Player*)this)->GetClient());
  2379. }
  2380. }
  2381. }
  2382. void Entity::RemoveStealthSpell(LuaSpell* spell) {
  2383. MutexList<LuaSpell*>* stealth_list = control_effects[CONTROL_EFFECT_TYPE_STEALTH];
  2384. if (!stealth_list || stealth_list->size(true) == 0)
  2385. return;
  2386. stealth_list->Remove(spell);
  2387. RemoveSpellEffect(spell);
  2388. if (stealth_list->size() == 0){
  2389. info_changed = true;
  2390. changed = true;
  2391. AddChangedZoneSpawn();
  2392. if (IsPlayer() && ((Player*)this)->GetClient())
  2393. {
  2394. ((Player*)this)->SetCharSheetChanged(true);
  2395. GetZone()->SendAllSpawnsForVisChange(((Player*)this)->GetClient());
  2396. }
  2397. }
  2398. }
  2399. void Entity::AddRootSpell(LuaSpell* spell) {
  2400. if (!spell)
  2401. return;
  2402. if (!control_effects[CONTROL_EFFECT_TYPE_ROOT])
  2403. control_effects[CONTROL_EFFECT_TYPE_ROOT] = new MutexList<LuaSpell*>;
  2404. if (control_effects[CONTROL_EFFECT_TYPE_ROOT]->size(true) == 0 && !IsRootImmune()) {
  2405. if (IsPlayer()){
  2406. if (!IsMezzedOrStunned())
  2407. ((Player*)this)->SetPlayerControlFlag(1, 8, true); // heading movement only
  2408. }
  2409. else
  2410. SetSpeedMultiplier(0.0f);
  2411. }
  2412. control_effects[CONTROL_EFFECT_TYPE_ROOT]->Add(spell);
  2413. }
  2414. void Entity::RemoveRootSpell(LuaSpell* spell) {
  2415. MutexList<LuaSpell*>* root_list = control_effects[CONTROL_EFFECT_TYPE_ROOT];
  2416. if (!root_list || root_list->size(true) == 0)
  2417. return;
  2418. root_list->Remove(spell);
  2419. if (root_list->size(true) == 0 && !IsRootImmune()) {
  2420. if (IsPlayer()){
  2421. if (!IsMezzedOrStunned())
  2422. ((Player*)this)->SetPlayerControlFlag(1, 8, false); // heading movement only
  2423. }
  2424. else {
  2425. // GetHighestSnare() will return 1.0f if no snares returning the spawn to full speed
  2426. SetSpeedMultiplier(GetHighestSnare());
  2427. }
  2428. if(!IsPlayer()) {
  2429. GetZone()->movementMgr->StopNavigation((Entity*)this);
  2430. ((Spawn*)this)->StopMovement();
  2431. }
  2432. }
  2433. }
  2434. void Entity::AddFearSpell(LuaSpell* spell){
  2435. if (!spell)
  2436. return;
  2437. if (!control_effects[CONTROL_EFFECT_TYPE_FEAR])
  2438. control_effects[CONTROL_EFFECT_TYPE_FEAR] = new MutexList<LuaSpell*>;
  2439. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_FEAR]->size(true) == 0 && !IsFearImmune()){
  2440. ((Player*)this)->SetPlayerControlFlag(4, 4, true); // feared
  2441. if (!IsMezzedOrStunned() && !IsStifled())
  2442. GetZone()->LockAllSpells((Player*)this);
  2443. }
  2444. if (!IsFearImmune() && IsNPC())
  2445. {
  2446. HaltMovement();
  2447. }
  2448. control_effects[CONTROL_EFFECT_TYPE_FEAR]->Add(spell);
  2449. }
  2450. void Entity::RemoveFearSpell(LuaSpell* spell){
  2451. MutexList<LuaSpell*>* fear_list = control_effects[CONTROL_EFFECT_TYPE_FEAR];
  2452. if (!fear_list || fear_list->size(true) == 0)
  2453. return;
  2454. fear_list->Remove(spell);
  2455. if (IsPlayer() && fear_list->size(true) == 0 && !IsFearImmune()){
  2456. ((Player*)this)->SetPlayerControlFlag(4, 4, false); // feared disabled
  2457. if (!IsMezzedOrStunned() && !IsStifled())
  2458. GetZone()->LockAllSpells((Player*)this);
  2459. }
  2460. if (IsNPC())
  2461. {
  2462. HaltMovement();
  2463. }
  2464. }
  2465. void Entity::AddSnareSpell(LuaSpell* spell) {
  2466. if (!spell)
  2467. return;
  2468. if (!control_effects[CONTROL_EFFECT_TYPE_SNARE])
  2469. control_effects[CONTROL_EFFECT_TYPE_SNARE] = new MutexList<LuaSpell*>;
  2470. control_effects[CONTROL_EFFECT_TYPE_SNARE]->Add(spell);
  2471. // Don't set speed multiplier if there is a root or no snare values
  2472. MutexList<LuaSpell*>* roots = control_effects[CONTROL_EFFECT_TYPE_ROOT];
  2473. if ((!roots || roots->size(true) == 0) && snare_values.size() > 0)
  2474. SetSpeedMultiplier(GetHighestSnare());
  2475. }
  2476. void Entity::RemoveSnareSpell(LuaSpell* spell) {
  2477. MutexList<LuaSpell*>* snare_list = control_effects[CONTROL_EFFECT_TYPE_SNARE];
  2478. if (!snare_list || snare_list->size(true) == 0)
  2479. return;
  2480. snare_list->Remove(spell);
  2481. snare_values.erase(spell);
  2482. //LogWrite(PLAYER__ERROR, 0, "Debug", "snare_values.size() = %u", snare_values.size());
  2483. // only change speeds if there are no roots
  2484. MutexList<LuaSpell*>* roots = control_effects[CONTROL_EFFECT_TYPE_ROOT];
  2485. if (!roots || roots->size(true) == 0) {
  2486. float multiplier = GetHighestSnare();
  2487. //LogWrite(PLAYER__ERROR, 0, "Debug", "GetHighestSnare() = %f", multiplier);
  2488. SetSpeedMultiplier(multiplier);
  2489. }
  2490. }
  2491. void Entity::SetSnareValue(LuaSpell* spell, float snare_val) {
  2492. if (!spell)
  2493. return;
  2494. snare_values[spell] = snare_val;
  2495. }
  2496. float Entity::GetHighestSnare() {
  2497. // For simplicity this will return the highest snare value, which is actually the lowest value
  2498. float ret = 1.0f;
  2499. float weight_diff = 0.0f;
  2500. if (IsPlayer() && rule_manager.GetGlobalRule(R_Player, WeightInflictsSpeed)->GetBool()) {
  2501. float weight_pct_impact = rule_manager.GetGlobalRule(R_Player, WeightPercentImpact)->GetFloat();
  2502. float weight_pct_cap = rule_manager.GetGlobalRule(R_Player, WeightPercentCap)->GetFloat();
  2503. if(weight_pct_impact > 1.0f) {
  2504. weight_pct_impact = 1.0f;
  2505. }
  2506. if(weight_pct_cap < weight_pct_impact) {
  2507. weight_pct_impact = weight_pct_cap;
  2508. }
  2509. int32 weight = GetInfoStruct()->get_weight();
  2510. int32 max_weight = GetInfoStruct()->get_max_weight();
  2511. if(weight > max_weight) {
  2512. int32 diff = weight - max_weight;
  2513. weight_diff = (float)diff * weight_pct_impact; // percentage impact rule on weight "per stone", default 1%
  2514. if(weight_diff > weight_pct_cap) // cap weight impact rule
  2515. weight_diff = weight_pct_cap; // cap weight impact rule
  2516. }
  2517. }
  2518. if (snare_values.size() == 0)
  2519. return ((ret - weight_diff) < 0.0f ) ? 0.0f : (ret - weight_diff);
  2520. map<LuaSpell*, float>::iterator itr;
  2521. for (itr = snare_values.begin(); itr != snare_values.end(); itr++) {
  2522. if (itr->second < ret)
  2523. ret = itr->second;
  2524. }
  2525. return ((ret - weight_diff) < 0.0f ) ? 0.0f : (ret - weight_diff);
  2526. }
  2527. bool Entity::IsSnared() {
  2528. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_SNARE])
  2529. return false;
  2530. MutexList<LuaSpell*>* snare_list = control_effects[CONTROL_EFFECT_TYPE_SNARE];
  2531. return (!snare_list || snare_list->size(true) == 0) == false;
  2532. }
  2533. bool Entity::IsMezzed(){
  2534. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_MEZ])
  2535. return false;
  2536. MutexList<LuaSpell*>* mez_spells = control_effects[CONTROL_EFFECT_TYPE_MEZ];
  2537. return (!mez_spells || mez_spells->size(true) == 0 || IsMezImmune()) == false;
  2538. }
  2539. bool Entity::IsStifled(){
  2540. if (!control_effects[CONTROL_EFFECT_TYPE_STIFLE])
  2541. return false;
  2542. MutexList<LuaSpell*>* stifle_list = control_effects[CONTROL_EFFECT_TYPE_STIFLE];
  2543. return (!stifle_list || stifle_list->size(true) == 0 || IsStifleImmune()) == false;
  2544. }
  2545. bool Entity::IsDazed(){
  2546. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_DAZE])
  2547. return false;
  2548. MutexList<LuaSpell*>* daze_list = control_effects[CONTROL_EFFECT_TYPE_DAZE];
  2549. return (!daze_list || daze_list->size(true) == 0 || IsDazeImmune()) == false;
  2550. }
  2551. bool Entity::IsStunned(){
  2552. if (!control_effects[CONTROL_EFFECT_TYPE_STUN])
  2553. return false;
  2554. MutexList<LuaSpell*>* stun_list = control_effects[CONTROL_EFFECT_TYPE_STUN];
  2555. return (!stun_list || stun_list->size(true) == 0 || IsStunImmune()) == false;
  2556. }
  2557. bool Entity::IsRooted(){
  2558. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_ROOT])
  2559. return false;
  2560. MutexList<LuaSpell*>* root_list = control_effects[CONTROL_EFFECT_TYPE_ROOT];
  2561. return (!root_list || root_list->size(true) == 0 || IsRootImmune()) == false;
  2562. }
  2563. bool Entity::IsFeared(){
  2564. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_FEAR])
  2565. return false;
  2566. MutexList<LuaSpell*>* fear_list = control_effects[CONTROL_EFFECT_TYPE_FEAR];
  2567. return (!fear_list || fear_list->size(true) == 0 || IsFearImmune()) == false;
  2568. }
  2569. void Entity::AddWaterwalkSpell(LuaSpell* spell){
  2570. if (!spell)
  2571. return;
  2572. if (!control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER])
  2573. control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER] = new MutexList<LuaSpell*>;
  2574. control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER]->Add(spell);
  2575. if (control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER]->size(true) == 1 && IsPlayer())
  2576. ((Player*)this)->SetPlayerControlFlag(3, 128, true); // enable walking underwater
  2577. }
  2578. void Entity::RemoveWaterwalkSpell(LuaSpell* spell){
  2579. MutexList<LuaSpell*>* waterwalk_list = control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER];
  2580. if (!waterwalk_list || waterwalk_list->size(true) == 0)
  2581. return;
  2582. waterwalk_list->Remove(spell);
  2583. if (waterwalk_list->size(true) == 0 && IsPlayer())
  2584. ((Player*)this)->SetPlayerControlFlag(3, 128, false); // disable walking underwater
  2585. }
  2586. void Entity::AddWaterjumpSpell(LuaSpell* spell){
  2587. if (!spell)
  2588. return;
  2589. if (!control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER])
  2590. control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER] = new MutexList<LuaSpell*>;
  2591. control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER]->Add(spell);
  2592. if (control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER]->size(true) == 1 && IsPlayer())
  2593. ((Player*)this)->SetPlayerControlFlag(4, 1, true); // enable moonjumps underwater
  2594. }
  2595. void Entity::RemoveWaterjumpSpell(LuaSpell* spell){
  2596. MutexList<LuaSpell*>* waterjump_list = control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER];
  2597. if (!waterjump_list || waterjump_list->size(true) == 0)
  2598. return;
  2599. waterjump_list->Remove(spell);
  2600. if (waterjump_list->size(true) == 0 && IsPlayer())
  2601. ((Player*)this)->SetPlayerControlFlag(4, 1, false); // disable moonjumps underwater
  2602. }
  2603. void Entity::AddAOEImmunity(LuaSpell* spell){
  2604. if (!spell)
  2605. return;
  2606. if (!immunities[IMMUNITY_TYPE_AOE])
  2607. immunities[IMMUNITY_TYPE_AOE] = new MutexList<LuaSpell*>;
  2608. immunities[IMMUNITY_TYPE_AOE]->Add(spell);
  2609. }
  2610. void Entity::RemoveAOEImmunity(LuaSpell* spell){
  2611. MutexList<LuaSpell*>* aoe_list = immunities[IMMUNITY_TYPE_AOE];
  2612. if (!aoe_list || aoe_list->size(true) == 0)
  2613. return;
  2614. aoe_list->Remove(spell);
  2615. }
  2616. bool Entity::IsAOEImmune(){
  2617. return (immunities[IMMUNITY_TYPE_AOE] && immunities[IMMUNITY_TYPE_AOE]->size(true));
  2618. }
  2619. void Entity::AddStunImmunity(LuaSpell* spell){
  2620. if (!spell)
  2621. return;
  2622. if (!immunities[IMMUNITY_TYPE_STUN])
  2623. immunities[IMMUNITY_TYPE_STUN] = new MutexList<LuaSpell*>;
  2624. if (IsPlayer() && IsStunned() && !IsMezzed()){
  2625. ((Player*)this)->SetPlayerControlFlag(4, 64, false);
  2626. if (!IsFeared() && !IsStifled())
  2627. ((Player*)this)->UnlockAllSpells();
  2628. }
  2629. immunities[IMMUNITY_TYPE_STUN]->Add(spell);
  2630. }
  2631. void Entity::RemoveStunImmunity(LuaSpell* spell){
  2632. MutexList<LuaSpell*>* stun_list = immunities[IMMUNITY_TYPE_STUN];
  2633. if (!stun_list || stun_list->size(true) == 0)
  2634. return;
  2635. stun_list->Remove(spell);
  2636. if (IsPlayer() && IsStunned() && !IsMezzed()){
  2637. ((Player*)this)->SetPlayerControlFlag(4, 64, true);
  2638. if (!IsFeared() && !IsStifled())
  2639. ((Player*)this)->UnlockAllSpells();
  2640. }
  2641. }
  2642. bool Entity::IsStunImmune(){
  2643. return (immunities[IMMUNITY_TYPE_STUN] && immunities[IMMUNITY_TYPE_STUN]->size(true) > 0);
  2644. }
  2645. void Entity::AddStifleImmunity(LuaSpell* spell){
  2646. if (!spell)
  2647. return;
  2648. if (!immunities[IMMUNITY_TYPE_STIFLE])
  2649. immunities[IMMUNITY_TYPE_STIFLE] = new MutexList<LuaSpell*>;
  2650. if (IsPlayer() && immunities[IMMUNITY_TYPE_STIFLE]->size(true) == 0){
  2651. if (IsStifled() && !IsMezzedOrStunned() && !IsFeared())
  2652. ((Player*)this)->UnlockAllSpells();
  2653. }
  2654. immunities[IMMUNITY_TYPE_STIFLE]->Add(spell);
  2655. }
  2656. void Entity::RemoveStifleImmunity(LuaSpell* spell){
  2657. MutexList<LuaSpell*>* stifle_list = immunities[IMMUNITY_TYPE_STIFLE];
  2658. if (!stifle_list || stifle_list->size(true) == 0)
  2659. return;
  2660. stifle_list->Remove(spell);
  2661. if (IsPlayer() && IsStifled() && !IsMezzedOrStunned() && !IsFeared())
  2662. ((Player*)this)->UnlockAllSpells();
  2663. }
  2664. bool Entity::IsStifleImmune(){
  2665. return (immunities[IMMUNITY_TYPE_STIFLE] && immunities[IMMUNITY_TYPE_STIFLE]->size(true) > 0);
  2666. }
  2667. void Entity::AddMezImmunity(LuaSpell* spell){
  2668. if (!spell)
  2669. return;
  2670. if (!immunities[IMMUNITY_TYPE_MEZ])
  2671. immunities[IMMUNITY_TYPE_MEZ] = new MutexList<LuaSpell*>;
  2672. if (IsPlayer() && IsMezzed() && !IsStunned()){
  2673. ((Player*)this)->SetPlayerControlFlag(4, 64, false);
  2674. if (!IsFeared() && !IsStifled())
  2675. ((Player*)this)->UnlockAllSpells();
  2676. }
  2677. immunities[IMMUNITY_TYPE_MEZ]->Add(spell);
  2678. }
  2679. void Entity::RemoveMezImmunity(LuaSpell* spell){
  2680. MutexList<LuaSpell*>* mez_list = immunities[IMMUNITY_TYPE_MEZ];
  2681. if (!mez_list || mez_list->size(true) == 0)
  2682. return;
  2683. mez_list->Remove(spell);
  2684. if (IsPlayer() && IsMezzed() && !IsStunned()){
  2685. ((Player*)this)->SetPlayerControlFlag(4, 64, true);
  2686. if (!IsFeared() && !IsStifled())
  2687. ((Player*)this)->LockAllSpells();
  2688. }
  2689. }
  2690. bool Entity::IsMezImmune(){
  2691. return (immunities[IMMUNITY_TYPE_MEZ] && immunities[IMMUNITY_TYPE_MEZ]->size(true) > 0);
  2692. }
  2693. void Entity::AddRootImmunity(LuaSpell* spell){
  2694. if (!spell)
  2695. return;
  2696. if (!immunities[IMMUNITY_TYPE_ROOT])
  2697. immunities[IMMUNITY_TYPE_ROOT] = new MutexList<LuaSpell*>;
  2698. if (IsPlayer() && IsRooted())
  2699. ((Player*)this)->SetPlayerControlFlag(1, 8, false);
  2700. immunities[IMMUNITY_TYPE_ROOT]->Add(spell);
  2701. }
  2702. void Entity::RemoveRootImmunity(LuaSpell* spell){
  2703. MutexList<LuaSpell*>* root_list = immunities[IMMUNITY_TYPE_ROOT];
  2704. if (!root_list || root_list->size(true) == 0)
  2705. return;
  2706. root_list->Remove(spell);
  2707. if (IsPlayer() && IsRooted())
  2708. ((Player*)this)->SetPlayerControlFlag(1, 8, true);
  2709. }
  2710. bool Entity::IsRootImmune(){
  2711. return (immunities[IMMUNITY_TYPE_ROOT] && immunities[IMMUNITY_TYPE_ROOT]->size(true) > 0);
  2712. }
  2713. void Entity::AddFearImmunity(LuaSpell* spell){
  2714. if (!spell)
  2715. return;
  2716. if (!immunities[IMMUNITY_TYPE_FEAR])
  2717. immunities[IMMUNITY_TYPE_FEAR] = new MutexList<LuaSpell*>;
  2718. if (IsPlayer() && IsFeared()){
  2719. if (!IsMezzedOrStunned() && !IsStifled())
  2720. ((Player*)this)->UnlockAllSpells();
  2721. ((Player*)this)->SetPlayerControlFlag(4, 4, false);
  2722. }
  2723. immunities[IMMUNITY_TYPE_FEAR]->Add(spell);
  2724. }
  2725. void Entity::RemoveFearImmunity(LuaSpell* spell){
  2726. MutexList<LuaSpell*>* fear_list = immunities[IMMUNITY_TYPE_FEAR];
  2727. if (!fear_list || fear_list->size(true) == 0)
  2728. return;
  2729. fear_list->Remove(spell);
  2730. if (IsPlayer() && IsFeared()){
  2731. if (!IsMezzedOrStunned() && !IsStifled())
  2732. ((Player*)this)->LockAllSpells();
  2733. ((Player*)this)->SetPlayerControlFlag(4, 4, true);
  2734. }
  2735. }
  2736. bool Entity::IsFearImmune(){
  2737. return (immunities[IMMUNITY_TYPE_FEAR] && immunities[IMMUNITY_TYPE_FEAR]->size(true) > 0);
  2738. }
  2739. void Entity::AddDazeImmunity(LuaSpell* spell){
  2740. if (!spell)
  2741. return;
  2742. if (!immunities[IMMUNITY_TYPE_DAZE])
  2743. immunities[IMMUNITY_TYPE_DAZE] = new MutexList<LuaSpell*>;
  2744. immunities[IMMUNITY_TYPE_DAZE]->Add(spell);
  2745. }
  2746. void Entity::RemoveDazeImmunity(LuaSpell* spell){
  2747. MutexList<LuaSpell*>* daze_list = immunities[IMMUNITY_TYPE_DAZE];
  2748. if (!daze_list || daze_list->size(true) == 0)
  2749. return;
  2750. daze_list->Remove(spell);
  2751. }
  2752. bool Entity::IsDazeImmune(){
  2753. return (immunities[IMMUNITY_TYPE_DAZE] && immunities[IMMUNITY_TYPE_DAZE]->size(true) > 0);
  2754. }
  2755. void Entity::AddImmunity(LuaSpell* spell, int16 type){
  2756. if (!spell)
  2757. return;
  2758. if (!immunities[type])
  2759. immunities[type] = new MutexList<LuaSpell*>;
  2760. immunities[type]->Add(spell);
  2761. }
  2762. void Entity::RemoveImmunity(LuaSpell* spell, int16 type){
  2763. MutexList<LuaSpell*>* list = immunities[type];
  2764. if (!list || list->size(true) == 0)
  2765. return;
  2766. list->Remove(spell);
  2767. }
  2768. bool Entity::IsImmune(int16 type){
  2769. return (immunities[type] && immunities[type]->size(true) > 0);
  2770. }
  2771. void Entity::RemoveEffectsFromLuaSpell(LuaSpell* spell){
  2772. if (!spell)
  2773. return;
  2774. //Attempt to remove all applied effects from this spell when spell has been removed from just this target. Should improve performance/easier maitenance
  2775. int32 effect_bitmask = spell->effect_bitmask;
  2776. if (effect_bitmask == 0)
  2777. return;
  2778. if (effect_bitmask & EFFECT_FLAG_STUN)
  2779. RemoveStunSpell(spell);
  2780. if (effect_bitmask & EFFECT_FLAG_ROOT)
  2781. RemoveRootSpell(spell);
  2782. if (effect_bitmask & EFFECT_FLAG_MEZ)
  2783. RemoveMezSpell(spell);
  2784. if (effect_bitmask & EFFECT_FLAG_STIFLE)
  2785. RemoveStifleSpell(spell);
  2786. if (effect_bitmask & EFFECT_FLAG_DAZE)
  2787. RemoveDazeSpell(spell);
  2788. if (effect_bitmask & EFFECT_FLAG_FEAR)
  2789. RemoveFearSpell(spell);
  2790. if (effect_bitmask & EFFECT_FLAG_SPELLBONUS)
  2791. RemoveSpellBonus(spell);
  2792. if (effect_bitmask & EFFECT_FLAG_SKILLBONUS)
  2793. RemoveSkillBonus(spell->spell->GetSpellID());
  2794. if (effect_bitmask & EFFECT_FLAG_STEALTH)
  2795. RemoveStealthSpell(spell);
  2796. if (effect_bitmask & EFFECT_FLAG_INVIS)
  2797. RemoveInvisSpell(spell);
  2798. if (effect_bitmask & EFFECT_FLAG_SNARE)
  2799. RemoveSnareSpell(spell);
  2800. if (effect_bitmask & EFFECT_FLAG_WATERWALK)
  2801. RemoveWaterwalkSpell(spell);
  2802. if (effect_bitmask & EFFECT_FLAG_WATERJUMP)
  2803. RemoveWaterjumpSpell(spell);
  2804. if (effect_bitmask & EFFECT_FLAG_FLIGHT)
  2805. RemoveFlightSpell(spell);
  2806. if (effect_bitmask & EFFECT_FLAG_GLIDE)
  2807. RemoveGlideSpell(spell);
  2808. if (effect_bitmask & EFFECT_FLAG_AOE_IMMUNE)
  2809. RemoveAOEImmunity(spell);
  2810. if (effect_bitmask & EFFECT_FLAG_STUN_IMMUNE)
  2811. RemoveStunImmunity(spell);
  2812. if (effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE)
  2813. RemoveMezImmunity(spell);
  2814. if (effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE)
  2815. RemoveDazeImmunity(spell);
  2816. if (effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE)
  2817. RemoveRootImmunity(spell);
  2818. if (effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE)
  2819. RemoveStifleImmunity(spell);
  2820. if (effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE)
  2821. RemoveFearImmunity(spell);
  2822. if (effect_bitmask & EFFECT_FLAG_SAFEFALL)
  2823. RemoveSafefallSpell(spell);
  2824. }
  2825. void Entity::RemoveSkillBonus(int32 spell_id){
  2826. //This is a virtual, just making it so we don't have to do extra checks for player/npcs
  2827. return;
  2828. }
  2829. void Entity::AddFlightSpell(LuaSpell* spell){
  2830. if (!spell)
  2831. return;
  2832. if (!control_effects[CONTROL_EFFECT_TYPE_FLIGHT])
  2833. control_effects[CONTROL_EFFECT_TYPE_FLIGHT] = new MutexList<LuaSpell*>;
  2834. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_FLIGHT]->size(true) == 0)
  2835. ((Player*)this)->SetPlayerControlFlag(5, 32, true);
  2836. control_effects[CONTROL_EFFECT_TYPE_FLIGHT]->Add(spell);
  2837. }
  2838. void Entity::RemoveFlightSpell(LuaSpell* spell){
  2839. MutexList<LuaSpell*>* flight_list = control_effects[CONTROL_EFFECT_TYPE_FLIGHT];
  2840. if (!flight_list || flight_list->size(true) == 0)
  2841. return;
  2842. flight_list->Remove(spell);
  2843. if (IsPlayer() && flight_list->size(true) == 0)
  2844. ((Player*)this)->SetPlayerControlFlag(5, 32, false);
  2845. }
  2846. void Entity::AddGlideSpell(LuaSpell* spell){
  2847. if (!spell)
  2848. return;
  2849. if (!control_effects[CONTROL_EFFECT_TYPE_GLIDE])
  2850. control_effects[CONTROL_EFFECT_TYPE_GLIDE] = new MutexList<LuaSpell*>;
  2851. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_GLIDE]->size(true) == 0)
  2852. ((Player*)this)->SetPlayerControlFlag(4, 16, true);
  2853. control_effects[CONTROL_EFFECT_TYPE_GLIDE]->Add(spell);
  2854. }
  2855. void Entity::RemoveGlideSpell(LuaSpell* spell){
  2856. MutexList<LuaSpell*>* glide_list = control_effects[CONTROL_EFFECT_TYPE_GLIDE];
  2857. if (!glide_list || glide_list->size(true) == 0)
  2858. return;
  2859. glide_list->Remove(spell);
  2860. if (IsPlayer() && glide_list->size(true) == 0)
  2861. ((Player*)this)->SetPlayerControlFlag(4, 16, false);
  2862. }
  2863. void Entity::AddSafefallSpell(LuaSpell* spell){
  2864. if (!spell)
  2865. return;
  2866. if (!control_effects[CONTROL_EFFECT_TYPE_SAFEFALL])
  2867. control_effects[CONTROL_EFFECT_TYPE_SAFEFALL] = new MutexList<LuaSpell*>;
  2868. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_SAFEFALL]->size(true) == 0)
  2869. ((Player*)this)->SetPlayerControlFlag(4, 32, true);
  2870. control_effects[CONTROL_EFFECT_TYPE_SAFEFALL]->Add(spell);
  2871. }
  2872. void Entity::RemoveSafefallSpell(LuaSpell* spell){
  2873. MutexList<LuaSpell*>* safe_list = control_effects[CONTROL_EFFECT_TYPE_SAFEFALL];
  2874. if (!safe_list || safe_list->size(true) == 0)
  2875. return;
  2876. safe_list->Remove(spell);
  2877. if (IsPlayer() && safe_list->size(true) == 0)
  2878. ((Player*)this)->SetPlayerControlFlag(4, 32, false);
  2879. }
  2880. void Entity::UpdateGroupMemberInfo(bool inGroupMgrLock, bool groupMembersLocked) {
  2881. if (!group_member_info || group_id == 0)
  2882. return;
  2883. if(!inGroupMgrLock)
  2884. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  2885. PlayerGroup* group = world.GetGroupManager()->GetGroup(group_id);
  2886. if (group)
  2887. group->UpdateGroupMemberInfo(this, groupMembersLocked);
  2888. if(!inGroupMgrLock)
  2889. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  2890. }
  2891. #include "WorldDatabase.h"
  2892. extern WorldDatabase database;
  2893. void Entity::CustomizeAppearance(PacketStruct* packet) {
  2894. bool is_soga = packet->getType_int8_ByName("is_soga") == 1 ? true : false;
  2895. int16 model_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("race_file").data);
  2896. EQ2_Color skin_color = packet->getType_EQ2_Color_ByName("skin_color");
  2897. EQ2_Color skin_color2 = packet->getType_EQ2_Color_ByName("skin_color2");
  2898. EQ2_Color eye_color = packet->getType_EQ2_Color_ByName("eye_color");
  2899. EQ2_Color hair_color1 = packet->getType_EQ2_Color_ByName("hair_color1");
  2900. EQ2_Color hair_color2 = packet->getType_EQ2_Color_ByName("hair_color2");
  2901. EQ2_Color hair_highlight = packet->getType_EQ2_Color_ByName("hair_highlight");
  2902. int16 hair_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("hair_file").data);
  2903. EQ2_Color hair_type_color = packet->getType_EQ2_Color_ByName("hair_type_color");
  2904. EQ2_Color hair_type_highlight_color = packet->getType_EQ2_Color_ByName("hair_type_highlight_color");
  2905. int16 face_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("face_file").data);
  2906. EQ2_Color hair_face_color = packet->getType_EQ2_Color_ByName("hair_face_color");
  2907. EQ2_Color hair_face_highlight_color = packet->getType_EQ2_Color_ByName("hair_face_highlight_color");
  2908. int16 wing_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("wing_file").data);
  2909. EQ2_Color wing_color1 = packet->getType_EQ2_Color_ByName("wing_color1");
  2910. EQ2_Color wing_color2 = packet->getType_EQ2_Color_ByName("wing_color2");
  2911. int16 chest_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("chest_file").data);
  2912. EQ2_Color shirt_color = packet->getType_EQ2_Color_ByName("shirt_color");
  2913. EQ2_Color unknown_chest_color = packet->getType_EQ2_Color_ByName("unknown_chest_color");
  2914. int16 legs_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("legs_file").data);
  2915. EQ2_Color pants_color = packet->getType_EQ2_Color_ByName("pants_color");
  2916. EQ2_Color unknown_legs_color = packet->getType_EQ2_Color_ByName("unknown_legs_color");
  2917. EQ2_Color unknown2 = packet->getType_EQ2_Color_ByName("unknown2");
  2918. float eyes2[3];
  2919. eyes2[0] = packet->getType_float_ByName("eyes2", 0) * 100;
  2920. eyes2[1] = packet->getType_float_ByName("eyes2", 1) * 100;
  2921. eyes2[2] = packet->getType_float_ByName("eyes2", 2) * 100;
  2922. float ears[3];
  2923. ears[0] = packet->getType_float_ByName("ears", 0) * 100;
  2924. ears[1] = packet->getType_float_ByName("ears", 1) * 100;
  2925. ears[2] = packet->getType_float_ByName("ears", 2) * 100;
  2926. float eye_brows[3];
  2927. eye_brows[0] = packet->getType_float_ByName("eye_brows", 0) * 100;
  2928. eye_brows[1] = packet->getType_float_ByName("eye_brows", 1) * 100;
  2929. eye_brows[2] = packet->getType_float_ByName("eye_brows", 2) * 100;
  2930. float cheeks[3];
  2931. cheeks[0] = packet->getType_float_ByName("cheeks", 0) * 100;
  2932. cheeks[1] = packet->getType_float_ByName("cheeks", 1) * 100;
  2933. cheeks[2] = packet->getType_float_ByName("cheeks", 2) * 100;
  2934. float lips[3];
  2935. lips[0] = packet->getType_float_ByName("lips", 0) * 100;
  2936. lips[1] = packet->getType_float_ByName("lips", 1) * 100;
  2937. lips[2] = packet->getType_float_ByName("lips", 2) * 100;
  2938. float chin[3];
  2939. chin[0] = packet->getType_float_ByName("chin", 0) * 100;
  2940. chin[1] = packet->getType_float_ByName("chin", 1) * 100;
  2941. chin[2] = packet->getType_float_ByName("chin", 2) * 100;
  2942. float nose[3];
  2943. nose[0] = packet->getType_float_ByName("nose", 0) * 100;
  2944. nose[1] = packet->getType_float_ByName("nose", 1) * 100;
  2945. nose[2] = packet->getType_float_ByName("nose", 2) * 100;
  2946. sint8 body_size = (sint8)(packet->getType_float_ByName("body_size") * 100);
  2947. sint8 body_age = (sint8)(packet->getType_float_ByName("body_age") * 100);
  2948. if (is_soga) {
  2949. appearance.soga_model_type = model_id;
  2950. features.soga_skin_color = skin_color;
  2951. features.soga_eye_color = eye_color;
  2952. features.soga_hair_color1 = hair_color1;
  2953. features.soga_hair_color2 = hair_color2;
  2954. features.soga_hair_highlight_color = hair_highlight;
  2955. features.soga_hair_type = hair_id;
  2956. features.soga_hair_type_color = hair_type_color;
  2957. features.soga_hair_type_highlight_color = hair_type_highlight_color;
  2958. features.soga_hair_face_type = face_id;
  2959. features.soga_hair_face_color = hair_face_color;
  2960. features.soga_hair_face_highlight_color = hair_face_highlight_color;
  2961. features.wing_type = wing_id;
  2962. features.wing_color1 = wing_color1;
  2963. features.wing_color2 = wing_color2;
  2964. features.soga_chest_type = chest_id;
  2965. features.shirt_color = shirt_color;
  2966. features.soga_legs_type = legs_id;
  2967. features.pants_color = pants_color;
  2968. features.soga_eye_type[0] = eyes2[0];
  2969. features.soga_eye_type[1] = eyes2[1];
  2970. features.soga_eye_type[2] = eyes2[2];
  2971. features.soga_ear_type[0] = ears[0];
  2972. features.soga_ear_type[0] = ears[1];
  2973. features.soga_ear_type[0] = ears[2];
  2974. features.soga_eye_brow_type[0] = eye_brows[0];
  2975. features.soga_eye_brow_type[1] = eye_brows[1];
  2976. features.soga_eye_brow_type[2] = eye_brows[2];
  2977. features.soga_cheek_type[0] = cheeks[0];
  2978. features.soga_cheek_type[1] = cheeks[1];
  2979. features.soga_cheek_type[2] = cheeks[2];
  2980. features.soga_lip_type[0] = lips[0];
  2981. features.soga_lip_type[1] = lips[1];
  2982. features.soga_lip_type[2] = lips[2];
  2983. features.soga_chin_type[0] = chin[0];
  2984. features.soga_chin_type[1] = chin[1];
  2985. features.soga_chin_type[2] = chin[2];
  2986. features.soga_nose_type[0] = nose[0];
  2987. features.soga_nose_type[1] = nose[1];
  2988. features.soga_nose_type[2] = nose[2];
  2989. }
  2990. else {
  2991. appearance.model_type = model_id;
  2992. features.skin_color = skin_color;
  2993. features.eye_color = eye_color;
  2994. features.hair_color1 = hair_color1;
  2995. features.hair_color2 = hair_color2;
  2996. features.hair_highlight_color = hair_highlight;
  2997. features.hair_type = hair_id;
  2998. features.hair_type_color = hair_type_color;
  2999. features.hair_type_highlight_color = hair_type_highlight_color;
  3000. features.hair_face_type = face_id;
  3001. features.hair_face_color = hair_face_color;
  3002. features.hair_face_highlight_color = hair_face_highlight_color;
  3003. features.wing_type = wing_id;
  3004. features.wing_color1 = wing_color1;
  3005. features.wing_color2 = wing_color2;
  3006. features.chest_type = chest_id;
  3007. features.shirt_color = shirt_color;
  3008. features.legs_type = legs_id;
  3009. features.pants_color = pants_color;
  3010. features.eye_type[0] = eyes2[0];
  3011. features.eye_type[1] = eyes2[1];
  3012. features.eye_type[2] = eyes2[2];
  3013. features.ear_type[0] = ears[0];
  3014. features.ear_type[0] = ears[1];
  3015. features.ear_type[0] = ears[2];
  3016. features.eye_brow_type[0] = eye_brows[0];
  3017. features.eye_brow_type[1] = eye_brows[1];
  3018. features.eye_brow_type[2] = eye_brows[2];
  3019. features.cheek_type[0] = cheeks[0];
  3020. features.cheek_type[1] = cheeks[1];
  3021. features.cheek_type[2] = cheeks[2];
  3022. features.lip_type[0] = lips[0];
  3023. features.lip_type[1] = lips[1];
  3024. features.lip_type[2] = lips[2];
  3025. features.chin_type[0] = chin[0];
  3026. features.chin_type[1] = chin[1];
  3027. features.chin_type[2] = chin[2];
  3028. features.nose_type[0] = nose[0];
  3029. features.nose_type[1] = nose[1];
  3030. features.nose_type[2] = nose[2];
  3031. }
  3032. features.body_size = body_size;
  3033. features.body_age = body_age;
  3034. features.soga_body_size = body_size;
  3035. features.soga_body_age = body_age;
  3036. info_changed = true;
  3037. changed = true;
  3038. }
  3039. void Entity::AddSkillBonus(int32 spell_id, int32 skill_id, float value) {
  3040. // handled in npc or player
  3041. return;
  3042. }
  3043. bool Entity::HasControlEffect(int8 type)
  3044. {
  3045. if (type >= CONTROL_MAX_EFFECTS)
  3046. return false;
  3047. MutexList<LuaSpell*>* spell_list = control_effects[type];
  3048. if (!spell_list || spell_list->size(true) == 0)
  3049. return false;
  3050. return true;
  3051. }
  3052. void Entity::HaltMovement()
  3053. {
  3054. this->ClearRunningLocations();
  3055. if (GetZone())
  3056. GetZone()->movementMgr->StopNavigation(this);
  3057. RunToLocation(GetX(), GetY(), GetZ());
  3058. }
  3059. std::string Entity::GetInfoStructString(std::string field)
  3060. {
  3061. map<string, boost::function<std::string()>>::const_iterator itr = get_string_funcs.find(field);
  3062. if(itr != get_string_funcs.end())
  3063. {
  3064. auto func = (itr->second)();
  3065. return func;
  3066. }
  3067. return std::string("");
  3068. }
  3069. int8 Entity::GetInfoStructInt8(std::string field)
  3070. {
  3071. map<string, boost::function<int8()>>::const_iterator itr = get_int8_funcs.find(field);
  3072. if(itr != get_int8_funcs.end())
  3073. {
  3074. auto func = (itr->second)();
  3075. return func;
  3076. }
  3077. return 0;
  3078. }
  3079. int16 Entity::GetInfoStructInt16(std::string field)
  3080. {
  3081. map<string, boost::function<int16()>>::const_iterator itr = get_int16_funcs.find(field);
  3082. if(itr != get_int16_funcs.end())
  3083. {
  3084. auto func = (itr->second)();
  3085. return func;
  3086. }
  3087. return 0;
  3088. }
  3089. int32 Entity::GetInfoStructInt32(std::string field)
  3090. {
  3091. map<string, boost::function<int32()>>::const_iterator itr = get_int32_funcs.find(field);
  3092. if(itr != get_int32_funcs.end())
  3093. {
  3094. auto func = (itr->second)();
  3095. return func;
  3096. }
  3097. return 0;
  3098. }
  3099. int64 Entity::GetInfoStructInt64(std::string field)
  3100. {
  3101. map<string, boost::function<int64()>>::const_iterator itr = get_int64_funcs.find(field);
  3102. if(itr != get_int64_funcs.end())
  3103. {
  3104. auto func = (itr->second)();
  3105. return func;
  3106. }
  3107. return 0;
  3108. }
  3109. sint8 Entity::GetInfoStructSInt8(std::string field)
  3110. {
  3111. map<string, boost::function<sint8()>>::const_iterator itr = get_sint8_funcs.find(field);
  3112. if(itr != get_sint8_funcs.end())
  3113. {
  3114. auto func = (itr->second)();
  3115. return func;
  3116. }
  3117. return 0;
  3118. }
  3119. sint16 Entity::GetInfoStructSInt16(std::string field)
  3120. {
  3121. map<string, boost::function<sint16()>>::const_iterator itr = get_sint16_funcs.find(field);
  3122. if(itr != get_sint16_funcs.end())
  3123. {
  3124. auto func = (itr->second)();
  3125. return func;
  3126. }
  3127. return 0;
  3128. }
  3129. sint32 Entity::GetInfoStructSInt32(std::string field)
  3130. {
  3131. map<string, boost::function<sint32()>>::const_iterator itr = get_sint32_funcs.find(field);
  3132. if(itr != get_sint32_funcs.end())
  3133. {
  3134. auto func = (itr->second)();
  3135. return func;
  3136. }
  3137. return 0;
  3138. }
  3139. sint64 Entity::GetInfoStructSInt64(std::string field)
  3140. {
  3141. map<string, boost::function<sint64()>>::const_iterator itr = get_sint64_funcs.find(field);
  3142. if(itr != get_sint64_funcs.end())
  3143. {
  3144. auto func = (itr->second)();
  3145. return func;
  3146. }
  3147. return 0;
  3148. }
  3149. float Entity::GetInfoStructFloat(std::string field)
  3150. {
  3151. map<string, boost::function<float()>>::const_iterator itr = get_float_funcs.find(field);
  3152. if(itr != get_float_funcs.end())
  3153. {
  3154. auto func = (itr->second)();
  3155. return func;
  3156. }
  3157. return 0.0f;
  3158. }
  3159. int64 Entity::GetInfoStructUInt(std::string field)
  3160. {
  3161. map<string, boost::function<int8()>>::const_iterator itr = get_int8_funcs.find(field);
  3162. if(itr != get_int8_funcs.end())
  3163. {
  3164. auto func = (itr->second)();
  3165. return func;
  3166. }
  3167. map<string, boost::function<int16()>>::const_iterator itr2 = get_int16_funcs.find(field);
  3168. if(itr2 != get_int16_funcs.end())
  3169. {
  3170. auto func = (itr2->second)();
  3171. return func;
  3172. }
  3173. map<string, boost::function<int32()>>::const_iterator itr3 = get_int32_funcs.find(field);
  3174. if(itr3 != get_int32_funcs.end())
  3175. {
  3176. auto func = (itr3->second)();
  3177. return func;
  3178. }
  3179. map<string, boost::function<int64()>>::const_iterator itr4 = get_int64_funcs.find(field);
  3180. if(itr4 != get_int64_funcs.end())
  3181. {
  3182. auto func = (itr4->second)();
  3183. return func;
  3184. }
  3185. return 0;
  3186. }
  3187. sint64 Entity::GetInfoStructSInt(std::string field)
  3188. {
  3189. map<string, boost::function<sint8()>>::const_iterator itr = get_sint8_funcs.find(field);
  3190. if(itr != get_sint8_funcs.end())
  3191. {
  3192. auto func = (itr->second)();
  3193. return func;
  3194. }
  3195. map<string, boost::function<sint16()>>::const_iterator itr2 = get_sint16_funcs.find(field);
  3196. if(itr2 != get_sint16_funcs.end())
  3197. {
  3198. auto func = (itr2->second)();
  3199. return func;
  3200. }
  3201. map<string, boost::function<sint32()>>::const_iterator itr3 = get_sint32_funcs.find(field);
  3202. if(itr3 != get_sint32_funcs.end())
  3203. {
  3204. auto func = (itr3->second)();
  3205. return func;
  3206. }
  3207. map<string, boost::function<sint64()>>::const_iterator itr4 = get_sint64_funcs.find(field);
  3208. if(itr4 != get_sint64_funcs.end())
  3209. {
  3210. auto func = (itr4->second)();
  3211. return func;
  3212. }
  3213. return 0;
  3214. }
  3215. bool Entity::SetInfoStructString(std::string field, std::string value)
  3216. {
  3217. map<string, boost::function<void(std::string)>>::const_iterator itr = set_string_funcs.find(field);
  3218. if(itr != set_string_funcs.end())
  3219. {
  3220. (itr->second)(value);
  3221. return true;
  3222. }
  3223. return false;
  3224. }
  3225. bool Entity::SetInfoStructUInt(std::string field, int64 value)
  3226. {
  3227. map<string, boost::function<void(int8)>>::const_iterator itr = set_int8_funcs.find(field);
  3228. if(itr != set_int8_funcs.end())
  3229. {
  3230. (itr->second)((int8)value);
  3231. return true;
  3232. }
  3233. map<string, boost::function<void(int16)>>::const_iterator itr2 = set_int16_funcs.find(field);
  3234. if(itr2 != set_int16_funcs.end())
  3235. {
  3236. (itr2->second)((int16)value);
  3237. return true;
  3238. }
  3239. map<string, boost::function<void(int32)>>::const_iterator itr3 = set_int32_funcs.find(field);
  3240. if(itr3 != set_int32_funcs.end())
  3241. {
  3242. (itr3->second)((int32)value);
  3243. return true;
  3244. }
  3245. map<string, boost::function<void(int64)>>::const_iterator itr4 = set_int64_funcs.find(field);
  3246. if(itr4 != set_int64_funcs.end())
  3247. {
  3248. (itr4->second)(value);
  3249. return true;
  3250. }
  3251. return false;
  3252. }
  3253. bool Entity::SetInfoStructSInt(std::string field, sint64 value)
  3254. {
  3255. map<string, boost::function<void(sint8)>>::const_iterator itr = set_sint8_funcs.find(field);
  3256. if(itr != set_sint8_funcs.end())
  3257. {
  3258. (itr->second)((sint8)value);
  3259. return true;
  3260. }
  3261. map<string, boost::function<void(sint16)>>::const_iterator itr2 = set_sint16_funcs.find(field);
  3262. if(itr2 != set_sint16_funcs.end())
  3263. {
  3264. (itr2->second)((sint16)value);
  3265. return true;
  3266. }
  3267. map<string, boost::function<void(sint32)>>::const_iterator itr3 = set_sint32_funcs.find(field);
  3268. if(itr3 != set_sint32_funcs.end())
  3269. {
  3270. (itr3->second)((sint32)value);
  3271. return true;
  3272. }
  3273. map<string, boost::function<void(sint64)>>::const_iterator itr4 = set_sint64_funcs.find(field);
  3274. if(itr4 != set_sint64_funcs.end())
  3275. {
  3276. (itr4->second)(value);
  3277. return true;
  3278. }
  3279. return false;
  3280. }
  3281. bool Entity::SetInfoStructFloat(std::string field, float value)
  3282. {
  3283. map<string, boost::function<void(float)>>::const_iterator itr = set_float_funcs.find(field);
  3284. if(itr != set_float_funcs.end())
  3285. {
  3286. (itr->second)(value);
  3287. return true;
  3288. }
  3289. return false;
  3290. }
  3291. Entity* Entity::GetOwner() {
  3292. Entity* ent = nullptr;
  3293. if(!GetZone()) {
  3294. return ent;
  3295. }
  3296. Spawn* spawn = GetZone()->GetSpawnByID(owner);
  3297. if ( spawn && spawn->IsEntity() )
  3298. ent = (Entity*)spawn;
  3299. return ent;
  3300. }
  3301. bool Entity::IsEngagedInEncounter(Spawn** res) {
  3302. if(res) {
  3303. *res = nullptr;
  3304. }
  3305. bool ret = false;
  3306. set<int32>::iterator itr;
  3307. MHatedBy.lock();
  3308. if(IsPlayer()) {
  3309. for (itr = HatedBy.begin(); itr != HatedBy.end(); itr++) {
  3310. Spawn* spawn = GetZone()->GetSpawnByID(*itr);
  3311. if (spawn && spawn->IsNPC() && ((NPC*)spawn)->Brain() && (spawn->GetLockedNoLoot() == ENCOUNTER_STATE_LOCKED || spawn->GetLockedNoLoot() == ENCOUNTER_STATE_OVERMATCHED)) {
  3312. if((ret = ((NPC*)spawn)->Brain()->IsPlayerInEncounter(((Player*)this)->GetCharacterID()))) {
  3313. if(res)
  3314. *res = spawn;
  3315. break;
  3316. }
  3317. }
  3318. }
  3319. }
  3320. else {
  3321. for (itr = HatedBy.begin(); itr != HatedBy.end(); itr++) {
  3322. Spawn* spawn = GetZone()->GetSpawnByID(*itr);
  3323. if (spawn && spawn->IsNPC() && ((NPC*)spawn)->Brain() && (spawn->GetLockedNoLoot() == ENCOUNTER_STATE_LOCKED || spawn->GetLockedNoLoot() == ENCOUNTER_STATE_OVERMATCHED)) {
  3324. if((ret = ((NPC*)spawn)->Brain()->IsEntityInEncounter(GetID()))) {
  3325. if(res)
  3326. *res = spawn;
  3327. break;
  3328. }
  3329. }
  3330. }
  3331. }
  3332. MHatedBy.unlock();
  3333. return ret;
  3334. }
  3335. bool Entity::IsEngagedBySpawnID(int32 id) {
  3336. bool ret = false;
  3337. Spawn* spawn = GetZone()->GetSpawnByID(id);
  3338. if (spawn && spawn->IsNPC() && ((NPC*)spawn)->Brain()) {
  3339. ret = ((NPC*)spawn)->Brain()->IsEntityInEncounter(GetID());
  3340. }
  3341. return ret;
  3342. }
  3343. void Entity::SendControlEffectDetailsToClient(Client* client) {
  3344. client->Message(CHANNEL_COLOR_YELLOW, "Current control effects on %s", GetName());
  3345. client->Message(CHANNEL_COLOR_YELLOW, "-------------------------------");
  3346. for (int i = 0; i < CONTROL_MAX_EFFECTS; i++) {
  3347. if(control_effects[i]) {
  3348. MutexList<LuaSpell*>* spells = control_effects[i];
  3349. if(spells->size() > 0) {
  3350. MutexList<LuaSpell*>::iterator itr = spells->begin();
  3351. while(itr.Next()){
  3352. LuaSpell* spell = itr->value;
  3353. if(spell && spell->spell && spell->spell->GetSpellData()) {
  3354. client->Message(CHANNEL_COLOR_YELLOW, "Spell %s (%u) control effect %s", spell->spell->GetName(), spell->spell->GetSpellData()->id, GetControlEffectName(i).c_str());
  3355. }
  3356. }
  3357. }
  3358. }
  3359. }
  3360. client->Message(CHANNEL_COLOR_YELLOW, "-------------------------------");
  3361. }
  3362. void Entity::TerminateTrade() {
  3363. Trade* tmpTradePtr = trade;
  3364. if (tmpTradePtr) {
  3365. tmpTradePtr->CancelTrade(this);
  3366. safe_delete(tmpTradePtr);
  3367. }
  3368. }
  3369. void Entity::CalculateMaxReduction() {
  3370. if(GetInfoStruct()->get_max_spell_reduction_override()) {
  3371. return; // override enabled, don't touch the max reduction
  3372. }
  3373. int16 effective_level = GetInfoStruct()->get_effective_level() != 0 ? GetInfoStruct()->get_effective_level() : GetLevel();
  3374. // Define thresholds and corresponding maximum reduction factors
  3375. const int thresholds[] = {1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120}; // Thresholds for level differences
  3376. const float maxReductions[] = {0.2f, 0.2f, 0.15f, 0.15f, 0.1f,0.1f,0.1f,0.1f,0.1f,0.075f,0.075f,0.075f,0.05f,0.05f,0.05f,0.05f,0.05f,0.05f,0.045f,0.045f,0.045f,0.045f,0.045f,0.045f,0.045f}; // Maximum reduction factors for each threshold
  3377. int numThresholds = sizeof(thresholds) / sizeof(thresholds[0]);
  3378. // Find the appropriate maximum reduction factor based on level difference
  3379. float maxReduction = .1f; // Default maximum reduction factor
  3380. for (int i = 0; i < numThresholds; ++i) {
  3381. if (effective_level >= thresholds[i]) {
  3382. maxReduction = maxReductions[i];
  3383. }
  3384. else {
  3385. break; // No need to check further
  3386. }
  3387. }
  3388. GetInfoStruct()->set_max_spell_reduction(maxReduction);
  3389. }