Ejemplo n.º 1
0
    public static NetworkInterfaceResponse HandleNetworkCommand(Player player, NetworkInterfaceCommand nic)
    {
        MSAccessPort port = nic.target as MSAccessPort;
        string       key  = nic.command;

        if (key != null)
        {
            if (key == InterfaceWithdrawItem)
            {
                int result;
                if (int.TryParse(nic.payload ?? "0", out result))
                {
                    MSAccessPortWindow.WithdrawItem(player, port, nic.itemContext, result);
                }
            }
            else if (key == InterfaceDepositItem)
            {
                int result;
                if (int.TryParse(nic.payload ?? "0", out result))
                {
                    MSAccessPortWindow.DepositItem(player, port, nic.itemContext, result);
                }
            }
        }
        return(new NetworkInterfaceResponse()
        {
            entity = port,
            inventory = player.mInventory
        });
    }
Ejemplo n.º 2
0
    public override bool ButtonClicked(string name, SegmentEntity targetEntity)
    {
        MSAccessPort port = targetEntity as MSAccessPort;

        if (name.Contains("itemicon"))
        {
            int slotNum = -1;
            int.TryParse(name.Replace("itemicon", ""), out slotNum); //Get slot name as number
            if (slotNum > -1)
            {
                //Enable Shift click and control click to only take 10/1 item at a time, default to whole stack
                int amount = 100;
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    amount = 10;
                }
                if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
                {
                    amount = 1;
                }

                // Set stack size for the withdraw and handle window refresh appropriately (restoring the empty slot as needed by redrawing)
                int      available;
                ItemBase item = this.GetItemForSlot(name, out available, port);
                if (item != null)
                {
                    item = item.NewInstance();
                }
                else
                {
                    Debug.LogWarning("MSAccessPort Attempted to withdraw null item?");
                    return(true);
                }
                if (item == null)
                {
                    Debug.LogWarning("accessport item wasn't null but new instance is!?");
                }
                if (amount < available && item.IsStack())
                {
                    ItemManager.SetItemCount(item, amount);
                    dirty = true;
                }
                else
                {
                    networkredraw = true;
                }

                if ((float)amount * port.mrTransportCost > port.mrCurrentPower)
                {
                    FloatingCombatTextManager.instance.QueueText(port.mnX, port.mnY + 1L, port.mnZ, 1f, "Low Power!", Color.red, 1.5f);
                    port.ErrorText   = "---INSUFFICIENT POWER---\n";
                    port.ErrorTime   = 1.5f;
                    port.ErrorResult = true;
                    return(true);
                }

                if (WithdrawMode)
                {
                    MSAccessPortWindow.WithdrawItem(WorldScript.mLocalPlayer, port, item, amount);
                    port.BuildInventoryList();
                }
                else
                {
                    MSAccessPortWindow.DepositItem(WorldScript.mLocalPlayer, port, item, amount);
                }

                return(true);
            }
        }
        else if (name == "modetoggle")
        {
            WithdrawMode = !WithdrawMode;
            this.manager.RedrawWindow();
        }

        return(false);
    }