Exemplo n.º 1
0
    void Update()
    {
        if (!isLocalPlayer)
        {
            return;
        }

        if (!phase1Init)
        {
            CmdFetchPlayerInfo();
            phase1Init = true;
            return;
        }

        if (!phase2Init)
        {
            if (info == null)
            {
                return;
            }

            beltUI = GameObject.FindGameObjectWithTag("ItemBar").GetComponent <BeltInventoryUI> ();
            beltUI.loadInventory(info.belt);


            backpackUI = GameObject.FindGameObjectWithTag("BackpackUI").GetComponent <BackpackInventoryUI> ();
            equipUI    = GameObject.FindGameObjectWithTag("EquipUI").GetComponent <EquipMenuUI> ();
            if (info.backpack != null)
            {
                backpackUI.loadInventory(info.backpack.inventory);
            }

            equipUI.updateUI(info);

            phase2Init = true;
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            int  slotNum = beltUI.getSelectedSlotNumber();
            Item item    = info.belt.getSlots() [slotNum].getItem();
            if (item != null)
            {
                CmdUseItem(slotNum, MessageUtil.ToArray(item));
            }
        }
    }
Exemplo n.º 2
0
    void handleSlotSelect(ItemInventorySlotUI slotUI, string menuIdentifier, string slotIdentifier, int quantity)
    {
        InventoryOperationRequest.InventoryType menuType = InventoryOperationRequest.InventoryType.Ground;
        InventoryOperationRequest req = null;

        if (menuIdentifier.Equals("BeltSlot"))
        {
            menuType = InventoryOperationRequest.InventoryType.Belt;
        }
        else if (menuIdentifier.Equals("BackpackSlot"))
        {
            menuType = InventoryOperationRequest.InventoryType.Backpack;
        }
        else if (menuIdentifier.Equals("EquipSlot"))
        {
            menuType = InventoryOperationRequest.InventoryType.Equip;
        }


        if (slotUI == null)           //THREW IT ON THE GROUND
        {
            req = new InventoryOperationRequest(InventoryOperationRequest.Operation.FromCursor, InventoryOperationRequest.InventoryType.Ground, System.Int32.Parse(slotIdentifier), quantity);
        }
        else if (cursorSlot.getSlotBackingInfo().isEmpty())
        {
            req = new InventoryOperationRequest(InventoryOperationRequest.Operation.ToCursor, menuType, System.Int32.Parse(slotIdentifier), quantity);
        }
        else
        {
            req = new InventoryOperationRequest(InventoryOperationRequest.Operation.FromCursor, menuType, System.Int32.Parse(slotIdentifier), quantity);
        }

        //perform local changes before sending info to server. Annoying to wait on server for ui change. If sync error, server should let us know eventually and fix
        if (InventoryOperationRequest.validateRequest(req, localPlayer.info))            //perform check server will do to verify before performing locally
        {
            ItemInventorySlot dropped = InventoryOperationRequest.performInventoryRequest(req, localPlayer);

            if (!localPlayer.isServer)
            {
                sendInventoryUpdateToServer(req);
            }
            else
            {
                //host drops items
                if (!dropped.isEmpty())
                {
                    SpawnManager spawnManager = GameObject.FindGameObjectWithTag("SpawnManager").GetComponent <SpawnManager>();
                    spawnManager.SpawnPlayerDroppedItem(dropped.getItem(), dropped.getQuantity(), localPlayer.controller);
                }
            }

            cursorSlot.updateUI();

            switch (menuType)
            {
            case InventoryOperationRequest.InventoryType.Belt:
                beltUI.updateUI();
                break;

            case InventoryOperationRequest.InventoryType.Backpack:
                backpackUI.updateUI();
                break;

            case InventoryOperationRequest.InventoryType.Equip:
                if (slotIdentifier.Equals("6"))
                {
                    if (localPlayer.info.backpack == null)
                    {
                        backpackUI.loadInventory(null);
                    }
                    else
                    {
                        backpackUI.loadInventory(localPlayer.info.backpack.inventory);
                    }
                }
                equipUI.updateUI(localPlayer.info);
                break;
            }
        }
    }
Exemplo n.º 3
0
    public static bool PerformOperationWithBackpackUIUpdate(Player player, EquipmentOperation operation, BackpackInventoryUI invUI)
    {
        Item item = assertGoodItem(operation.itemData);

        if (item == null)
        {
            return(false);
        }

        switch (operation.op)
        {
        case Operation.SetHelmet:
            if (item is HelmetItem)
            {
                player.info.helmet = item as HelmetItem;
                return(true);
            }
            else
            {
                return(false);
            }

        case Operation.SetUpperBody:
            if (item is UpperBodyItem)
            {
                player.info.upperBody = item as UpperBodyItem;
                return(true);
            }
            else
            {
                return(false);
            }

        case Operation.SetLowerBody:
            if (item is LowerBodyItem)
            {
                player.info.lowerBody = item as LowerBodyItem;
                return(true);
            }
            else
            {
                return(false);
            }

        case Operation.SetBoots:
            if (item is BootsItem)
            {
                player.info.boots = item as BootsItem;
                return(true);
            }
            else
            {
                return(false);
            }

        case Operation.SetLeftClaw:
            if (item is ClawItem)
            {
                player.info.leftClaw = item as ClawItem;
                return(true);
            }
            else
            {
                return(false);
            }

        case Operation.SetRightClaw:
            if (item is ClawItem)
            {
                player.info.rightClaw = item as ClawItem;
                return(true);
            }
            else
            {
                return(false);
            }

        case Operation.SetBackpack:
            if (item is BackpackItem)
            {
                player.info.backpack = item as BackpackItem;
                if (invUI != null)
                {
                    invUI.loadInventory(player.info.backpack.inventory);
                }


                return(true);
            }
            else
            {
                return(false);
            }

        case Operation.SmartSet:
            return(smartEquip(item, player.info, invUI));

        default:
            Debug.Log("Unhandled EquipmentOperation case");
            return(false);
        }
    }
Exemplo n.º 4
0
    public bool EquipItem(EquipmentItem equip, bool rightSide)
    {
        if (equip is BackpackItem)
        {
            BackpackItem backpack = equip as BackpackItem;
            info.backpack = backpack;

            if (isLocalPlayer)
            {
                backpackUI.loadInventory(backpack.inventory);
                equipUI.setBackpack(equip as BackpackItem);
            }


            return(true);
        }
        else if (equip is HelmetItem)
        {
            info.helmet = equip as HelmetItem;

            if (isLocalPlayer)
            {
                equipUI.setHelmet(equip as HelmetItem);
            }

            return(true);
        }
        else if (equip is UpperBodyItem)
        {
            info.upperBody = equip as UpperBodyItem;

            if (isLocalPlayer)
            {
                equipUI.setUpperBody(equip as UpperBodyItem);
            }

            return(true);
        }
        else if (equip is LowerBodyItem)
        {
            info.lowerBody = equip as LowerBodyItem;

            if (isLocalPlayer)
            {
                equipUI.setLowerBody(equip as LowerBodyItem);
            }

            return(true);
        }
        else if (equip is BootsItem)
        {
            info.boots = equip as BootsItem;

            if (isLocalPlayer)
            {
                equipUI.setBoots(equip as BootsItem);
            }

            return(true);
        }
        else if (equip is ClawItem)
        {
            if (rightSide)
            {
                info.rightClaw = equip as ClawItem;

                if (isLocalPlayer)
                {
                    equipUI.setRightClaw(equip as ClawItem);
                }
            }
            else
            {
                info.leftClaw = equip as ClawItem;

                if (isLocalPlayer)
                {
                    equipUI.setLeftClaw(equip as ClawItem);
                }
            }
            return(true);
        }

        return(false);
    }
Exemplo n.º 5
0
    private static bool smartEquip(Item equip, PlayerInfo info, BackpackInventoryUI invUI)
    {
        if (equip is BackpackItem)
        {
            BackpackItem backpack = equip as BackpackItem;
            if (info.backpack == null)
            {
                info.backpack = backpack;
                if (invUI != null)
                {
                    invUI.loadInventory(info.backpack.inventory);
                }
                return(true);
            }
            return(false);
        }
        else if (equip is HelmetItem)
        {
            HelmetItem helmet = equip as HelmetItem;
            if (info.helmet == null)
            {
                info.helmet = helmet;
                return(true);
            }
            return(false);
        }
        else if (equip is UpperBodyItem)
        {
            UpperBodyItem upperBody = equip as UpperBodyItem;
            if (info.upperBody == null)
            {
                info.upperBody = upperBody;
                return(true);
            }
            return(false);
        }
        else if (equip is LowerBodyItem)
        {
            LowerBodyItem lowerBody = equip as LowerBodyItem;
            if (info.lowerBody == null)
            {
                info.lowerBody = lowerBody;
                return(true);
            }
            return(false);
        }
        else if (equip is BootsItem)
        {
            BootsItem boots = equip as BootsItem;
            if (info.boots == null)
            {
                info.boots = boots;
                return(true);
            }
            return(false);
        }
        else if (equip is ClawItem)
        {
            ClawItem claw = equip as ClawItem;
            if (info.rightClaw == null)
            {
                info.rightClaw = claw;
                return(true);
            }
            else if (info.leftClaw == null)
            {
                info.leftClaw = claw;
            }
            else
            {
                return(false);
            }
        }

        return(false);
    }