Fixes dictionary uses (#7)

This commit is contained in:
Kamron Batman 2018-11-02 08:16:42 -07:00 • committed by GitHub
parent d4a52344f2
commit 916d404c51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
161 changed files with 1211 additions and 1722 deletions

View file

@ -110,50 +110,50 @@ namespace Server.Engines.Craft
public static int ItemIDOf(Type type)
{
if (!_itemIds.TryGetValue(type, out int itemId))
if (_itemIds.TryGetValue(type, out int itemId))
return itemId;
if (type == typeof(FactionExplosionTrap))
itemId = 14034;
else if (type == typeof(FactionGasTrap))
itemId = 4523;
else if (type == typeof(FactionSawTrap))
itemId = 4359;
else if (type == typeof(FactionSpikeTrap)) itemId = 4517;
if (itemId == 0)
{
if (type == typeof(FactionExplosionTrap))
itemId = 14034;
else if (type == typeof(FactionGasTrap))
itemId = 4523;
else if (type == typeof(FactionSawTrap))
itemId = 4359;
else if (type == typeof(FactionSpikeTrap)) itemId = 4517;
object[] attrs = type.GetCustomAttributes(typeof(CraftItemIDAttribute), false);
if (itemId == 0)
if (attrs.Length > 0)
{
object[] attrs = type.GetCustomAttributes(typeof(CraftItemIDAttribute), false);
if (attrs.Length > 0)
{
CraftItemIDAttribute craftItemID = (CraftItemIDAttribute)attrs[0];
itemId = craftItemID.ItemID;
}
CraftItemIDAttribute craftItemID = (CraftItemIDAttribute)attrs[0];
itemId = craftItemID.ItemID;
}
if (itemId == 0)
{
Item item = null;
try
{
item = Activator.CreateInstance(type) as Item;
}
catch
{
// ignored
}
if (item != null)
{
itemId = item.ItemID;
item.Delete();
}
}
_itemIds[type] = itemId;
}
if (itemId == 0)
{
Item item = null;
try
{
item = Activator.CreateInstance(type) as Item;
}
catch
{
// ignored
}
if (item != null)
{
itemId = item.ItemID;
item.Delete();
}
}
_itemIds[type] = itemId;
return itemId;
}
@ -1248,4 +1248,4 @@ namespace Server.Engines.Craft
#endregion
}
}
}

View file

@ -81,9 +81,7 @@ namespace Server.Engines.Craft
return null;
}
m_ContextTable.TryGetValue(m, out CraftContext c);
if (c == null)
if (!m_ContextTable.TryGetValue(m, out CraftContext c))
m_ContextTable[m] = c = new CraftContext();
return c;
@ -91,9 +89,7 @@ namespace Server.Engines.Craft
public void OnMade(Mobile m, CraftItem item)
{
CraftContext c = GetContext(m);
c?.OnMade(item);
GetContext(m)?.OnMade(item);
}
public virtual bool ConsumeOnFailure(Mobile from, Type resourceType, CraftItem craftItem)
@ -104,8 +100,8 @@ namespace Server.Engines.Craft
public void CreateItem(Mobile from, Type type, Type typeRes, BaseTool tool, CraftItem realCraftItem)
{
// Verify if the type is in the list of the craftable item
CraftItem craftItem = CraftItems.SearchFor(type);
if (craftItem != null) realCraftItem.Craft(from, this, typeRes, tool);
if (CraftItems.SearchFor(type) != null)
realCraftItem.Craft(from, this, typeRes, tool);
}
public int RandomRecipe()
@ -359,4 +355,4 @@ namespace Server.Engines.Craft
public abstract int CanCraft(Mobile from, BaseTool tool, Type itemType);
}
}
}