Entity.cpp 117 KB

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