9
3

Entity.cpp 73 KB

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