internal override float GetTacticWeight()
        {
            float  num1 = this.team.QuerySystem.PowerRatioIncludingCasualties / this.team.QuerySystem.OverallPowerRatio;
            double num2 = (double)MBMath.LinearExtrapolation(0.0f, Math.Max(this.team.QuerySystem.InfantryRatio, Math.Max(this.team.QuerySystem.RangedRatio, this.team.QuerySystem.CavalryRatio)), MBMath.ClampFloat(num1, 0.0f, 2.66f) / 2f);
            float  num3 = this.team.QuerySystem.EnemyTeams.Average <TeamQuerySystem>((Func <TeamQuerySystem, float>)(et => et.CavalryRatio)) + this.team.QuerySystem.EnemyTeams.Average <TeamQuerySystem>((Func <TeamQuerySystem, float>)(et => et.RangedCavalryRatio));
            double num4 = (double)num3 != 0.0 ? (double)MBMath.Lerp(0.8f, 1.2f, MBMath.ClampFloat((this.team.QuerySystem.CavalryRatio + this.team.QuerySystem.RangedCavalryRatio) / num3, 0.0f, 2f) / 2f) : 1.20000004768372;

            return((float)(num2 * num4) * (float)Math.Min(1.0, Math.Sqrt((double)this.team.QuerySystem.OverallPowerRatio)));
        }
Example #2
0
 private void TickCameraZoom(float dt)
 {
     if (!((NativeObject)this._camera != (NativeObject)null))
     {
         return;
     }
     this.SetCamFovHorizontal(MBMath.ClampFloat(this._camera.HorizontalFov + this._curZoomSpeed, 0.1f, 2f));
     if ((double)dt <= 0.0)
     {
         return;
     }
     this._curZoomSpeed = MBMath.Lerp(this._curZoomSpeed, 0.0f, MBMath.ClampFloat(dt * 25.9f, 0.0f, 1f), 1E-05f);
 }
 protected override void OnBehaviorActivatedAux()
 {
     this._cantShoot         = false;
     this._cantShootDistance = float.MaxValue;
     this._behaviorState     = BehaviorSkirmish.BehaviorState.Shooting;
     this._cantShootTimer.Reset(Mission.Current.Time, MBMath.Lerp(5f, 10f, (float)(((double)MBMath.ClampFloat((float)this.formation.CountOfUnits, 10f, 60f) - 10.0) * 0.0199999995529652)));
     this.CalculateCurrentOrder();
     this.formation.MovementOrder    = this.CurrentOrder;
     this.formation.FacingOrder      = this.CurrentFacingOrder;
     this.formation.ArrangementOrder = ArrangementOrder.ArrangementOrderLoose;
     this.formation.FiringOrder      = FiringOrder.FiringOrderFireAtWill;
     this.formation.FormOrder        = FormOrder.FormOrderWide;
     this.formation.WeaponUsageOrder = WeaponUsageOrder.WeaponUsageOrderUseAny;
 }
Example #4
0
        private float GetTacticalPositionScore(TacticalPosition tacticalPosition)
        {
            if (!this.CheckAndDetermineFormation(ref this._mainInfantry, (Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation)) || !this.CheckAndDetermineFormation(ref this._archers, (Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation)))
            {
                return(0.0f);
            }
            double    num1          = (double)MBMath.Lerp(1f, 1.5f, MBMath.ClampFloat(tacticalPosition.Slope, 0.0f, 60f) / 60f);
            Formation formation     = this.team.Formations.Where <Formation>((Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation)).MaxBy <Formation, int>((Func <Formation, int>)(f => f.CountOfUnits));
            float     num2          = Math.Max(formation.arrangement.Depth, formation.arrangement.Width);
            float     num3          = MBMath.ClampFloat(tacticalPosition.Width / num2, 0.7f, 1f);
            float     num4          = tacticalPosition.IsInsurmountable ? 1.5f : 1f;
            float     cavalryFactor = this.GetCavalryFactor(tacticalPosition);
            float     num5          = MBMath.Lerp(0.7f, 1f, (float)((150.0 - (double)MBMath.ClampFloat(this._mainInfantry.QuerySystem.AveragePosition.Distance(tacticalPosition.Position.AsVec2), 50f, 150f)) / 100.0));
            double    num6          = (double)num3;

            return((float)(num1 * num6) * num4 * cavalryFactor * num5);
        }
        static bool PrefixGetAiWeight(ref Formation ___formation, ref float __result)
        {
            if (___formation != null)
            {
                FormationQuerySystem querySystem = ___formation.QuerySystem;
                if (___formation.AI.ActiveBehavior == null)
                {
                    __result = 0f;
                    return(false);
                }
                PropertyInfo property = typeof(BehaviorComponent).GetProperty("BehaviorCoherence", BindingFlags.NonPublic | BindingFlags.Instance);
                property.DeclaringType.GetProperty("BehaviorCoherence");
                float behaviorCoherence = (float)property.GetValue(___formation.AI.ActiveBehavior, BindingFlags.NonPublic | BindingFlags.GetProperty, null, null, null) * 2.75f;

                //__result =  MBMath.Lerp(0.1f, 1.2f, MBMath.ClampFloat(behaviorCoherence * (querySystem.FormationIntegrityData.DeviationOfPositionsExcludeFarAgents + 1f) / (querySystem.IdealAverageDisplacement + 1f), 0f, 3f) / 3f);
                __result = MBMath.Lerp(0.1f, 1.2f, MBMath.ClampFloat(behaviorCoherence * (querySystem.FormationIntegrityData.DeviationOfPositionsExcludeFarAgents + 1f) / (querySystem.IdealAverageDisplacement + 1f), 0f, 3f) / 3f);
                return(false);
            }
            return(true);
        }
Example #6
0
        private float GetTacticalPositionScore(TacticalPosition tacticalPosition)
        {
            if (!this.CheckAndDetermineFormation(ref this._mainInfantry, (Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation)))
            {
                return(0.0f);
            }
            double num1         = (double)MBMath.Lerp(1f, 1.5f, MBMath.ClampFloat(tacticalPosition.Slope, 0.0f, 60f) / 60f);
            int    countOfUnits = this._mainInfantry.CountOfUnits;
            float  num2         = MBMath.Lerp(0.67f, 1.5f, (float)(((double)MBMath.ClampFloat((float)((double)this._mainInfantry.Interval * (double)(countOfUnits - 1) + (double)this._mainInfantry.UnitDiameter * (double)countOfUnits) / tacticalPosition.Width, 0.5f, 3f) - 0.5) / 2.5));
            float  num3         = 1f;

            if (this.CheckAndDetermineFormation(ref this._archers, (Func <Formation, bool>)(f => f.QuerySystem.IsRangedFormation)) && tacticalPosition.LinkedTacticalPositions.Where <TacticalPosition>((Func <TacticalPosition, bool>)(lcp => lcp.TacticalPositionType == TacticalPosition.TacticalPositionTypeEnum.Cliff)).ToList <TacticalPosition>().Any <TacticalPosition>())
            {
                num3 = MBMath.Lerp(1f, 1.5f, (float)(((double)MBMath.ClampFloat(this.team.QuerySystem.RangedRatio, 0.05f, 0.25f) - 0.0500000007450581) * 5.0));
            }
            float  num4 = MBMath.Lerp(0.7f, 1f, (float)((150.0 - (double)MBMath.ClampFloat(this._mainInfantry.QuerySystem.AveragePosition.Distance(tacticalPosition.Position.AsVec2), 50f, 150f)) / 100.0));
            double num5 = (double)num2;

            return((float)(num1 * num5) * num3 * num4);
        }
        internal override float GetTacticWeight()
        {
            if (!this.team.TeamAI.IsDefenseApplicable || this.Formations.All <Formation>((Func <Formation, bool>)(f => !f.QuerySystem.IsInfantryFormation)))
            {
                return(0.0f);
            }
            Formation formation = this._mainInfantry ?? this.Formations.Where <Formation>((Func <Formation, bool>)(f => f.QuerySystem.IsInfantryFormation)).MaxBy <Formation, int>((Func <Formation, int>)(f => f.CountOfUnits));

            if (formation == null)
            {
                return(0.0f);
            }
            if (this._mainInfantry == null)
            {
                this._mainInfantry = formation;
            }
            double num1 = (double)this.team.QuerySystem.InfantryRatio + (double)this.team.QuerySystem.RangedRatio;
            float  num2 = MBMath.Lerp(0.7f, 1f, (float)((150.0 - (double)MBMath.ClampFloat(this._mainInfantry.QuerySystem.AveragePosition.Distance(this._mainInfantry.QuerySystem.HighGroundCloseToForeseenBattleGround), 50f, 150f)) / 100.0));

            return((float)(num1 * 1.10000002384186) * TacticComponent.CalculateNotEngagingTacticalAdvantage(this.team.QuerySystem) * num2 / (float)Math.Sqrt((double)this.team.QuerySystem.OverallPowerRatio));
        }
        protected internal override void OnTick(float dt)
        {
            if (this.SynchronizeCompleted)
            {
                return;
            }
            MatrixFrame frame1 = this.GameEntity.GetFrame();

            if (this._synchState == SynchedMissionObject.SynchState.SynchronizePosition && this._lastSynchedFrame.origin.NearlyEquals(frame1.origin) || this._lastSynchedFrame.NearlyEquals(frame1))
            {
                this.SetSynchState(SynchedMissionObject.SynchState.SynchronizeCompleted);
            }
            else
            {
                MatrixFrame frame2;
                frame2.origin = this._synchState == SynchedMissionObject.SynchState.SynchronizeFrameOverTime ? MBMath.Lerp(this._firstFrame.origin, this._lastSynchedFrame.origin, this._timer / this._duration, 0.2f * dt) : MBMath.Lerp(frame1.origin, this._lastSynchedFrame.origin, 8f * dt, 0.2f * dt);
                if (this._synchState == SynchedMissionObject.SynchState.SynchronizeFrame || this._synchState == SynchedMissionObject.SynchState.SynchronizeFrameOverTime)
                {
                    frame2.rotation.s = MBMath.Lerp(frame1.rotation.s, this._lastSynchedFrame.rotation.s, 8f * dt, 0.2f * dt);
                    frame2.rotation.f = MBMath.Lerp(frame1.rotation.f, this._lastSynchedFrame.rotation.f, 8f * dt, 0.2f * dt);
                    frame2.rotation.u = MBMath.Lerp(frame1.rotation.u, this._lastSynchedFrame.rotation.u, 8f * dt, 0.2f * dt);
                    if (frame2.origin != this._lastSynchedFrame.origin || frame2.rotation.s != this._lastSynchedFrame.rotation.s || (frame2.rotation.f != this._lastSynchedFrame.rotation.f || frame2.rotation.u != this._lastSynchedFrame.rotation.u))
                    {
                        frame2.rotation.Orthonormalize();
                        if (this._lastSynchedFrame.rotation.HasScale())
                        {
                            frame2.rotation.ApplyScaleLocal(this._lastSynchedFrame.rotation.GetScaleVector());
                        }
                    }
                    this.GameEntity.SetFrame(ref frame2);
                }
                else
                {
                    this.GameEntity.SetLocalPosition(frame2.origin);
                }
                this._timer = Math.Min(this._timer + dt, this._duration);
            }
        }
Example #9
0
        protected override void CalculateCurrentOrder()
        {
            WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition;
            bool          flag           = false;
            Vec2          vec2_1;
            WorldPosition worldPosition;
            Vec2          vec2_2;

            if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation == null || this._archerFormation == null)
            {
                vec2_1 = this.formation.Direction;
                medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
            }
            else
            {
                worldPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition;
                vec2_1        = worldPosition.AsVec2 - this.formation.QuerySystem.AveragePosition;
                float val2 = vec2_1.Normalize();
                float num  = this._archerFormation.QuerySystem.RangedUnitRatio * 0.5f / (float)this._archerFormation.arrangement.RankCount;
                switch (this._behaviorState)
                {
                case BehaviorCautiousAdvance.BehaviorState.Approaching:
                    if ((double)val2 < (double)this._cantShootDistance * 0.800000011920929)
                    {
                        this._behaviorState = BehaviorCautiousAdvance.BehaviorState.Shooting;
                        this._cantShoot     = false;
                        flag = true;
                    }
                    else if ((double)this._archerFormation.QuerySystem.MakingRangedAttackRatio >= (double)num * 1.20000004768372)
                    {
                        this._behaviorState = BehaviorCautiousAdvance.BehaviorState.Shooting;
                        this._cantShoot     = false;
                        flag = true;
                    }
                    if (this._behaviorState == BehaviorCautiousAdvance.BehaviorState.Shooting)
                    {
                        this._shootPosition = this.formation.QuerySystem.AveragePosition + vec2_1 * 5f;
                        break;
                    }
                    break;

                case BehaviorCautiousAdvance.BehaviorState.Shooting:
                    if ((double)this._archerFormation.QuerySystem.MakingRangedAttackRatio <= (double)num)
                    {
                        if ((double)val2 > (double)this._archerFormation.QuerySystem.MissileRange)
                        {
                            this._behaviorState     = BehaviorCautiousAdvance.BehaviorState.Approaching;
                            this._cantShootDistance = Math.Min(this._cantShootDistance, this._archerFormation.QuerySystem.MissileRange * 0.9f);
                            this._shootPosition     = Vec2.Invalid;
                            break;
                        }
                        if (!this._cantShoot)
                        {
                            this._cantShoot = true;
                            this._cantShootTimer.Reset(Mission.Current.Time, this._archerFormation == null ? 10f : MBMath.Lerp(10f, 15f, (float)(((double)MBMath.ClampFloat((float)this._archerFormation.CountOfUnits, 10f, 60f) - 10.0) * 0.0199999995529652)));
                            break;
                        }
                        if (this._cantShootTimer.Check(Mission.Current.Time))
                        {
                            this._behaviorState     = BehaviorCautiousAdvance.BehaviorState.Approaching;
                            this._cantShootDistance = Math.Min(this._cantShootDistance, val2);
                            this._shootPosition     = Vec2.Invalid;
                            break;
                        }
                        break;
                    }
                    this._cantShootDistance = Math.Max(this._cantShootDistance, val2);
                    this._cantShoot         = false;
                    if ((!this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsRangedFormation && !this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsRangedCavalryFormation || (double)val2 < (double)this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MissileRange && (double)this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MakingRangedAttackRatio < 0.100000001490116) && (double)val2 < (double)Math.Min(this._archerFormation.QuerySystem.MissileRange * 0.4f, this._cantShootDistance * 0.667f))
                    {
                        this._behaviorState = BehaviorCautiousAdvance.BehaviorState.PullingBack;
                        this._shootPosition = Vec2.Invalid;
                        break;
                    }
                    break;

                case BehaviorCautiousAdvance.BehaviorState.PullingBack:
                    if ((double)val2 > (double)Math.Min(this._cantShootDistance, this._archerFormation.QuerySystem.MissileRange) * 0.800000011920929)
                    {
                        this._behaviorState = BehaviorCautiousAdvance.BehaviorState.Shooting;
                        this._cantShoot     = false;
                        this._shootPosition = this.formation.QuerySystem.AveragePosition + vec2_1 * 5f;
                        flag = true;
                        break;
                    }
                    break;
                }
                switch (this._behaviorState)
                {
                case BehaviorCautiousAdvance.BehaviorState.Approaching:
                    medianPosition = this.formation.QuerySystem.ClosestEnemyFormation.MedianPosition;
                    if (this._switchedToShieldWallRecently && !this._switchedToShieldWallTimer.Check(Mission.Current.Time) && (double)this.formation.QuerySystem.FormationDispersedness > 2.0)
                    {
                        if (this._reformPosition.IsValid)
                        {
                            medianPosition.SetVec2(this._reformPosition);
                            break;
                        }
                        worldPosition        = this.formation.QuerySystem.Team.MedianTargetFormationPosition;
                        vec2_2               = worldPosition.AsVec2 - this.formation.QuerySystem.AveragePosition;
                        vec2_1               = vec2_2.Normalized();
                        this._reformPosition = this.formation.QuerySystem.AveragePosition + vec2_1 * 5f;
                        medianPosition.SetVec2(this._reformPosition);
                        break;
                    }
                    this._switchedToShieldWallRecently = false;
                    this._reformPosition = Vec2.Invalid;
                    medianPosition.SetVec2(this.formation.QuerySystem.ClosestEnemyFormation.AveragePosition);
                    break;

                case BehaviorCautiousAdvance.BehaviorState.Shooting:
                    if (this._shootPosition.IsValid)
                    {
                        medianPosition.SetVec2(this._shootPosition);
                        break;
                    }
                    medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
                    break;

                case BehaviorCautiousAdvance.BehaviorState.PullingBack:
                    medianPosition = this.formation.QuerySystem.MedianPosition;
                    medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
                    break;
                }
            }
            worldPosition = this.CurrentOrder.GetPosition(this.formation);
            if (((!worldPosition.IsValid ? 1 : (this._behaviorState != BehaviorCautiousAdvance.BehaviorState.Shooting ? 1 : 0)) | (flag ? 1 : 0)) == 0)
            {
                worldPosition = this.CurrentOrder.GetPosition(this.formation);
                if ((double)worldPosition.GetNavMeshVec3().DistanceSquared(medianPosition.GetNavMeshVec3()) < (double)this.formation.Depth * (double)this.formation.Depth)
                {
                    goto label_34;
                }
            }
            this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition);
label_34:
            vec2_2 = this.CurrentFacingOrder.GetDirection(this.formation);
            if (vec2_2.IsValid && !(this._behaviorState != BehaviorCautiousAdvance.BehaviorState.Shooting | flag))
            {
                vec2_2 = this.CurrentFacingOrder.GetDirection(this.formation);
                if ((double)vec2_2.DotProduct(vec2_1) > (double)MBMath.Lerp(0.5f, 1f, (float)(1.0 - (double)MBMath.ClampFloat(this.formation.Width, 1f, 20f) * 0.0500000007450581)))
                {
                    return;
                }
            }
            this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(vec2_1);
        }
Example #10
0
        protected override void OnBehaviorActivatedAux()
        {
            IEnumerable <Formation> source = this.formation.Team.Formations.Where <Formation>((Func <Formation, bool>)(f => f != this.formation && f.QuerySystem.IsRangedFormation));

            if (source.Any <Formation>())
            {
                this._archerFormation = source.MaxBy <Formation, float>((Func <Formation, float>)(f => f.QuerySystem.FormationPower));
            }
            this._cantShoot         = false;
            this._cantShootDistance = float.MaxValue;
            this._behaviorState     = BehaviorCautiousAdvance.BehaviorState.Shooting;
            this._cantShootTimer.Reset(Mission.Current.Time, this._archerFormation == null ? 10f : MBMath.Lerp(10f, 15f, (float)(((double)MBMath.ClampFloat((float)this._archerFormation.CountOfUnits, 10f, 60f) - 10.0) * 0.0199999995529652)));
            this.CalculateCurrentOrder();
            this.formation.MovementOrder    = this.CurrentOrder;
            this.formation.FacingOrder      = this.CurrentFacingOrder;
            this._isInShieldWallDistance    = true;
            this.formation.ArrangementOrder = ArrangementOrder.ArrangementOrderLine;
            this.formation.FiringOrder      = FiringOrder.FiringOrderFireAtWill;
            this.formation.FormOrder        = FormOrder.FormOrderWide;
            this.formation.WeaponUsageOrder = WeaponUsageOrder.WeaponUsageOrderUseAny;
        }
        protected override void CalculateCurrentOrder()
        {
            WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition;
            bool          flag           = false;
            Vec2          direction;
            WorldPosition worldPosition;

            if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation == null)
            {
                direction = this.formation.Direction;
                medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
            }
            else
            {
                worldPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition;
                direction     = worldPosition.AsVec2 - this.formation.QuerySystem.AveragePosition;
                float val2 = direction.Normalize();
                float num  = MBMath.Lerp(0.1f, 0.33f, (float)(1.0 - (double)MBMath.ClampFloat((float)this.formation.CountOfUnits, 1f, 50f) * 0.0199999995529652)) * this.formation.QuerySystem.RangedUnitRatio;
                switch (this._behaviorState)
                {
                case BehaviorSkirmish.BehaviorState.Approaching:
                    if ((double)val2 < (double)this._cantShootDistance * 0.800000011920929)
                    {
                        this._behaviorState = BehaviorSkirmish.BehaviorState.Shooting;
                        this._cantShoot     = false;
                        flag = true;
                        break;
                    }
                    if ((double)this.formation.QuerySystem.MakingRangedAttackRatio >= (double)num * 1.20000004768372)
                    {
                        this._behaviorState = BehaviorSkirmish.BehaviorState.Shooting;
                        this._cantShoot     = false;
                        flag = true;
                        break;
                    }
                    break;

                case BehaviorSkirmish.BehaviorState.Shooting:
                    if ((double)this.formation.QuerySystem.MakingRangedAttackRatio <= (double)num)
                    {
                        if ((double)val2 > (double)this.formation.QuerySystem.MissileRange)
                        {
                            this._behaviorState     = BehaviorSkirmish.BehaviorState.Approaching;
                            this._cantShootDistance = Math.Min(this._cantShootDistance, this.formation.QuerySystem.MissileRange * 0.9f);
                            break;
                        }
                        if (!this._cantShoot)
                        {
                            this._cantShoot = true;
                            this._cantShootTimer.Reset(Mission.Current.Time, MBMath.Lerp(5f, 10f, (float)(((double)MBMath.ClampFloat((float)this.formation.CountOfUnits, 10f, 60f) - 10.0) * 0.0199999995529652)));
                            break;
                        }
                        if (this._cantShootTimer.Check(Mission.Current.Time))
                        {
                            this._behaviorState     = BehaviorSkirmish.BehaviorState.Approaching;
                            this._cantShootDistance = Math.Min(this._cantShootDistance, val2);
                            break;
                        }
                        break;
                    }
                    this._cantShootDistance = Math.Max(this._cantShootDistance, val2);
                    this._cantShoot         = false;
                    if (this.formation.QuerySystem.IsInfantryFormation && (double)val2 < (double)Math.Min(this.formation.QuerySystem.MissileRange * 0.4f, this._cantShootDistance * 0.666f))
                    {
                        this._behaviorState = BehaviorSkirmish.BehaviorState.PullingBack;
                        break;
                    }
                    break;

                case BehaviorSkirmish.BehaviorState.PullingBack:
                    if ((double)val2 > (double)Math.Min(this._cantShootDistance, this.formation.QuerySystem.MissileRange) * 0.800000011920929)
                    {
                        this._behaviorState = BehaviorSkirmish.BehaviorState.Shooting;
                        this._cantShoot     = false;
                        flag = true;
                        break;
                    }
                    break;
                }
                switch (this._behaviorState)
                {
                case BehaviorSkirmish.BehaviorState.Approaching:
                    medianPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition;
                    medianPosition.SetVec2(this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.AveragePosition);
                    break;

                case BehaviorSkirmish.BehaviorState.Shooting:
                    medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
                    break;

                case BehaviorSkirmish.BehaviorState.PullingBack:
                    medianPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition;
                    medianPosition.SetVec2(medianPosition.AsVec2 - direction * (float)((double)this.formation.QuerySystem.MissileRange - (double)this.formation.Depth * 0.5 - 10.0));
                    break;
                }
            }
            worldPosition = this.CurrentOrder.GetPosition(this.formation);
            if (((!worldPosition.IsValid ? 1 : (this._behaviorState != BehaviorSkirmish.BehaviorState.Shooting ? 1 : 0)) | (flag ? 1 : 0)) != 0)
            {
                this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition);
            }
            if (((!this.CurrentFacingOrder.GetDirection(this.formation).IsValid ? 1 : (this._behaviorState != BehaviorSkirmish.BehaviorState.Shooting ? 1 : 0)) | (flag ? 1 : 0)) == 0)
            {
                return;
            }
            this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);
        }
        protected override float GetAiWeight()
        {
            FormationQuerySystem querySystem = this.formation.QuerySystem;

            return(MBMath.Lerp(0.1f, 1f, MBMath.ClampFloat(querySystem.RangedUnitRatio + querySystem.RangedCavalryUnitRatio, 0.0f, 0.5f) * 2f));
        }
        //private int GetWeaponSkill(BasicCharacterObject character, WeaponComponentData equippedItem)
        //{
        //    SkillObject skill = DefaultSkills.Athletics;
        //    if (equippedItem != null)
        //        skill = equippedItem.RelevantSkill;
        //    return character.GetSkillValue(skill);
        //}

        //private int GetMeleeSkill(
        //    BasicCharacterObject character,
        //    WeaponComponentData equippedItem,
        //    WeaponComponentData secondaryItem)
        //{
        //    SkillObject skill = DefaultSkills.Athletics;
        //    if (equippedItem != null)
        //    {
        //        SkillObject relevantSkill = equippedItem.RelevantSkill;
        //        skill = relevantSkill == DefaultSkills.OneHanded || relevantSkill == DefaultSkills.Polearm ? relevantSkill : (relevantSkill != DefaultSkills.TwoHanded ? DefaultSkills.OneHanded : (secondaryItem == null ? DefaultSkills.TwoHanded : DefaultSkills.OneHanded));
        //    }
        //    return character.GetSkillValue(skill);
        //}

        private void EnhancedSetAiRelatedProperties(
            Agent agent,
            AgentDrivenProperties agentDrivenProperties)
        {
            MissionEquipment    equipment         = agent.Equipment;
            EquipmentIndex      mainHandItemIndex = agent.GetWieldedItemIndex(Agent.HandIndex.MainHand);
            MissionWeapon       missionWeapon;
            WeaponComponentData mainHandWeapon;

            if (mainHandItemIndex == EquipmentIndex.None)
            {
                mainHandWeapon = null;
            }
            else
            {
                missionWeapon  = equipment[mainHandItemIndex];
                mainHandWeapon = missionWeapon.CurrentUsageItem;
            }

            EquipmentIndex      offHandItemIndex = agent.GetWieldedItemIndex(Agent.HandIndex.OffHand);
            WeaponComponentData offHandWeapon;

            if (offHandItemIndex == EquipmentIndex.None)
            {
                offHandWeapon = null;
            }
            else
            {
                missionWeapon = equipment[offHandItemIndex];
                offHandWeapon = missionWeapon.CurrentUsageItem;
            }
            var   config = ImprovedCombatAIConfig.Get();
            float meleeAILevel;

            if (config.DirectlySetMeleeAI)
            {
                meleeAILevel = MathF.Clamp(config.MeleeAIDifficulty / 100.0f, 0, 1);
            }
            else
            {
                int meleeSkill = GetMeleeSkill(agent, mainHandWeapon, offHandWeapon);
                meleeAILevel = CalculateAILevel(agent, meleeSkill);
                meleeAILevel = MathF.Clamp(meleeAILevel / Math.Max(1 - config.MeleeAIDifficulty / 100f, 0.001f), 0, 1);
            }

            float rangedAILevel;

            if (config.DirectlySetRangedAI)
            {
                rangedAILevel = MathF.Clamp(config.RangedAIDifficulty / 100.0f, 0, 1);
            }
            else
            {
                SkillObject skill       = mainHandWeapon == null ? DefaultSkills.Athletics : mainHandWeapon.RelevantSkill;
                int         weaponSkill = GetEffectiveSkill(agent.Character, agent.Origin, agent.Formation, skill);
                rangedAILevel = CalculateAILevel(agent, weaponSkill);
                rangedAILevel = MathF.Clamp(rangedAILevel / Math.Max(1 - config.RangedAIDifficulty / 100f, 0.001f), 0, 1);
            }

            float num1 = meleeAILevel + agent.Defensiveness;

            agentDrivenProperties.AiRangedHorsebackMissileRange = (float)(0.300000011920929 + 0.400000005960464 * rangedAILevel);
            agentDrivenProperties.AiFacingMissileWatch          = (float)(meleeAILevel * 0.0599999986588955 - 0.959999978542328);
            agentDrivenProperties.AiFlyingMissileCheckRadius    = (float)(8.0 - 6.0 * meleeAILevel);
            agentDrivenProperties.AiShootFreq             = (float)(0.300000011920929 + 0.699999988079071 * rangedAILevel);
            agentDrivenProperties.AiWaitBeforeShootFactor = agent._propertyModifiers.resetAiWaitBeforeShootFactor ? 0.0f : (float)(1.0 - 0.5 * rangedAILevel);
            int num2 = offHandWeapon != null ? 1 : 0;

            agentDrivenProperties.AIBlockOnDecideAbility     = MBMath.Lerp(0.25f, 0.99f, MBMath.ClampFloat((float)Math.Pow(meleeAILevel, 1.0), 0.0f, 1f));
            agentDrivenProperties.AIParryOnDecideAbility     = MBMath.Lerp(0.01f, 0.95f, MBMath.ClampFloat((float)Math.Pow(meleeAILevel, 1.5), 0.0f, 1f));
            agentDrivenProperties.AiTryChamberAttackOnDecide = (float)((meleeAILevel - 0.150000005960464) * 0.100000001490116);
            agentDrivenProperties.AIAttackOnParryChance      = (float)(0.300000011920929 - 0.100000001490116 * agent.Defensiveness);
            agentDrivenProperties.AiAttackOnParryTiming      = (float)(0.300000011920929 * meleeAILevel - 0.200000002980232);
            agentDrivenProperties.AIDecideOnAttackChance     = 0.15f * agent.Defensiveness;
            agentDrivenProperties.AIParryOnAttackAbility     = MBMath.ClampFloat((float)Math.Pow(meleeAILevel, 3.0), 0.0f, 1f);
            agentDrivenProperties.AiKick = (float)(meleeAILevel - 0.100000001490116);
            agentDrivenProperties.AiAttackCalculationMaxTimeFactor            = meleeAILevel;
            agentDrivenProperties.AiDecideOnAttackWhenReceiveHitTiming        = (float)(-0.25 * (1.0 - meleeAILevel));
            agentDrivenProperties.AiDecideOnAttackContinueAction              = (float)(-0.5 * (1.0 - meleeAILevel));
            agentDrivenProperties.AiDecideOnAttackingContinue                 = 0.1f * meleeAILevel;
            agentDrivenProperties.AIParryOnAttackingContinueAbility           = MBMath.Lerp(0.05f, 0.95f, MBMath.ClampFloat((float)Math.Pow(meleeAILevel, 3.0), 0.0f, 1f));
            agentDrivenProperties.AIDecideOnRealizeEnemyBlockingAttackAbility = 0.5f * MBMath.ClampFloat((float)Math.Pow(meleeAILevel, 2.5) - 0.1f, 0.0f, 1f);
            agentDrivenProperties.AIRealizeBlockingFromIncorrectSideAbility   = 0.5f * MBMath.ClampFloat((float)Math.Pow(meleeAILevel, 2.5) - 0.1f, 0.0f, 1f);
            agentDrivenProperties.AiAttackingShieldDefenseChance              = (float)(0.200000002980232 + 0.300000011920929 * meleeAILevel);
            agentDrivenProperties.AiAttackingShieldDefenseTimer               = (float)(0.300000011920929 * meleeAILevel - 0.300000011920929);
            agentDrivenProperties.AiRandomizedDefendDirectionChance           = (float)(1.0 - Math.Log(meleeAILevel * 7.0 + 1.0, 2.0) * 0.333330005407333);
            agentDrivenProperties.AISetNoAttackTimerAfterBeingHitAbility      = MBMath.ClampFloat((float)Math.Pow(meleeAILevel, 2.0), 0.05f, 0.95f);
            agentDrivenProperties.AISetNoAttackTimerAfterBeingParriedAbility  = MBMath.ClampFloat((float)Math.Pow(meleeAILevel, 2.0), 0.05f, 0.95f);
            agentDrivenProperties.AISetNoDefendTimerAfterHittingAbility       = MBMath.ClampFloat((float)Math.Pow(meleeAILevel, 2.0), 0.05f, 0.95f);
            agentDrivenProperties.AISetNoDefendTimerAfterParryingAbility      = MBMath.ClampFloat((float)Math.Pow(meleeAILevel, 2.0), 0.05f, 0.95f);
            agentDrivenProperties.AIEstimateStunDurationPrecision             = 1f - MBMath.ClampFloat((float)Math.Pow(meleeAILevel, 2.0), 0.05f, 0.95f);
            agentDrivenProperties.AIHoldingReadyMaxDuration                 = MBMath.Lerp(0.25f, 0.0f, Math.Min(1f, meleeAILevel * 1.2f));
            agentDrivenProperties.AIHoldingReadyVariationPercentage         = meleeAILevel;
            agentDrivenProperties.AiRaiseShieldDelayTimeBase                = (float)(0.5 * meleeAILevel - 0.75);
            agentDrivenProperties.AiUseShieldAgainstEnemyMissileProbability = (float)(0.100000001490116 + meleeAILevel * 0.600000023841858 + num1 * 0.200000002980232);
            agentDrivenProperties.AiCheckMovementIntervalFactor             = (float)(0.00499999988824129 * (1.10000002384186 - meleeAILevel));
            agentDrivenProperties.AiMovemetDelayFactor                  = (float)(4.0 / (3.0 + rangedAILevel));
            agentDrivenProperties.AiParryDecisionChangeValue            = (float)(0.0500000007450581 + 0.699999988079071 * meleeAILevel);
            agentDrivenProperties.AiDefendWithShieldDecisionChanceValue = Math.Min(1f, (float)(0.200000002980232 + 0.5 * meleeAILevel + 0.200000002980232 * num1));
            agentDrivenProperties.AiMoveEnemySideTimeValue              = (float)(0.5 * meleeAILevel - 2.5);
            agentDrivenProperties.AiMinimumDistanceToContinueFactor     = (float)(2.0 + 0.300000011920929 * (3.0 - meleeAILevel));
            agentDrivenProperties.AiStandGroundTimerValue               = (float)(0.5 * (meleeAILevel - 1.0));
            agentDrivenProperties.AiStandGroundTimerMoveAlongValue      = (float)(0.5 * meleeAILevel - 1.0);
            agentDrivenProperties.AiHearingDistanceFactor               = 1f + meleeAILevel;
            agentDrivenProperties.AiChargeHorsebackTargetDistFactor     = (float)(1.5 * (3.0 - meleeAILevel));
            agentDrivenProperties.AiWaitBeforeShootFactor               = agent._propertyModifiers.resetAiWaitBeforeShootFactor ? 0.0f : (float)(1.0 - 0.5 * rangedAILevel);
            float num3 = 1f - rangedAILevel;

            agentDrivenProperties.AiRangerLeadErrorMin              = (float)(-(double)num3 * 0.349999994039536) + config.RangedError;
            agentDrivenProperties.AiRangerLeadErrorMax              = num3 * 0.2f + config.RangedError;
            agentDrivenProperties.AiRangerVerticalErrorMultiplier   = num3 * 0.1f;
            agentDrivenProperties.AiRangerHorizontalErrorMultiplier = num3 * ((float)Math.PI / 90f);
            agentDrivenProperties.AIAttackOnDecideChance            = MathF.Clamp((float)(0.230000004172325 * CalculateAIAttackOnDecideMaxValue() * (3.0 - agent.Defensiveness)), 0.05f, 1f);
            //agentDrivenProperties.SetStat(DrivenProperty.UseRealisticBlocking, agent.Controller != Agent.ControllerType.Player ? 1f : 0.0f);
            if (config.UseRealisticBlocking)
            {
                agentDrivenProperties.SetStat(DrivenProperty.UseRealisticBlocking, 1f);
            }
        }
        public override void UpdateAgentStats(Agent agent, AgentDrivenProperties agentDrivenProperties)
        {
            if (!agent.IsHuman)
            {
                return;
            }
            BasicCharacterObject character1     = agent.Character;
            MissionEquipment     equipment      = agent.Equipment;
            float          totalWeightOfWeapons = equipment.GetTotalWeightOfWeapons();
            int            weight            = agent.Monster.Weight;
            float          num1              = agentDrivenProperties.ArmorEncumbrance + totalWeightOfWeapons;
            EquipmentIndex wieldedItemIndex1 = agent.GetWieldedItemIndex(Agent.HandIndex.MainHand);
            EquipmentIndex wieldedItemIndex2 = agent.GetWieldedItemIndex(Agent.HandIndex.OffHand);

            if (wieldedItemIndex1 != EquipmentIndex.None)
            {
                ItemObject itemObject       = equipment[wieldedItemIndex1].Item;
                float      realWeaponLength = itemObject.WeaponComponent.PrimaryWeapon.GetRealWeaponLength();
                totalWeightOfWeapons += 1.5f * itemObject.Weight * MathF.Sqrt(realWeaponLength);
            }
            if (wieldedItemIndex2 != EquipmentIndex.None)
            {
                ItemObject itemObject = equipment[wieldedItemIndex2].Item;
                totalWeightOfWeapons += 1.5f * itemObject.Weight;
            }
            agentDrivenProperties.WeaponsEncumbrance = totalWeightOfWeapons;
            EquipmentIndex      wieldedItemIndex3 = agent.GetWieldedItemIndex(Agent.HandIndex.MainHand);
            MissionWeapon       missionWeapon;
            WeaponComponentData weaponComponentData1;

            if (wieldedItemIndex3 == EquipmentIndex.None)
            {
                weaponComponentData1 = (WeaponComponentData)null;
            }
            else
            {
                missionWeapon        = equipment[wieldedItemIndex3];
                weaponComponentData1 = missionWeapon.CurrentUsageItem;
            }
            WeaponComponentData equippedItem = weaponComponentData1;
            ItemObject          itemObject1;

            if (wieldedItemIndex3 == EquipmentIndex.None)
            {
                itemObject1 = (ItemObject)null;
            }
            else
            {
                missionWeapon = equipment[wieldedItemIndex3];
                itemObject1   = missionWeapon.Item;
            }
            ItemObject          primaryItem       = itemObject1;
            EquipmentIndex      wieldedItemIndex4 = agent.GetWieldedItemIndex(Agent.HandIndex.OffHand);
            WeaponComponentData weaponComponentData2;

            if (wieldedItemIndex4 == EquipmentIndex.None)
            {
                weaponComponentData2 = (WeaponComponentData)null;
            }
            else
            {
                missionWeapon        = equipment[wieldedItemIndex4];
                weaponComponentData2 = missionWeapon.CurrentUsageItem;
            }
            WeaponComponentData secondaryItem = weaponComponentData2;
            float inaccuracy;

            agentDrivenProperties.LongestRangedWeaponSlotIndex       = (float)equipment.GetLongestRangedWeaponWithAimingError(out inaccuracy, agent);
            agentDrivenProperties.LongestRangedWeaponInaccuracy      = inaccuracy;
            agentDrivenProperties.SwingSpeedMultiplier               = (float)(0.930000007152557 + 0.000699999975040555 * (double)this.GetSkillValueForItem(agent, primaryItem));
            agentDrivenProperties.ThrustOrRangedReadySpeedMultiplier = agentDrivenProperties.SwingSpeedMultiplier;
            agentDrivenProperties.HandlingMultiplier = 1f;
            agentDrivenProperties.ShieldBashStunDurationMultiplier = 1f;
            agentDrivenProperties.KickStunDurationMultiplier       = 1f;
            agentDrivenProperties.ReloadSpeed = (float)(0.930000007152557 + 0.000699999975040555 * (double)this.GetSkillValueForItem(agent, primaryItem));
            agentDrivenProperties.ReloadMovementPenaltyFactor = 1f;
            agentDrivenProperties.WeaponInaccuracy            = 0.0f;
            IAgentOriginBase     origin     = agent.Origin;
            BasicCharacterObject character2 = agent.Character;
            Formation            formation  = agent.Formation;
            int effectiveSkill1             = this.GetEffectiveSkill(character2, origin, agent.Formation, DefaultSkills.Athletics);
            int effectiveSkill2             = this.GetEffectiveSkill(character2, origin, formation, DefaultSkills.Riding);

            if (equippedItem != null)
            {
                int thrustSpeed            = equippedItem.ThrustSpeed;
                WeaponComponentData weapon = equippedItem;
                int effectiveSkill3        = this.GetEffectiveSkill(character2, origin, formation, equippedItem.RelevantSkill);
                agentDrivenProperties.WeaponInaccuracy = this.GetWeaponInaccuracy(agent, weapon, effectiveSkill3);
                if (equippedItem.IsRangedWeapon)
                {
                    agentDrivenProperties.WeaponMaxMovementAccuracyPenalty = (float)(500 - effectiveSkill3) * 0.00025f;
                    agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty = (float)(500 - effectiveSkill3) * 0.0002f;
                    if (agent.HasMount)
                    {
                        agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty *= Math.Max(1f, (float)(700 - effectiveSkill3 - effectiveSkill2) * (3f / 1000f));
                        agentDrivenProperties.WeaponMaxMovementAccuracyPenalty *= Math.Max(1f, (float)(700 - effectiveSkill3 - effectiveSkill2) * 0.0033f);
                    }
                    else if (weapon.RelevantSkill == DefaultSkills.Bow)
                    {
                        agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty *= 4.5f / MBMath.Lerp(0.75f, 2f, (float)(((double)thrustSpeed - 45.0) / 90.0));
                        agentDrivenProperties.WeaponMaxMovementAccuracyPenalty *= 6f;
                    }
                    else if (weapon.RelevantSkill == DefaultSkills.Crossbow)
                    {
                        agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty *= 1.2f;
                        agentDrivenProperties.WeaponMaxMovementAccuracyPenalty *= 2.5f;
                    }
                    else if (weapon.RelevantSkill == DefaultSkills.Throwing)
                    {
                        agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty *= 3.5f * MBMath.Lerp(1.5f, 0.8f, (float)(((double)thrustSpeed - 89.0) / 13.0));
                    }
                    if (weapon.WeaponClass == WeaponClass.Bow)
                    {
                        agentDrivenProperties.WeaponBestAccuracyWaitTime = (float)(0.300000011920929 + (95.75 - (double)thrustSpeed) * 0.00499999988824129);
                        agentDrivenProperties.WeaponUnsteadyBeginTime    = (float)(0.600000023841858 + (double)effectiveSkill3 * 0.00999999977648258 * (double)MBMath.Lerp(2f, 4f, (float)(((double)thrustSpeed - 45.0) / 90.0)));
                        if (agent.IsAIControlled)
                        {
                            agentDrivenProperties.WeaponUnsteadyBeginTime *= 4f;
                        }
                        agentDrivenProperties.WeaponUnsteadyEndTime = 2f + agentDrivenProperties.WeaponUnsteadyBeginTime;
                        agentDrivenProperties.WeaponRotationalAccuracyPenaltyInRadians = 0.1f;
                    }
                    else if (weapon.WeaponClass == WeaponClass.Javelin || weapon.WeaponClass == WeaponClass.ThrowingAxe || weapon.WeaponClass == WeaponClass.ThrowingKnife)
                    {
                        agentDrivenProperties.WeaponBestAccuracyWaitTime = (float)(0.400000005960464 + (89.0 - (double)thrustSpeed) * 0.0299999993294477);
                        agentDrivenProperties.WeaponUnsteadyBeginTime    = (float)(2.5 + (double)character1.GetSkillValue(equippedItem.RelevantSkill) * 0.00999999977648258);
                        agentDrivenProperties.WeaponUnsteadyEndTime      = 10f + agentDrivenProperties.WeaponUnsteadyBeginTime;
                        agentDrivenProperties.WeaponRotationalAccuracyPenaltyInRadians = 0.025f;
                    }
                    else
                    {
                        agentDrivenProperties.WeaponBestAccuracyWaitTime = 0.1f;
                        agentDrivenProperties.WeaponUnsteadyBeginTime    = 0.0f;
                        agentDrivenProperties.WeaponUnsteadyEndTime      = 0.0f;
                        agentDrivenProperties.WeaponRotationalAccuracyPenaltyInRadians = 0.1f;
                    }
                }
                else if (equippedItem.RelevantSkill == DefaultSkills.Polearm && equippedItem.WeaponFlags.HasAllFlags <WeaponFlags>(WeaponFlags.WideGrip))
                {
                    agentDrivenProperties.WeaponUnsteadyBeginTime = (float)(1.0 + (double)effectiveSkill3 * 0.00499999988824129);
                    agentDrivenProperties.WeaponUnsteadyEndTime   = (float)(3.0 + (double)effectiveSkill3 * 0.00999999977648258);
                }
                if (agent.HasMount)
                {
                    float num2 = 1f - Math.Max(0.0f, (float)(0.200000002980232 - (double)effectiveSkill2 * (1.0 / 500.0)));
                    agentDrivenProperties.SwingSpeedMultiplier *= num2;
                    agentDrivenProperties.ThrustOrRangedReadySpeedMultiplier *= num2;
                    agentDrivenProperties.ReloadSpeed *= num2;
                }
            }
            agentDrivenProperties.TopSpeedReachDuration = 2f / Math.Max((float)((200.0 + (double)effectiveSkill1) / 300.0 * ((double)weight / ((double)weight + (double)num1))), 0.3f);
            float num3 = 1f;

            if (!agent.Mission.Scene.IsAtmosphereIndoor && (double)agent.Mission.Scene.GetRainDensity() > 0.0)
            {
                num3 *= 0.9f;
            }
            agentDrivenProperties.MaxSpeedMultiplier = num3 * Math.Min((float)((200.0 + (double)effectiveSkill1) / 300.0 * ((double)weight * 2.0 / ((double)weight * 2.0 + (double)num1))), 1f);
            float managedParameter1 = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.BipedalCombatSpeedMinMultiplier);
            float managedParameter2 = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.BipedalCombatSpeedMaxMultiplier);
            float amount            = Math.Min(num1 / (float)weight, 1f);

            agentDrivenProperties.CombatMaxSpeedMultiplier = Math.Min(MBMath.Lerp(managedParameter2, managedParameter1, amount), 1f);
            agentDrivenProperties.AttributeShieldMissileCollisionBodySizeAdder = 0.3f;
            Agent mountAgent = agent.MountAgent;
            float num4       = mountAgent != null?mountAgent.GetAgentDrivenPropertyValue(DrivenProperty.AttributeRiding) : 1f;

            agentDrivenProperties.AttributeRiding                    = (float)effectiveSkill2 * num4;
            agentDrivenProperties.AttributeHorseArchery              = Game.Current.BasicModels.StrikeMagnitudeModel.CalculateHorseArcheryFactor(character1);
            agentDrivenProperties.BipedalRangedReadySpeedMultiplier  = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.BipedalRangedReadySpeedMultiplier);
            agentDrivenProperties.BipedalRangedReloadSpeedMultiplier = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.BipedalRangedReloadSpeedMultiplier);
            this.SetAiRelatedProperties(agent, agentDrivenProperties, equippedItem, secondaryItem);
        }
        protected internal override void OnTick(float dt)
        {
            base.OnTick(dt);
            if (GameNetwork.IsServer && !this._stopUpdating)
            {
                if (Mission.Current == null || Mission.Current.AttackerTeam == null || Mission.Current.DefenderTeam == null)
                {
                    return;
                }
                int defendingSideCount = this.DefendingSideCount;
                int attackingSideCount = this.AttackingSideCount;
                this._status = attackingSideCount <= 0 || defendingSideCount != 0 ? (attackingSideCount <= 0 || defendingSideCount <= 0 ? (attackingSideCount != 0 || defendingSideCount <= 0 ? CaptureTheFlagCapturePointSiege.FlagStatusEnum.NoAttackersAndDefenders : CaptureTheFlagCapturePointSiege.FlagStatusEnum.DefendersOnly) : CaptureTheFlagCapturePointSiege.FlagStatusEnum.AttackersAndDefenders) : CaptureTheFlagCapturePointSiege.FlagStatusEnum.AttackersOnly;
                if (this._status != CaptureTheFlagCapturePointSiege.FlagStatusEnum.None)
                {
                    float num   = 0.0f;
                    bool  flag1 = false;
                    bool  flag2 = this._prevStatus != this._status;
                    if (flag2)
                    {
                        this._flagSyncTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission));
                    }
                    switch (this._status)
                    {
                    case CaptureTheFlagCapturePointSiege.FlagStatusEnum.AttackersOnly:
                        num = dt / this.FlagRaiseTime;
                        this.Flag.Direction = CaptureTheFlagFlagDirection.Up;
                        this.Flag.Speed     = this.FlagRaiseTime;
                        break;

                    case CaptureTheFlagCapturePointSiege.FlagStatusEnum.DefendersOnly:
                        num = -dt / this.FlagLowerTime;
                        this.Flag.Direction = CaptureTheFlagFlagDirection.Down;
                        this.Flag.Speed     = this.FlagLowerTime;
                        break;

                    case CaptureTheFlagCapturePointSiege.FlagStatusEnum.AttackersAndDefenders:
                        num = 0.0f;
                        this.Flag.Direction = CaptureTheFlagFlagDirection.Static;
                        break;

                    case CaptureTheFlagCapturePointSiege.FlagStatusEnum.NoAttackersAndDefenders:
                        num = -dt / this.FlagLowerTime;
                        this.Flag.Direction = CaptureTheFlagFlagDirection.Down;
                        this.Flag.Speed     = this.FlagLowerTime;
                        break;
                    }
                    this.Flag.Progress += num;
                    if (flag1 || (double)this.Flag.Progress >= 1.0)
                    {
                        this.OnRaised();
                        flag2 = true;
                        this._stopUpdating  = true;
                        this.Flag.Direction = CaptureTheFlagFlagDirection.Static;
                    }
                    this.Flag.Progress = MBMath.ClampFloat(this.Flag.Progress, 0.0f, 1f);
                    if (this.Flag.Direction == CaptureTheFlagFlagDirection.Up || this.Flag.Direction == CaptureTheFlagFlagDirection.Down)
                    {
                        flag2 = flag2 || this._flagSyncTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission));
                    }
                    if (flag2)
                    {
                        GameNetwork.BeginBroadcastModuleEvent();
                        GameNetwork.WriteMessage((GameNetworkMessage) new FlagRaisingStatus(this.Flag.Progress, this.Flag.Direction, this.Flag.Speed));
                        GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.AddToMissionRecord);
                    }
                    MatrixFrame globalFrame = this.Flag.FlagHolder.GameEntity.GetGlobalFrame();
                    globalFrame.origin.z = MBMath.Lerp(this.Flag.FlagBottomBoundary.GetGlobalFrame().origin.z, this.Flag.FlagTopBoundary.GetGlobalFrame().origin.z, 1f - this.Flag.Progress);
                    this.Flag.FlagHolder.GameEntity.SetGlobalFrame(globalFrame);
                }
                this._prevStatus = this._status;
            }
            if (!GameNetwork.IsClientOrReplay || !this.Flag.UpdateFlag)
            {
                return;
            }
            MatrixFrame globalFrame1 = this.Flag.FlagHolder.GameEntity.GetGlobalFrame();

            globalFrame1.origin.z = MBMath.Lerp(this.Flag.FlagBottomBoundary.GetGlobalFrame().origin.z, this.Flag.FlagTopBoundary.GetGlobalFrame().origin.z, 1f - this.Flag.Progress);
            this.Flag.FlagHolder.GameEntity.SetGlobalFrame(globalFrame1);
            if (!MBMath.ApproximatelyEquals(this.Flag.Speed, 0.0f) && this.Flag.Direction != CaptureTheFlagFlagDirection.None && this.Flag.Direction != CaptureTheFlagFlagDirection.Static)
            {
                this.Flag.Progress += (float)((this.Flag.Direction == CaptureTheFlagFlagDirection.Up ? 1.0 : (this.Flag.Direction == CaptureTheFlagFlagDirection.Down ? -1.0 : 0.0)) * ((double)dt / (double)this.Flag.Speed));
            }
            else
            {
                this.Flag.UpdateFlag = false;
            }
            this.Flag.Progress = MBMath.ClampFloat(this.Flag.Progress, 0.0f, 1f);
        }
        protected override float GetAiWeight()
        {
            FormationQuerySystem querySystem = this.formation.QuerySystem;

            return(this.formation.AI.ActiveBehavior == null ? 0.0f : MBMath.Lerp(0.1f, 1.2f, MBMath.ClampFloat((float)((double)this.formation.AI.ActiveBehavior.BehaviorCoherence * ((double)querySystem.FormationIntegrityData.DeviationOfPositionsExcludeFarAgents + 1.0) / ((double)querySystem.IdealAverageDisplacement + 1.0)), 0.0f, 3f) / 3f));
        }
Example #17
0
        private float CalculateAIWeight(bool isSiege, bool isInsideCastle)
        {
            FormationQuerySystem formationQuerySystem = this.formation.QuerySystem;
            float num1 = formationQuerySystem.AveragePosition.Distance(formationQuerySystem.ClosestEnemyFormation.MedianPosition.AsVec2) / formationQuerySystem.MovementSpeedMaximum;
            float num2 = formationQuerySystem.IsCavalryFormation || formationQuerySystem.IsRangedCavalryFormation ? ((double)num1 > 4.0 ? MBMath.Lerp(0.1f, 1.4f, (float)(1.0 - ((double)MBMath.ClampFloat(num1, 4f, 10f) - 4.0) / 6.0)) : MBMath.Lerp(0.1f, 1.4f, MBMath.ClampFloat(num1, 0.0f, 4f) / 4f)) : MBMath.Lerp(0.1f, 1f, (float)(1.0 - ((double)MBMath.ClampFloat(num1, 4f, 10f) - 4.0) / 6.0));
            float num3 = 0.0f;

            foreach (Team team in (ReadOnlyCollection <Team>)Mission.Current.Teams)
            {
                if (team.IsEnemyOf(this.formation.Team))
                {
                    foreach (Formation formation in team.FormationsIncludingSpecialAndEmpty)
                    {
                        Formation enemyFormation = formation;
                        if (enemyFormation.CountOfUnits > 0 && formationQuerySystem.ClosestEnemyFormation.Formation != enemyFormation && (!isSiege || TeamAISiegeComponent.IsFormationInsideCastle(enemyFormation, true) == isInsideCastle))
                        {
                            WorldPosition medianPosition = enemyFormation.QuerySystem.MedianPosition;
                            Vec2          asVec2_1       = medianPosition.AsVec2;
                            ref Vec2      local          = ref asVec2_1;
                            medianPosition = formationQuerySystem.ClosestEnemyFormation.MedianPosition;
                            Vec2  asVec2_2   = medianPosition.AsVec2;
                            float reliefTime = local.Distance(asVec2_2) / enemyFormation.QuerySystem.MovementSpeedMaximum;
                            if ((double)reliefTime <= (double)num1 + 4.0 && ((double)num1 > 8.0 || enemyFormation.QuerySystem.ClosestEnemyFormation == this.formation.QuerySystem) && ((double)num1 > 8.0 || !this.formation.QuerySystem.Team.AllyTeams.SelectMany <TeamQuerySystem, Formation>((Func <TeamQuerySystem, IEnumerable <Formation> >)(t => t.Team.FormationsIncludingSpecial)).Any <Formation>((Func <Formation, bool>)(f => f.QuerySystem.ClosestEnemyFormation == enemyFormation.QuerySystem && (double)f.QuerySystem.MedianPosition.AsVec2.Distance(formationQuerySystem.AveragePosition) / (double)f.QuerySystem.MovementSpeedMaximum < (double)reliefTime + 4.0))))
                            {
                                num3 += enemyFormation.QuerySystem.FormationMeleeFightingPower * enemyFormation.QuerySystem.GetClassWeightedFactor(1f, 1f, 1f, 1f);
                            }
                        }
                    }
                }
            }
        protected void SetAiRelatedProperties(
            Agent agent,
            AgentDrivenProperties agentDrivenProperties,
            WeaponComponentData equippedItem,
            WeaponComponentData secondaryItem)
        {
            int         meleeSkill     = this.GetMeleeSkill(agent, equippedItem, secondaryItem);
            SkillObject skill          = equippedItem == null ? DefaultSkills.Athletics : equippedItem.RelevantSkill;
            int         effectiveSkill = this.GetEffectiveSkill(agent.Character, agent.Origin, agent.Formation, skill);
            float       aiLevel1       = this.CalculateAILevel(agent, meleeSkill);
            float       aiLevel2       = this.CalculateAILevel(agent, effectiveSkill);
            float       num1           = aiLevel1 + agent.Defensiveness;

            agentDrivenProperties.AiRangedHorsebackMissileRange = (float)(0.300000011920929 + 0.400000005960464 * (double)aiLevel2);
            agentDrivenProperties.AiFacingMissileWatch          = (float)((double)aiLevel1 * 0.0599999986588955 - 0.959999978542328);
            agentDrivenProperties.AiFlyingMissileCheckRadius    = (float)(8.0 - 6.0 * (double)aiLevel1);
            agentDrivenProperties.AiShootFreq             = (float)(0.300000011920929 + 0.699999988079071 * (double)aiLevel2);
            agentDrivenProperties.AiWaitBeforeShootFactor = agent._propertyModifiers.resetAiWaitBeforeShootFactor ? 0.0f : (float)(1.0 - 0.5 * (double)aiLevel2);
            int num2 = secondaryItem != null ? 1 : 0;

            agentDrivenProperties.AIBlockOnDecideAbility     = MBMath.Lerp(0.25f, 0.99f, MBMath.ClampFloat((float)Math.Pow((double)aiLevel1, 1.0), 0.0f, 1f));
            agentDrivenProperties.AIParryOnDecideAbility     = MBMath.Lerp(0.01f, 0.95f, MBMath.ClampFloat((float)Math.Pow((double)aiLevel1, 1.5), 0.0f, 1f));
            agentDrivenProperties.AiTryChamberAttackOnDecide = (float)(((double)aiLevel1 - 0.150000005960464) * 0.100000001490116);
            agentDrivenProperties.AIAttackOnParryChance      = (float)(0.300000011920929 - 0.100000001490116 * (double)agent.Defensiveness);
            agentDrivenProperties.AiAttackOnParryTiming      = (float)(0.300000011920929 * (double)aiLevel1 - 0.200000002980232);
            agentDrivenProperties.AIDecideOnAttackChance     = 0.15f * agent.Defensiveness;
            agentDrivenProperties.AIParryOnAttackAbility     = MBMath.ClampFloat((float)Math.Pow((double)aiLevel1, 3.0), 0.0f, 1f);
            agentDrivenProperties.AiKick = (float)(((double)aiLevel1 > 0.400000005960464 ? 0.400000005960464 : (double)aiLevel1) - 0.100000001490116);
            agentDrivenProperties.AiAttackCalculationMaxTimeFactor            = aiLevel1;
            agentDrivenProperties.AiDecideOnAttackWhenReceiveHitTiming        = (float)(-0.25 * (1.0 - (double)aiLevel1));
            agentDrivenProperties.AiDecideOnAttackContinueAction              = (float)(-0.5 * (1.0 - (double)aiLevel1));
            agentDrivenProperties.AiDecideOnAttackingContinue                 = 0.1f * aiLevel1;
            agentDrivenProperties.AIParryOnAttackingContinueAbility           = MBMath.Lerp(0.05f, 0.95f, MBMath.ClampFloat((float)Math.Pow((double)aiLevel1, 3.0), 0.0f, 1f));
            agentDrivenProperties.AIDecideOnRealizeEnemyBlockingAttackAbility = 0.5f * MBMath.ClampFloat((float)Math.Pow((double)aiLevel1, 2.5) - 0.1f, 0.0f, 1f);
            agentDrivenProperties.AIRealizeBlockingFromIncorrectSideAbility   = 0.5f * MBMath.ClampFloat((float)Math.Pow((double)aiLevel1, 2.5) - 0.1f, 0.0f, 1f);
            agentDrivenProperties.AiAttackingShieldDefenseChance              = (float)(0.200000002980232 + 0.300000011920929 * (double)aiLevel1);
            agentDrivenProperties.AiAttackingShieldDefenseTimer               = (float)(0.300000011920929 * (double)aiLevel1 - 0.300000011920929);
            agentDrivenProperties.AiRandomizedDefendDirectionChance           = (float)(1.0 - Math.Log((double)aiLevel1 * 7.0 + 1.0, 2.0) * 0.333330005407333);
            agentDrivenProperties.AISetNoAttackTimerAfterBeingHitAbility      = MBMath.ClampFloat((float)Math.Pow((double)aiLevel1, 2.0), 0.05f, 0.95f);
            agentDrivenProperties.AISetNoAttackTimerAfterBeingParriedAbility  = MBMath.ClampFloat((float)Math.Pow((double)aiLevel1, 2.0), 0.05f, 0.95f);
            agentDrivenProperties.AISetNoDefendTimerAfterHittingAbility       = MBMath.ClampFloat((float)Math.Pow((double)aiLevel1, 2.0), 0.05f, 0.95f);
            agentDrivenProperties.AISetNoDefendTimerAfterParryingAbility      = MBMath.ClampFloat((float)Math.Pow((double)aiLevel1, 2.0), 0.05f, 0.95f);
            agentDrivenProperties.AIEstimateStunDurationPrecision             = 1f - MBMath.ClampFloat((float)Math.Pow((double)aiLevel1, 2.0), 0.05f, 0.95f);
            agentDrivenProperties.AIHoldingReadyMaxDuration                 = MBMath.Lerp(0.25f, 0.0f, Math.Min(1f, aiLevel1 * 1.2f));
            agentDrivenProperties.AIHoldingReadyVariationPercentage         = aiLevel1;
            agentDrivenProperties.AiRaiseShieldDelayTimeBase                = (float)(0.5 * (double)aiLevel1 - 0.75);
            agentDrivenProperties.AiUseShieldAgainstEnemyMissileProbability = (float)(0.100000001490116 + (double)aiLevel1 * 0.600000023841858 + (double)num1 * 0.200000002980232);
            agentDrivenProperties.AiCheckMovementIntervalFactor             = (float)(0.00499999988824129 * (1.10000002384186 - (double)aiLevel1));
            agentDrivenProperties.AiMovemetDelayFactor                  = (float)(4.0 / (3.0 + (double)aiLevel2));
            agentDrivenProperties.AiParryDecisionChangeValue            = (float)(0.0500000007450581 + 0.699999988079071 * (double)aiLevel1);
            agentDrivenProperties.AiDefendWithShieldDecisionChanceValue = Math.Min(1f, (float)(0.200000002980232 + 0.5 * (double)aiLevel1 + 0.200000002980232 * (double)num1));
            agentDrivenProperties.AiMoveEnemySideTimeValue              = (float)(0.5 * (double)aiLevel1 - 2.5);
            agentDrivenProperties.AiMinimumDistanceToContinueFactor     = (float)(2.0 + 0.300000011920929 * (3.0 - (double)aiLevel1));
            agentDrivenProperties.AiStandGroundTimerValue               = (float)(0.5 * ((double)aiLevel1 - 1.0));
            agentDrivenProperties.AiStandGroundTimerMoveAlongValue      = (float)(0.5 * (double)aiLevel1 - 1.0);
            agentDrivenProperties.AiHearingDistanceFactor               = 1f + aiLevel1;
            agentDrivenProperties.AiChargeHorsebackTargetDistFactor     = (float)(1.5 * (3.0 - (double)aiLevel1));
            agentDrivenProperties.AiWaitBeforeShootFactor               = agent._propertyModifiers.resetAiWaitBeforeShootFactor ? 0.0f : (float)(1.0 - 0.5 * (double)aiLevel2);
            float num3 = 1f - aiLevel2;

            agentDrivenProperties.AiRangerLeadErrorMin              = (float)(-(double)num3 * 0.349999994039536);
            agentDrivenProperties.AiRangerLeadErrorMax              = num3 * 0.2f;
            agentDrivenProperties.AiRangerVerticalErrorMultiplier   = num3 * 0.1f;
            agentDrivenProperties.AiRangerHorizontalErrorMultiplier = num3 * ((float)Math.PI / 90f);
            agentDrivenProperties.AIAttackOnDecideChance            = MathF.Clamp((float)(0.230000004172325 * (double)this.CalculateAIAttackOnDecideMaxValue() * (3.0 - (double)agent.Defensiveness)), 0.05f, 1f);
            agentDrivenProperties.SetStat(DrivenProperty.UseRealisticBlocking, agent.Controller != Agent.ControllerType.Player ? 1f : 0.0f);
        }
Example #19
0
        private void UpdateHumanAgentStats(Agent agent, AgentDrivenProperties agentDrivenProperties)
        {
            MPPerkObject.MPPerkHandler perkHandler = MPPerkObject.GetPerkHandler(agent);
            BasicCharacterObject       character   = agent.Character;
            MissionEquipment           equipment   = agent.Equipment;
            float          num1 = equipment.GetTotalWeightOfWeapons() * (float)(1.0 + (perkHandler != null ? (double)perkHandler.GetEncumbrance(true) : 0.0));
            EquipmentIndex wieldedItemIndex1 = agent.GetWieldedItemIndex(Agent.HandIndex.MainHand);
            EquipmentIndex wieldedItemIndex2 = agent.GetWieldedItemIndex(Agent.HandIndex.OffHand);

            if (wieldedItemIndex1 != EquipmentIndex.None)
            {
                ItemObject      itemObject       = equipment[wieldedItemIndex1].Item;
                WeaponComponent weaponComponent  = itemObject.WeaponComponent;
                float           realWeaponLength = weaponComponent.PrimaryWeapon.GetRealWeaponLength();
                float           num2             = (weaponComponent.GetItemType() == ItemObject.ItemTypeEnum.Bow ? 4f : 1.5f) * itemObject.Weight * MathF.Sqrt(realWeaponLength) * (float)(1.0 + (perkHandler != null ? (double)perkHandler.GetEncumbrance(false) : 0.0));
                num1 += num2;
            }
            if (wieldedItemIndex2 != EquipmentIndex.None)
            {
                float num2 = 1.5f * equipment[wieldedItemIndex2].Item.Weight * (float)(1.0 + (perkHandler != null ? (double)perkHandler.GetEncumbrance(false) : 0.0));
                num1 += num2;
            }
            agentDrivenProperties.WeaponsEncumbrance = num1;
            EquipmentIndex      wieldedItemIndex3   = agent.GetWieldedItemIndex(Agent.HandIndex.MainHand);
            WeaponComponentData weaponComponentData = wieldedItemIndex3 != EquipmentIndex.None ? equipment[wieldedItemIndex3].CurrentUsageItem : (WeaponComponentData)null;
            ItemObject          primaryItem         = wieldedItemIndex3 != EquipmentIndex.None ? equipment[wieldedItemIndex3].Item : (ItemObject)null;
            EquipmentIndex      wieldedItemIndex4   = agent.GetWieldedItemIndex(Agent.HandIndex.OffHand);
            WeaponComponentData secondaryItem       = wieldedItemIndex4 != EquipmentIndex.None ? equipment[wieldedItemIndex4].CurrentUsageItem : (WeaponComponentData)null;
            float inaccuracy;

            agentDrivenProperties.LongestRangedWeaponSlotIndex       = (float)equipment.GetLongestRangedWeaponWithAimingError(out inaccuracy, agent);
            agentDrivenProperties.LongestRangedWeaponInaccuracy      = inaccuracy;
            agentDrivenProperties.SwingSpeedMultiplier               = (float)(0.930000007152557 + 0.000699999975040555 * (double)this.GetSkillValueForItem(character, primaryItem));
            agentDrivenProperties.ThrustOrRangedReadySpeedMultiplier = agentDrivenProperties.SwingSpeedMultiplier;
            agentDrivenProperties.HandlingMultiplier = 1f;
            agentDrivenProperties.ShieldBashStunDurationMultiplier = 1f;
            agentDrivenProperties.KickStunDurationMultiplier       = 1f;
            agentDrivenProperties.ReloadSpeed = (float)(0.930000007152557 + 0.000699999975040555 * (double)this.GetSkillValueForItem(character, primaryItem));
            agentDrivenProperties.ReloadMovementPenaltyFactor = 1f;
            agentDrivenProperties.WeaponInaccuracy            = 0.0f;
            MultiplayerClassDivisions.MPHeroClass classForCharacter = MultiplayerClassDivisions.GetMPHeroClassForCharacter(agent.Character);
            agentDrivenProperties.MaxSpeedMultiplier = (float)(1.04999995231628 * ((double)classForCharacter.MovementSpeedMultiplier * (100.0 / (100.0 + (double)num1))));
            int  skillValue = character.GetSkillValue(DefaultSkills.Riding);
            bool flag1      = false;
            bool flag2      = false;

            if (weaponComponentData != null)
            {
                int weaponSkill = character.GetSkillValue(weaponComponentData.RelevantSkill);
                if (weaponSkill > 0 && weaponComponentData.IsRangedWeapon && perkHandler != null)
                {
                    weaponSkill = MathF.Ceiling((float)weaponSkill * (perkHandler.GetRangedAccuracy() + 1f));
                }
                int thrustSpeed = weaponComponentData.ThrustSpeed;
                agentDrivenProperties.WeaponInaccuracy = this.GetWeaponInaccuracy(agent, weaponComponentData, weaponSkill);
                if (weaponComponentData.IsRangedWeapon)
                {
                    agentDrivenProperties.WeaponMaxMovementAccuracyPenalty = (float)(500 - weaponSkill) * 0.00025f;
                    agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty = (float)(500 - weaponSkill) * 0.0002f;
                    if (agent.HasMount)
                    {
                        agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty *= Math.Max(1f, (float)(700 - weaponSkill - skillValue) * (3f / 1000f));
                        agentDrivenProperties.WeaponMaxMovementAccuracyPenalty *= Math.Max(1f, (float)(700 - weaponSkill - skillValue) * 0.0033f);
                    }
                    else if (weaponComponentData.RelevantSkill == DefaultSkills.Bow)
                    {
                        agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty *= 4.5f / MBMath.Lerp(0.75f, 2f, (float)(((double)thrustSpeed - 60.0) / 75.0));
                        agentDrivenProperties.WeaponMaxMovementAccuracyPenalty *= 6f;
                    }
                    else if (weaponComponentData.RelevantSkill == DefaultSkills.Crossbow)
                    {
                        agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty *= 1.2f;
                        agentDrivenProperties.WeaponMaxMovementAccuracyPenalty *= 2.5f;
                    }
                    else if (weaponComponentData.RelevantSkill == DefaultSkills.Throwing)
                    {
                        agentDrivenProperties.WeaponMaxUnsteadyAccuracyPenalty *= 3.5f * MBMath.Lerp(1.5f, 0.8f, (float)(((double)thrustSpeed - 89.0) / 13.0));
                    }
                    if (weaponComponentData.WeaponClass == WeaponClass.Bow)
                    {
                        flag1 = true;
                        agentDrivenProperties.WeaponBestAccuracyWaitTime = (float)(0.300000011920929 + (95.75 - (double)thrustSpeed) * 0.00499999988824129);
                        agentDrivenProperties.WeaponUnsteadyBeginTime    = (float)(0.100000001490116 + (double)weaponSkill * 0.00999999977648258 * (double)MBMath.Lerp(1f, 2f, (float)(((double)thrustSpeed - 60.0) / 75.0)));
                        if (agent.IsAIControlled)
                        {
                            agentDrivenProperties.WeaponUnsteadyBeginTime *= 4f;
                        }
                        agentDrivenProperties.WeaponUnsteadyEndTime = 2f + agentDrivenProperties.WeaponUnsteadyBeginTime;
                        agentDrivenProperties.WeaponRotationalAccuracyPenaltyInRadians = 0.1f;
                    }
                    else if (weaponComponentData.WeaponClass == WeaponClass.Javelin || weaponComponentData.WeaponClass == WeaponClass.ThrowingAxe || weaponComponentData.WeaponClass == WeaponClass.ThrowingKnife)
                    {
                        agentDrivenProperties.WeaponBestAccuracyWaitTime = (float)(0.400000005960464 + (89.0 - (double)thrustSpeed) * 0.0299999993294477);
                        agentDrivenProperties.WeaponUnsteadyBeginTime    = (float)(2.5 + (double)weaponSkill * 0.00999999977648258);
                        agentDrivenProperties.WeaponUnsteadyEndTime      = 10f + agentDrivenProperties.WeaponUnsteadyBeginTime;
                        agentDrivenProperties.WeaponRotationalAccuracyPenaltyInRadians = 0.025f;
                    }
                    else
                    {
                        agentDrivenProperties.WeaponBestAccuracyWaitTime = 0.1f;
                        agentDrivenProperties.WeaponUnsteadyBeginTime    = 0.0f;
                        agentDrivenProperties.WeaponUnsteadyEndTime      = 0.0f;
                        agentDrivenProperties.WeaponRotationalAccuracyPenaltyInRadians = 0.1f;
                    }
                }
                else if (weaponComponentData.WeaponFlags.HasAllFlags <WeaponFlags>(WeaponFlags.WideGrip))
                {
                    flag2 = true;
                    agentDrivenProperties.WeaponUnsteadyBeginTime = (float)(1.0 + (double)weaponSkill * 0.00499999988824129);
                    agentDrivenProperties.WeaponUnsteadyEndTime   = (float)(3.0 + (double)weaponSkill * 0.00999999977648258);
                }
            }
            agentDrivenProperties.AttributeShieldMissileCollisionBodySizeAdder = 0.3f;
            Agent mountAgent = agent.MountAgent;
            float num3       = mountAgent != null?mountAgent.GetAgentDrivenPropertyValue(DrivenProperty.AttributeRiding) : 1f;

            agentDrivenProperties.AttributeRiding                    = (float)skillValue * num3;
            agentDrivenProperties.AttributeHorseArchery              = Game.Current.BasicModels.StrikeMagnitudeModel.CalculateHorseArcheryFactor(character);
            agentDrivenProperties.BipedalRangedReadySpeedMultiplier  = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.BipedalRangedReadySpeedMultiplier);
            agentDrivenProperties.BipedalRangedReloadSpeedMultiplier = ManagedParameters.Instance.GetManagedParameter(ManagedParametersEnum.BipedalRangedReloadSpeedMultiplier);
            foreach (DrivenPropertyBonusAgentComponent bonusAgentComponent in agent.Components.OfType <DrivenPropertyBonusAgentComponent>())
            {
                if (!MBMath.IsBetween((int)bonusAgentComponent.DrivenProperty, 0, 56))
                {
                    float num2 = agentDrivenProperties.GetStat(bonusAgentComponent.DrivenProperty) + bonusAgentComponent.DrivenPropertyBonus;
                    agentDrivenProperties.SetStat(bonusAgentComponent.DrivenProperty, num2);
                }
            }
            if (perkHandler != null)
            {
                for (int index = 56; index < 85; ++index)
                {
                    DrivenProperty drivenProperty = (DrivenProperty)index;
                    if (((drivenProperty == DrivenProperty.WeaponUnsteadyBeginTime ? 0 : (drivenProperty != DrivenProperty.WeaponUnsteadyEndTime ? 1 : 0)) | (flag1 ? 1 : 0) | (flag2 ? 1 : 0)) != 0 && drivenProperty != DrivenProperty.WeaponRotationalAccuracyPenaltyInRadians | flag1)
                    {
                        float stat = agentDrivenProperties.GetStat(drivenProperty);
                        agentDrivenProperties.SetStat(drivenProperty, stat + perkHandler.GetDrivenPropertyBonus(drivenProperty, stat));
                    }
                }
            }
            this.SetAiRelatedProperties(agent, agentDrivenProperties, weaponComponentData, secondaryItem);
        }
        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()));
        }