Entity.cpp 113 KB

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