Entity.cpp 119 KB

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