/// <summary>
    /// Called when a player retrieves a hacking device from the panel.
    /// </summary>
    /// <param name="playerScript"></param>
    /// <param name="hackDevice"></param>
    public virtual void ServerPlayerRemoveHackingDevice(PlayerScript playerScript, HackingDevice hackDevice)
    {
        Pickupable item     = hackDevice.GetComponent <Pickupable>();
        ItemSlot   handSlot = playerScript.Equipment.ItemStorage.GetActiveHandSlot();
        Pickupable handItem = handSlot.Item;

        if (handItem == null)
        {
            Inventory.ServerPerform(InventoryMove.Transfer(item.ItemSlot, handSlot));
        }
    }
    /// <summary>
    /// Removes a hacking device from the panel. Usually called in conjunction with ServerPlayerRemoveHackingDevice if called serverside. Can be called clientside, but will only modify clientside devices.
    /// </summary>
    /// <param name="device"></param>
    public virtual void RemoveHackingDevice(HackingDevice device)
    {
        devices.Remove(device);
        hackNodes.Remove(device.InputNode);

        //Ensure that nothing is connected to the device when it's removed.
        hackNodes.ForEach(x => x.RemoveConnectedNode(device.InputNode));

        device.OutputNode.RemoveAllConnectedNodes();
        hackNodes.Remove(device.OutputNode);
    }
	public void AttemptAddDevice()
	{
		Pickupable handItem = PlayerManager.LocalPlayerScript.Equipment.ItemStorage.GetActiveHandSlot().Item;
		if (handItem != null)
		{
			HackingDevice hackDevice = handItem.GetComponent<HackingDevice>();
			if (hackDevice != null)
			{
				AddHackingDevice.Send(PlayerManager.LocalPlayerScript.gameObject, hackProcess.gameObject, hackDevice.gameObject);
			}
		}
	}
Example #4
0
    //In theory, this should sync devices between server and client. In practice, I worry there may be a race condition, so, watch out for that I guess.

    /// <summary>
    /// Function to update devices from observed slots in storage. Mostly used on client.
    /// </summary>
    public void UpdateDevices()
    {
        hackProcess.RemoveAllDevices();
        foreach (ItemSlot deviceSlot in hackProcess.ItemStorage.GetItemSlots())
        {
            Pickupable devicePickup = deviceSlot.Item;
            if (devicePickup != null)
            {
                HackingDevice device = devicePickup.GetComponent <HackingDevice>();
                hackProcess.AddHackingDevice(device);
            }
        }
    }
    /// <summary>
    /// Called when we want to store a device in the hacking panel.
    /// </summary>
    /// <param name="hackDevice"></param>
    public virtual void ServerStoreHackingDevice(HackingDevice hackDevice)
    {
        Pickupable item = hackDevice.GetComponent <Pickupable>();

        if (item.ItemSlot != null)
        {
            Inventory.ServerPerform(InventoryMove.Transfer(item.ItemSlot, itemStorage.GetBestSlotFor(item)));
        }
        else
        {
            Inventory.ServerPerform(InventoryMove.Add(item, itemStorage.GetBestSlotFor(item)));
        }
    }
	public void RemoveDevice(GUI_HackingDevice deviceUI)
	{
		HackingDevice hackDevice = null;
		foreach( ItemSlot itemSlot in hackProcess.ItemStorage.GetItemSlots())
		{
			if (itemSlot.Item != null && itemSlot.Item.GetComponent<HackingDevice>().Equals(deviceUI.Device))
			{
				hackDevice = itemSlot.Item.GetComponent<HackingDevice>();
			}
		}

		RemoveHackingDevice.Send(PlayerManager.LocalPlayerScript.gameObject, hackProcess.gameObject, hackDevice.gameObject);
	}
Example #7
0
    private void GenerateDeviceNodeUI()
    {
        foreach (ItemSlot itemSlot in hackProcess.ItemStorage.GetItemSlots())
        {
            HackingDevice device = itemSlot.Item != null?itemSlot.Item.GetComponent <HackingDevice>() : null;

            if (device == null)
            {
                continue;
            }

            GameObject    devicePanel = Instantiate(hackingDeviceUIPrefab, hackingDeviceLayout);
            RectTransform deviceRect  = devicePanel.transform as RectTransform;
            deviceRect.sizeDelta = deviceCellSize;

            GUI_HackingDevice GUIDevice = devicePanel.GetComponent <GUI_HackingDevice>();
            GUIDevice.SetHackingDevice(device);

            ForceLayoutGroupUpdates();

            /////////////////////////Adding Input Node For Device/////////////////////////
            GameObject    inputNodeUIObject = Instantiate(inputHackingNodeUIPrefab, GUIDevice.transform);
            RectTransform inNodeRect        = inputNodeUIObject.transform as RectTransform;
            inNodeRect.sizeDelta = deviceNodeCellSize;
            inputNodeUIObject.transform.position = (Vector2)devicePanel.transform.position - new Vector2(0, deviceCellSize.y / 3);

            GUI_HackingNode inputNodeGUI = inputNodeUIObject.GetComponent <GUI_HackingNode>();
            inputNodeGUI.SetHackingNode(device.InputNode);

            inputNodeUIObjects.Add(inputNodeGUI);
            nodeUIObjects.Add(inputNodeGUI);
            /////////////////////////////////////////////////////////////////////////////


            /////////////////////////Adding Output Node For Device/////////////////////////
            GameObject    outputNodeUIObject = Instantiate(outputHackingNodeUIPrefab, GUIDevice.transform);
            RectTransform outNodeRect        = outputNodeUIObject.transform as RectTransform;
            outNodeRect.sizeDelta = deviceNodeCellSize;
            outputNodeUIObject.transform.position = (Vector2)devicePanel.transform.position + new Vector2(0, deviceCellSize.y / 3);

            GUI_HackingNode outputNodeGUI = outputNodeUIObject.GetComponent <GUI_HackingNode>();
            outputNodeGUI.SetHackingNode(device.OutputNode);

            outputNodeUIObjects.Add(outputNodeGUI);
            nodeUIObjects.Add(outputNodeGUI);
            /////////////////////////////////////////////////////////////////////////////

            hackingDevices.Add(GUIDevice);
        }
    }
    /// <summary>
    /// Checks to see if a player can remove a device from the panel. By default, only checks if they're in each and the wires are exposed.
    /// </summary>
    /// <param name="playerScript"></param>
    /// <param name="device"></param>
    /// <returns></returns>
    public virtual bool ServerPlayerCanRemoveDevice(PlayerScript playerScript, HackingDevice device)
    {
        if (!playerScript.IsInReach(gameObject, true))
        {
            return(false);
        }

        if (!WiresExposed)
        {
            return(false);
        }

        return(true);
    }
    /// <summary>
    /// Check to see if a player can add a device to the panel. By default, only checks if they're in reach and the wires are exposed.
    /// </summary>
    /// <param name="playerScript"></param>
    /// <param name="device"></param>
    /// <returns></returns>
    public virtual bool ServerPlayerCanAddDevice(PlayerScript playerScript, HackingDevice device)
    {
        if (!playerScript.IsGameObjectReachable(gameObject, true, context: gameObject))
        {
            return(false);
        }

        if (!WiresExposed)
        {
            return(false);
        }

        return(true);
    }
Example #10
0
    private void EnsureInit()
    {
        if (pickupable != null)
        {
            return;
        }

        pickupable   = GetComponent <Pickupable>();
        itemAtts     = GetComponent <ItemAttributesV2>();
        registerTile = GetComponent <RegisterTile>();

        radioMessager = GetComponent <RadioMessager>();
        radioReceiver = GetComponent <RadioReceiver>();

        hackDevice = GetComponent <HackingDevice>();
    }
    public override void Process()
    {
        LoadMultipleObjects(new uint[] { Player, HackableObject, HackingDevice });

        var                playerScript   = NetworkObjects[0].GetComponent <PlayerScript>();
        var                hackObject     = NetworkObjects[1];
        HackingDevice      hackDevice     = NetworkObjects[2].GetComponent <HackingDevice>();
        HackingProcessBase hackingProcess = hackObject.GetComponent <HackingProcessBase>();

        if (hackingProcess.ServerPlayerCanAddDevice(playerScript, hackDevice))
        {
            hackingProcess.AddHackingDevice(hackDevice);
            hackingProcess.ServerStoreHackingDevice(hackDevice);
            HackingNodeConnectionList.Send(NetworkObjects[0], hackObject, hackingProcess.GetNodeConnectionList());
        }
    }
 /// <summary>
 /// Adds a hacking device to the panel. Usually called in conjunction with ServerStoreHackingDevice if called serverside. Can be called clientside, but will only modify client side devices.
 /// </summary>
 /// <param name="device"></param>
 public virtual void AddHackingDevice(HackingDevice device)
 {
     devices.Add(device);
     hackNodes.Add(device.InputNode);
     hackNodes.Add(device.OutputNode);
 }
 public void SetHackingDevice(HackingDevice device)
 {
     this.device = device;
     SetUpDeviceData();
 }