Entity.cpp 127 KB

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