Exemplo n.º 1
0
    void buildSlots()
    {
        if (inventory == null)
        {
            return;
        }

        ItemInventorySlot[] slotBackings = inventory.getSlots();
        slots = new ItemInventorySlotUI[slotBackings.Length];

        for (int i = 0; i < slots.Length; i++)
        {
            int col = i % NUM_SLOTS_WIDTH;
            int row = i / NUM_SLOTS_WIDTH;

            GameObject iconObj = GameObject.Instantiate(inventorySlotPrefab, GetComponent <Transform> ());
            iconObj.name = "BackpackSlot " + i;
            RectTransform iconTrans = iconObj.GetComponent <RectTransform> ();
            iconTrans.localPosition = slotSeed.localPosition + new Vector3(slotSeed.rect.size.x * col, slotSeed.rect.size.y * row);
            ItemInventorySlotUI slot = iconObj.GetComponent <ItemInventorySlotUI> ();
            slot.setSlotBackingInfo(slotBackings[i]);
            slots [i] = slot;
        }
    }
Exemplo n.º 2
0
    public static bool validateRequest(InventoryOperationRequest request, PlayerInfo info)
    {
        BackpackInventory backpack = null;

        if (info.backpack != null)
        {
            backpack = info.backpack.inventory;
        }
        BeltInventory     belt   = info.belt;
        ItemInventorySlot cursor = info.cursorSlot;

        ItemInventorySlot swapSlot      = null;
        EquipmentItem     swapEquipItem = null;
        bool drop = false;

        switch (request.swapInv)
        {
        case InventoryType.Ground:
            drop = true;
            break;

        case InventoryType.Backpack:
            swapSlot = assertSlotExists(backpack.getSlots(), request.swapInvSlot);
            if (swapSlot == null)
            {
                Debug.Log("InventoryOperation validation error: trying to swap to bad backpack slot");
                return(false);
            }
            break;

        case InventoryType.Belt:
            swapSlot = assertSlotExists(belt.getSlots(), request.swapInvSlot);
            if (swapSlot == null)
            {
                Debug.Log("InventoryOperation validation error: trying to swap to bad belt slot");
                return(false);
            }
            break;

        case InventoryType.Equip:
            swapEquipItem = getEquipItem(info, request.swapInvSlot);
            break;

        default:
            Debug.Log("InventoryOperation validation error: unsupported inventory detected");
            return(false);
        }

        switch (request.op)
        {
        case Operation.ToCursor:
            return(validateToCursorOperation(swapSlot, swapEquipItem, request.quantity, info));

        case Operation.FromCursor:
            return(validateFromCursorOperation(swapSlot, swapEquipItem, request.swapInvSlot, drop, request.quantity, info));

        default:
            Debug.Log("InventoryOperation validation error: unsupported operation detected");
            return(false);
        }
    }