Entity.cpp 119 KB

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