Entity.cpp 118 KB

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