Some cleanup of contains keys and try get values (#246)
This commit is contained in:
parent
9cbb0cfd23
commit
a236617ad9
69 changed files with 3508 additions and 350 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue