Entity.cpp 73 KB

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