Ejemplo n.º 1
0
    public bool Interact(Transform _transform, Vector3 position)
    {
        if (playerMove.isGhost)
        {
            return(false);
        }

        //attempt to trigger the things in range we clicked on
        if (PlayerManager.LocalPlayerScript.IsInReach(Camera.main.ScreenToWorldPoint(Input.mousePosition)))
        {
            //Check for melee triggers first:
            MeleeTrigger meleeTrigger = _transform.GetComponentInParent <MeleeTrigger>();
            if (meleeTrigger != null)
            {
                if (meleeTrigger.MeleeInteract(gameObject, UIManager.Hands.CurrentSlot.eventName))
                {
                    return(true);
                }
            }

            //check the actual transform for an input trigger and if there is non, check the parent
            InputTrigger inputTrigger = _transform.GetComponentInParent <InputTrigger>();
            if (inputTrigger)
            {
                if (objectBehaviour.visibleState)
                {
                    inputTrigger.Trigger(position);

                    //FIXME currently input controller only uses the first InputTrigger found on an object
                    /////// some objects have more then 1 input trigger, like players for example
                    /////// below is a solution that should be removed when InputController is refactored
                    /////// to support multiple InputTriggers on the target object
                    if (inputTrigger.gameObject.layer == 8)
                    {
                        //This is a player. Attempt to use the player based inputTrigger
                        P2PInteractions playerInteractions = inputTrigger.gameObject.GetComponent <P2PInteractions>();
                        if (playerInteractions != null)
                        {
                            playerInteractions.Trigger(position);
                        }
                    }
                    return(true);
                }
                //Allow interact with cupboards we are inside of!
                ClosetControl cCtrl = inputTrigger.GetComponent <ClosetControl>();
                if (cCtrl && cCtrl.transform.position == PlayerManager.LocalPlayerScript.transform.position)
                {
                    inputTrigger.Trigger(position);
                    return(true);
                }
                return(false);
            }
        }
        //if we are holding onto an item like a gun attempt to shoot it if we were not in range to trigger anything
        return(InteractHands());
    }
Ejemplo n.º 2
0
    private bool DetermineTileAction(GameObject originator, Vector3 position, string hand)
    {
        metaTileMap = originator.GetComponentInParent <MetaTileMap>();
        objectLayer = originator.GetComponentInParent <ObjectLayer>();
        PlayerNetworkActions pna = originator.GetComponent <PlayerNetworkActions>();

        Vector3Int pos = objectLayer.transform.InverseTransformPoint(position).RoundToInt();

        pos.z = 0;
        Vector3Int cellPos = baseTileMap.WorldToCell(position);

        LayerTile tile = metaTileMap.GetTile(pos);

        GameObject handObj;

        //if we are client, our pna.Inventory is always empty so we should get the hand item a different way
        if (!isServer)
        {
            if (originator != PlayerManager.LocalPlayer)
            {
                Logger.LogError("Client is attempting to determine the tile actions of a player other than" +
                                " themselves. This should not happen and should be fixed. Client should only determine their own" +
                                " actions.");
                return(false);
            }
            else
            {
                handObj = UIManager.InventorySlots[hand].Item;
            }
        }
        else
        {
            handObj = pna.Inventory[hand].Item;
        }



        // Nothing in hand, do nothing
        if (handObj == null)
        {
            return(false);
        }

        if (tile != null)
        {
            switch (tile.TileType)
            {
            case TileType.Table:
            {
                Vector3 targetPosition = position;
                targetPosition.z = -0.2f;
                pna.CmdPlaceItem(hand, targetPosition, originator, true);
                return(true);
            }

            case TileType.Floor:
            {
                //Crowbar
                if (handObj.GetComponent <CrowbarTrigger>())
                {
                    pna.CmdCrowBarRemoveFloorTile(originator, LayerType.Floors,
                                                  new Vector2(cellPos.x, cellPos.y), position);

                    return(true);
                }

                break;
            }

            case TileType.Base:
            {
                if (handObj.GetComponent <UniFloorTile>())
                {
                    pna.CmdPlaceFloorTile(originator,
                                          new Vector2(cellPos.x, cellPos.y), handObj);

                    return(true);
                }

                break;
            }

            case TileType.Window:
            {
                //Check Melee:
                MeleeTrigger melee = windowTileMap.gameObject.GetComponent <MeleeTrigger>();
                if (melee != null && melee.MeleeInteract(originator, hand))
                {
                    return(true);
                }

                break;
            }

            case TileType.Grill:
            {
                //Check Melee:
                MeleeTrigger melee = grillTileMap.gameObject.GetComponent <MeleeTrigger>();
                if (melee != null && melee.MeleeInteract(originator, hand))
                {
                    return(true);
                }

                break;
            }

            case TileType.Wall:
            {
                Welder welder = handObj.GetComponent <Welder>();
                if (welder)
                {
                    if (welder.isOn)
                    {
                        //Request to deconstruct from the server:
                        RequestTileDeconstructMessage.Send(originator, gameObject, TileType.Wall,
                                                           cellPos, position);

                        return(true);
                    }
                }

                break;
            }
            }
        }

        return(false);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Checks for the various interactions that can occur and delegates to the appropriate trigger classes.
    /// Note that only one interaction is allowed to occur in this method - the first time any trigger returns true
    /// (indicating that interaction logic has occurred), the method returns.
    /// </summary>
    /// <param name="_transform">transform to check the interaction of</param>
    /// <param name="position">position the interaction is taking place</param>
    /// <param name="isDrag">is this during (but not at the very start of) a drag?</param>
    /// <returns>true iff an interaction occurred</returns>
    public bool Interact(Transform _transform, Vector3 position, bool isDrag)
    {
        if (playerMove.isGhost)
        {
            return(false);
        }

        //attempt to trigger the things in range we clicked on
        var localPlayer = PlayerManager.LocalPlayerScript;

        if (localPlayer.IsInReach(Camera.main.ScreenToWorldPoint(Input.mousePosition)) || localPlayer.IsHidden)
        {
            //Check for melee triggers first. If a melee interaction occurs, stop checking for any further interactions
            MeleeTrigger meleeTrigger = _transform.GetComponentInParent <MeleeTrigger>();
            //no melee action happens due to a drag
            if (meleeTrigger != null && !isDrag)
            {
                if (meleeTrigger.MeleeInteract(gameObject, UIManager.Hands.CurrentSlot.eventName))
                {
                    return(true);
                }
            }

            //check the actual transform for an input trigger and if there is non, check the parent
            InputTrigger inputTrigger = _transform.GetComponentInParent <InputTrigger>();
            if (inputTrigger)
            {
                if (objectBehaviour.visibleState)
                {
                    bool interacted = false;
                    if (isDrag)
                    {
                        interacted = inputTrigger.TriggerDrag(position);
                    }
                    else
                    {
                        interacted = inputTrigger.Trigger(position);
                    }

                    if (interacted)
                    {
                        return(true);
                    }

                    //FIXME currently input controller only uses the first InputTrigger found on an object
                    /////// some objects have more then 1 input trigger, like players for example
                    /////// below is a solution that should be removed when InputController is refactored
                    /////// to support multiple InputTriggers on the target object
                    if (inputTrigger.gameObject.layer == 8)
                    {
                        //This is a player. Attempt to use the player based inputTrigger
                        P2PInteractions playerInteractions = inputTrigger.gameObject.GetComponent <P2PInteractions>();
                        if (playerInteractions != null)
                        {
                            if (isDrag)
                            {
                                interacted = playerInteractions.TriggerDrag(position);
                            }
                            else
                            {
                                interacted = playerInteractions.Trigger(position);
                            }
                        }
                    }
                    if (interacted)
                    {
                        return(true);
                    }
                }
                //Allow interact with cupboards we are inside of!
                ClosetControl closet = inputTrigger.GetComponent <ClosetControl>();
                //no closet interaction happens when dragging
                if (closet && Camera2DFollow.followControl.target == closet.transform && !isDrag)
                {
                    if (inputTrigger.Trigger(position))
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }

        //if we are holding onto an item like a gun attempt to shoot it if we were not in range to trigger anything
        return(InteractHands(isDrag));
    }
Ejemplo n.º 4
0
    private bool DetermineTileAction(GameObject originator, Vector3 position, string hand)
    {
        metaTileMap = originator.GetComponentInParent <MetaTileMap>();
        objectLayer = originator.GetComponentInParent <ObjectLayer>();
        PlayerNetworkActions pna = originator.GetComponent <PlayerNetworkActions>();

        Vector3Int pos = objectLayer.transform.InverseTransformPoint(position).RoundToInt();

        pos.z = 0;
        Vector3Int cellPos = baseTileMap.WorldToCell(position);

        LayerTile tile = metaTileMap.GetTile(pos);

        GameObject handObj = UIManager.Hands.CurrentSlot.Item;

        // Nothing in hand, do nothing
        if (handObj == null)
        {
            return(false);
        }

        if (tile != null)
        {
            switch (tile.TileType)
            {
            case TileType.Table:
            {
                Vector3 targetPosition = position;
                targetPosition.z = -0.2f;
                pna.CmdPlaceItem(hand, targetPosition, originator, true);
                return(true);
            }

            case TileType.Floor:
            {
                //Crowbar
                if (handObj.GetComponent <CrowbarTrigger>())
                {
                    pna.CmdCrowBarRemoveFloorTile(originator, LayerType.Floors,
                                                  new Vector2(cellPos.x, cellPos.y), position);

                    return(true);
                }

                break;
            }

            case TileType.Base:
            {
                if (handObj.GetComponent <UniFloorTile>())
                {
                    pna.CmdPlaceFloorTile(originator,
                                          new Vector2(cellPos.x, cellPos.y), handObj);

                    return(true);
                }

                break;
            }

            case TileType.Window:
            {
                //Check Melee:
                MeleeTrigger melee = windowTileMap.gameObject.GetComponent <MeleeTrigger>();
                if (melee != null && melee.MeleeInteract(originator, hand))
                {
                    return(true);
                }

                break;
            }

            case TileType.Grill:
            {
                //Check Melee:
                MeleeTrigger melee = grillTileMap.gameObject.GetComponent <MeleeTrigger>();
                if (melee != null && melee.MeleeInteract(originator, hand))
                {
                    return(true);
                }

                break;
            }

            case TileType.Wall:
            {
                Welder welder = handObj.GetComponent <Welder>();
                if (welder)
                {
                    if (welder.isOn)
                    {
                        //Request to deconstruct from the server:
                        RequestTileDeconstructMessage.Send(originator, gameObject, TileType.Wall,
                                                           cellPos, position);

                        return(true);
                    }
                }

                break;
            }
            }
        }

        return(false);
    }