예제 #1
0
 public void RocketsActive()
 {
     //Debug.Log("Rockets");
     if (jumpState)
     {
         JumpActive();
     }
     else if (shieldState)
     {
         ShieldActive();
     }
     else if (laserState)
     {
         LaserActive();
     }
     if (turnManager.playerTurn && weaponState && !abilityUsed && turnManager.combatActive && (currentRocketReloadAmount >= rocketReloadTime || rocketState))
     {
         playerFlats.Clear();
         rocketState = !rocketState;
         //player.GetComponent<MovementController>().abilityActive = rocketState;
         abilityActive = rocketState;
         playerFlats   = mapManager.GetFlats(rocketRange, gridLayout.WorldToCell(player.transform.position), false);
         mapManager.HighlightSet(playerFlats, rocketState);
     }
 }
예제 #2
0
    public void TakeTurn()
    {
        if (!shotIncoming)
        {
            int          distToPlayer = mapManager.HexCellDistance(mapManager.evenq2cube(enemyCellPosition), mapManager.evenq2cube(player.gameObject.GetComponent <MovementController>().playerCellPosition));
            GameObject[] rockets      = GameObject.FindGameObjectsWithTag("Rocket");
            foreach (GameObject rocket in rockets)
            {
                int distToRocket = mapManager.HexCellDistance(mapManager.evenq2cube(enemyCellPosition), mapManager.evenq2cube(gridLayout.WorldToCell(rocket.transform.position)));
                Debug.Log(thisEnemyName + " is " + distToRocket + " hexes from a rocket");
                if (distToRocket < resourceAndUpgradeManager.CurrentMaxRocketYield + 2)
                {
                    runAway = true;
                }
            }

            if (rockets.Length <= 0)
            {
                runAway = false;
            }


            switch (thisEnemyName)
            {
            case "EnemyA":
                List <Vector3Int> playerFlats    = mapManager.GetFlats(3, movementController.playerCellPosition, false);
                List <Vector3Int> playerEndFlats = mapManager.GetFlats(3, movementController.playerCellPosition, true);
                Vector3Int        nearestEndFlat = playerEndFlats[0];
                int distToNearestEndFlat         = 999999;
                foreach (Vector3Int flat in playerEndFlats)
                {
                    int distToFlat = mapManager.HexCellDistance(mapManager.evenq2cube(enemyCellPosition), mapManager.evenq2cube(flat));

                    if (distToFlat < distToNearestEndFlat)
                    {
                        distToNearestEndFlat = distToFlat;
                        nearestEndFlat       = flat;
                    }
                }

                Vector3Int nearestFlat       = playerFlats[0];
                int        distToNearestFlat = 999999;
                foreach (Vector3Int flat in playerFlats)
                {
                    int distToFlat = mapManager.HexCellDistance(mapManager.evenq2cube(enemyCellPosition), mapManager.evenq2cube(flat));
                    if (distToFlat < distToNearestFlat)
                    {
                        distToNearestFlat = distToFlat;
                        nearestFlat       = flat;
                    }
                    if (flat == enemyCellPosition)
                    {
                        inFlats = true;
                        break;
                    }
                    else
                    {
                        inFlats = false;
                    }
                }
                if (enemyCellPosition != nearestEndFlat && !inFlats || runAway)
                {
                    if (distToPlayer < 3)
                    {
                        nearestEndFlat = nearestFlat;
                    }
                    List <Vector3Int> neighbours          = mapManager.GetNeighbours(enemyCellPosition, 1);
                    Vector3Int        shortestMove        = new Vector3Int(0, 0, 0);
                    int        shortestMoveDist           = 100;
                    Vector3Int furthestFromRockets        = new Vector3Int(0, 0, 0);
                    int        sumFurthestFromRocketsDist = 0;
                    int        i = 1;
                    foreach (Vector3Int neighbour in neighbours)
                    {
                        if (i == 1)
                        {
                            shortestMove     = neighbour;
                            shortestMoveDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(nearestEndFlat));

                            if (rockets.Length > 0)
                            {
                                furthestFromRockets        = neighbour;
                                sumFurthestFromRocketsDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(gridLayout.WorldToCell(rockets[0].transform.position)));
                            }
                        }
                        else
                        {
                            if (mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(nearestEndFlat)) < shortestMoveDist)
                            {
                                shortestMove     = neighbour;
                                shortestMoveDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(nearestEndFlat));
                            }

                            int thisSumFurthestFromRocketsDist = 0;
                            foreach (GameObject rocket in rockets)
                            {
                                thisSumFurthestFromRocketsDist += mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(gridLayout.WorldToCell(rocket.transform.position)));
                            }
                            if (thisSumFurthestFromRocketsDist > sumFurthestFromRocketsDist)
                            {
                                furthestFromRockets        = neighbour;
                                sumFurthestFromRocketsDist = thisSumFurthestFromRocketsDist;
                            }
                        }
                        i++;
                    }
                    foreach (EnemyObject listEnemy in mapManager.spawnedEnemies)
                    {
                        if (listEnemy.xCoordinate == thisEnemyObject.xCoordinate && listEnemy.yCoordinate == thisEnemyObject.yCoordinate)
                        {
                            mapManager.spawnedEnemies.Remove(listEnemy);
                            break;
                        }
                    }

                    if (runAway)
                    {
                        SetOrientation(gridLayout.CellToWorld(furthestFromRockets));
                        transform.position += (gridLayout.CellToWorld(furthestFromRockets) - gridLayout.CellToWorld(enemyCellPosition));
                    }
                    else
                    {
                        SetOrientation(gridLayout.CellToWorld(shortestMove));
                        transform.position += (gridLayout.CellToWorld(shortestMove) - gridLayout.CellToWorld(enemyCellPosition));
                    }
                    enemyCellPosition = gridLayout.WorldToCell(transform.position);
                    thisEnemyObject   = new EnemyObject(enemyCellPosition.x, enemyCellPosition.y, thisEnemyObject.enemyString);
                    mapManager.spawnedEnemies.Add(thisEnemyObject);
                }
                else
                {
                    Instantiate(enemyLaser, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
                }


                break;

            case "EnemyB":
                if (distToPlayer > 1 || runAway)
                {
                    List <Vector3Int> neighbours          = mapManager.GetNeighbours(enemyCellPosition, 1);
                    Vector3Int        shortestMove        = new Vector3Int(0, 0, 0);
                    int        shortestMoveDist           = 100;
                    Vector3Int furthestFromRockets        = new Vector3Int(0, 0, 0);
                    int        sumFurthestFromRocketsDist = 0;
                    int        i = 1;
                    foreach (Vector3Int neighbour in neighbours)
                    {
                        if (i == 1)
                        {
                            shortestMove     = neighbour;
                            shortestMoveDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), movementController.playerCellPositionCubeCoords);

                            if (rockets.Length > 0)
                            {
                                furthestFromRockets        = neighbour;
                                sumFurthestFromRocketsDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(gridLayout.WorldToCell(rockets[0].transform.position)));
                            }
                        }
                        else
                        {
                            if (mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), movementController.playerCellPositionCubeCoords) < shortestMoveDist)
                            {
                                shortestMove     = neighbour;
                                shortestMoveDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), movementController.playerCellPositionCubeCoords);
                            }

                            int thisSumFurthestFromRocketsDist = 0;
                            foreach (GameObject rocket in rockets)
                            {
                                thisSumFurthestFromRocketsDist += mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(gridLayout.WorldToCell(rocket.transform.position)));
                            }
                            if (thisSumFurthestFromRocketsDist > sumFurthestFromRocketsDist)
                            {
                                furthestFromRockets        = neighbour;
                                sumFurthestFromRocketsDist = thisSumFurthestFromRocketsDist;
                            }
                        }
                        i++;
                    }

                    foreach (EnemyObject listEnemy in mapManager.spawnedEnemies)
                    {
                        if (listEnemy.xCoordinate == thisEnemyObject.xCoordinate && listEnemy.yCoordinate == thisEnemyObject.yCoordinate)
                        {
                            mapManager.spawnedEnemies.Remove(listEnemy);
                            break;
                        }
                    }

                    if (runAway)
                    {
                        SetOrientation(gridLayout.CellToWorld(furthestFromRockets));
                        transform.position += (gridLayout.CellToWorld(furthestFromRockets) - gridLayout.CellToWorld(enemyCellPosition));
                    }
                    else
                    {
                        SetOrientation(gridLayout.CellToWorld(shortestMove));
                        transform.position += (gridLayout.CellToWorld(shortestMove) - gridLayout.CellToWorld(enemyCellPosition));
                    }
                    enemyCellPosition = gridLayout.WorldToCell(transform.position);
                    thisEnemyObject   = new EnemyObject(enemyCellPosition.x, enemyCellPosition.y, thisEnemyObject.enemyString);
                    mapManager.spawnedEnemies.Add(thisEnemyObject);
                }
                else
                {
                    Instantiate(enemyLaser, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
                }

                break;

            case "EnemyC":
                if (distToPlayer > 2 || runAway)
                {
                    List <Vector3Int> neighbours          = mapManager.GetNeighbours(enemyCellPosition, 1);
                    Vector3Int        shortestMove        = new Vector3Int(0, 0, 0);
                    int        shortestMoveDist           = 100;
                    Vector3Int longestJump                = new Vector3Int(0, 0, 0);
                    int        longestJumpDist            = 0;
                    Vector3Int furthestFromRockets        = new Vector3Int(0, 0, 0);
                    int        sumFurthestFromRocketsDist = 0;
                    int        i        = 1;
                    int        randJump = Random.Range(0, 2);
                    if (jumpChargeTracker < 1 && randJump > 0.1)
                    {
                        jumpChargeTracker = 1;
                        List <Vector3Int> playerNeighbours = mapManager.GetNeighbours(movementController.playerCellPosition, 2);

                        foreach (Vector3Int playerNeighbour in playerNeighbours)
                        {
                            if (mapManager.HexCellDistance(mapManager.evenq2cube(playerNeighbour), mapManager.evenq2cube(enemyCellPosition)) > longestJumpDist)
                            {
                                longestJump     = playerNeighbour;
                                longestJumpDist = mapManager.HexCellDistance(mapManager.evenq2cube(playerNeighbour), mapManager.evenq2cube(enemyCellPosition));
                            }
                        }
                        foreach (EnemyObject listEnemy in mapManager.spawnedEnemies)
                        {
                            if (listEnemy.xCoordinate == thisEnemyObject.xCoordinate && listEnemy.yCoordinate == thisEnemyObject.yCoordinate)
                            {
                                mapManager.spawnedEnemies.Remove(listEnemy);
                                break;
                            }
                        }
                        SetOrientation(gridLayout.CellToWorld(longestJump));
                        transform.position += (gridLayout.CellToWorld(longestJump) - gridLayout.CellToWorld(enemyCellPosition));
                        enemyCellPosition   = gridLayout.WorldToCell(transform.position);
                        thisEnemyObject     = new EnemyObject(enemyCellPosition.x, enemyCellPosition.y, thisEnemyObject.enemyString);
                        mapManager.spawnedEnemies.Add(thisEnemyObject);
                    }
                    else
                    {
                        foreach (Vector3Int neighbour in neighbours)
                        {
                            if (i == 1)
                            {
                                shortestMove     = neighbour;
                                shortestMoveDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), movementController.playerCellPositionCubeCoords);

                                if (rockets.Length > 0)
                                {
                                    furthestFromRockets        = neighbour;
                                    sumFurthestFromRocketsDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(gridLayout.WorldToCell(rockets[0].transform.position)));
                                }
                            }
                            else
                            {
                                if (mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), movementController.playerCellPositionCubeCoords) < shortestMoveDist)
                                {
                                    shortestMove     = neighbour;
                                    shortestMoveDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), movementController.playerCellPositionCubeCoords);
                                }

                                int thisSumFurthestFromRocketsDist = 0;
                                foreach (GameObject rocket in rockets)
                                {
                                    thisSumFurthestFromRocketsDist += mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(gridLayout.WorldToCell(rocket.transform.position)));
                                }
                                if (thisSumFurthestFromRocketsDist > sumFurthestFromRocketsDist)
                                {
                                    furthestFromRockets        = neighbour;
                                    sumFurthestFromRocketsDist = thisSumFurthestFromRocketsDist;
                                }
                            }
                            i++;
                        }

                        foreach (EnemyObject listEnemy in mapManager.spawnedEnemies)
                        {
                            if (listEnemy.xCoordinate == thisEnemyObject.xCoordinate && listEnemy.yCoordinate == thisEnemyObject.yCoordinate)
                            {
                                mapManager.spawnedEnemies.Remove(listEnemy);
                                break;
                            }
                        }

                        if (runAway)
                        {
                            SetOrientation(gridLayout.CellToWorld(furthestFromRockets));
                            transform.position += (gridLayout.CellToWorld(furthestFromRockets) - gridLayout.CellToWorld(enemyCellPosition));
                        }
                        else
                        {
                            SetOrientation(gridLayout.CellToWorld(shortestMove));
                            transform.position += (gridLayout.CellToWorld(shortestMove) - gridLayout.CellToWorld(enemyCellPosition));
                        }
                        enemyCellPosition = gridLayout.WorldToCell(transform.position);
                        thisEnemyObject   = new EnemyObject(enemyCellPosition.x, enemyCellPosition.y, thisEnemyObject.enemyString);
                        mapManager.spawnedEnemies.Add(thisEnemyObject);

                        if (jumpChargeTracker >= 1)
                        {
                            jumpChargeTracker--;
                        }
                    }
                }
                else
                {
                    Instantiate(enemyLaser, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
                    if (jumpChargeTracker >= 1)
                    {
                        jumpChargeTracker--;
                    }
                }

                break;

            default:
                break;
            }
        }
    }