Exemple #1
0
        //Exaustively checks all enemies in vision and sets a best path based on paths to their neighboring tiles.
        //This is search heavy.
        private void CalculateBestTargetAndPath()
        {
            bestTarget = null;
            List <Actor> enemies = actor.GetComponent <Vision>().EnemiesInVision;

//			Debug.Log ("enemies size in calc: " + enemies.Count);
            if (enemies.Count <= 0)
            {
                return;
            }

            Actor bestT = enemies[0];


            //Without this, actors see a path other than when already adjacent to enemy.
            for (int i = 0; i < enemies.Count; i++)
            {
                if (AiController.TwoActorsAreAdjacent(enemies[i], actor) && !enemies[i].Dying)
                {
                    bestTarget = enemies [i];
                    return;
                }
            }

            List <ATTile> bestP = AiController.BestPathFromTo(actor, bestT);

            for (int i = 1; i < enemies.Count; i++)
            {
                if (enemies [i].Dying)
                {
                    continue;
                }

                List <ATTile> proposed = AiController.BestPathFromTo(actor, enemies [i]);
                if (bestP == null && proposed != null)
                {
                    bestP = proposed;
                    bestT = enemies [i];
                }
                else if (proposed != null && bestP != null && AiController.PathCost(bestP, actor) > AiController.PathCost(proposed, actor))
                {
                    bestP = proposed;
                    bestT = enemies [i];
                }
            }

//			Debug.LogError ("Calculated best target as: " + bestT.CharSheet.Name);
            if (bestP != null)
            {
                noPathToBestTarget = false;
                bestTarget         = bestT;
            }
            else
            {
                noPathToBestTarget = true;
//				Debug.LogError ("no path to any targets!");
            }
        }
Exemple #2
0
        private List <ATTile> BestPathTo(Actor enemy)
        {
//			return BestPath (PathsFromTiles (TilesAdjacentTo (enemy)));
            return(AiController.BestPath(
                       AiController.PathsFromTiles(
                           AiController.OccupyableTilesAdjacentTo(enemy)
                           , actor)
                       , actor));
        }
Exemple #3
0
        public FindingBestTarget(AiControlledActor actor, AiController aic) : base(actor, aic)
        {
            OnDidEnter += (s, fromPrevious) => {
                CalculateBestTargetAndPath();
                actor.OnTurnBegan += RecalcOnTurnBegan;
            };

            OnWillExit += (s, toDestination) => {
                actor.OnTurnBegan -= RecalcOnTurnBegan;
            };
        }
        //choose action???  Consults the current ai state?
        // Use this for initialization
        public override void Start()
        {
            base.Start();



            BattleManager.instance.ReportInAs(BattleManager.Side.ENEMY, this);
            controller = new AI.MeleeAttacker(this);
            controller.OnStateChanged += (fromS, toS) => {
                currentStateName = toS.GetType().ToString();
            };
            currentStateName = controller.CurrentState.GetType().ToString();
            StartCoroutine(UpdateAi());
        }
        public override Action DecideOnAction()
        {
            Move move = new Move(actor);

            move.cachedPath = AiController.DoablePath(MapManager.instance.AStarPathForMover(actor, position, true), actor);
            if (move.cachedPath.Count == 0)
            {
                if (!actor.UsedAction() && asFastAsPossible)
                {
                    return(new Dash(actor));
                }
                else
                {
                    return(new Wait(actor));
                }
            }

            return(move);
        }
        public Attacking(AiControlledActor actor, AiController aic) : base(actor, aic)
        {
            actor.GetComponent <Vision>().OnVisionOfEnemyLost += (Actor enemy) => {
                if (enemy == target)
                {
                    lostEnemySight = true;
                }
            };

            OnDidEnter += (s, fromPrevious) => {
                lostEnemySight        = false;
                targetMoved           = false;
                targetDied            = false;
                target.OnActorKilled += SetEnemyKilled;
                target.OnDidPerform  += SetTargetMoved;
            };
            OnWillExit += (s, toDestination) => {
                target.OnActorKilled -= SetEnemyKilled;
                target.OnDidPerform  -= SetTargetMoved;
            };
        }
Exemple #7
0
 public Camping(AiControlledActor actor, AiController aic) : base(actor, aic)
 {
 }
Exemple #8
0
 public AiState(AiControlledActor c, AiController aic) : base(aic)
 {
     this.actor = c;
 }
 public MovingToPosition(AiControlledActor actor, AiController aic) : base(actor, aic)
 {
     OnDidEnter += (s, fromPrevious) => {
         canceled = false;
     };
 }
Exemple #10
0
 public SeekingTarget(AiControlledActor actor, AiController aic) : base(actor, aic)
 {
     OnDidEnter += (s, fromPrevious) => {
         bestPosition = null;
     };
 }