Entity.cpp 135 KB

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