Example #1
0
        private void CheckAndChangeState()
        {
            switch (this._state)
            {
            case TacticSallyOutHitAndRun.TacticState.HeadingOutFromCastle:
                if (!this._cavalryFormations.All <Formation>((Func <Formation, bool>)(cf => !TeamAISiegeComponent.IsFormationInsideCastle(cf, false))))
                {
                    break;
                }
                this._state = TacticSallyOutHitAndRun.TacticState.DestroyingSiegeWeapons;
                this.DestroySiegeWeapons();
                break;

            case TacticSallyOutHitAndRun.TacticState.DestroyingSiegeWeapons:
                if (!this._destructibleEnemySiegeWeapons.All <SiegeWeapon>((Func <SiegeWeapon, bool>)(desw => desw.IsDestroyed)) && !this._cavalryFormations.All <Formation>((Func <Formation, bool>)(cf =>
                {
                    if (!(cf.AI.ActiveBehavior is BehaviorDestroySiegeWeapons) || cf.MovementOrder == (object)MovementOrder.MovementOrderRetreat)
                    {
                        return(true);
                    }
                    if ((cf.AI.ActiveBehavior as BehaviorDestroySiegeWeapons).LastTargetWeapon == null)
                    {
                        return(false);
                    }
                    Vec3 globalPosition = (cf.AI.ActiveBehavior as BehaviorDestroySiegeWeapons).LastTargetWeapon.GameEntity.GlobalPosition;
                    return((double)this.team.QuerySystem.GetLocalEnemyPower(globalPosition.AsVec2) > (double)this.team.QuerySystem.GetLocalAllyPower(globalPosition.AsVec2) + (double)cf.QuerySystem.FormationPower);
                })))
                {
                    break;
                }
                this._state = TacticSallyOutHitAndRun.TacticState.CavalryRetreating;
                this.CavalryRetreat();
                break;

            case TacticSallyOutHitAndRun.TacticState.CavalryRetreating:
                if (!this._cavalryFormations.IsEmpty <Formation>() && !TeamAISiegeComponent.IsFormationGroupInsideCastle((IEnumerable <Formation>) this._cavalryFormations, false))
                {
                    break;
                }
                this._state = TacticSallyOutHitAndRun.TacticState.InfantryRetreating;
                this.InfantryRetreat();
                break;
            }
        }
Example #2
0
        public override bool MissionEnded(ref MissionResult missionResult)
        {
            if (this.IsSallyOutOver)
            {
                missionResult = MissionResult.CreateSuccessful((IMission)this.Mission);
                return(true);
            }
            if (this._checkState != SallyOutEndLogic.EndConditionCheckState.Active)
            {
                return(false);
            }
            foreach (Team team in (ReadOnlyCollection <Team>) this.Mission.Teams)
            {
                switch (team.Side)
                {
                case BattleSideEnum.Defender:
                    if (team.FormationsIncludingSpecial.Any <Formation>() && team.Formations.Any <Formation>((Func <Formation, bool>)(f => !TeamAISiegeComponent.IsFormationInsideCastle(f, false, 0.9f))))
                    {
                        this._checkState = SallyOutEndLogic.EndConditionCheckState.Idle;
                        return(false);
                    }
                    continue;

                case BattleSideEnum.Attacker:
                    if (TeamAISiegeComponent.IsFormationGroupInsideCastle(team.FormationsIncludingSpecial, false, 0.1f))
                    {
                        this._checkState = SallyOutEndLogic.EndConditionCheckState.Idle;
                        return(false);
                    }
                    continue;

                default:
                    continue;
                }
            }
            this.IsSallyOutOver = true;
            missionResult       = MissionResult.CreateSuccessful((IMission)this.Mission);
            return(true);
        }