Entity.cpp 119 KB

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