Entity.cpp 73 KB

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