Inheritance: MonoBehaviour
Exemplo n.º 1
0
        public void OnCapturePointOwnerChanged(FlagCapturePoint flagCapturePoint, Team ownerTeam)
        {
            this._capturePointOwners[flagCapturePoint.FlagIndex] = ownerTeam;
            Action <FlagCapturePoint, Team> ownerChangedEvent = this.OnCapturePointOwnerChangedEvent;

            if (ownerChangedEvent != null)
            {
                ownerChangedEvent(flagCapturePoint, ownerTeam);
            }
            if (this._myRepresentative == null || this._myRepresentative.MissionPeer.Team == null)
            {
                return;
            }
            MatrixFrame cameraFrame = Mission.Current.GetCameraFrame();
            Vec3        position    = cameraFrame.origin + cameraFrame.rotation.u;

            if (this._myRepresentative.MissionPeer.Team == ownerTeam)
            {
                MBSoundEvent.PlaySound(SoundEvent.GetEventIdFromString("event:/alerts/report/flag_captured"), position);
            }
            else
            {
                MBSoundEvent.PlaySound(SoundEvent.GetEventIdFromString("event:/alerts/report/flag_lost"), position);
            }
        }
        public void OnCapturePointOwnerChanged(FlagCapturePoint flagCapturePoint, Team ownerTeam)
        {
            this._capturePointOwners[flagCapturePoint.FlagIndex] = ownerTeam;
            Action <FlagCapturePoint, Team> ownerChangedEvent = this.OnCapturePointOwnerChangedEvent;

            if (ownerChangedEvent != null)
            {
                ownerChangedEvent(flagCapturePoint, ownerTeam);
            }
            if (ownerTeam != null && ownerTeam.Side == BattleSideEnum.Defender && ((double)this._remainingTimeForBellSoundToStop > 8.0 && flagCapturePoint == this._masterFlag))
            {
                this._bellSoundEvent.Stop();
                this._bellSoundEvent = (SoundEvent)null;
                this._remainingTimeForBellSoundToStop = float.MinValue;
                this._lastBellSoundPercentage        += 0.2f;
            }
            if (this._myRepresentative == null || this._myRepresentative.MissionPeer.Team == null)
            {
                return;
            }
            MatrixFrame cameraFrame = Mission.Current.GetCameraFrame();
            Vec3        position    = cameraFrame.origin + cameraFrame.rotation.u;

            if (this._myRepresentative.MissionPeer.Team == ownerTeam)
            {
                MBSoundEvent.PlaySound(SoundEvent.GetEventIdFromString("event:/alerts/report/flag_captured"), position);
            }
            else
            {
                MBSoundEvent.PlaySound(SoundEvent.GetEventIdFromString("event:/alerts/report/flag_lost"), position);
            }
        }
Exemplo n.º 3
0
        protected override float GetAiWeight()
        {
            if (this._lastEffort)
            {
                return(10f);
            }
            this._flagpositions.RemoveAll((Predicate <FlagCapturePoint>)(fp => fp.IsDeactivated));
            FlagCapturePoint flag = this._flagpositions.FirstOrDefault <FlagCapturePoint>();

            if (this._flagpositions.Count != 1 || this._flagDominationGameMode.GetFlagOwnerTeam(flag) == null || !this._flagDominationGameMode.GetFlagOwnerTeam(flag).IsEnemyOf(this.formation.Team))
            {
                return(0.0f);
            }
            float battleSideVictory = this._flagDominationGameMode.GetTimeUntilBattleSideVictory(this._flagDominationGameMode.GetFlagOwnerTeam(flag).Side);

            if ((double)battleSideVictory <= 60.0)
            {
                return(10f);
            }
            if ((double)this.formation.QuerySystem.AveragePosition.Distance(flag.Position.AsVec2) / (double)this.formation.QuerySystem.MovementSpeedMaximum * 8.0 <= (double)battleSideVictory)
            {
                return(0.0f);
            }
            this._lastEffort = true;
            return(10f);
        }
Exemplo n.º 4
0
        private int RemoveCapturePoint(FlagCapturePoint capToRemove)
        {
            int flagIndex = capToRemove.FlagIndex;

            capToRemove.RemovePointAsServer();
            GameNetwork.BeginBroadcastModuleEvent();
            GameNetwork.WriteMessage((GameNetworkMessage) new FlagDominationCapturePointMessage(flagIndex, (Team)null));
            GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.None);
            return(flagIndex);
        }
Exemplo n.º 5
0
        private MovementOrder UncapturedFlagMoveOrder()
        {
            if (this._flagpositions.Any <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team)))
            {
                FlagCapturePoint flagCapturePoint = this._flagpositions.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team)).MinBy <FlagCapturePoint, float>((Func <FlagCapturePoint, float>)(fp => this.formation.Team.QuerySystem.GetLocalEnemyPower(fp.Position.AsVec2)));
                return(MovementOrder.MovementOrderMove(new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, flagCapturePoint.Position, false)));
            }
            if (!this._flagpositions.Any <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) == this.formation.Team)))
            {
                return(MovementOrder.MovementOrderStop);
            }
            Vec3 position = this._flagpositions.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) == this.formation.Team)).MinBy <FlagCapturePoint, float>((Func <FlagCapturePoint, float>)(fp => fp.Position.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition))).Position;

            return(MovementOrder.MovementOrderMove(new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, position, false)));
        }
 public override void AfterStart()
 {
     this.Mission.SetMissionMode(MissionMode.Battle, true);
     foreach (FlagCapturePoint allCapturePoint in this.AllCapturePoints)
     {
         if (allCapturePoint.GameEntity.HasTag("keep_capture_point"))
         {
             this._masterFlag = allCapturePoint;
         }
         else if (allCapturePoint.FlagIndex == 0)
         {
             MatrixFrame globalFrame = allCapturePoint.GameEntity.GetGlobalFrame();
             this._retreatHornPosition = globalFrame.origin + globalFrame.rotation.u * 3f;
         }
     }
 }
 protected override void CalculateCurrentOrder()
 {
     if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation == null || (double)this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition) > 2500.0)
     {
         this.CurrentOrder       = this.UncapturedFlagMoveOrder();
         this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
     }
     else
     {
         FlagCapturePoint flagCapturePoint = (FlagCapturePoint)null;
         if (this._flagpositions.Any <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team && !fp.IsContested)))
         {
             flagCapturePoint = this._flagpositions.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team && !fp.IsContested)).MinBy <FlagCapturePoint, float>((Func <FlagCapturePoint, float>)(fp => this.formation.QuerySystem.AveragePosition.DistanceSquared(fp.Position.AsVec2)));
         }
         if (!this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsInfantryFormation && flagCapturePoint != null)
         {
             this.CurrentOrder       = MovementOrder.MovementOrderMove(new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, flagCapturePoint.Position, false));
             this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
         }
         else if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsRangedFormation)
         {
             this.CurrentOrder       = MovementOrder.MovementOrderChargeToTarget(this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.Formation);
             this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtEnemy;
         }
         else
         {
             Vec2          direction      = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2 - this.formation.QuerySystem.AveragePosition;
             float         num            = direction.Normalize();
             WorldPosition medianPosition = this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition;
             if ((double)num > (double)this.formation.QuerySystem.MissileRange)
             {
                 medianPosition.SetVec2(medianPosition.AsVec2 - direction * (this.formation.QuerySystem.MissileRange - this.formation.Depth * 0.5f));
             }
             else if ((double)num < (double)this.formation.QuerySystem.MissileRange * 0.400000005960464)
             {
                 medianPosition.SetVec2(medianPosition.AsVec2 - direction * (this.formation.QuerySystem.MissileRange * 0.7f));
             }
             else
             {
                 direction = direction.RightVec();
                 medianPosition.SetVec2(this.formation.QuerySystem.AveragePosition + direction * 20f);
             }
             this.CurrentOrder       = MovementOrder.MovementOrderMove(medianPosition);
             this.CurrentFacingOrder = FacingOrder.FacingOrderLookAtDirection(direction);
         }
     }
 }
Exemplo n.º 8
0
 protected override void CalculateCurrentOrder()
 {
     if (this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation == null || (double)this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.MedianPosition.AsVec2.DistanceSquared(this.formation.QuerySystem.AveragePosition) > 2500.0)
     {
         this.CurrentOrder = this.UncapturedFlagMoveOrder();
     }
     else
     {
         FlagCapturePoint flagCapturePoint = (FlagCapturePoint)null;
         if (this._flagpositions.Any <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team && !fp.IsContested)))
         {
             flagCapturePoint = this._flagpositions.Where <FlagCapturePoint>((Func <FlagCapturePoint, bool>)(fp => this._flagDominationGameMode.GetFlagOwnerTeam(fp) != this.formation.Team && !fp.IsContested)).MinBy <FlagCapturePoint, float>((Func <FlagCapturePoint, float>)(fp => this.formation.QuerySystem.AveragePosition.DistanceSquared(fp.Position.AsVec2)));
         }
         if ((!this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.IsRangedFormation ? 0 : ((double)this.formation.QuerySystem.FormationPower / (double)this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.FormationPower / (double)this.formation.Team.QuerySystem.OverallPowerRatio > 0.699999988079071 ? 1 : 0)) == 0 && flagCapturePoint != null)
         {
             this.CurrentOrder = MovementOrder.MovementOrderMove(new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, flagCapturePoint.Position, false));
         }
         else
         {
             this.CurrentOrder = MovementOrder.MovementOrderChargeToTarget(this.formation.QuerySystem.ClosestSignificantlyLargeEnemyFormation.Formation);
         }
     }
 }
Exemplo n.º 9
0
 public Team GetFlagOwner(FlagCapturePoint flag) => this._capturePointOwners[flag.FlagIndex];
 public void OnFlagDeactivated(FlagCapturePoint flag) => ++ this._activeSpawnZoneIndex;
Exemplo n.º 11
0
 public Team GetFlagOwnerTeam(FlagCapturePoint flag) => flag == null ? (Team)null : this._capturePointOwners[flag.FlagIndex];
Exemplo n.º 12
0
        public int GetNumberOfAttackersAroundFlag(FlagCapturePoint capturePoint)
        {
            Team ownerTeam = this.GetFlagOwnerTeam(capturePoint);

            return(ownerTeam == null ? 0 : Mission.Current.GetAgentsInRange(capturePoint.Position.AsVec2, 6f).Count <Agent>((Func <Agent, bool>)(a => a.IsHuman && a.IsActive() && (double)a.Position.DistanceSquared(capturePoint.Position) <= 36.0 && a.Team.Side != ownerTeam.Side)));
        }
Exemplo n.º 13
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);
        }
 public void FlagXRemaining(FlagCapturePoint remainingFlag) => this.HandleNewNotification(MultiplayerGameNotificationsComponent.MultiplayerNotificationEnum.FlagXRemaining, remainingFlag.FlagChar);