Fixes dictionary uses (#7)
This commit is contained in:
parent
d4a52344f2
commit
916d404c51
161 changed files with 1211 additions and 1722 deletions
|
|
@ -258,58 +258,53 @@ namespace Server.Regions
|
|||
|
||||
public void CheckGuardCandidate(Mobile m)
|
||||
{
|
||||
if (IsDisabled())
|
||||
if (IsDisabled() || !IsGuardCandidate(m))
|
||||
return;
|
||||
|
||||
if (IsGuardCandidate(m))
|
||||
if (!m_GuardCandidates.TryGetValue(m, out GuardTimer timer))
|
||||
{
|
||||
m_GuardCandidates.TryGetValue(m, out GuardTimer timer);
|
||||
timer = new GuardTimer(m, m_GuardCandidates);
|
||||
timer.Start();
|
||||
|
||||
if (timer == null)
|
||||
{
|
||||
timer = new GuardTimer(m, m_GuardCandidates);
|
||||
timer.Start();
|
||||
m_GuardCandidates[m] = timer;
|
||||
m.SendLocalizedMessage(502275); // Guards can now be called on you!
|
||||
|
||||
m_GuardCandidates[m] = timer;
|
||||
m.SendLocalizedMessage(502275); // Guards can now be called on you!
|
||||
Map map = m.Map;
|
||||
|
||||
Map map = m.Map;
|
||||
if (map == null)
|
||||
return;
|
||||
|
||||
if (map != null)
|
||||
Mobile fakeCall = null;
|
||||
double prio = 0.0;
|
||||
|
||||
foreach (Mobile v in m.GetMobilesInRange(8))
|
||||
if (!v.Player && v != m && !IsGuardCandidate(v) &&
|
||||
((v as BaseCreature)?.IsHumanInTown() ?? v.Body.IsHuman && v.Region.IsPartOf(this)))
|
||||
{
|
||||
Mobile fakeCall = null;
|
||||
double prio = 0.0;
|
||||
double dist = m.GetDistanceToSqrt(v);
|
||||
|
||||
foreach (Mobile v in m.GetMobilesInRange(8))
|
||||
if (!v.Player && v != m && !IsGuardCandidate(v) &&
|
||||
((v as BaseCreature)?.IsHumanInTown() ?? v.Body.IsHuman && v.Region.IsPartOf(this)))
|
||||
{
|
||||
double dist = m.GetDistanceToSqrt(v);
|
||||
|
||||
if (fakeCall == null || dist < prio)
|
||||
{
|
||||
fakeCall = v;
|
||||
prio = dist;
|
||||
}
|
||||
}
|
||||
|
||||
if (fakeCall != null)
|
||||
if (fakeCall == null || dist < prio)
|
||||
{
|
||||
fakeCall.Say(Utility.RandomList(1007037, 501603, 1013037, 1013038, 1013039, 1013041, 1013042,
|
||||
1013043, 1013052));
|
||||
MakeGuard(m);
|
||||
timer.Stop();
|
||||
m_GuardCandidates.Remove(m);
|
||||
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
|
||||
fakeCall = v;
|
||||
prio = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (fakeCall != null)
|
||||
{
|
||||
fakeCall.Say(Utility.RandomList(1007037, 501603, 1013037, 1013038, 1013039, 1013041, 1013042,
|
||||
1013043, 1013052));
|
||||
MakeGuard(m);
|
||||
timer.Stop();
|
||||
timer.Start();
|
||||
m_GuardCandidates.Remove(m);
|
||||
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
timer.Stop();
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public void CallGuards(Point3D p)
|
||||
|
|
@ -323,9 +318,7 @@ namespace Server.Regions
|
|||
if (IsGuardCandidate(m) &&
|
||||
(!AllowReds && m.Kills >= 5 && m.Region.IsPartOf(this) || m_GuardCandidates.ContainsKey(m)))
|
||||
{
|
||||
m_GuardCandidates.TryGetValue(m, out GuardTimer timer);
|
||||
|
||||
if (timer != null)
|
||||
if (m_GuardCandidates.TryGetValue(m, out GuardTimer timer))
|
||||
{
|
||||
timer.Stop();
|
||||
m_GuardCandidates.Remove(m);
|
||||
|
|
@ -371,4 +364,4 @@ namespace Server.Regions
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,9 +36,7 @@ namespace Server.Regions
|
|||
if (!Region.ReadString(xml, "name", ref group))
|
||||
return null;
|
||||
|
||||
SpawnDefinition def = SpawnGroup.Table[@group];
|
||||
|
||||
if (def == null)
|
||||
if (!SpawnGroup.Table.TryGetValue(group, out SpawnGroup def))
|
||||
{
|
||||
Console.WriteLine("Could not find group '{0}' in a SpawnDefinition", group);
|
||||
return null;
|
||||
|
|
@ -152,9 +150,7 @@ namespace Server.Regions
|
|||
|
||||
public static SpawnMobile Get(Type type)
|
||||
{
|
||||
SpawnMobile sm = m_Table[type];
|
||||
|
||||
if (sm == null)
|
||||
if (!m_Table.TryGetValue(type, out SpawnMobile sm))
|
||||
m_Table[type] = sm = new SpawnMobile(type);
|
||||
|
||||
return sm;
|
||||
|
|
@ -221,9 +217,7 @@ namespace Server.Regions
|
|||
|
||||
public static SpawnItem Get(Type type)
|
||||
{
|
||||
SpawnItem si = m_Table[type];
|
||||
|
||||
if (si == null)
|
||||
if (!m_Table.TryGetValue(type, out SpawnItem si))
|
||||
m_Table[type] = si = new SpawnItem(type);
|
||||
|
||||
return si;
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ namespace Server.Regions
|
|||
m_SpawnTimer = null;
|
||||
}
|
||||
|
||||
if (Table[ID] == this)
|
||||
if (Table.TryGetValue(ID, out SpawnEntry entry) && entry == this)
|
||||
Table.Remove(ID);
|
||||
}
|
||||
|
||||
|
|
@ -310,6 +310,7 @@ namespace Server.Regions
|
|||
Mobile from = args.Mobile;
|
||||
|
||||
Region reg;
|
||||
|
||||
if (args.Length == 0)
|
||||
{
|
||||
reg = from.Region;
|
||||
|
|
@ -317,29 +318,26 @@ namespace Server.Regions
|
|||
else
|
||||
{
|
||||
string name = args.GetString(0);
|
||||
//reg = if (!from.Map.Regions.TryGetValue( name, out (Region) from.Map.Regions[name] ))
|
||||
if (!from.Map.Regions.TryGetValue(name, out reg))
|
||||
{
|
||||
from.SendMessage("Could not find region '{0}'.", name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
BaseRegion br = reg as BaseRegion;
|
||||
if (reg is BaseRegion br && br.Spawns != null)
|
||||
return br;
|
||||
|
||||
if (br?.Spawns == null)
|
||||
{
|
||||
from.SendMessage("There are no spawners in region '{0}'.", reg);
|
||||
return null;
|
||||
}
|
||||
|
||||
return br;
|
||||
from.SendMessage("There are no spawners in region '{0}'.", reg);
|
||||
return null;
|
||||
}
|
||||
|
||||
[Usage("RespawnAllRegions")]
|
||||
[Description("Respawns all regions and sets the spawners as running.")]
|
||||
private static void RespawnAllRegions_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
foreach (SpawnEntry entry in Table.Values) entry.Respawn();
|
||||
foreach (SpawnEntry entry in Table.Values)
|
||||
entry.Respawn();
|
||||
|
||||
args.Mobile.SendMessage("All regions have respawned.");
|
||||
}
|
||||
|
|
@ -363,7 +361,8 @@ namespace Server.Regions
|
|||
[Description("Deletes all spawned objects of every regions and sets the spawners as not running.")]
|
||||
private static void DelAllRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
foreach (SpawnEntry entry in Table.Values) entry.DeleteSpawnedObjects();
|
||||
foreach (SpawnEntry entry in Table.Values)
|
||||
entry.DeleteSpawnedObjects();
|
||||
|
||||
args.Mobile.SendMessage("All region spawned objects have been deleted.");
|
||||
}
|
||||
|
|
@ -388,7 +387,8 @@ namespace Server.Regions
|
|||
[Description("Sets the region spawners of all regions as running.")]
|
||||
private static void StartAllRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
foreach (SpawnEntry entry in Table.Values) entry.Start();
|
||||
foreach (SpawnEntry entry in Table.Values)
|
||||
entry.Start();
|
||||
|
||||
args.Mobile.SendMessage("All region spawners have started.");
|
||||
}
|
||||
|
|
@ -412,7 +412,8 @@ namespace Server.Regions
|
|||
[Description("Sets the region spawners of all regions as not running.")]
|
||||
private static void StopAllRegionSpawns_OnCommand(CommandEventArgs args)
|
||||
{
|
||||
foreach (SpawnEntry entry in Table.Values) entry.Stop();
|
||||
foreach (SpawnEntry entry in Table.Values)
|
||||
entry.Stop();
|
||||
|
||||
args.Mobile.SendMessage("All region spawners have stopped.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue