private void GetMoveOpponet(List <HexCoord> attackTilesNotCanBeCount, List <HexCoord> attackTilesCanBeCount, List <Player> opponetsNotCanBeCount, bool isDirect) { List <Player> tempUser = GameMidiator.m_Instance.m_PlayerManager.GetUserPlayers(null, false); List <HexCoord> tempPlayers = GameMidiator.m_Instance.m_PlayerManager.GetPlayerHexes(new HexCoord(-999, -999)); for (int i = 0; i < tempUser.Count; i++) { Player player = tempUser[i]; List <HexCoord> playerRing = HexCoord.HexRing(player.m_Hex, isDirect ? 1 : 2); List <HexCoord> tiles = attackTilesCanBeCount; if (!player.GetIsCanAttack(isDirect)) { opponetsNotCanBeCount.Add(player); tiles = attackTilesNotCanBeCount; } for (int j = 0; j < playerRing.Count; j++) { HexCoord hex = playerRing[j]; if (!tiles.Contains(hex) && m_StageMapManager.GetMapTile(hex) != null && !tempPlayers.Contains(hex)) { tiles.Add(hex); } } } }
public virtual List <HexCoord> GetAttackRangeHex() { List <HexCoord> range = new List <HexCoord>(); if (GetIsCanAttack(true)) { range.AddRange(HexCoord.HexRing(m_Hex, 1)); } if (GetIsCanAttack(false)) { range.AddRange(HexCoord.HexRing(m_Hex, 2)); } return(range); }
//public static Vector2 CubeDirection(int direction) //{ // return m_CubeDirections[direction]; //} //public static Vector2 CubeNeighbor(Vector2 cube, int direction) //{ // return cube + CubeDirection(direction); //} //public static Vector2 Scale(Vector2 pos, int k) //{ // return pos * k; //} //public static List<Vector2> CubeRing(Vector2 center, int radius) //{ // List<Vector2> results = new List<Vector2>(); // if (radius <= 0) // { // results.Add(center); // return results; // } // var cube = center + Scale(CubeDirection(4), radius); // for (int i = 0; i < 6; i++) // { // for (int j = 0; j < radius; j++) // { // results.Add(cube); // cube = CubeNeighbor(cube, i); // } // } // return results; //} //public static List<Vector2> CubeSpiral(Vector2 center, int min, int max) //{ // List<Vector2> results = new List<Vector2>(); // if (min > max) // { // return new List<Vector2>(); // } // for (int i = min; i <= max; i++) // { // results.AddRange(CubeRing(center, i)); // } // return results; //} //public static List<HexTile> GetCubeRingTile(Vector2 center, int radius, int mapSizeX, int mapSizeY) //{ // List<HexTile> cubeRingTile = new List<HexTile>(); // List<Vector2> cubeRing = CubeRing(center, radius); // for (int i = 0; i < cubeRing.Count; i++) // { // Vector2 n = MapHexIndex(cubeRing[i]); // if (n.x < 0 || n.x > mapSizeX - 1 - (n.y % 2) || n.y < 0 || n.y > mapSizeY - 1) // { // continue; // } // if (SceneManager.GetActiveScene().name == "GameScene") // { // cubeRingTile.Add(GameMidiator.m_Instance.m_StageMapManager.m_MapHex[(int)n.y][(int)n.x]); // } // } // return cubeRingTile; //} public static List <HexCoord> GetCubeRingTile(HexCoord center, int radius) { List <HexCoord> cubeRingTile = new List <HexCoord>(); List <HexCoord> cubeRing = HexCoord.HexRing(center, radius); for (int i = 0; i < cubeRing.Count; i++) { HexTile tile = m_StageMapManager.GetMapTile(cubeRing[i]); if (tile == null) { cubeRingTile.Remove(tile.m_Hex); } } return(cubeRingTile); }
private void EnemyAction() { if (m_IsMoving) { return; } //priority queue List <HexCoord> attackHexesDirect = HexCoord.HexRing(m_Hex, 1); List <HexCoord> attackHexesIndirect = HexCoord.HexRing(m_Hex, 2); List <HexCoord> moveRange = new List <HexCoord>(); if (m_PlayerState.Equals(PlayerState.Action)) { if (m_EnemyAIType == EnemyAIType.Attacker) { moveRange = m_StageMapManager.FindHighlight(m_Hex, m_MovementPerActionPoint, false); moveRange = m_PlayerManager.GetEmptyHex(moveRange); } else if (m_EnemyAIType == EnemyAIType.Defanser) { moveRange = m_StageMapManager.FindHighlight(m_Hex, m_SearchRange, false); moveRange = m_PlayerManager.GetEmptyHex(moveRange); } } List <HexCoord> attackHexesInRange = new List <HexCoord>(); List <HexCoord> opponetsCanBeAttackDirect = new List <HexCoord>(); List <HexCoord> opponetsCanBeAttackIndirect = new List <HexCoord>(); List <HexCoord> opponetsNotCanBeCountDirect = new List <HexCoord>(); List <HexCoord> opponetsNotCanBeCountIndirect = new List <HexCoord>(); int directAtk = 0; int indirectAtk = 0; GetWeaponAttack(ref directAtk, ref indirectAtk); List <Player> opponets = new List <Player>(); List <Player> opponetsNotCanBeCount = new List <Player>(); List <Player> moveOpponets = new List <Player>(); List <Player> moveOpponetsNotCanBeCount = new List <Player>(); //Get player who can (not) counter in range if (directAtk > 0) { GetOpponet(attackHexesDirect, attackHexesInRange, opponets, opponetsNotCanBeCount, true); GetMoveOpponet(opponetsNotCanBeCountDirect, opponetsCanBeAttackDirect, moveOpponetsNotCanBeCount, true); } if (indirectAtk > 0) { GetOpponet(attackHexesIndirect, attackHexesInRange, opponets, opponetsNotCanBeCount, false); GetMoveOpponet(opponetsNotCanBeCountIndirect, opponetsCanBeAttackIndirect, moveOpponetsNotCanBeCount, false); } //Attack player who cannot counter if (AttackOpponent(opponetsNotCanBeCount)) { return; } //Move to player who cannot counter in move range if (MoveToOpponent(opponetsNotCanBeCountDirect.Union(opponetsNotCanBeCountIndirect).Intersect(moveRange).ToList())) { return; } //Attack player in range if (AttackOpponent(opponets)) { return; } //Move to player who can counter in move range if (MoveToOpponent(opponetsCanBeAttackDirect.Union(opponetsCanBeAttackIndirect).Intersect(moveRange).ToList())) { return; } if (m_PlayerState.Equals(PlayerState.Active) && m_EnemyAIType == EnemyAIType.Attacker) { //Move to nearist target List <HexCoord> opponentTiles = new List <HexCoord>(); List <HexTilePath> opponentPaths = new List <HexTilePath>(); int minDistance = 9999; List <Player> temp = m_PlayerManager.GetUserPlayers(null, false); for (int i = 0; i < temp.Count; i++) { Player userPlayer = temp[i]; for (int j = 0; j < moveRange.Count; j++) { int distance = HexCoord.HexDistance(moveRange[j], userPlayer.m_Hex); if (distance < minDistance) { minDistance = distance; opponentTiles.Clear(); opponentTiles.Add(moveRange[j]); } else if (distance == minDistance) { opponentTiles.Add(moveRange[j]); } } } opponentTiles = opponentTiles.OrderBy(x => HexCoord.HexDistance(m_Hex, x)).ToList(); for (int i = 0; i < opponentTiles.Count; i++) { opponentPaths.Add(m_StageMapManager.FindPath(m_Hex, opponentTiles[i])); } HexTile destTile = null; float cost = 0; List <HexTile> path = new List <HexTile>(); for (int i = 0; i < opponentPaths[0].listOfTiles.Count; i++) { HexTile tile = opponentPaths[0].listOfTiles[i]; cost += tile.m_MovementCost; if (cost <= m_MovementPerActionPoint) { destTile = tile; } else { break; } } m_StageMapManager.HighlightTileAt(moveRange); GameManager.m_Instance.MoveCurrentPlayer(destTile); return; } //Nothing can do. TurnEnd(); }