public void ItemUseNotEnoughInCollectionTest() { var itemDef = new ItemDefinition(Guid.NewGuid()) { maxStackSize = 10 }; var item = new CollectionItemInstance(Guid.NewGuid(), itemDef); _collection.Set(0, item, 2); CollectionRemoveResult <IItemInstance> removeResult = null; int removeCallCount = 0; _collection.OnRemovedItem += (sender, result) => { removeResult = result; removeCallCount++; }; var context1 = new ItemContext { useAmount = 3 }; var usedResult = item.Use(null, context1); Assert.AreEqual(Errors.CollectionDoesNotContainItem, usedResult.error); Assert.AreEqual(0, removeCallCount); Assert.AreEqual(2, _collection.GetAmount(0)); }
public void ItemUseCollectionUpdateTest() { var itemDef = new ItemDefinition(Guid.NewGuid()) { maxStackSize = 10 }; var item = new CollectionItemInstance(Guid.NewGuid(), itemDef); var item2 = (CollectionItemInstance)item.Clone(); _collection.Set(0, item); _collection.Set(1, item2); CollectionRemoveResult <IItemInstance> removeResult = null; int removeCallCount = 0; _collection.OnRemovedItem += (sender, result) => { removeResult = result; removeCallCount++; }; var used = item.Use(null, new ItemContext()); Assert.IsNull(used.error); Assert.AreEqual(1, removeResult.affectedSlots[0].amount); Assert.AreEqual(1, removeCallCount); Assert.AreEqual(0, _collection.GetAmount(0)); Assert.IsNull(_collection[0]); }
public void BuyItemFromVendorMultipleCurrenciesTest() { var item = new CollectionItemInstance(Guid.NewGuid(), new ItemDefinition(Guid.NewGuid()) { maxStackSize = 5, buyPrice = new [] { new CurrencyDecorator(_gold, 1d), new CurrencyDecorator(_silver, 40d), }, sellPrice = new [] { new CurrencyDecorator(_gold, 1d), new CurrencyDecorator(_silver, 10d), } }); var product = ToProduct(item); _vendorCollection.Add(product, 3); _customerCurrencies.Add(_gold, 100); _customerCurrencies.Add(_silver, 100); var soldToVendor = _vendor.BuyFromVendor(_customer, product.item, 2); Assert.IsNull(soldToVendor.error); Assert.AreEqual(2d, _vendorCurrencies.GetAmount(_gold)); Assert.AreEqual(80d, _vendorCurrencies.GetAmount(_silver)); Assert.AreEqual(98d, _customerCurrencies.GetAmount(_gold)); Assert.AreEqual(20d, _customerCurrencies.GetAmount(_silver)); Assert.AreEqual(2, _customerCollection.GetAmount(item)); Assert.AreEqual(1, _vendorCollection.GetAmount(product)); }
public void Setup() { _vendorCollection = new Collection <IVendorProduct <IItemInstance> >(10); _vendorCurrencies = new CurrencyCollection(); _gold = new Currency(Guid.NewGuid(), "Gold", "GOLD", 2, 999f); _silver = new Currency(Guid.NewGuid(), "Silver", "SILVER", 2, 999f); _vendor = new Vendor <IItemInstance>(new VendorConfig(), _vendorCollection, _vendorCurrencies); _customerCollection = new Collection <IItemInstance>(10); _customerCurrencies = new CurrencyCollection(); _customer = new Customer <IItemInstance>(Guid.NewGuid(), null, new CollectionGroup <IItemInstance>(new [] { new CollectionGroup <IItemInstance> .Slot(_customerCollection), }), new CurrencyCollectionGroup <ICurrency>(_customerCurrencies)); _item1 = new CollectionItemInstance(Guid.NewGuid(), new ItemDefinition(Guid.NewGuid()) { maxStackSize = 5, buyPrice = new [] { new CurrencyDecorator(_gold, 1d) }, sellPrice = new [] { new CurrencyDecorator(_gold, 0.6d) } }); _item2 = new CollectionItemInstance(Guid.NewGuid(), new ItemDefinition(Guid.NewGuid()) { maxStackSize = 5, buyPrice = new [] { new CurrencyDecorator(_gold, 2d) }, sellPrice = new [] { new CurrencyDecorator(_gold, 1.6d) } }); _product1 = ToProduct(_item1); _product1_1 = ToProduct(_item1); _product2 = ToProduct(_item2); }
public void ItemUseNotInCollectionTest() { var itemDef = new ItemDefinition(Guid.NewGuid()) { maxStackSize = 10 }; var item = new CollectionItemInstance(Guid.NewGuid(), itemDef); // item.amountContainer.SetAmount(10); var used = item.Use(null, new ItemContext()); Assert.IsNull(used.error); Assert.AreEqual(1, used.result.usedAmount); }
public void SellItemWithoutPriceTest() { var itemWithoutBuyPrice = new CollectionItemInstance(Guid.NewGuid(), new ItemDefinition(Guid.NewGuid()) { maxStackSize = 5, buyPrice = new [] { new CurrencyDecorator(_gold, 10f) } }); _vendorCollection.Add(ToProduct(itemWithoutBuyPrice), 3); var canBuy = _vendor.CanSellToVendor(_customer, new VendorProduct <IItemInstance>(itemWithoutBuyPrice, itemWithoutBuyPrice.itemDefinition.buyPrice, itemWithoutBuyPrice.itemDefinition.sellPrice), 1); Assert.AreEqual(Errors.VendorProductHasNoPrice, canBuy.error); Assert.IsFalse(canBuy.result); }
public void SwapOrMergeSlotsChangedEventsTest() { var itemDef = new ItemDefinition(Guid.NewGuid()) { maxStackSize = 3 }; var item = new CollectionItemInstance(Guid.NewGuid(), itemDef); var item2 = new CollectionItemInstance(Guid.NewGuid(), itemDef); CollectionSlotsChangedResult changeResult = null; object changeObj = null; int changeCallCount = 0; var set1 = _collection.Set(0, item, 3); var set2 = _collection.Set(1, item2, 2); Assert.IsTrue(set1.result); Assert.IsTrue(set2.result); _collection.OnSlotsChanged += (sender, result) => { changeObj = sender; changeResult = result; changeCallCount++; }; var swap = _collection.SwapOrMerge(0, _collection, 1, 3); Assert.IsTrue(swap.result); Assert.AreSame(item2, _collection[0]); Assert.AreSame(item, _collection[1]); Assert.AreEqual(2, _collection.GetAmount(0)); Assert.AreEqual(3, _collection.GetAmount(1)); Assert.AreEqual(1, changeCallCount); Assert.AreSame(changeObj, _collection); Assert.AreEqual(2, changeResult.affectedSlots.Length); Assert.IsTrue(changeResult.affectedSlots.Contains(0)); Assert.IsTrue(changeResult.affectedSlots.Contains(1)); }
public void ItemUseAmountTest() { var itemDef = new ItemDefinition(Guid.NewGuid()) { maxStackSize = 10 }; var item = new CollectionItemInstance(Guid.NewGuid(), itemDef); var item2 = (CollectionItemInstance)item.Clone(); _collection.Set(0, item, 5); _collection.Set(1, item2, 4); var context1 = new ItemContext { useAmount = 3 }; var used = item.Use(null, context1); Assert.IsNull(used.error); Assert.AreEqual(3, used.result.usedAmount); Assert.AreEqual(2, _collection.GetAmount(0)); }
public void ItemUseAmountReadOnlyCollectionTest() { var itemDef = new ItemDefinition(Guid.NewGuid()) { maxStackSize = 10 }; var item = new CollectionItemInstance(Guid.NewGuid(), itemDef); var item2 = (CollectionItemInstance)item.Clone(); _collection.Set(0, item, 5); _collection.Set(1, item2, 4); var context1 = new ItemContext { useAmount = 3 }; _collection.isReadOnly = true; var used = item.Use(null, context1); Assert.AreEqual(Errors.CollectionIsReadOnly, used.error); Assert.AreEqual(5, _collection.GetAmount(0)); }
private static VendorProduct <IItemInstance> ToProduct(CollectionItemInstance item) { return(new VendorProduct <IItemInstance>(item, item.itemDefinition.buyPrice, item.itemDefinition.sellPrice)); }