Entity.cpp 126 KB

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