Fixes dictionary uses (#7)

This commit is contained in:
Kamron Batman 2018-11-02 08:16:42 -07:00 committed by GitHub
parent d4a52344f2
commit 916d404c51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
161 changed files with 1211 additions and 1722 deletions

View file

@ -205,9 +205,7 @@ namespace Server.Spells.Necromancy
if (master == null)
return;
m_Table.TryGetValue(master, out List<Mobile> list);
if (list == null)
if (!m_Table.TryGetValue(master, out List<Mobile> list))
return;
list.Remove(summoned);
@ -221,9 +219,7 @@ namespace Server.Spells.Necromancy
if (master == null)
return;
m_Table.TryGetValue(master, out List<Mobile> list);
if (list == null)
if (!m_Table.TryGetValue(master, out List<Mobile> list))
m_Table[master] = list = new List<Mobile>();
for (int i = list.Count - 1; i >= 0; --i)
@ -306,6 +302,7 @@ namespace Server.Spells.Necromancy
}
catch
{
// ignored
}
if (summoned == null)
@ -394,4 +391,4 @@ namespace Server.Spells.Necromancy
}
}
}
}
}

View file

@ -62,7 +62,7 @@ namespace Server.Spells.Necromancy
* ((ss-rm)/8)+8
*/
ExpireTimer timer = m_Table[m];
m_Table.TryGetValue(m, out ExpireTimer timer);
timer?.DoExpire();
m_OathTable[Caster] = Caster;
@ -96,17 +96,13 @@ namespace Server.Spells.Necromancy
public static void RemoveCurse(Mobile m)
{
ExpireTimer t = m_Table[m];
m_Table.TryGetValue(m, out ExpireTimer t);
t?.DoExpire();
}
public static Mobile GetBloodOath(Mobile m)
{
if (m == null)
return null;
Mobile oath = m_OathTable[m];
return oath == m ? null : oath;
return m == null || m_OathTable.TryGetValue(m, out Mobile oath) && oath == m ? null : oath;
}
private class ExpireTimer : Timer

View file

@ -49,9 +49,7 @@ namespace Server.Spells.Necromancy
* NOTE: Resistance is not checked if targeting yourself
*/
ExpireTimer timer = m_Table[m];
if (timer != null)
if (m_Table.TryGetValue(m, out ExpireTimer timer))
timer.DoExpire();
else
m.SendLocalizedMessage(1061689); // Your skin turns dry and corpselike.

View file

@ -50,12 +50,10 @@ namespace Server.Spells.Necromancy
TimeSpan duration = TimeSpan.FromSeconds(Caster.Skills.SpiritSpeak.Value / 3.4 + 1.0);
ExpireTimer timer = m_Table[weapon];
m_Table.TryGetValue(weapon, out ExpireTimer timer);
timer?.Stop();
weapon.Cursed = true;
m_Table[weapon] = timer = new ExpireTimer(weapon, duration);
timer.Start();

View file

@ -69,7 +69,7 @@ namespace Server.Spells.Necromancy
TimeSpan duration = TimeSpan.FromSeconds(Caster.Skills.SpiritSpeak.Value / 12 + 1.0);
Timer.DelayCall(duration, () => TryEndEffect(m));
Timer.DelayCall(duration, TryEndEffect_Callback, m);
HarmfulSpell(m);
@ -86,6 +86,10 @@ namespace Server.Spells.Necromancy
*
* -refactored.
*/
private static void TryEndEffect_Callback(Mobile m)
{
TryEndEffect(m);
}
public static bool TryEndEffect(Mobile m)
{

View file

@ -58,10 +58,7 @@ namespace Server.Spells.Necromancy
((GetDamageSkill(Caster) - GetResistSkill(m)) / 5.0 + 20.0) * (m.Player ? 1.0 : 2.0));
m.CheckSkill(SkillName.MagicResist, 0.0, 120.0); //Skill check for gain
if (m.Player)
SetMindRotScalar(Caster, m, 1.25, duration);
else
SetMindRotScalar(Caster, m, 2.00, duration);
SetMindRotScalar(Caster, m, m.Player ? 1.25 : 2.00, duration);
HarmfulSpell(m);
}
@ -71,9 +68,7 @@ namespace Server.Spells.Necromancy
public static void ClearMindRotScalar(Mobile m)
{
MRBucket tmpB = m_Table[m];
if (tmpB == null)
if (!m_Table.TryGetValue(m, out MRBucket tmpB))
return;
BuffInfo.RemoveBuff(m, BuffIcon.Mindrot);
@ -89,13 +84,13 @@ namespace Server.Spells.Necromancy
public static bool GetMindRotScalar(Mobile m, ref double scalar)
{
MRBucket tmpB = m_Table[m];
if (m_Table.TryGetValue(m, out MRBucket tmpB))
{
scalar = tmpB.m_Scalar;
return true;
}
if (tmpB == null)
return false;
scalar = tmpB.m_Scalar;
return true;
return false;
}
public static void SetMindRotScalar(Mobile caster, Mobile target, double scalar, TimeSpan duration)

View file

@ -59,9 +59,7 @@ namespace Server.Spells.Necromancy
TimeSpan buffTime = TimeSpan.FromSeconds(10.0);
InternalTimer timer = m_Table[m];
if (timer == null)
if (!m_Table.TryGetValue(m, out InternalTimer timer))
{
m_Table[m] = timer = new InternalTimer(m, damage);
timer.Start();

View file

@ -59,9 +59,7 @@ namespace Server.Spells.Necromancy
m.FixedParticles(0x36CB, 1, 9, 9911, 67, 5, EffectLayer.Head);
m.FixedParticles(0x374A, 1, 17, 9502, 1108, 4, (EffectLayer)255);
InternalTimer timer = m_Table[m];
if (timer == null)
if (!m_Table.TryGetValue(m, out InternalTimer timer))
{
m_Table[m] = timer = new InternalTimer(m, Caster);
timer.Start();
@ -111,9 +109,7 @@ namespace Server.Spells.Necromancy
public static bool RemoveCurse(Mobile m)
{
Timer timer = m_Table[m];
if (timer == null)
if (!m_Table.TryGetValue(m, out InternalTimer timer))
return false;
timer.Stop();

View file

@ -40,15 +40,11 @@ namespace Server.Spells.Necromancy
public override bool CheckCast()
{
BaseCreature check = Table[Caster];
if (!(Table.TryGetValue(Caster, out BaseCreature check) && check?.Deleted == false))
return base.CheckCast();
if (check?.Deleted == false)
{
Caster.SendLocalizedMessage(1061605); // You already have a familiar.
return false;
}
return base.CheckCast();
Caster.SendLocalizedMessage(1061605); // You already have a familiar.
return false;
}
public override void OnCast()
@ -149,18 +145,12 @@ namespace Server.Spells.Necromancy
double necro = m_From.Skills.Necromancy.Value;
double spirit = m_From.Skills.SpiritSpeak.Value;
BaseCreature check = SummonFamiliarSpell.Table[m_From];
#region Dueling
if ((m_From as PlayerMobile)?.DuelContext != null &&
!((PlayerMobile)m_From).DuelContext.AllowSpellCast(m_From, m_Spell))
if ((m_From as PlayerMobile)?.DuelContext?.AllowSpellCast(m_From, m_Spell) == false)
{
}
#endregion
else if (check?.Deleted == false)
else if (SummonFamiliarSpell.Table.TryGetValue(m_From, out BaseCreature check) && check?.Deleted == false)
{
m_From.SendLocalizedMessage(1061605); // You already have a familiar.
}