Fixes dictionary uses (#7)
This commit is contained in:
parent
d4a52344f2
commit
916d404c51
161 changed files with 1211 additions and 1722 deletions
|
|
@ -288,14 +288,14 @@ namespace Server.Items
|
|||
|
||||
public static void AddDelay(Mobile m)
|
||||
{
|
||||
m_Delay[m]?.Stop();
|
||||
m_Delay.TryGetValue(m, out Timer timer);
|
||||
timer?.Stop();
|
||||
m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(30), EndDelay, m);
|
||||
}
|
||||
|
||||
public static int GetDelay(Mobile m)
|
||||
{
|
||||
Timer timer = m_Delay[m];
|
||||
if (timer?.Next > DateTime.UtcNow)
|
||||
if (m_Delay.TryGetValue(m, out Timer timer) && timer.Next > DateTime.UtcNow)
|
||||
return (int)(timer.Next - DateTime.UtcNow).TotalSeconds;
|
||||
|
||||
return 0;
|
||||
|
|
@ -303,9 +303,7 @@ namespace Server.Items
|
|||
|
||||
public static void EndDelay(Mobile m)
|
||||
{
|
||||
Timer timer = m_Delay[m];
|
||||
|
||||
if (timer != null)
|
||||
if (m_Delay.TryGetValue(m, out Timer timer))
|
||||
{
|
||||
timer.Stop();
|
||||
m_Delay.Remove(m);
|
||||
|
|
|
|||
|
|
@ -153,14 +153,14 @@ namespace Server.Items
|
|||
|
||||
public static void AddDelay(Mobile m)
|
||||
{
|
||||
m_Delay[m]?.Stop();
|
||||
m_Delay.TryGetValue(m, out Timer timer);
|
||||
timer?.Stop();
|
||||
m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(60), EndDelay, m);
|
||||
}
|
||||
|
||||
public static int GetDelay(Mobile m)
|
||||
{
|
||||
Timer timer = m_Delay[m];
|
||||
if (timer?.Next > DateTime.UtcNow)
|
||||
if (m_Delay.TryGetValue(m, out Timer timer) && timer.Next > DateTime.UtcNow)
|
||||
return (int)(timer.Next - DateTime.UtcNow).TotalSeconds;
|
||||
|
||||
return 0;
|
||||
|
|
@ -168,8 +168,7 @@ namespace Server.Items
|
|||
|
||||
public static void EndDelay(Mobile m)
|
||||
{
|
||||
Timer timer = m_Delay[m];
|
||||
if (timer != null)
|
||||
if (m_Delay.TryGetValue(m, out Timer timer))
|
||||
{
|
||||
timer.Stop();
|
||||
m_Delay.Remove(m);
|
||||
|
|
|
|||
|
|
@ -63,26 +63,20 @@ namespace Server.Items
|
|||
|
||||
public static bool HasTimer(Mobile m)
|
||||
{
|
||||
return m_Table[m] != null;
|
||||
return m_Table.ContainsKey(m);
|
||||
}
|
||||
|
||||
public static void RemoveTimer(Mobile m)
|
||||
public static void RemoveTimer(Mobile m, bool interrupted = false)
|
||||
{
|
||||
Timer timer = m_Table[m];
|
||||
|
||||
if (timer != null)
|
||||
if (m_Table.TryGetValue(m, out Timer timer))
|
||||
{
|
||||
if (interrupted)
|
||||
m.SendLocalizedMessage(1073187); // The invisibility effect is interrupted.
|
||||
timer.Stop();
|
||||
m_Table.Remove(m);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Iterrupt(Mobile m)
|
||||
{
|
||||
m.SendLocalizedMessage(1073187); // The invisibility effect is interrupted.
|
||||
RemoveTimer(m);
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
|
|
|||
|
|
@ -435,11 +435,9 @@ namespace Server.Items
|
|||
return null;
|
||||
}
|
||||
|
||||
m_Table.TryGetValue(from, out List<Spellbook> list);
|
||||
|
||||
bool searchAgain = false;
|
||||
|
||||
if (list == null)
|
||||
if (!m_Table.TryGetValue(from, out List<Spellbook> list))
|
||||
m_Table[from] = list = FindAllSpellbooks(from);
|
||||
else
|
||||
searchAgain = true;
|
||||
|
|
@ -911,4 +909,4 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue