Entity.cpp 137 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866
  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. deletedPtrs[GetInfoStruct()->maintained_effects[i].spell] = true;
  109. lua_interface->RemoveSpell(GetInfoStruct()->maintained_effects[i].spell, false, removeClient, "", removeClient);
  110. if (IsPlayer())
  111. GetInfoStruct()->maintained_effects[i].icon = 0xFFFF;
  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. deletedPtrs[GetInfoStruct()->spell_effects[i].spell] = true;
  123. lua_interface->RemoveSpell(GetInfoStruct()->spell_effects[i].spell, false, removeClient, "", removeClient);
  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. CalculateApplyWeight();
  1343. safe_delete(values);
  1344. }
  1345. void Entity::CalculateApplyWeight() {
  1346. if (IsPlayer()) {
  1347. int32 prev_weight = GetInfoStruct()->get_weight();
  1348. int32 inv_weight = ((Player*)this)->item_list.GetWeight();
  1349. // calculate coin
  1350. int32 coin_copper = GetInfoStruct()->get_coin_copper();
  1351. int32 coin_silver = GetInfoStruct()->get_coin_silver();
  1352. int32 coin_gold = GetInfoStruct()->get_coin_gold();
  1353. int32 coin_plat = GetInfoStruct()->get_coin_plat();
  1354. float weight_per_hundred = rule_manager.GetGlobalRule(R_Player, CoinWeightPerHundred)->GetFloat();
  1355. if(weight_per_hundred < 0.0f) {
  1356. weight_per_hundred = 0.0f;
  1357. }
  1358. int32 total_weight = (int32)((double)coin_copper / weight_per_hundred) + (double)((double)coin_silver / weight_per_hundred) + (double)((double)coin_gold / weight_per_hundred) + (double)((double)coin_plat / weight_per_hundred);
  1359. total_weight += (int32)((double)inv_weight / 10.0);
  1360. GetInfoStruct()->set_weight(total_weight);
  1361. SetSpeedMultiplier(GetHighestSnare());
  1362. ((Player*)this)->SetSpeed(GetSpeed());
  1363. if(((Player*)this)->GetClient()) {
  1364. ((Player*)this)->GetClient()->SendControlGhost();
  1365. }
  1366. info_changed = true;
  1367. changed = true;
  1368. AddChangedZoneSpawn();
  1369. ((Player*)this)->SetCharSheetChanged(true);
  1370. }
  1371. int32 max_weight = 0;
  1372. float weight_str_multiplier = rule_manager.GetGlobalRule(R_Player, MaxWeightStrengthMultiplier)->GetFloat();
  1373. int32 base_weight = rule_manager.GetGlobalRule(R_Player, BaseWeight)->GetInt32();
  1374. if(weight_str_multiplier < 0.0f) {
  1375. weight_str_multiplier = 0.0f;
  1376. }
  1377. if(GetInfoStruct()->get_str() <= 0.0f) {
  1378. max_weight = base_weight; // rule for base strength
  1379. }
  1380. else {
  1381. max_weight = (int32)((double)GetInfoStruct()->get_str() * weight_str_multiplier); // rule multipler for strength
  1382. max_weight += base_weight; // rule for base strength
  1383. }
  1384. GetInfoStruct()->set_max_weight(max_weight);
  1385. }
  1386. void Entity::SetRegenValues(int16 effective_level)
  1387. {
  1388. bool classicRegen = rule_manager.GetGlobalRule(R_Spawn, ClassicRegen)->GetBool();
  1389. bool override_ = (IsPlayer() && !GetInfoStruct()->get_engaged_encounter());
  1390. if(!GetInfoStruct()->get_hp_regen_override())
  1391. {
  1392. sint16 regen_hp_rate = 0;
  1393. sint16 temp = 0;
  1394. MStats.lock();
  1395. if(!IsAggroed() || override_)
  1396. {
  1397. if(classicRegen)
  1398. {
  1399. // classic regen only gives OUT OF COMBAT, doesn't combine in+out of combat
  1400. regen_hp_rate = (int)(effective_level*.75)+1;
  1401. temp = regen_hp_rate + stats[ITEM_STAT_HPREGEN];
  1402. temp += stats[ITEM_STAT_HPREGENPPT];
  1403. }
  1404. else
  1405. {
  1406. regen_hp_rate = (int)(effective_level*.75)+(int)(effective_level/10) + 1;
  1407. temp = regen_hp_rate + stats[ITEM_STAT_HPREGEN];
  1408. temp += stats[ITEM_STAT_HPREGENPPT] + stats[ITEM_STAT_COMBATHPREGENPPT];
  1409. }
  1410. }
  1411. else
  1412. {
  1413. regen_hp_rate = (sint16)(effective_level / 10) + 1;
  1414. temp = regen_hp_rate + stats[ITEM_STAT_COMBATHPREGENPPT];
  1415. }
  1416. MStats.unlock();
  1417. GetInfoStruct()->set_hp_regen(temp);
  1418. }
  1419. if(!GetInfoStruct()->get_power_regen_override())
  1420. {
  1421. sint16 regen_power_rate = 0;
  1422. sint16 temp = 0;
  1423. MStats.lock();
  1424. if(!IsAggroed() || override_)
  1425. {
  1426. if(classicRegen)
  1427. {
  1428. regen_power_rate = effective_level + 1;
  1429. temp = regen_power_rate + stats[ITEM_STAT_MANAREGEN];
  1430. temp += stats[ITEM_STAT_MPREGENPPT];
  1431. }
  1432. else
  1433. {
  1434. regen_power_rate = effective_level + (int)(effective_level/10) + 1;
  1435. temp = regen_power_rate + stats[ITEM_STAT_MANAREGEN];
  1436. temp += stats[ITEM_STAT_MPREGENPPT] + stats[ITEM_STAT_COMBATMPREGENPPT];
  1437. }
  1438. }
  1439. else
  1440. {
  1441. regen_power_rate = (sint16)(effective_level / 10) + 1;
  1442. temp = regen_power_rate + stats[ITEM_STAT_COMBATMPREGENPPT];
  1443. }
  1444. MStats.unlock();
  1445. GetInfoStruct()->set_power_regen(temp);
  1446. }
  1447. }
  1448. EquipmentItemList* Entity::GetEquipmentList(){
  1449. return &equipment_list;
  1450. }
  1451. EquipmentItemList* Entity::GetAppearanceEquipmentList(){
  1452. return &appearance_equipment_list;
  1453. }
  1454. void Entity::SetEquipment(Item* item, int8 slot){
  1455. std::lock_guard<std::mutex> lk(MEquipment);
  1456. if(!item && slot < NUM_SLOTS){
  1457. SetInfo(&equipment.equip_id[slot], 0);
  1458. SetInfo(&equipment.color[slot].red, 0);
  1459. SetInfo(&equipment.color[slot].green, 0);
  1460. SetInfo(&equipment.color[slot].blue, 0);
  1461. SetInfo(&equipment.highlight[slot].red, 0);
  1462. SetInfo(&equipment.highlight[slot].green, 0);
  1463. SetInfo(&equipment.highlight[slot].blue, 0);
  1464. }
  1465. else{
  1466. if ( slot >= NUM_SLOTS )
  1467. slot = item->details.slot_id;
  1468. if( slot >= NUM_SLOTS )
  1469. return;
  1470. SetInfo(&equipment.equip_id[slot], item->generic_info.appearance_id);
  1471. SetInfo(&equipment.color[slot].red, item->generic_info.appearance_red);
  1472. SetInfo(&equipment.color[slot].green, item->generic_info.appearance_green);
  1473. SetInfo(&equipment.color[slot].blue, item->generic_info.appearance_blue);
  1474. SetInfo(&equipment.highlight[slot].red, item->generic_info.appearance_highlight_red);
  1475. SetInfo(&equipment.highlight[slot].green, item->generic_info.appearance_highlight_green);
  1476. SetInfo(&equipment.highlight[slot].blue, item->generic_info.appearance_highlight_blue);
  1477. }
  1478. }
  1479. bool Entity::CheckSpellBonusRemoval(LuaSpell* spell, int16 type){
  1480. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  1481. while(itr.Next()){
  1482. if(itr.value->luaspell == spell && itr.value->type == type){
  1483. bonus_list.Remove(itr.value, true);
  1484. return true;
  1485. }
  1486. }
  1487. return false;
  1488. }
  1489. void Entity::AddSpellBonus(LuaSpell* spell, int16 type, float value, int64 class_req, vector<int16> race_req, vector<int16> faction_req){
  1490. CheckSpellBonusRemoval(spell, type);
  1491. BonusValues* bonus = new BonusValues;
  1492. if(spell && spell->spell) {
  1493. bonus->spell_id = spell->spell->GetSpellID();
  1494. }
  1495. else {
  1496. bonus->spell_id = 0;
  1497. }
  1498. bonus->luaspell = spell;
  1499. bonus->type = type;
  1500. bonus->value = value;
  1501. bonus->class_req = class_req;
  1502. bonus->race_req = race_req;
  1503. bonus->faction_req = faction_req;
  1504. bonus->tier = (spell && spell->spell) ? spell->spell->GetSpellTier() : 0;
  1505. bonus_list.Add(bonus);
  1506. if(IsNPC() || IsPlayer())
  1507. CalculateBonuses();
  1508. }
  1509. BonusValues* Entity::GetSpellBonus(int32 spell_id) {
  1510. BonusValues *ret = 0;
  1511. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  1512. while (itr.Next()) {
  1513. if (itr.value->spell_id == spell_id) {
  1514. ret = itr.value;
  1515. break;
  1516. }
  1517. }
  1518. return ret;
  1519. }
  1520. vector<BonusValues*>* Entity::GetAllSpellBonuses(LuaSpell* spell) {
  1521. vector<BonusValues*>* list = new vector<BonusValues*>;
  1522. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  1523. while (itr.Next()) {
  1524. if (itr.value->luaspell == spell)
  1525. list->push_back(itr.value);
  1526. }
  1527. return list;
  1528. }
  1529. void Entity::RemoveSpellBonus(const LuaSpell* spell, bool remove_all){
  1530. // spell can be null!
  1531. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  1532. while(itr.Next()){
  1533. if(itr.value->luaspell == spell || remove_all)
  1534. bonus_list.Remove(itr.value, true);
  1535. }
  1536. if(IsNPC() || IsPlayer())
  1537. CalculateBonuses();
  1538. }
  1539. void Entity::CalculateSpellBonuses(ItemStatsValues* stats){
  1540. if(stats){
  1541. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  1542. vector<BonusValues*> bv;
  1543. //First check if we meet the requirement for each bonus
  1544. bool race_match = false;
  1545. while(itr.Next()) {
  1546. if (itr.value->race_req.size() > 0) {
  1547. for (int8 i = 0; i < itr.value->race_req.size(); i++) {
  1548. if (GetRace() == itr.value->race_req[i]) {
  1549. race_match = true;
  1550. }
  1551. }
  1552. }
  1553. else
  1554. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1555. int64 const class1 = pow(2.0, (GetAdventureClass() - 1));
  1556. int64 const class2 = pow(2.0, (classes.GetSecondaryBaseClass(GetAdventureClass()) - 1));
  1557. int64 const class3 = pow(2.0, (classes.GetBaseClass(GetAdventureClass()) - 1));
  1558. 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 )
  1559. bv.push_back(itr.value);
  1560. }
  1561. //Sort the bonuses by spell id and luaspell
  1562. BonusValues* bonus = nullptr;
  1563. map <int32, map<LuaSpell*, vector<BonusValues*> > > sort;
  1564. for (int8 i = 0; i < bv.size(); i++){
  1565. bonus = bv.at(i);
  1566. sort[bonus->spell_id][bonus->luaspell].push_back(bonus);
  1567. }
  1568. //Now check for the highest tier of each spell id and apply those bonuses
  1569. map<LuaSpell*, vector<BonusValues*> >::iterator tier_itr;
  1570. map <int32, map<LuaSpell*, vector<BonusValues*> > >::iterator sort_itr;
  1571. for (sort_itr = sort.begin(); sort_itr != sort.end(); sort_itr++){
  1572. LuaSpell* key = nullptr;
  1573. sint8 highest_tier = -1;
  1574. //Find the highest tier for this spell id
  1575. for (tier_itr = sort_itr->second.begin(); tier_itr != sort_itr->second.end(); tier_itr++){
  1576. LuaSpell* current_spell = tier_itr->first;
  1577. sint8 current_tier = 0;
  1578. if (current_spell && current_spell->spell && ((current_tier = current_spell->spell->GetSpellTier()) > highest_tier)) {
  1579. highest_tier = current_tier;
  1580. key = current_spell;
  1581. }
  1582. }
  1583. //We've found the highest tier for this spell id, so add the bonuses
  1584. vector<BonusValues*>* final_bonuses = &sort_itr->second[key];
  1585. for (int8 i = 0; i < final_bonuses->size(); i++)
  1586. world.AddBonuses(nullptr, stats, final_bonuses->at(i)->type, final_bonuses->at(i)->value, this);
  1587. }
  1588. }
  1589. }
  1590. void Entity::AddMezSpell(LuaSpell* spell) {
  1591. if (!spell)
  1592. return;
  1593. if (!control_effects[CONTROL_EFFECT_TYPE_MEZ])
  1594. control_effects[CONTROL_EFFECT_TYPE_MEZ] = new MutexList<LuaSpell*>;
  1595. MutexList<LuaSpell*>* mez_spells = control_effects[CONTROL_EFFECT_TYPE_MEZ];
  1596. if (IsPlayer() && !IsStunned() && !IsMezImmune() && mez_spells->size(true) == 0){
  1597. ((Player*)this)->SetPlayerControlFlag(1, 16, true);
  1598. if (!IsRooted())
  1599. ((Player*)this)->SetPlayerControlFlag(1, 8, true);
  1600. if (!IsStifled() && !IsFeared())
  1601. GetZone()->LockAllSpells((Player*)this);
  1602. }
  1603. if (IsNPC() && !IsMezImmune())
  1604. {
  1605. HaltMovement();
  1606. }
  1607. mez_spells->Add(spell);
  1608. }
  1609. void Entity::RemoveMezSpell(LuaSpell* spell) {
  1610. MutexList<LuaSpell*>* mez_spells = control_effects[CONTROL_EFFECT_TYPE_MEZ];
  1611. if (!mez_spells || mez_spells->size(true) == 0)
  1612. return;
  1613. mez_spells->Remove(spell);
  1614. if (mez_spells->size(true) == 0){
  1615. if (IsPlayer() && !IsMezImmune() && !IsStunned()){
  1616. if (!IsStifled() && !IsFeared())
  1617. GetZone()->UnlockAllSpells((Player*)this);
  1618. ((Player*)this)->SetPlayerControlFlag(1, 16, false);
  1619. if (!IsRooted())
  1620. ((Player*)this)->SetPlayerControlFlag(1, 8, false);
  1621. }
  1622. if(!IsPlayer()) {
  1623. GetZone()->movementMgr->StopNavigation((Entity*)this);
  1624. ((Spawn*)this)->StopMovement();
  1625. }
  1626. }
  1627. }
  1628. void Entity::RemoveAllMezSpells() {
  1629. MutexList<LuaSpell*>* mez_spells = control_effects[CONTROL_EFFECT_TYPE_MEZ];
  1630. if (!mez_spells)
  1631. return;
  1632. MutexList<LuaSpell*>::iterator itr = mez_spells->begin();
  1633. while (itr.Next()){
  1634. LuaSpell* spell = itr.value;
  1635. if (!spell)
  1636. continue;
  1637. GetZone()->RemoveTargetFromSpell(spell, this);
  1638. RemoveDetrimentalSpell(spell);
  1639. RemoveSpellEffect(spell);
  1640. if (IsPlayer())
  1641. ((Player*)this)->RemoveSkillBonus(spell->spell->GetSpellID());
  1642. }
  1643. mez_spells->clear();
  1644. if (IsPlayer() && !IsMezImmune() && !IsStunned()){
  1645. if (!IsStifled() && !IsFeared())
  1646. GetZone()->UnlockAllSpells((Player*)this);
  1647. ((Player*)this)->SetPlayerControlFlag(1, 16, false);
  1648. if (!IsRooted())
  1649. ((Player*)this)->SetPlayerControlFlag(1, 8, false);
  1650. }
  1651. }
  1652. void Entity::AddStifleSpell(LuaSpell* spell) {
  1653. if (!spell)
  1654. return;
  1655. if (!control_effects[CONTROL_EFFECT_TYPE_STIFLE])
  1656. control_effects[CONTROL_EFFECT_TYPE_STIFLE] = new MutexList<LuaSpell*>;
  1657. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_STIFLE]->size(true) == 0 && !IsStifleImmune() && !IsMezzedOrStunned())
  1658. GetZone()->LockAllSpells((Player*)this);
  1659. control_effects[CONTROL_EFFECT_TYPE_STIFLE]->Add(spell);
  1660. }
  1661. void Entity::RemoveStifleSpell(LuaSpell* spell) {
  1662. MutexList<LuaSpell*>* stifle_list = control_effects[CONTROL_EFFECT_TYPE_STIFLE];
  1663. if (!stifle_list || stifle_list->size(true) == 0)
  1664. return;
  1665. stifle_list->Remove(spell);
  1666. if (IsPlayer() && stifle_list->size(true) == 0 && !IsStifleImmune() && !IsMezzedOrStunned())
  1667. GetZone()->UnlockAllSpells((Player*)this);
  1668. }
  1669. void Entity::AddDazeSpell(LuaSpell* spell) {
  1670. if (!spell)
  1671. return;
  1672. if (!control_effects[CONTROL_EFFECT_TYPE_DAZE])
  1673. control_effects[CONTROL_EFFECT_TYPE_DAZE] = new MutexList<LuaSpell*>;
  1674. control_effects[CONTROL_EFFECT_TYPE_DAZE]->Add(spell);
  1675. }
  1676. void Entity::RemoveDazeSpell(LuaSpell* spell) {
  1677. MutexList<LuaSpell*>* daze_list = control_effects[CONTROL_EFFECT_TYPE_DAZE];
  1678. if (!daze_list || daze_list->size(true) == 0)
  1679. return;
  1680. daze_list->Remove(spell);
  1681. }
  1682. void Entity::AddStunSpell(LuaSpell* spell) {
  1683. if (!spell)
  1684. return;
  1685. if (!control_effects[CONTROL_EFFECT_TYPE_STUN])
  1686. control_effects[CONTROL_EFFECT_TYPE_STUN] = new MutexList<LuaSpell*>;
  1687. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_STUN]->size(true) == 0 && !IsStunImmune()){
  1688. if (!IsMezzed()){
  1689. ((Player*)this)->SetPlayerControlFlag(1, 16, true);
  1690. if (!IsRooted())
  1691. ((Player*)this)->SetPlayerControlFlag(1, 8, true);
  1692. if (!IsStifled() && !IsFeared())
  1693. GetZone()->LockAllSpells((Player*)this);
  1694. }
  1695. }
  1696. control_effects[CONTROL_EFFECT_TYPE_STUN]->Add(spell);
  1697. }
  1698. void Entity::RemoveStunSpell(LuaSpell* spell) {
  1699. MutexList<LuaSpell*>* stun_list = control_effects[CONTROL_EFFECT_TYPE_STUN];
  1700. if (!stun_list || stun_list->size(true) == 0)
  1701. return;
  1702. stun_list->Remove(spell);
  1703. if (stun_list->size(true) == 0){
  1704. if (IsPlayer() && !IsMezzed() && !IsStunImmune()){
  1705. ((Player*)this)->SetPlayerControlFlag(1, 16, false);
  1706. if (!IsRooted())
  1707. ((Player*)this)->SetPlayerControlFlag(1, 8, false);
  1708. if (!IsStifled() && !IsFeared())
  1709. GetZone()->UnlockAllSpells((Player*)this);
  1710. }
  1711. if(!IsPlayer()) {
  1712. GetZone()->movementMgr->StopNavigation((Entity*)this);
  1713. ((Spawn*)this)->StopMovement();
  1714. }
  1715. }
  1716. }
  1717. void Entity::HideDeityPet(bool val) {
  1718. if (!deityPet)
  1719. return;
  1720. if (val) {
  1721. deityPet->AddAllowAccessSpawn(deityPet);
  1722. GetZone()->HidePrivateSpawn(deityPet);
  1723. }
  1724. else
  1725. deityPet->MakeSpawnPublic();
  1726. }
  1727. void Entity::HideCosmeticPet(bool val) {
  1728. if (!cosmeticPet)
  1729. return;
  1730. if (val) {
  1731. cosmeticPet->AddAllowAccessSpawn(cosmeticPet);
  1732. GetZone()->HidePrivateSpawn(cosmeticPet);
  1733. }
  1734. else
  1735. cosmeticPet->MakeSpawnPublic();
  1736. }
  1737. void Entity::DismissAllPets(bool from_death, bool spawnListLocked)
  1738. {
  1739. DismissPet(GetPet(), from_death, spawnListLocked);
  1740. DismissPet(GetCharmedPet(), from_death, spawnListLocked);
  1741. DismissPet(GetDeityPet(), from_death, spawnListLocked);
  1742. DismissPet(GetCosmeticPet(), from_death, spawnListLocked);
  1743. }
  1744. void Entity::DismissPet(Entity* pet, bool from_death, bool spawnListLocked) {
  1745. if (!pet)
  1746. return;
  1747. Entity* PetOwner = pet->GetOwner();
  1748. if(pet->IsNPC())
  1749. {
  1750. ((NPC*)pet)->SetDismissing(true);
  1751. // Remove the spell maintained spell
  1752. Spell* spell = master_spell_list.GetSpell(pet->GetPetSpellID(), pet->GetPetSpellTier());
  1753. if (spell)
  1754. GetZone()->GetSpellProcess()->DeleteCasterSpell(this, spell, from_death == true ? (string)"pet_death" : (string)"canceled");
  1755. }
  1756. if (pet->GetPetType() == PET_TYPE_CHARMED) {
  1757. if(PetOwner)
  1758. PetOwner->SetCharmedPet(0);
  1759. if (!from_death) {
  1760. // set the pet flag to false, owner to 0, and give the mob its old brain back
  1761. pet->SetPet(false);
  1762. pet->SetOwner(0);
  1763. if(pet->IsNPC())
  1764. ((NPC*)pet)->SetBrain(new Brain((NPC*)pet));
  1765. pet->SetDismissing(false);
  1766. }
  1767. }
  1768. else if (PetOwner && pet->GetPetType() == PET_TYPE_COMBAT)
  1769. PetOwner->SetCombatPet(0);
  1770. else if (PetOwner && pet->GetPetType() == PET_TYPE_DEITY)
  1771. PetOwner->SetDeityPet(0);
  1772. else if (PetOwner && pet->GetPetType() == PET_TYPE_COSMETIC)
  1773. PetOwner->SetCosmeticPet(0);
  1774. // if owner is player and no combat pets left reset the pet info
  1775. if (PetOwner && PetOwner->IsPlayer()) {
  1776. if (!PetOwner->GetPet() && !PetOwner->GetCharmedPet())
  1777. ((Player*)PetOwner)->ResetPetInfo();
  1778. }
  1779. // remove the spawn from the world
  1780. if (!from_death && pet->GetPetType() != PET_TYPE_CHARMED)
  1781. GetZone()->RemoveSpawn(pet);
  1782. }
  1783. float Entity::CalculateBonusMod() {
  1784. int8 level = GetLevel();
  1785. if (level <= 20)
  1786. return 3.0;
  1787. else if (level >= 90)
  1788. return 10.0;
  1789. else
  1790. return (level - 20) * .1 + 3.0;
  1791. }
  1792. float Entity::CalculateDPSMultiplier(){
  1793. float dps = GetInfoStruct()->get_dps();
  1794. if (dps > 0){
  1795. if (dps <= 100)
  1796. return (dps / 100 + 1);
  1797. else if (dps <= 200)
  1798. return (((dps - 100) * .25 + 100) / 100 + 1);
  1799. else if (dps <= 300)
  1800. return (((dps - 200) * .1 + 125) / 100 + 1);
  1801. else if (dps <= 900)
  1802. return (((dps - 300) * .05 + 135) / 100 + 1);
  1803. else
  1804. return (((dps - 900) * .01 + 165) / 100 + 1);
  1805. }
  1806. return 1;
  1807. }
  1808. void Entity::AddWard(int32 spellID, WardInfo* ward) {
  1809. if (m_wardList.count(spellID) == 0) {
  1810. m_wardList[spellID] = ward;
  1811. }
  1812. }
  1813. WardInfo* Entity::GetWard(int32 spellID) {
  1814. WardInfo* ret = 0;
  1815. if (m_wardList.count(spellID) > 0)
  1816. ret = m_wardList[spellID];
  1817. return ret;
  1818. }
  1819. void Entity::RemoveWard(int32 spellID) {
  1820. if (m_wardList.count(spellID) > 0) {
  1821. // Delete the ward info
  1822. safe_delete(m_wardList[spellID]);
  1823. // Remove from the ward list
  1824. m_wardList.erase(spellID);
  1825. }
  1826. }
  1827. int32 Entity::CheckWards(Entity* attacker, int32 damage, int8 damage_type) {
  1828. map<int32, WardInfo*>::iterator itr;
  1829. WardInfo* ward = 0;
  1830. LuaSpell* spell = 0;
  1831. while (m_wardList.size() > 0 && damage > 0) {
  1832. // Get the ward with the lowest base damage
  1833. for (itr = m_wardList.begin(); itr != m_wardList.end(); itr++) {
  1834. if(itr->second->RoundTriggered)
  1835. continue;
  1836. if (!ward || itr->second->BaseDamage < ward->BaseDamage) {
  1837. if ((itr->second->AbsorbAllDamage || itr->second->DamageLeft > 0) &&
  1838. (itr->second->WardType == WARD_TYPE_ALL ||
  1839. (itr->second->WardType == WARD_TYPE_PHYSICAL && damage_type >= DAMAGE_PACKET_DAMAGE_TYPE_SLASH && damage_type <= DAMAGE_PACKET_DAMAGE_TYPE_PIERCE) ||
  1840. (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)))))
  1841. ward = itr->second;
  1842. }
  1843. }
  1844. if (!ward)
  1845. break;
  1846. spell = ward->Spell;
  1847. // damage to redirect at the source (like intercept)
  1848. int32 redirectDamage = 0;
  1849. if (ward->RedirectDamagePercent)
  1850. redirectDamage = (int32)(double)damage * ((double)ward->RedirectDamagePercent / 100.0);
  1851. // percentage the spell absorbs of all possible damage
  1852. int32 damageToAbsorb = 0;
  1853. if (ward->DamageAbsorptionPercentage > 0)
  1854. damageToAbsorb = (int32)(double)damage * ((double)ward->DamageAbsorptionPercentage/100.0);
  1855. else
  1856. damageToAbsorb = damage;
  1857. int32 maxDamageAbsorptionAllowed = 0;
  1858. // spells like Divine Aura have caps on health, eg. anything more than 50% damage is not absorbed
  1859. if (ward->DamageAbsorptionMaxHealthPercent > 0)
  1860. maxDamageAbsorptionAllowed = (int32)(double)GetTotalHP() * ((double)ward->DamageAbsorptionMaxHealthPercent / 100.0);
  1861. if (maxDamageAbsorptionAllowed > 0 && damageToAbsorb >= maxDamageAbsorptionAllowed)
  1862. damageToAbsorb = 0; // its over or equal to 50% of the total hp allowed, thus this damage is not absorbed
  1863. int32 baseDamageRemaining = damage - damageToAbsorb;
  1864. bool hasSpellBeenRemoved = false;
  1865. if (ward->AbsorbAllDamage)
  1866. {
  1867. ward->LastAbsorbedDamage = ward->DamageLeft;
  1868. if (!redirectDamage)
  1869. GetZone()->SendHealPacket(ward->Spell->caster, this, HEAL_PACKET_TYPE_ABSORB, damage, spell->spell->GetName());
  1870. damage = 0;
  1871. }
  1872. else if (damageToAbsorb >= ward->DamageLeft) {
  1873. // Damage is greater than or equal to the amount left on the ward
  1874. ward->LastAbsorbedDamage = ward->DamageLeft;
  1875. // remove what damage we can absorb
  1876. damageToAbsorb -= ward->DamageLeft;
  1877. // move back what couldn't be absorbed to the base dmg and apply to the overall damage
  1878. baseDamageRemaining += damageToAbsorb;
  1879. damage = baseDamageRemaining;
  1880. ward->DamageLeft = 0;
  1881. spell->damage_remaining = 0;
  1882. if(!redirectDamage)
  1883. GetZone()->SendHealPacket(spell->caster, this, HEAL_PACKET_TYPE_ABSORB, ward->DamageLeft, spell->spell->GetName());
  1884. if (!ward->keepWard) {
  1885. hasSpellBeenRemoved = true;
  1886. RemoveWard(spell->spell->GetSpellID());
  1887. GetZone()->GetSpellProcess()->DeleteCasterSpell(spell, "purged");
  1888. }
  1889. }
  1890. else {
  1891. ward->LastAbsorbedDamage = damageToAbsorb;
  1892. // Damage is less then the amount left on the ward
  1893. ward->DamageLeft -= damageToAbsorb;
  1894. spell->damage_remaining = ward->DamageLeft;
  1895. if (spell->caster->IsPlayer())
  1896. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  1897. if (!redirectDamage)
  1898. GetZone()->SendHealPacket(ward->Spell->caster, this, HEAL_PACKET_TYPE_ABSORB, damage, spell->spell->GetName());
  1899. // remaining damage not absorbed by percentage must be set
  1900. damage = baseDamageRemaining;
  1901. }
  1902. if (redirectDamage)
  1903. {
  1904. ward->LastRedirectDamage = redirectDamage;
  1905. if (this->IsPlayer())
  1906. {
  1907. Client* client = this->GetClient();
  1908. if(client) {
  1909. client->Message(CHANNEL_COMBAT, "%s intercepted some of the damage intended for you!", spell->caster->GetName());
  1910. }
  1911. }
  1912. if (spell->caster && spell->caster->IsPlayer())
  1913. {
  1914. Client* client = ((Player*)spell->caster)->GetClient();
  1915. if(client) {
  1916. client->Message(CHANNEL_COMBAT, "YOU intercept some of the damage intended for %s!", this->GetName());
  1917. }
  1918. }
  1919. if (attacker && spell->caster)
  1920. attacker->DamageSpawn(spell->caster, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, damage_type, redirectDamage, redirectDamage, 0, 0, false, false, false, false, spell);
  1921. }
  1922. bool shouldRemoveSpell = false;
  1923. ward->HitCount++; // increment hit count
  1924. ward->RoundTriggered = true;
  1925. if (ward->MaxHitCount && spell->num_triggers && spell->caster->GetZone())
  1926. {
  1927. spell->num_triggers--;
  1928. if(spell->caster->IsPlayer()) {
  1929. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, spell->num_triggers, 0);
  1930. }
  1931. }
  1932. 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
  1933. shouldRemoveSpell = true;
  1934. if (shouldRemoveSpell && !hasSpellBeenRemoved)
  1935. {
  1936. RemoveWard(spell->spell->GetSpellID());
  1937. GetZone()->GetSpellProcess()->DeleteCasterSpell(spell, "purged");
  1938. }
  1939. // Reset ward pointer
  1940. ward = 0;
  1941. }
  1942. for (itr = m_wardList.begin(); itr != m_wardList.end(); itr++) {
  1943. itr->second->RoundTriggered = false;
  1944. }
  1945. return damage;
  1946. }
  1947. float Entity::CalculateCastingSpeedMod() {
  1948. float cast_speed = info_struct.get_casting_speed();
  1949. if(cast_speed > 0)
  1950. return 100 * max((float) 0.5, (float) (1 + (1 - (1 / (1 + (cast_speed * .01))))));
  1951. else if (cast_speed < 0)
  1952. return 100 * min((float) 1.5, (float) (1 + (1 - (1 / (1 + (cast_speed * -.01))))));
  1953. return 0;
  1954. }
  1955. float Entity::GetSpeed() {
  1956. float ret = speed > GetBaseSpeed() ? speed : GetBaseSpeed();
  1957. MStats.lock();
  1958. if ((IsStealthed() || IsInvis()) && stats.count(ITEM_STAT_STEALTHINVISSPEEDMOD)) {
  1959. ret += stats[ITEM_STAT_STEALTHINVISSPEEDMOD];
  1960. }
  1961. if (!GetInfoStruct()->get_engaged_encounter()) {
  1962. if (stats.count(ITEM_STAT_SPEED) && stats.count(ITEM_STAT_MOUNTSPEED)) {
  1963. ret += max(stats[ITEM_STAT_SPEED], stats[ITEM_STAT_MOUNTSPEED]);
  1964. }
  1965. else if (stats.count(ITEM_STAT_SPEED)) {
  1966. ret += stats[ITEM_STAT_SPEED];
  1967. }
  1968. else if (stats.count(ITEM_STAT_MOUNTSPEED)) {
  1969. ret += stats[ITEM_STAT_MOUNTSPEED];
  1970. }
  1971. }
  1972. else if (GetInfoStruct()->get_engaged_encounter()) {
  1973. if (GetMaxSpeed() > 0.0f)
  1974. ret = GetMaxSpeed();
  1975. if (stats.count(ITEM_STAT_OFFENSIVESPEED)) {
  1976. ret += stats[ITEM_STAT_OFFENSIVESPEED];
  1977. }
  1978. }
  1979. MStats.unlock();
  1980. ret *= speed_multiplier;
  1981. return ret;
  1982. }
  1983. float Entity::GetAirSpeed() {
  1984. float ret = speed;
  1985. if (!GetInfoStruct()->get_engaged_encounter())
  1986. ret += stats[ITEM_STAT_MOUNTAIRSPEED];
  1987. ret *= speed_multiplier;
  1988. return ret;
  1989. }
  1990. void Entity::SetThreatTransfer(ThreatTransfer* transfer) {
  1991. safe_delete(m_threatTransfer);
  1992. m_threatTransfer = transfer;
  1993. }
  1994. int8 Entity::GetTraumaCount() {
  1995. return det_count_list[DET_TYPE_TRAUMA];
  1996. }
  1997. int8 Entity::GetArcaneCount() {
  1998. return det_count_list[DET_TYPE_ARCANE];
  1999. }
  2000. int8 Entity::GetNoxiousCount() {
  2001. return det_count_list[DET_TYPE_NOXIOUS];
  2002. }
  2003. int8 Entity::GetElementalCount() {
  2004. return det_count_list[DET_TYPE_ELEMENTAL];
  2005. }
  2006. int8 Entity::GetCurseCount() {
  2007. return det_count_list[DET_TYPE_CURSE];
  2008. }
  2009. Mutex* Entity::GetDetrimentMutex() {
  2010. return &MDetriments;
  2011. }
  2012. Mutex* Entity::GetMaintainedMutex() {
  2013. return &MMaintainedSpells;
  2014. }
  2015. Mutex* Entity::GetSpellEffectMutex() {
  2016. return &MSpellEffects;
  2017. }
  2018. bool Entity::HasCurableDetrimentType(int8 det_type) {
  2019. DetrimentalEffects* det;
  2020. bool ret = false;
  2021. MDetriments.readlock(__FUNCTION__, __LINE__);
  2022. for (int32 i = 0; i < detrimental_spell_effects.size(); i++){
  2023. det = &detrimental_spell_effects.at(i);
  2024. if(det && det->det_type == det_type && !det->incurable){
  2025. ret = true;
  2026. break;
  2027. }
  2028. }
  2029. MDetriments.releasereadlock(__FUNCTION__, __LINE__);
  2030. return ret;
  2031. }
  2032. void Entity::ClearAllDetriments() {
  2033. MDetriments.writelock(__FUNCTION__, __LINE__);
  2034. detrimental_spell_effects.clear();
  2035. det_count_list.clear();
  2036. MDetriments.releasewritelock(__FUNCTION__, __LINE__);
  2037. }
  2038. void Entity::CureDetrimentByType(int8 cure_count, int8 det_type, string cure_name, Entity* caster, int8 cure_level) {
  2039. if (cure_count <= 0 || GetDetTypeCount(det_type) <= 0)
  2040. return;
  2041. vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
  2042. DetrimentalEffects* det;
  2043. vector<LuaSpell*> remove_list;
  2044. LuaSpell* spell = 0;
  2045. vector<LevelArray*>* levels;
  2046. int8 caster_class1 = 0;
  2047. int8 caster_class2 = 0;
  2048. int8 caster_class3 = 0;
  2049. InfoStruct* info_struct = 0;
  2050. bool pass_level_check = false;
  2051. MDetriments.readlock(__FUNCTION__, __LINE__);
  2052. for (int32 i = 0; i<det_list->size(); i++){
  2053. det = &det_list->at(i);
  2054. if (det && det->det_type == det_type && !det->incurable){
  2055. levels = det->spell->spell->GetSpellLevels();
  2056. info_struct = det->caster->GetInfoStruct();
  2057. pass_level_check = false;
  2058. bool has_level_checks = false;
  2059. for (int32 x = 0; x < levels->size(); x++){
  2060. has_level_checks = true;
  2061. // class checks are worthless we can't guarantee the caster is that class
  2062. if (!cure_level || cure_level >= (levels->at(x)->spell_level / 10)){
  2063. pass_level_check = true;
  2064. break;
  2065. }
  2066. }
  2067. if (pass_level_check || !has_level_checks){
  2068. remove_list.push_back(det->spell);
  2069. cure_count--;
  2070. if (cure_count == 0)
  2071. break;
  2072. }
  2073. }
  2074. }
  2075. MDetriments.releasereadlock(__FUNCTION__, __LINE__);
  2076. for (int32 i = 0; i<remove_list.size(); i++){
  2077. spell = remove_list.at(i);
  2078. LogWrite(PLAYER__ERROR, 0, "Debug", "Remove spell %s", remove_list.at(i)->spell->GetName());
  2079. GetZone()->SendDispellPacket(caster, this, cure_name, (string)remove_list.at(i)->spell->GetName(), DISPELL_TYPE_CURE);
  2080. GetZone()->GetSpellProcess()->DeleteCasterSpell(spell, "cured", false, this);
  2081. }
  2082. remove_list.clear();
  2083. }
  2084. void Entity::CureDetrimentByControlEffect(int8 cure_count, int8 control_type, string cure_name, Entity* caster, int8 cure_level) {
  2085. if (cure_count <= 0 || GetDetCount() <= 0)
  2086. return;
  2087. vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
  2088. DetrimentalEffects* det;
  2089. vector<LuaSpell*> remove_list;
  2090. LuaSpell* spell = 0;
  2091. vector<LevelArray*>* levels;
  2092. int8 caster_class1 = 0;
  2093. int8 caster_class2 = 0;
  2094. int8 caster_class3 = 0;
  2095. InfoStruct* info_struct = 0;
  2096. bool pass_level_check = false;
  2097. MDetriments.readlock(__FUNCTION__, __LINE__);
  2098. for (int32 i = 0; i<det_list->size(); i++){
  2099. det = &det_list->at(i);
  2100. if (det && det->control_effect == control_type && !det->incurable){
  2101. levels = det->spell->spell->GetSpellLevels();
  2102. info_struct = det->caster->GetInfoStruct();
  2103. pass_level_check = false;
  2104. for (int32 x = 0; x < levels->size(); x++){
  2105. if (!cure_level || cure_level >= (levels->at(x)->spell_level / 10)){
  2106. pass_level_check = true;
  2107. break;
  2108. }
  2109. }
  2110. if (pass_level_check){
  2111. remove_list.push_back(det->spell);
  2112. cure_count--;
  2113. if (cure_count == 0)
  2114. break;
  2115. }
  2116. }
  2117. }
  2118. MDetriments.releasereadlock(__FUNCTION__, __LINE__);
  2119. for (int32 i = 0; i<remove_list.size(); i++){
  2120. spell = remove_list.at(i);
  2121. GetZone()->SendDispellPacket(caster, this, cure_name, (string)remove_list.at(i)->spell->GetName(), DISPELL_TYPE_CURE);
  2122. if (GetZone())
  2123. GetZone()->RemoveTargetFromSpell(spell, this);
  2124. RemoveSpellEffect(spell);
  2125. RemoveDetrimentalSpell(spell);
  2126. }
  2127. remove_list.clear();
  2128. }
  2129. void Entity::RemoveDetrimentalSpell(LuaSpell* spell) {
  2130. if(!spell || (spell->spell && spell->spell->GetSpellData() && spell->spell->GetSpellData()->det_type == 0))
  2131. return;
  2132. MDetriments.writelock(__FUNCTION__, __LINE__);
  2133. vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
  2134. vector<DetrimentalEffects>::iterator itr;
  2135. for(itr = det_list->begin(); itr != det_list->end(); itr++){
  2136. if((*itr).spell == spell){
  2137. det_count_list[(*itr).det_type]--;
  2138. det_list->erase(itr);
  2139. if(IsPlayer())
  2140. ((Player*)this)->SetCharSheetChanged(true);
  2141. break;
  2142. }
  2143. }
  2144. MDetriments.releasewritelock(__FUNCTION__, __LINE__);
  2145. }
  2146. int8 Entity::GetDetTypeCount(int8 det_type){
  2147. return det_count_list[det_type];
  2148. }
  2149. int8 Entity::GetDetCount() {
  2150. int8 det_count = 0;
  2151. map<int8, int8>::iterator itr;
  2152. for(itr=det_count_list.begin(); itr != det_count_list.end(); itr++)
  2153. det_count += (*itr).second;
  2154. return det_count;
  2155. }
  2156. vector<DetrimentalEffects>* Entity::GetDetrimentalSpellEffects() {
  2157. return &detrimental_spell_effects;
  2158. }
  2159. void Entity::AddDetrimentalSpell(LuaSpell* luaspell, int32 override_expire_timestamp){
  2160. if(!luaspell || !luaspell->caster)
  2161. return;
  2162. Spell* spell = luaspell->spell;
  2163. DetrimentalEffects* det = GetDetrimentalEffect(spell->GetSpellID(), luaspell->caster);
  2164. DetrimentalEffects new_det;
  2165. if(det)
  2166. RemoveDetrimentalSpell(det->spell);
  2167. SpellData* data = spell->GetSpellData();
  2168. if(!data)
  2169. return;
  2170. new_det.caster = luaspell->caster;
  2171. new_det.spell = luaspell;
  2172. if (spell->GetSpellData()->duration_until_cancel)
  2173. new_det.expire_timestamp = 0xFFFFFFFF;
  2174. else if(override_expire_timestamp)
  2175. new_det.expire_timestamp = override_expire_timestamp;
  2176. else
  2177. new_det.expire_timestamp = Timer::GetCurrentTime2() + (spell->GetSpellDuration()*100);
  2178. new_det.icon = data->icon;
  2179. new_det.icon_backdrop = data->icon_backdrop;
  2180. new_det.tier = data->tier;
  2181. new_det.det_type = data->det_type;
  2182. new_det.incurable = data->incurable;
  2183. new_det.spell_id = spell->GetSpellID();
  2184. new_det.control_effect = data->control_effect_type;
  2185. new_det.total_time = spell->GetSpellDuration()/10;
  2186. MDetriments.writelock(__FUNCTION__, __LINE__);
  2187. detrimental_spell_effects.push_back(new_det);
  2188. det_count_list[new_det.det_type]++;
  2189. MDetriments.releasewritelock(__FUNCTION__, __LINE__);
  2190. }
  2191. DetrimentalEffects* Entity::GetDetrimentalEffect(int32 spell_id, Entity* caster){
  2192. vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
  2193. DetrimentalEffects* ret = 0;
  2194. MDetriments.readlock(__FUNCTION__, __LINE__);
  2195. for(int32 i=0; i<det_list->size(); i++){
  2196. if (det_list->at(i).spell_id == spell_id && det_list->at(i).caster == caster)
  2197. ret = &det_list->at(i);
  2198. }
  2199. MDetriments.releasereadlock(__FUNCTION__, __LINE__);
  2200. return ret;
  2201. }
  2202. void Entity::CancelAllStealth() {
  2203. bool did_change = false;
  2204. MutexList<LuaSpell*>* stealth_list = control_effects[CONTROL_EFFECT_TYPE_STEALTH];
  2205. if (stealth_list){
  2206. MutexList<LuaSpell*>::iterator itr = stealth_list->begin();
  2207. while (itr.Next()){
  2208. if (itr.value->caster == this)
  2209. GetZone()->GetSpellProcess()->AddSpellCancel(itr.value);
  2210. else{
  2211. GetZone()->RemoveTargetFromSpell(itr.value, this);
  2212. RemoveSpellEffect(itr.value);
  2213. }
  2214. did_change = true;
  2215. }
  2216. }
  2217. MutexList<LuaSpell*>* invis_list = control_effects[CONTROL_EFFECT_TYPE_INVIS];
  2218. if (invis_list){
  2219. MutexList<LuaSpell*>::iterator invis_itr = invis_list->begin();
  2220. while (invis_itr.Next()){
  2221. if (invis_itr.value->caster == this)
  2222. GetZone()->GetSpellProcess()->AddSpellCancel(invis_itr.value);
  2223. else{
  2224. GetZone()->RemoveTargetFromSpell(invis_itr.value, this);
  2225. RemoveSpellEffect(invis_itr.value);
  2226. }
  2227. did_change = true;
  2228. }
  2229. }
  2230. if (did_change){
  2231. info_changed = true;
  2232. changed = true;
  2233. AddChangedZoneSpawn();
  2234. if (IsPlayer())
  2235. ((Player*)this)->SetCharSheetChanged(true);
  2236. }
  2237. }
  2238. bool Entity::IsStealthed(){
  2239. MutexList<LuaSpell*>* stealth_list = control_effects[CONTROL_EFFECT_TYPE_STEALTH];
  2240. return (!stealth_list || stealth_list->size(true) == 0) == false;
  2241. }
  2242. bool Entity::CanSeeInvis(Entity* target) {
  2243. if (!target)
  2244. return true;
  2245. if (!target->IsStealthed() && !target->IsInvis())
  2246. return true;
  2247. if (target->IsStealthed() && HasSeeHideSpell())
  2248. return true;
  2249. else if (target->IsInvis() && HasSeeInvisSpell())
  2250. return true;
  2251. return false;
  2252. }
  2253. bool Entity::IsInvis(){
  2254. MutexList<LuaSpell*>* invis_list = control_effects[CONTROL_EFFECT_TYPE_INVIS];
  2255. return (!invis_list || invis_list->size(true) == 0) == false;
  2256. }
  2257. void Entity::AddStealthSpell(LuaSpell* spell) {
  2258. if (!spell)
  2259. return;
  2260. if (!control_effects[CONTROL_EFFECT_TYPE_STEALTH])
  2261. control_effects[CONTROL_EFFECT_TYPE_STEALTH] = new MutexList<LuaSpell*>;
  2262. control_effects[CONTROL_EFFECT_TYPE_STEALTH]->Add(spell);
  2263. if (control_effects[CONTROL_EFFECT_TYPE_STEALTH]->size(true) == 1){
  2264. info_changed = true;
  2265. changed = true;
  2266. AddChangedZoneSpawn();
  2267. if (IsPlayer() && ((Player*)this)->GetClient())
  2268. {
  2269. ((Player*)this)->SetCharSheetChanged(true);
  2270. GetZone()->SendAllSpawnsForVisChange(((Player*)this)->GetClient());
  2271. }
  2272. }
  2273. }
  2274. void Entity::AddInvisSpell(LuaSpell* spell) {
  2275. if (!spell)
  2276. return;
  2277. if (!control_effects[CONTROL_EFFECT_TYPE_INVIS])
  2278. control_effects[CONTROL_EFFECT_TYPE_INVIS] = new MutexList<LuaSpell*>;
  2279. control_effects[CONTROL_EFFECT_TYPE_INVIS]->Add(spell);
  2280. if (control_effects[CONTROL_EFFECT_TYPE_INVIS]->size(true) == 1){
  2281. info_changed = true;
  2282. changed = true;
  2283. AddChangedZoneSpawn();
  2284. if (IsPlayer() && ((Player*)this)->GetClient())
  2285. {
  2286. ((Player*)this)->SetCharSheetChanged(true);
  2287. GetZone()->SendAllSpawnsForVisChange(((Player*)this)->GetClient());
  2288. }
  2289. }
  2290. }
  2291. void Entity::RemoveInvisSpell(LuaSpell* spell) {
  2292. MutexList<LuaSpell*>* invis_list = control_effects[CONTROL_EFFECT_TYPE_INVIS];
  2293. if (!invis_list || invis_list->size(true) == 0)
  2294. return;
  2295. invis_list->Remove(spell);
  2296. RemoveSpellEffect(spell);
  2297. if (invis_list->size(true) == 0){
  2298. info_changed = true;
  2299. changed = true;
  2300. AddChangedZoneSpawn();
  2301. if (IsPlayer() && ((Player*)this)->GetClient())
  2302. {
  2303. ((Player*)this)->SetCharSheetChanged(true);
  2304. GetZone()->SendAllSpawnsForVisChange(((Player*)this)->GetClient());
  2305. }
  2306. }
  2307. }
  2308. void Entity::RemoveStealthSpell(LuaSpell* spell) {
  2309. MutexList<LuaSpell*>* stealth_list = control_effects[CONTROL_EFFECT_TYPE_STEALTH];
  2310. if (!stealth_list || stealth_list->size(true) == 0)
  2311. return;
  2312. stealth_list->Remove(spell);
  2313. RemoveSpellEffect(spell);
  2314. if (stealth_list->size() == 0){
  2315. info_changed = true;
  2316. changed = true;
  2317. AddChangedZoneSpawn();
  2318. if (IsPlayer() && ((Player*)this)->GetClient())
  2319. {
  2320. ((Player*)this)->SetCharSheetChanged(true);
  2321. GetZone()->SendAllSpawnsForVisChange(((Player*)this)->GetClient());
  2322. }
  2323. }
  2324. }
  2325. void Entity::AddRootSpell(LuaSpell* spell) {
  2326. if (!spell)
  2327. return;
  2328. if (!control_effects[CONTROL_EFFECT_TYPE_ROOT])
  2329. control_effects[CONTROL_EFFECT_TYPE_ROOT] = new MutexList<LuaSpell*>;
  2330. if (control_effects[CONTROL_EFFECT_TYPE_ROOT]->size(true) == 0 && !IsRootImmune()) {
  2331. if (IsPlayer()){
  2332. if (!IsMezzedOrStunned())
  2333. ((Player*)this)->SetPlayerControlFlag(1, 8, true); // heading movement only
  2334. }
  2335. else
  2336. SetSpeedMultiplier(0.0f);
  2337. }
  2338. control_effects[CONTROL_EFFECT_TYPE_ROOT]->Add(spell);
  2339. }
  2340. void Entity::RemoveRootSpell(LuaSpell* spell) {
  2341. MutexList<LuaSpell*>* root_list = control_effects[CONTROL_EFFECT_TYPE_ROOT];
  2342. if (!root_list || root_list->size(true) == 0)
  2343. return;
  2344. root_list->Remove(spell);
  2345. if (root_list->size(true) == 0 && !IsRootImmune()) {
  2346. if (IsPlayer()){
  2347. if (!IsMezzedOrStunned())
  2348. ((Player*)this)->SetPlayerControlFlag(1, 8, false); // heading movement only
  2349. }
  2350. else {
  2351. // GetHighestSnare() will return 1.0f if no snares returning the spawn to full speed
  2352. SetSpeedMultiplier(GetHighestSnare());
  2353. }
  2354. if(!IsPlayer()) {
  2355. GetZone()->movementMgr->StopNavigation((Entity*)this);
  2356. ((Spawn*)this)->StopMovement();
  2357. }
  2358. }
  2359. }
  2360. void Entity::AddFearSpell(LuaSpell* spell){
  2361. if (!spell)
  2362. return;
  2363. if (!control_effects[CONTROL_EFFECT_TYPE_FEAR])
  2364. control_effects[CONTROL_EFFECT_TYPE_FEAR] = new MutexList<LuaSpell*>;
  2365. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_FEAR]->size(true) == 0 && !IsFearImmune()){
  2366. ((Player*)this)->SetPlayerControlFlag(4, 4, true); // feared
  2367. if (!IsMezzedOrStunned() && !IsStifled())
  2368. GetZone()->LockAllSpells((Player*)this);
  2369. }
  2370. if (!IsFearImmune() && IsNPC())
  2371. {
  2372. HaltMovement();
  2373. }
  2374. control_effects[CONTROL_EFFECT_TYPE_FEAR]->Add(spell);
  2375. }
  2376. void Entity::RemoveFearSpell(LuaSpell* spell){
  2377. MutexList<LuaSpell*>* fear_list = control_effects[CONTROL_EFFECT_TYPE_FEAR];
  2378. if (!fear_list || fear_list->size(true) == 0)
  2379. return;
  2380. fear_list->Remove(spell);
  2381. if (IsPlayer() && fear_list->size(true) == 0 && !IsFearImmune()){
  2382. ((Player*)this)->SetPlayerControlFlag(4, 4, false); // feared disabled
  2383. if (!IsMezzedOrStunned() && !IsStifled())
  2384. GetZone()->LockAllSpells((Player*)this);
  2385. }
  2386. if (IsNPC())
  2387. {
  2388. HaltMovement();
  2389. }
  2390. }
  2391. void Entity::AddSnareSpell(LuaSpell* spell) {
  2392. if (!spell)
  2393. return;
  2394. if (!control_effects[CONTROL_EFFECT_TYPE_SNARE])
  2395. control_effects[CONTROL_EFFECT_TYPE_SNARE] = new MutexList<LuaSpell*>;
  2396. control_effects[CONTROL_EFFECT_TYPE_SNARE]->Add(spell);
  2397. // Don't set speed multiplier if there is a root or no snare values
  2398. MutexList<LuaSpell*>* roots = control_effects[CONTROL_EFFECT_TYPE_ROOT];
  2399. if ((!roots || roots->size(true) == 0) && snare_values.size() > 0)
  2400. SetSpeedMultiplier(GetHighestSnare());
  2401. }
  2402. void Entity::RemoveSnareSpell(LuaSpell* spell) {
  2403. MutexList<LuaSpell*>* snare_list = control_effects[CONTROL_EFFECT_TYPE_SNARE];
  2404. if (!snare_list || snare_list->size(true) == 0)
  2405. return;
  2406. snare_list->Remove(spell);
  2407. snare_values.erase(spell);
  2408. //LogWrite(PLAYER__ERROR, 0, "Debug", "snare_values.size() = %u", snare_values.size());
  2409. // only change speeds if there are no roots
  2410. MutexList<LuaSpell*>* roots = control_effects[CONTROL_EFFECT_TYPE_ROOT];
  2411. if (!roots || roots->size(true) == 0) {
  2412. float multiplier = GetHighestSnare();
  2413. //LogWrite(PLAYER__ERROR, 0, "Debug", "GetHighestSnare() = %f", multiplier);
  2414. SetSpeedMultiplier(multiplier);
  2415. }
  2416. }
  2417. void Entity::SetSnareValue(LuaSpell* spell, float snare_val) {
  2418. if (!spell)
  2419. return;
  2420. snare_values[spell] = snare_val;
  2421. }
  2422. float Entity::GetHighestSnare() {
  2423. // For simplicity this will return the highest snare value, which is actually the lowest value
  2424. float ret = 1.0f;
  2425. float weight_diff = 0.0f;
  2426. if (IsPlayer() && rule_manager.GetGlobalRule(R_Player, WeightInflictsSpeed)->GetBool()) {
  2427. float weight_pct_impact = rule_manager.GetGlobalRule(R_Player, WeightPercentImpact)->GetFloat();
  2428. float weight_pct_cap = rule_manager.GetGlobalRule(R_Player, WeightPercentCap)->GetFloat();
  2429. if(weight_pct_impact > 1.0f) {
  2430. weight_pct_impact = 1.0f;
  2431. }
  2432. if(weight_pct_cap < weight_pct_impact) {
  2433. weight_pct_impact = weight_pct_cap;
  2434. }
  2435. int32 weight = GetInfoStruct()->get_weight();
  2436. int32 max_weight = GetInfoStruct()->get_max_weight();
  2437. if(weight > max_weight) {
  2438. int32 diff = weight - max_weight;
  2439. weight_diff = (float)diff * weight_pct_impact; // percentage impact rule on weight "per stone", default 1%
  2440. if(weight_diff > weight_pct_cap) // cap weight impact rule
  2441. weight_diff = weight_pct_cap; // cap weight impact rule
  2442. }
  2443. }
  2444. if (snare_values.size() == 0)
  2445. return ((ret - weight_diff) < 0.0f ) ? 0.0f : (ret - weight_diff);
  2446. map<LuaSpell*, float>::iterator itr;
  2447. for (itr = snare_values.begin(); itr != snare_values.end(); itr++) {
  2448. if (itr->second < ret)
  2449. ret = itr->second;
  2450. }
  2451. return ((ret - weight_diff) < 0.0f ) ? 0.0f : (ret - weight_diff);
  2452. }
  2453. bool Entity::IsSnared() {
  2454. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_SNARE])
  2455. return false;
  2456. MutexList<LuaSpell*>* snare_list = control_effects[CONTROL_EFFECT_TYPE_SNARE];
  2457. return (!snare_list || snare_list->size(true) == 0) == false;
  2458. }
  2459. bool Entity::IsMezzed(){
  2460. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_MEZ])
  2461. return false;
  2462. MutexList<LuaSpell*>* mez_spells = control_effects[CONTROL_EFFECT_TYPE_MEZ];
  2463. return (!mez_spells || mez_spells->size(true) == 0 || IsMezImmune()) == false;
  2464. }
  2465. bool Entity::IsStifled(){
  2466. if (!control_effects[CONTROL_EFFECT_TYPE_STIFLE])
  2467. return false;
  2468. MutexList<LuaSpell*>* stifle_list = control_effects[CONTROL_EFFECT_TYPE_STIFLE];
  2469. return (!stifle_list || stifle_list->size(true) == 0 || IsStifleImmune()) == false;
  2470. }
  2471. bool Entity::IsDazed(){
  2472. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_DAZE])
  2473. return false;
  2474. MutexList<LuaSpell*>* daze_list = control_effects[CONTROL_EFFECT_TYPE_DAZE];
  2475. return (!daze_list || daze_list->size(true) == 0 || IsDazeImmune()) == false;
  2476. }
  2477. bool Entity::IsStunned(){
  2478. if (!control_effects[CONTROL_EFFECT_TYPE_STUN])
  2479. return false;
  2480. MutexList<LuaSpell*>* stun_list = control_effects[CONTROL_EFFECT_TYPE_STUN];
  2481. return (!stun_list || stun_list->size(true) == 0 || IsStunImmune()) == false;
  2482. }
  2483. bool Entity::IsRooted(){
  2484. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_ROOT])
  2485. return false;
  2486. MutexList<LuaSpell*>* root_list = control_effects[CONTROL_EFFECT_TYPE_ROOT];
  2487. return (!root_list || root_list->size(true) == 0 || IsRootImmune()) == false;
  2488. }
  2489. bool Entity::IsFeared(){
  2490. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_FEAR])
  2491. return false;
  2492. MutexList<LuaSpell*>* fear_list = control_effects[CONTROL_EFFECT_TYPE_FEAR];
  2493. return (!fear_list || fear_list->size(true) == 0 || IsFearImmune()) == false;
  2494. }
  2495. void Entity::AddWaterwalkSpell(LuaSpell* spell){
  2496. if (!spell)
  2497. return;
  2498. if (!control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER])
  2499. control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER] = new MutexList<LuaSpell*>;
  2500. control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER]->Add(spell);
  2501. if (control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER]->size(true) == 1 && IsPlayer())
  2502. ((Player*)this)->SetPlayerControlFlag(3, 128, true); // enable walking underwater
  2503. }
  2504. void Entity::RemoveWaterwalkSpell(LuaSpell* spell){
  2505. MutexList<LuaSpell*>* waterwalk_list = control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER];
  2506. if (!waterwalk_list || waterwalk_list->size(true) == 0)
  2507. return;
  2508. waterwalk_list->Remove(spell);
  2509. if (waterwalk_list->size(true) == 0 && IsPlayer())
  2510. ((Player*)this)->SetPlayerControlFlag(3, 128, false); // disable walking underwater
  2511. }
  2512. void Entity::AddWaterjumpSpell(LuaSpell* spell){
  2513. if (!spell)
  2514. return;
  2515. if (!control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER])
  2516. control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER] = new MutexList<LuaSpell*>;
  2517. control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER]->Add(spell);
  2518. if (control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER]->size(true) == 1 && IsPlayer())
  2519. ((Player*)this)->SetPlayerControlFlag(4, 1, true); // enable moonjumps underwater
  2520. }
  2521. void Entity::RemoveWaterjumpSpell(LuaSpell* spell){
  2522. MutexList<LuaSpell*>* waterjump_list = control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER];
  2523. if (!waterjump_list || waterjump_list->size(true) == 0)
  2524. return;
  2525. waterjump_list->Remove(spell);
  2526. if (waterjump_list->size(true) == 0 && IsPlayer())
  2527. ((Player*)this)->SetPlayerControlFlag(4, 1, false); // disable moonjumps underwater
  2528. }
  2529. void Entity::AddAOEImmunity(LuaSpell* spell){
  2530. if (!spell)
  2531. return;
  2532. if (!immunities[IMMUNITY_TYPE_AOE])
  2533. immunities[IMMUNITY_TYPE_AOE] = new MutexList<LuaSpell*>;
  2534. immunities[IMMUNITY_TYPE_AOE]->Add(spell);
  2535. }
  2536. void Entity::RemoveAOEImmunity(LuaSpell* spell){
  2537. MutexList<LuaSpell*>* aoe_list = immunities[IMMUNITY_TYPE_AOE];
  2538. if (!aoe_list || aoe_list->size(true) == 0)
  2539. return;
  2540. aoe_list->Remove(spell);
  2541. }
  2542. bool Entity::IsAOEImmune(){
  2543. return (immunities[IMMUNITY_TYPE_AOE] && immunities[IMMUNITY_TYPE_AOE]->size(true));
  2544. }
  2545. void Entity::AddStunImmunity(LuaSpell* spell){
  2546. if (!spell)
  2547. return;
  2548. if (!immunities[IMMUNITY_TYPE_STUN])
  2549. immunities[IMMUNITY_TYPE_STUN] = new MutexList<LuaSpell*>;
  2550. if (IsPlayer() && IsStunned() && !IsMezzed()){
  2551. ((Player*)this)->SetPlayerControlFlag(4, 64, false);
  2552. if (!IsFeared() && !IsStifled())
  2553. ((Player*)this)->UnlockAllSpells();
  2554. }
  2555. immunities[IMMUNITY_TYPE_STUN]->Add(spell);
  2556. }
  2557. void Entity::RemoveStunImmunity(LuaSpell* spell){
  2558. MutexList<LuaSpell*>* stun_list = immunities[IMMUNITY_TYPE_STUN];
  2559. if (!stun_list || stun_list->size(true) == 0)
  2560. return;
  2561. stun_list->Remove(spell);
  2562. if (IsPlayer() && IsStunned() && !IsMezzed()){
  2563. ((Player*)this)->SetPlayerControlFlag(4, 64, true);
  2564. if (!IsFeared() && !IsStifled())
  2565. ((Player*)this)->UnlockAllSpells();
  2566. }
  2567. }
  2568. bool Entity::IsStunImmune(){
  2569. return (immunities[IMMUNITY_TYPE_STUN] && immunities[IMMUNITY_TYPE_STUN]->size(true) > 0);
  2570. }
  2571. void Entity::AddStifleImmunity(LuaSpell* spell){
  2572. if (!spell)
  2573. return;
  2574. if (!immunities[IMMUNITY_TYPE_STIFLE])
  2575. immunities[IMMUNITY_TYPE_STIFLE] = new MutexList<LuaSpell*>;
  2576. if (IsPlayer() && immunities[IMMUNITY_TYPE_STIFLE]->size(true) == 0){
  2577. if (IsStifled() && !IsMezzedOrStunned() && !IsFeared())
  2578. ((Player*)this)->UnlockAllSpells();
  2579. }
  2580. immunities[IMMUNITY_TYPE_STIFLE]->Add(spell);
  2581. }
  2582. void Entity::RemoveStifleImmunity(LuaSpell* spell){
  2583. MutexList<LuaSpell*>* stifle_list = immunities[IMMUNITY_TYPE_STIFLE];
  2584. if (!stifle_list || stifle_list->size(true) == 0)
  2585. return;
  2586. stifle_list->Remove(spell);
  2587. if (IsPlayer() && IsStifled() && !IsMezzedOrStunned() && !IsFeared())
  2588. ((Player*)this)->UnlockAllSpells();
  2589. }
  2590. bool Entity::IsStifleImmune(){
  2591. return (immunities[IMMUNITY_TYPE_STIFLE] && immunities[IMMUNITY_TYPE_STIFLE]->size(true) > 0);
  2592. }
  2593. void Entity::AddMezImmunity(LuaSpell* spell){
  2594. if (!spell)
  2595. return;
  2596. if (!immunities[IMMUNITY_TYPE_MEZ])
  2597. immunities[IMMUNITY_TYPE_MEZ] = new MutexList<LuaSpell*>;
  2598. if (IsPlayer() && IsMezzed() && !IsStunned()){
  2599. ((Player*)this)->SetPlayerControlFlag(4, 64, false);
  2600. if (!IsFeared() && !IsStifled())
  2601. ((Player*)this)->UnlockAllSpells();
  2602. }
  2603. immunities[IMMUNITY_TYPE_MEZ]->Add(spell);
  2604. }
  2605. void Entity::RemoveMezImmunity(LuaSpell* spell){
  2606. MutexList<LuaSpell*>* mez_list = immunities[IMMUNITY_TYPE_MEZ];
  2607. if (!mez_list || mez_list->size(true) == 0)
  2608. return;
  2609. mez_list->Remove(spell);
  2610. if (IsPlayer() && IsMezzed() && !IsStunned()){
  2611. ((Player*)this)->SetPlayerControlFlag(4, 64, true);
  2612. if (!IsFeared() && !IsStifled())
  2613. ((Player*)this)->LockAllSpells();
  2614. }
  2615. }
  2616. bool Entity::IsMezImmune(){
  2617. return (immunities[IMMUNITY_TYPE_MEZ] && immunities[IMMUNITY_TYPE_MEZ]->size(true) > 0);
  2618. }
  2619. void Entity::AddRootImmunity(LuaSpell* spell){
  2620. if (!spell)
  2621. return;
  2622. if (!immunities[IMMUNITY_TYPE_ROOT])
  2623. immunities[IMMUNITY_TYPE_ROOT] = new MutexList<LuaSpell*>;
  2624. if (IsPlayer() && IsRooted())
  2625. ((Player*)this)->SetPlayerControlFlag(1, 8, false);
  2626. immunities[IMMUNITY_TYPE_ROOT]->Add(spell);
  2627. }
  2628. void Entity::RemoveRootImmunity(LuaSpell* spell){
  2629. MutexList<LuaSpell*>* root_list = immunities[IMMUNITY_TYPE_ROOT];
  2630. if (!root_list || root_list->size(true) == 0)
  2631. return;
  2632. root_list->Remove(spell);
  2633. if (IsPlayer() && IsRooted())
  2634. ((Player*)this)->SetPlayerControlFlag(1, 8, true);
  2635. }
  2636. bool Entity::IsRootImmune(){
  2637. return (immunities[IMMUNITY_TYPE_ROOT] && immunities[IMMUNITY_TYPE_ROOT]->size(true) > 0);
  2638. }
  2639. void Entity::AddFearImmunity(LuaSpell* spell){
  2640. if (!spell)
  2641. return;
  2642. if (!immunities[IMMUNITY_TYPE_FEAR])
  2643. immunities[IMMUNITY_TYPE_FEAR] = new MutexList<LuaSpell*>;
  2644. if (IsPlayer() && IsFeared()){
  2645. if (!IsMezzedOrStunned() && !IsStifled())
  2646. ((Player*)this)->UnlockAllSpells();
  2647. ((Player*)this)->SetPlayerControlFlag(4, 4, false);
  2648. }
  2649. immunities[IMMUNITY_TYPE_FEAR]->Add(spell);
  2650. }
  2651. void Entity::RemoveFearImmunity(LuaSpell* spell){
  2652. MutexList<LuaSpell*>* fear_list = immunities[IMMUNITY_TYPE_FEAR];
  2653. if (!fear_list || fear_list->size(true) == 0)
  2654. return;
  2655. fear_list->Remove(spell);
  2656. if (IsPlayer() && IsFeared()){
  2657. if (!IsMezzedOrStunned() && !IsStifled())
  2658. ((Player*)this)->LockAllSpells();
  2659. ((Player*)this)->SetPlayerControlFlag(4, 4, true);
  2660. }
  2661. }
  2662. bool Entity::IsFearImmune(){
  2663. return (immunities[IMMUNITY_TYPE_FEAR] && immunities[IMMUNITY_TYPE_FEAR]->size(true) > 0);
  2664. }
  2665. void Entity::AddDazeImmunity(LuaSpell* spell){
  2666. if (!spell)
  2667. return;
  2668. if (!immunities[IMMUNITY_TYPE_DAZE])
  2669. immunities[IMMUNITY_TYPE_DAZE] = new MutexList<LuaSpell*>;
  2670. immunities[IMMUNITY_TYPE_DAZE]->Add(spell);
  2671. }
  2672. void Entity::RemoveDazeImmunity(LuaSpell* spell){
  2673. MutexList<LuaSpell*>* daze_list = immunities[IMMUNITY_TYPE_DAZE];
  2674. if (!daze_list || daze_list->size(true) == 0)
  2675. return;
  2676. daze_list->Remove(spell);
  2677. }
  2678. bool Entity::IsDazeImmune(){
  2679. return (immunities[IMMUNITY_TYPE_DAZE] && immunities[IMMUNITY_TYPE_DAZE]->size(true) > 0);
  2680. }
  2681. void Entity::AddImmunity(LuaSpell* spell, int16 type){
  2682. if (!spell)
  2683. return;
  2684. if (!immunities[type])
  2685. immunities[type] = new MutexList<LuaSpell*>;
  2686. immunities[type]->Add(spell);
  2687. }
  2688. void Entity::RemoveImmunity(LuaSpell* spell, int16 type){
  2689. MutexList<LuaSpell*>* list = immunities[type];
  2690. if (!list || list->size(true) == 0)
  2691. return;
  2692. list->Remove(spell);
  2693. }
  2694. bool Entity::IsImmune(int16 type){
  2695. return (immunities[type] && immunities[type]->size(true) > 0);
  2696. }
  2697. void Entity::RemoveEffectsFromLuaSpell(LuaSpell* spell){
  2698. if (!spell)
  2699. return;
  2700. //Attempt to remove all applied effects from this spell when spell has been removed from just this target. Should improve performance/easier maitenance
  2701. int32 effect_bitmask = spell->effect_bitmask;
  2702. if (effect_bitmask == 0)
  2703. return;
  2704. if (effect_bitmask & EFFECT_FLAG_STUN)
  2705. RemoveStunSpell(spell);
  2706. if (effect_bitmask & EFFECT_FLAG_ROOT)
  2707. RemoveRootSpell(spell);
  2708. if (effect_bitmask & EFFECT_FLAG_MEZ)
  2709. RemoveMezSpell(spell);
  2710. if (effect_bitmask & EFFECT_FLAG_STIFLE)
  2711. RemoveStifleSpell(spell);
  2712. if (effect_bitmask & EFFECT_FLAG_DAZE)
  2713. RemoveDazeSpell(spell);
  2714. if (effect_bitmask & EFFECT_FLAG_FEAR)
  2715. RemoveFearSpell(spell);
  2716. if (effect_bitmask & EFFECT_FLAG_SPELLBONUS)
  2717. RemoveSpellBonus(spell);
  2718. if (effect_bitmask & EFFECT_FLAG_SKILLBONUS)
  2719. RemoveSkillBonus(spell->spell->GetSpellID());
  2720. if (effect_bitmask & EFFECT_FLAG_STEALTH)
  2721. RemoveStealthSpell(spell);
  2722. if (effect_bitmask & EFFECT_FLAG_INVIS)
  2723. RemoveInvisSpell(spell);
  2724. if (effect_bitmask & EFFECT_FLAG_SNARE)
  2725. RemoveSnareSpell(spell);
  2726. if (effect_bitmask & EFFECT_FLAG_WATERWALK)
  2727. RemoveWaterwalkSpell(spell);
  2728. if (effect_bitmask & EFFECT_FLAG_WATERJUMP)
  2729. RemoveWaterjumpSpell(spell);
  2730. if (effect_bitmask & EFFECT_FLAG_FLIGHT)
  2731. RemoveFlightSpell(spell);
  2732. if (effect_bitmask & EFFECT_FLAG_GLIDE)
  2733. RemoveGlideSpell(spell);
  2734. if (effect_bitmask & EFFECT_FLAG_AOE_IMMUNE)
  2735. RemoveAOEImmunity(spell);
  2736. if (effect_bitmask & EFFECT_FLAG_STUN_IMMUNE)
  2737. RemoveStunImmunity(spell);
  2738. if (effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE)
  2739. RemoveMezImmunity(spell);
  2740. if (effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE)
  2741. RemoveDazeImmunity(spell);
  2742. if (effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE)
  2743. RemoveRootImmunity(spell);
  2744. if (effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE)
  2745. RemoveStifleImmunity(spell);
  2746. if (effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE)
  2747. RemoveFearImmunity(spell);
  2748. if (effect_bitmask & EFFECT_FLAG_SAFEFALL)
  2749. RemoveSafefallSpell(spell);
  2750. }
  2751. void Entity::RemoveSkillBonus(int32 spell_id){
  2752. //This is a virtual, just making it so we don't have to do extra checks for player/npcs
  2753. return;
  2754. }
  2755. void Entity::AddFlightSpell(LuaSpell* spell){
  2756. if (!spell)
  2757. return;
  2758. if (!control_effects[CONTROL_EFFECT_TYPE_FLIGHT])
  2759. control_effects[CONTROL_EFFECT_TYPE_FLIGHT] = new MutexList<LuaSpell*>;
  2760. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_FLIGHT]->size(true) == 0)
  2761. ((Player*)this)->SetPlayerControlFlag(5, 32, true);
  2762. control_effects[CONTROL_EFFECT_TYPE_FLIGHT]->Add(spell);
  2763. }
  2764. void Entity::RemoveFlightSpell(LuaSpell* spell){
  2765. MutexList<LuaSpell*>* flight_list = control_effects[CONTROL_EFFECT_TYPE_FLIGHT];
  2766. if (!flight_list || flight_list->size(true) == 0)
  2767. return;
  2768. flight_list->Remove(spell);
  2769. if (IsPlayer() && flight_list->size(true) == 0)
  2770. ((Player*)this)->SetPlayerControlFlag(5, 32, false);
  2771. }
  2772. void Entity::AddGlideSpell(LuaSpell* spell){
  2773. if (!spell)
  2774. return;
  2775. if (!control_effects[CONTROL_EFFECT_TYPE_GLIDE])
  2776. control_effects[CONTROL_EFFECT_TYPE_GLIDE] = new MutexList<LuaSpell*>;
  2777. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_GLIDE]->size(true) == 0)
  2778. ((Player*)this)->SetPlayerControlFlag(4, 16, true);
  2779. control_effects[CONTROL_EFFECT_TYPE_GLIDE]->Add(spell);
  2780. }
  2781. void Entity::RemoveGlideSpell(LuaSpell* spell){
  2782. MutexList<LuaSpell*>* glide_list = control_effects[CONTROL_EFFECT_TYPE_GLIDE];
  2783. if (!glide_list || glide_list->size(true) == 0)
  2784. return;
  2785. glide_list->Remove(spell);
  2786. if (IsPlayer() && glide_list->size(true) == 0)
  2787. ((Player*)this)->SetPlayerControlFlag(4, 16, false);
  2788. }
  2789. void Entity::AddSafefallSpell(LuaSpell* spell){
  2790. if (!spell)
  2791. return;
  2792. if (!control_effects[CONTROL_EFFECT_TYPE_SAFEFALL])
  2793. control_effects[CONTROL_EFFECT_TYPE_SAFEFALL] = new MutexList<LuaSpell*>;
  2794. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_SAFEFALL]->size(true) == 0)
  2795. ((Player*)this)->SetPlayerControlFlag(4, 32, true);
  2796. control_effects[CONTROL_EFFECT_TYPE_SAFEFALL]->Add(spell);
  2797. }
  2798. void Entity::RemoveSafefallSpell(LuaSpell* spell){
  2799. MutexList<LuaSpell*>* safe_list = control_effects[CONTROL_EFFECT_TYPE_SAFEFALL];
  2800. if (!safe_list || safe_list->size(true) == 0)
  2801. return;
  2802. safe_list->Remove(spell);
  2803. if (IsPlayer() && safe_list->size(true) == 0)
  2804. ((Player*)this)->SetPlayerControlFlag(4, 32, false);
  2805. }
  2806. void Entity::UpdateGroupMemberInfo(bool inGroupMgrLock, bool groupMembersLocked) {
  2807. if (!group_member_info || group_id == 0)
  2808. return;
  2809. if(!inGroupMgrLock)
  2810. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  2811. PlayerGroup* group = world.GetGroupManager()->GetGroup(group_id);
  2812. if (group)
  2813. group->UpdateGroupMemberInfo(this, groupMembersLocked);
  2814. if(!inGroupMgrLock)
  2815. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  2816. }
  2817. #include "WorldDatabase.h"
  2818. extern WorldDatabase database;
  2819. void Entity::CustomizeAppearance(PacketStruct* packet) {
  2820. bool is_soga = packet->getType_int8_ByName("is_soga") == 1 ? true : false;
  2821. int16 model_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("race_file").data);
  2822. EQ2_Color skin_color = packet->getType_EQ2_Color_ByName("skin_color");
  2823. EQ2_Color skin_color2 = packet->getType_EQ2_Color_ByName("skin_color2");
  2824. EQ2_Color eye_color = packet->getType_EQ2_Color_ByName("eye_color");
  2825. EQ2_Color hair_color1 = packet->getType_EQ2_Color_ByName("hair_color1");
  2826. EQ2_Color hair_color2 = packet->getType_EQ2_Color_ByName("hair_color2");
  2827. EQ2_Color hair_highlight = packet->getType_EQ2_Color_ByName("hair_highlight");
  2828. int16 hair_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("hair_file").data);
  2829. EQ2_Color hair_type_color = packet->getType_EQ2_Color_ByName("hair_type_color");
  2830. EQ2_Color hair_type_highlight_color = packet->getType_EQ2_Color_ByName("hair_type_highlight_color");
  2831. int16 face_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("face_file").data);
  2832. EQ2_Color hair_face_color = packet->getType_EQ2_Color_ByName("hair_face_color");
  2833. EQ2_Color hair_face_highlight_color = packet->getType_EQ2_Color_ByName("hair_face_highlight_color");
  2834. int16 wing_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("wing_file").data);
  2835. EQ2_Color wing_color1 = packet->getType_EQ2_Color_ByName("wing_color1");
  2836. EQ2_Color wing_color2 = packet->getType_EQ2_Color_ByName("wing_color2");
  2837. int16 chest_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("chest_file").data);
  2838. EQ2_Color shirt_color = packet->getType_EQ2_Color_ByName("shirt_color");
  2839. EQ2_Color unknown_chest_color = packet->getType_EQ2_Color_ByName("unknown_chest_color");
  2840. int16 legs_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("legs_file").data);
  2841. EQ2_Color pants_color = packet->getType_EQ2_Color_ByName("pants_color");
  2842. EQ2_Color unknown_legs_color = packet->getType_EQ2_Color_ByName("unknown_legs_color");
  2843. EQ2_Color unknown2 = packet->getType_EQ2_Color_ByName("unknown2");
  2844. float eyes2[3];
  2845. eyes2[0] = packet->getType_float_ByName("eyes2", 0) * 100;
  2846. eyes2[1] = packet->getType_float_ByName("eyes2", 1) * 100;
  2847. eyes2[2] = packet->getType_float_ByName("eyes2", 2) * 100;
  2848. float ears[3];
  2849. ears[0] = packet->getType_float_ByName("ears", 0) * 100;
  2850. ears[1] = packet->getType_float_ByName("ears", 1) * 100;
  2851. ears[2] = packet->getType_float_ByName("ears", 2) * 100;
  2852. float eye_brows[3];
  2853. eye_brows[0] = packet->getType_float_ByName("eye_brows", 0) * 100;
  2854. eye_brows[1] = packet->getType_float_ByName("eye_brows", 1) * 100;
  2855. eye_brows[2] = packet->getType_float_ByName("eye_brows", 2) * 100;
  2856. float cheeks[3];
  2857. cheeks[0] = packet->getType_float_ByName("cheeks", 0) * 100;
  2858. cheeks[1] = packet->getType_float_ByName("cheeks", 1) * 100;
  2859. cheeks[2] = packet->getType_float_ByName("cheeks", 2) * 100;
  2860. float lips[3];
  2861. lips[0] = packet->getType_float_ByName("lips", 0) * 100;
  2862. lips[1] = packet->getType_float_ByName("lips", 1) * 100;
  2863. lips[2] = packet->getType_float_ByName("lips", 2) * 100;
  2864. float chin[3];
  2865. chin[0] = packet->getType_float_ByName("chin", 0) * 100;
  2866. chin[1] = packet->getType_float_ByName("chin", 1) * 100;
  2867. chin[2] = packet->getType_float_ByName("chin", 2) * 100;
  2868. float nose[3];
  2869. nose[0] = packet->getType_float_ByName("nose", 0) * 100;
  2870. nose[1] = packet->getType_float_ByName("nose", 1) * 100;
  2871. nose[2] = packet->getType_float_ByName("nose", 2) * 100;
  2872. sint8 body_size = (sint8)(packet->getType_float_ByName("body_size") * 100);
  2873. sint8 body_age = (sint8)(packet->getType_float_ByName("body_age") * 100);
  2874. if (is_soga) {
  2875. appearance.soga_model_type = model_id;
  2876. features.soga_skin_color = skin_color;
  2877. features.soga_eye_color = eye_color;
  2878. features.soga_hair_color1 = hair_color1;
  2879. features.soga_hair_color2 = hair_color2;
  2880. features.soga_hair_highlight_color = hair_highlight;
  2881. features.soga_hair_type = hair_id;
  2882. features.soga_hair_type_color = hair_type_color;
  2883. features.soga_hair_type_highlight_color = hair_type_highlight_color;
  2884. features.soga_hair_face_type = face_id;
  2885. features.soga_hair_face_color = hair_face_color;
  2886. features.soga_hair_face_highlight_color = hair_face_highlight_color;
  2887. features.wing_type = wing_id;
  2888. features.wing_color1 = wing_color1;
  2889. features.wing_color2 = wing_color2;
  2890. features.soga_chest_type = chest_id;
  2891. features.shirt_color = shirt_color;
  2892. features.soga_legs_type = legs_id;
  2893. features.pants_color = pants_color;
  2894. features.soga_eye_type[0] = eyes2[0];
  2895. features.soga_eye_type[1] = eyes2[1];
  2896. features.soga_eye_type[2] = eyes2[2];
  2897. features.soga_ear_type[0] = ears[0];
  2898. features.soga_ear_type[0] = ears[1];
  2899. features.soga_ear_type[0] = ears[2];
  2900. features.soga_eye_brow_type[0] = eye_brows[0];
  2901. features.soga_eye_brow_type[1] = eye_brows[1];
  2902. features.soga_eye_brow_type[2] = eye_brows[2];
  2903. features.soga_cheek_type[0] = cheeks[0];
  2904. features.soga_cheek_type[1] = cheeks[1];
  2905. features.soga_cheek_type[2] = cheeks[2];
  2906. features.soga_lip_type[0] = lips[0];
  2907. features.soga_lip_type[1] = lips[1];
  2908. features.soga_lip_type[2] = lips[2];
  2909. features.soga_chin_type[0] = chin[0];
  2910. features.soga_chin_type[1] = chin[1];
  2911. features.soga_chin_type[2] = chin[2];
  2912. features.soga_nose_type[0] = nose[0];
  2913. features.soga_nose_type[1] = nose[1];
  2914. features.soga_nose_type[2] = nose[2];
  2915. }
  2916. else {
  2917. appearance.model_type = model_id;
  2918. features.skin_color = skin_color;
  2919. features.eye_color = eye_color;
  2920. features.hair_color1 = hair_color1;
  2921. features.hair_color2 = hair_color2;
  2922. features.hair_highlight_color = hair_highlight;
  2923. features.hair_type = hair_id;
  2924. features.hair_type_color = hair_type_color;
  2925. features.hair_type_highlight_color = hair_type_highlight_color;
  2926. features.hair_face_type = face_id;
  2927. features.hair_face_color = hair_face_color;
  2928. features.hair_face_highlight_color = hair_face_highlight_color;
  2929. features.wing_type = wing_id;
  2930. features.wing_color1 = wing_color1;
  2931. features.wing_color2 = wing_color2;
  2932. features.chest_type = chest_id;
  2933. features.shirt_color = shirt_color;
  2934. features.legs_type = legs_id;
  2935. features.pants_color = pants_color;
  2936. features.eye_type[0] = eyes2[0];
  2937. features.eye_type[1] = eyes2[1];
  2938. features.eye_type[2] = eyes2[2];
  2939. features.ear_type[0] = ears[0];
  2940. features.ear_type[0] = ears[1];
  2941. features.ear_type[0] = ears[2];
  2942. features.eye_brow_type[0] = eye_brows[0];
  2943. features.eye_brow_type[1] = eye_brows[1];
  2944. features.eye_brow_type[2] = eye_brows[2];
  2945. features.cheek_type[0] = cheeks[0];
  2946. features.cheek_type[1] = cheeks[1];
  2947. features.cheek_type[2] = cheeks[2];
  2948. features.lip_type[0] = lips[0];
  2949. features.lip_type[1] = lips[1];
  2950. features.lip_type[2] = lips[2];
  2951. features.chin_type[0] = chin[0];
  2952. features.chin_type[1] = chin[1];
  2953. features.chin_type[2] = chin[2];
  2954. features.nose_type[0] = nose[0];
  2955. features.nose_type[1] = nose[1];
  2956. features.nose_type[2] = nose[2];
  2957. }
  2958. features.body_size = body_size;
  2959. features.body_age = body_age;
  2960. features.soga_body_size = body_size;
  2961. features.soga_body_age = body_age;
  2962. info_changed = true;
  2963. changed = true;
  2964. }
  2965. void Entity::AddSkillBonus(int32 spell_id, int32 skill_id, float value) {
  2966. // handled in npc or player
  2967. return;
  2968. }
  2969. bool Entity::HasControlEffect(int8 type)
  2970. {
  2971. if (type >= CONTROL_MAX_EFFECTS)
  2972. return false;
  2973. MutexList<LuaSpell*>* spell_list = control_effects[type];
  2974. if (!spell_list || spell_list->size(true) == 0)
  2975. return false;
  2976. return true;
  2977. }
  2978. void Entity::HaltMovement()
  2979. {
  2980. this->ClearRunningLocations();
  2981. if (GetZone())
  2982. GetZone()->movementMgr->StopNavigation(this);
  2983. RunToLocation(GetX(), GetY(), GetZ());
  2984. }
  2985. std::string Entity::GetInfoStructString(std::string field)
  2986. {
  2987. map<string, boost::function<std::string()>>::const_iterator itr = get_string_funcs.find(field);
  2988. if(itr != get_string_funcs.end())
  2989. {
  2990. auto func = (itr->second)();
  2991. return func;
  2992. }
  2993. return std::string("");
  2994. }
  2995. int8 Entity::GetInfoStructInt8(std::string field)
  2996. {
  2997. map<string, boost::function<int8()>>::const_iterator itr = get_int8_funcs.find(field);
  2998. if(itr != get_int8_funcs.end())
  2999. {
  3000. auto func = (itr->second)();
  3001. return func;
  3002. }
  3003. return 0;
  3004. }
  3005. int16 Entity::GetInfoStructInt16(std::string field)
  3006. {
  3007. map<string, boost::function<int16()>>::const_iterator itr = get_int16_funcs.find(field);
  3008. if(itr != get_int16_funcs.end())
  3009. {
  3010. auto func = (itr->second)();
  3011. return func;
  3012. }
  3013. return 0;
  3014. }
  3015. int32 Entity::GetInfoStructInt32(std::string field)
  3016. {
  3017. map<string, boost::function<int32()>>::const_iterator itr = get_int32_funcs.find(field);
  3018. if(itr != get_int32_funcs.end())
  3019. {
  3020. auto func = (itr->second)();
  3021. return func;
  3022. }
  3023. return 0;
  3024. }
  3025. int64 Entity::GetInfoStructInt64(std::string field)
  3026. {
  3027. map<string, boost::function<int64()>>::const_iterator itr = get_int64_funcs.find(field);
  3028. if(itr != get_int64_funcs.end())
  3029. {
  3030. auto func = (itr->second)();
  3031. return func;
  3032. }
  3033. return 0;
  3034. }
  3035. sint8 Entity::GetInfoStructSInt8(std::string field)
  3036. {
  3037. map<string, boost::function<sint8()>>::const_iterator itr = get_sint8_funcs.find(field);
  3038. if(itr != get_sint8_funcs.end())
  3039. {
  3040. auto func = (itr->second)();
  3041. return func;
  3042. }
  3043. return 0;
  3044. }
  3045. sint16 Entity::GetInfoStructSInt16(std::string field)
  3046. {
  3047. map<string, boost::function<sint16()>>::const_iterator itr = get_sint16_funcs.find(field);
  3048. if(itr != get_sint16_funcs.end())
  3049. {
  3050. auto func = (itr->second)();
  3051. return func;
  3052. }
  3053. return 0;
  3054. }
  3055. sint32 Entity::GetInfoStructSInt32(std::string field)
  3056. {
  3057. map<string, boost::function<sint32()>>::const_iterator itr = get_sint32_funcs.find(field);
  3058. if(itr != get_sint32_funcs.end())
  3059. {
  3060. auto func = (itr->second)();
  3061. return func;
  3062. }
  3063. return 0;
  3064. }
  3065. sint64 Entity::GetInfoStructSInt64(std::string field)
  3066. {
  3067. map<string, boost::function<sint64()>>::const_iterator itr = get_sint64_funcs.find(field);
  3068. if(itr != get_sint64_funcs.end())
  3069. {
  3070. auto func = (itr->second)();
  3071. return func;
  3072. }
  3073. return 0;
  3074. }
  3075. float Entity::GetInfoStructFloat(std::string field)
  3076. {
  3077. map<string, boost::function<float()>>::const_iterator itr = get_float_funcs.find(field);
  3078. if(itr != get_float_funcs.end())
  3079. {
  3080. auto func = (itr->second)();
  3081. return func;
  3082. }
  3083. return 0.0f;
  3084. }
  3085. int64 Entity::GetInfoStructUInt(std::string field)
  3086. {
  3087. map<string, boost::function<int8()>>::const_iterator itr = get_int8_funcs.find(field);
  3088. if(itr != get_int8_funcs.end())
  3089. {
  3090. auto func = (itr->second)();
  3091. return func;
  3092. }
  3093. map<string, boost::function<int16()>>::const_iterator itr2 = get_int16_funcs.find(field);
  3094. if(itr2 != get_int16_funcs.end())
  3095. {
  3096. auto func = (itr2->second)();
  3097. return func;
  3098. }
  3099. map<string, boost::function<int32()>>::const_iterator itr3 = get_int32_funcs.find(field);
  3100. if(itr3 != get_int32_funcs.end())
  3101. {
  3102. auto func = (itr3->second)();
  3103. return func;
  3104. }
  3105. map<string, boost::function<int64()>>::const_iterator itr4 = get_int64_funcs.find(field);
  3106. if(itr4 != get_int64_funcs.end())
  3107. {
  3108. auto func = (itr4->second)();
  3109. return func;
  3110. }
  3111. return 0;
  3112. }
  3113. sint64 Entity::GetInfoStructSInt(std::string field)
  3114. {
  3115. map<string, boost::function<sint8()>>::const_iterator itr = get_sint8_funcs.find(field);
  3116. if(itr != get_sint8_funcs.end())
  3117. {
  3118. auto func = (itr->second)();
  3119. return func;
  3120. }
  3121. map<string, boost::function<sint16()>>::const_iterator itr2 = get_sint16_funcs.find(field);
  3122. if(itr2 != get_sint16_funcs.end())
  3123. {
  3124. auto func = (itr2->second)();
  3125. return func;
  3126. }
  3127. map<string, boost::function<sint32()>>::const_iterator itr3 = get_sint32_funcs.find(field);
  3128. if(itr3 != get_sint32_funcs.end())
  3129. {
  3130. auto func = (itr3->second)();
  3131. return func;
  3132. }
  3133. map<string, boost::function<sint64()>>::const_iterator itr4 = get_sint64_funcs.find(field);
  3134. if(itr4 != get_sint64_funcs.end())
  3135. {
  3136. auto func = (itr4->second)();
  3137. return func;
  3138. }
  3139. return 0;
  3140. }
  3141. bool Entity::SetInfoStructString(std::string field, std::string value)
  3142. {
  3143. map<string, boost::function<void(std::string)>>::const_iterator itr = set_string_funcs.find(field);
  3144. if(itr != set_string_funcs.end())
  3145. {
  3146. (itr->second)(value);
  3147. return true;
  3148. }
  3149. return false;
  3150. }
  3151. bool Entity::SetInfoStructUInt(std::string field, int64 value)
  3152. {
  3153. map<string, boost::function<void(int8)>>::const_iterator itr = set_int8_funcs.find(field);
  3154. if(itr != set_int8_funcs.end())
  3155. {
  3156. (itr->second)((int8)value);
  3157. return true;
  3158. }
  3159. map<string, boost::function<void(int16)>>::const_iterator itr2 = set_int16_funcs.find(field);
  3160. if(itr2 != set_int16_funcs.end())
  3161. {
  3162. (itr2->second)((int16)value);
  3163. return true;
  3164. }
  3165. map<string, boost::function<void(int32)>>::const_iterator itr3 = set_int32_funcs.find(field);
  3166. if(itr3 != set_int32_funcs.end())
  3167. {
  3168. (itr3->second)((int32)value);
  3169. return true;
  3170. }
  3171. map<string, boost::function<void(int64)>>::const_iterator itr4 = set_int64_funcs.find(field);
  3172. if(itr4 != set_int64_funcs.end())
  3173. {
  3174. (itr4->second)(value);
  3175. return true;
  3176. }
  3177. return false;
  3178. }
  3179. bool Entity::SetInfoStructSInt(std::string field, sint64 value)
  3180. {
  3181. map<string, boost::function<void(sint8)>>::const_iterator itr = set_sint8_funcs.find(field);
  3182. if(itr != set_sint8_funcs.end())
  3183. {
  3184. (itr->second)((sint8)value);
  3185. return true;
  3186. }
  3187. map<string, boost::function<void(sint16)>>::const_iterator itr2 = set_sint16_funcs.find(field);
  3188. if(itr2 != set_sint16_funcs.end())
  3189. {
  3190. (itr2->second)((sint16)value);
  3191. return true;
  3192. }
  3193. map<string, boost::function<void(sint32)>>::const_iterator itr3 = set_sint32_funcs.find(field);
  3194. if(itr3 != set_sint32_funcs.end())
  3195. {
  3196. (itr3->second)((sint32)value);
  3197. return true;
  3198. }
  3199. map<string, boost::function<void(sint64)>>::const_iterator itr4 = set_sint64_funcs.find(field);
  3200. if(itr4 != set_sint64_funcs.end())
  3201. {
  3202. (itr4->second)(value);
  3203. return true;
  3204. }
  3205. return false;
  3206. }
  3207. bool Entity::SetInfoStructFloat(std::string field, float value)
  3208. {
  3209. map<string, boost::function<void(float)>>::const_iterator itr = set_float_funcs.find(field);
  3210. if(itr != set_float_funcs.end())
  3211. {
  3212. (itr->second)(value);
  3213. return true;
  3214. }
  3215. return false;
  3216. }
  3217. Entity* Entity::GetOwner() {
  3218. Entity* ent = nullptr;
  3219. if(!GetZone()) {
  3220. return ent;
  3221. }
  3222. Spawn* spawn = GetZone()->GetSpawnByID(owner);
  3223. if ( spawn && spawn->IsEntity() )
  3224. ent = (Entity*)spawn;
  3225. return ent;
  3226. }
  3227. bool Entity::IsEngagedInEncounter(Spawn** res) {
  3228. if(res) {
  3229. *res = nullptr;
  3230. }
  3231. bool ret = false;
  3232. set<int32>::iterator itr;
  3233. MHatedBy.lock();
  3234. if(IsPlayer()) {
  3235. for (itr = HatedBy.begin(); itr != HatedBy.end(); itr++) {
  3236. Spawn* spawn = GetZone()->GetSpawnByID(*itr);
  3237. if (spawn && spawn->IsNPC() && ((NPC*)spawn)->Brain() && (spawn->GetLockedNoLoot() == ENCOUNTER_STATE_LOCKED || spawn->GetLockedNoLoot() == ENCOUNTER_STATE_OVERMATCHED)) {
  3238. if((ret = ((NPC*)spawn)->Brain()->IsPlayerInEncounter(((Player*)this)->GetCharacterID()))) {
  3239. if(res)
  3240. *res = spawn;
  3241. break;
  3242. }
  3243. }
  3244. }
  3245. }
  3246. else {
  3247. for (itr = HatedBy.begin(); itr != HatedBy.end(); itr++) {
  3248. Spawn* spawn = GetZone()->GetSpawnByID(*itr);
  3249. if (spawn && spawn->IsNPC() && ((NPC*)spawn)->Brain() && (spawn->GetLockedNoLoot() == ENCOUNTER_STATE_LOCKED || spawn->GetLockedNoLoot() == ENCOUNTER_STATE_OVERMATCHED)) {
  3250. if((ret = ((NPC*)spawn)->Brain()->IsEntityInEncounter(GetID()))) {
  3251. if(res)
  3252. *res = spawn;
  3253. break;
  3254. }
  3255. }
  3256. }
  3257. }
  3258. MHatedBy.unlock();
  3259. return ret;
  3260. }
  3261. bool Entity::IsEngagedBySpawnID(int32 id) {
  3262. bool ret = false;
  3263. Spawn* spawn = GetZone()->GetSpawnByID(id);
  3264. if (spawn && spawn->IsNPC() && ((NPC*)spawn)->Brain()) {
  3265. ret = ((NPC*)spawn)->Brain()->IsEntityInEncounter(GetID());
  3266. }
  3267. return ret;
  3268. }
  3269. void Entity::SendControlEffectDetailsToClient(Client* client) {
  3270. client->Message(CHANNEL_COLOR_YELLOW, "Current control effects on %s", GetName());
  3271. client->Message(CHANNEL_COLOR_YELLOW, "-------------------------------");
  3272. for (int i = 0; i < CONTROL_MAX_EFFECTS; i++) {
  3273. if(control_effects[i]) {
  3274. MutexList<LuaSpell*>* spells = control_effects[i];
  3275. if(spells->size() > 0) {
  3276. MutexList<LuaSpell*>::iterator itr = spells->begin();
  3277. while(itr.Next()){
  3278. LuaSpell* spell = itr->value;
  3279. if(spell && spell->spell && spell->spell->GetSpellData()) {
  3280. client->Message(CHANNEL_COLOR_YELLOW, "Spell %s (%u) control effect %s", spell->spell->GetName(), spell->spell->GetSpellData()->id, GetControlEffectName(i).c_str());
  3281. }
  3282. }
  3283. }
  3284. }
  3285. }
  3286. client->Message(CHANNEL_COLOR_YELLOW, "-------------------------------");
  3287. }