Entity.cpp 135 KB

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