/// <summary> /// Initializes a new instance of the <see cref="Item"/> class. /// </summary> /// <param name="meta">Non-NULL instance of the <see cref="ItemMeta"/> that is represented by this instance.</param> /// <param name="itemServices">Non-NULL instance of <see cref="AggregatedItemServices"/> which are necessary for this <see cref="Item"/>.</param> protected Item(ItemMeta meta, AggregatedItemServices itemServices) { if (meta == null) { throw new ArgumentNullException(nameof(meta)); } this.ItemMergeStrategyHandler = itemServices.ItemMergeStrategyHandler; this.ItemSplitStrategyHandler = itemServices.ItemSplitStrategyHandler; this.itemFactory = itemServices.ItemFactory; this.RuntimeId = Guid.NewGuid(); this.Meta = meta; var(valid, errorMessage) = this.ValidateMeta(); if (valid == false) { throw new ArgumentException(errorMessage, nameof(meta)); } this.SingleWeight = this.Meta.DefaultWeight; this.Handle = this.Meta.Handle; this.DefaultDisplayName = this.Meta.DisplayName; this.Stackable = (this.Meta.Flags & ItemFlags.NotStackable) == 0; this.WeightChangable = (this.Meta.Flags & ItemFlags.WeightChangable) != 0; this.displayName = this.DefaultDisplayName; this.Amount = Math.Max(MinimalItemAmount, 1); }
public void CreatingAggregatedInventoryServiceSetsRightNullValues() { var service = new AggregatedItemServices(null, null, null); service.ItemMergeStrategyHandler.Should().BeNull(); service.ItemSplitStrategyHandler.Should().BeNull(); service.ItemFactory.Should().BeNull(); }
public void CreatingAggregatedInventoryServiceSetsRightValues() { var itemMergeHandler = new Mock <IItemMergeStrategyHandler>(); var itemSplitHandler = new Mock <IItemSplitStrategyHandler>(); var itemFactory = new Mock <IItemFactory>(); var service = new AggregatedItemServices(itemMergeHandler.Object, itemSplitHandler.Object, itemFactory.Object); Assert.AreEqual(itemMergeHandler.Object, service.ItemMergeStrategyHandler); Assert.AreEqual(itemSplitHandler.Object, service.ItemSplitStrategyHandler); service.ItemFactory.Should().Be(itemFactory.Object); }
protected void SetupServiceProvider(params ItemMeta[] itemMetas) { this.SetupDependencies(); foreach (var itemMeta in itemMetas) { this.ItemRegistry.AddItemMeta(itemMeta); } this.ServiceCollection.AddItemTypes(this.ItemRegistry); this.ServiceProvider = this.ServiceCollection.BuildServiceProvider(); this.ItemFactory = this.ServiceProvider.GetRequiredService <IItemFactory>(); this.ItemServices = this.ServiceProvider.GetRequiredService <AggregatedItemServices>(); this.InventoryFactory = this.ServiceProvider.GetRequiredService <IInventoryFactory>(); this.InventoryServices = this.ServiceProvider.GetRequiredService <AggregatedInventoryServices>(); this.ItemSplitStrategyHandler = this.ServiceProvider.GetRequiredService <IItemSplitStrategyHandler>(); this.ItemMergeStrategyHandler = this.ServiceProvider.GetRequiredService <IItemMergeStrategyHandler>(); this.Item = (Item)this.ItemFactory.CreateItem(itemMetas.First(), 1); this.Inventory = this.InventoryFactory.CreateInventory(100); }
public WaterItem(ItemMeta meta, AggregatedItemServices itemServices) : base(meta, itemServices) { }
/// <summary> /// Initializes a new instance of the <see cref="ActionableItem{TOut,TIn}"/> class. /// </summary> /// <param name="meta">Non-NULL instance of the <see cref="ItemMeta"/> that is represented by this instance.</param> /// <param name="itemServices">Non-NULL instance of <see cref="AggregatedItemServices"/> which are necessary for this <see cref="Item"/>.</param> protected ActionableItem(ItemMeta meta, AggregatedItemServices itemServices) : base(meta, itemServices) { this.actions = new ConcurrentDictionary <Guid, IItemAction <TOut, TIn> >(); }
public RealActionItem(ItemMeta meta, AggregatedItemServices itemServices) : base(meta, itemServices) { }