Entity.cpp 107 KB

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