Пример #1
0
 public virtual void DoPatrol()
 {
     routes.Clear();
     for (int i = 0; i < 10; i++)
     {
         int     dir  = UnityEngine.Random.Range(0, 6);
         HexCell cell = currentCell.GetNeighbour((HexDirection)dir);
         if (cell.CanbeDestination())
         {
             routes.Add(cell);
             routePtr = 0;
             IsMoving = true;
             return;
         }
     }
     for (int i = 0; i < 6; i++)
     {
         HexCell cell = currentCell.GetNeighbour((HexDirection)i);
         if (cell.CanbeDestination())
         {
             routes.Add(cell);
             routePtr = 0;
             IsMoving = true;
             return;
         }
     }
     SetIsAction(false);
 }
Пример #2
0
    private void UpdateRoute()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            if (hit.collider.GetComponent <HexCell>())
            {
                HexCell toCell = hit.collider.GetComponent <HexCell>();
                if (!toCell.CanbeDestination() ||
                    toCell == selectedPawn.currentCell ||
                    !hexMap.IsReachable(toCell))
                {
                    validRoute = false;
                }
                else
                {
                    validRoute = true;
                }
                hexMap.FindPath(selectedPawn.currentCell, toCell);
                //hexMap.ShowPath(selectedPawn.currentCell, toCell);
            }
        }
    }
Пример #3
0
    public void Move(HexCell from, HexCell to)
    {
        if (!to.CanbeDestination())
        {
            return;
        }

        from.pawn   = null;
        to.pawn     = this;
        currentCell = to;
    }
Пример #4
0
    public bool SetGameEventDisplayerCell(GameEventDisplayer displayer, HexCell cell)
    {
        if (displayer == null || cell == null || !cell.CanbeDestination())
        {
            return(false);
        }
        cell.gameEventDisplayer = displayer;
        displayer.currentCell   = cell;

        displayer.transform.position = cell.transform.position;
        return(true);
    }
Пример #5
0
    public bool SetBuildingCell(Building building, HexCell cell)
    {
        if (building == null || cell == null || !cell.CanbeDestination())
        {
            return(false);
        }
        cell.building        = building;
        building.currentCell = cell;

        building.transform.position = cell.transform.position;
        return(true);
    }
Пример #6
0
    public HexCell GetRandomCellToSpawn()
    {
        // make it centered
        int     ranX = Random.Range(mapWidth / 4, mapWidth / 4 * 3);
        int     ranY = Random.Range(mapHeight / 4, mapHeight / 4 * 3);
        HexCell cell = cells[ranX + ranY * mapWidth];

        while (!cell.CanbeDestination())
        {
            ranX = Random.Range(mapWidth / 4, mapWidth / 4 * 3);
            ranY = Random.Range(mapHeight / 4, mapHeight / 4 * 3);
            cell = cells[ranX + ranY * mapWidth];
        }
        return(cell);
    }
Пример #7
0
    public HexCell GetEmptyNearestCellAround(HexCell startcell)
    {
        if (startcell == null)
        {
            return(null);
        }

        List <HexCell> cellToFind = new List <HexCell>();

        // Set distance to max value
        for (int i = 0; i < cells.Length; i++)
        {
            cells[i].Distance = int.MaxValue;
            cells[i].prevCell = null;
        }

        startcell.Distance = 0;
        cellToFind.Add(startcell);
        while (cellToFind.Count > 0)
        {
            HexCell cell = cellToFind[0];
            cellToFind.RemoveAt(0);

            for (HexDirection dir = (HexDirection)0; dir <= (HexDirection)5; dir++)
            {
                HexCell nextCell = cell.GetNeighbour(dir);
                if (nextCell != null)
                {
                    if (nextCell.Distance == int.MaxValue)
                    {
                        nextCell.Distance = 0;
                        cellToFind.Add(nextCell);
                    }
                }
                if (cell != startcell && cell.CanbeDestination())
                {
                    return(cell);
                }
            }
            cellToFind.Sort((x, y) => x.Distance.CompareTo(y.Distance));
        }
        return(null);
    }
Пример #8
0
    public bool SetCharacterCell(Pawn pawn, HexCell cell)
    {
        if (pawn == null || cell == null || !cell.CanbeDestination())
        {
            return(false);
        }

        HexCell oldCell = pawn.currentCell;

        if (oldCell != null)
        {
            oldCell.pawn = null;
        }
        pawn.currentCell = cell;
        cell.pawn        = pawn;

        pawn.transform.position = cell.transform.position;

        return(true);
    }
Пример #9
0
    public void FindReachableCells(HexCell startCell, int maxDistance)
    {
        List <HexCell> cellToFind = new List <HexCell>();

        for (int i = 0; i < cells.Length; i++)
        {
            cells[i].Distance = int.MaxValue;
        }

        startCell.Distance = 0;
        cellToFind.Add(startCell);
        reachableCells.Clear();

        while (cellToFind.Count > 0)
        {
            HexCell cell = cellToFind[0];
            cellToFind.RemoveAt(0);

            for (HexDirection dir = (HexDirection)0; dir <= (HexDirection)5; dir++)
            {
                HexCell nextCell = cell.GetNeighbour(dir);
                if (nextCell != null)
                {
                    int distance = cell.Distance;
                    if (!nextCell.CanbeDestination())
                    {
                        continue;
                    }
                    else if (nextCell.hexType == HexType.Plain)
                    {
                        distance = cell.Distance + 1;
                    }
                    else if (nextCell.hexType == HexType.Forest || nextCell.hexType == HexType.Swamp)
                    {
                        distance = cell.Distance + 2;
                    }

                    if (nextCell.Distance == int.MaxValue)
                    {
                        nextCell.Distance = distance;
                        if (nextCell.Distance < maxDistance + 1)
                        {
                            cellToFind.Add(nextCell);
                        }
                    }
                    else if (nextCell.Distance > distance)
                    {
                        if (nextCell.Distance > distance)
                        {
                            nextCell.Distance = distance;
                        }
                    }
                    if (cell.Distance <= maxDistance && cell != startCell && cell.hexType != HexType.Mountain && cell.hexType != HexType.Thorns && cell.hexType != HexType.Stones)
                    {
                        reachableCells.Add(cell);
                    }
                }
            }
            cellToFind.Sort((x, y) => x.Distance.CompareTo(y.Distance));
        }

        reachableCells.Remove(startCell);
    }
Пример #10
0
    public void FindPath(HexCell fromCell, HexCell toCell)
    {
        if (fromCell == toCell || !toCell.CanbeDestination())
        {
            return;
        }

        List <HexCell> cellToFind = new List <HexCell>();

        currentRoutes.Clear();

        // Set distance to max value
        for (int i = 0; i < cells.Length; i++)
        {
            cells[i].Distance = int.MaxValue;
            cells[i].prevCell = null;
        }

        fromCell.Distance = 0;
        cellToFind.Add(fromCell);
        while (cellToFind.Count > 0)
        {
            HexCell cell = cellToFind[0];
            cellToFind.RemoveAt(0);
            if (cell == toCell)
            {
                break;
            }

            for (HexDirection dir = (HexDirection)0; dir <= (HexDirection)5; dir++)
            {
                HexCell nextCell = cell.GetNeighbour(dir);
                if (nextCell != null)
                {
                    int distance = cell.Distance;
                    if (!nextCell.CanbeDestination())
                    {
                        continue;
                    }
                    else if (nextCell.hexType == HexType.Plain)
                    {
                        distance = cell.Distance + 1;
                    }
                    else if (nextCell.hexType == HexType.Forest || nextCell.hexType == HexType.Swamp)
                    {
                        distance = cell.Distance + 2;
                    }


                    nextCell.heuristicDistance = nextCell.DistanceTo(toCell);
                    if (nextCell.Distance == int.MaxValue)
                    {
                        distance         += nextCell.heuristicDistance;
                        nextCell.Distance = distance;
                        cellToFind.Add(nextCell);
                        nextCell.prevCell = cell;
                    }
                    else if (nextCell.Distance > distance + nextCell.heuristicDistance)
                    {
                        nextCell.Distance = distance + nextCell.heuristicDistance;
                        nextCell.prevCell = cell;
                    }
                }
            }
            cellToFind.Sort((x, y) => x.Distance.CompareTo(y.Distance));
        }
        pathLength = 0;
        currentRoutes.Clear();
        if (toCell.prevCell != null)
        {
            HexCell prev = toCell;
            while (prev != fromCell)
            {
                currentRoutes.Insert(0, prev);
                pathLength += (prev.hexType == HexType.Plain)?1:2;
                prev        = prev.prevCell;
            }
        }
    }
Пример #11
0
    public Enemy SpawnEnemyAtCell(EnemyType type, HexCell cell)
    {
        Enemy newEnemy = null;

        if (cell.CanbeDestination())
        {
            switch (type)
            {
            case EnemyType.wanderingswordman:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_sword);
                break;

            case EnemyType.magicapprentice:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_magic);
                break;

            case EnemyType.thief:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_thief);
                break;

            case EnemyType.bandit:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_bandit);
                break;

            case EnemyType.robinhood:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_robinhood);
                break;

            case EnemyType.banditcaptain:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_banditcaptain);
                break;

            case EnemyType.berserker:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_berserker);
                break;

            case EnemyType.bard:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_bard);
                break;

            case EnemyType.magicmaster:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_magicmaster);
                break;

            case EnemyType.tatenoyousya:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_tatenoyousta);
                break;

            case EnemyType.magicgrandmaster:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_magicmgraneaster);
                break;

            case EnemyType.witch:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_witch);
                break;

            case EnemyType.assassin:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_assassin);
                break;

            case EnemyType.catapult:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_catapult);
                break;

            case EnemyType.jinjyamiko:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_jinjyamiko);
                break;

            case EnemyType.cultist:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_cultist);
                break;

            case EnemyType.priest:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_priest);
                break;

            case EnemyType.bloodwitch:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_bloodwitch);
                break;

            case EnemyType.darkknight:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_darkknight);
                break;

            case EnemyType.orchestraleader:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_orchestraleader);
                break;

            case EnemyType.magebelial:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_magebelial);
                break;

            case EnemyType.royalinquisitor:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_royalinquisitor);
                break;

            case EnemyType.shadowfran:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_shadowfran);
                break;

            case EnemyType.cardinaleriri:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_cardinaleriri);
                break;

            case EnemyType.cinderlord:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_cinderlord);
                break;

            case EnemyType.andrethehero:
                newEnemy = Instantiate <Enemy>(EnemyPrefab_andrethehero);
                break;

            default:
                break;
            }

            if (newEnemy != null)
            {
                gm.characterReader.InitEnemyData(ref newEnemy, getEnemyLevel(type), type);
                newEnemy.healthbar = gm.healthbarManager.InitializeHealthBar(newEnemy);
                EnemyPawns.Add(newEnemy);

                newEnemy.transform.SetParent(EnemyRoot.transform);
                gm.hexMap.SetCharacterCell(newEnemy, cell);

                //UnityEngine.Debug.Log(newEnemy.Name + " - Current Cell: " + newEnemy.currentCell.ToString());
                //gm.hexMap.RevealCell(cell);
                gm.gameCamera.FocusOnPoint(cell.transform.localPosition);

                gm.animationManager.PlayCreateEff(newEnemy.transform.position);
            }
        }
        return(newEnemy);
    }