Пример #1
0
 // Use this for initialization
 void Start()
 {
     lockStatus    = GameObject.Find("PlayerData").GetComponent <Variables>();
     spellSelector = GameObject.Find("PlayerData").GetComponent <SpellSelector>();
     gui           = GameObject.Find("GUI").GetComponent <drawGUI>();
     SetLockSpeed(lockStatus.speed);
 }
Пример #2
0
 public void GetSpell(SpellTitles title, PlayerSpell spell, SpellSelector spellSelector)
 {
     this.spellSelector = spellSelector;
     this.title         = title;
     this.spell         = spell;
     icon.sprite        = spell.icon;
 }
Пример #3
0
        public virtual void Play()
        {
            Stopwatch sw = null;

            if (BenchmarkManager.Enable)
            {
                sw = Stopwatch.StartNew();
            }

            Environment.ResetMoveZone();

            SpellSelector.AnalysePossibilities();

            if (!Fighter.Fight.AIDebugMode)
            {
                ExecuteSpellCast();
                ExecutePostMove();
            }

            if (sw != null)
            {
                sw.Stop();

                if (sw.ElapsedMilliseconds > 50)
                {
                    BenchmarkManager.Instance.Add(BenchmarkEntry.Create("[AI] " + Fighter, sw.Elapsed, "type", "ai",
                                                                        "spells", SpellSelector.Possibilities.Select(x => x.Spell.ToString()).ToCSV(",")));
                }
            }
        }
Пример #4
0
    protected override void Awake()
    {
        alive = true;

        target_   = null;
        lockedOn  = false;
        selector_ = GetComponent <SpellSelector>();
        casting_  = false;
        animator_ = GetComponent <Animator>();
        inControl = true;
        fallen    = false;

        invincible_ = false;
        recovering_ = false;

        targetables = new List <Targetable>();
    }
Пример #5
0
 // Use this for initialization
 void Start()
 {
     lockStatus = GameObject.Find("PlayerData").GetComponent<Variables>();
     spellSelector = GameObject.Find("PlayerData").GetComponent<SpellSelector>();
     gui = GameObject.Find("GUI").GetComponent<drawGUI>();
     SetLockSpeed(lockStatus.speed);
 }
Пример #6
0
 public Brain(AIFighter fighter)
 {
     Fighter       = fighter;
     Environment   = new EnvironmentAnalyser(Fighter);
     SpellSelector = new SpellSelector(Fighter, Environment);
 }
Пример #7
0
        public void ExecuteSpellCast()
        {
            AISpellCastPossibility cast;

            while ((cast = SpellSelector.FindFirstSpellCast()) != null)
            {
                if (cast.MoveBefore != null)
                {
                    var success = Fighter.StartMove(cast.MoveBefore);
                    var lastPos = Fighter.Cell.Id;

                    var tries         = 0;
                    var destinationId = cast.MoveBefore.EndCell.Id;
                    // re-attempt to move if we didn't reach the cell i.e as we trigger a trap
                    while (success && Fighter.Cell.Id != destinationId && Fighter.CanMove() && tries <= MaxMovesTries)
                    {
                        var pathfinder = new Pathfinder(Environment.CellInformationProvider);
                        var path       = pathfinder.FindPath(Fighter.Position.Cell.Id, destinationId, false, Fighter.MP);

                        if (path == null || path.IsEmpty())
                        {
                            break;
                        }

                        if (path.MPCost > Fighter.MP)
                        {
                            break;
                        }

                        success = Fighter.StartMove(path);

                        // the mob didn't move so we give up
                        if (Fighter.Cell.Id == lastPos)
                        {
                            break;
                        }

                        lastPos = Fighter.Cell.Id;
                        tries++; // avoid infinite loops
                    }
                }

                var targets = Fighter.Fight.GetAllFighters(cast.Target.AffectedCells).ToArray();

                var i = 0;
                while (Fighter.CanCastSpell(cast.Spell, cast.TargetCell.Cell) == SpellCastResult.OK && i < cast.MaxConsecutiveCast)
                {
                    if (!Fighter.CastSpell(cast.Spell, cast.TargetCell.Cell))
                    {
                        break;
                    }

                    i++;

                    if (Fighter.AP > 0 && targets.All(x => !cast.Target.AffectedCells.Contains(x.Cell)) ||
                        targets.Any(x => x.IsDead())) // target has moved, we re-analyse the situation
                    {
                        SpellSelector.AnalysePossibilities();
                        break;
                    }
                }

                if (i > 0 && i < cast.MaxConsecutiveCast && Fighter.Spells.Values.Any(x => x.CurrentSpellLevel.ApCost <= Fighter.AP))
                {
                    SpellSelector.AnalysePossibilities();
                }
                else
                {
                    break;
                }
            }
        }