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(); } } } }
public void CheckEnemiesInLine() { GameObject[] Enemies = GameObject.FindGameObjectsWithTag("Enemy"); GameObject Player = GameObject.Find(map.selecterPlayer); PlayableCharacter player = Player.GetComponent <PlayableCharacter> (); Vector3 playerRet = new Vector3(); Vector3 enemyRet = new Vector3(); playerRet.y = player.PlayerClass.TileY; playerRet.z = player.PlayerClass.TileX - (player.PlayerClass.TileY - (Mathf.Abs(player.PlayerClass.TileY) % 2)) / 2; playerRet.x = -playerRet.y - playerRet.z; int minDistance = 30; // foreach (Node Tile in pathTiles) { // } foreach (GameObject Enemy in Enemies) { BaseEnemy enemy = Enemy.GetComponent <BaseEnemy> (); GameObject Tile = GameObject.Find("Hex_" + enemy.TileX + "_" + enemy.TileY); ClickableTile tile = Tile.GetComponent <ClickableTile> (); enemy.distanceToPlayer = 30; // Debug.Log (tile.lineTargetted); if (tile.lineTargetted) { // Debug.Log (enemy.name); enemyRet.y = enemy.TileY; enemyRet.z = enemy.TileX - (enemy.TileY - (Mathf.Abs(enemy.TileY) % 2)) / 2; enemyRet.x = -enemyRet.y - enemyRet.z; int d = (int)(Mathf.Abs(playerRet.x - enemyRet.x) + Mathf.Abs(playerRet.y - enemyRet.y) + Mathf.Abs(playerRet.z - enemyRet.z)) / 2; enemy.distanceToPlayer = d; if (d <= minDistance) { minDistance = d; } } } foreach (GameObject Enemy in Enemies) { BaseEnemy enemy = Enemy.GetComponent <BaseEnemy> (); GameObject Tile = GameObject.Find("Hex_" + enemy.TileX + "_" + enemy.TileY); ClickableTile tile = Tile.GetComponent <ClickableTile> (); if (enemy.distanceToPlayer == minDistance && tile.lineTargetted && enemy.distanceToPlayer != 30) { GameObject CardDropArea = GameObject.Find("CardDropArea"); DropZone dropZone = CardDropArea.GetComponent <DropZone>(); if (dropZone.areaRange >= 1) { GameObject Area = GameObject.Find("_Scripts"); ChangeTilesArea area = Area.GetComponent <ChangeTilesArea> (); area.area = dropZone.areaRange; area.skillDistance = 30; area.CalculateArea(tile.tileX, tile.tileY); } else { GameObject HighlightTiles = GameObject.Find("_Scripts"); HighlightTiles highlightTiles = HighlightTiles.GetComponent <HighlightTiles> (); highlightTiles.ShowTilesThatWillBeHitSkill(); } } } }
void RunTargets() { // GameObject ButtonScripts = GameObject.Find ("ButtonsCanvas"); // ButtonScripts buttonScripts = ButtonScripts.GetComponent<ButtonScripts> (); GameObject HighlightTiles = GameObject.Find("_Scripts"); HighlightTiles highlightTiles = HighlightTiles.GetComponent <HighlightTiles> (); // Debug.Log(effect); /* if (effect == Effects.Attack) { * buttonScripts.TurnEverythingFalse(); * map.HideAllowedTiles(); * map.ShowAttackableTiles(); * // GameObject Unit = GameObject.Find("UnitOne"); * // Unit unit = Unit.GetComponent<Unit> (); * // unit.Attack(); * buttonScripts.attackSelected = true; * // changeAreaTiles = false; * // moveSelected = false; * // moveSelected = false; * } * else if (effect == Effects.ChangeArea) { * // Debug.Log(effect); * buttonScripts.TurnEverythingFalse(); * buttonScripts.changeAreaTiles = true; * Debug.Log(buttonScripts.changeAreaTiles); * map.HideAllowedTiles(); * * } */ switch (target) { case Targets.Ally: // GameObject[] Players = GameObject.FindGameObjectsWithTag("Player"); // foreach (GameObject PlayerAlly in Players) { // GameObject Distance = GameObject.Find ("_Scripts"); // CalculateDistance distance = Distance.GetComponent<CalculateDistance> (); // PlayableCharacter playerAlly = PlayerAlly.GetComponent<PlayableCharacter> (); // GameObject TileAlly = GameObject.Find ("Hex_" + playerAlly.PlayerClass.TileX + "_" + playerAlly.PlayerClass.TileY ); // ClickableTile tileAlly = TileAlly.GetComponent<ClickableTile> (); buttonScripts.allySelected = true; // distance.range = range; // tileAlly.ChangeMaterial(); // } break; case Targets.Area: GameObject Area = GameObject.Find("_Scripts"); ChangeTilesArea area = Area.GetComponent <ChangeTilesArea> (); area.area = areaRange; area.skillDistance = range; buttonScripts.changeAreaTiles = true; break; case Targets.Cone: // Debug.Log("Runeffect Cone"); GameObject Cone = GameObject.Find("_Scripts"); Cone cone = Cone.GetComponent <Cone> (); cone.skillDistance = range; buttonScripts.coneSelected = true; break; case Targets.Enemy: buttonScripts.attackSelected = true; break; case Targets.Line: GameObject Line = GameObject.Find("LineRenderer"); DrawLine line = Line.GetComponent <DrawLine> (); line.skillDistance = range; buttonScripts.drawSelected = true; break; case Targets.Self: selectedTarget = map.selecterPlayer; GameObject PlayerSelf = GameObject.Find(map.selecterPlayer); PlayableCharacter playerSelf = PlayerSelf.GetComponent <PlayableCharacter> (); GameObject TileSelf = GameObject.Find("Hex_" + playerSelf.PlayerClass.TileX + "_" + playerSelf.PlayerClass.TileY); ClickableTile tileSelf = TileSelf.GetComponent <ClickableTile> (); highlightTiles.tileX = tileSelf.tileX; highlightTiles.tileY = tileSelf.tileY; highlightTiles.ShowHoveringTileSkill(); break; case Targets.AreaMobility: GameObject AreaMobility = GameObject.Find("_Scripts"); ChangeTilesArea areaMobility = AreaMobility.GetComponent <ChangeTilesArea> (); areaMobility.area = areaRange; areaMobility.skillDistance = range; buttonScripts.changeAreaTilesNoMid = true; break; case Targets.Trap: buttonScripts.trapSelected = true; break; default: break; } }