Entity.cpp 143 KB

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