private IItemCraftingHandler CreateCraftingHandler(ItemCrafting crafting) { if (crafting.ItemCraftingHandlerClassName != null) { var type = Type.GetType(crafting.ItemCraftingHandlerClassName); if (type != null) { if (type.BaseType == typeof(SimpleItemCraftingHandler)) { return((IItemCraftingHandler)Activator.CreateInstance(type, crafting.SimpleCraftingSettings)); } return((IItemCraftingHandler)Activator.CreateInstance(type)); } throw new ArgumentException($"Item crafting handler '{crafting.ItemCraftingHandlerClassName}' not found.", nameof(crafting)); } if (crafting.SimpleCraftingSettings != null) { return(new SimpleItemCraftingHandler(crafting.SimpleCraftingSettings)); } throw new ArgumentException("No simple crafting settings or item crafting handler name specified.", nameof(crafting)); }
private IItemCraftingHandler CreateCraftingHandler(Player player, ItemCrafting crafting) { if (crafting.SimpleCraftingSettings != null) { return(new SimpleItemCraftingHandler(crafting.SimpleCraftingSettings)); } if (crafting.ItemCraftingHandlerClassName != null) { var type = Type.GetType(crafting.ItemCraftingHandlerClassName); if (type != null) { return(Activator.CreateInstance(type, player.GameContext) as IItemCraftingHandler); } throw new ArgumentException($"Item crafting handler '{crafting.ItemCraftingHandlerClassName}' not found.", nameof(crafting)); } throw new ArgumentException("No simple crafting settings or item crafting handler name specified.", nameof(crafting)); }
/// <summary> /// Mixes the items at the currently opened Monster crafter. /// </summary> /// <param name="player">The player.</param> /// <param name="mixTypeId">The mix type identifier.</param> public void MixItems(Player player, byte mixTypeId) { var npcStats = player.OpenedNpc.Definition; ItemCrafting crafting = npcStats?.ItemCraftings.FirstOrDefault(c => c.Number == mixTypeId); if (crafting == null) { return; } IItemCraftingHandler craftingHandler; if (!this.craftingHandlerCache.TryGetValue(crafting, out craftingHandler)) { craftingHandler = this.CreateCraftingHandler(crafting); this.craftingHandlerCache.Add(crafting, craftingHandler); } craftingHandler.DoMix(player); }