Exemplo n.º 1
0
 public void RemoveRaceComparisons()
 {
     if (SRLComparisonGenerator.IsRaceComparison(Model.CurrentState.CurrentComparison))
     {
         Model.CurrentState.CurrentComparison = Run.PersonalBestComparisonName;
     }
     for (var ind = 0; ind < Model.CurrentState.Run.ComparisonGenerators.Count; ind++)
     {
         if (SRLComparisonGenerator.IsRaceComparison(Model.CurrentState.Run.ComparisonGenerators[ind].Name))
         {
             Model.CurrentState.Run.ComparisonGenerators.RemoveAt(ind);
             ind--;
         }
     }
     foreach (var segment in Model.CurrentState.Run)
     {
         for (var index = 0; index < segment.Comparisons.Count; index++)
         {
             var comparison = segment.Comparisons.ElementAt(index);
             if (SRLComparisonGenerator.IsRaceComparison(comparison.Key))
             {
                 segment.Comparisons[comparison.Key] = default(Time);
             }
         }
     }
 }
Exemplo n.º 2
0
        protected void AddSplit(string user, ISegment segment, TimeSpan?time, TimingMethod method)
        {
            var comparisonName = SRLComparisonGenerator.GetRaceComparisonName(user);
            var newTime        = new Time(segment.Comparisons[comparisonName]);

            newTime[method] = time;
            segment.Comparisons[comparisonName] = newTime;
        }
Exemplo n.º 3
0
        protected void AddComparison(string userName)
        {
            var run            = Model.CurrentState.Run;
            var comparisonName = SRLComparisonGenerator.GetRaceComparisonName(userName);

            if (run.ComparisonGenerators.All(x => x.Name != comparisonName))
            {
                CompositeComparisons.AddShortComparisonName(comparisonName, userName);
                run.ComparisonGenerators.Add(new SRLComparisonGenerator(comparisonName));
            }
        }
Exemplo n.º 4
0
        private static ISegment GetMatchingSegment(IRun run, string user, string segmentName, TimingMethod method, bool timeHasValue)
        {
            var comparisonName     = SRLComparisonGenerator.GetRaceComparisonName(user);
            var trimmedSegmentName = segmentName.Trim().ToLower();

            if (timeHasValue)
            {
                return(run.FirstOrDefault(x => x.Name.Trim().ToLower() == trimmedSegmentName && x.Comparisons[comparisonName][method] == null));
            }
            return(run.LastOrDefault(x => x.Name.Trim().ToLower() == trimmedSegmentName && x.Comparisons[comparisonName][method] != null));
        }
Exemplo n.º 5
0
        protected void ProcessRaceChannelMessage(string user, string message)
        {
            if (user == "RaceBot")
            {
                if (message.Contains("GO!") && RaceState == RaceState.EnteredRaceAndReady)
                {
                    Model.Start();
                    RaceState = RaceState.RaceStarted;
                }
                else if (message == Client.LocalUser.NickName + " has been removed from the race.")
                {
                    RaceState = RaceState.NotInRace;
                }
                else if (message.Contains(" has been removed from the race."))
                {
                    var userName       = message.Substring(0, message.IndexOf(" "));
                    var raceComparison = SRLComparisonGenerator.GetRaceComparisonName(userName);

                    if (Model.CurrentState.CurrentComparison.Equals(raceComparison))
                    {
                        Model.CurrentState.CurrentComparison = Run.PersonalBestComparisonName;
                    }

                    var comparisonGenerator = Model.CurrentState.Run.ComparisonGenerators.FirstOrDefault(x => x.Name == raceComparison);
                    if (comparisonGenerator != null)
                    {
                        Model.CurrentState.Run.ComparisonGenerators.Remove(comparisonGenerator);
                    }

                    foreach (var segment in Model.CurrentState.Run)
                    {
                        segment.Comparisons[raceComparison] = default(Time);
                    }
                }
                else if (message.StartsWith(Client.LocalUser.NickName + " enters the race!"))
                {
                    RaceState = RaceState.EnteredRace;
                }
                else if (message.Contains(" enters the race!"))
                {
                    var userName = message.Substring(0, message.IndexOf(" "));
                    if (LiveSplitChannel.Users.Select(x => x.User.NickName).Contains(userName))
                    {
                        AddComparison(userName);
                    }
                }
                else if (message.StartsWith(Client.LocalUser.NickName + " is ready!"))
                {
                    RaceState = RaceState.EnteredRaceAndReady;
                }
                else if (message.StartsWith(Client.LocalUser.NickName + " isn't ready!"))
                {
                    RaceState = RaceState.EnteredRace;
                }
                else if (message.StartsWith(Client.LocalUser.NickName + " has forfeited from the race."))
                {
                    RaceState = RaceState.RaceEnded;
                }
                else if (message.StartsWith(Client.LocalUser.NickName + " has been undone from the race."))
                {
                    RaceState = RaceState.RaceStarted;
                }
                else if (message.StartsWith(Client.LocalUser.NickName + " has finished in"))
                {
                    RaceState = RaceState.RaceEnded;
                }
                else if (message == "Rematch!")
                {
                    RaceState = RaceState.NotInRace;
                    RemoveRaceComparisons();
                }
            }
        }