Entity.cpp 140 KB

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