Entity.cpp 119 KB

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