示例#1
0
    public int removeManyFromSlot(int quantity, int slotNum)
    {
        if (slotNum >= slots.Length || slotNum < 0)
        {
            return(-1);
        }

        ItemInventorySlot s = slots [slotNum];

        return(s.removeMany(quantity));
    }
    //returns items to be dropped/spawned
    public static ItemInventorySlot performInventoryRequest(InventoryOperationRequest request, Player p)
    {
        switch (request.op)
        {
        case InventoryOperationRequest.Operation.ToCursor:
            switch (request.swapInv)
            {
            case InventoryOperationRequest.InventoryType.Belt:
                ItemInventorySlot beltslot = p.info.belt.getSlots() [request.swapInvSlot];
                ItemInventorySlot tempSlot = new ItemInventorySlot();
                if (request.quantity <= 0)
                {
                    tempSlot.setSlot(beltslot.getItem(), beltslot.getQuantity());
                    beltslot.setSlot(p.info.cursorSlot.getItem(), p.info.cursorSlot.getQuantity());
                    p.info.cursorSlot.setSlot(tempSlot.getItem(), tempSlot.getQuantity());
                }
                else
                {
                    p.info.cursorSlot.addItemMany(beltslot.getItem(), request.quantity);
                    beltslot.removeMany(request.quantity);
                }
                break;

            case InventoryOperationRequest.InventoryType.Backpack:
                ItemInventorySlot backpackslot = p.info.backpack.inventory.getSlots() [request.swapInvSlot];
                ItemInventorySlot tempSlot2    = new ItemInventorySlot();
                if (request.quantity <= 0)
                {
                    tempSlot2.setSlot(backpackslot.getItem(), backpackslot.getQuantity());
                    backpackslot.setSlot(p.info.cursorSlot.getItem(), p.info.cursorSlot.getQuantity());
                    p.info.cursorSlot.setSlot(tempSlot2.getItem(), tempSlot2.getQuantity());
                }
                else
                {
                    p.info.cursorSlot.addItemMany(backpackslot.getItem(), request.quantity);
                    backpackslot.removeMany(request.quantity);
                }
                break;

            case InventoryOperationRequest.InventoryType.Equip:
                switch ((InventoryOperationRequest.EquipSlots)request.swapInvSlot)
                {
                case InventoryOperationRequest.EquipSlots.Helmet:
                    p.info.cursorSlot.setSlot(p.info.helmet, 1);
                    p.info.helmet = null;
                    break;

                case InventoryOperationRequest.EquipSlots.UpperBody:
                    p.info.cursorSlot.setSlot(p.info.upperBody, 1);
                    p.info.upperBody = null;
                    break;

                case InventoryOperationRequest.EquipSlots.LowerBody:
                    p.info.cursorSlot.setSlot(p.info.lowerBody, 1);
                    p.info.lowerBody = null;
                    break;

                case InventoryOperationRequest.EquipSlots.Boots:
                    p.info.cursorSlot.setSlot(p.info.boots, 1);
                    p.info.boots = null;
                    break;

                case InventoryOperationRequest.EquipSlots.RightClaw:
                    p.info.cursorSlot.setSlot(p.info.rightClaw, 1);
                    p.info.rightClaw = null;
                    break;

                case InventoryOperationRequest.EquipSlots.LeftClaw:
                    p.info.cursorSlot.setSlot(p.info.leftClaw, 1);
                    p.info.leftClaw = null;
                    break;

                case InventoryOperationRequest.EquipSlots.Backpack:
                    p.info.cursorSlot.setSlot(p.info.backpack, 1);
                    p.info.backpack = null;
                    break;
                }
                break;
            }
            break;

        case InventoryOperationRequest.Operation.FromCursor:

            Item cursorItem = p.info.cursorSlot.getItem();

            switch (request.swapInv)
            {
            //if moving to an inventory slot, slot is either empty or has the item in it already.
            case InventoryOperationRequest.InventoryType.Belt:
                ItemInventorySlot beltslot = p.info.belt.getSlots() [request.swapInvSlot];

                if (request.quantity == 0)
                {
                    if (!p.info.cursorSlot.getItem().IsSameType(beltslot.getItem()))
                    {
                        ItemInventorySlot tempSlot = new ItemInventorySlot();
                        tempSlot.setSlot(beltslot.getItem(), beltslot.getQuantity());
                        beltslot.setSlot(p.info.cursorSlot.getItem(), p.info.cursorSlot.getQuantity());
                        p.info.cursorSlot.setSlot(tempSlot.getItem(), tempSlot.getQuantity());
                    }
                    else
                    {
                        int remainder = beltslot.addItemMany(cursorItem, p.info.cursorSlot.getQuantity());
                        p.info.cursorSlot.removeMany(p.info.cursorSlot.getQuantity() - remainder);
                    }
                }
                else
                {
                    beltslot.addItemMany(cursorItem, request.quantity);
                    p.info.cursorSlot.removeMany(request.quantity);
                }
                break;

            case InventoryOperationRequest.InventoryType.Backpack:
                ItemInventorySlot backpackslot = p.info.backpack.inventory.getSlots() [request.swapInvSlot];


                if (request.quantity == 0)
                {
                    if (!p.info.cursorSlot.getItem().IsSameType(backpackslot.getItem()))
                    {
                        ItemInventorySlot tempSlot2 = new ItemInventorySlot();
                        tempSlot2.setSlot(backpackslot.getItem(), backpackslot.getQuantity());
                        backpackslot.setSlot(p.info.cursorSlot.getItem(), p.info.cursorSlot.getQuantity());
                        p.info.cursorSlot.setSlot(tempSlot2.getItem(), tempSlot2.getQuantity());
                    }
                    else
                    {
                        int remainder = backpackslot.addItemMany(cursorItem, p.info.cursorSlot.getQuantity());
                        p.info.cursorSlot.removeMany(p.info.cursorSlot.getQuantity() - remainder);
                    }
                }
                else
                {
                    backpackslot.addItemMany(cursorItem, request.quantity);
                    p.info.cursorSlot.removeMany(request.quantity);
                }
                break;

            case InventoryOperationRequest.InventoryType.Equip:
                switch ((InventoryOperationRequest.EquipSlots)request.swapInvSlot)
                {
                case InventoryOperationRequest.EquipSlots.Helmet:
                    Item tempHelmet = p.info.helmet;
                    p.info.helmet = p.info.cursorSlot.getItem() as HelmetItem;
                    p.info.cursorSlot.setSlot(tempHelmet, 1);
                    break;

                case InventoryOperationRequest.EquipSlots.UpperBody:
                    Item tempUpperBody = p.info.upperBody;
                    p.info.upperBody = p.info.cursorSlot.getItem() as UpperBodyItem;
                    p.info.cursorSlot.setSlot(tempUpperBody, 1);
                    break;

                case InventoryOperationRequest.EquipSlots.LowerBody:
                    Item tempLowerBody = p.info.lowerBody;
                    p.info.lowerBody = p.info.cursorSlot.getItem() as LowerBodyItem;
                    p.info.cursorSlot.setSlot(tempLowerBody, 1);
                    break;

                case InventoryOperationRequest.EquipSlots.Boots:
                    Item tempBoots = p.info.boots;
                    p.info.boots = p.info.cursorSlot.getItem() as BootsItem;
                    p.info.cursorSlot.setSlot(tempBoots, 1);
                    break;

                case InventoryOperationRequest.EquipSlots.RightClaw:
                    Item tempRightClaw = p.info.rightClaw;
                    p.info.rightClaw = p.info.cursorSlot.getItem() as ClawItem;
                    p.info.cursorSlot.setSlot(tempRightClaw, 1);
                    break;

                case InventoryOperationRequest.EquipSlots.LeftClaw:
                    Item tempLeftClaw = p.info.leftClaw;
                    p.info.leftClaw = p.info.cursorSlot.getItem() as ClawItem;
                    p.info.cursorSlot.setSlot(tempLeftClaw, 1);
                    break;

                case InventoryOperationRequest.EquipSlots.Backpack:
                    Item tempBackpack = p.info.backpack;
                    p.info.backpack = p.info.cursorSlot.getItem() as BackpackItem;
                    p.info.cursorSlot.setSlot(tempBackpack, 1);
                    break;
                }
                break;

            case InventoryOperationRequest.InventoryType.Ground:
                ItemInventorySlot dropped = new ItemInventorySlot();
                if (request.quantity == 0)
                {
                    dropped.setSlot(p.info.cursorSlot.getItem(), p.info.cursorSlot.getQuantity());
                    p.info.cursorSlot.removeMany(p.info.cursorSlot.getQuantity());
                }
                else
                {
                    dropped.setSlot(p.info.cursorSlot.getItem(), request.quantity);
                    p.info.cursorSlot.removeMany(request.quantity);
                }
                return(dropped);
            }
            break;
        }
        return(new ItemInventorySlot());
    }