示例#1
0
        protected override DereferenceResult Perform(Inventory reference, FieldInfo field, List <ReferenceWrapper> objects)
        {
            if (Matches(reference, "mItems", field, objects))
            {
                InventoryItem item = Find <InventoryItem>(objects);
                if (item != null)
                {
                    if (Performing)
                    {
                        InventoryStack stack = Find <InventoryStack>(objects);
                        if (stack != null)
                        {
                            try
                            {
                                reference.RemoveInternal(item, false, stack);
                            }
                            catch (Exception e)
                            {
                                Common.DebugException(item.Object, e);
                            }
                        }
                    }

                    return(DereferenceResult.End);
                }
            }

            if (Matches(reference, "Owner", field, objects))
            {
                Remove(ref reference.Owner);
                return(DereferenceResult.End);
            }

            return(DereferenceResult.Failure);
        }
示例#2
0
        public static bool GetIfEquipped(Player player, InventoryStack stack)
        {
            if (!(stack.TopItem is IEquipableItem equipable))
            {
                return(false);
            }

            return(player.Equipment.IsEquiped(equipable));
        }
示例#3
0
        /// <inheritdoc />
        public void Collect(InventoryStack stack)
        {
            if (stack.IsEmpty)
            {
                return;
            }

            var remainder = _player.Inventory.AddToStorage(stack);
            // TODO do something with the remainder
        }
示例#4
0
        public void Fill_in_non_empty_other_slot_returns_the_original()
        {
            var contentsOfSlotZero = new InventoryStack(_model3, 30);

            Assert.AreEqual(contentsOfSlotZero, Get(0));

            var remaining = _container.Fill(_container.GetCursor(0), new InventoryStack(_model1, 5));

            Assert.AreEqual(contentsOfSlotZero, Get(0));

            // put value is returned
            Assert.AreEqual(new InventoryStack(_model1, 5), remaining);
        }
示例#5
0
        public void Put_in_a_non_empty_slot_returns_the_original_amount()
        {
            var contentsOfSlotZero = new InventoryStack(_model3, 30);

            Assert.Equal(contentsOfSlotZero, Get(0));

            var remaining = _container.Put(_container.GetCursor(0), new InventoryStack(_model1, 5));

            Assert.Equal(contentsOfSlotZero, Get(0));

            // put value is returned
            Assert.Equal(new InventoryStack(_model1, 5), remaining);
        }
示例#6
0
        private static bool AddInternal(Inventory ths, IGameObject obj, uint stackNumber, bool testPurge)
        {
            InventoryStack stack = ths.GetStack(ref stackNumber);

            try
            {
                return(ths.AddInternal(obj, stackNumber, stack, testPurge) != null);
            }
            catch (Exception e)
            {
                Common.Exception(ths.Owner, obj, e);
                return(false);
            }
        }
示例#7
0
        private static string GetEquippedText(Player player, InventoryStack stack)
        {
            if (!(stack.TopItem is IEquipableItem equipable))
            {
                return(null);
            }

            if (!player.Equipment.IsEquiped(equipable))
            {
                return(null);
            }

            if (!(equipable is IHoldableItem holdableItem))
            {
                return(EquippedText);
            }

            if (player.Equipment.LeftHandItem.Equals(holdableItem))
            {
                return(EquippedLeftText);
            }

            return(EquippedRightText);
        }
示例#8
0
 protected InventoryStackItem(InventoryStack stack)
 {
     Stack = stack;
 }
示例#9
0
 protected abstract InventoryStackItem CreateListBoxItem(InventoryStack stack);
示例#10
0
 public PlayerInventoryItem(InventoryStack itemStack, Player player)
     : base(itemStack)
 {
     this.player = player;
 }
示例#11
0
 protected override InventoryStackItem CreateListBoxItem(InventoryStack stack)
 {
     return(new PlayerInventoryItem(stack, Player));
 }
示例#12
0
 public CustomInventoryItem(InventoryStack itemStack)
     : base(itemStack)
 {
 }