Exemplo n.º 1
0
        public override void OnUdpNetworkHandlerTick(float dt)
        {
            if (!GameNetwork.IsServer)
            {
                return;
            }
            float time = MBCommon.GetTime(MBCommon.TimeType.Mission);

            if ((double)this._lastTestSendTime >= (double)time + 10.0)
            {
                return;
            }
            IReadOnlyList <Agent> agents = Mission.Current.Agents;
            int count = agents.Count;

            this._lastTestSendTime = time;
            Agent toTest = agents[(int)(new Random().NextDouble() * (double)count)];

            if (!toTest.IsActive())
            {
                return;
            }
            GameNetwork.BeginBroadcastModuleEvent();
            GameNetwork.WriteMessage((GameNetworkMessage) new DebugAgentScaleOnNetworkTest(toTest, toTest.AgentScale));
            GameNetwork.EndBroadcastModuleEventUnreliable(GameNetwork.EventBroadcastFlags.None);
        }
 protected void ResetSpawnTimers()
 {
     foreach (NetworkCommunicator networkPeer in GameNetwork.NetworkPeers)
     {
         networkPeer.GetComponent <MissionPeer>()?.SpawnTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission), 0.0f);
     }
 }
Exemplo n.º 3
0
 internal void OnApply(Formation formation)
 {
     formation.SetPositioning(unitSpacing: new int?(this.GetUnitSpacing()));
     this.Rearrange(formation);
     if (this.OrderEnum == ArrangementOrder.ArrangementOrderEnum.Scatter)
     {
         this.TickOccasionally(formation);
     }
     ArrangementOrder.ArrangementOrderEnum orderEnum = this.OrderEnum;
     formation.ApplyActionOnEachUnit((Action <Agent>)(agent =>
     {
         if (agent.IsAIControlled)
         {
             Agent.UsageDirection shieldDirectionOfUnit = ArrangementOrder.GetShieldDirectionOfUnit(formation, agent, orderEnum);
             agent.EnforceShieldUsage(shieldDirectionOfUnit);
         }
         agent.UpdateAgentProperties();
     }));
     if (formation.MovementOrder.OrderEnum != MovementOrder.MovementOrderEnum.Charge && formation.MovementOrder.OrderEnum != MovementOrder.MovementOrderEnum.ChargeToTarget)
     {
         if (this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Circle && this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.ShieldWall && (this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Square && this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Column))
         {
             formation.ApplyActionOnEachUnit(new Action <Agent>(MovementOrder.SetDefaultMoveBehaviorValues));
         }
         else if (this.OrderEnum != ArrangementOrder.ArrangementOrderEnum.Column)
         {
             formation.ApplyActionOnEachUnit(new Action <Agent>(MovementOrder.SetDefensiveArrangementMoveBehaviorValues));
         }
         else
         {
             formation.ApplyActionOnEachUnit(new Action <Agent>(MovementOrder.SetFollowBehaviorValues));
         }
     }
     this.tickTimer = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 0.5f);
 }
 public IncrementalTimer(float totalDuration, float tickInterval)
 {
     this._tickInterval  = Math.Max(tickInterval, 0.01f);
     this._totalDuration = Math.Max(totalDuration, 0.01f);
     this.TimerCounter   = 0.0f;
     this._timer         = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), this._tickInterval);
 }
 public override void AfterStart()
 {
     this._isInitialized        = false;
     this._friendsPerTeam       = new Dictionary <Team, IEnumerable <VirtualPlayer> >();
     this._friendsCachingTimer  = new Timer(MBCommon.GetTime(MBCommon.TimeType.Application), 1f);
     MissionPeer.OnTeamChanged += new MissionPeer.OnTeamChangedDelegate(this.UpdateTeams);
 }
Exemplo n.º 6
0
        internal ArrangementOrder(ArrangementOrder.ArrangementOrderEnum orderEnum)
        {
            this.OrderEnum        = orderEnum;
            this._walkRestriction = new float?();
            switch (this.OrderEnum)
            {
            case ArrangementOrder.ArrangementOrderEnum.Circle:
                this._runRestriction = new float?(0.5f);
                break;

            case ArrangementOrder.ArrangementOrderEnum.Line:
                this._runRestriction = new float?(0.8f);
                break;

            case ArrangementOrder.ArrangementOrderEnum.Loose:
            case ArrangementOrder.ArrangementOrderEnum.Scatter:
            case ArrangementOrder.ArrangementOrderEnum.Skein:
                this._runRestriction = new float?(0.9f);
                break;

            case ArrangementOrder.ArrangementOrderEnum.ShieldWall:
            case ArrangementOrder.ArrangementOrderEnum.Square:
                this._runRestriction = new float?(0.3f);
                break;

            default:
                this._runRestriction = new float?(1f);
                break;
            }
            this._unitSpacing = ArrangementOrder.GetUnitSpacingOf(this.OrderEnum);
            this.tickTimer    = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 0.5f);
        }
 protected override void CalculateCurrentOrder()
 {
     if (this._mainFormation == null || this.formation.AI.IsMainFormation || this.formation.AI.Side != FormationAI.BehaviorSide.Left && this.formation.AI.Side != FormationAI.BehaviorSide.Right)
     {
         this._flankingEnemyCavalryFormation = (Formation)null;
         WorldPosition medianPosition = this.formation.QuerySystem.MedianPosition;
         medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition);
         this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition);
     }
     else
     {
         float time = MBCommon.GetTime(MBCommon.TimeType.Mission);
         if ((double)this._threatFormationCacheTime + 5.0 < (double)time)
         {
             this._threatFormationCacheTime = time;
             Vec2 vec2_1;
             Vec2 vec2_2;
             if (this.formation.AI.Side != FormationAI.BehaviorSide.Left)
             {
                 vec2_1 = this._mainFormation.Direction;
                 vec2_2 = vec2_1.RightVec();
             }
             else
             {
                 vec2_1 = this._mainFormation.Direction;
                 vec2_2 = vec2_1.LeftVec();
             }
             vec2_1 = vec2_2;
             Vec2 vec2_3 = vec2_1.Normalized();
             vec2_1 = this._mainFormation.Direction;
             Vec2 vec2_4                    = vec2_1.Normalized();
             Vec2 threatDirection           = vec2_3 - vec2_4;
             IEnumerable <Formation> source = Mission.Current.Teams.GetEnemiesOf(this.formation.Team).SelectMany <Team, Formation>((Func <Team, IEnumerable <Formation> >)(t => t.FormationsIncludingSpecial)).Where <Formation>((Func <Formation, bool>)(f =>
             {
                 WorldPosition medianPosition = f.QuerySystem.MedianPosition;
                 Vec2 asVec2_1  = medianPosition.AsVec2;
                 medianPosition = this._mainFormation.QuerySystem.MedianPosition;
                 Vec2 asVec2_2  = medianPosition.AsVec2;
                 Vec2 vec2      = asVec2_1 - asVec2_2;
                 return((double)threatDirection.Normalized().DotProduct(vec2.Normalized()) > Math.Cos(Math.PI / 8.0));
             }));
             this._flankingEnemyCavalryFormation = !source.Any <Formation>() ? (Formation)null : source.MaxBy <Formation, float>((Func <Formation, float>)(tef => tef.QuerySystem.FormationPower));
         }
         WorldPosition medianPosition1;
         if (this._flankingEnemyCavalryFormation == null)
         {
             medianPosition1 = this.formation.QuerySystem.MedianPosition;
             medianPosition1.SetVec2(this.formation.QuerySystem.AveragePosition);
         }
         else
         {
             Vec2  vec2 = this._flankingEnemyCavalryFormation.QuerySystem.MedianPosition.AsVec2 - this._mainFormation.QuerySystem.MedianPosition.AsVec2;
             float num  = vec2.Normalize() * 0.5f;
             medianPosition1 = this._mainFormation.QuerySystem.MedianPosition;
             medianPosition1.SetVec2(medianPosition1.AsVec2 + num * vec2);
         }
         this.CurrentOrder = MovementOrder.MovementOrderMove(medianPosition1);
     }
 }
 public RangedSiegeWeaponAi(RangedSiegeWeapon rangedSiegeWeapon)
     : base((UsableMachine)rangedSiegeWeapon)
 {
     this.threatSeeker = new ThreatSeeker(rangedSiegeWeapon);
     (this.UsableMachine as RangedSiegeWeapon).OnReloadDone += new RangedSiegeWeapon.OnSiegeWeaponReloadDone(this.FindNextTarget);
     this._delayTimer            = this._delayDuration;
     this._targetEvaluationTimer = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 0.5f);
 }
Exemplo n.º 9
0
 internal void SoftUpdate(Formation formation)
 {
     if (this.OrderEnum == ArrangementOrder.ArrangementOrderEnum.Scatter)
     {
         this.TickOccasionally(formation);
     }
     this.tickTimer = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 0.5f);
 }
 public override void OnTick(float dt)
 {
     if (this.IsSpawningEnabled && this._spawnCheckTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission)))
     {
         this.SpawnAgents();
     }
     base.OnTick(dt);
 }
 protected internal override void OnMissionReset()
 {
     base.OnMissionReset();
     this.CaptureTimeOutMode = false;
     this._status            = CaptureTheFlagCapturePointSiege.FlagStatusEnum.None;
     this._stopUpdating      = false;
     this.Flag.Reset();
     this._flagSyncTimer = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 4f);
 }
 public bool Check()
 {
     if (!this._timer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission)))
     {
         return(false);
     }
     this.TimerCounter += this._tickInterval / this._totalDuration;
     return(true);
 }
Exemplo n.º 13
0
 public T GetCachedValueWithMaxAge(float age)
 {
     if ((double)MBCommon.GetTime(MBCommon.TimeType.Mission) <= (double)this._expireTime - (double)this._lifetime + (double)Math.Min(this._lifetime, age))
     {
         return(this._cachedValue);
     }
     this.Expire();
     return(this.Value);
 }
Exemplo n.º 14
0
 protected override void OnTick(float dt)
 {
     base.OnTick(dt);
     if (!GameNetwork.IsClient || !this._inactivityTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Application)))
     {
         return;
     }
     this._gameClient.IsInCriticalState = MBAPI.IMBNetwork.ElapsedTimeSinceLastUdpPacketArrived() > (double)LobbyGameStateCustomGameClient.InactivityThreshold;
 }
Exemplo n.º 15
0
 protected override void OnActivate()
 {
     base.OnActivate();
     this._inactivityTimer = new Timer(MBCommon.GetTime(MBCommon.TimeType.Application), LobbyGameStateCustomGameClient.InactivityThreshold);
     if (this._gameClient == null || !this._gameClient.AtLobby && this._gameClient.Connected)
     {
         return;
     }
     this.GameStateManager.PopState();
 }
        internal void RemindSergeantPlayer()
        {
            float time = MBCommon.GetTime(MBCommon.TimeType.Mission);

            if (this != this.formation.AI.ActiveBehavior || (double)this._lastPlayerInformTime + 60.0 >= (double)time)
            {
                return;
            }
            this.InformSergeantPlayer();
            this._lastPlayerInformTime = time;
        }
Exemplo n.º 17
0
        internal bool Tick(Formation formation)
        {
            int num = this.tickTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission)) ? 1 : 0;

            if (num == 0)
            {
                return(num != 0);
            }
            this.TickOccasionally(formation);
            return(num != 0);
        }
Exemplo n.º 18
0
 public void Retreat(WorldPosition?retreatPosition = null)
 {
     if (this.IsRetreating && !retreatPosition.HasValue)
     {
         return;
     }
     this.positionReevaluateTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission));
     if (!retreatPosition.HasValue)
     {
         retreatPosition = new WorldPosition?(this.Agent.Mission.GetClosestFleePositionForAgent(this.Agent));
     }
     this.Agent.Retreat(retreatPosition.Value);
 }
Exemplo n.º 19
0
        protected internal override void OnInit()
        {
            base.OnInit();
            this._tickOccasionallyTimer = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), (float)(0.5 + (double)MBRandom.RandomFloat * 0.5));
            this._givenItem             = Game.Current.ObjectManager.GetObject <ItemObject>(this.GivenItemID);
            List <VolumeBox> source = this.GameEntity.CollectObjects <VolumeBox>();

            this._throwingPoints      = new List <StonePile.ThrowingPoint>();
            this._volumeBoxTimerPairs = new List <StonePile.VolumeBoxTimerPair>();
            foreach (StandingPointWithWeaponRequirement weaponRequirement in this.StandingPoints.OfType <StandingPointWithWeaponRequirement>())
            {
                if (weaponRequirement.GameEntity.HasTag(this.AmmoPickUpTag))
                {
                    weaponRequirement.InitGivenWeapon(this._givenItem);
                    weaponRequirement.SetHasAlternative(true);
                }
                else if (weaponRequirement.GameEntity.HasTag(this.ThrowingPointTag))
                {
                    weaponRequirement.InitRequiredWeapon(this._givenItem);
                    StonePile.ThrowingPoint throwingPoint = new StonePile.ThrowingPoint();
                    throwingPoint.StandingPoint   = weaponRequirement as StandingPointWithVolumeBox;
                    throwingPoint.AmmoPickUpPoint = (StandingPointWithWeaponRequirement)null;
                    throwingPoint.AttackEntity    = (GameEntity)null;
                    bool flag = false;
                    for (int index = 0; index < this._volumeBoxTimerPairs.Count && !flag; ++index)
                    {
                        if (this._volumeBoxTimerPairs[index].VolumeBox.GameEntity.HasTag(throwingPoint.StandingPoint.VolumeBoxTag))
                        {
                            throwingPoint.EnemyInRangeTimer = this._volumeBoxTimerPairs[index].Timer;
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        VolumeBox volumeBox = source.FirstOrDefault <VolumeBox>((Func <VolumeBox, bool>)(vb => vb.GameEntity.HasTag(throwingPoint.StandingPoint.VolumeBoxTag)));
                        StonePile.VolumeBoxTimerPair volumeBoxTimerPair = new StonePile.VolumeBoxTimerPair();
                        volumeBoxTimerPair.VolumeBox    = volumeBox;
                        volumeBoxTimerPair.Timer        = new Timer(-3.5f, 0.5f, false);
                        throwingPoint.EnemyInRangeTimer = volumeBoxTimerPair.Timer;
                        this._volumeBoxTimerPairs.Add(volumeBoxTimerPair);
                    }
                    this._throwingPoints.Add(throwingPoint);
                }
            }
            this.EnemyRangeToStopUsing = 5f;
            this.AmmoCount             = this.StartingAmmoCount;
            this.UpdateAmmoMesh();
            this.SetScriptComponentToTick(this.GetTickRequirement());
        }
Exemplo n.º 20
0
        public void CheckFadeOut()
        {
            if (!this.timer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission)) || this.Agent.IsFadingOut())
            {
                return;
            }
            Vec3          position   = this.Agent.Position;
            WorldPosition retreatPos = this.Agent.GetRetreatPos();

            if ((!retreatPos.AsVec2.IsValid || (double)retreatPos.AsVec2.DistanceSquared(position.AsVec2) >= 25.0 || (double)retreatPos.GetGroundVec3().DistanceSquared(position) >= 25.0) && (this.Agent.Mission.IsPositionInsideBoundaries(position.AsVec2) && (double)position.DistanceSquared(this.Agent.Mission.GetClosestBoundaryPosition(position.AsVec2).ToVec3()) >= 25.0))
            {
                return;
            }
            this.Agent.StartFadingOut();
        }
Exemplo n.º 21
0
 protected virtual void OnPlayerDies(MissionPeer peer, MissionPeer assistorPeer)
 {
     if (assistorPeer != null && assistorPeer.GetNetworkPeer().IsConnectionActive)
     {
         GameNetwork.BeginBroadcastModuleEvent();
         GameNetwork.WriteMessage((GameNetworkMessage) new KillDeathCountChange(assistorPeer.GetNetworkPeer(), (NetworkCommunicator)null, assistorPeer.KillCount, assistorPeer.AssistCount, assistorPeer.DeathCount, assistorPeer.Score));
         GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
     }
     ++peer.DeathCount;
     peer.SpawnTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission), (float)MissionLobbyComponent.GetSpawnPeriodDurationForPeer(peer));
     peer.WantsToSpawnAsBot    = false;
     peer.HasSpawnTimerExpired = false;
     this._missionScoreboardComponent.PlayerPropertiesChanged(peer.GetNetworkPeer());
     GameNetwork.BeginBroadcastModuleEvent();
     GameNetwork.WriteMessage((GameNetworkMessage) new KillDeathCountChange(peer.GetNetworkPeer(), (NetworkCommunicator)null, peer.KillCount, peer.AssistCount, peer.DeathCount, peer.Score));
     GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
 }
 internal void OnBehaviorActivated()
 {
     if (!this.formation.Team.IsPlayerGeneral && !this.formation.Team.IsPlayerSergeant && (this.formation.IsPlayerInFormation && Mission.Current.MainAgent != null))
     {
         MBTextManager.SetTextVariable("BEHAVIOUR_NAME_BEGIN", new TextObject(this.ToString().Replace("MBModule.Behavior", "")), false);
         InformationManager.AddQuickInformation(GameTexts.FindText("str_formation_ai_soldier_instruction_text"), 2000, Mission.Current.MainAgent.Character);
     }
     if (Game.Current.GameType != MultiplayerGame.Current)
     {
         this.InformSergeantPlayer();
         this._lastPlayerInformTime = MBCommon.GetTime(MBCommon.TimeType.Mission);
     }
     if (!this.formation.IsAIControlled)
     {
         return;
     }
     this.OnBehaviorActivatedAux();
 }
Exemplo n.º 23
0
 public override void OnBehaviourInitialize()
 {
     base.OnBehaviourInitialize();
     this.CurrentMultiplayerState = MissionLobbyComponent.MultiplayerGameState.WaitingFirstPlayers;
     if (GameNetwork.IsServerOrRecorder)
     {
         MissionMultiplayerGameModeBase missionBehaviour = Mission.Current.GetMissionBehaviour <MissionMultiplayerGameModeBase>();
         if (missionBehaviour == null || missionBehaviour.AllowCustomPlayerBanners())
         {
             return;
         }
         this._usingFixedBanners       = true;
         MissionPeer.OnPreTeamChanged += new MissionPeer.OnTeamChangedDelegate(MissionLobbyComponent.CreateFixedBannerForPeer);
     }
     else
     {
         this._inactivityTimer = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), MissionLobbyComponent.InactivityThreshold);
     }
 }
Exemplo n.º 24
0
 private void CheckForPlayersSpawningAsBots()
 {
     foreach (MissionPeer peer in VirtualPlayer.Peers <MissionPeer>())
     {
         if (peer.GetNetworkPeer().IsSynchronized&& peer.ControlledAgent == null && (peer.Team != null && peer.ControlledFormation != null) && peer.SpawnCountThisRound > 0)
         {
             if (!peer.HasSpawnTimerExpired && peer.SpawnTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission)))
             {
                 peer.HasSpawnTimerExpired = true;
             }
             if (peer.HasSpawnTimerExpired && peer.WantsToSpawnAsBot && peer.ControlledFormation.HasUnitsWithCondition((Func <Agent, bool>)(agent => agent.IsActive() && agent.IsAIControlled)))
             {
                 Agent newAgent       = (Agent)null;
                 Agent followingAgent = peer.FollowedAgent;
                 if (followingAgent != null && followingAgent.IsActive() && (followingAgent.IsAIControlled && peer.ControlledFormation.HasUnitsWithCondition((Func <Agent, bool>)(agent => agent == followingAgent))))
                 {
                     newAgent = followingAgent;
                 }
                 else
                 {
                     float maxHealth = 0.0f;
                     peer.ControlledFormation.ApplyActionOnEachUnit((Action <Agent>)(agent =>
                     {
                         if ((double)agent.Health <= (double)maxHealth)
                         {
                             return;
                         }
                         maxHealth = agent.Health;
                         newAgent  = agent;
                     }));
                 }
                 Mission.Current.ReplaceBotWithPlayer(newAgent, peer);
                 peer.WantsToSpawnAsBot    = false;
                 peer.HasSpawnTimerExpired = false;
             }
         }
     }
 }
Exemplo n.º 25
0
 public override void OnMissionTick(float dt)
 {
     if (GameNetwork.IsClient && this._inactivityTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission)))
     {
         NetworkMain.GameClient.IsInCriticalState = MBAPI.IMBNetwork.ElapsedTimeSinceLastUdpPacketArrived() > (double)MissionLobbyComponent.InactivityThreshold;
     }
     if (this.CurrentMultiplayerState == MissionLobbyComponent.MultiplayerGameState.WaitingFirstPlayers)
     {
         if (!GameNetwork.IsServer || this._warmupComponent != null && (this._warmupComponent.IsInWarmup || !this._timerComponent.CheckIfTimerPassed()))
         {
             return;
         }
         int num1     = GameNetwork.NetworkPeers.Count <NetworkCommunicator>((Func <NetworkCommunicator, bool>)(x => x.IsSynchronized));
         int num2     = MultiplayerOptions.OptionType.NumberOfBotsTeam1.GetIntValue() + MultiplayerOptions.OptionType.NumberOfBotsTeam2.GetIntValue();
         int intValue = MultiplayerOptions.OptionType.MinNumberOfPlayersForMatchStart.GetIntValue();
         int num3     = num2;
         if (num1 + num3 < intValue && MBCommon.CurrentGameType != MBCommon.GameType.MultiClientServer)
         {
             return;
         }
         this.SetStatePlayingAsServer();
     }
     else
     {
         if (this.CurrentMultiplayerState != MissionLobbyComponent.MultiplayerGameState.Playing)
         {
             return;
         }
         bool flag = this._timerComponent.CheckIfTimerPassed();
         if (!GameNetwork.IsServerOrRecorder || this._gameMode.RoundController != null || !flag && !this._gameMode.CheckForMatchEnd())
         {
             return;
         }
         this._gameMode.GetWinnerTeam();
         this._gameMode.SpawnComponent.SpawningBehaviour.RequestStopSpawnSession();
         this.SetStateEndingAsServer();
     }
 }
        private void ChangeTeamServer(NetworkCommunicator networkPeer, Team team)
        {
            MissionPeer component1 = networkPeer.GetComponent <MissionPeer>();
            MissionPeer component2 = networkPeer.GetComponent <MissionPeer>();
            Team        team1      = component1.Team;

            if (team1 != null && team1 != this.Mission.SpectatorTeam && (team1 != team && component1.ControlledAgent != null))
            {
                component1.ControlledAgent.Die(new Blow(component1.ControlledAgent.Index)
                {
                    DamageType    = DamageTypes.Invalid,
                    BaseMagnitude = 10000f,
                    Position      = component1.ControlledAgent.Position
                }, Agent.KillInfo.Stone);
            }
            component1.Team = team;
            if (team != team1)
            {
                if (component2.HasSpawnedAgentVisuals)
                {
                    component2.HasSpawnedAgentVisuals = false;
                    MBDebug.Print("HasSpawnedAgentVisuals = false for peer: " + component2.Name + " because he just changed his team");
                    component2.SpawnCountThisRound = 0;
                    Mission.Current.GetMissionBehaviour <MultiplayerMissionAgentVisualSpawnComponent>().RemoveAgentVisuals(component2, true);
                }
                if (!this._gameModeServer.IsGameModeHidingAllAgentVisuals && !networkPeer.IsServerPeer)
                {
                    this._missionNetworkComponent?.OnPeerSelectedTeam(component1);
                }
                this._gameModeServer.OnPeerChangedTeam(networkPeer, team1, team);
                component2.SpawnTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission), 0.1f);
                component2.WantsToSpawnAsBot    = false;
                component2.HasSpawnTimerExpired = false;
            }
            this.UpdateTeams(networkPeer, team1, team);
        }
 protected internal override void OnEditorTick(float dt)
 {
     base.OnEditorTick(dt);
     this.CheckSpawnParticle(MBCommon.GetTime(MBCommon.TimeType.Application));
 }
        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 void SpawnAgents()
        {
            BasicCultureObject cultureLimit1 = MBObjectManager.Instance.GetObject <BasicCultureObject>(MultiplayerOptions.OptionType.CultureTeam1.GetStrValue());
            BasicCultureObject cultureLimit2 = MBObjectManager.Instance.GetObject <BasicCultureObject>(MultiplayerOptions.OptionType.CultureTeam2.GetStrValue());

            foreach (MissionPeer peer in VirtualPlayer.Peers <MissionPeer>())
            {
                if (peer.GetNetworkPeer().IsSynchronized&& peer.ControlledAgent == null && (!peer.HasSpawnedAgentVisuals && peer.Team != null) && (peer.Team != this.Mission.SpectatorTeam && peer.SpawnTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission))))
                {
                    IAgentVisual       agentVisualForPeer = peer.GetAgentVisualForPeer(0);
                    BasicCultureObject basicCultureObject = peer.Team.Side == BattleSideEnum.Attacker ? cultureLimit1 : cultureLimit2;
                    int num = peer.SelectedTroopIndex;
                    IEnumerable <MultiplayerClassDivisions.MPHeroClass> mpHeroClasses = MultiplayerClassDivisions.GetMPHeroClasses(basicCultureObject);
                    MultiplayerClassDivisions.MPHeroClass mpHeroClass = num < 0 ? (MultiplayerClassDivisions.MPHeroClass)null : mpHeroClasses.ElementAt <MultiplayerClassDivisions.MPHeroClass>(num);
                    if (mpHeroClass == null && num < 0)
                    {
                        mpHeroClass = mpHeroClasses.First <MultiplayerClassDivisions.MPHeroClass>();
                        num         = 0;
                    }
                    BasicCharacterObject heroCharacter = mpHeroClass.HeroCharacter;
                    Equipment            equipment     = heroCharacter.Equipment.Clone();
                    IEnumerable <(EquipmentIndex, EquipmentElement)> alternativeEquipments = MPPerkObject.GetOnSpawnPerkHandler(peer)?.GetAlternativeEquipments(true);
                    if (alternativeEquipments != null)
                    {
                        foreach ((EquipmentIndex, EquipmentElement)tuple in alternativeEquipments)
                        {
                            equipment[tuple.Item1] = tuple.Item2;
                        }
                    }
                    AgentBuildData agentBuildData = new AgentBuildData(heroCharacter);
                    agentBuildData.MissionPeer(peer);
                    agentBuildData.Equipment(equipment);
                    agentBuildData.Team(peer.Team);
                    MatrixFrame frame;
                    if (agentVisualForPeer == null)
                    {
                        frame = this.SpawnComponent.GetSpawnFrame(peer.Team, heroCharacter.Equipment.Horse.Item != null);
                    }
                    else
                    {
                        frame = agentVisualForPeer.GetFrame();
                        frame.rotation.MakeUnit();
                    }
                    agentBuildData.InitialFrame(frame);
                    agentBuildData.IsFemale(peer.Peer.IsFemale);
                    BodyProperties bodyProperties = this.GetBodyProperties(peer, basicCultureObject);
                    agentBuildData.BodyProperties(bodyProperties);
                    agentBuildData.VisualsIndex(0);
                    agentBuildData.ClothingColor1(peer.Team == this.Mission.AttackerTeam ? basicCultureObject.Color : basicCultureObject.ClothAlternativeColor);
                    agentBuildData.ClothingColor2(peer.Team == this.Mission.AttackerTeam ? basicCultureObject.Color2 : basicCultureObject.ClothAlternativeColor2);
                    agentBuildData.TroopOrigin((IAgentOriginBase) new BasicBattleAgentOrigin(heroCharacter));
                    NetworkCommunicator networkPeer = peer.GetNetworkPeer();
                    if (this.GameMode.ShouldSpawnVisualsForServer(networkPeer))
                    {
                        this.AgentVisualSpawnComponent.SpawnAgentVisualsForPeer(peer, agentBuildData, num);
                    }
                    this.GameMode.HandleAgentVisualSpawning(networkPeer, agentBuildData);
                }
            }
            if (this.Mission.AttackerTeam != null)
            {
                int num = 0;
                foreach (Agent activeAgent in this.Mission.AttackerTeam.ActiveAgents)
                {
                    if (activeAgent.Character != null && activeAgent.MissionPeer == null)
                    {
                        ++num;
                    }
                }
                if (num < MultiplayerOptions.OptionType.NumberOfBotsTeam1.GetIntValue())
                {
                    this.SpawnBot(this.Mission.AttackerTeam, cultureLimit1);
                }
            }
            if (this.Mission.DefenderTeam == null)
            {
                return;
            }
            int num1 = 0;

            foreach (Agent activeAgent in this.Mission.DefenderTeam.ActiveAgents)
            {
                if (activeAgent.Character != null && activeAgent.MissionPeer == null)
                {
                    ++num1;
                }
            }
            if (num1 >= MultiplayerOptions.OptionType.NumberOfBotsTeam2.GetIntValue())
            {
                return;
            }
            this.SpawnBot(this.Mission.DefenderTeam, cultureLimit2);
        }
 public WarmupSpawningBehaviour()
 {
     this._spawnCheckTimer  = new Timer(MBCommon.GetTime(MBCommon.TimeType.Mission), 0.2f);
     this.IsSpawningEnabled = true;
 }