Entity.cpp 72 KB

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