Entity.cpp 106 KB

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