Entity.cpp 72 KB

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