Exemplo n.º 1
0
    public void CheckLineTiles(int startPointX, int startPointY, int endPointX, int endPointY)
    {
//		GameObject Tile = GameObject.Find ("Hex_" + endTileX + "_" + endTileX);
//		ClickableTile tile = Tile.GetComponent<ClickableTile> ();
        Vector3 startLoc = new Vector3();
        Vector3 endLoc   = new Vector3();

        startLoc.y = startPointY;
        startLoc.z = startPointX - (startPointY - (Mathf.Abs(startPointY) % 2)) / 2;
        startLoc.x = -startLoc.y - startLoc.z;
        endLoc.y   = endPointY;
        endLoc.z   = endPointX - (endPointY - (Mathf.Abs(endPointY) % 2)) / 2;
        endLoc.x   = -endLoc.y - endLoc.z;
        int n = (int)(Mathf.Abs(startLoc.x - endLoc.x) + Mathf.Abs(startLoc.y - endLoc.y) + Mathf.Abs(startLoc.z - endLoc.z)) / 2;

        Vector3 [] tiles = new Vector3[n];

        for (int i = 0; i < n; i++)
        {
            float a = (1.0f / n) * (i + 1);
            tiles[i] = CubeLerp(startLoc, endLoc, a);
            GameObject[] Tiles = GameObject.FindGameObjectsWithTag("Hex");
            foreach (GameObject tile in Tiles)
            {
                ClickableTile clickableTile = tile.GetComponent <ClickableTile> ();
//						clickableTile.lineTargetted = false;
                Vector3 hexLoc = new Vector3();
                hexLoc.y = clickableTile.tileY;
                hexLoc.z = clickableTile.tileX - (clickableTile.tileY - (Mathf.Abs(clickableTile.tileY) % 2)) / 2;
                hexLoc.x = -hexLoc.y - hexLoc.z;
                int m = (int)(Mathf.Abs(startLoc.x - hexLoc.x) + Mathf.Abs(startLoc.y - hexLoc.y) + Mathf.Abs(startLoc.z - hexLoc.z)) / 2;
                if (tiles[i].x >= clickableTile.worldPos.x - 0.5f && tiles[i].y <= clickableTile.worldPos.y + 0.50f)
                {
                    if (tiles[i].y >= clickableTile.worldPos.y - 0.5f && tiles[i].y <= clickableTile.worldPos.y + 0.50f)
                    {
                        if (tiles[i].z >= clickableTile.worldPos.z - 0.5f && tiles[i].z <= clickableTile.worldPos.z + 0.50f)
                        {
                            if (m <= skillDistance)
                            {
                                GameObject     HighlightTiles = GameObject.Find("_Scripts");
                                HighlightTiles highlightTiles = HighlightTiles.GetComponent <HighlightTiles> ();
                                highlightTiles.tileX        = clickableTile.tileX;
                                highlightTiles.tileY        = clickableTile.tileY;
                                clickableTile.lineTargetted = true;
                                highlightTiles.ShowTilesThatWillNotBeHitSkill();
                            }
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    void OnMouseEnter()
    {
        if (map != null)
        {
            canAttack = true;
//		Material[] mat = this.GetComponent<Renderer>().materials;
//		mat[1] = hoverMaterialMouse;
//		GameObject ButtonScripts = GameObject.Find ("ButtonsCanvas");
//		ButtonScripts buttonScripts = ButtonScripts.GetComponent<ButtonScripts> ();
            GameObject        Player         = GameObject.Find(map.selecterPlayer);
            PlayableCharacter player         = Player.GetComponent <PlayableCharacter> ();
            GameObject        HighlightTiles = GameObject.Find("_Scripts");
            HighlightTiles    highlightTiles = HighlightTiles.GetComponent <HighlightTiles> ();
//		highlightTiles.HighlightTilesInRange();

            if (buttonScripts.moveSelected)
            {
                highlightTiles.tileX = tileX;
                highlightTiles.tileY = tileY;
                highlightTiles.ShowHoveringTileMovement();
            }

            if (buttonScripts.changeAreaTiles && hexVisible)
            {
                highlightTiles.ColorTargettedTiles();
                if (EventSystem.current.IsPointerOverGameObject())
                {
                    return;
                }
                GameObject      ChangeTilesArea = GameObject.Find("_Scripts");
                ChangeTilesArea changeTilesArea = ChangeTilesArea.GetComponent <ChangeTilesArea> ();
                changeTilesArea.tileX = tileX;
                changeTilesArea.tileY = tileY;
                changeTilesArea.CalculateArea(tileX, tileY);
            }


            if (buttonScripts.changeAreaTilesNoMid && map.UnitCanEnterTile(tileX, tileY) == true && hexVisible)
            {
                highlightTiles.ColorTargettedTiles();

                GameObject[] Enemies = GameObject.FindGameObjectsWithTag("Enemy");
                foreach (GameObject enemyAi in Enemies)
                {
                    BaseEnemy enemy = enemyAi.GetComponent <BaseEnemy> ();
                    if (enemy.TileX == tileX && enemy.TileY == tileY)
                    {
                        canAttack = false;
                        return;
                    }
                }

                if (EventSystem.current.IsPointerOverGameObject())
                {
                    return;
                }
                GameObject      ChangeTilesArea = GameObject.Find("_Scripts");
                ChangeTilesArea changeTilesArea = ChangeTilesArea.GetComponent <ChangeTilesArea> ();
                changeTilesArea.tileX = tileX;
                changeTilesArea.tileY = tileY;
                changeTilesArea.CalculateAreaNoMid(tileX, tileY);
            }


            if (buttonScripts.drawSelected && hexVisible)
            {
                highlightTiles.ColorTargettedTiles();
                GameObject   DrawLine = GameObject.Find("LineRenderer");
                DrawLine     drawLine = DrawLine.GetComponent <DrawLine> ();
                GameObject[] Tiles    = GameObject.FindGameObjectsWithTag("Hex");
                foreach (GameObject tile in Tiles)
                {
                    ClickableTile clickableTile = tile.GetComponent <ClickableTile> ();
                    clickableTile.lineTargetted = false;
                }
                drawLine.CheckLineTiles(player.PlayerClass.TileX, player.PlayerClass.TileY, tileX, tileY);

                drawLine.CheckEnemiesInLine();
            }

            if (buttonScripts.coneSelected)
            {
//			Debug.Log("tile " + tileX + " " + tileY);
                GameObject Cone = GameObject.Find("_Scripts");
                Cone       cone = Cone.GetComponent <Cone> ();
//			GameObject Unit = GameObject.Find (map.selecterPlayer);
//			Unit unit = Unit.GetComponent<Unit> ();
//			Debug.Log("tile " + unit.tileX + " " + unit.tileY);
                cone.CalculateCone(player.PlayerClass.TileX, player.PlayerClass.TileY, tileX, tileY);
                if (!willTakeHit)
                {
                    cone.CalculateConeEquals(player.PlayerClass.TileX, player.PlayerClass.TileY, tileX, tileY);
                }
            }
            if (buttonScripts.allySelected)
            {
                canAttack   = false;
                enemyTarget = false;
                // Makes basic coloring for all tiles in range
                highlightTiles.ShowTilesThatInRangeGeneral(player.PlayerClass.TileX, player.PlayerClass.TileY);
                highlightTiles.tileX = tileX;
                highlightTiles.tileY = tileY;
                if (canAttack)
                {
                    highlightTiles.ShowTilesThatWillBeHitSkill();
                }
                else if (!canAttack)
                {
                    highlightTiles.ShowTilesThatWillNotBeHitSkill();
                }
            }
            if (buttonScripts.trapSelected)
            {
                canAttack = false;
//			enemyTarget = true;
                // Makes basic coloring for all tiles in range
                highlightTiles.ShowTilesThatInTrapRange(player.PlayerClass.TileX, player.PlayerClass.TileY);
                highlightTiles.tileX = tileX;
                highlightTiles.tileY = tileY;
                if (canAttack)
                {
                    highlightTiles.ShowTilesThatWillBeHitSkill();
                }
                else if (!canAttack)
                {
                    highlightTiles.ShowTilesThatWillNotBeHitSkill();
                }
            }

            if (buttonScripts.attackSelected)
            {
                canAttack   = false;
                enemyTarget = true;
                // Makes basic coloring for all tiles in range
                highlightTiles.ShowTilesThatInRangeGeneral(player.PlayerClass.TileX, player.PlayerClass.TileY);
                highlightTiles.tileX = tileX;
                highlightTiles.tileY = tileY;
                if (canAttack)
                {
                    highlightTiles.ShowTilesThatWillBeHitSkill();
                }
                else if (!canAttack)
                {
                    highlightTiles.ShowTilesThatWillNotBeHitSkill();
                }
            }
        }
    }