Entity.cpp 135 KB

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