Exemplo n.º 1
0
        private void ScheduleMovementForToon(ToonScript toon, GameAction action)
        {
            var pathFinding = new AstarPathFinding();
            IEnumerable <MovingStep> movingSteps = pathFinding.FromTo((int)toon.transform.position.x, (int)toon.transform.position.z, action.X, action.Z);

            toon.ScheduleMovingSteps(movingSteps);
        }
Exemplo n.º 2
0
        private void ScheduleMovementForNeerRockPosition(ToonScript toon, GameAction action)
        {
            var pathFinding = new AstarPathFinding();
            int startX      = (int)toon.transform.position.x;
            int startZ      = (int)toon.transform.position.z;

            List <IEnumerable <MovingStep> > allPaths = new List <IEnumerable <MovingStep> >();

            for (int xoff = -1; xoff <= 1; xoff++)
            {
                if (xoff == 0)
                {
                    continue;
                }
                if (MapService.IsBlockedPosition(action.X + xoff, action.Z))
                {
                    continue;
                }

                IEnumerable <MovingStep> movingSteps = pathFinding.FromTo(startX, startZ, action.X + xoff, action.Z);
                if (movingSteps.Any())
                {
                    allPaths.Add(movingSteps);
                }
            }

            for (int zoff = -1; zoff <= 1; zoff++)
            {
                if (zoff == 0)
                {
                    continue;
                }
                if (MapService.IsBlockedPosition(action.X, action.Z + zoff))
                {
                    continue;
                }

                IEnumerable <MovingStep> movingSteps = pathFinding.FromTo(startX, startZ, action.X, action.Z + zoff);
                if (movingSteps.Any())
                {
                    allPaths.Add(movingSteps);
                }
            }

            if (allPaths.Any())
            {
                var shortestPath = allPaths.OrderBy(p => p.Count()).First();
                toon.ScheduleMovingSteps(shortestPath);
                toon.SetLifeGoal(ToonLifeGoals.MineRock, action.X, action.Z);
            }
            else
            {
                toon.SetLifeGoal(ToonLifeGoals.Wait, startX, startZ);
            }
        }
Exemplo n.º 3
0
        private void ContinueRoad(ToonScript toon, GameAction action)
        {
            var pathFinding = new AstarPathFinding();
            int startX      = (int)toon.transform.position.x;
            int startZ      = (int)toon.transform.position.z;

            var path = pathFinding.FromTo(startX, startZ, action.X, action.Z);

            toon.ScheduleMovingSteps(path);
            toon.SetLifeGoal(ToonLifeGoals.ContinueRoad, action.X, action.Z);
        }
Exemplo n.º 4
0
 public void AddToon(ToonScript villager)
 {
     if (villager == null)
     {
         return;
     }
     if (Toons.Contains(villager))
     {
         return;
     }
     Toons.Add(villager);
 }
Exemplo n.º 5
0
        private void ScheduleMovementToPullKing(ToonScript toon, GameAction action)
        {
            var kingPos = MapService.GetKingPosition();
            var kingX   = (int)kingPos.x;
            var kingZ   = (int)kingPos.z;

            bool bestFound = false;
            int  bestX     = kingX;
            int  bestZ     = kingZ;

            for (int xoff = -1; xoff <= 1; xoff++)
            {
                if (xoff == 0)
                {
                    continue;
                }
                if (!MapService.IsBlockedPosition(kingX + xoff, kingZ))
                {
                    bestX     = kingX + xoff;
                    bestZ     = kingZ;
                    bestFound = true;
                }
            }

            for (int zoff = -1; zoff <= 1; zoff++)
            {
                if (zoff == 0)
                {
                    continue;
                }
                if (!MapService.IsBlockedPosition(kingX, kingZ + zoff))
                {
                    bestX     = kingX;
                    bestZ     = kingZ + zoff;
                    bestFound = true;
                }
            }

            if (!bestFound)
            {
                return;
            }

            var pathFinding = new AstarPathFinding();
            int startX      = (int)toon.transform.position.x;
            int startZ      = (int)toon.transform.position.z;

            IEnumerable <MovingStep> movingSteps = pathFinding.FromTo(startX, startZ, bestX, bestZ);

            toon.ScheduleMovingSteps(movingSteps);
            toon.SetLifeGoal(ToonLifeGoals.PullKing, action.X, action.Z);
        }
Exemplo n.º 6
0
 void Start()
 {
     ResetFlashingColor();
     toon = GetComponent <ToonScript>();
 }
Exemplo n.º 7
0
 public bool IsToonSelected(ToonScript toon)
 {
     return(SelectedToon == toon);
 }