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

@ -62,10 +62,9 @@ namespace Server.Spells.Bushido
public static void EndConfidence(Mobile m)
{
if (m_Table.TryGetValue(m, out var timer))
if (m_Table.Remove(m, out var timer))
{
timer.Stop();
m_Table.Remove(m);
}
OnEffectEnd(m, typeof(Confidence));
@ -85,10 +84,9 @@ namespace Server.Spells.Bushido
public static void StopRegenerating(Mobile m)
{
if (m_RegenTable.TryGetValue(m, out var timer))
if (m_RegenTable.Remove(m, out var timer))
{
timer.Stop();
m_RegenTable.Remove(m);
}
}

View file

@ -77,10 +77,9 @@ namespace Server.Spells.Bushido
public static void StopCountering(Mobile m)
{
if (m_Table.TryGetValue(m, out var timer))
if (m_Table.Remove(m, out var timer))
{
timer.Stop();
m_Table.Remove(m);
}
OnEffectEnd(m, typeof(CounterAttack));

View file

@ -181,10 +181,9 @@ namespace Server.Spells.Bushido
public static void EndEvasion(Mobile m)
{
if (m_Table.TryGetValue(m, out var timer))
if (m_Table.Remove(m, out var timer))
{
timer.Stop();
m_Table.Remove(m);
}
OnEffectEnd(m, typeof(Evasion));

View file

@ -25,7 +25,9 @@ namespace Server.Spells.Bushido
public override void OnHit(Mobile attacker, Mobile defender, int damage)
{
if (!Validate(attacker) || !CheckMana(attacker, true))
{
return;
}
ClearCurrentMove(attacker);
@ -64,7 +66,9 @@ namespace Server.Spells.Bushido
var resSpells = attacker.Skills.MagicResist.Value;
if (resSpells > 0.0)
{
mods.Add(new DefaultSkillMod(SkillName.MagicResist, true, -resSpells));
}
info = new HonorableExecutionInfo(attacker, mods);
info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(7.0), RemovePenalty, info.m_Mobile);
@ -81,12 +85,13 @@ namespace Server.Spells.Bushido
public static void RemovePenalty(Mobile target)
{
if (!m_Table.TryGetValue(target, out var info) || !info.m_Penalty)
if (!m_Table.Remove(target, out var info) || !info.m_Penalty)
{
return;
}
info.Clear();
info.m_Timer?.Stop();
m_Table.Remove(target);
}
private class HonorableExecutionInfo
@ -114,32 +119,44 @@ namespace Server.Spells.Bushido
public void Apply()
{
if (m_Mods == null)
{
return;
}
for (var i = 0; i < m_Mods.Count; ++i)
{
var mod = m_Mods[i];
if (mod is ResistanceMod resistanceMod)
{
m_Mobile.AddResistanceMod(resistanceMod);
}
else if (mod is SkillMod skillMod)
{
m_Mobile.AddSkillMod(skillMod);
}
}
}
public void Clear()
{
if (m_Mods == null)
{
return;
}
for (var i = 0; i < m_Mods.Count; ++i)
{
var mod = m_Mods[i];
if (mod is ResistanceMod resistanceMod)
{
m_Mobile.RemoveResistanceMod(resistanceMod);
}
else if (mod is SkillMod skillMod)
{
m_Mobile.RemoveSkillMod(skillMod);
}
}
}
}