9
3

Entity.cpp 76 KB

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