Combat.cpp 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548
  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 "Combat.h"
  17. #include "client.h"
  18. #include "../common/ConfigReader.h"
  19. #include "classes.h"
  20. #include "../common/debug.h"
  21. #include "../common/Log.h"
  22. #include "zoneserver.h"
  23. #include "Skills.h"
  24. #include "classes.h"
  25. #include "World.h"
  26. #include "LuaInterface.h"
  27. #include "Rules/Rules.h"
  28. #include "SpellProcess.h"
  29. #include "World.h"
  30. #include <math.h>
  31. extern Classes classes;
  32. extern ConfigReader configReader;
  33. extern MasterSkillList master_skill_list;
  34. extern RuleManager rule_manager;
  35. extern LuaInterface* lua_interface;
  36. extern World world;
  37. /* ******************************************************************************
  38. DamageSpawn() - Damage equation
  39. MeleeAttack() - Melee auto attacks
  40. RangeAttack() - Range auto attacks
  41. DetermineHit() - ToHit chance as well as defender parry / dodge / block / riposte
  42. CheckInterruptSpell() - Interrupt equations
  43. No mitigation equations yet
  44. ****************************************************************************** */
  45. /* New Combat code */
  46. bool Entity::PrimaryWeaponReady() {
  47. //Can only be ready if no ranged timer
  48. if (GetPrimaryLastAttackTime() == 0 || (Timer::GetCurrentTime2() >= (GetPrimaryLastAttackTime() + GetPrimaryAttackDelay()))) {
  49. if (GetRangeLastAttackTime() == 0 || Timer::GetCurrentTime2() >= (GetRangeLastAttackTime() + GetRangeAttackDelay()))
  50. return true;
  51. }
  52. return false;
  53. }
  54. bool Entity::SecondaryWeaponReady() {
  55. //Can only be ready if no ranged timer
  56. // if(IsDualWield() && (GetPrimaryLastAttackTime()
  57. if (IsDualWield() && (GetSecondaryLastAttackTime() == 0 || (Timer::GetCurrentTime2() >= (GetSecondaryLastAttackTime() + GetSecondaryAttackDelay())))) {
  58. if(GetRangeLastAttackTime() == 0 || Timer::GetCurrentTime2() >= (GetRangeLastAttackTime() + GetRangeAttackDelay()))
  59. return true;
  60. }
  61. return false;
  62. }
  63. bool Entity::RangeWeaponReady() {
  64. //Ranged can only be ready if no other attack timers are active
  65. if(GetRangeLastAttackTime() == 0 || (Timer::GetCurrentTime2() >= (GetRangeLastAttackTime() + GetRangeAttackDelay()))) {
  66. if((GetPrimaryLastAttackTime() == 0 || (Timer::GetCurrentTime2() >= (GetPrimaryLastAttackTime() + GetPrimaryAttackDelay()))) && (GetSecondaryLastAttackTime() == 0 || Timer::GetCurrentTime2() >= (GetSecondaryLastAttackTime() + GetSecondaryAttackDelay()))){
  67. if(!IsPlayer() || ((Player*)this)->GetRangeAttack()) {
  68. return true;
  69. }
  70. }
  71. }
  72. return false;
  73. }
  74. bool Entity::AttackAllowed(Entity* target, float distance, bool range_attack) {
  75. Entity* attacker = this;
  76. Client* client = 0;
  77. if(!target || IsMezzedOrStunned() || IsDazed()) {
  78. LogWrite(COMBAT__DEBUG, 3, "AttackAllowed", "Failed to attack: no target, mezzed, stunned or dazed");
  79. return false;
  80. }
  81. if (IsPlayer())
  82. client = GetZone()->GetClientBySpawn(this);
  83. if (IsPet())
  84. attacker = ((NPC*)this)->GetOwner();
  85. if (target->IsNPC() && ((NPC*)target)->IsPet()){
  86. if (((NPC*)target)->GetOwner())
  87. target = ((NPC*)target)->GetOwner();
  88. }
  89. if (attacker == target) {
  90. LogWrite(COMBAT__DEBUG, 3, "AttackAllowed", "Failed to attack: attacker tried to attack himself or his pet.");
  91. return false;
  92. }
  93. if (IsPlayer() && target->GetAttackable() == 0) {
  94. LogWrite(COMBAT__DEBUG, 3, "AttackAllowed", "Failed to attack: target is not attackable");
  95. return false;
  96. }
  97. if (IsPlayer() && target->IsBot()) {
  98. LogWrite(COMBAT__DEBUG, 3, "AttackAllowed", "Failed to attack: players are not allowed to attack bots");
  99. return false;
  100. }
  101. if (attacker->IsPlayer() && target->IsPlayer())
  102. {
  103. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  104. if (!pvp_allowed) {
  105. LogWrite(COMBAT__DEBUG, 3, "AttackAllowed", "Failed to attack: pvp is not allowed");
  106. return false;
  107. }
  108. else
  109. {
  110. sint32 pvpLevelRange = rule_manager.GetGlobalRule(R_PVP, LevelRange)->GetSInt32();
  111. int32 attackerLevel = attacker->GetLevel();
  112. int32 defenderLevel = target->GetLevel();
  113. if ((sint32)abs((sint32)attackerLevel - (sint32)defenderLevel) > pvpLevelRange)
  114. {
  115. LogWrite(COMBAT__DEBUG, 3, "AttackAllowed", "Failed to attack: pvp range of %i exceeded abs(%i-%i).", pvpLevelRange, attackerLevel, defenderLevel);
  116. return false;
  117. }
  118. }
  119. }
  120. if (target->GetHP() <= 0) {
  121. LogWrite(COMBAT__DEBUG, 3, "AttackAllowed", "Failed to attack: target is dead");
  122. return false;
  123. }
  124. if(range_attack && distance != 0) {
  125. Item* weapon = 0;
  126. Item* ammo = 0;
  127. if(attacker->IsPlayer()) {
  128. weapon = ((Player*)attacker)->GetEquipmentList()->GetItem(EQ2_RANGE_SLOT);
  129. ammo = ((Player*)attacker)->GetEquipmentList()->GetItem(EQ2_AMMO_SLOT);
  130. }
  131. if(weapon && weapon->IsRanged() && ammo && ammo->IsAmmo() && ammo->IsThrown()) {
  132. // Distance is less then min weapon range
  133. if(distance < weapon->ranged_info->range_low) {
  134. if (client)
  135. client->SimpleMessage(CHANNEL_GENERAL_COMBAT, "Your target is too close! Move back!");
  136. LogWrite(COMBAT__DEBUG, 3, "AttackAllowed", "Failed to attack: range attack, target to close");
  137. return false;
  138. }
  139. // Distance is greater then max weapon range
  140. if (distance > (weapon->ranged_info->range_high + ammo->thrown_info->range)) {
  141. if (client)
  142. client->SimpleMessage(CHANNEL_GENERAL_COMBAT, "Your target is too far away! Move closer!");
  143. LogWrite(COMBAT__DEBUG, 3, "AttackAllowed", "Failed to attack: range attack, target is to far");
  144. return false;
  145. }
  146. }
  147. }
  148. else if (distance != 0) {
  149. if(distance >= rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat()) {
  150. LogWrite(COMBAT__DEBUG, 3, "AttackAllowed", "Failed to attack: distance is beyond melee range");
  151. return false;
  152. }
  153. }
  154. LogWrite(MISC__TODO, 3, "TODO", "Add more AttackAllowed calculations\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  155. return true;
  156. }
  157. void Entity::MeleeAttack(Spawn* victim, float distance, bool primary, bool multi_attack) {
  158. if(!victim)
  159. return;
  160. int8 damage_type = 0;
  161. int32 min_damage = 0;
  162. int32 max_damage = 0;
  163. if(primary) {
  164. damage_type = GetPrimaryWeaponType();
  165. min_damage = GetPrimaryWeaponMinDamage();
  166. max_damage = GetPrimaryWeaponMaxDamage();
  167. }
  168. else {
  169. damage_type = GetSecondaryWeaponType();
  170. min_damage = GetSecondaryWeaponMinDamage();
  171. max_damage = GetSecondaryWeaponMaxDamage();
  172. }
  173. if (IsStealthed() || IsInvis())
  174. CancelAllStealth();
  175. int8 hit_result = DetermineHit(victim, damage_type, 0, false);
  176. if(hit_result == DAMAGE_PACKET_RESULT_SUCCESSFUL){
  177. /*if(GetAdventureClass() == MONK){
  178. max_damage*=3;
  179. crit_chance = GetLevel()/4+5;
  180. }
  181. else if(GetAdventureClass() == BRUISER){
  182. min_damage = GetLevel();
  183. max_damage*=3;
  184. crit_chance = GetLevel()/3+5;
  185. }
  186. if(rand()%100 <=crit_chance){
  187. max_damage*= 2;
  188. DamageSpawn((Entity*)victim, DAMAGE_PACKET_TYPE_SIMPLE_CRIT_DMG, damage_type, min_damage, max_damage, 0);
  189. }
  190. else*/
  191. DamageSpawn((Entity*)victim, DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE, damage_type, min_damage, max_damage, 0);
  192. if (!multi_attack) {
  193. CheckProcs(PROC_TYPE_OFFENSIVE, victim);
  194. CheckProcs(PROC_TYPE_PHYSICAL_OFFENSIVE, victim);
  195. }
  196. }
  197. else{
  198. GetZone()->SendDamagePacket(this, victim, DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE, hit_result, damage_type, 0, 0);
  199. if(hit_result == DAMAGE_PACKET_RESULT_RIPOSTE && victim->IsEntity())
  200. ((Entity*)victim)->MeleeAttack(this, distance, true);
  201. }
  202. //Multi Attack roll
  203. if(!multi_attack){
  204. float multi_attack = info_struct.get_multi_attack();
  205. if(multi_attack > 0){
  206. float chance = multi_attack;
  207. if (multi_attack > 100){
  208. int8 automatic_multi = (int8)floor((float)(multi_attack / 100));
  209. chance = (multi_attack - (floor((float) ((multi_attack / 100) * 100))));
  210. while(automatic_multi > 0){
  211. MeleeAttack(victim, 100, primary, true);
  212. automatic_multi--;
  213. }
  214. }
  215. if (MakeRandomFloat(0, 100) <= chance)
  216. MeleeAttack(victim, 100, primary, true);
  217. }
  218. }
  219. //Apply attack speed mods
  220. if(!multi_attack)
  221. SetAttackDelay(primary);
  222. if(victim->IsNPC() && victim->EngagedInCombat() == false) {
  223. ((NPC*)victim)->AddHate(this, 50);
  224. }
  225. if (victim->IsEntity() && victim->GetHP() > 0 && ((Entity*)victim)->HasPet()) {
  226. Entity* pet = 0;
  227. bool AddHate = false;
  228. if (victim->IsPlayer()) {
  229. if (((Player*)victim)->GetInfoStruct()->get_pet_behavior() & 1)
  230. AddHate = true;
  231. }
  232. else
  233. AddHate = true;
  234. if (AddHate) {
  235. pet = ((Entity*)victim)->GetPet();
  236. if (pet)
  237. pet->AddHate(this, 1);
  238. pet = ((Entity*)victim)->GetCharmedPet();
  239. if (pet)
  240. pet->AddHate(this, 1);
  241. }
  242. }
  243. }
  244. void Entity::RangeAttack(Spawn* victim, float distance, Item* weapon, Item* ammo, bool multi_attack) {
  245. if(!victim)
  246. return;
  247. if(weapon && weapon->IsRanged() && ammo && ammo->IsAmmo() && ammo->IsThrown()) {
  248. if(weapon->ranged_info->range_low <= distance && (weapon->ranged_info->range_high + ammo->thrown_info->range) >= distance) {
  249. int8 hit_result = DetermineHit(victim, ammo->thrown_info->damage_type, ammo->thrown_info->hit_bonus, false);
  250. if(hit_result == DAMAGE_PACKET_RESULT_SUCCESSFUL) {
  251. DamageSpawn((Entity*)victim, DAMAGE_PACKET_TYPE_RANGE_DAMAGE, ammo->thrown_info->damage_type, weapon->ranged_info->weapon_info.damage_low3, weapon->ranged_info->weapon_info.damage_high3+ammo->thrown_info->damage_modifier, 0);
  252. if (!multi_attack) {
  253. CheckProcs(PROC_TYPE_OFFENSIVE, victim);
  254. CheckProcs(PROC_TYPE_PHYSICAL_OFFENSIVE, victim);
  255. }
  256. }
  257. else
  258. GetZone()->SendDamagePacket(this, victim, DAMAGE_PACKET_TYPE_RANGE_DAMAGE, hit_result, ammo->thrown_info->damage_type, 0, 0);
  259. // If is a player subtract ammo
  260. if (IsPlayer()) {
  261. if (ammo->details.count > 1) {
  262. ammo->details.count -= 1;
  263. ammo->save_needed = true;
  264. }
  265. else
  266. ((Player*)this)->equipment_list.RemoveItem(ammo->details.slot_id, true);
  267. Client* client = GetZone()->GetClientBySpawn(this);
  268. EQ2Packet* outapp = ((Player*)this)->GetEquipmentList()->serialize(client->GetVersion());
  269. if(outapp)
  270. client->QueuePacket(outapp);
  271. }
  272. if(victim->IsNPC() && victim->EngagedInCombat() == false) {
  273. ((NPC*)victim)->AddHate(this, 50);
  274. }
  275. if (victim->IsEntity() && victim->GetHP() > 0 && ((Entity*)victim)->HasPet()) {
  276. Entity* pet = 0;
  277. bool AddHate = false;
  278. if (victim->IsPlayer()) {
  279. if (((Player*)victim)->GetInfoStruct()->get_pet_behavior() & 1)
  280. AddHate = true;
  281. }
  282. else
  283. AddHate = true;
  284. if (AddHate) {
  285. pet = ((Entity*)victim)->GetPet();
  286. if (pet)
  287. pet->AddHate(this, 1);
  288. pet = ((Entity*)victim)->GetCharmedPet();
  289. if (pet)
  290. pet->AddHate(this, 1);
  291. }
  292. }
  293. // Check Ranged attack proc
  294. CheckProcs(PROC_TYPE_RANGED_ATTACK, victim);
  295. // Check Ranged defence proc
  296. if (victim->IsEntity())
  297. ((Entity*)victim)->CheckProcs(PROC_TYPE_RANGED_DEFENSE, this);
  298. SetRangeLastAttackTime(Timer::GetCurrentTime2());
  299. }
  300. }
  301. //Multi Attack roll
  302. if(!multi_attack){
  303. float multi_attack = info_struct.get_multi_attack();
  304. if(multi_attack > 0){
  305. float chance = multi_attack;
  306. if (multi_attack > 100){
  307. int8 automatic_multi = (int8)floor((float)(multi_attack / 100));
  308. chance = (multi_attack - (floor((float)(multi_attack / 100) * 100)));
  309. while(automatic_multi > 0){
  310. RangeAttack(victim, 100, weapon, ammo, true);
  311. automatic_multi--;
  312. }
  313. }
  314. if (MakeRandomFloat(0, 100) <= chance)
  315. RangeAttack(victim, 100, weapon, ammo, true);
  316. }
  317. }
  318. //Apply attack speed mods
  319. if(!multi_attack)
  320. SetAttackDelay(false, true);
  321. }
  322. bool Entity::SpellAttack(Spawn* victim, float distance, LuaSpell* luaspell, int8 damage_type, int32 low_damage, int32 high_damage, int8 crit_mod, bool no_calcs){
  323. if(!victim || !luaspell || !luaspell->spell)
  324. return false;
  325. Spell* spell = luaspell->spell;
  326. float bonus = 0;
  327. Skill* skill = nullptr;
  328. if(spell->GetSpellData()->resistibility > 0)
  329. bonus -= (1 - spell->GetSpellData()->resistibility)*100;
  330. skill = master_skill_list.GetSkill(spell->GetSpellData()->mastery_skill);
  331. if(skill){
  332. skill = GetSkillByName(skill->name.data.c_str(), true);
  333. if(skill)
  334. bonus += skill->current_val / 25;
  335. }
  336. int8 hit_result = 0;
  337. bool is_tick = false; // if spell is already active, this is a tick
  338. if (GetZone()->GetSpellProcess()->GetActiveSpells()->count(luaspell)){
  339. hit_result = DAMAGE_PACKET_RESULT_SUCCESSFUL;
  340. is_tick = true;
  341. }
  342. else if(spell->GetSpellData()->type == SPELL_BOOK_TYPE_COMBAT_ART)
  343. hit_result = DetermineHit(victim, damage_type, 0, false);
  344. else
  345. hit_result = DetermineHit(victim, damage_type, 0, true);
  346. if(hit_result == DAMAGE_PACKET_RESULT_SUCCESSFUL) {
  347. luaspell->last_spellattack_hit = true;
  348. //If this spell is a tick and has already crit, force the tick to crit
  349. if(is_tick){
  350. if(luaspell->crit)
  351. crit_mod = 1;
  352. else
  353. crit_mod = 2;
  354. }
  355. if(DamageSpawn((Entity*)victim, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, damage_type, low_damage, high_damage, spell->GetName(), crit_mod, is_tick, no_calcs) && !luaspell->crit)
  356. luaspell->crit = true;
  357. CheckProcs(PROC_TYPE_OFFENSIVE, victim);
  358. CheckProcs(PROC_TYPE_MAGICAL_OFFENSIVE, victim);
  359. if(spell->GetSpellData()->success_message.length() > 0){
  360. Client* client = nullptr;
  361. if(IsPlayer())
  362. client = GetZone()->GetClientBySpawn(this);
  363. if(client){
  364. string success_message = spell->GetSpellData()->success_message;
  365. if(success_message.find("%t") < 0xFFFFFFFF)
  366. success_message.replace(success_message.find("%t"), 2, victim->GetName());
  367. client->Message(CHANNEL_YOU_CAST, success_message.c_str());
  368. //commented out the following line as it was causing a duplicate message EmemJR 5/4/2019
  369. //GetZone()->SendDamagePacket(this, victim, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, hit_result, damage_type, 0, spell->GetName());
  370. }
  371. }
  372. if(spell->GetSpellData()->effect_message.length() > 0){
  373. string effect_message = spell->GetSpellData()->effect_message;
  374. if(effect_message.find("%t") < 0xFFFFFFFF)
  375. effect_message.replace(effect_message.find("%t"), 2, victim->GetName());
  376. GetZone()->SimpleMessage(CHANNEL_SPELLS, effect_message.c_str(), victim, 50);
  377. }
  378. }
  379. else {
  380. if(hit_result == DAMAGE_PACKET_RESULT_RESIST)
  381. luaspell->resisted = true;
  382. if(victim->IsNPC())
  383. ((NPC*)victim)->AddHate(this, 5);
  384. luaspell->last_spellattack_hit = false;
  385. GetZone()->SendDamagePacket(this, victim, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, hit_result, damage_type, 0, spell->GetName());
  386. }
  387. if(EngagedInCombat() == false)
  388. {
  389. LogWrite(MISC__TODO, 1, "TODO", "//It would probably be better to add a column to the spells table for 'starts autoattack'\nfile: %s, func: %s, Line: %i", __FILE__, __FUNCTION__, __LINE__);
  390. int8 class1_ = GetInfoStruct()->get_class1();
  391. if(class1_ == COMMONER ||
  392. class1_ == FIGHTER ||
  393. class1_ == WARRIOR ||
  394. class1_ == GUARDIAN ||
  395. class1_ == BERSERKER ||
  396. class1_ == BRAWLER ||
  397. class1_ == MONK ||
  398. class1_ == BRUISER ||
  399. class1_ == CRUSADER ||
  400. class1_ == SHADOWKNIGHT ||
  401. class1_ == PALADIN ||
  402. class1_ == SCOUT ||
  403. class1_ == ROGUE ||
  404. class1_ == SWASHBUCKLER ||
  405. class1_ == BRIGAND ||
  406. class1_ == BARD ||
  407. class1_ == TROUBADOR ||
  408. class1_ == DIRGE ||
  409. class1_ == PREDATOR ||
  410. class1_ == RANGER ||
  411. class1_ == ASSASSIN ||
  412. class1_ == ANIMALIST ||
  413. class1_ == BEASTLORD ||
  414. class1_ == SHAPER ||
  415. class1_ == CHANNELER) //note: it would probably be better to add a column to the spells table for "starts autoattack".
  416. {
  417. if (victim->IsNPC())
  418. ((NPC*)victim)->AddHate(this, 5);
  419. else
  420. InCombat(true);
  421. }
  422. }
  423. if (victim->IsEntity() && victim->GetHP() > 0 && ((Entity*)victim)->HasPet()) {
  424. Entity* pet = 0;
  425. bool AddHate = false;
  426. if (victim->IsPlayer()) {
  427. if (((Player*)victim)->GetInfoStruct()->get_pet_behavior() & 1)
  428. AddHate = true;
  429. }
  430. else
  431. AddHate = true;
  432. if (AddHate) {
  433. pet = ((Entity*)victim)->GetPet();
  434. if (pet)
  435. pet->AddHate(this, 1);
  436. pet = ((Entity*)victim)->GetCharmedPet();
  437. if (pet)
  438. pet->AddHate(this, 1);
  439. }
  440. }
  441. return true;
  442. }
  443. bool Entity::ProcAttack(Spawn* victim, int8 damage_type, int32 low_damage, int32 high_damage, string name, string success_msg, string effect_msg) {
  444. int8 hit_result = DetermineHit(victim, damage_type, 0, true);
  445. if (hit_result == DAMAGE_PACKET_RESULT_SUCCESSFUL) {
  446. DamageSpawn((Entity*)victim, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, damage_type, low_damage, high_damage, name.c_str());
  447. if (success_msg.length() > 0) {
  448. Client* client = 0;
  449. if(IsPlayer())
  450. client = GetZone()->GetClientBySpawn(this);
  451. if(client) {
  452. if(success_msg.find("%t") < 0xFFFFFFFF)
  453. success_msg.replace(success_msg.find("%t"), 2, victim->GetName());
  454. client->Message(CHANNEL_YOU_CAST, success_msg.c_str());
  455. }
  456. }
  457. if (effect_msg.length() > 0) {
  458. if(effect_msg.find("%t") < 0xFFFFFFFF)
  459. effect_msg.replace(effect_msg.find("%t"), 2, victim->GetName());
  460. GetZone()->SimpleMessage(CHANNEL_SPELLS, effect_msg.c_str(), victim, 50);
  461. }
  462. }
  463. else {
  464. if(victim->IsNPC())
  465. ((NPC*)victim)->AddHate(this, 5);
  466. GetZone()->SendDamagePacket(this, victim, DAMAGE_PACKET_TYPE_SPELL_DAMAGE, hit_result, damage_type, 0, name.c_str());
  467. }
  468. if (victim->IsEntity() && victim->GetHP() > 0 && ((Entity*)victim)->HasPet()) {
  469. Entity* pet = 0;
  470. bool AddHate = false;
  471. if (victim->IsPlayer()) {
  472. if (((Player*)victim)->GetInfoStruct()->get_pet_behavior() & 1)
  473. AddHate = true;
  474. }
  475. else
  476. AddHate = true;
  477. if (AddHate) {
  478. pet = ((Entity*)victim)->GetPet();
  479. if (pet)
  480. pet->AddHate(this, 1);
  481. pet = ((Entity*)victim)->GetCharmedPet();
  482. if (pet)
  483. pet->AddHate(this, 1);
  484. }
  485. }
  486. return true;
  487. }
  488. // this is used exclusively by LUA, heal_type is forced lower case via boost::lower(heal_type); in the LUA Functions used by this
  489. bool Entity::SpellHeal(Spawn* target, float distance, LuaSpell* luaspell, string heal_type, int32 low_heal, int32 high_heal, int8 crit_mod, bool no_calcs, string custom_spell_name){
  490. if(!target || !luaspell || !luaspell->spell)
  491. return false;
  492. if (!target->Alive())
  493. return false;
  494. if (target->GetHP() == target->GetTotalHP())
  495. return true;
  496. int32 heal_amt = 0;
  497. bool crit = false;
  498. if(high_heal < low_heal)
  499. high_heal = low_heal;
  500. if(high_heal == low_heal)
  501. heal_amt = high_heal;
  502. else
  503. heal_amt = MakeRandomInt(low_heal, high_heal);
  504. if(!no_calcs){
  505. // if spell is already active, this is a tick
  506. bool is_tick = GetZone()->GetSpellProcess()->GetActiveSpells()->count(luaspell);
  507. //if is a tick and the spell has crit, force crit, else disable
  508. if(is_tick){
  509. if(luaspell->crit)
  510. crit_mod = 1;
  511. else
  512. crit_mod = 2;
  513. }
  514. if (heal_amt > 0){
  515. //int32 base_roll = heal_amt;
  516. //potency mod
  517. MStats.lock();
  518. heal_amt *= (stats[ITEM_STAT_POTENCY] / 100 + 1);
  519. MStats.unlock();
  520. //primary stat mod, insert forula here when done
  521. //heal_amt += base_roll * (GetPrimaryStat()
  522. //Ability Modifier can only be up to half of base roll + potency and primary stat bonus
  523. heal_amt += (int32)min(info_struct.get_ability_modifier(), (float)(heal_amt / 2));
  524. }
  525. if(!crit_mod || crit_mod == 1){
  526. if(crit_mod == 1)
  527. crit = true;
  528. else {
  529. // Crit Roll
  530. float chance = max((float)0, info_struct.get_crit_chance());
  531. crit = (MakeRandomFloat(0, 100) <= chance);
  532. }
  533. if(crit){
  534. //Apply total crit multiplier with crit bonus
  535. heal_amt *= (info_struct.get_crit_bonus() / 100) + 1.3;
  536. if(luaspell->spell)
  537. luaspell->crit = true;
  538. }
  539. }
  540. }
  541. int16 type = 0;
  542. if (heal_type == "heal") {
  543. if(crit)
  544. type = HEAL_PACKET_TYPE_CRIT_HEAL;
  545. else
  546. type = HEAL_PACKET_TYPE_SIMPLE_HEAL;
  547. //apply heal
  548. if (target->GetHP() + (sint32)heal_amt > target->GetTotalHP())
  549. heal_amt = target->GetTotalHP() - target->GetHP();
  550. target->SetHP(target->GetHP() + heal_amt);
  551. /*
  552. if (target->GetHP() + (sint32)heal_amt > target->GetTotalHP())
  553. target->SetHP(target->GetTotalHP());
  554. else
  555. target->SetHP(target->GetHP() + heal_amt);
  556. */
  557. }
  558. else if (heal_type == "power"){
  559. if(crit)
  560. type = HEAL_PACKET_TYPE_CRIT_MANA;
  561. else
  562. type = HEAL_PACKET_TYPE_SIMPLE_MANA;
  563. //give power
  564. if (target->GetPower() + (sint32)heal_amt > target->GetTotalPower())
  565. heal_amt = target->GetTotalPower() - target->GetPower();
  566. target->SetPower(GetPower() + heal_amt);
  567. /*
  568. if (target->GetPower() + (sint32)heal_amt > target->GetTotalPower())
  569. target->SetPower(target->GetTotalPower());
  570. else
  571. target->SetPower(GetPower() + heal_amt);
  572. */
  573. }
  574. /*else if (heal_type == "Savagery"){
  575. if(crit)
  576. type = HEAL_PACKET_TYPE_CRIT_SAVAGERY;
  577. else
  578. type = HEAL_PACKET_TYPE_SAVAGERY;
  579. }
  580. else if (heal_type == "Repair"){
  581. if(crit)
  582. type = HEAL_PACKET_TYPE_CRIT_REPAIR;
  583. else
  584. type = HEAL_PACKET_TYPE_REPAIR;
  585. }*/
  586. else{ //default to heal if type cannot be determined
  587. if(crit)
  588. type = HEAL_PACKET_TYPE_CRIT_HEAL;
  589. else
  590. type = HEAL_PACKET_TYPE_SIMPLE_HEAL;
  591. if (target->GetHP() + (sint32)heal_amt > target->GetTotalHP())
  592. heal_amt = target->GetTotalHP() - target->GetHP();
  593. target->SetHP(target->GetHP() + heal_amt);
  594. /*
  595. if (target->GetHP() + (sint32)heal_amt > target->GetTotalHP())
  596. target->SetHP(target->GetTotalHP());
  597. else
  598. target->SetHP(target->GetHP() + heal_amt);
  599. */
  600. }
  601. target->GetZone()->TriggerCharSheetTimer();
  602. if (heal_amt > 0)
  603. GetZone()->SendHealPacket(this, target, type, heal_amt, custom_spell_name.length() > 0 ? (char*)custom_spell_name.c_str() : luaspell->spell->GetName());
  604. CheckProcs(PROC_TYPE_HEALING, target);
  605. CheckProcs(PROC_TYPE_BENEFICIAL, target);
  606. if (target->IsEntity()) {
  607. int32 hate_amt = heal_amt / 2;
  608. set<int32>::iterator itr;
  609. ((Entity*)target)->MHatedBy.lock();
  610. for (itr = ((Entity*)target)->HatedBy.begin(); itr != ((Entity*)target)->HatedBy.end(); itr++) {
  611. Spawn* spawn = GetZone()->GetSpawnByID(*itr);
  612. if (spawn && spawn->IsEntity() && target != this) {
  613. ((Entity*)spawn)->AddHate(this, hate_amt);
  614. }
  615. }
  616. ((Entity*)target)->MHatedBy.unlock();
  617. }
  618. return true;
  619. }
  620. int8 Entity::DetermineHit(Spawn* victim, int8 damage_type, float ToHitBonus, bool spell){
  621. if(!victim) {
  622. return DAMAGE_PACKET_RESULT_MISS;
  623. }
  624. if(victim->GetInvulnerable()) {
  625. return DAMAGE_PACKET_RESULT_INVULNERABLE;
  626. }
  627. bool behind = false;
  628. // Monk added with Brawler to 360 degree support per KoS Prima Official eGuide Fighter: Monk, pg 138, denoted '360-Degree Avoidance!'
  629. if(!victim->IsEntity() || (!spell && victim->GetAdventureClass() != BRAWLER && victim->GetAdventureClass() != MONK && (behind = BehindTarget(victim)))) {
  630. return DAMAGE_PACKET_RESULT_SUCCESSFUL;
  631. }
  632. float bonus = ToHitBonus;
  633. Skill* skill = GetSkillByWeaponType(damage_type, true);
  634. float skillAddedByWeapon = 0.0f;
  635. if(skill)
  636. {
  637. int16 skillID = master_item_list.GetItemStatIDByName(skill->name.data);
  638. if(skillID != 0xFFFFFFFF)
  639. {
  640. MStats.lock();
  641. skillAddedByWeapon = stats[skillID];
  642. MStats.unlock();
  643. }
  644. }
  645. if (skill)
  646. bonus += (skill->current_val+skillAddedByWeapon) / 25;
  647. if (victim->IsEntity())
  648. bonus -= ((Entity*)victim)->GetDamageTypeResistPercentage(damage_type);
  649. Entity* entity_victim = (Entity*)victim;
  650. float chance = 80 + bonus; //80% base chance that the victim will get hit (plus bonus)
  651. sint16 roll_chance = 100;
  652. if(skill)
  653. roll_chance -= skill->current_val / 25;
  654. if(!spell){ // melee or range attack
  655. skill = GetSkillByName("Offense", true); //add this skill for NPCs
  656. if(skill)
  657. roll_chance -= skill->current_val / 25;
  658. if(entity_victim->IsImmune(IMMUNITY_TYPE_RIPOSTE))
  659. return DAMAGE_PACKET_RESULT_RIPOSTE;
  660. // Avoidance Instructions: https://forums.daybreakgames.com/eq2/index.php?threads/avoidance-faq.482979/
  661. /*Parry: reads as parry in the avoidance tooltip, increased by items with +parry on them
  662. Caps at 70%. For plate tanks, works in the front quadrant only, for brawlers this is 360 degrees.
  663. A small % of parries will be ripostes, which not only avoid the attack but also damage your attacker
  664. */
  665. skill = entity_victim->GetSkillByName("Parry", true);
  666. if(skill){
  667. float parryChance = entity_victim->GetInfoStruct()->get_parry();
  668. float chanceValue = (100.0f - parryChance);
  669. if(rand()%roll_chance >= chanceValue){ //successful parry
  670. /* You may only riposte things in the front quadrant.
  671. Riposte is based off of parry: a certain % of parries turn into ripostes.
  672. */
  673. if(!behind && victim->InFrontSpawn((Spawn*)this, victim->GetX(), victim->GetZ())) { // if the attacker is not behind the victim, and the victim is facing the attacker (in front of spawn) then we can riposte
  674. float riposteChanceValue = parryChance / 7.0f; // Riposte is based off of parry: a certain % of parries turn into ripostes. Unknown what the value is divided by, 7 to make it 10% even.
  675. if(rand()%100 <= riposteChanceValue) {
  676. entity_victim->CheckProcs(PROC_TYPE_RIPOSTE, this);
  677. return DAMAGE_PACKET_RESULT_RIPOSTE;
  678. }
  679. }
  680. entity_victim->CheckProcs(PROC_TYPE_PARRY, this);
  681. return DAMAGE_PACKET_RESULT_PARRY;
  682. }
  683. }
  684. skill = nullptr;
  685. float blockChance = 0.0f;
  686. if(victim->GetAdventureClass() == BRAWLER)
  687. skill = entity_victim->GetSkillByName("Deflection", true);
  688. blockChance = entity_victim->GetInfoStruct()->get_block();
  689. if(blockChance > 0.0f)
  690. {
  691. blockChance += (blockChance*(entity_victim->GetInfoStruct()->get_block_chance()/100.0f));
  692. float chanceValue = (100.0f - blockChance);
  693. /* Non-brawlers may only block things in the front quadrant.
  694. Riposte is based off of parry: a certain % of parries turn into ripostes.
  695. */
  696. float rnd = rand()%roll_chance;
  697. if(rnd >= chanceValue){ //successful block
  698. if((victim->GetAdventureClass() == BRAWLER || victim->GetAdventureClass() == MONK) || (!behind && victim->InFrontSpawn((Spawn*)this, victim->GetX(), victim->GetZ()))) { // if the attacker is not behind the victim, and the victim is facing the attacker (in front of spawn) then we can block
  699. entity_victim->CheckProcs(PROC_TYPE_BLOCK, this);
  700. return (victim->GetAdventureClass() == BRAWLER) ? DAMAGE_PACKET_RESULT_DEFLECT : DAMAGE_PACKET_RESULT_BLOCK;
  701. }
  702. }
  703. }
  704. skill = entity_victim->GetSkillByName("Defense", true);
  705. float dodgeChance = entity_victim->GetInfoStruct()->get_avoidance_base();
  706. if(dodgeChance > 0.0f)
  707. {
  708. float chanceValue = (100.0f - dodgeChance);
  709. float rnd = rand()%roll_chance;
  710. if(rnd >= chanceValue){ //successful dodge
  711. entity_victim->CheckProcs(PROC_TYPE_EVADE, this);
  712. return DAMAGE_PACKET_RESULT_DODGE;//successfully dodged
  713. }
  714. }
  715. if(rand() % roll_chance >= chance)
  716. return DAMAGE_PACKET_RESULT_MISS; //successfully avoided
  717. }
  718. else{
  719. skill = entity_victim->GetSkillByName("Spell Avoidance", true);
  720. if(skill)
  721. chance -= skill->current_val / 25;
  722. if(rand()%roll_chance >= chance) {
  723. return DAMAGE_PACKET_RESULT_RESIST; //successfully resisted
  724. }
  725. }
  726. return DAMAGE_PACKET_RESULT_SUCCESSFUL;
  727. }
  728. float Entity::GetDamageTypeResistPercentage(int8 damage_type) {
  729. float ret = 1;
  730. switch(damage_type) {
  731. case DAMAGE_PACKET_DAMAGE_TYPE_CRUSH:
  732. case DAMAGE_PACKET_DAMAGE_TYPE_PIERCE:
  733. case DAMAGE_PACKET_DAMAGE_TYPE_SLASH: {
  734. Skill* skill = GetSkillByName("Defense", true);
  735. if(skill)
  736. ret += skill->current_val / 25;
  737. if(IsNPC())
  738. LogWrite(COMBAT__DEBUG, 3, "Combat", "DamageType: Crush/Pierce/Slash (%i)", damage_type, ret);
  739. break;
  740. }
  741. case DAMAGE_PACKET_DAMAGE_TYPE_HEAT: {
  742. ret += GetInfoStruct()->get_heat() / 50;
  743. LogWrite(COMBAT__DEBUG, 3, "Combat", "DamageType: Heat (%i), Amt: %.2f", damage_type, ret);
  744. break;
  745. }
  746. case DAMAGE_PACKET_DAMAGE_TYPE_COLD: {
  747. ret += GetInfoStruct()->get_cold() / 50;
  748. LogWrite(COMBAT__DEBUG, 3, "Combat", "DamageType: Cold (%i), Amt: %.2f", damage_type, ret);
  749. break;
  750. }
  751. case DAMAGE_PACKET_DAMAGE_TYPE_MAGIC: {
  752. ret += GetInfoStruct()->get_magic() / 50;
  753. LogWrite(COMBAT__DEBUG, 3, "Combat", "DamageType: Magic (%i), Amt: %.2f", damage_type, ret);
  754. break;
  755. }
  756. case DAMAGE_PACKET_DAMAGE_TYPE_MENTAL: {
  757. ret += GetInfoStruct()->get_mental() / 50;
  758. LogWrite(COMBAT__DEBUG, 3, "Combat", "DamageType: Mental (%i), Amt: %.2f", damage_type, ret);
  759. break;
  760. }
  761. case DAMAGE_PACKET_DAMAGE_TYPE_DIVINE: {
  762. ret += GetInfoStruct()->get_divine() / 50;
  763. LogWrite(COMBAT__DEBUG, 3, "Combat", "DamageType: Divine (%i), Amt: %.2f", damage_type, ret);
  764. break;
  765. }
  766. case DAMAGE_PACKET_DAMAGE_TYPE_DISEASE: {
  767. ret += GetInfoStruct()->get_disease() / 50;
  768. LogWrite(COMBAT__DEBUG, 3, "Combat", "DamageType: Disease (%i), Amt: %.2f", damage_type, ret);
  769. break;
  770. }
  771. case DAMAGE_PACKET_DAMAGE_TYPE_POISON: {
  772. ret += GetInfoStruct()->get_poison() / 50;
  773. LogWrite(COMBAT__DEBUG, 3, "Combat", "DamageType: Poison (%i), Amt: %.2f", damage_type, ret);
  774. break;
  775. }
  776. }
  777. return ret;
  778. }
  779. Skill* Entity::GetSkillByWeaponType(int8 type, bool update) {
  780. switch(type) {
  781. case DAMAGE_PACKET_DAMAGE_TYPE_SLASH: // slash
  782. return GetSkillByName("Slashing", update);
  783. case DAMAGE_PACKET_DAMAGE_TYPE_CRUSH: // crush
  784. return GetSkillByName("Crushing", update);
  785. case DAMAGE_PACKET_DAMAGE_TYPE_PIERCE: // pierce
  786. return GetSkillByName("Piercing", update);
  787. case DAMAGE_PACKET_DAMAGE_TYPE_HEAT:
  788. case DAMAGE_PACKET_DAMAGE_TYPE_COLD:
  789. case DAMAGE_PACKET_DAMAGE_TYPE_MAGIC:
  790. case DAMAGE_PACKET_DAMAGE_TYPE_MENTAL:
  791. case DAMAGE_PACKET_DAMAGE_TYPE_DIVINE:
  792. case DAMAGE_PACKET_DAMAGE_TYPE_DISEASE:
  793. case DAMAGE_PACKET_DAMAGE_TYPE_POISON:
  794. return GetSkillByName("Disruption", update);
  795. }
  796. return 0;
  797. }
  798. bool Entity::DamageSpawn(Entity* victim, int8 type, int8 damage_type, int32 low_damage, int32 high_damage, const char* spell_name, int8 crit_mod, bool is_tick, bool no_calcs, bool ignore_attacker) {
  799. if(!victim || victim->GetHP() == 0)
  800. return false;
  801. int8 hit_result = 0;
  802. int16 blow_type = 0;
  803. sint32 damage = 0;
  804. bool crit = false;
  805. if(low_damage > high_damage)
  806. high_damage = low_damage;
  807. if(low_damage == high_damage)
  808. damage = low_damage;
  809. else
  810. damage = MakeRandomInt(low_damage, high_damage);
  811. if(!no_calcs) {
  812. //this can be simplified by taking out the / 2, but I wanted the damage to be more consistent
  813. //damage = (rand()%((int)(high_damage/2-low_damage/2) + low_damage/2)) + (rand()%((int)(high_damage/2-low_damage/2) + low_damage/2));
  814. //damage = (rand()%((int)(high_damage-low_damage) + low_damage)) + (rand()%((int)(high_damage-low_damage) + low_damage));
  815. //DPS mod is only applied to auto attacks
  816. if (type == DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE || type == DAMAGE_PACKET_TYPE_RANGE_DAMAGE ) {
  817. damage *= (info_struct.get_dps_multiplier());
  818. }
  819. //Potency and ability mod is only applied to spells/CAs
  820. else {
  821. // Potency mod
  822. MStats.lock();
  823. damage *= ((stats[ITEM_STAT_POTENCY] / 100) + 1);
  824. MStats.unlock();
  825. // Ability mod can only give up to half of damage after potency
  826. int32 mod = (int32)min(info_struct.get_ability_modifier(), (float)(damage / 2));
  827. damage += mod;
  828. }
  829. if(!crit_mod || crit_mod == 1){
  830. //force crit if crit_mod == 1
  831. if(crit_mod == 1)
  832. crit = true;
  833. // Crit Roll
  834. else {
  835. victim->MStats.lock();
  836. float chance = max((float)0, (info_struct.get_crit_chance() - victim->stats[ITEM_STAT_CRITAVOIDANCE]));
  837. victim->MStats.unlock();
  838. if (MakeRandomFloat(0, 100) <= chance)
  839. crit = true;
  840. }
  841. if(crit){
  842. //Apply total crit multiplier with crit bonus
  843. if(info_struct.get_crit_bonus() > 0)
  844. damage *= (1.3 + (info_struct.get_crit_bonus() / 100));
  845. else
  846. damage *= 1.3;
  847. // Change packet type to crit
  848. if (type == DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE)
  849. type = DAMAGE_PACKET_TYPE_SIMPLE_CRIT_DMG;
  850. else if (type == DAMAGE_PACKET_TYPE_SPELL_DAMAGE)
  851. type = DAMAGE_PACKET_TYPE_SPELL_CRIT_DMG;
  852. }
  853. }
  854. // TODO: Mitigation equation from http://www.guildportal.com/Guild.aspx?GuildID=20881&TabID=189653&ForumID=95908&TopicID=9024250
  855. }
  856. LogWrite(MISC__TODO, 3, "TODO", "Take players armor into account\nfile: %s, func: %s, line: %i)", __FILE__, __FUNCTION__, __LINE__);
  857. bool useWards = false;
  858. if(damage <= 0){
  859. hit_result = DAMAGE_PACKET_RESULT_NO_DAMAGE;
  860. damage = 0;
  861. }
  862. else{
  863. hit_result = DAMAGE_PACKET_RESULT_SUCCESSFUL;
  864. GetZone()->CallSpawnScript(victim, SPAWN_SCRIPT_HEALTHCHANGED, this);
  865. int32 prevDmg = damage;
  866. damage = victim->CheckWards(this, damage, damage_type);
  867. if (damage < (sint64)prevDmg)
  868. useWards = true;
  869. victim->TakeDamage(damage);
  870. victim->CheckProcs(PROC_TYPE_DAMAGED, this);
  871. if (IsPlayer()) {
  872. switch (damage_type) {
  873. case DAMAGE_PACKET_DAMAGE_TYPE_SLASH:
  874. case DAMAGE_PACKET_DAMAGE_TYPE_CRUSH:
  875. case DAMAGE_PACKET_DAMAGE_TYPE_PIERCE:
  876. if (((Player*)this)->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_MELEE_HIT) < damage)
  877. ((Player*)this)->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_MELEE_HIT, damage, true);
  878. victim->CheckProcs(PROC_TYPE_DAMAGED_MELEE, this);
  879. break;
  880. case DAMAGE_PACKET_DAMAGE_TYPE_HEAT:
  881. case DAMAGE_PACKET_DAMAGE_TYPE_COLD:
  882. case DAMAGE_PACKET_DAMAGE_TYPE_MAGIC:
  883. case DAMAGE_PACKET_DAMAGE_TYPE_MENTAL:
  884. case DAMAGE_PACKET_DAMAGE_TYPE_DIVINE:
  885. case DAMAGE_PACKET_DAMAGE_TYPE_DISEASE:
  886. case DAMAGE_PACKET_DAMAGE_TYPE_POISON:
  887. if (((Player*)this)->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_MAGIC_HIT) < damage)
  888. ((Player*)this)->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_MAGIC_HIT, damage, true);
  889. victim->CheckProcs(PROC_TYPE_DAMAGED_MAGIC, this);
  890. break;
  891. }
  892. }
  893. }
  894. if(victim->IsNPC() && victim->GetHP() > 0)
  895. ((Entity*)victim)->AddHate(this, damage);
  896. Entity* attacker = nullptr;
  897. if(!ignore_attacker)
  898. attacker = this;
  899. if (damage > 0) {
  900. GetZone()->SendDamagePacket(attacker, victim, type, hit_result, damage_type, damage, spell_name);
  901. if (IsStealthed() || IsInvis())
  902. CancelAllStealth();
  903. if (victim->IsEntity())
  904. ((Entity*)victim)->CheckInterruptSpell(this);
  905. }
  906. else if (useWards)
  907. {
  908. GetZone()->SendDamagePacket(attacker, victim, DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE, DAMAGE_PACKET_RESULT_NO_DAMAGE, damage_type, 0, spell_name);
  909. }
  910. if (victim->GetHP() <= 0)
  911. KillSpawn(victim, damage_type, blow_type);
  912. else {
  913. victim->CheckProcs(PROC_TYPE_DEFENSIVE, this);
  914. if (spell_name)
  915. victim->CheckProcs(PROC_TYPE_MAGICAL_DEFENSIVE, this);
  916. else
  917. victim->CheckProcs(PROC_TYPE_PHYSICAL_DEFENSIVE, this);
  918. }
  919. return crit;
  920. }
  921. void Entity::AddHate(Entity* attacker, sint32 hate) {
  922. if(!attacker || GetHP() <= 0 || attacker->GetHP() <= 0)
  923. return;
  924. // If a players pet and protect self is off
  925. if (IsPet() && ((NPC*)this)->GetOwner()->IsPlayer() && ((((Player*)((NPC*)this)->GetOwner())->GetInfoStruct()->get_pet_behavior() & 2) == 0))
  926. return;
  927. if (IsNPC()) {
  928. LogWrite(COMBAT__DEBUG, 3, "Combat", "Add NPC_AI Hate: Victim '%s', Attacker '%s', Hate: %i", GetName(), attacker->GetName(), hate);
  929. ((NPC*)this)->Brain()->AddHate(attacker, hate);
  930. // if encounter size is 0 then add the attacker to the encounter
  931. if (((NPC*)this)->Brain()->GetEncounterSize() == 0)
  932. ((NPC*)this)->Brain()->AddToEncounter(attacker);
  933. }
  934. if (attacker->GetThreatTransfer() && hate > 0) {
  935. Spawn* transfer_target = (Entity*)GetZone()->GetSpawnByID(attacker->GetThreatTransfer()->Target);
  936. if (transfer_target && transfer_target->IsEntity()) {
  937. sint32 transfered_hate = hate * (attacker->GetThreatTransfer()->Amount / 100);
  938. hate -= transfered_hate;
  939. this->AddHate((Entity*)transfer_target, transfered_hate);
  940. }
  941. }
  942. // If pet is adding hate add some to the pets owner as well
  943. if (attacker->IsNPC() && ((NPC*)attacker)->IsPet())
  944. AddHate(((NPC*)attacker)->GetOwner(), 1);
  945. // If player and player has a pet and protect master is set add hate to the pet
  946. if (IsPlayer() && HasPet() && (((Player*)this)->GetInfoStruct()->get_pet_behavior() & 1)) {
  947. // If we have a combat pet add hate to it
  948. if (((Player*)this)->GetPet())
  949. AddHate(((Player*)this)->GetPet(), 1);
  950. if (((Player*)this)->GetCharmedPet())
  951. AddHate(((Player*)this)->GetCharmedPet(), 1);
  952. }
  953. // If this spawn has a spawn group then add the attacker to the hate list of the other
  954. // group members if not already in their list
  955. if (HasSpawnGroup()) {
  956. vector<Spawn*>* group = GetSpawnGroup();
  957. vector<Spawn*>::iterator itr;
  958. for (itr = group->begin(); itr != group->end(); itr++) {
  959. if (!(*itr)->IsNPC())
  960. continue;
  961. NPC* spawn = (NPC*)(*itr);
  962. if (spawn->Brain()->GetHate(attacker) == 0)
  963. spawn->Brain()->AddHate(attacker, 1);
  964. }
  965. safe_delete(group);
  966. }
  967. }
  968. bool Entity::CheckInterruptSpell(Entity* attacker) {
  969. if(!IsCasting())
  970. return false;
  971. Spell* spell = GetZone()->GetSpell(this);
  972. if(!spell || spell->GetSpellData()->interruptable == 0)
  973. return false;
  974. if(GetInfoStruct()->get_no_interrupt())
  975. return false;
  976. //originally base of 30 percent chance to continue casting if attacked
  977. //modified to 50% and added global rule, 30% was too small at starting levels
  978. int8 percent = rule_manager.GetGlobalRule(R_Spells, NoInterruptBaseChance)->GetInt32();
  979. Skill* skill = GetSkillByName("Focus", true);
  980. float focusSkillPts = 0.0f;
  981. MStats.lock();
  982. focusSkillPts = stats[ITEM_STAT_FOCUS];
  983. MStats.unlock();
  984. if(skill)
  985. percent += ((skill->current_val + 1 + focusSkillPts)/6);
  986. if(MakeRandomInt(1, 100) > percent) {
  987. LogWrite(COMBAT__DEBUG, 0, "Combat", "'%s' interrupted spell for '%s': %i%%", attacker->GetName(), GetName(), percent);
  988. GetZone()->Interrupted(this, attacker, SPELL_ERROR_INTERRUPTED);
  989. return true;
  990. }
  991. LogWrite(COMBAT__DEBUG, 0, "Combat", "'%s' failed to interrupt spell for '%s': %i%%", attacker->GetName(), GetName(), percent);
  992. return false;
  993. }
  994. void Entity::KillSpawn(Spawn* dead, int8 damage_type, int16 kill_blow_type) {
  995. if(!dead)
  996. return;
  997. if (IsPlayer()) {
  998. Client* client = GetZone()->GetClientBySpawn(this);
  999. PacketStruct* packet = configReader.getStruct("WS_EnterCombat", client->GetVersion());
  1000. if (packet) {
  1001. client->QueuePacket(packet->serialize());
  1002. }
  1003. safe_delete(packet);
  1004. ((Player*)this)->InCombat(false);
  1005. }
  1006. if (IsPlayer() && dead->IsEntity())
  1007. GetZone()->GetSpellProcess()->KillHOBySpawnID(dead->GetID());
  1008. //if (dead->IsEntity()) same code called in zone server
  1009. //((Entity*)dead)->InCombat(false);
  1010. /* just for sake of not knowing if we are in a read lock, write lock, or no lock
  1011. ** say spawnlist is locked (DismissPet arg 3 true), which means RemoveSpawn will remove the id from the spawn_list outside of the potential lock
  1012. */
  1013. if (dead->IsPet())
  1014. ((NPC*)dead)->GetOwner()->DismissPet((NPC*)dead, true, true);
  1015. else if (dead->IsEntity()) {
  1016. // remove all pets for this entity
  1017. ((Entity*)dead)->DismissAllPets(false, true);
  1018. }
  1019. // If not in combat and no one in the encounter list add this killer to the list
  1020. if(dead->EngagedInCombat() == false && dead->IsNPC() && ((NPC*)dead)->Brain()->GetEncounterSize() == 0)
  1021. ((NPC*)dead)->Brain()->AddToEncounter(this);
  1022. if (IsCasting())
  1023. GetZone()->Interrupted(this, dead, SPELL_ERROR_NOT_ALIVE);
  1024. LogWrite(COMBAT__DEBUG, 3, "Combat", "Killing '%s'", dead->GetName());
  1025. // Kill movement for the dead npc so the corpse doesn't move
  1026. GetZone()->movementMgr->StopNavigation((Entity*)dead);
  1027. dead->ClearRunningLocations();
  1028. dead->CalculateRunningLocation(true);
  1029. GetZone()->KillSpawn(true, dead, this, true, damage_type, kill_blow_type);
  1030. }
  1031. void Entity::HandleDeathExperienceDebt(Spawn* killer)
  1032. {
  1033. if(!IsPlayer())
  1034. return;
  1035. float ruleDebt = 0.0f;
  1036. if(killer && killer->IsPlayer())
  1037. ruleDebt = rule_manager.GetGlobalRule(R_Combat, PVPDeathExperienceDebt)->GetFloat()/100.0f;
  1038. else
  1039. ruleDebt = rule_manager.GetGlobalRule(R_Combat, DeathExperienceDebt)->GetFloat()/100.0f;
  1040. if(ruleDebt > 0.0f)
  1041. {
  1042. bool groupDebt = rule_manager.GetGlobalRule(R_Combat, GroupExperienceDebt)->GetBool();
  1043. if(groupDebt && ((Player*)this)->GetGroupMemberInfo())
  1044. {
  1045. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  1046. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)this)->GetGroupMemberInfo()->group_id);
  1047. if (group)
  1048. {
  1049. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  1050. deque<GroupMemberInfo*>* members = group->GetMembers();
  1051. int32 size = members->size();
  1052. float xpDebtPerMember = ruleDebt/(float)size;
  1053. deque<GroupMemberInfo*>::iterator itr;
  1054. for (itr = members->begin(); itr != members->end(); itr++) {
  1055. GroupMemberInfo* gmi = *itr;
  1056. if (gmi->client && gmi->client->GetPlayer()) {
  1057. gmi->client->GetPlayer()->GetInfoStruct()->set_xp_debt(gmi->client->GetPlayer()->GetInfoStruct()->get_xp_debt()+xpDebtPerMember);
  1058. gmi->client->GetPlayer()->SetCharSheetChanged(true);
  1059. }
  1060. }
  1061. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  1062. }
  1063. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1064. }
  1065. else
  1066. {
  1067. ((Player*)this)->GetInfoStruct()->set_xp_debt(((Player*)this)->GetInfoStruct()->get_xp_debt()+ruleDebt);
  1068. ((Player*)this)->SetCharSheetChanged(true);
  1069. }
  1070. }
  1071. }
  1072. void Entity::ProcessCombat() {
  1073. // This is a virtual function so when a NPC calls this it will use the NPC::ProcessCombat() version
  1074. // and a player will use the Player::ProcessCombat() version, leave this function blank.
  1075. }
  1076. void NPC::ProcessCombat() {
  1077. MBrain.writelock(__FUNCTION__, __LINE__);
  1078. // Check to see if it is time to call the AI again
  1079. if (GetHP() > 0 && Timer::GetCurrentTime2() >= (m_brain->LastTick() + m_brain->Tick())) {
  1080. // Probably never want to use the following log, will spam the console for every NPC in a zone 4 times a second
  1081. //LogWrite(NPC_AI__DEBUG, 9, "NPC_AI", "%s is thinking...", GetName());
  1082. m_brain->Think();
  1083. // Set the time for when the brain was last called
  1084. m_brain->SetLastTick(Timer::GetCurrentTime2());
  1085. }
  1086. MBrain.releasewritelock(__FUNCTION__, __LINE__);
  1087. }
  1088. void Player::ProcessCombat() {
  1089. // if not in combat OR casting a spell OR dazed OR feared return out
  1090. if (!EngagedInCombat() || IsCasting() || IsDazed() || IsFeared())
  1091. return;
  1092. //If no target delete combat_target and return out
  1093. Spawn* Target = GetZone()->GetSpawnByID(target);
  1094. if (!Target) {
  1095. combat_target = 0;
  1096. if (target > 0) {
  1097. SetTarget(0);
  1098. }
  1099. return;
  1100. }
  1101. // If is not an entity return out
  1102. if (!Target->IsEntity())
  1103. return;
  1104. // Reset combat target
  1105. combat_target = 0;
  1106. if (Target->HasTarget()) {
  1107. if (Target->IsPlayer() || (Target->IsNPC() && Target->IsPet() && ((NPC*)Target)->GetOwner()->IsPlayer())){
  1108. Spawn* secondary_target = Target->GetTarget();
  1109. if (secondary_target->IsNPC() && secondary_target->appearance.attackable) {
  1110. if (!secondary_target->IsPet() || (secondary_target->IsPet() && ((NPC*)secondary_target)->GetOwner()->IsNPC())) {
  1111. combat_target = secondary_target;
  1112. }
  1113. }
  1114. }
  1115. }
  1116. // If combat_target wasn't set in the above if set it to the original target
  1117. if (!combat_target)
  1118. combat_target = Target;
  1119. // this if may not be required as at the min combat_target will be Target, which we already check at the begining
  1120. if(!combat_target)
  1121. return;
  1122. float distance = 0;
  1123. distance = GetDistance(combat_target);
  1124. // Check to see if we are doing ranged auto attacks if not check to see if we are in melee range
  1125. if (GetRangeAttack()) {
  1126. // We are doing ranged auto attacks
  1127. //check to see if we can attack the target AND the ranged weapon is ready
  1128. if(AttackAllowed((Entity*)combat_target, distance, true) && RangeWeaponReady()) {
  1129. Item* weapon = 0;
  1130. Item* ammo = 0;
  1131. // Get the currently equiped weapon and ammo for the ranged attack
  1132. weapon = GetEquipmentList()->GetItem(EQ2_RANGE_SLOT);
  1133. ammo = GetEquipmentList()->GetItem(EQ2_AMMO_SLOT);
  1134. LogWrite(COMBAT__DEBUG, 1, "Combat", "Weapon '%s', Ammo '%s'", ( weapon )? weapon->name.c_str() : "None", ( ammo ) ? ammo->name.c_str() : "None");
  1135. // If weapon and ammo are both valid perform the ranged attack else send a message to the client
  1136. if(weapon && ammo) {
  1137. LogWrite(COMBAT__DEBUG, 1, "Combat", "Weapon: Primary, Fighter: '%s', Target: '%s', Distance: %.2f", GetName(), combat_target->GetName(), distance);
  1138. RangeAttack(combat_target, distance, weapon, ammo);
  1139. }
  1140. else {
  1141. Client* client = GetZone()->GetClientBySpawn(this);
  1142. if (client) {
  1143. // Need to get messages from live, made these up so the player knows what is wrong in game if weapon or ammo are not valid
  1144. if (!ammo)
  1145. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Out of ammo.");
  1146. if (!weapon)
  1147. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "No ranged weapon found.");
  1148. }
  1149. }
  1150. }
  1151. }
  1152. else if(distance <= rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat()) {
  1153. // We are doing melee auto attacks and are within range
  1154. // Check to see if we can attack the target
  1155. if(AttackAllowed((Entity*)combat_target)) {
  1156. // Check to see if the primary melee weapon is ready
  1157. if(PrimaryWeaponReady()) {
  1158. // Set the time of the last melee attack with the primary weapon and perform the melee attack with primary weapon
  1159. SetPrimaryLastAttackTime(Timer::GetCurrentTime2());
  1160. MeleeAttack(combat_target, distance, true);
  1161. }
  1162. // Check to see if the secondary weapon is ready
  1163. if(SecondaryWeaponReady()) {
  1164. // set the time of the last melee attack with the secondary weapon and perform the melee attack with the secondary weapon
  1165. SetSecondaryLastAttackTime(Timer::GetCurrentTime2());
  1166. MeleeAttack(combat_target, distance, false);
  1167. }
  1168. }
  1169. }
  1170. }
  1171. void Entity::SetAttackDelay(bool primary, bool ranged) {
  1172. float mod = CalculateAttackSpeedMod();
  1173. bool dual_wield = IsDualWield();
  1174. //Note: Capping all attack speed increases at 125% normal speed (from function CalculateAttackSpeedMod())
  1175. //Add 33% longer delay if dual wielding
  1176. if(dual_wield && ! ranged) {
  1177. if(primary)
  1178. SetPrimaryAttackDelay((GetPrimaryWeaponDelay() * 1.33) / mod);
  1179. else
  1180. SetSecondaryAttackDelay((GetSecondaryWeaponDelay() * 1.33) / mod);
  1181. }
  1182. else {
  1183. if(primary)
  1184. SetPrimaryAttackDelay(GetPrimaryWeaponDelay() / mod);
  1185. else if(ranged)
  1186. SetRangeAttackDelay(GetRangeWeaponDelay() / mod);
  1187. else
  1188. SetSecondaryAttackDelay(GetSecondaryWeaponDelay() / mod);
  1189. }
  1190. }
  1191. float Entity::CalculateAttackSpeedMod(){
  1192. float aspeed = info_struct.get_attackspeed();
  1193. if(aspeed > 0) {
  1194. if (aspeed <= 100)
  1195. return (aspeed / 100 + 1);
  1196. else if (aspeed <= 200)
  1197. return 2.25;
  1198. }
  1199. return 1;
  1200. }
  1201. void Entity::AddProc(int8 type, float chance, Item* item, LuaSpell* spell) {
  1202. if (type == 0) {
  1203. LogWrite(COMBAT__ERROR, 0, "Proc", "Entity::AddProc called with an invalid type.");
  1204. return;
  1205. }
  1206. if (!item && !spell) {
  1207. LogWrite(COMBAT__ERROR, 0, "Proc", "Entity::AddProc must have a valid item or spell.");
  1208. return;
  1209. }
  1210. MProcList.writelock(__FUNCTION__, __LINE__);
  1211. Proc* proc = new Proc();
  1212. proc->chance = chance;
  1213. proc->item = item;
  1214. proc->spell = spell;
  1215. proc->spellid = spell->spell->GetSpellID();
  1216. m_procList[type].push_back(proc);
  1217. MProcList.releasewritelock(__FUNCTION__, __LINE__);
  1218. }
  1219. void Entity::RemoveProc(Item* item, LuaSpell* spell) {
  1220. if (!item && !spell) {
  1221. LogWrite(COMBAT__ERROR, 0, "Proc", "Entity::RemoveProc must have a valid item or spell.");
  1222. return;
  1223. }
  1224. MProcList.writelock(__FUNCTION__, __LINE__);
  1225. map<int8, vector<Proc*> >::iterator proc_itr;
  1226. vector<Proc*>::iterator itr;
  1227. for (proc_itr = m_procList.begin(); proc_itr != m_procList.end(); proc_itr++) {
  1228. itr = proc_itr->second.begin();
  1229. while (itr != proc_itr->second.end()) {
  1230. Proc* proc = *itr;
  1231. if ((item && proc->item == item) || (spell && proc->spell == spell)) {
  1232. itr = proc_itr->second.erase(itr);
  1233. safe_delete(proc);
  1234. }
  1235. else
  1236. itr++;
  1237. }
  1238. }
  1239. MProcList.releasewritelock(__FUNCTION__, __LINE__);
  1240. }
  1241. bool Entity::CastProc(Proc* proc, int8 type, Spawn* target) {
  1242. lua_State* state = 0;
  1243. bool item_proc = false;
  1244. int8 num_args = 3;
  1245. if (proc->spell) {
  1246. state = proc->spell->state;
  1247. }
  1248. else if (proc->item) {
  1249. state = lua_interface->GetItemScript(proc->item->GetItemScript());
  1250. item_proc = true;
  1251. }
  1252. if (!state) {
  1253. LogWrite(COMBAT__ERROR, 0, "Proc", "No valid lua_State* found");
  1254. return false;
  1255. }
  1256. lua_getglobal(state, "proc");
  1257. if (item_proc) {
  1258. num_args++;
  1259. lua_interface->SetItemValue(state, proc->item);
  1260. }
  1261. lua_interface->SetSpawnValue(state, this);
  1262. lua_interface->SetSpawnValue(state, target);
  1263. lua_interface->SetInt32Value(state, type);
  1264. /*
  1265. Add spell data from db in case of a spell proc here...
  1266. */
  1267. if (!item_proc) {
  1268. // Append spell data to the param list
  1269. vector<LUAData*>* data = proc->spell->spell->GetLUAData();
  1270. for(int32 i = 0; i < data->size(); i++) {
  1271. switch(data->at(i)->type) {
  1272. case 0:{
  1273. lua_interface->SetSInt32Value(proc->spell->state, data->at(i)->int_value);
  1274. break;
  1275. }
  1276. case 1:{
  1277. lua_interface->SetFloatValue(proc->spell->state, data->at(i)->float_value);
  1278. break;
  1279. }
  1280. case 2:{
  1281. lua_interface->SetBooleanValue(proc->spell->state, data->at(i)->bool_value);
  1282. break;
  1283. }
  1284. case 3:{
  1285. lua_interface->SetStringValue(proc->spell->state, data->at(i)->string_value.c_str());
  1286. break;
  1287. }
  1288. default:{
  1289. LogWrite(SPELL__ERROR, 0, "Spell", "Error: Unknown LUA Type '%i' in Entity::CastProc for Spell '%s'", (int)data->at(i)->type, proc->spell->spell->GetName());
  1290. return false;
  1291. }
  1292. }
  1293. num_args++;
  1294. }
  1295. }
  1296. if (lua_pcall(state, num_args, 0, 0) != 0) {
  1297. LogWrite(COMBAT__ERROR, 0, "Proc", "Unable to call the proc function for spell %i tier %i", proc->spell->spell->GetSpellID(), proc->spell->spell->GetSpellTier());
  1298. lua_pop(state, 1);
  1299. return false;
  1300. }
  1301. return true;
  1302. }
  1303. void Entity::CheckProcs(int8 type, Spawn* target) {
  1304. if (type == 0) {
  1305. LogWrite(COMBAT__ERROR, 0, "Proc", "Entity::CheckProcs called with an invalid type.");
  1306. return;
  1307. }
  1308. float roll = MakeRandomFloat(0, 100);
  1309. vector<Proc*> tmpList;
  1310. MProcList.readlock(__FUNCTION__, __LINE__);
  1311. for (int8 i = 0; i < m_procList[type].size(); i++) {
  1312. Proc* proc = m_procList[type].at(i);
  1313. if (roll <= proc->chance)
  1314. {
  1315. Proc* tmpProc = new Proc();
  1316. tmpProc->chance = proc->chance;
  1317. tmpProc->item = proc->item;
  1318. tmpProc->spell = proc->spell;
  1319. tmpProc->spellid = proc->spellid;
  1320. tmpList.push_back(tmpProc);
  1321. }
  1322. }
  1323. MProcList.releasereadlock(__FUNCTION__, __LINE__);
  1324. vector<Proc*>::iterator proc_itr;
  1325. for (proc_itr = tmpList.begin(); proc_itr != tmpList.end();) {
  1326. Proc* tmpProc = *proc_itr;
  1327. CastProc(tmpProc, type, target);
  1328. proc_itr++;
  1329. safe_delete(tmpProc);
  1330. }
  1331. }
  1332. void Entity::ClearProcs() {
  1333. MProcList.writelock(__FUNCTION__, __LINE__);
  1334. map<int8, vector<Proc*> >::iterator proc_itr;
  1335. vector<Proc*>::iterator itr;
  1336. for (proc_itr = m_procList.begin(); proc_itr != m_procList.end(); proc_itr++) {
  1337. itr = proc_itr->second.begin();
  1338. while (itr != proc_itr->second.end()) {
  1339. safe_delete(*itr);
  1340. itr = proc_itr->second.erase(itr);
  1341. }
  1342. proc_itr->second.clear();
  1343. }
  1344. m_procList.clear();
  1345. MProcList.releasewritelock(__FUNCTION__, __LINE__);
  1346. }