Example #1
0
    public void GetAccuracy(int targetTileX, int targetTileY)
    {
        ClickebleTile closest = GetClosestPlayersquare(targetTileX, targetTileY);

        mapConfig.tileMap.GeneratePathTo(closest.tileX, closest.tileY, this, true);
        //testDebug = currentBulletPath;
        accuracy = unitWeapon.baseAim;
        int distans;

        if (currentBulletPath == null)
        {
            distans = 0;
        }
        else
        {
            distans = currentBulletPath.Count - 1;
        }
        for (int aim = 1; aim < distans; aim++)//is the path possible
        {
            accuracy += AimReductionAmount(aim + 1);
            if (accuracy <= 0)
            {
                break;
            }
        }

        if (accuracy < 0)
        {
            accuracy = 0;
        }
        else if (accuracy > 100)
        {
            accuracy = 100;
        }
    }
Example #2
0
    private void GetNeighbours(ClickebleTile neighbourConfig, int currentRun)
    {
        for (int x = -1; x <= 1; x++)
        {
            for (int y = -1; y <= 1; y++)
            {
                if (neighbourConfig.tileX + x < 0 || neighbourConfig.tileY + y < 0)
                {
                    continue;
                }
                if (neighbourConfig.tileX + x > mapSizeX - 1 || neighbourConfig.tileY + y > mapSizeY - 1)
                {
                    continue;
                }
                if ((x != 0 && y != 0) || (x == 0 && y == 0))//if it is looking for a diagonal pos skip to next
                {
                    continue;
                }

                if (currentGrid[neighbourConfig.tileX + x, neighbourConfig.tileY + y] > currentRun) //check if has position has been filed
                {
                    if (tiles[neighbourConfig.tileX + x, neighbourConfig.tileY + y] == 0)           //is tile walkeble?
                    {
                        currentneighbour.Add(tileobjects[neighbourConfig.tileX + x, neighbourConfig.tileY + y]);
                        currentGrid[neighbourConfig.tileX + x, neighbourConfig.tileY + y] = currentRun;//if the filed position is lower then the former run replace value
                    }
                }
            }
        }
    }
Example #3
0
    private void OnGUI()
    {
        EditorGUILayout.LabelField("Output name");
        fileName = EditorGUILayout.TextField(fileName);
        EditorGUILayout.LabelField("Index");
        tileIndex = EditorGUILayout.TextField(tileIndex);
        EditorGUILayout.LabelField("Description");
        description = EditorGUILayout.TextField(description);

        path = "Assets/Scenes/" + fileName + ".txt";


        if (GUILayout.Button("Generate"))
        {
            StreamWriter writer = new StreamWriter(path, true);
            writer.WriteLine();
            writer.WriteLine("//" + description);

            foreach (GameObject tile in Selection.gameObjects)
            {
                ClickebleTile currentTile = tile.transform.parent.GetComponent <ClickebleTile>();
                writer.WriteLine("tiles[" + currentTile.tileX + ", " + currentTile.tileY + "] = " + tileIndex + ";");
            }
            writer.Close();
        }
    }
Example #4
0
 void GenerateMapVisual()// make the grid visible
 {
     tileobjects = new ClickebleTile[mapSizeX, mapSizeY];
     for (int x = 0; x < mapSizeX; x++)
     {
         for (int y = 0; y < mapSizeY; y++)
         {
             TileType      tt = tileType[tiles[x, y]];
             GameObject    go = Instantiate(tt.tileVisualPrefab, new Vector3(x * offset, 0, y * offset), Quaternion.identity, transform);
             ClickebleTile ct = go.GetComponent <ClickebleTile>();
             tileobjects[x, y] = ct;
             ct.tileX          = x;
             ct.tileY          = y;
             ct.map            = this;
         }
     }
 }
Example #5
0
 public void ChangeColorGrid(int movement, int actions)
 {
     for (int x = (playerGridColorChange.tileX - (movement * actions)); x <= (playerGridColorChange.tileX + (movement * actions)); x++)
     {
         for (int y = (playerGridColorChange.tileY - (movement * actions)); y <= (playerGridColorChange.tileY + (movement * actions)); y++)
         {
             if (y < 0)
             {
                 continue;
             }
             if (y > mapSizeY - 1)
             {
                 continue;
             }
             if (x < 0)
             {
                 continue;
             }
             if (x > mapSizeX - 1)
             {
                 continue;
             }
             if (currentGrid[x, y] == 99)
             {
                 continue;
             }
             if (tiles[x, y] == 1)
             {
                 continue;
             }
             ClickebleTile tile = tileobjects[x, y];
             if (currentGrid[x, y] < movement && actions != 1)
             {
                 tile.GetComponentInChildren <Renderer>().material = gridMaterials.walkMaterial;        // walk color
             }
             else if (currentGrid[x, y] >= movement || (currentGrid[x, y] <= movement && actions == 1)) //dash if more then movment or if unit only have one action
             {
                 tile.GetComponentInChildren <Renderer>().material = gridMaterials.dashMaterial;        //dash color
             }
         }
     }
 }
Example #6
0
    private ClickebleTile GetClosestPlayersquare(int targetTileX, int targetTileY)
    {
        ClickebleTile closest  = null;
        float         distance = Mathf.Infinity;

        for (int x = -1; x < 2; x++)
        {
            for (int y = -1; y < 2; y++)
            {
                //the loop will not work under the following conditions
                if ((x == 0 && y == 0) || (y != 0 && x != 0))
                {
                    continue;
                }
                if ((y + targetTileY) < 0 ||
                    (y + targetTileY) > mapConfig.tileMap.mapSizeY - 1 ||
                    (x + targetTileX) < 0 ||
                    (x + targetTileX) > mapConfig.tileMap.mapSizeX - 1)
                {
                    continue;
                }

                Vector3 diff        = transform.position - mapConfig.tileMap.tileobjects[x + targetTileX, y + targetTileY].transform.position;
                float   curDistance = diff.sqrMagnitude;
                if (curDistance < distance)//set new closest location
                {
                    closest  = mapConfig.tileMap.tileobjects[x + targetTileX, y + targetTileY];
                    distance = curDistance;
                }
                else if (curDistance <= (distance) &&
                         (mapConfig.tileMap.tiles[x + targetTileX, y + targetTileY] != 0 &&
                          mapConfig.tileMap.tiles[x + targetTileX, y + targetTileY] != 4))//if location is not the closest but has a cover
                {
                    closest  = mapConfig.tileMap.tileobjects[x + targetTileX, y + targetTileY];
                    distance = curDistance;
                }
            }
        }
        return(closest);
    }
Example #7
0
    private void GetPointUnderCursor()
    {
        Ray raycast = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit hitPosition;

        Physics.Raycast(raycast, out hitPosition);
        if (hitPosition.collider && StateController.CurrentState == StateController.GameState.TacticalMode)
        {
            if (hitPosition.collider.CompareTag("Ground"))
            {
                GameObject hit = hitPosition.collider.gameObject;
                cursorObject = hit.GetComponent <ClickebleTile>();

                if (activeObject != cursorObject)
                {
                    activeObject = cursorObject;
                    if (explosionObject != null)
                    {
                        explosionObject.transform.position = activeObject.transform.position;
                    }

                    if (turnSystem.playerTurn)
                    {
                        if (TurnSystem.selectedUnit != null && TurnSystem.selectedUnit.CheckUnitState(UnitConfig.UnitState.Idle))
                        {
                            if (map != null && map.currentGrid[cursorObject.tileX, cursorObject.tileY] != 99)
                            {
                                map.GeneratePathTo(cursorObject.tileX, cursorObject.tileY, TurnSystem.selectedUnit);
                            }
                            else
                            {
                                TurnSystem.selectedUnit.currentPath = null;
                            }
                        }
                    }
                }

                if (Input.GetMouseButtonUp(1) && turnSystem.playerTurn && StateController.CurrentState == StateController.GameState.TacticalMode)
                {
                    if (TurnSystem.selectedUnit.CheckUnitState(UnitConfig.UnitState.Idle))
                    {
                        //map.GeneratePathTo(activeObject.tileX, activeObject.tileY, turnSystem.selectedUnit.baseUnit);


                        TurnSystem.selectedUnit.MoveNextTile();
                        TurnSystem.hasMoved = true;
                    }
                }
            }

            if (hitPosition.collider.CompareTag("Unit") || hitPosition.collider.CompareTag("FriendlyUnit"))
            {
                if (lastHit != null && lastHit != hitPosition.collider.GetComponent <UnitConfig>())
                {
                    lastHit.isHighlighted = false;
                }
                lastHit = hitPosition.collider.GetComponent <UnitConfig>();
                lastHit.isHighlighted = true;
            }
            else if (lastHit != null)
            {
                lastHit.isHighlighted = false;
            }
        }
    }