Entity.cpp 128 KB

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