コード例 #1
0
        public bool FoundAndUpdatedEntry(InventoryObject.InventoryObjectItem _itm)
        {
            foreach (Control ec in Controls)
            {
                TestSlot tst = ec as TestSlot;
                if (tst != null && tst.assignedItem.ItemType == _itm.ItemType)
                {
                    if ((_itm.ItemType as AmmoItemType) != null)
                    {
                        tst.SetQuantity(_itm.Juice);
                    }
                    else
                    {
                        tst.SetQuantity(tst.quantity + 1);
                        unassigned_itms.Add(_itm);
                    }

                    return(true);
                }
            }

            return(false);
        }
コード例 #2
0
        void SetSlot(SlotHolder _sender, SlotHolder _receiver)
        {
            if (_receiver.holderType > SlotHolder.HolderType.Inventory)
            {
                //TODO: SWAP ITEMS IN INVENTORY
                if (_receiver.Controls.Count != 0)
                {
                    return;
                }

                //TODO: MAKE RECEIVER CHECK FOR ITEM TYPE

                VBCharacter chSnd = _sender.owner as VBCharacter;
                switch (_receiver.holderType)
                {
                case SlotHolder.HolderType.Armor:
                    //set player armor
                    break;

                case SlotHolder.HolderType.Slot1:
                    if (chSnd != null)
                    {
                        chSnd.SetItem(assignedItem, true);
                    }
                    break;

                case SlotHolder.HolderType.Slot2:
                    if (chSnd != null)
                    {
                        chSnd.SetItem(assignedItem, false);
                    }
                    break;

                case SlotHolder.HolderType.Drop:
                    _sender.owner.DropItem(assignedItem);
                    break;
                }
            }
            else
            {
                if (_sender.holderType == SlotHolder.HolderType.Inventory)
                {
                    if (_receiver.owner.CanHoldItem(assignedItem.ItemType))
                    {
                        _sender.owner.Inventory.Remove(assignedItem);
                        _receiver.owner.Inventory.Add(assignedItem);
                    }
                    else
                    {
                        return;  //full stop
                    }
                }
            }

            //TODO: THE PROBLEM WITH THIS SYSTEM IS THAT OBJECTS CANNOT BE SWAPPED BETWEEN SLOTS, INSTEAD OF NOT ACCEPTING THE NEW HOLDER REMOVE THE PREVIOUS ONE

            //if my sender is on primary or secondary reset its slot
            VBCharacter chRec = _receiver.owner as VBCharacter;

            if (chRec != null)
            {
                if (_sender.holderType == SlotHolder.HolderType.Slot1)
                {
                    chRec.ResetSlot(true);
                }

                if (_sender.holderType == SlotHolder.HolderType.Slot2)
                {
                    chRec.ResetSlot(false);
                }
            }

            //if my quantity is > 1, then instead of swapping the slot, add a new identical one to the receiver
            //and decrease the quntity to the initial one while strring the new one to 0

            if (quantity > 1 && (assignedItem.ItemType as AmmoItemType) == null)
            {
                if (_receiver.holderType != SlotHolder.HolderType.Drop)
                {
                    //create a new and identical slot but with the assigned item of the other object
                    TestSlot stmp = new TestSlot(_sender.GetFirstOfTypeUnassignedItem(assignedItem.ItemType));
                    _receiver.Controls.Add(stmp);
                }

                SetQuantity(quantity - 1);
            }
            else
            {
                Position = new ScaleValue(ScaleType.ScaleByResolution, Vec2.Zero);
                Parent.Controls.Remove(this);

                if (_receiver.holderType != SlotHolder.HolderType.Drop && !_receiver.FoundAndUpdatedEntry(assignedItem))
                {
                    _receiver.Controls.Add(this);
                }
            }
        }