Entity.cpp 133 KB

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