Entity.cpp 141 KB

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