internal override void OnValidBehaviorSideSet()
        {
            base.OnValidBehaviorSideSet();
            this._ladders = Mission.Current.ActiveMissionObjects.Where <MissionObject>((Func <MissionObject, bool>)(amo => amo is SiegeLadder)).Select <MissionObject, SiegeLadder>((Func <MissionObject, SiegeLadder>)(amo => amo as SiegeLadder)).ToList <SiegeLadder>();
            this._ladders.RemoveAll((Predicate <SiegeLadder>)(l => l.IsDeactivated || l.WeaponSide != this.behaviorSide));
            SiegeLane siegeLane = TeamAISiegeComponent.SiegeLanes.FirstOrDefault <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == this.behaviorSide));

            this._breachedWallSegment = (siegeLane != null ? siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>((Func <ICastleKeyPosition, bool>)(dp => dp is WallSegment && (dp as WallSegment).IsBreachedWall)) : (ICastleKeyPosition)null) as WallSegment;
            this.ResetFollowOrder();
            this._behaviourState = BehaviorWaitForLadders.BehaviourState.Unset;
        }
        private void ResetOrderPositions()
        {
            this._primarySiegeWeapons = Mission.Current.ActiveMissionObjects.FindAllWithType <UsableMachine>().Where <UsableMachine>((Func <UsableMachine, bool>)(amo => amo is IPrimarySiegeWeapon)).Select <UsableMachine, IPrimarySiegeWeapon>((Func <UsableMachine, IPrimarySiegeWeapon>)(amo => amo as IPrimarySiegeWeapon)).ToList <IPrimarySiegeWeapon>();
            this._primarySiegeWeapons.RemoveAll((Predicate <IPrimarySiegeWeapon>)(uM => uM.WeaponSide != this.behaviorSide));
            IEnumerable <ICastleKeyPosition> source = TeamAISiegeComponent.SiegeLanes.Where <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == this.behaviorSide)).SelectMany <SiegeLane, ICastleKeyPosition>((Func <SiegeLane, IEnumerable <ICastleKeyPosition> >)(sila => (IEnumerable <ICastleKeyPosition>)sila.DefensePoints));

            this._innerGate   = this._teamAISiegeComponent.InnerGate;
            this._isGateLane  = this._teamAISiegeComponent.OuterGate.DefenseSide == this.behaviorSide;
            this._wallSegment = !this._isGateLane ? (!(source.FirstOrDefault <ICastleKeyPosition>((Func <ICastleKeyPosition, bool>)(dp => dp is WallSegment && (dp as WallSegment).IsBreachedWall)) is WallSegment wallSegment) ? this._primarySiegeWeapons.MaxBy <IPrimarySiegeWeapon, float>((Func <IPrimarySiegeWeapon, float>)(psw => psw.SiegeWeaponPriority)).TargetCastlePosition as WallSegment : wallSegment) : (WallSegment)null;
            this._stopOrder   = MovementOrder.MovementOrderStop;
            this._chargeOrder = MovementOrder.MovementOrderCharge;
            bool flag = this._teamAISiegeComponent.OuterGate != null && this.behaviorSide == this._teamAISiegeComponent.OuterGate.DefenseSide;

            this._attackEntityOrderOuterGate = !flag || this._teamAISiegeComponent.OuterGate.IsDeactivated || this._teamAISiegeComponent.OuterGate.State == CastleGate.GateState.Open ? MovementOrder.MovementOrderStop : MovementOrder.MovementOrderAttackEntity(this._teamAISiegeComponent.OuterGate.GameEntity, false);
            this._attackEntityOrderInnerGate = !flag || this._teamAISiegeComponent.InnerGate == null || (this._teamAISiegeComponent.InnerGate.IsDeactivated || this._teamAISiegeComponent.InnerGate.State == CastleGate.GateState.Open) ? MovementOrder.MovementOrderStop : MovementOrder.MovementOrderAttackEntity(this._teamAISiegeComponent.InnerGate.GameEntity, false);
            this._castleGateMoveOrder        = MovementOrder.MovementOrderMove(this._teamAISiegeComponent.OuterGate.MiddleFrame.Origin);
            this._wallSegmentMoveOrder       = !this._isGateLane ? MovementOrder.MovementOrderMove(this._wallSegment.MiddleFrame.Origin) : this._castleGateMoveOrder;
            this._facingOrder = FacingOrder.FacingOrderLookAtEnemy;
        }
        public BehaviorWaitForLadders(Formation formation)
            : base(formation)
        {
            this.behaviorSide = formation.AI.Side;
            this._ladders     = Mission.Current.ActiveMissionObjects.Where <MissionObject>((Func <MissionObject, bool>)(amo => amo is SiegeLadder)).Select <MissionObject, SiegeLadder>((Func <MissionObject, SiegeLadder>)(amo => amo as SiegeLadder)).ToList <SiegeLadder>();
            this._ladders.RemoveAll((Predicate <SiegeLadder>)(l => l.IsDeactivated || l.WeaponSide != this.behaviorSide));
            this._teamAISiegeComponent = (TeamAISiegeComponent)formation.Team.TeamAI;
            SiegeLane siegeLane = TeamAISiegeComponent.SiegeLanes.FirstOrDefault <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == this.behaviorSide));

            this._breachedWallSegment = (siegeLane != null ? siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>((Func <ICastleKeyPosition, bool>)(dp => dp is WallSegment && (dp as WallSegment).IsBreachedWall)) : (ICastleKeyPosition)null) as WallSegment;
            this.ResetFollowOrder();
            this._stopOrder = MovementOrder.MovementOrderStop;
            if (this._followOrder != (object)null)
            {
                this.CurrentOrder    = this._followOrder;
                this._behaviourState = BehaviorWaitForLadders.BehaviourState.Follow;
            }
            else
            {
                this.CurrentOrder    = this._stopOrder;
                this._behaviourState = BehaviorWaitForLadders.BehaviourState.Stop;
            }
        }
Exemplo n.º 4
0
        private void ResetOrderPositions()
        {
            this.behaviorSide = this.formation.AI.Side;
            this._innerGate   = (CastleGate)null;
            this._outerGate   = (CastleGate)null;
            this._laddersOnThisSide.Clear();
            int num1 = Mission.Current.ActiveMissionObjects.FindAllWithType <CastleGate>().Any <CastleGate>((Func <CastleGate, bool>)(cg => cg.DefenseSide == this.behaviorSide && cg.GameEntity.HasTag("outer_gate"))) ? 1 : 0;

            this._isDefendingWideGap = false;
            WorldFrame worldFrame1;
            WorldFrame worldFrame2;

            if (num1 != 0)
            {
                CastleGate outerGate = this._teamAISiegeDefender.OuterGate;
                this._innerGate          = this._teamAISiegeDefender.InnerGate;
                this._outerGate          = this._teamAISiegeDefender.OuterGate;
                worldFrame1              = outerGate.MiddleFrame;
                worldFrame2              = outerGate.DefenseWaitFrame;
                this._tacticalMiddlePos  = outerGate.MiddlePosition;
                this._tacticalWaitPos    = outerGate.WaitPosition;
                this._isDefendingWideGap = false;
            }
            else
            {
                WallSegment wallSegment = Mission.Current.ActiveMissionObjects.FindAllWithType <WallSegment>().Where <WallSegment>((Func <WallSegment, bool>)(ws => ws.DefenseSide == this.behaviorSide && ws.IsBreachedWall)).FirstOrDefault <WallSegment>();
                if (wallSegment != null)
                {
                    worldFrame1              = wallSegment.MiddleFrame;
                    worldFrame2              = wallSegment.DefenseWaitFrame;
                    this._tacticalMiddlePos  = wallSegment.MiddlePosition;
                    this._tacticalWaitPos    = wallSegment.WaitPosition;
                    this._isDefendingWideGap = false;
                }
                else
                {
                    IEnumerable <SiegeWeapon> source = Mission.Current.ActiveMissionObjects.FindAllWithType <SiegeWeapon>().Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(sw =>
                    {
                        if (!(sw is IPrimarySiegeWeapon) || (sw as IPrimarySiegeWeapon).WeaponSide != this.behaviorSide)
                        {
                            return(false);
                        }
                        return(!sw.IsDestroyed || (sw as IPrimarySiegeWeapon).HasCompletedAction());
                    }));
                    if (!source.Any <SiegeWeapon>())
                    {
                        worldFrame1             = WorldFrame.Invalid;
                        worldFrame2             = WorldFrame.Invalid;
                        this._tacticalMiddlePos = (TacticalPosition)null;
                        this._tacticalWaitPos   = (TacticalPosition)null;
                    }
                    else
                    {
                        this._laddersOnThisSide = source.Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(aw => aw is SiegeLadder)).Select <SiegeWeapon, SiegeLadder>((Func <SiegeWeapon, SiegeLadder>)(aw => aw as SiegeLadder)).ToList <SiegeLadder>();
                        ICastleKeyPosition targetCastlePosition = (source.FirstOrDefault <SiegeWeapon>() as IPrimarySiegeWeapon).TargetCastlePosition as ICastleKeyPosition;
                        worldFrame1             = targetCastlePosition.MiddleFrame;
                        worldFrame2             = targetCastlePosition.DefenseWaitFrame;
                        this._tacticalMiddlePos = targetCastlePosition.MiddlePosition;
                        this._tacticalWaitPos   = targetCastlePosition.WaitPosition;
                    }
                }
            }
            if (this._tacticalMiddlePos != null)
            {
                this._readyOrder       = MovementOrder.MovementOrderMove(this._tacticalMiddlePos.Position);
                this._readyFacingOrder = FacingOrder.FacingOrderLookAtDirection(this._tacticalMiddlePos.Direction);
            }
            else if (worldFrame1.Origin.IsValid)
            {
                double num2 = (double)worldFrame1.Rotation.f.Normalize();
                this._readyOrder       = MovementOrder.MovementOrderMove(worldFrame1.Origin);
                this._readyFacingOrder = FacingOrder.FacingOrderLookAtDirection(worldFrame1.Rotation.f.AsVec2);
            }
            else
            {
                this._readyOrder       = MovementOrder.MovementOrderStop;
                this._readyFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
            }
            if (this._tacticalWaitPos != null)
            {
                this._waitOrder       = MovementOrder.MovementOrderMove(this._tacticalWaitPos.Position);
                this._waitFacingOrder = FacingOrder.FacingOrderLookAtDirection(this._tacticalWaitPos.Direction);
            }
            else if (worldFrame2.Origin.IsValid)
            {
                double num2 = (double)worldFrame2.Rotation.f.Normalize();
                this._waitOrder       = MovementOrder.MovementOrderMove(worldFrame2.Origin);
                this._waitFacingOrder = FacingOrder.FacingOrderLookAtDirection(worldFrame2.Rotation.f.AsVec2);
            }
            else
            {
                this._waitOrder       = MovementOrder.MovementOrderStop;
                this._waitFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
            }
            this.CurrentOrder       = this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready ? this._readyOrder : this._waitOrder;
            this.CurrentFacingOrder = this.formation.QuerySystem.ClosestEnemyFormation == null || !TeamAISiegeComponent.IsFormationInsideCastle(this.formation.QuerySystem.ClosestEnemyFormation.Formation, true) ? (this._behaviourState == BehaviorDefendCastleKeyPosition.BehaviourState.Ready ? this._readyFacingOrder : this._waitFacingOrder) : FacingOrder.FacingOrderLookAtEnemy;
        }
        private void ArrangeDestructedMeshes()
        {
            float num1 = 0.0f;

            foreach (float hitPointPercentage in this._wallHitPointPercentages)
            {
                num1 += hitPointPercentage;
            }
            if (!((IEnumerable <float>) this._wallHitPointPercentages).IsEmpty <float>())
            {
                num1 /= (float)this._wallHitPointPercentages.Length;
            }
            float num2 = MBMath.Lerp(0.0f, 0.7f, 1f - num1);
            IEnumerable <SynchedMissionObject>  source1 = this.Mission.MissionObjects.OfType <SynchedMissionObject>();
            IEnumerable <DestructableComponent> destructibleComponents = source1.OfType <DestructableComponent>();

            foreach (StrategicArea strategicArea in this.Mission.ActiveMissionObjects.OfType <StrategicArea>().ToList <StrategicArea>())
            {
                strategicArea.DetermineAssociatedDestructibleComponents(destructibleComponents);
            }
            foreach (SynchedMissionObject synchedMissionObject in source1)
            {
                if (this._hasAnySiegeTower && synchedMissionObject.GameEntity.HasTag("tower_merlon"))
                {
                    synchedMissionObject.SetVisibleSynched(false, true);
                }
                else
                {
                    DestructableComponent firstScriptOfType = synchedMissionObject.GameEntity.GetFirstScriptOfType <DestructableComponent>();
                    if (firstScriptOfType != null && firstScriptOfType.CanBeDestroyedInitially && ((double)num2 > 0.0 && (double)MBRandom.RandomFloat <= (double)num2))
                    {
                        firstScriptOfType.PreDestroy();
                    }
                }
            }
            if ((double)num2 >= 0.100000001490116)
            {
                List <GameEntity> list = this.Mission.Scene.FindEntitiesWithTag("damage_decal").ToList <GameEntity>();
                foreach (GameEntity gameEntity in list)
                {
                    gameEntity.GetFirstScriptOfType <SynchedMissionObject>().SetVisibleSynched(false);
                }
                for (double num3 = Math.Floor((double)list.Count * (double)num2); num3 > 0.0; --num3)
                {
                    GameEntity gameEntity = list[MBRandom.RandomInt(list.Count)];
                    list.Remove(gameEntity);
                    gameEntity.GetFirstScriptOfType <SynchedMissionObject>().SetVisibleSynched(true);
                }
            }
            List <WallSegment> source2 = new List <WallSegment>();
            List <WallSegment> list1   = this.Mission.ActiveMissionObjects.FindAllWithType <WallSegment>().Where <WallSegment>((Func <WallSegment, bool>)(ws => ws.DefenseSide != FormationAI.BehaviorSide.BehaviorSideNotSet && ws.GameEntity.GetChildren().Any <GameEntity>((Func <GameEntity, bool>)(ge => ge.HasTag("broken_child"))))).ToList <WallSegment>();
            int val2 = 0;

            foreach (float hitPointPercentage in this._wallHitPointPercentages)
            {
                if ((double)Math.Abs(hitPointPercentage) < 9.99999974737875E-06)
                {
                    ++val2;
                }
            }
            int num4 = Math.Min(list1.Count <WallSegment>(), val2);

            while (num4 > 0)
            {
                WallSegment randomElement = list1.GetRandomElement <WallSegment>();
                randomElement.OnChooseUsedWallSegment(true);
                list1.Remove(randomElement);
                --num4;
                source2.Add(randomElement);
            }
            foreach (WallSegment wallSegment in list1)
            {
                wallSegment.OnChooseUsedWallSegment(false);
            }
            if ((double)num2 < 0.100000001490116)
            {
                return;
            }
            List <SiegeWeapon> siegeWeaponList = new List <SiegeWeapon>();

            foreach (SiegeWeapon siegeWeapon in this.Mission.ActiveMissionObjects.FindAllWithType <SiegeWeapon>().Where <SiegeWeapon>((Func <SiegeWeapon, bool>)(sw => sw is IPrimarySiegeWeapon)))
            {
                SiegeWeapon primarySiegeWeapon = siegeWeapon;
                if (source2.Any <WallSegment>((Func <WallSegment, bool>)(b => b.DefenseSide == ((IPrimarySiegeWeapon)primarySiegeWeapon).WeaponSide)))
                {
                    siegeWeaponList.Add(primarySiegeWeapon);
                }
            }
            siegeWeaponList.ForEach((Action <SiegeWeapon>)(siegeWeaponToRemove => siegeWeaponToRemove.SetDisabledSynched()));
        }