Entity.cpp 76 KB

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