Some cleanup of contains keys and try get values (#246)

This commit is contained in:
Kamron Batman 2020-09-13 20:20:44 -07:00 • committed by GitHub
parent 9cbb0cfd23
commit a236617ad9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
69 changed files with 3508 additions and 350 deletions

View file

@ -21,7 +21,9 @@ namespace Server.Items
public override void OnHit(Mobile attacker, Mobile defender, int damage)
{
if (!Validate(attacker) || !CheckMana(attacker, true))
{
return;
}
ClearCurrentAbility(attacker);
@ -73,7 +75,9 @@ namespace Server.Items
var damage = Utility.RandomMinMax(level, level * 2);
if (!m.Player)
{
damage *= 2;
}
m.PlaySound(0x133);
m.Damage(damage, from);
@ -89,14 +93,17 @@ namespace Server.Items
public static void EndBleed(Mobile m, bool message)
{
if (!m_Table.TryGetValue(m, out var t))
if (!m_Table.Remove(m, out var t))
{
return;
}
t.Stop();
m_Table.Remove(m);
if (message)
{
m.SendLocalizedMessage(1060167); // The bleeding wounds have healed, you are no longer bleeding!
}
}
private class InternalTimer : Timer
@ -117,7 +124,9 @@ namespace Server.Items
DoBleed(m_Mobile, m_From, 5 - m_Count);
if (++m_Count == 5)
{
EndBleed(m_Mobile, true);
}
}
}
}

View file

@ -29,7 +29,9 @@ namespace Server.Items
public override void OnHit(Mobile attacker, Mobile defender, int damage)
{
if (!Validate(attacker) || !CheckMana(attacker, true))
{
return;
}
ClearCurrentAbility(attacker);
@ -49,7 +51,9 @@ namespace Server.Items
public static bool GetBonus(Mobile targ, ref int bonus)
{
if (!m_Table.TryGetValue(targ, out var info))
{
return false;
}
bonus = info.m_Bonus;
return true;
@ -63,11 +67,10 @@ namespace Server.Items
public static void EndBlock(Mobile m)
{
if (!m_Table.TryGetValue(m, out var info))
return;
info.m_Timer?.Stop();
m_Table.Remove(m);
if (m_Table.Remove(m, out var info))
{
info.m_Timer?.Stop();
}
}
private class BlockInfo

View file

@ -19,7 +19,10 @@ namespace Server.Items
public override void OnHit(Mobile attacker, Mobile defender, int damage)
{
if (!Validate(attacker) || !CheckMana(attacker, true)) return;
if (!Validate(attacker) || !CheckMana(attacker, true))
{
return;
}
ClearCurrentAbility(attacker);
@ -31,7 +34,9 @@ namespace Server.Items
// Do not reset timer if one is already in place.
if (!IsWounded(defender))
{
BeginWound(defender, defender.Player ? PlayerDuration : NPCDuration);
}
}
public static bool IsWounded(Mobile m) => m_Table.ContainsKey(m);
@ -39,7 +44,9 @@ namespace Server.Items
public static void BeginWound(Mobile m, TimeSpan duration)
{
if (m_Table.TryGetValue(m, out var timer))
{
timer?.Stop();
}
m_Table[m] = timer = new InternalTimer(m, duration);
timer.Start();
@ -49,10 +56,9 @@ namespace Server.Items
public static void EndWound(Mobile m)
{
if (m_Table.TryGetValue(m, out var timer))
if (m_Table.Remove(m, out var timer))
{
timer.Stop();
m_Table.Remove(m);
}
m.YellowHealthbar = false;

View file

@ -22,17 +22,17 @@ namespace Server.Items
{
if (!base.CheckSkills( from ))
return false;
if (!(from.Weapon is Fists))
return true;
Skill skill = from.Skills.Anatomy;
if (skill?.Base >= 80.0)
return true;
from.SendLocalizedMessage( 1061811 ); // You lack the required anatomy skill to perform that attack!
return false;
}*/
@ -91,10 +91,9 @@ namespace Server.Items
public static void EndImmunity(Mobile m)
{
if (m_Table.TryGetValue(m, out var timer))
if (m_Table.Remove(m, out var timer))
{
timer?.Stop();
m_Table.Remove(m);
}
}