Пример #1
0
        private void CheckMorales()
        {
            if ((double)this._nextTimeToCheckForMorales < 0.0)
            {
                this._nextTimeToCheckForMorales = this.Mission.Time + 1f;
            }
            if ((double)this.Mission.Time < (double)this._nextTimeToCheckForMorales)
            {
                return;
            }
            ++this._nextTimeToCheckForMorales;
            float moraleGain;

            if (!this.GetMoraleGain(out moraleGain))
            {
                return;
            }
            this._morale += moraleGain;
            this._morale  = MBMath.ClampFloat(this._morale, -1f, 1f);
            GameNetwork.BeginBroadcastModuleEvent();
            GameNetwork.WriteMessage((GameNetworkMessage) new FlagDominationMoraleChangeMessage(this.MoraleRounded));
            GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
            this._gameModeFlagDominationClient?.OnMoraleChanged(this.MoraleRounded);
            MPPerkObject.RaiseEventForAllPeers(MPPerkCondition.PerkEventFlags.MoraleChange);
        }
Пример #2
0
 private void TickFlags(float dt)
 {
     this._dtSumFlagStateCheck += dt;
     if ((double)this._dtSumFlagStateCheck < 0.25)
     {
         return;
     }
     this._dtSumFlagStateCheck -= 0.25f;
     foreach (FlagCapturePoint allCapturePoint in this.AllCapturePoints)
     {
         if (!allCapturePoint.IsDeactivated)
         {
             Team  capturePointOwner = this._capturePointOwners[allCapturePoint.FlagIndex];
             Agent agent1            = (Agent)null;
             float num1 = float.MaxValue;
             foreach (Agent agent2 in Mission.Current.GetAgentsInRange(allCapturePoint.Position.AsVec2, 4f).Where <Agent>((Func <Agent, bool>)(a => a.IsHuman && a.IsActive())))
             {
                 float num2 = agent2.Position.DistanceSquared(allCapturePoint.Position);
                 if ((double)num2 <= 16.0 && (double)num2 < (double)num1)
                 {
                     agent1 = agent2;
                     num1   = num2;
                 }
             }
             bool isContested = allCapturePoint.IsContested;
             if (capturePointOwner == null)
             {
                 if (!isContested && agent1 != null)
                 {
                     allCapturePoint.SetMoveFlag(CaptureTheFlagFlagDirection.Down);
                 }
                 else if (agent1 == null & isContested)
                 {
                     allCapturePoint.SetMoveFlag(CaptureTheFlagFlagDirection.Up);
                 }
             }
             else if (agent1 != null)
             {
                 if (agent1.Team != capturePointOwner && !isContested)
                 {
                     allCapturePoint.SetMoveFlag(CaptureTheFlagFlagDirection.Down);
                 }
                 else if (agent1.Team == capturePointOwner & isContested)
                 {
                     allCapturePoint.SetMoveFlag(CaptureTheFlagFlagDirection.Up);
                 }
             }
             else if (isContested)
             {
                 allCapturePoint.SetMoveFlag(CaptureTheFlagFlagDirection.Up);
             }
             bool ownerTeamChanged;
             allCapturePoint.OnAfterTick(agent1 != null, out ownerTeamChanged);
             if (ownerTeamChanged)
             {
                 Team team   = agent1.Team;
                 uint color  = team != null ? team.Color : 4284111450U;
                 uint color2 = team != null ? team.Color2 : uint.MaxValue;
                 allCapturePoint.SetTeamColorsWithAllSynched(color, color2);
                 this._capturePointOwners[allCapturePoint.FlagIndex] = team;
                 GameNetwork.BeginBroadcastModuleEvent();
                 GameNetwork.WriteMessage((GameNetworkMessage) new FlagDominationCapturePointMessage(allCapturePoint.FlagIndex, team));
                 GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
                 this._gameModeFlagDominationClient?.OnCapturePointOwnerChanged(allCapturePoint, team);
                 this.NotificationsComponent.FlagXCapturedByTeamX((SynchedMissionObject)allCapturePoint, agent1.Team);
                 MPPerkObject.RaiseEventForAllPeers(MPPerkCondition.PerkEventFlags.FlagCapture);
             }
         }
     }
 }
Пример #3
0
        private void CheckRemovingOfPoints()
        {
            if ((double)this._nextTimeToCheckForPointRemoval < 0.0)
            {
                this._nextTimeToCheckForPointRemoval = this.Mission.Time + this._pointRemovalTimeInSeconds;
            }
            if ((double)this.Mission.Time < (double)this._nextTimeToCheckForPointRemoval)
            {
                return;
            }
            this._nextTimeToCheckForPointRemoval += this._pointRemovalTimeInSeconds;
            List <BattleSideEnum> battleSideEnumList = new List <BattleSideEnum>();

            foreach (Team team1 in (ReadOnlyCollection <Team>) this.Mission.Teams)
            {
                Team team = team1;
                if (team.Side != BattleSideEnum.None)
                {
                    int num = (int)team.Side * 2 - 1;
                    if (this.AllCapturePoints.All <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => this.GetFlagOwnerTeam(cp) != team)))
                    {
                        if (this.AllCapturePoints.FirstOrDefault <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => this.GetFlagOwnerTeam(cp) == null)) != null)
                        {
                            this._morale -= 0.1f * (float)num;
                            battleSideEnumList.Add(BattleSideEnum.None);
                        }
                        else
                        {
                            this._morale -= (float)(0.100000001490116 * (double)num * 2.0);
                            battleSideEnumList.Add(team.Side.GetOppositeSide());
                        }
                        this._morale = MBMath.ClampFloat(this._morale, -1f, 1f);
                    }
                    else
                    {
                        battleSideEnumList.Add(team.Side);
                    }
                }
            }
            List <int> removedCapIndexList = new List <int>();
            List <FlagCapturePoint> list1  = this.AllCapturePoints.ToList <FlagCapturePoint>();

            foreach (BattleSideEnum battleSideEnum in battleSideEnumList)
            {
                BattleSideEnum side = battleSideEnum;
                if (side == BattleSideEnum.None)
                {
                    removedCapIndexList.Add(this.RemoveCapturePoint(list1.GetRandomElementWithPredicate <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => this.GetFlagOwnerTeam(cp) == null))));
                }
                else
                {
                    List <FlagCapturePoint> list2 = list1.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => this.GetFlagOwnerTeam(cp) != null && this.GetFlagOwnerTeam(cp).Side == side)).ToList <FlagCapturePoint>();
                    List <FlagCapturePoint> list3 = list2.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => this.GetNumberOfAttackersAroundFlag(cp) == 0)).ToList <FlagCapturePoint>();
                    if (list3.Any <FlagCapturePoint>())
                    {
                        removedCapIndexList.Add(this.RemoveCapturePoint(list3.GetRandomElement <FlagCapturePoint>()));
                    }
                    else
                    {
                        List <KeyValuePair <FlagCapturePoint, int> > keyValuePairList = new List <KeyValuePair <FlagCapturePoint, int> >();
                        foreach (FlagCapturePoint flagCapturePoint in list2)
                        {
                            if (!keyValuePairList.Any <KeyValuePair <FlagCapturePoint, int> >())
                            {
                                keyValuePairList.Add(new KeyValuePair <FlagCapturePoint, int>(flagCapturePoint, this.GetNumberOfAttackersAroundFlag(flagCapturePoint)));
                            }
                            else
                            {
                                int count = this.GetNumberOfAttackersAroundFlag(flagCapturePoint);
                                if (keyValuePairList.Any <KeyValuePair <FlagCapturePoint, int> >((Func <KeyValuePair <FlagCapturePoint, int>, bool>)(cc => cc.Value > count)))
                                {
                                    keyValuePairList.Clear();
                                    keyValuePairList.Add(new KeyValuePair <FlagCapturePoint, int>(flagCapturePoint, count));
                                }
                                else if (keyValuePairList.Any <KeyValuePair <FlagCapturePoint, int> >((Func <KeyValuePair <FlagCapturePoint, int>, bool>)(cc => cc.Value == count)))
                                {
                                    keyValuePairList.Add(new KeyValuePair <FlagCapturePoint, int>(flagCapturePoint, count));
                                }
                            }
                        }
                        removedCapIndexList.Add(this.RemoveCapturePoint(keyValuePairList.GetRandomElement <KeyValuePair <FlagCapturePoint, int> >().Key));
                    }
                }
                FlagCapturePoint flagCapturePoint1 = list1.First <FlagCapturePoint>(closure_0 ?? (closure_0 = (Func <FlagCapturePoint, bool>)(fl => fl.FlagIndex == removedCapIndexList[removedCapIndexList.Count - 1])));
                list1.Remove(flagCapturePoint1);
            }
            removedCapIndexList.Sort();
            int first  = removedCapIndexList[0];
            int second = removedCapIndexList[1];
            FlagCapturePoint remainingFlag = this.AllCapturePoints.First <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(cp => cp.FlagIndex != first && cp.FlagIndex != second));

            this.NotificationsComponent.FlagXRemaining(remainingFlag);
            GameNetwork.BeginBroadcastModuleEvent();
            GameNetwork.WriteMessage((GameNetworkMessage) new FlagDominationMoraleChangeMessage(this.MoraleRounded));
            GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
            GameNetwork.BeginBroadcastModuleEvent();
            GameNetwork.WriteMessage((GameNetworkMessage) new FlagDominationFlagsRemovedMessage());
            GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
            this._flagRemovalOccured = true;
            this._gameModeFlagDominationClient?.OnNumberOfFlagsChanged();
            foreach (MissionBehaviour missionBehaviour in this.Mission.MissionBehaviours)
            {
                if (missionBehaviour is IFlagRemoved flagRemoved1)
                {
                    flagRemoved1.OnFlagsRemoved(remainingFlag.FlagIndex);
                }
            }
            MPPerkObject.RaiseEventForAllPeers(MPPerkCondition.PerkEventFlags.FlagRemoval);
        }