Ejemplo n.º 1
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]);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
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));
        }