fix: Don't crash the world if a stealable artifact fails to construct (#789)

This commit is contained in:
Kamron Batman 2021-09-16 23:55:37 -07:00 committed by GitHub
parent fd440f29ce
commit b6641c4853
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,11 +1,14 @@
using System;
using System.Collections.Generic;
using Server.Logging;
using Server.Utilities;
namespace Server.Items
{
public class StealableArtifactsSpawner : Item
{
private static readonly ILogger logger = LogFactory.GetLogger(typeof(StealableArtifactsSpawner));
private static Type[] m_TypesOfEntries;
private StealableInstance[] m_Artifacts;
@ -342,17 +345,25 @@ namespace Server.Items
public Item CreateInstance()
{
var item = Type.CreateInstance<Item>();
if (Hue > 0)
try
{
item.Hue = Hue;
var item = Type.CreateInstance<Item>();
if (Hue > 0)
{
item.Hue = Hue;
}
item.Movable = false;
item.MoveToWorld(Location, Map);
return item;
}
catch (Exception e)
{
logger.Warning(e, $"Failed to construct stealable artifact: {Type.FullName}");
return null;
}
item.Movable = false;
item.MoveToWorld(Location, Map);
return item;
}
}