Ejemplo n.º 1
0
    private void NodeScatter(Vector3Int location, OreProbability materialSpecified)
    {
        var locations = new List <Vector3Int>()
        {
            location,
        };
        var strength = materialSpecified.PossibleClusterSizes[RANDOM.Next(materialSpecified.PossibleClusterSizes.Count)];

        while (strength > 0)
        {
            var chosenLocation = locations[RANDOM.Next(locations.Count)];
            var ranLocation    = chosenLocation + DIRECTIONS[RANDOM.Next(DIRECTIONS.Count)];
            var tile           = metaTileMap.GetTile(ranLocation);
            if (tile != null && tile.name.Contains("rock_wall"))
            {
                tileChangeManager.UpdateTile(ranLocation, materialSpecified.WallTile);
                locations.Add(ranLocation);
                ranLocation.z = -1;
                tileChangeManager.AddOverlay(ranLocation, materialSpecified.OverlayTile as OverlayTile);
            }
            strength--;
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Gets the LayerTile of the tile at the indicated position, null if no tile there (open space).
    /// </summary>
    /// <param name="worldPos"></param>
    /// <returns></returns>
    public LayerTile LayerTileAt(Vector2 worldPos, bool ignoreEffectsLayer = false)
    {
        Vector3Int pos = objectLayer.transform.InverseTransformPoint(worldPos).RoundToInt();

        return(metaTileMap.GetTile(pos, ignoreEffectsLayer));
    }
Ejemplo 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);
    }
    private bool IsDifferent(Vector3Int position, TileType tileType, string tileName)
    {
        LayerTile layerTile = TileManager.GetTile(tileType, tileName);

        return(metaTileMap.GetTile(position, layerTile.LayerType) != layerTile);
    }
Ejemplo n.º 5
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);
    }
    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);
    }
Ejemplo n.º 7
0
    public void RunOreGenerator()
    {
        metaTileMap       = GetComponentInChildren <MetaTileMap>();
        wallTilemap       = metaTileMap.Layers[LayerType.Walls].GetComponent <Tilemap>();
        tileChangeManager = GetComponent <TileChangeManager>();

        if (CustomNetworkManager.IsServer == false)
        {
            return;
        }

        if (TryGetComponent <NetworkedMatrix>(out var net) && net.MatrixSync == null)
        {
            net.BackUpSetMatrixSync();

            if (net.MatrixSync.netId == 0)
            {
                StartCoroutine(WaitForNetId(net.MatrixSync));
                return;
            }
        }

        List <OreProbability> weightedList = new List <OreProbability>();

        foreach (var ores in config.OreProbabilities)
        {
            for (int i = 0; i < ores.SpawnChance; i++)
            {
                weightedList.Add(ores);
            }
        }

        //TODO move BoundsInt bounds = wallTilemap.cellBounds to metaTileMap
        BoundsInt         bounds      = wallTilemap.cellBounds;
        List <Vector3Int> miningTiles = new List <Vector3Int>();

        for (int n = bounds.xMin; n < bounds.xMax; n++)
        {
            for (int p = bounds.yMin; p < bounds.yMax; p++)
            {
                Vector3Int localPlace = (new Vector3Int(n, p, 0));

                if (metaTileMap.HasTile(localPlace))
                {
                    var tile = metaTileMap.GetTile(localPlace);
                    if (tile.name.Contains("rock_wall"))
                    {
                        miningTiles.Add(localPlace);
                    }
                }
            }
        }

        int numberOfTiles = (int)((miningTiles.Count / 100f) * config.Density);

        for (int i = 0; i < numberOfTiles; i++)
        {
            var oreTile     = miningTiles[RANDOM.Next(miningTiles.Count)];
            var oreCategory = weightedList[RANDOM.Next(weightedList.Count)];
            tileChangeManager.UpdateTile(oreTile, oreCategory.WallTile);
            var intLocation = oreTile + Vector3Int.zero;
            intLocation.z = -1;
            tileChangeManager.AddOverlay(intLocation, oreCategory.OverlayTile as OverlayTile);

            NodeScatter(oreTile, oreCategory);
        }
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Gets the LayerTile of the tile at the indicated position, null if no tile there (open space).
    /// </summary>
    /// <param name="worldPos"></param>
    /// <returns></returns>
    public LayerTile LayerTileAt(Vector2 worldPos)
    {
        Vector3Int pos = objectLayer.transform.InverseTransformPoint(worldPos).RoundToInt();

        return(metaTileMap.GetTile(pos));
    }