Entity.cpp 126 KB

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