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

@ -16,7 +16,9 @@ namespace Server.Engines.Craft
CraftItem = item;
if (Recipes.ContainsKey(id))
{
throw new Exception("Attempting to create recipe with preexisting ID.");
}
Recipes.Add(id, this);
LargestRecipeID = Math.Max(id, LargestRecipeID);

View file

@ -33,18 +33,20 @@ namespace Server.Engines.Spawners
for (var i = 0; i < count; ++i)
// IEntity e = World.FindEntity( reader.ReadInt() );
{
if (reader.ReadEntity() is ISpawnable e)
{
e.Spawner = parent;
if (e is BaseCreature creature)
{
creature.RemoveIfUntamed = true;
}
Spawned.Add(e);
if (!parent.Spawned.ContainsKey(e))
parent.Spawned.Add(e, this);
parent.Spawned.TryAdd(e, this);
}
}
}
[JsonPropertyName("probability")] public int SpawnedProbability { get; set; }
@ -81,11 +83,17 @@ namespace Server.Engines.Spawners
object o = Spawned[i];
if (o is Item item)
{
writer.Write(item);
}
else if (o is Mobile mobile)
{
writer.Write(mobile);
}
else
{
writer.Write(Serial.MinusOne);
}
}
}