Entity.cpp 76 KB

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