9
3

Entity.cpp 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588
  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. max_speed = 6;
  33. base_speed = 0.0f;
  34. last_x = -1;
  35. last_y = -1;
  36. last_z = -1;
  37. last_heading = -1;
  38. regen_hp_rate = 0;
  39. regen_power_rate = 0;
  40. in_combat = false;
  41. casting = false;
  42. memset(&melee_combat_data, 0, sizeof(CombatData));
  43. memset(&ranged_combat_data, 0, sizeof(CombatData));
  44. memset(&info_struct, 0, sizeof(InfoStruct));
  45. loot_coins = 0;
  46. trap_triggered = false;
  47. memset(&features, 0, sizeof(CharFeatures));
  48. memset(&equipment, 0, sizeof(EQ2_Equipment));
  49. pet = 0;
  50. charmedPet = 0;
  51. deityPet = 0;
  52. cosmeticPet = 0;
  53. speed = 0;
  54. speed_multiplier = 1.0f;
  55. m_threatTransfer = 0;
  56. group_member_info = 0;
  57. trade = 0;
  58. deity = 0;
  59. MProcList.SetName("Entity::m_procList");
  60. MDetriments.SetName("Entity::MDetriments");
  61. MMaintainedSpells.SetName("Entity::MMaintainedSpells");
  62. MSpellEffects.SetName("Entity::MSpellEffects");
  63. m_procList.clear();
  64. control_effects.clear();
  65. for (int i = 0; i < CONTROL_MAX_EFFECTS; i++)
  66. control_effects[i] = NULL;
  67. immunities.clear();
  68. for(int i=0;i<45;i++){
  69. if(i<NUM_MAINTAINED_EFFECTS){
  70. info_struct.maintained_effects[i].spell_id = 0xFFFFFFFF;
  71. if (IsPlayer())
  72. info_struct.maintained_effects[i].icon = 0xFFFF;
  73. }
  74. info_struct.spell_effects[i].spell_id = 0xFFFFFFFF;
  75. }
  76. MCommandMutex.SetName("Entity::MCommandMutex");
  77. hasSeeInvisSpell = false;
  78. hasSeeHideSpell = false;
  79. }
  80. Entity::~Entity(){
  81. vector<Item*>::iterator itr;
  82. for(itr = loot_items.begin(); itr != loot_items.end(); itr++)
  83. safe_delete(*itr);
  84. MutexList<BonusValues*>::iterator itr2 = bonus_list.begin();
  85. while(itr2.Next())
  86. safe_delete(itr2.value);
  87. ClearProcs();
  88. safe_delete(m_threatTransfer);
  89. map<int8, MutexList<LuaSpell*>*>::iterator itr3;
  90. for (itr3 = control_effects.begin(); itr3 != control_effects.end(); itr3++)
  91. safe_delete(itr3->second);
  92. control_effects.clear();
  93. map<int8, MutexList<LuaSpell*>*>::iterator itr4;
  94. for (itr4 = immunities.begin(); itr4 != immunities.end(); itr4++)
  95. safe_delete(itr4->second);
  96. immunities.clear();
  97. }
  98. bool Entity::HasMoved(bool include_heading){
  99. if(GetX() == last_x && GetY() == last_y && GetZ() == last_z && ((!include_heading) || (include_heading && GetHeading() == last_heading)))
  100. return false;
  101. bool ret_val = true;
  102. if(last_x == -1 && last_y == -1 && last_z == -1 && last_heading == -1){
  103. ret_val = false;
  104. }
  105. last_x = GetX();
  106. last_y = GetY();
  107. last_z = GetZ();
  108. last_heading = GetHeading();
  109. return ret_val;
  110. }
  111. int16 Entity::GetStr(){
  112. return GetInfoStruct()->str;
  113. }
  114. int16 Entity::GetSta(){
  115. return GetInfoStruct()->sta;
  116. }
  117. int16 Entity::GetInt(){
  118. return GetInfoStruct()->intel;
  119. }
  120. int16 Entity::GetWis(){
  121. return GetInfoStruct()->wis;
  122. }
  123. int16 Entity::GetAgi(){
  124. return GetInfoStruct()->agi;
  125. }
  126. int16 Entity::GetPrimaryStat(){
  127. int8 base_class = classes.GetBaseClass(GetAdventureClass());
  128. if (base_class == FIGHTER)
  129. return GetInfoStruct()->str;
  130. else if (base_class == PRIEST)
  131. return GetInfoStruct()->wis;
  132. else if (base_class == MAGE)
  133. return GetInfoStruct()->intel;
  134. else
  135. return GetInfoStruct()->agi;
  136. }
  137. int16 Entity::GetHeatResistance(){
  138. return GetInfoStruct()->heat;
  139. }
  140. int16 Entity::GetColdResistance(){
  141. return GetInfoStruct()->cold;
  142. }
  143. int16 Entity::GetMagicResistance(){
  144. return GetInfoStruct()->magic;
  145. }
  146. int16 Entity::GetMentalResistance(){
  147. return GetInfoStruct()->mental;
  148. }
  149. int16 Entity::GetDivineResistance(){
  150. return GetInfoStruct()->divine;
  151. }
  152. int16 Entity::GetDiseaseResistance(){
  153. return GetInfoStruct()->disease;
  154. }
  155. int16 Entity::GetPoisonResistance(){
  156. return GetInfoStruct()->poison;
  157. }
  158. int8 Entity::GetConcentrationCurrent() {
  159. return GetInfoStruct()->cur_concentration;
  160. }
  161. int8 Entity::GetConcentrationMax() {
  162. return GetInfoStruct()->max_concentration;
  163. }
  164. int16 Entity::GetStrBase(){
  165. return GetInfoStruct()->str_base;
  166. }
  167. int16 Entity::GetStaBase(){
  168. return GetInfoStruct()->sta_base;
  169. }
  170. int16 Entity::GetIntBase(){
  171. return GetInfoStruct()->intel_base;
  172. }
  173. int16 Entity::GetWisBase(){
  174. return GetInfoStruct()->wis_base;
  175. }
  176. int16 Entity::GetAgiBase(){
  177. return GetInfoStruct()->agi_base;
  178. }
  179. int16 Entity::GetHeatResistanceBase(){
  180. return GetInfoStruct()->heat_base;
  181. }
  182. int16 Entity::GetColdResistanceBase(){
  183. return GetInfoStruct()->cold_base;
  184. }
  185. int16 Entity::GetMagicResistanceBase(){
  186. return GetInfoStruct()->magic_base;
  187. }
  188. int16 Entity::GetMentalResistanceBase(){
  189. return GetInfoStruct()->mental_base;
  190. }
  191. int16 Entity::GetDivineResistanceBase(){
  192. return GetInfoStruct()->divine_base;
  193. }
  194. int16 Entity::GetDiseaseResistanceBase(){
  195. return GetInfoStruct()->disease_base;
  196. }
  197. int16 Entity::GetPoisonResistanceBase(){
  198. return GetInfoStruct()->poison_base;
  199. }
  200. sint8 Entity::GetAlignment(){
  201. return GetInfoStruct()->alignment;
  202. }
  203. bool Entity::IsCasting(){
  204. return casting;
  205. }
  206. void Entity::IsCasting(bool val){
  207. casting = val;
  208. }
  209. int32 Entity::GetRangeLastAttackTime(){
  210. return ranged_combat_data.range_last_attack_time;
  211. }
  212. void Entity::SetRangeLastAttackTime(int32 time){
  213. ranged_combat_data.range_last_attack_time = time;
  214. }
  215. int16 Entity::GetRangeAttackDelay(){
  216. return ranged_combat_data.ranged_attack_delay;
  217. // if(IsPlayer()){
  218. // Item* item = ((Player*)this)->GetEquipmentList()->GetItem(EQ2_RANGE_SLOT);
  219. // if(item && item->IsRanged())
  220. // return item->ranged_info->weapon_info.delay*100;
  221. // }
  222. // return 3000;
  223. }
  224. int32 Entity::GetPrimaryLastAttackTime(){
  225. return melee_combat_data.primary_last_attack_time;
  226. }
  227. int16 Entity::GetPrimaryAttackDelay(){
  228. return melee_combat_data.primary_attack_delay;
  229. }
  230. void Entity::SetPrimaryAttackDelay(int16 new_delay){
  231. melee_combat_data.primary_attack_delay = new_delay;
  232. }
  233. void Entity::SetPrimaryLastAttackTime(int32 new_time){
  234. melee_combat_data.primary_last_attack_time = new_time;
  235. }
  236. int32 Entity::GetSecondaryLastAttackTime(){
  237. return melee_combat_data.secondary_last_attack_time;
  238. }
  239. int16 Entity::GetSecondaryAttackDelay(){
  240. return melee_combat_data.secondary_attack_delay;
  241. }
  242. void Entity::SetSecondaryAttackDelay(int16 new_delay){
  243. melee_combat_data.secondary_attack_delay = new_delay;
  244. }
  245. void Entity::SetSecondaryLastAttackTime(int32 new_time){
  246. melee_combat_data.secondary_last_attack_time = new_time;
  247. }
  248. void Entity::ChangePrimaryWeapon(){
  249. Item* item = equipment_list.GetItem(EQ2_PRIMARY_SLOT);
  250. if(item && item->details.item_id > 0 && item->IsWeapon()){
  251. melee_combat_data.primary_weapon_delay = item->weapon_info->delay * 100;
  252. melee_combat_data.primary_weapon_damage_low = item->weapon_info->damage_low3;
  253. melee_combat_data.primary_weapon_damage_high = item->weapon_info->damage_high3;
  254. melee_combat_data.primary_weapon_type = item->GetWeaponType();
  255. melee_combat_data.wield_type = item->weapon_info->wield_type;
  256. }
  257. else{
  258. melee_combat_data.primary_weapon_delay = 2000;
  259. melee_combat_data.primary_weapon_damage_low = (int32)(1 + GetLevel() * .2);
  260. melee_combat_data.primary_weapon_damage_high = (int32)(5 + GetLevel() * (GetLevel()/5));
  261. if(IsNPC())
  262. melee_combat_data.primary_weapon_type = ((NPC*)this)->GetAttackType();
  263. else
  264. melee_combat_data.primary_weapon_type = 1;
  265. melee_combat_data.wield_type = 2;
  266. }
  267. if(IsNPC())
  268. melee_combat_data.primary_weapon_damage_high += (int32)(GetInfoStruct()->str / 10);
  269. else
  270. melee_combat_data.primary_weapon_damage_high += (int32)(GetInfoStruct()->str / 25);
  271. }
  272. void Entity::ChangeSecondaryWeapon(){
  273. Item* item = equipment_list.GetItem(EQ2_SECONDARY_SLOT);
  274. if(item && item->details.item_id > 0 && item->IsWeapon()){
  275. melee_combat_data.secondary_weapon_delay = item->weapon_info->delay * 100;
  276. melee_combat_data.secondary_weapon_damage_low = item->weapon_info->damage_low3;
  277. melee_combat_data.secondary_weapon_damage_high = item->weapon_info->damage_high3;
  278. melee_combat_data.secondary_weapon_type = item->GetWeaponType();
  279. }
  280. else{
  281. melee_combat_data.secondary_weapon_delay = 2000;
  282. melee_combat_data.secondary_weapon_damage_low = (int32)(1 + GetLevel() * .2);
  283. melee_combat_data.secondary_weapon_damage_high = (int32)(5 + GetLevel() * (GetLevel()/6));
  284. melee_combat_data.secondary_weapon_type = 1;
  285. }
  286. if(IsNPC())
  287. melee_combat_data.secondary_weapon_damage_high += (int32)(GetInfoStruct()->str / 10);
  288. else
  289. melee_combat_data.secondary_weapon_damage_high += (int32)(GetInfoStruct()->str / 25);
  290. }
  291. void Entity::ChangeRangedWeapon(){
  292. Item* item = equipment_list.GetItem(EQ2_RANGE_SLOT);
  293. if(item && item->details.item_id > 0 && item->IsRanged()){
  294. ranged_combat_data.ranged_weapon_delay = item->ranged_info->weapon_info.delay*100;
  295. ranged_combat_data.ranged_weapon_damage_low = item->ranged_info->weapon_info.damage_low3;
  296. ranged_combat_data.ranged_weapon_damage_high = item->ranged_info->weapon_info.damage_high3;
  297. ranged_combat_data.ranged_weapon_type = item->GetWeaponType();
  298. }
  299. }
  300. int32 Entity::GetPrimaryWeaponMinDamage(){
  301. return melee_combat_data.primary_weapon_damage_low;
  302. }
  303. int32 Entity::GetPrimaryWeaponMaxDamage(){
  304. return melee_combat_data.primary_weapon_damage_high;
  305. }
  306. int32 Entity::GetSecondaryWeaponMinDamage(){
  307. return melee_combat_data.secondary_weapon_damage_low;
  308. }
  309. int32 Entity::GetSecondaryWeaponMaxDamage(){
  310. return melee_combat_data.secondary_weapon_damage_high;
  311. }
  312. int8 Entity::GetPrimaryWeaponType(){
  313. return melee_combat_data.primary_weapon_type;
  314. }
  315. int8 Entity::GetSecondaryWeaponType(){
  316. return melee_combat_data.secondary_weapon_type;
  317. }
  318. int32 Entity::GetRangedWeaponMinDamage(){
  319. return ranged_combat_data.ranged_weapon_damage_low;
  320. }
  321. int32 Entity::GetRangedWeaponMaxDamage(){
  322. return ranged_combat_data.ranged_weapon_damage_high;
  323. }
  324. int8 Entity::GetRangedWeaponType(){
  325. return ranged_combat_data.ranged_weapon_type;
  326. }
  327. bool Entity::IsDualWield(){
  328. return melee_combat_data.wield_type == 1;
  329. }
  330. int8 Entity::GetWieldType(){
  331. return melee_combat_data.wield_type;
  332. }
  333. bool Entity::BehindTarget(Spawn* target){
  334. float target_angle = 360 - target->GetHeading();
  335. float angle = 360 - GetHeading();
  336. if(target_angle > angle)
  337. angle = target_angle - angle;
  338. else
  339. angle -= target_angle;
  340. return (angle < 90 || angle > 270);
  341. }
  342. bool Entity::FlankingTarget(Spawn* target) {
  343. float angle;
  344. double diff_x = target->GetX() - GetX();
  345. double diff_z = target->GetZ() - GetZ();
  346. if (diff_z == 0) {
  347. if (diff_x > 0)
  348. angle = 90;
  349. else
  350. angle = 270;
  351. }
  352. else
  353. angle = ((atan(diff_x / diff_z)) * 180) / 3.14159265358979323846;
  354. if (angle < 0)
  355. angle = angle + 360;
  356. else
  357. angle = angle + 180;
  358. if (diff_x < 0)
  359. angle = angle + 180;
  360. if (angle > GetHeading())
  361. angle = angle - GetHeading();
  362. else
  363. angle = GetHeading() - angle;
  364. if (angle > 360)
  365. angle -= 360;
  366. //LogWrite(SPAWN__ERROR, 0, "Angle", "spawn heading = %f", GetHeading());
  367. //LogWrite(SPAWN__ERROR, 0, "Angle", "angle = %f", angle);
  368. return (angle >= 45 && angle <= 315);
  369. }
  370. float Entity::GetShieldBlockChance(){
  371. float ret = 0;
  372. Item* item = equipment_list.GetItem(1);
  373. if(item && item->details.item_id > 0 && item->IsShield()){
  374. }
  375. return ret;
  376. }
  377. float Entity::GetDodgeChance(){
  378. float ret = 0;
  379. return ret;
  380. }
  381. bool Entity::EngagedInCombat(){
  382. return in_combat;
  383. }
  384. void Entity::InCombat(bool val){
  385. in_combat = val;
  386. }
  387. void Entity::SetHPRegen(int16 new_val){
  388. regen_hp_rate = new_val;
  389. }
  390. void Entity::SetPowerRegen(int16 new_val){
  391. regen_power_rate = new_val;
  392. }
  393. int16 Entity::GetHPRegen(){
  394. return regen_hp_rate;
  395. }
  396. int16 Entity::GetPowerRegen(){
  397. return regen_power_rate;
  398. }
  399. void Entity::DoRegenUpdate(){
  400. if(GetHP() == 0)//dead
  401. return;
  402. sint32 hp = GetHP();
  403. sint32 power = GetPower();
  404. int16 level = GetLevel();
  405. // No regen for NPC's while in combat
  406. // Temp solution for now
  407. if (IsNPC() && EngagedInCombat())
  408. return;
  409. if(hp < GetTotalHP()){
  410. if(regen_hp_rate == 0)
  411. regen_hp_rate = (int)(level*.75)+(int)(level/10) + 1;
  412. int16 temp = regen_hp_rate + stats[ITEM_STAT_HPREGEN];
  413. if((hp + temp) > GetTotalHP())
  414. SetHP(GetTotalHP());
  415. else
  416. SetHP(hp + temp);
  417. LogWrite(MISC__TODO, 1, "TODO", "Fix this later for mobs\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  418. }
  419. if(GetPower() < GetTotalPower()){
  420. if(regen_power_rate == 0)
  421. regen_power_rate = level + (int)(level/10) + 1;
  422. if((power + regen_power_rate) > GetTotalPower())
  423. SetPower(GetTotalPower());
  424. else
  425. SetPower(power + regen_power_rate);
  426. LogWrite(MISC__TODO, 1, "TODO", "Fix this later for mobs\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  427. }
  428. }
  429. void Entity::AddMaintainedSpell(LuaSpell* luaspell){
  430. if (!luaspell)
  431. return;
  432. Spell* spell = luaspell->spell;
  433. MaintainedEffects* effect = GetFreeMaintainedSpellSlot();
  434. if (effect){
  435. MMaintainedSpells.writelock(__FUNCTION__, __LINE__);
  436. effect->spell = luaspell;
  437. effect->spell_id = spell->GetSpellData()->id;
  438. LogWrite(NPC__SPELLS, 5, "NPC", "AddMaintainedSpell Spell ID: %u", spell->GetSpellData()->id);
  439. effect->conc_used = spell->GetSpellData()->req_concentration / 256;
  440. effect->total_time = spell->GetSpellDuration() / 10;
  441. effect->tier = spell->GetSpellData()->tier;
  442. if (spell->GetSpellData()->duration_until_cancel)
  443. effect->expire_timestamp = 0xFFFFFFFF;
  444. else
  445. effect->expire_timestamp = Timer::GetCurrentTime2() + (spell->GetSpellDuration() * 100);
  446. MMaintainedSpells.releasewritelock(__FUNCTION__, __LINE__);
  447. }
  448. }
  449. void Entity::AddSpellEffect(LuaSpell* luaspell){
  450. if (!luaspell || !luaspell->caster)
  451. return;
  452. Spell* spell = luaspell->spell;
  453. SpellEffects* old_effect = GetSpellEffect(spell->GetSpellID(), luaspell->caster);
  454. SpellEffects* effect = 0;
  455. if (old_effect){
  456. GetZone()->RemoveTargetFromSpell(old_effect->spell, this);
  457. RemoveSpellEffect(old_effect->spell);
  458. }
  459. effect = GetFreeSpellEffectSlot();
  460. if(effect){
  461. MSpellEffects.writelock(__FUNCTION__, __LINE__);
  462. effect->spell = luaspell;
  463. effect->spell_id = spell->GetSpellData()->id;
  464. effect->caster = luaspell->caster;
  465. effect->total_time = spell->GetSpellDuration()/10;
  466. if (spell->GetSpellData()->duration_until_cancel)
  467. effect->expire_timestamp = 0xFFFFFFFF;
  468. else
  469. effect->expire_timestamp = Timer::GetCurrentTime2() + (spell->GetSpellDuration()*100);
  470. effect->icon = spell->GetSpellData()->icon;
  471. effect->icon_backdrop = spell->GetSpellData()->icon_backdrop;
  472. effect->tier = spell->GetSpellTier();
  473. MSpellEffects.releasewritelock(__FUNCTION__, __LINE__);
  474. changed = true;
  475. info_changed = true;
  476. AddChangedZoneSpawn();
  477. }
  478. }
  479. void Entity::RemoveMaintainedSpell(LuaSpell* luaspell){
  480. if (!luaspell)
  481. return;
  482. bool found = false;
  483. MMaintainedSpells.writelock(__FUNCTION__, __LINE__);
  484. for (int i = 0; i<30; i++){
  485. // If we already found the spell then we are bumping all other up one so there are no gaps
  486. // This check needs to be first so found can never be true on the first iteration (i = 0)
  487. if (found) {
  488. GetInfoStruct()->maintained_effects[i].slot_pos = i - 1;
  489. GetInfoStruct()->maintained_effects[i - 1] = GetInfoStruct()->maintained_effects[i];
  490. }
  491. // Compare spells, if we found a match set the found flag
  492. if (GetInfoStruct()->maintained_effects[i].spell == luaspell)
  493. found = true;
  494. }
  495. // if we found the spell in the array then we need to set the last element to empty
  496. if (found) {
  497. memset(&GetInfoStruct()->maintained_effects[29], 0, sizeof(MaintainedEffects));
  498. GetInfoStruct()->maintained_effects[29].spell_id = 0xFFFFFFFF;
  499. GetInfoStruct()->maintained_effects[29].icon = 0xFFFF;
  500. }
  501. MMaintainedSpells.releasewritelock(__FUNCTION__, __LINE__);
  502. }
  503. void Entity::RemoveSpellEffect(LuaSpell* spell) {
  504. bool found = false;
  505. MSpellEffects.writelock(__FUNCTION__, __LINE__);
  506. for(int i=0;i<45;i++) {
  507. if (found) {
  508. GetInfoStruct()->spell_effects[i-1] = GetInfoStruct()->spell_effects[i];
  509. }
  510. if (GetInfoStruct()->spell_effects[i].spell == spell)
  511. found = true;
  512. }
  513. if (found) {
  514. memset(&GetInfoStruct()->spell_effects[44], 0, sizeof(SpellEffects));
  515. GetInfoStruct()->spell_effects[44].spell_id = 0xFFFFFFFF;
  516. changed = true;
  517. info_changed = true;
  518. AddChangedZoneSpawn();
  519. }
  520. MSpellEffects.releasewritelock(__FUNCTION__, __LINE__);
  521. }
  522. bool Entity::HasActiveMaintainedSpell(Spell* spell, Spawn* target){
  523. LogWrite(MISC__TODO, 1, "TODO", "This does nothing... yet...\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  524. return false;
  525. }
  526. bool Entity::HasActiveSpellEffect(Spell* spell, Spawn* target){
  527. LogWrite(MISC__TODO, 1, "TODO", "This does nothing... yet...\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  528. return false;
  529. }
  530. MaintainedEffects* Entity::GetFreeMaintainedSpellSlot(){
  531. MaintainedEffects* ret = 0;
  532. InfoStruct* info = GetInfoStruct();
  533. MMaintainedSpells.readlock(__FUNCTION__, __LINE__);
  534. for (int i = 0; i<NUM_MAINTAINED_EFFECTS; i++){
  535. if (info->maintained_effects[i].spell_id == 0xFFFFFFFF){
  536. ret = &info->maintained_effects[i];
  537. ret->spell_id = 0;
  538. ret->slot_pos = i;
  539. break;
  540. }
  541. }
  542. MMaintainedSpells.releasereadlock(__FUNCTION__, __LINE__);
  543. return ret;
  544. }
  545. MaintainedEffects* Entity::GetMaintainedSpell(int32 spell_id){
  546. MaintainedEffects* ret = 0;
  547. InfoStruct* info = GetInfoStruct();
  548. MMaintainedSpells.readlock(__FUNCTION__, __LINE__);
  549. for (int i = 0; i<NUM_MAINTAINED_EFFECTS; i++){
  550. if (info->maintained_effects[i].spell_id == spell_id){
  551. ret = &info->maintained_effects[i];
  552. break;
  553. }
  554. }
  555. MMaintainedSpells.releasereadlock(__FUNCTION__, __LINE__);
  556. return ret;
  557. }
  558. SpellEffects* Entity::GetFreeSpellEffectSlot(){
  559. SpellEffects* ret = 0;
  560. InfoStruct* info = GetInfoStruct();
  561. MSpellEffects.readlock(__FUNCTION__, __LINE__);
  562. for(int i=0;i<45;i++){
  563. if(info->spell_effects[i].spell_id == 0xFFFFFFFF){
  564. ret = &info->spell_effects[i];
  565. ret->spell_id = 0;
  566. break;
  567. }
  568. }
  569. MSpellEffects.releasereadlock(__FUNCTION__, __LINE__);
  570. return ret;
  571. }
  572. SpellEffects* Entity::GetSpellEffect(int32 id, Entity* caster) {
  573. SpellEffects* ret = 0;
  574. InfoStruct* info = GetInfoStruct();
  575. MSpellEffects.readlock(__FUNCTION__, __LINE__);
  576. for(int i = 0; i < 45; i++) {
  577. if(info->spell_effects[i].spell_id == id) {
  578. if (!caster || info->spell_effects[i].caster == caster){
  579. ret = &info->spell_effects[i];
  580. break;
  581. }
  582. }
  583. }
  584. MSpellEffects.releasereadlock(__FUNCTION__, __LINE__);
  585. return ret;
  586. }
  587. InfoStruct* Entity::GetInfoStruct(){
  588. return &info_struct;
  589. }
  590. Item* Entity::LootItem(int32 id){
  591. Item* ret = 0;
  592. vector<Item*>::iterator itr;
  593. MLootItems.lock();
  594. for(itr = loot_items.begin(); itr != loot_items.end(); itr++){
  595. if((*itr)->details.item_id == id){
  596. ret = *itr;
  597. loot_items.erase(itr);
  598. break;
  599. }
  600. }
  601. MLootItems.unlock();
  602. return ret;
  603. }
  604. int32 Entity::GetLootItemID(){
  605. int32 ret = 0;
  606. vector<Item*>::iterator itr;
  607. MLootItems.lock();
  608. for(itr = loot_items.begin(); itr != loot_items.end(); itr++){
  609. ret = (*itr)->details.item_id;
  610. break;
  611. }
  612. MLootItems.unlock();
  613. return ret;
  614. }
  615. bool Entity::HasLootItemID(int32 id) {
  616. bool ret = false;
  617. vector<Item*>::iterator itr;
  618. MLootItems.readlock(__FUNCTION__, __LINE__);
  619. for (itr = loot_items.begin(); itr != loot_items.end(); itr++) {
  620. if ((*itr)->details.item_id == id) {
  621. ret = true;
  622. break;
  623. }
  624. }
  625. MLootItems.releasereadlock(__FUNCTION__, __LINE__);
  626. return ret;
  627. }
  628. Skill* Entity::GetSkillByName(const char* name, bool check_update){
  629. LogWrite(MISC__TODO, 1, "TODO", "This does nothing... yet...\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  630. return 0;
  631. }
  632. float Entity::GetMaxSpeed(){
  633. return max_speed;
  634. }
  635. void Entity::SetMaxSpeed(float val){
  636. max_speed = val;
  637. }
  638. void Entity::CalculateBonuses(){
  639. InfoStruct* info = &info_struct;
  640. info->block = info->block_base;
  641. info->cur_attack = info->attack_base;
  642. info->cur_mitigation = info->mitigation_base;
  643. info->base_avoidance_pct = info->avoidance_base;
  644. LogWrite(MISC__TODO, 1, "TODO", "Calculate via current spells\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  645. //info->cur_concentration = 0;
  646. info->parry = info->parry_base;
  647. info->deflection = info->deflection_base;
  648. info->disease = info->disease_base;
  649. info->divine = info->divine_base;
  650. info->heat = info->heat_base;
  651. info->magic = info->magic_base;
  652. info->mental = info->mental_base;
  653. info->cold = info->cold_base;
  654. info->poison = info->poison_base;
  655. info->elemental_base = info->heat;
  656. info->noxious_base = info->poison;
  657. info->arcane_base = info->magic;
  658. info->sta = info->sta_base;
  659. info->agi = info->agi_base;
  660. info->str = info->str_base;
  661. info->wis = info->wis_base;
  662. info->intel = info->intel_base;
  663. info->ability_modifier = 0;
  664. info->critical_mitigation = 0;
  665. info->block_chance = 0;
  666. info->crit_chance = 0;
  667. info->crit_bonus = 0;
  668. info->potency = 0;
  669. info->hate_mod = 0;
  670. info->reuse_speed = 0;
  671. info->casting_speed = 0;
  672. info->recovery_speed = 0;
  673. info->spell_reuse_speed = 0;
  674. info->spell_multi_attack = 0;
  675. info->dps = 0;
  676. info->dps_multiplier = 0;
  677. info->haste = 0;
  678. info->attackspeed = 0;
  679. info->multi_attack = 0;
  680. info->flurry = 0;
  681. info->melee_ae = 0;
  682. info->strikethrough = 0;
  683. info->accuracy = 0;
  684. info->offensivespeed = 0;
  685. stats.clear();
  686. ItemStatsValues* values = equipment_list.CalculateEquipmentBonuses(this);
  687. CalculateSpellBonuses(values);
  688. info->sta += values->sta;
  689. info->str += values->str;
  690. info->agi += values->agi;
  691. info->wis += values->wis;
  692. info->intel += values->int_;
  693. info->disease += values->vs_disease;
  694. info->divine += values->vs_divine;
  695. info->heat += values->vs_heat;
  696. info->magic += values->vs_magic;
  697. int32 sta_hp_bonus = 0.0;
  698. int32 prim_power_bonus = 0.0;
  699. float bonus_mod = 0.0;
  700. if (IsPlayer()) {
  701. bonus_mod = CalculateBonusMod();
  702. sta_hp_bonus = info->sta * bonus_mod;
  703. prim_power_bonus = GetPrimaryStat() * bonus_mod;
  704. }
  705. prim_power_bonus = floor(float(prim_power_bonus));
  706. sta_hp_bonus = floor(float(sta_hp_bonus));
  707. SetTotalHP(GetTotalHPBase() + values->health + sta_hp_bonus);
  708. SetTotalPower(GetTotalPowerBase() + values->power + prim_power_bonus);
  709. if(GetHP() > GetTotalHP())
  710. SetHP(GetTotalHP());
  711. if(GetPower() > GetTotalPower())
  712. SetPower(GetTotalPower());
  713. info->mental += values->vs_mental;
  714. info->poison += values->vs_poison;
  715. info->max_concentration += values->concentration;
  716. info->cold += values->vs_cold;
  717. info->mitigation_skill1 += values->vs_slash;
  718. info->mitigation_skill2 += values->vs_pierce;
  719. info->mitigation_skill3 += values->vs_crush;
  720. info->ability_modifier += values->ability_modifier;
  721. info->critical_mitigation += values->criticalmitigation;
  722. info->block_chance += values->extrashieldblockchance;
  723. info->crit_chance += values->beneficialcritchance;
  724. info->crit_bonus += values->critbonus;
  725. info->potency += values->potency;
  726. info->hate_mod += values->hategainmod;
  727. info->reuse_speed += values->abilityreusespeed;
  728. info->casting_speed += values->abilitycastingspeed;
  729. info->recovery_speed += values->abilityrecoveryspeed;
  730. info->spell_reuse_speed += values->spellreusespeed;
  731. info->spell_multi_attack += values->spellmultiattackchance;
  732. info->dps += values->dps;
  733. info->dps_multiplier = CalculateDPSMultiplier();
  734. info->haste += values->attackspeed;
  735. info->multi_attack += values->multiattackchance;
  736. info->flurry += values->flurry;
  737. info->melee_ae += values->aeautoattackchance;
  738. info->strikethrough += values->strikethrough;
  739. info->accuracy += values->accuracy;
  740. info->offensivespeed += values->offensivespeed;
  741. info->uncontested_block += values->uncontested_block;
  742. info->uncontested_parry += values->uncontested_parry;
  743. info->uncontested_dodge += values->uncontested_dodge;
  744. info->uncontested_riposte += values->uncontested_riposte;
  745. safe_delete(values);
  746. }
  747. EquipmentItemList* Entity::GetEquipmentList(){
  748. return &equipment_list;
  749. }
  750. void Entity::SetEquipment(Item* item, int8 slot){
  751. if(!item && slot < NUM_SLOTS){
  752. SetInfo(&equipment.equip_id[slot], 0);
  753. SetInfo(&equipment.color[slot].red, 0);
  754. SetInfo(&equipment.color[slot].green, 0);
  755. SetInfo(&equipment.color[slot].blue, 0);
  756. SetInfo(&equipment.highlight[slot].red, 0);
  757. SetInfo(&equipment.highlight[slot].green, 0);
  758. SetInfo(&equipment.highlight[slot].blue, 0);
  759. }
  760. else{
  761. SetInfo(&equipment.equip_id[item->details.slot_id], item->generic_info.appearance_id);
  762. SetInfo(&equipment.color[item->details.slot_id].red, item->generic_info.appearance_red);
  763. SetInfo(&equipment.color[item->details.slot_id].green, item->generic_info.appearance_green);
  764. SetInfo(&equipment.color[item->details.slot_id].blue, item->generic_info.appearance_blue);
  765. SetInfo(&equipment.highlight[item->details.slot_id].red, item->generic_info.appearance_highlight_red);
  766. SetInfo(&equipment.highlight[item->details.slot_id].green, item->generic_info.appearance_highlight_green);
  767. SetInfo(&equipment.highlight[item->details.slot_id].blue, item->generic_info.appearance_highlight_blue);
  768. }
  769. }
  770. bool Entity::CheckSpellBonusRemoval(LuaSpell* spell, int16 type){
  771. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  772. while(itr.Next()){
  773. if(itr.value->luaspell == spell && itr.value->type == type){
  774. bonus_list.Remove(itr.value, true);
  775. return true;
  776. }
  777. }
  778. return false;
  779. }
  780. void Entity::AddSpellBonus(LuaSpell* spell, int16 type, float value, int64 class_req, vector<int16> race_req, vector<int16> faction_req){
  781. CheckSpellBonusRemoval(spell, type);
  782. BonusValues* bonus = new BonusValues;
  783. bonus->spell_id = spell->spell->GetSpellID();
  784. bonus->luaspell = spell;
  785. bonus->type = type;
  786. bonus->value = value;
  787. bonus->class_req = class_req;
  788. bonus->race_req = race_req;
  789. bonus->faction_req = faction_req;
  790. bonus->tier = spell ? spell->spell->GetSpellTier() : 0;
  791. bonus_list.Add(bonus);
  792. }
  793. BonusValues* Entity::GetSpellBonus(int32 spell_id) {
  794. BonusValues *ret = 0;
  795. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  796. while (itr.Next()) {
  797. if (itr.value->spell_id == spell_id) {
  798. ret = itr.value;
  799. break;
  800. }
  801. }
  802. return ret;
  803. }
  804. vector<BonusValues*>* Entity::GetAllSpellBonuses(LuaSpell* spell) {
  805. vector<BonusValues*>* list = new vector<BonusValues*>;
  806. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  807. while (itr.Next()) {
  808. if (itr.value->luaspell == spell)
  809. list->push_back(itr.value);
  810. }
  811. return list;
  812. }
  813. void Entity::RemoveSpellBonus(const LuaSpell* spell){
  814. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  815. while(itr.Next()){
  816. if(itr.value->luaspell == spell)
  817. bonus_list.Remove(itr.value, true);
  818. }
  819. }
  820. void Entity::CalculateSpellBonuses(ItemStatsValues* stats){
  821. if(stats){
  822. MutexList<BonusValues*>::iterator itr = bonus_list.begin();
  823. vector<BonusValues*> bv;
  824. //First check if we meet the requirement for each bonus
  825. bool race_match = false;
  826. while(itr.Next()) {
  827. if (itr.value->race_req.size() > 0) {
  828. for (int8 i = 0; i < itr.value->race_req.size(); i++) {
  829. if (GetRace() == itr.value->race_req[i]) {
  830. race_match = true;
  831. }
  832. }
  833. }
  834. else
  835. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  836. int64 const class1 = pow(2.0, (GetAdventureClass() - 1));
  837. int64 const class2 = pow(2.0, (classes.GetSecondaryBaseClass(GetAdventureClass()) - 1));
  838. int64 const class3 = pow(2.0, (classes.GetBaseClass(GetAdventureClass()) - 1));
  839. 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 )
  840. bv.push_back(itr.value);
  841. }
  842. //Sort the bonuses by spell id and luaspell
  843. BonusValues* bonus = nullptr;
  844. map <int32, map<LuaSpell*, vector<BonusValues*> > > sort;
  845. for (int8 i = 0; i < bv.size(); i++){
  846. bonus = bv.at(i);
  847. sort[bonus->spell_id][bonus->luaspell].push_back(bonus);
  848. }
  849. //Now check for the highest tier of each spell id and apply those bonuses
  850. map<LuaSpell*, vector<BonusValues*> >::iterator tier_itr;
  851. map <int32, map<LuaSpell*, vector<BonusValues*> > >::iterator sort_itr;
  852. for (sort_itr = sort.begin(); sort_itr != sort.end(); sort_itr++){
  853. LuaSpell* key = nullptr;
  854. sint8 highest_tier = -1;
  855. //Find the highest tier for this spell id
  856. for (tier_itr = sort_itr->second.begin(); tier_itr != sort_itr->second.end(); tier_itr++){
  857. LuaSpell* current_spell = tier_itr->first;
  858. sint8 current_tier = 0;
  859. if (current_spell && ((current_tier = current_spell->spell->GetSpellTier()) > highest_tier)) {
  860. highest_tier = current_tier;
  861. key = current_spell;
  862. }
  863. }
  864. //We've found the highest tier for this spell id, so add the bonuses
  865. vector<BonusValues*>* final_bonuses = &sort_itr->second[key];
  866. for (int8 i = 0; i < final_bonuses->size(); i++)
  867. world.AddBonuses(stats, final_bonuses->at(i)->type, final_bonuses->at(i)->value, this);
  868. }
  869. }
  870. }
  871. void Entity::AddMezSpell(LuaSpell* spell) {
  872. if (!spell)
  873. return;
  874. if (!control_effects[CONTROL_EFFECT_TYPE_MEZ])
  875. control_effects[CONTROL_EFFECT_TYPE_MEZ] = new MutexList<LuaSpell*>;
  876. MutexList<LuaSpell*>* mez_spells = control_effects[CONTROL_EFFECT_TYPE_MEZ];
  877. if (IsPlayer() && !IsStunned() && !IsMezImmune() && mez_spells->size(true) == 0){
  878. ((Player*)this)->SetPlayerControlFlag(1, 16, true);
  879. if (!IsRooted())
  880. ((Player*)this)->SetPlayerControlFlag(1, 8, true);
  881. if (!IsStifled() && !IsFeared())
  882. GetZone()->LockAllSpells((Player*)this);
  883. }
  884. if (IsNPC() && !IsMezImmune())
  885. {
  886. HaltMovement();
  887. }
  888. mez_spells->Add(spell);
  889. }
  890. void Entity::RemoveMezSpell(LuaSpell* spell) {
  891. MutexList<LuaSpell*>* mez_spells = control_effects[CONTROL_EFFECT_TYPE_MEZ];
  892. if (!mez_spells || mez_spells->size(true) == 0)
  893. return;
  894. mez_spells->Remove(spell);
  895. if (mez_spells->size(true) == 0){
  896. if (IsPlayer() && !IsMezImmune() && !IsStunned()){
  897. if (!IsStifled() && !IsFeared())
  898. GetZone()->UnlockAllSpells((Player*)this);
  899. ((Player*)this)->SetPlayerControlFlag(1, 16, false);
  900. if (!IsRooted())
  901. ((Player*)this)->SetPlayerControlFlag(1, 8, false);
  902. }
  903. }
  904. }
  905. void Entity::RemoveAllMezSpells() {
  906. MutexList<LuaSpell*>* mez_spells = control_effects[CONTROL_EFFECT_TYPE_MEZ];
  907. if (!mez_spells)
  908. return;
  909. MutexList<LuaSpell*>::iterator itr = mez_spells->begin();
  910. while (itr.Next()){
  911. LuaSpell* spell = itr.value;
  912. if (!spell)
  913. continue;
  914. GetZone()->RemoveTargetFromSpell(spell, this);
  915. RemoveDetrimentalSpell(spell);
  916. RemoveSpellEffect(spell);
  917. if (IsPlayer())
  918. ((Player*)this)->RemoveSkillBonus(spell->spell->GetSpellID());
  919. }
  920. mez_spells->clear();
  921. if (IsPlayer() && !IsMezImmune() && !IsStunned()){
  922. if (!IsStifled() && !IsFeared())
  923. GetZone()->UnlockAllSpells((Player*)this);
  924. ((Player*)this)->SetPlayerControlFlag(1, 16, false);
  925. if (!IsRooted())
  926. ((Player*)this)->SetPlayerControlFlag(1, 8, false);
  927. }
  928. }
  929. void Entity::AddStifleSpell(LuaSpell* spell) {
  930. if (!spell)
  931. return;
  932. if (!control_effects[CONTROL_EFFECT_TYPE_STIFLE])
  933. control_effects[CONTROL_EFFECT_TYPE_STIFLE] = new MutexList<LuaSpell*>;
  934. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_STIFLE]->size(true) == 0 && !IsStifleImmune() && !IsMezzedOrStunned())
  935. GetZone()->LockAllSpells((Player*)this);
  936. control_effects[CONTROL_EFFECT_TYPE_STIFLE]->Add(spell);
  937. }
  938. void Entity::RemoveStifleSpell(LuaSpell* spell) {
  939. MutexList<LuaSpell*>* stifle_list = control_effects[CONTROL_EFFECT_TYPE_STIFLE];
  940. if (!stifle_list || stifle_list->size(true) == 0)
  941. return;
  942. stifle_list->Remove(spell);
  943. if (IsPlayer() && stifle_list->size(true) == 0 && !IsStifleImmune() && !IsMezzedOrStunned())
  944. GetZone()->UnlockAllSpells((Player*)this);
  945. }
  946. void Entity::AddDazeSpell(LuaSpell* spell) {
  947. if (!spell)
  948. return;
  949. if (!control_effects[CONTROL_EFFECT_TYPE_DAZE])
  950. control_effects[CONTROL_EFFECT_TYPE_DAZE] = new MutexList<LuaSpell*>;
  951. control_effects[CONTROL_EFFECT_TYPE_DAZE]->Add(spell);
  952. }
  953. void Entity::RemoveDazeSpell(LuaSpell* spell) {
  954. MutexList<LuaSpell*>* daze_list = control_effects[CONTROL_EFFECT_TYPE_DAZE];
  955. if (!daze_list || daze_list->size(true) == 0)
  956. return;
  957. daze_list->Remove(spell);
  958. }
  959. void Entity::AddStunSpell(LuaSpell* spell) {
  960. if (!spell)
  961. return;
  962. if (!control_effects[CONTROL_EFFECT_TYPE_STUN])
  963. control_effects[CONTROL_EFFECT_TYPE_STUN] = new MutexList<LuaSpell*>;
  964. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_STUN]->size(true) == 0 && !IsStunImmune()){
  965. if (!IsMezzed()){
  966. ((Player*)this)->SetPlayerControlFlag(1, 16, true);
  967. if (!IsRooted())
  968. ((Player*)this)->SetPlayerControlFlag(1, 8, true);
  969. if (!IsStifled() && !IsFeared())
  970. GetZone()->LockAllSpells((Player*)this);
  971. }
  972. }
  973. control_effects[CONTROL_EFFECT_TYPE_STUN]->Add(spell);
  974. }
  975. void Entity::RemoveStunSpell(LuaSpell* spell) {
  976. MutexList<LuaSpell*>* stun_list = control_effects[CONTROL_EFFECT_TYPE_STUN];
  977. if (!stun_list || stun_list->size(true) == 0)
  978. return;
  979. stun_list->Remove(spell);
  980. if (stun_list->size(true) == 0){
  981. if (IsPlayer() && !IsMezzed() && !IsStunImmune()){
  982. ((Player*)this)->SetPlayerControlFlag(1, 16, false);
  983. if (!IsRooted())
  984. ((Player*)this)->SetPlayerControlFlag(1, 8, false);
  985. if (!IsStifled() && !IsFeared())
  986. GetZone()->UnlockAllSpells((Player*)this);
  987. }
  988. }
  989. }
  990. void Entity::HideDeityPet(bool val) {
  991. if (!deityPet)
  992. return;
  993. if (val) {
  994. deityPet->AddAllowAccessSpawn(deityPet);
  995. GetZone()->HidePrivateSpawn(deityPet);
  996. }
  997. else
  998. deityPet->MakeSpawnPublic();
  999. }
  1000. void Entity::HideCosmeticPet(bool val) {
  1001. if (!cosmeticPet)
  1002. return;
  1003. if (val) {
  1004. cosmeticPet->AddAllowAccessSpawn(cosmeticPet);
  1005. GetZone()->HidePrivateSpawn(cosmeticPet);
  1006. }
  1007. else
  1008. cosmeticPet->MakeSpawnPublic();
  1009. }
  1010. void Entity::DismissPet(NPC* pet, bool from_death) {
  1011. if (!pet)
  1012. return;
  1013. Entity* PetOwner = pet->GetOwner();
  1014. pet->SetDismissing(true);
  1015. // Remove the spell maintained spell
  1016. Spell* spell = master_spell_list.GetSpell(pet->GetPetSpellID(), pet->GetPetSpellTier());
  1017. if (spell)
  1018. GetZone()->GetSpellProcess()->DeleteCasterSpell(this, spell);
  1019. if (pet->GetPetType() == PET_TYPE_CHARMED) {
  1020. PetOwner->SetCharmedPet(0);
  1021. if (!from_death) {
  1022. // set the pet flag to false, owner to 0, and give the mob its old brain back
  1023. pet->SetPet(false);
  1024. pet->SetOwner(0);
  1025. pet->SetBrain(new Brain(pet));
  1026. pet->SetDismissing(false);
  1027. }
  1028. }
  1029. else if (pet->GetPetType() == PET_TYPE_COMBAT)
  1030. PetOwner->SetCombatPet(0);
  1031. else if (pet->GetPetType() == PET_TYPE_DEITY)
  1032. PetOwner->SetDeityPet(0);
  1033. else if (pet->GetPetType() == PET_TYPE_COSMETIC)
  1034. PetOwner->SetCosmeticPet(0);
  1035. // if owner is player and no combat pets left reset the pet info
  1036. if (PetOwner->IsPlayer()) {
  1037. if (!PetOwner->GetPet() && !PetOwner->GetCharmedPet())
  1038. ((Player*)PetOwner)->ResetPetInfo();
  1039. }
  1040. // remove the spawn from the world
  1041. if (!from_death && pet->GetPetType() != PET_TYPE_CHARMED)
  1042. GetZone()->RemoveSpawn(false, pet);
  1043. }
  1044. float Entity::CalculateBonusMod() {
  1045. int8 level = GetLevel();
  1046. if (level <= 20)
  1047. return 3.0;
  1048. else if (level >= 90)
  1049. return 10.0;
  1050. else
  1051. return (level - 20) * .1 + 3.0;
  1052. }
  1053. float Entity::CalculateDPSMultiplier(){
  1054. float dps = GetInfoStruct()->dps;
  1055. if (dps > 0){
  1056. if (dps <= 100)
  1057. return (dps / 100 + 1);
  1058. else if (dps <= 200)
  1059. return (((dps - 100) * .25 + 100) / 100 + 1);
  1060. else if (dps <= 300)
  1061. return (((dps - 200) * .1 + 125) / 100 + 1);
  1062. else if (dps <= 900)
  1063. return (((dps - 300) * .05 + 135) / 100 + 1);
  1064. else
  1065. return (((dps - 900) * .01 + 165) / 100 + 1);
  1066. }
  1067. return 1;
  1068. }
  1069. void Entity::AddWard(int32 spellID, WardInfo* ward) {
  1070. if (m_wardList.count(spellID) == 0) {
  1071. m_wardList[spellID] = ward;
  1072. }
  1073. }
  1074. WardInfo* Entity::GetWard(int32 spellID) {
  1075. WardInfo* ret = 0;
  1076. if (m_wardList.count(spellID) > 0)
  1077. ret = m_wardList[spellID];
  1078. return ret;
  1079. }
  1080. void Entity::RemoveWard(int32 spellID) {
  1081. if (m_wardList.count(spellID) > 0) {
  1082. // Delete the ward info
  1083. safe_delete(m_wardList[spellID]);
  1084. // Remove from the ward list
  1085. m_wardList.erase(spellID);
  1086. }
  1087. }
  1088. int32 Entity::CheckWards(Entity* attacker, int32 damage, int8 damage_type) {
  1089. map<int32, WardInfo*>::iterator itr;
  1090. WardInfo* ward = 0;
  1091. LuaSpell* spell = 0;
  1092. while (m_wardList.size() > 0 && damage > 0) {
  1093. // Get the ward with the lowest base damage
  1094. for (itr = m_wardList.begin(); itr != m_wardList.end(); itr++) {
  1095. if (!ward || itr->second->BaseDamage < ward->BaseDamage) {
  1096. if ((itr->second->AbsorbAllDamage || itr->second->DamageLeft > 0) &&
  1097. (itr->second->WardType == WARD_TYPE_ALL ||
  1098. (itr->second->WardType == WARD_TYPE_PHYSICAL && damage_type >= DAMAGE_PACKET_DAMAGE_TYPE_SLASH && damage_type <= DAMAGE_PACKET_DAMAGE_TYPE_PIERCE) ||
  1099. (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)))))
  1100. ward = itr->second;
  1101. }
  1102. }
  1103. if (!ward)
  1104. break;
  1105. spell = ward->Spell;
  1106. // damage to redirect at the source (like intercept)
  1107. int32 redirectDamage = 0;
  1108. if (ward->RedirectDamagePercent)
  1109. redirectDamage = (int32)(double)damage * ((double)ward->RedirectDamagePercent / 100.0);
  1110. // percentage the spell absorbs of all possible damage
  1111. int32 damageToAbsorb = 0;
  1112. if (ward->DamageAbsorptionPercentage > 0)
  1113. damageToAbsorb = (int32)(double)damage * ((double)ward->DamageAbsorptionPercentage/100.0);
  1114. else
  1115. damageToAbsorb = damage;
  1116. int32 maxDamageAbsorptionAllowed = 0;
  1117. // spells like Divine Aura have caps on health, eg. anything more than 50% damage is not absorbed
  1118. if (ward->DamageAbsorptionMaxHealthPercent > 0)
  1119. maxDamageAbsorptionAllowed = (int32)(double)GetTotalHP() * ((double)ward->DamageAbsorptionMaxHealthPercent / 100.0);
  1120. if (maxDamageAbsorptionAllowed > 0 && damageToAbsorb >= maxDamageAbsorptionAllowed)
  1121. damageToAbsorb = 0; // its over or equal to 50% of the total hp allowed, thus this damage is not absorbed
  1122. int32 baseDamageRemaining = damage - damageToAbsorb;
  1123. bool hasSpellBeenRemoved = false;
  1124. if (ward->AbsorbAllDamage)
  1125. {
  1126. ward->LastAbsorbedDamage = ward->DamageLeft;
  1127. if (!redirectDamage)
  1128. GetZone()->SendHealPacket(ward->Spell->caster, this, HEAL_PACKET_TYPE_ABSORB, damage, spell->spell->GetName());
  1129. damage = 0;
  1130. }
  1131. else if (damageToAbsorb >= ward->DamageLeft) {
  1132. // Damage is greater than or equal to the amount left on the ward
  1133. ward->LastAbsorbedDamage = ward->DamageLeft;
  1134. // remove what damage we can absorb
  1135. damageToAbsorb -= ward->DamageLeft;
  1136. // move back what couldn't be absorbed to the base dmg and apply to the overall damage
  1137. baseDamageRemaining += damageToAbsorb;
  1138. damage = baseDamageRemaining;
  1139. ward->DamageLeft = 0;
  1140. spell->damage_remaining = 0;
  1141. if(!redirectDamage)
  1142. GetZone()->SendHealPacket(spell->caster, this, HEAL_PACKET_TYPE_ABSORB, ward->DamageLeft, spell->spell->GetName());
  1143. if (!ward->keepWard) {
  1144. hasSpellBeenRemoved = true;
  1145. RemoveWard(spell->spell->GetSpellID());
  1146. GetZone()->GetSpellProcess()->DeleteCasterSpell(spell);
  1147. }
  1148. }
  1149. else {
  1150. ward->LastAbsorbedDamage = damageToAbsorb;
  1151. // Damage is less then the amount left on the ward
  1152. ward->DamageLeft -= damageToAbsorb;
  1153. spell->damage_remaining = ward->DamageLeft;
  1154. if (spell->caster->IsPlayer())
  1155. ClientPacketFunctions::SendMaintainedExamineUpdate(GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  1156. if (!redirectDamage)
  1157. GetZone()->SendHealPacket(ward->Spell->caster, this, HEAL_PACKET_TYPE_ABSORB, damage, spell->spell->GetName());
  1158. // remaining damage not absorbed by percentage must be set
  1159. damage = baseDamageRemaining;
  1160. }
  1161. if (redirectDamage)
  1162. {
  1163. ward->LastRedirectDamage = redirectDamage;
  1164. if (this->IsPlayer())
  1165. {
  1166. Client* client = GetZone()->GetClientBySpawn(this);
  1167. client->Message(CHANNEL_COLOR_COMBAT, "%s intercepted some of the damage intended for you!", spell->caster->GetName());
  1168. }
  1169. if (spell->caster && spell->caster->IsPlayer())
  1170. {
  1171. Client* client = GetZone()->GetClientBySpawn(spell->caster);
  1172. client->Message(CHANNEL_COLOR_COMBAT, "YOU intercept some of the damage intended for %s!", this->GetName());
  1173. }
  1174. if (attacker && spell->caster)
  1175. attacker->DamageSpawn(spell->caster, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, damage_type, redirectDamage, redirectDamage, 0);
  1176. }
  1177. bool shouldRemoveSpell = false;
  1178. ward->HitCount++; // increment hit count
  1179. if (ward->MaxHitCount && spell->num_triggers)
  1180. {
  1181. spell->num_triggers--;
  1182. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  1183. }
  1184. if (ward->HitCount >= ward->MaxHitCount) // there isn't a max hit requirement with the hit count, so just go based on hit count
  1185. shouldRemoveSpell = true;
  1186. if (shouldRemoveSpell && !hasSpellBeenRemoved)
  1187. {
  1188. RemoveWard(spell->spell->GetSpellID());
  1189. GetZone()->GetSpellProcess()->DeleteCasterSpell(spell);
  1190. }
  1191. // Reset ward pointer
  1192. ward = 0;
  1193. }
  1194. return damage;
  1195. }
  1196. float Entity::CalculateCastingSpeedMod() {
  1197. float cast_speed = info_struct.casting_speed;
  1198. if(cast_speed > 0)
  1199. return 100 * max((float) 0.5, (float) (1 + (1 - (1 / (1 + (cast_speed * .01))))));
  1200. else if (cast_speed < 0)
  1201. return 100 * min((float) 1.5, (float) (1 + (1 - (1 / (1 + (cast_speed * -.01))))));
  1202. return 0;
  1203. }
  1204. float Entity::GetSpeed() {
  1205. float ret = speed > GetBaseSpeed() ? speed : GetBaseSpeed();
  1206. if (EngagedInCombat() && GetMaxSpeed() > 0.0f)
  1207. ret = GetMaxSpeed();
  1208. if (IsStealthed() || IsInvis())
  1209. ret += stats[ITEM_STAT_STEALTHINVISSPEEDMOD];
  1210. else if (EngagedInCombat())
  1211. ret += stats[ITEM_STAT_OFFENSIVESPEED];
  1212. else
  1213. ret += max(stats[ITEM_STAT_SPEED], stats[ITEM_STAT_MOUNTSPEED]);
  1214. ret *= speed_multiplier;
  1215. return ret;
  1216. }
  1217. float Entity::GetAirSpeed() {
  1218. float ret = speed;
  1219. if (!EngagedInCombat())
  1220. ret += stats[ITEM_STAT_MOUNTAIRSPEED];
  1221. ret *= speed_multiplier;
  1222. return ret;
  1223. }
  1224. int8 Entity::GetTraumaCount() {
  1225. return det_count_list[DET_TYPE_TRAUMA];
  1226. }
  1227. int8 Entity::GetArcaneCount() {
  1228. return det_count_list[DET_TYPE_ARCANE];
  1229. }
  1230. int8 Entity::GetNoxiousCount() {
  1231. return det_count_list[DET_TYPE_NOXIOUS];
  1232. }
  1233. int8 Entity::GetElementalCount() {
  1234. return det_count_list[DET_TYPE_ELEMENTAL];
  1235. }
  1236. int8 Entity::GetCurseCount() {
  1237. return det_count_list[DET_TYPE_CURSE];
  1238. }
  1239. Mutex* Entity::GetDetrimentMutex() {
  1240. return &MDetriments;
  1241. }
  1242. Mutex* Entity::GetMaintainedMutex() {
  1243. return &MMaintainedSpells;
  1244. }
  1245. Mutex* Entity::GetSpellEffectMutex() {
  1246. return &MSpellEffects;
  1247. }
  1248. bool Entity::HasCurableDetrimentType(int8 det_type) {
  1249. DetrimentalEffects* det;
  1250. bool ret = false;
  1251. MDetriments.readlock(__FUNCTION__, __LINE__);
  1252. for (int32 i = 0; i < detrimental_spell_effects.size(); i++){
  1253. det = &detrimental_spell_effects.at(i);
  1254. if(det && det->det_type == det_type && !det->incurable){
  1255. ret = true;
  1256. break;
  1257. }
  1258. }
  1259. MDetriments.releasereadlock(__FUNCTION__, __LINE__);
  1260. return ret;
  1261. }
  1262. void Entity::ClearAllDetriments() {
  1263. MDetriments.writelock(__FUNCTION__, __LINE__);
  1264. detrimental_spell_effects.clear();
  1265. det_count_list.clear();
  1266. MDetriments.releasewritelock(__FUNCTION__, __LINE__);
  1267. }
  1268. void Entity::CureDetrimentByType(int8 cure_count, int8 det_type, string cure_name, Entity* caster, int8 cure_level) {
  1269. if (cure_count <= 0 || GetDetTypeCount(det_type) <= 0)
  1270. return;
  1271. vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
  1272. DetrimentalEffects* det;
  1273. vector<LuaSpell*> remove_list;
  1274. LuaSpell* spell = 0;
  1275. vector<LevelArray*>* levels;
  1276. int8 caster_class1 = 0;
  1277. int8 caster_class2 = 0;
  1278. int8 caster_class3 = 0;
  1279. int8 level_class = 0;
  1280. InfoStruct* info_struct = 0;
  1281. bool pass_level_check = false;
  1282. MDetriments.readlock(__FUNCTION__, __LINE__);
  1283. for (int32 i = 0; i<det_list->size(); i++){
  1284. det = &det_list->at(i);
  1285. if (det && det->det_type == det_type && !det->incurable){
  1286. levels = det->spell->spell->GetSpellLevels();
  1287. info_struct = det->caster->GetInfoStruct();
  1288. caster_class1 = info_struct->class1;
  1289. caster_class2 = info_struct->class2;
  1290. caster_class3 = info_struct->class3;
  1291. pass_level_check = false;
  1292. for (int32 x = 0; x < levels->size(); x++){
  1293. level_class = levels->at(x)->adventure_class;
  1294. if (!cure_level || ((caster_class1 == level_class || caster_class2 == level_class || caster_class3 == level_class)
  1295. && cure_level >= (levels->at(x)->spell_level / 10))){
  1296. pass_level_check = true;
  1297. break;
  1298. }
  1299. }
  1300. if (pass_level_check){
  1301. remove_list.push_back(det->spell);
  1302. cure_count--;
  1303. if (cure_count == 0)
  1304. break;
  1305. }
  1306. }
  1307. }
  1308. MDetriments.releasereadlock(__FUNCTION__, __LINE__);
  1309. for (int32 i = 0; i<remove_list.size(); i++){
  1310. spell = remove_list.at(i);
  1311. GetZone()->SendDispellPacket(caster, this, cure_name, (string)remove_list.at(i)->spell->GetName(), DISPELL_TYPE_CURE);
  1312. if (GetZone())
  1313. GetZone()->RemoveTargetFromSpell(spell, this);
  1314. RemoveSpellEffect(spell);
  1315. RemoveDetrimentalSpell(spell);
  1316. }
  1317. remove_list.clear();
  1318. }
  1319. void Entity::CureDetrimentByControlEffect(int8 cure_count, int8 control_type, string cure_name, Entity* caster, int8 cure_level) {
  1320. if (cure_count <= 0 || GetDetCount() <= 0)
  1321. return;
  1322. vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
  1323. DetrimentalEffects* det;
  1324. vector<LuaSpell*> remove_list;
  1325. LuaSpell* spell = 0;
  1326. vector<LevelArray*>* levels;
  1327. int8 caster_class1 = 0;
  1328. int8 caster_class2 = 0;
  1329. int8 caster_class3 = 0;
  1330. int8 level_class = 0;
  1331. InfoStruct* info_struct = 0;
  1332. bool pass_level_check = false;
  1333. MDetriments.readlock(__FUNCTION__, __LINE__);
  1334. for (int32 i = 0; i<det_list->size(); i++){
  1335. det = &det_list->at(i);
  1336. if (det && det->control_effect == control_type && !det->incurable){
  1337. levels = det->spell->spell->GetSpellLevels();
  1338. info_struct = det->caster->GetInfoStruct();
  1339. caster_class1 = info_struct->class1;
  1340. caster_class2 = info_struct->class2;
  1341. caster_class3 = info_struct->class3;
  1342. pass_level_check = false;
  1343. for (int32 x = 0; x < levels->size(); x++){
  1344. level_class = levels->at(x)->adventure_class;
  1345. if (!cure_level || ((caster_class1 == level_class || caster_class2 == level_class || caster_class3 == level_class)
  1346. && cure_level >= (levels->at(x)->spell_level / 10))){
  1347. pass_level_check = true;
  1348. break;
  1349. }
  1350. }
  1351. if (pass_level_check){
  1352. remove_list.push_back(det->spell);
  1353. cure_count--;
  1354. if (cure_count == 0)
  1355. break;
  1356. }
  1357. }
  1358. }
  1359. MDetriments.releasereadlock(__FUNCTION__, __LINE__);
  1360. for (int32 i = 0; i<remove_list.size(); i++){
  1361. spell = remove_list.at(i);
  1362. GetZone()->SendDispellPacket(caster, this, cure_name, (string)remove_list.at(i)->spell->GetName(), DISPELL_TYPE_CURE);
  1363. if (GetZone())
  1364. GetZone()->RemoveTargetFromSpell(spell, this);
  1365. RemoveSpellEffect(spell);
  1366. RemoveDetrimentalSpell(spell);
  1367. }
  1368. remove_list.clear();
  1369. }
  1370. void Entity::RemoveDetrimentalSpell(LuaSpell* spell) {
  1371. if(!spell || spell->spell->GetSpellData()->det_type == 0)
  1372. return;
  1373. MDetriments.writelock(__FUNCTION__, __LINE__);
  1374. vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
  1375. vector<DetrimentalEffects>::iterator itr;
  1376. for(itr = det_list->begin(); itr != det_list->end(); itr++){
  1377. if((*itr).spell == spell){
  1378. det_count_list[(*itr).det_type]--;
  1379. det_list->erase(itr);
  1380. if(IsPlayer())
  1381. ((Player*)this)->SetCharSheetChanged(true);
  1382. break;
  1383. }
  1384. }
  1385. MDetriments.releasewritelock(__FUNCTION__, __LINE__);
  1386. }
  1387. int8 Entity::GetDetTypeCount(int8 det_type){
  1388. return det_count_list[det_type];
  1389. }
  1390. int8 Entity::GetDetCount() {
  1391. int8 det_count = 0;
  1392. map<int8, int8>::iterator itr;
  1393. for(itr=det_count_list.begin(); itr != det_count_list.end(); itr++)
  1394. det_count += (*itr).second;
  1395. return det_count;
  1396. }
  1397. vector<DetrimentalEffects>* Entity::GetDetrimentalSpellEffects() {
  1398. return &detrimental_spell_effects;
  1399. }
  1400. void Entity::AddDetrimentalSpell(LuaSpell* luaspell){
  1401. if(!luaspell || !luaspell->caster)
  1402. return;
  1403. Spell* spell = luaspell->spell;
  1404. DetrimentalEffects* det = GetDetrimentalEffect(spell->GetSpellID(), luaspell->caster);
  1405. DetrimentalEffects new_det;
  1406. if(det)
  1407. RemoveDetrimentalSpell(det->spell);
  1408. SpellData* data = spell->GetSpellData();
  1409. if(!data)
  1410. return;
  1411. new_det.caster = luaspell->caster;
  1412. new_det.spell = luaspell;
  1413. if (spell->GetSpellData()->duration_until_cancel)
  1414. new_det.expire_timestamp = 0xFFFFFFFF;
  1415. else
  1416. new_det.expire_timestamp = Timer::GetCurrentTime2() + (spell->GetSpellDuration()*100);
  1417. new_det.icon = data->icon;
  1418. new_det.icon_backdrop = data->icon_backdrop;
  1419. new_det.tier = data->tier;
  1420. new_det.det_type = data->det_type;
  1421. new_det.incurable = data->incurable;
  1422. new_det.spell_id = spell->GetSpellID();
  1423. new_det.control_effect = data->control_effect_type;
  1424. new_det.total_time = spell->GetSpellDuration()/10;
  1425. MDetriments.writelock(__FUNCTION__, __LINE__);
  1426. detrimental_spell_effects.push_back(new_det);
  1427. det_count_list[new_det.det_type]++;
  1428. MDetriments.releasewritelock(__FUNCTION__, __LINE__);
  1429. }
  1430. DetrimentalEffects* Entity::GetDetrimentalEffect(int32 spell_id, Entity* caster){
  1431. vector<DetrimentalEffects>* det_list = &detrimental_spell_effects;
  1432. DetrimentalEffects* ret = 0;
  1433. MDetriments.readlock(__FUNCTION__, __LINE__);
  1434. for(int32 i=0; i<det_list->size(); i++){
  1435. if (det_list->at(i).spell_id == spell_id && det_list->at(i).caster == caster)
  1436. ret = &det_list->at(i);
  1437. }
  1438. MDetriments.releasereadlock(__FUNCTION__, __LINE__);
  1439. return ret;
  1440. }
  1441. void Entity::CancelAllStealth() {
  1442. bool did_change = false;
  1443. MutexList<LuaSpell*>* stealth_list = control_effects[CONTROL_EFFECT_TYPE_STEALTH];
  1444. if (stealth_list){
  1445. MutexList<LuaSpell*>::iterator itr = stealth_list->begin();
  1446. while (itr.Next()){
  1447. if (itr.value->caster == this)
  1448. GetZone()->GetSpellProcess()->AddSpellCancel(itr.value);
  1449. else{
  1450. GetZone()->RemoveTargetFromSpell(itr.value, this);
  1451. RemoveSpellEffect(itr.value);
  1452. }
  1453. did_change = true;
  1454. }
  1455. }
  1456. MutexList<LuaSpell*>* invis_list = control_effects[CONTROL_EFFECT_TYPE_INVIS];
  1457. if (invis_list){
  1458. MutexList<LuaSpell*>::iterator invis_itr = invis_list->begin();
  1459. while (invis_itr.Next()){
  1460. if (invis_itr.value->caster == this)
  1461. GetZone()->GetSpellProcess()->AddSpellCancel(invis_itr.value);
  1462. else{
  1463. GetZone()->RemoveTargetFromSpell(invis_itr.value, this);
  1464. RemoveSpellEffect(invis_itr.value);
  1465. }
  1466. did_change = true;
  1467. }
  1468. }
  1469. if (did_change){
  1470. info_changed = true;
  1471. changed = true;
  1472. AddChangedZoneSpawn();
  1473. if (IsPlayer())
  1474. ((Player*)this)->SetCharSheetChanged(true);
  1475. }
  1476. }
  1477. bool Entity::IsStealthed(){
  1478. MutexList<LuaSpell*>* stealth_list = control_effects[CONTROL_EFFECT_TYPE_STEALTH];
  1479. return (!stealth_list || stealth_list->size(true) == 0) == false;
  1480. }
  1481. bool Entity::CanSeeInvis(Entity* target) {
  1482. if (!target)
  1483. return true;
  1484. if (!target->IsStealthed() && !target->IsInvis())
  1485. return true;
  1486. if (target->IsStealthed() && HasSeeHideSpell())
  1487. return true;
  1488. else if (target->IsInvis() && HasSeeInvisSpell())
  1489. return true;
  1490. return false;
  1491. }
  1492. bool Entity::IsInvis(){
  1493. MutexList<LuaSpell*>* invis_list = control_effects[CONTROL_EFFECT_TYPE_INVIS];
  1494. return (!invis_list || invis_list->size(true) == 0) == false;
  1495. }
  1496. void Entity::AddStealthSpell(LuaSpell* spell) {
  1497. if (!spell)
  1498. return;
  1499. if (!control_effects[CONTROL_EFFECT_TYPE_STEALTH])
  1500. control_effects[CONTROL_EFFECT_TYPE_STEALTH] = new MutexList<LuaSpell*>;
  1501. control_effects[CONTROL_EFFECT_TYPE_STEALTH]->Add(spell);
  1502. if (control_effects[CONTROL_EFFECT_TYPE_STEALTH]->size(true) == 1){
  1503. info_changed = true;
  1504. changed = true;
  1505. AddChangedZoneSpawn();
  1506. if (IsPlayer())
  1507. {
  1508. ((Player*)this)->SetCharSheetChanged(true);
  1509. GetZone()->SendAllSpawnsForVisChange(GetZone()->GetClientBySpawn(this));
  1510. }
  1511. }
  1512. }
  1513. void Entity::AddInvisSpell(LuaSpell* spell) {
  1514. if (!spell)
  1515. return;
  1516. if (!control_effects[CONTROL_EFFECT_TYPE_INVIS])
  1517. control_effects[CONTROL_EFFECT_TYPE_INVIS] = new MutexList<LuaSpell*>;
  1518. control_effects[CONTROL_EFFECT_TYPE_INVIS]->Add(spell);
  1519. if (control_effects[CONTROL_EFFECT_TYPE_INVIS]->size(true) == 1){
  1520. info_changed = true;
  1521. changed = true;
  1522. AddChangedZoneSpawn();
  1523. if (IsPlayer())
  1524. {
  1525. ((Player*)this)->SetCharSheetChanged(true);
  1526. GetZone()->SendAllSpawnsForVisChange(GetZone()->GetClientBySpawn(this));
  1527. }
  1528. }
  1529. }
  1530. void Entity::RemoveInvisSpell(LuaSpell* spell) {
  1531. MutexList<LuaSpell*>* invis_list = control_effects[CONTROL_EFFECT_TYPE_INVIS];
  1532. if (!invis_list || invis_list->size(true) == 0)
  1533. return;
  1534. invis_list->Remove(spell);
  1535. RemoveSpellEffect(spell);
  1536. if (invis_list->size(true) == 0){
  1537. info_changed = true;
  1538. changed = true;
  1539. AddChangedZoneSpawn();
  1540. if (IsPlayer())
  1541. {
  1542. ((Player*)this)->SetCharSheetChanged(true);
  1543. GetZone()->SendAllSpawnsForVisChange(GetZone()->GetClientBySpawn(this));
  1544. }
  1545. }
  1546. }
  1547. void Entity::RemoveStealthSpell(LuaSpell* spell) {
  1548. MutexList<LuaSpell*>* stealth_list = control_effects[CONTROL_EFFECT_TYPE_STEALTH];
  1549. if (!stealth_list || stealth_list->size(true) == 0)
  1550. return;
  1551. stealth_list->Remove(spell);
  1552. RemoveSpellEffect(spell);
  1553. if (stealth_list->size() == 0){
  1554. info_changed = true;
  1555. changed = true;
  1556. AddChangedZoneSpawn();
  1557. if (IsPlayer())
  1558. {
  1559. ((Player*)this)->SetCharSheetChanged(true);
  1560. GetZone()->SendAllSpawnsForVisChange(GetZone()->GetClientBySpawn(this));
  1561. }
  1562. }
  1563. }
  1564. void Entity::AddRootSpell(LuaSpell* spell) {
  1565. if (!spell)
  1566. return;
  1567. if (!control_effects[CONTROL_EFFECT_TYPE_ROOT])
  1568. control_effects[CONTROL_EFFECT_TYPE_ROOT] = new MutexList<LuaSpell*>;
  1569. if (control_effects[CONTROL_EFFECT_TYPE_ROOT]->size(true) == 0 && !IsRootImmune()) {
  1570. if (IsPlayer()){
  1571. if (!IsMezzedOrStunned())
  1572. ((Player*)this)->SetPlayerControlFlag(1, 8, true); // heading movement only
  1573. }
  1574. else
  1575. SetSpeedMultiplier(0.0f);
  1576. }
  1577. control_effects[CONTROL_EFFECT_TYPE_ROOT]->Add(spell);
  1578. }
  1579. void Entity::RemoveRootSpell(LuaSpell* spell) {
  1580. MutexList<LuaSpell*>* root_list = control_effects[CONTROL_EFFECT_TYPE_ROOT];
  1581. if (!root_list || root_list->size(true) == 0)
  1582. return;
  1583. root_list->Remove(spell);
  1584. if (root_list->size(true) == 0 && !IsRootImmune()) {
  1585. if (IsPlayer()){
  1586. if (!IsMezzedOrStunned())
  1587. ((Player*)this)->SetPlayerControlFlag(1, 8, false); // heading movement only
  1588. }
  1589. else {
  1590. // GetHighestSnare() will return 1.0f if no snares returning the spawn to full speed
  1591. SetSpeedMultiplier(GetHighestSnare());
  1592. }
  1593. }
  1594. }
  1595. void Entity::AddFearSpell(LuaSpell* spell){
  1596. if (!spell)
  1597. return;
  1598. if (!control_effects[CONTROL_EFFECT_TYPE_FEAR])
  1599. control_effects[CONTROL_EFFECT_TYPE_FEAR] = new MutexList<LuaSpell*>;
  1600. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_FEAR]->size(true) == 0 && !IsFearImmune()){
  1601. ((Player*)this)->SetPlayerControlFlag(4, 4, true); // feared
  1602. if (!IsMezzedOrStunned() && !IsStifled())
  1603. GetZone()->LockAllSpells((Player*)this);
  1604. }
  1605. if (!IsFearImmune() && IsNPC())
  1606. {
  1607. HaltMovement();
  1608. }
  1609. control_effects[CONTROL_EFFECT_TYPE_FEAR]->Add(spell);
  1610. }
  1611. void Entity::RemoveFearSpell(LuaSpell* spell){
  1612. MutexList<LuaSpell*>* fear_list = control_effects[CONTROL_EFFECT_TYPE_FEAR];
  1613. if (!fear_list || fear_list->size(true) == 0)
  1614. return;
  1615. fear_list->Remove(spell);
  1616. if (IsPlayer() && fear_list->size(true) == 0 && !IsFearImmune()){
  1617. ((Player*)this)->SetPlayerControlFlag(4, 4, false); // feared disabled
  1618. if (!IsMezzedOrStunned() && !IsStifled())
  1619. GetZone()->LockAllSpells((Player*)this);
  1620. }
  1621. if (IsNPC())
  1622. {
  1623. HaltMovement();
  1624. }
  1625. }
  1626. void Entity::AddSnareSpell(LuaSpell* spell) {
  1627. if (!spell)
  1628. return;
  1629. if (!control_effects[CONTROL_EFFECT_TYPE_SNARE])
  1630. control_effects[CONTROL_EFFECT_TYPE_SNARE] = new MutexList<LuaSpell*>;
  1631. control_effects[CONTROL_EFFECT_TYPE_SNARE]->Add(spell);
  1632. // Don't set speed multiplier if there is a root or no snare values
  1633. MutexList<LuaSpell*>* roots = control_effects[CONTROL_EFFECT_TYPE_ROOT];
  1634. if ((!roots || roots->size(true) == 0) && snare_values.size() > 0)
  1635. SetSpeedMultiplier(GetHighestSnare());
  1636. }
  1637. void Entity::RemoveSnareSpell(LuaSpell* spell) {
  1638. MutexList<LuaSpell*>* snare_list = control_effects[CONTROL_EFFECT_TYPE_SNARE];
  1639. if (!snare_list || snare_list->size(true) == 0)
  1640. return;
  1641. snare_list->Remove(spell);
  1642. snare_values.erase(spell);
  1643. //LogWrite(PLAYER__ERROR, 0, "Debug", "snare_values.size() = %u", snare_values.size());
  1644. // only change speeds if there are no roots
  1645. MutexList<LuaSpell*>* roots = control_effects[CONTROL_EFFECT_TYPE_ROOT];
  1646. if (!roots || roots->size(true) == 0) {
  1647. float multiplier = GetHighestSnare();
  1648. //LogWrite(PLAYER__ERROR, 0, "Debug", "GetHighestSnare() = %f", multiplier);
  1649. SetSpeedMultiplier(multiplier);
  1650. }
  1651. }
  1652. void Entity::SetSnareValue(LuaSpell* spell, float snare_val) {
  1653. if (!spell)
  1654. return;
  1655. snare_values[spell] = snare_val;
  1656. }
  1657. float Entity::GetHighestSnare() {
  1658. // For simplicity this will return the highest snare value, which is actually the lowest value
  1659. float ret = 1.0f;
  1660. if (snare_values.size() == 0)
  1661. return ret;
  1662. map<LuaSpell*, float>::iterator itr;
  1663. for (itr = snare_values.begin(); itr != snare_values.end(); itr++) {
  1664. if (itr->second < ret)
  1665. ret = itr->second;
  1666. }
  1667. return ret;
  1668. }
  1669. bool Entity::IsSnared() {
  1670. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_SNARE])
  1671. return false;
  1672. MutexList<LuaSpell*>* snare_list = control_effects[CONTROL_EFFECT_TYPE_SNARE];
  1673. return (!snare_list || snare_list->size(true) == 0) == false;
  1674. }
  1675. bool Entity::IsMezzed(){
  1676. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_MEZ])
  1677. return false;
  1678. MutexList<LuaSpell*>* mez_spells = control_effects[CONTROL_EFFECT_TYPE_MEZ];
  1679. return (!mez_spells || mez_spells->size(true) == 0 || IsMezImmune()) == false;
  1680. }
  1681. bool Entity::IsStifled(){
  1682. if (!control_effects[CONTROL_EFFECT_TYPE_STIFLE])
  1683. return false;
  1684. MutexList<LuaSpell*>* stifle_list = control_effects[CONTROL_EFFECT_TYPE_STIFLE];
  1685. return (!stifle_list || stifle_list->size(true) == 0 || IsStifleImmune()) == false;
  1686. }
  1687. bool Entity::IsDazed(){
  1688. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_DAZE])
  1689. return false;
  1690. MutexList<LuaSpell*>* daze_list = control_effects[CONTROL_EFFECT_TYPE_DAZE];
  1691. return (!daze_list || daze_list->size(true) == 0 || IsDazeImmune()) == false;
  1692. }
  1693. bool Entity::IsStunned(){
  1694. if (!control_effects[CONTROL_EFFECT_TYPE_STUN])
  1695. return false;
  1696. MutexList<LuaSpell*>* stun_list = control_effects[CONTROL_EFFECT_TYPE_STUN];
  1697. return (!stun_list || stun_list->size(true) == 0 || IsStunImmune()) == false;
  1698. }
  1699. bool Entity::IsRooted(){
  1700. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_ROOT])
  1701. return false;
  1702. MutexList<LuaSpell*>* root_list = control_effects[CONTROL_EFFECT_TYPE_ROOT];
  1703. return (!root_list || root_list->size(true) == 0 || IsRootImmune()) == false;
  1704. }
  1705. bool Entity::IsFeared(){
  1706. if (control_effects.size() < 1 || !control_effects[CONTROL_EFFECT_TYPE_FEAR])
  1707. return false;
  1708. MutexList<LuaSpell*>* fear_list = control_effects[CONTROL_EFFECT_TYPE_FEAR];
  1709. return (!fear_list || fear_list->size(true) == 0 || IsFearImmune()) == false;
  1710. }
  1711. void Entity::AddWaterwalkSpell(LuaSpell* spell){
  1712. if (!spell)
  1713. return;
  1714. if (!control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER])
  1715. control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER] = new MutexList<LuaSpell*>;
  1716. control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER]->Add(spell);
  1717. if (control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER]->size(true) == 1 && IsPlayer())
  1718. ((Player*)this)->SetPlayerControlFlag(3, 128, true); // enable walking underwater
  1719. }
  1720. void Entity::RemoveWaterwalkSpell(LuaSpell* spell){
  1721. MutexList<LuaSpell*>* waterwalk_list = control_effects[CONTROL_EFFECT_TYPE_WALKUNDERWATER];
  1722. if (!waterwalk_list || waterwalk_list->size(true) == 0)
  1723. return;
  1724. waterwalk_list->Remove(spell);
  1725. if (waterwalk_list->size(true) == 0 && IsPlayer())
  1726. ((Player*)this)->SetPlayerControlFlag(3, 128, false); // disable walking underwater
  1727. }
  1728. void Entity::AddWaterjumpSpell(LuaSpell* spell){
  1729. if (!spell)
  1730. return;
  1731. if (!control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER])
  1732. control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER] = new MutexList<LuaSpell*>;
  1733. control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER]->Add(spell);
  1734. if (control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER]->size(true) == 1 && IsPlayer())
  1735. ((Player*)this)->SetPlayerControlFlag(4, 1, true); // enable moonjumps underwater
  1736. }
  1737. void Entity::RemoveWaterjumpSpell(LuaSpell* spell){
  1738. MutexList<LuaSpell*>* waterjump_list = control_effects[CONTROL_EFFECT_TYPE_JUMPUNDERWATER];
  1739. if (!waterjump_list || waterjump_list->size(true) == 0)
  1740. return;
  1741. waterjump_list->Remove(spell);
  1742. if (waterjump_list->size(true) == 0 && IsPlayer())
  1743. ((Player*)this)->SetPlayerControlFlag(4, 1, false); // disable moonjumps underwater
  1744. }
  1745. void Entity::AddAOEImmunity(LuaSpell* spell){
  1746. if (!spell)
  1747. return;
  1748. if (!immunities[IMMUNITY_TYPE_AOE])
  1749. immunities[IMMUNITY_TYPE_AOE] = new MutexList<LuaSpell*>;
  1750. immunities[IMMUNITY_TYPE_AOE]->Add(spell);
  1751. }
  1752. void Entity::RemoveAOEImmunity(LuaSpell* spell){
  1753. MutexList<LuaSpell*>* aoe_list = immunities[IMMUNITY_TYPE_AOE];
  1754. if (!aoe_list || aoe_list->size(true) == 0)
  1755. return;
  1756. aoe_list->Remove(spell);
  1757. }
  1758. bool Entity::IsAOEImmune(){
  1759. return (immunities[IMMUNITY_TYPE_AOE] && immunities[IMMUNITY_TYPE_AOE]->size(true));
  1760. }
  1761. void Entity::AddStunImmunity(LuaSpell* spell){
  1762. if (!spell)
  1763. return;
  1764. if (!immunities[IMMUNITY_TYPE_STUN])
  1765. immunities[IMMUNITY_TYPE_STUN] = new MutexList<LuaSpell*>;
  1766. if (IsPlayer() && IsStunned() && !IsMezzed()){
  1767. ((Player*)this)->SetPlayerControlFlag(4, 64, false);
  1768. if (!IsFeared() && !IsStifled())
  1769. ((Player*)this)->UnlockAllSpells();
  1770. }
  1771. immunities[IMMUNITY_TYPE_STUN]->Add(spell);
  1772. }
  1773. void Entity::RemoveStunImmunity(LuaSpell* spell){
  1774. MutexList<LuaSpell*>* stun_list = immunities[IMMUNITY_TYPE_STUN];
  1775. if (!stun_list || stun_list->size(true) == 0)
  1776. return;
  1777. stun_list->Remove(spell);
  1778. if (IsPlayer() && IsStunned() && !IsMezzed()){
  1779. ((Player*)this)->SetPlayerControlFlag(4, 64, true);
  1780. if (!IsFeared() && !IsStifled())
  1781. ((Player*)this)->UnlockAllSpells();
  1782. }
  1783. }
  1784. bool Entity::IsStunImmune(){
  1785. return (immunities[IMMUNITY_TYPE_STUN] && immunities[IMMUNITY_TYPE_STUN]->size(true) > 0);
  1786. }
  1787. void Entity::AddStifleImmunity(LuaSpell* spell){
  1788. if (!spell)
  1789. return;
  1790. if (!immunities[IMMUNITY_TYPE_STIFLE])
  1791. immunities[IMMUNITY_TYPE_STIFLE] = new MutexList<LuaSpell*>;
  1792. if (IsPlayer() && immunities[IMMUNITY_TYPE_STIFLE]->size(true) == 0){
  1793. if (IsStifled() && !IsMezzedOrStunned() && !IsFeared())
  1794. ((Player*)this)->UnlockAllSpells();
  1795. }
  1796. immunities[IMMUNITY_TYPE_STIFLE]->Add(spell);
  1797. }
  1798. void Entity::RemoveStifleImmunity(LuaSpell* spell){
  1799. MutexList<LuaSpell*>* stifle_list = immunities[IMMUNITY_TYPE_STIFLE];
  1800. if (!stifle_list || stifle_list->size(true) == 0)
  1801. return;
  1802. stifle_list->Remove(spell);
  1803. if (IsPlayer() && IsStifled() && !IsMezzedOrStunned() && !IsFeared())
  1804. ((Player*)this)->UnlockAllSpells();
  1805. }
  1806. bool Entity::IsStifleImmune(){
  1807. return (immunities[IMMUNITY_TYPE_STIFLE] && immunities[IMMUNITY_TYPE_STIFLE]->size(true) > 0);
  1808. }
  1809. void Entity::AddMezImmunity(LuaSpell* spell){
  1810. if (!spell)
  1811. return;
  1812. if (!immunities[IMMUNITY_TYPE_MEZ])
  1813. immunities[IMMUNITY_TYPE_MEZ] = new MutexList<LuaSpell*>;
  1814. if (IsPlayer() && IsMezzed() && !IsStunned()){
  1815. ((Player*)this)->SetPlayerControlFlag(4, 64, false);
  1816. if (!IsFeared() && !IsStifled())
  1817. ((Player*)this)->UnlockAllSpells();
  1818. }
  1819. immunities[IMMUNITY_TYPE_MEZ]->Add(spell);
  1820. }
  1821. void Entity::RemoveMezImmunity(LuaSpell* spell){
  1822. MutexList<LuaSpell*>* mez_list = immunities[IMMUNITY_TYPE_MEZ];
  1823. if (!mez_list || mez_list->size(true) == 0)
  1824. return;
  1825. mez_list->Remove(spell);
  1826. if (IsPlayer() && IsMezzed() && !IsStunned()){
  1827. ((Player*)this)->SetPlayerControlFlag(4, 64, true);
  1828. if (!IsFeared() && !IsStifled())
  1829. ((Player*)this)->LockAllSpells();
  1830. }
  1831. }
  1832. bool Entity::IsMezImmune(){
  1833. return (immunities[IMMUNITY_TYPE_MEZ] && immunities[IMMUNITY_TYPE_MEZ]->size(true) > 0);
  1834. }
  1835. void Entity::AddRootImmunity(LuaSpell* spell){
  1836. if (!spell)
  1837. return;
  1838. if (!immunities[IMMUNITY_TYPE_ROOT])
  1839. immunities[IMMUNITY_TYPE_ROOT] = new MutexList<LuaSpell*>;
  1840. if (IsPlayer() && IsRooted())
  1841. ((Player*)this)->SetPlayerControlFlag(1, 8, false);
  1842. immunities[IMMUNITY_TYPE_ROOT]->Add(spell);
  1843. }
  1844. void Entity::RemoveRootImmunity(LuaSpell* spell){
  1845. MutexList<LuaSpell*>* root_list = immunities[IMMUNITY_TYPE_ROOT];
  1846. if (!root_list || root_list->size(true) == 0)
  1847. return;
  1848. root_list->Remove(spell);
  1849. if (IsPlayer() && IsRooted())
  1850. ((Player*)this)->SetPlayerControlFlag(1, 8, true);
  1851. }
  1852. bool Entity::IsRootImmune(){
  1853. return (immunities[IMMUNITY_TYPE_ROOT] && immunities[IMMUNITY_TYPE_ROOT]->size(true) > 0);
  1854. }
  1855. void Entity::AddFearImmunity(LuaSpell* spell){
  1856. if (!spell)
  1857. return;
  1858. if (!immunities[IMMUNITY_TYPE_FEAR])
  1859. immunities[IMMUNITY_TYPE_FEAR] = new MutexList<LuaSpell*>;
  1860. if (IsPlayer() && IsFeared()){
  1861. if (!IsMezzedOrStunned() && !IsStifled())
  1862. ((Player*)this)->UnlockAllSpells();
  1863. ((Player*)this)->SetPlayerControlFlag(4, 4, false);
  1864. }
  1865. immunities[IMMUNITY_TYPE_FEAR]->Add(spell);
  1866. }
  1867. void Entity::RemoveFearImmunity(LuaSpell* spell){
  1868. MutexList<LuaSpell*>* fear_list = immunities[IMMUNITY_TYPE_FEAR];
  1869. if (!fear_list || fear_list->size(true) == 0)
  1870. return;
  1871. fear_list->Remove(spell);
  1872. if (IsPlayer() && IsFeared()){
  1873. if (!IsMezzedOrStunned() && !IsStifled())
  1874. ((Player*)this)->LockAllSpells();
  1875. ((Player*)this)->SetPlayerControlFlag(4, 4, true);
  1876. }
  1877. }
  1878. bool Entity::IsFearImmune(){
  1879. return (immunities[IMMUNITY_TYPE_FEAR] && immunities[IMMUNITY_TYPE_FEAR]->size(true) > 0);
  1880. }
  1881. void Entity::AddDazeImmunity(LuaSpell* spell){
  1882. if (!spell)
  1883. return;
  1884. if (!immunities[IMMUNITY_TYPE_DAZE])
  1885. immunities[IMMUNITY_TYPE_DAZE] = new MutexList<LuaSpell*>;
  1886. immunities[IMMUNITY_TYPE_DAZE]->Add(spell);
  1887. }
  1888. void Entity::RemoveDazeImmunity(LuaSpell* spell){
  1889. MutexList<LuaSpell*>* daze_list = immunities[IMMUNITY_TYPE_DAZE];
  1890. if (!daze_list || daze_list->size(true) == 0)
  1891. return;
  1892. daze_list->Remove(spell);
  1893. }
  1894. bool Entity::IsDazeImmune(){
  1895. return (immunities[IMMUNITY_TYPE_DAZE] && immunities[IMMUNITY_TYPE_DAZE]->size(true) > 0);
  1896. }
  1897. void Entity::RemoveEffectsFromLuaSpell(LuaSpell* spell){
  1898. if (!spell)
  1899. return;
  1900. //Attempt to remove all applied effects from this spell when spell has been removed from just this target. Should improve performance/easier maitenance
  1901. int32 effect_bitmask = spell->effect_bitmask;
  1902. if (effect_bitmask == 0)
  1903. return;
  1904. if (effect_bitmask & EFFECT_FLAG_STUN)
  1905. RemoveStunSpell(spell);
  1906. if (effect_bitmask & EFFECT_FLAG_ROOT)
  1907. RemoveRootSpell(spell);
  1908. if (effect_bitmask & EFFECT_FLAG_MEZ)
  1909. RemoveMezSpell(spell);
  1910. if (effect_bitmask & EFFECT_FLAG_STIFLE)
  1911. RemoveStifleSpell(spell);
  1912. if (effect_bitmask & EFFECT_FLAG_DAZE)
  1913. RemoveDazeSpell(spell);
  1914. if (effect_bitmask & EFFECT_FLAG_FEAR)
  1915. RemoveFearSpell(spell);
  1916. if (effect_bitmask & EFFECT_FLAG_SPELLBONUS)
  1917. RemoveSpellBonus(spell);
  1918. if (effect_bitmask & EFFECT_FLAG_SKILLBONUS)
  1919. RemoveSkillBonus(spell->spell->GetSpellID());
  1920. if (effect_bitmask & EFFECT_FLAG_STEALTH)
  1921. RemoveStealthSpell(spell);
  1922. if (effect_bitmask & EFFECT_FLAG_INVIS)
  1923. RemoveInvisSpell(spell);
  1924. if (effect_bitmask & EFFECT_FLAG_SNARE)
  1925. RemoveSnareSpell(spell);
  1926. if (effect_bitmask & EFFECT_FLAG_WATERWALK)
  1927. RemoveWaterwalkSpell(spell);
  1928. if (effect_bitmask & EFFECT_FLAG_WATERJUMP)
  1929. RemoveWaterjumpSpell(spell);
  1930. if (effect_bitmask & EFFECT_FLAG_FLIGHT)
  1931. RemoveFlightSpell(spell);
  1932. if (effect_bitmask & EFFECT_FLAG_GLIDE)
  1933. RemoveGlideSpell(spell);
  1934. if (effect_bitmask & EFFECT_FLAG_AOE_IMMUNE)
  1935. RemoveAOEImmunity(spell);
  1936. if (effect_bitmask & EFFECT_FLAG_STUN_IMMUNE)
  1937. RemoveStunImmunity(spell);
  1938. if (effect_bitmask & EFFECT_FLAG_MEZ_IMMUNE)
  1939. RemoveMezImmunity(spell);
  1940. if (effect_bitmask & EFFECT_FLAG_DAZE_IMMUNE)
  1941. RemoveDazeImmunity(spell);
  1942. if (effect_bitmask & EFFECT_FLAG_ROOT_IMMUNE)
  1943. RemoveRootImmunity(spell);
  1944. if (effect_bitmask & EFFECT_FLAG_STIFLE_IMMUNE)
  1945. RemoveStifleImmunity(spell);
  1946. if (effect_bitmask & EFFECT_FLAG_FEAR_IMMUNE)
  1947. RemoveFearImmunity(spell);
  1948. if (effect_bitmask & EFFECT_FLAG_SAFEFALL)
  1949. RemoveSafefallSpell(spell);
  1950. }
  1951. void Entity::RemoveSkillBonus(int32 spell_id){
  1952. //This is a virtual, just making it so we don't have to do extra checks for player/npcs
  1953. return;
  1954. }
  1955. void Entity::AddFlightSpell(LuaSpell* spell){
  1956. if (!spell)
  1957. return;
  1958. if (!control_effects[CONTROL_EFFECT_TYPE_FLIGHT])
  1959. control_effects[CONTROL_EFFECT_TYPE_FLIGHT] = new MutexList<LuaSpell*>;
  1960. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_FLIGHT]->size(true) == 0)
  1961. ((Player*)this)->SetPlayerControlFlag(5, 32, true);
  1962. control_effects[CONTROL_EFFECT_TYPE_FLIGHT]->Add(spell);
  1963. }
  1964. void Entity::RemoveFlightSpell(LuaSpell* spell){
  1965. MutexList<LuaSpell*>* flight_list = control_effects[CONTROL_EFFECT_TYPE_FLIGHT];
  1966. if (!flight_list || flight_list->size(true) == 0)
  1967. return;
  1968. flight_list->Remove(spell);
  1969. if (IsPlayer() && flight_list->size(true) == 0)
  1970. ((Player*)this)->SetPlayerControlFlag(5, 32, false);
  1971. }
  1972. void Entity::AddGlideSpell(LuaSpell* spell){
  1973. if (!spell)
  1974. return;
  1975. if (!control_effects[CONTROL_EFFECT_TYPE_GLIDE])
  1976. control_effects[CONTROL_EFFECT_TYPE_GLIDE] = new MutexList<LuaSpell*>;
  1977. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_GLIDE]->size(true) == 0)
  1978. ((Player*)this)->SetPlayerControlFlag(4, 16, true);
  1979. control_effects[CONTROL_EFFECT_TYPE_GLIDE]->Add(spell);
  1980. }
  1981. void Entity::RemoveGlideSpell(LuaSpell* spell){
  1982. MutexList<LuaSpell*>* glide_list = control_effects[CONTROL_EFFECT_TYPE_GLIDE];
  1983. if (!glide_list || glide_list->size(true) == 0)
  1984. return;
  1985. glide_list->Remove(spell);
  1986. if (IsPlayer() && glide_list->size(true) == 0)
  1987. ((Player*)this)->SetPlayerControlFlag(4, 16, false);
  1988. }
  1989. void Entity::AddSafefallSpell(LuaSpell* spell){
  1990. if (!spell)
  1991. return;
  1992. if (!control_effects[CONTROL_EFFECT_TYPE_SAFEFALL])
  1993. control_effects[CONTROL_EFFECT_TYPE_SAFEFALL] = new MutexList<LuaSpell*>;
  1994. if (IsPlayer() && control_effects[CONTROL_EFFECT_TYPE_SAFEFALL]->size(true) == 0)
  1995. ((Player*)this)->SetPlayerControlFlag(4, 32, true);
  1996. control_effects[CONTROL_EFFECT_TYPE_SAFEFALL]->Add(spell);
  1997. }
  1998. void Entity::RemoveSafefallSpell(LuaSpell* spell){
  1999. MutexList<LuaSpell*>* safe_list = control_effects[CONTROL_EFFECT_TYPE_SAFEFALL];
  2000. if (!safe_list || safe_list->size(true) == 0)
  2001. return;
  2002. safe_list->Remove(spell);
  2003. if (IsPlayer() && safe_list->size(true) == 0)
  2004. ((Player*)this)->SetPlayerControlFlag(4, 32, false);
  2005. }
  2006. void Entity::UpdateGroupMemberInfo() {
  2007. if (!group_member_info)
  2008. return;
  2009. group_member_info->class_id = GetAdventureClass();
  2010. group_member_info->hp_max = GetTotalHP();
  2011. group_member_info->hp_current = GetHP();
  2012. group_member_info->level_max = GetLevel();
  2013. group_member_info->level_current = GetLevel();
  2014. group_member_info->name = string(GetName());
  2015. group_member_info->power_current = GetPower();
  2016. group_member_info->power_max = GetTotalPower();
  2017. group_member_info->race_id = GetRace();
  2018. if (GetZone())
  2019. group_member_info->zone = GetZone()->GetZoneDescription();
  2020. else
  2021. group_member_info->zone = "Unknown";
  2022. }
  2023. #include "WorldDatabase.h"
  2024. extern WorldDatabase database;
  2025. void Entity::CustomizeAppearance(PacketStruct* packet) {
  2026. bool is_soga = packet->getType_int8_ByName("is_soga") == 1 ? true : false;
  2027. int16 model_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("race_file").data);
  2028. EQ2_Color skin_color = packet->getType_EQ2_Color_ByName("skin_color");
  2029. EQ2_Color skin_color2 = packet->getType_EQ2_Color_ByName("skin_color2");
  2030. EQ2_Color eye_color = packet->getType_EQ2_Color_ByName("eye_color");
  2031. EQ2_Color hair_color1 = packet->getType_EQ2_Color_ByName("hair_color1");
  2032. EQ2_Color hair_color2 = packet->getType_EQ2_Color_ByName("hair_color2");
  2033. EQ2_Color hair_highlight = packet->getType_EQ2_Color_ByName("hair_highlight");
  2034. int16 hair_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("hair_file").data);
  2035. EQ2_Color hair_type_color = packet->getType_EQ2_Color_ByName("hair_type_color");
  2036. EQ2_Color hair_type_highlight_color = packet->getType_EQ2_Color_ByName("hair_type_highlight_color");
  2037. int16 face_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("face_file").data);
  2038. EQ2_Color hair_face_color = packet->getType_EQ2_Color_ByName("hair_face_color");
  2039. EQ2_Color hair_face_highlight_color = packet->getType_EQ2_Color_ByName("hair_face_highlight_color");
  2040. int16 wing_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("wing_file").data);
  2041. EQ2_Color wing_color1 = packet->getType_EQ2_Color_ByName("wing_color1");
  2042. EQ2_Color wing_color2 = packet->getType_EQ2_Color_ByName("wing_color2");
  2043. int16 chest_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("chest_file").data);
  2044. EQ2_Color shirt_color = packet->getType_EQ2_Color_ByName("shirt_color");
  2045. EQ2_Color unknown_chest_color = packet->getType_EQ2_Color_ByName("unknown_chest_color");
  2046. int16 legs_id = database.GetAppearanceID(packet->getType_EQ2_16BitString_ByName("legs_file").data);
  2047. EQ2_Color pants_color = packet->getType_EQ2_Color_ByName("pants_color");
  2048. EQ2_Color unknown_legs_color = packet->getType_EQ2_Color_ByName("unknown_legs_color");
  2049. EQ2_Color unknown2 = packet->getType_EQ2_Color_ByName("unknown2");
  2050. float eyes2[3];
  2051. eyes2[0] = packet->getType_float_ByName("eyes2", 0) * 100;
  2052. eyes2[1] = packet->getType_float_ByName("eyes2", 1) * 100;
  2053. eyes2[2] = packet->getType_float_ByName("eyes2", 2) * 100;
  2054. float ears[3];
  2055. ears[0] = packet->getType_float_ByName("ears", 0) * 100;
  2056. ears[1] = packet->getType_float_ByName("ears", 1) * 100;
  2057. ears[2] = packet->getType_float_ByName("ears", 2) * 100;
  2058. float eye_brows[3];
  2059. eye_brows[0] = packet->getType_float_ByName("eye_brows", 0) * 100;
  2060. eye_brows[1] = packet->getType_float_ByName("eye_brows", 1) * 100;
  2061. eye_brows[2] = packet->getType_float_ByName("eye_brows", 2) * 100;
  2062. float cheeks[3];
  2063. cheeks[0] = packet->getType_float_ByName("cheeks", 0) * 100;
  2064. cheeks[1] = packet->getType_float_ByName("cheeks", 1) * 100;
  2065. cheeks[2] = packet->getType_float_ByName("cheeks", 2) * 100;
  2066. float lips[3];
  2067. lips[0] = packet->getType_float_ByName("lips", 0) * 100;
  2068. lips[1] = packet->getType_float_ByName("lips", 1) * 100;
  2069. lips[2] = packet->getType_float_ByName("lips", 2) * 100;
  2070. float chin[3];
  2071. chin[0] = packet->getType_float_ByName("chin", 0) * 100;
  2072. chin[1] = packet->getType_float_ByName("chin", 1) * 100;
  2073. chin[2] = packet->getType_float_ByName("chin", 2) * 100;
  2074. float nose[3];
  2075. nose[0] = packet->getType_float_ByName("nose", 0) * 100;
  2076. nose[1] = packet->getType_float_ByName("nose", 1) * 100;
  2077. nose[2] = packet->getType_float_ByName("nose", 2) * 100;
  2078. sint8 body_size = (sint8)(packet->getType_float_ByName("body_size") * 100);
  2079. sint8 body_age = (sint8)(packet->getType_float_ByName("body_age") * 100);
  2080. if (is_soga) {
  2081. appearance.soga_model_type = model_id;
  2082. features.soga_skin_color = skin_color;
  2083. features.soga_eye_color = eye_color;
  2084. features.soga_hair_color1 = hair_color1;
  2085. features.soga_hair_color2 = hair_color2;
  2086. features.soga_hair_highlight_color = hair_highlight;
  2087. features.soga_hair_type = hair_id;
  2088. features.soga_hair_type_color = hair_type_color;
  2089. features.soga_hair_type_highlight_color = hair_type_highlight_color;
  2090. features.soga_hair_face_type = face_id;
  2091. features.soga_hair_face_color = hair_face_color;
  2092. features.soga_hair_face_highlight_color = hair_face_highlight_color;
  2093. features.wing_type = wing_id;
  2094. features.wing_color1 = wing_color1;
  2095. features.wing_color2 = wing_color2;
  2096. features.soga_chest_type = chest_id;
  2097. features.shirt_color = shirt_color;
  2098. features.soga_legs_type = legs_id;
  2099. features.pants_color = pants_color;
  2100. features.soga_eye_type[0] = eyes2[0];
  2101. features.soga_eye_type[1] = eyes2[1];
  2102. features.soga_eye_type[2] = eyes2[2];
  2103. features.soga_ear_type[0] = ears[0];
  2104. features.soga_ear_type[0] = ears[1];
  2105. features.soga_ear_type[0] = ears[2];
  2106. features.soga_eye_brow_type[0] = eye_brows[0];
  2107. features.soga_eye_brow_type[1] = eye_brows[1];
  2108. features.soga_eye_brow_type[2] = eye_brows[2];
  2109. features.soga_cheek_type[0] = cheeks[0];
  2110. features.soga_cheek_type[1] = cheeks[1];
  2111. features.soga_cheek_type[2] = cheeks[2];
  2112. features.soga_lip_type[0] = lips[0];
  2113. features.soga_lip_type[1] = lips[1];
  2114. features.soga_lip_type[2] = lips[2];
  2115. features.soga_chin_type[0] = chin[0];
  2116. features.soga_chin_type[1] = chin[1];
  2117. features.soga_chin_type[2] = chin[2];
  2118. features.soga_nose_type[0] = nose[0];
  2119. features.soga_nose_type[1] = nose[1];
  2120. features.soga_nose_type[2] = nose[2];
  2121. }
  2122. else {
  2123. appearance.model_type = model_id;
  2124. features.skin_color = skin_color;
  2125. features.eye_color = eye_color;
  2126. features.hair_color1 = hair_color1;
  2127. features.hair_color2 = hair_color2;
  2128. features.hair_highlight_color = hair_highlight;
  2129. features.hair_type = hair_id;
  2130. features.hair_type_color = hair_type_color;
  2131. features.hair_type_highlight_color = hair_type_highlight_color;
  2132. features.hair_face_type = face_id;
  2133. features.hair_face_color = hair_face_color;
  2134. features.hair_face_highlight_color = hair_face_highlight_color;
  2135. features.wing_type = wing_id;
  2136. features.wing_color1 = wing_color1;
  2137. features.wing_color2 = wing_color2;
  2138. features.chest_type = chest_id;
  2139. features.shirt_color = shirt_color;
  2140. features.legs_type = legs_id;
  2141. features.pants_color = pants_color;
  2142. features.eye_type[0] = eyes2[0];
  2143. features.eye_type[1] = eyes2[1];
  2144. features.eye_type[2] = eyes2[2];
  2145. features.ear_type[0] = ears[0];
  2146. features.ear_type[0] = ears[1];
  2147. features.ear_type[0] = ears[2];
  2148. features.eye_brow_type[0] = eye_brows[0];
  2149. features.eye_brow_type[1] = eye_brows[1];
  2150. features.eye_brow_type[2] = eye_brows[2];
  2151. features.cheek_type[0] = cheeks[0];
  2152. features.cheek_type[1] = cheeks[1];
  2153. features.cheek_type[2] = cheeks[2];
  2154. features.lip_type[0] = lips[0];
  2155. features.lip_type[1] = lips[1];
  2156. features.lip_type[2] = lips[2];
  2157. features.chin_type[0] = chin[0];
  2158. features.chin_type[1] = chin[1];
  2159. features.chin_type[2] = chin[2];
  2160. features.nose_type[0] = nose[0];
  2161. features.nose_type[1] = nose[1];
  2162. features.nose_type[2] = nose[2];
  2163. }
  2164. features.body_size = body_size;
  2165. features.body_age = body_age;
  2166. info_changed = true;
  2167. changed = true;
  2168. }
  2169. void Entity::AddSkillBonus(int32 spell_id, int32 skill_id, float value) {
  2170. // handled in npc or player
  2171. return;
  2172. }
  2173. void Entity::HaltMovement()
  2174. {
  2175. this->ClearRunningLocations();
  2176. if (GetZone())
  2177. GetZone()->movementMgr->StopNavigation(this);
  2178. RunToLocation(GetX(), GetY(), GetZ());
  2179. }