Example #1
0
 public BehaviorDefendCastleKeyPosition(Formation formation)
     : base(formation)
 {
     this._teamAISiegeDefender = formation.Team.TeamAI as TeamAISiegeComponent;
     this._behaviourState      = BehaviorDefendCastleKeyPosition.BehaviourState.UnSet;
     this._laddersOnThisSide   = new List <SiegeLadder>();
     this.ResetOrderPositions();
 }
Example #2
0
        protected internal override void TickOccasionally()
        {
            base.TickOccasionally();
            BehaviorDefendCastleKeyPosition.BehaviourState behaviourState = (this._teamAISiegeDefender == null ? 0 : (TeamAISiegeComponent.SiegeLanes.Any <SiegeLane>((Func <SiegeLane, bool>)(sl =>
            {
                if (sl.LaneSide != this.behaviorSide)
                {
                    return(false);
                }
                return(sl.IsOpen || sl.PrimarySiegeWeapons.Any <IPrimarySiegeWeapon>((Func <IPrimarySiegeWeapon, bool>)(psw => psw is SiegeWeapon && (psw as SiegeWeapon).GetComponent <SiegeWeaponMovementComponent>() != null && (psw as SiegeWeapon).GetComponent <SiegeWeaponMovementComponent>().HasArrivedAtTarget)));
            })) ? 1 : 0)) != 0 ? BehaviorDefendCastleKeyPosition.BehaviourState.Ready : BehaviorDefendCastleKeyPosition.BehaviourState.Waiting;
            if (behaviourState != this._behaviourState)
            {
                this._behaviourState    = behaviourState;
                this.CurrentOrder       = this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready ? this._readyOrder : this._waitOrder;
                this.CurrentFacingOrder = this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready ? this._readyFacingOrder : this._waitFacingOrder;
            }
            if (Mission.Current.MissionTeamAIType == Mission.MissionTeamAITypeEnum.Siege)
            {
                if (this._outerGate != null && this._outerGate.State == CastleGate.GateState.Open && !this._outerGate.IsDestroyed)
                {
                    if (!this.formation.IsUsingMachine((UsableMachine)this._outerGate))
                    {
                        this.formation.StartUsingMachine((UsableMachine)this._outerGate);
                    }
                }
                else if (this._innerGate != null && this._innerGate.State == CastleGate.GateState.Open && (!this._innerGate.IsDestroyed && !this.formation.IsUsingMachine((UsableMachine)this._innerGate)))
                {
                    this.formation.StartUsingMachine((UsableMachine)this._innerGate);
                }
                foreach (SiegeLadder siegeLadder in this._laddersOnThisSide)
                {
                    if (!siegeLadder.IsDisabledForBattleSide(BattleSideEnum.Defender) && !this.formation.IsUsingMachine((UsableMachine)siegeLadder))
                    {
                        this.formation.StartUsingMachine((UsableMachine)siegeLadder);
                    }
                }
            }
            this.CalculateCurrentOrder();
            this.formation.MovementOrder = this.CurrentOrder;
            this.formation.FacingOrder   = this.CurrentFacingOrder;
            if (this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready && this._tacticalMiddlePos != null)
            {
                this.formation.FormOrder = FormOrder.FormOrderCustom(this._tacticalMiddlePos.Width);
            }
            else if (this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Waiting && this._tacticalWaitPos != null)
            {
                this.formation.FormOrder = FormOrder.FormOrderCustom(this._tacticalWaitPos.Width);
            }
            bool flag = this._isDefendingWideGap && this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready && this.formation.QuerySystem.ClosestEnemyFormation != null && (this.formation.QuerySystem.IsUnderRangedAttack || (double)this.formation.QuerySystem.AveragePosition.DistanceSquared(this.CurrentOrder.GetPosition(this.formation).AsVec2) < 25.0 + (this._isInShieldWallDistance ? 75.0 : 0.0));

            if (flag == this._isInShieldWallDistance)
            {
                return;
            }
            this._isInShieldWallDistance = flag;
            if (this._isInShieldWallDistance && this.formation.QuerySystem.HasShield)
            {
                if (!(this.formation.ArrangementOrder != ArrangementOrder.ArrangementOrderShieldWall))
                {
                    return;
                }
                this.formation.ArrangementOrder = ArrangementOrder.ArrangementOrderShieldWall;
            }
            else
            {
                if (!(this.formation.ArrangementOrder == ArrangementOrder.ArrangementOrderLine))
                {
                    return;
                }
                this.formation.ArrangementOrder = ArrangementOrder.ArrangementOrderLine;
            }
        }