private void ResetSplitsBet(object sender, TimerPhase value) { BackgroundWorker invoker = new BackgroundWorker(); invoker.DoWork += delegate { Thread.Sleep(TimeSpan.FromSeconds(Settings.Delay)); SplitIndex = -1; BetIndex = -1; try { Array.Clear(Bets, 0, Bets.Length); Array.Clear(Scores, 0, Scores.Length); SpecialBets.Clear(); initArrays(); } catch (Exception ex) { LogException(ex); } if (!EndOfRun) { SendMessage(Settings.msgReset); } }; invoker.RunWorkerAsync(); }
private void SpecialBet(TwitchChat.User user, string argument) { if (argument.ToLower().StartsWith("start")) { ActiveSpecialBets = true; return; } if (argument.ToLower().StartsWith("end") || argument.ToLower().StartsWith("stop")) { var args = argument.Split(new string[] { " " }, StringSplitOptions.None); if (args.Count() > 1) { try { //TODO Accuracy better than seconds, special events are meant to be short (OoT Dampe < 1 min iirc, SM64 Secret Slide between 12.5s and 13s generally...) var time = TimeSpanParser.Parse(args[1]); Scores[SplitIndex] = Scores[SplitIndex] ?? (SplitIndex > 0 ? new Dictionary <string, int>(Scores[SplitIndex - 1]) : new Dictionary <string, int>()); foreach (KeyValuePair <string, TimeSpan> entry in SpecialBets) { if (Scores[SplitIndex].ContainsKey(entry.Key)) { Scores[SplitIndex][entry.Key] += (int)(time.TotalSeconds * Math.Exp(-(Math.Pow((int)time.TotalSeconds - (int)entry.Value.TotalSeconds, 2) / (int)time.TotalSeconds))); } else { Scores[SplitIndex].Add(entry.Key, (int)(time.TotalSeconds * Math.Exp(-(Math.Pow((int)time.TotalSeconds - (int)entry.Value.TotalSeconds, 2) / (int)time.TotalSeconds)))); } } SendMessage("Scores will be shown at the next split!"); //TODO Special ShowScore() for special bets ? SpecialBets.Clear(); } catch (Exception e) { LogException(e); } } ActiveSpecialBets = false; return; } if (!ActiveSpecialBets) { SendMessage("No special bet active."); } switch (State.CurrentPhase) { case TimerPhase.NotRunning: SendMessage(Settings.msgTimerNotRunning); return; case TimerPhase.Paused: SendMessage(Settings.msgTimerPaused); return; case TimerPhase.Ended: SendMessage(Settings.msgTimerEnded); return; } if (SpecialBets.ContainsKey(user.Name)) { SendMessage(user.Name + ": You already bet, silly!"); return; } try { var time = TimeSpanParser.Parse(argument); if (time.CompareTo(Settings.MinimumTime) <= 0) { SendMessage(user.Name + ": Invalid time, please retry."); return; } SpecialBets.Add(user.Name, time); } catch (Exception e) { LogException(e); } }