Entity.cpp 116 KB

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