public static RequestTileDeconstructMessage Send(GameObject player, GameObject matrixRoot, TileType tileType, Vector3 cellPos, Vector3 cellWorldPos)
    {
        RequestTileDeconstructMessage msg = new RequestTileDeconstructMessage
        {
            Player       = player.GetComponent <NetworkIdentity>().netId,
            MatrixRoot   = matrixRoot.GetComponent <NetworkIdentity>().netId,
            TileType     = (int)tileType,
            CellPos      = cellPos,
            CellWorldPos = cellWorldPos
        };

        msg.Send();
        return(msg);
    }
Exemplo 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 = 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);
    }
Exemplo n.º 3
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);
    }
    public bool Interact(PositionalHandApply interaction)
    {
        if (!DefaultWillInteract.PositionalHandApply(interaction, NetworkSide.Client))
        {
            return(false);
        }

        PlayerNetworkActions pna = interaction.Performer.GetComponent <PlayerNetworkActions>();

        Vector3Int pos = objectLayer.transform.InverseTransformPoint(interaction.WorldPositionTarget).RoundToInt();

        pos.z = 0;
        Vector3Int cellPos = baseLayer.WorldToCell(interaction.WorldPositionTarget);

        LayerTile tile = metaTileMap.GetTile(pos);

        if (tile != null)
        {
            switch (tile.TileType)
            {
            case TileType.Table:
            {
                Vector3 targetPosition = interaction.WorldPositionTarget;
                targetPosition.z = -0.2f;
                pna.CmdPlaceItem(interaction.HandSlot.equipSlot, targetPosition, interaction.Performer, true);
                return(true);
            }

            case TileType.Floor:
            {
                //Crowbar
                if (Validations.IsTool(interaction.HandObject, ToolType.Crowbar))
                {
                    pna.CmdCrowBarRemoveFloorTile(interaction.Performer, LayerType.Floors,
                                                  new Vector2(cellPos.x, cellPos.y), interaction.WorldPositionTarget);
                    return(true);
                }

                break;
            }

            case TileType.Base:
            {
                if (Validations.HasComponent <UniFloorTile>(interaction.HandObject))
                {
                    pna.CmdPlaceFloorTile(interaction.Performer,
                                          new Vector2(cellPos.x, cellPos.y), interaction.HandObject);
                    return(true);
                }

                break;
            }

            case TileType.Window:
            {
                //Check Melee:
                Meleeable melee = windowLayer.gameObject.GetComponent <Meleeable>();
                if (melee != null &&
                    melee.Interact(PositionalHandApply.ByLocalPlayer(gameObject)))
                {
                    return(true);
                }

                break;
            }

            case TileType.Grill:
            {
                //Check Melee:
                Meleeable melee = grillTileMap.gameObject.GetComponent <Meleeable>();
                if (melee != null && melee.Interact(PositionalHandApply.ByLocalPlayer(gameObject)))
                {
                    return(true);
                }

                break;
            }

            case TileType.Wall:
            {
                Welder welder = interaction.HandObject != null?interaction.HandObject.GetComponent <Welder>() : null;

                if (welder != null)
                {
                    if (welder.isOn)
                    {
                        //Request to deconstruct from the server:
                        RequestTileDeconstructMessage.Send(interaction.Performer, gameObject, TileType.Wall,
                                                           cellPos, interaction.WorldPositionTarget);
                        return(true);
                    }
                }
                break;
            }
            }
        }

        return(false);
    }