public static void InitializeGameModes(bool lightsOn) { if (!lightsOn) { return; } if (OtherModes.TimeModeOn) { OtherModes.SetMultiplier(TwitchPlaySettings.data.TimeModeStartingMultiplier); } List <TwitchBomb> bombHandles = TwitchGame.Instance.Bombs; foreach (TwitchBomb bomb in bombHandles) { if (OtherModes.TimeModeOn) { bomb.CurrentTimer = TwitchPlaySettings.data.TimeModeStartingTime * 60; } else if (OtherModes.ZenModeOn) { bomb.CurrentTimer = 1; } } }
public void InitializeGameModes(bool lightsOn) { if (!lightsOn) { return; } if (OtherModes.TimeModeOn) { OtherModes.SetMultiplier(TwitchPlaySettings.data.TimeModeStartingMultiplier); } List <TwitchBombHandle> bombHandles = BombMessageResponder.Instance.BombHandles; foreach (TwitchBombHandle handle in bombHandles) { if (OtherModes.TimeModeOn) { handle.bombCommander.timerComponent.TimeRemaining = TwitchPlaySettings.data.TimeModeStartingTime * 60; } else if (OtherModes.ZenModeOn) { handle.bombCommander.timerComponent.TimeRemaining = 1; } } }
private void AwardSolve(string userNickName, int ComponentValue) { if (OtherModes.ZenModeOn) { ComponentValue = (int)Math.Ceiling(ComponentValue * 0.20f); } if (userNickName == null) { TwitchPlaySettings.AddRewardBonus(ComponentValue); } else { string headerText = UnsupportedModule ? modInfo.moduleDisplayName : BombComponent.GetModuleDisplayName(); IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.AwardSolve, Code, userNickName, ComponentValue, headerText); string RecordMessageTone = $"Module ID: {Code} | Player: {userNickName} | Module Name: {headerText} | Value: {ComponentValue}"; Leaderboard.Instance?.AddSolve(userNickName); if (!UserAccess.HasAccess(userNickName, AccessLevel.NoPoints)) { Leaderboard.Instance?.AddScore(userNickName, ComponentValue); } else { TwitchPlaySettings.AddRewardBonus(ComponentValue); } TwitchPlaySettings.AppendToSolveStrikeLog(RecordMessageTone); TwitchPlaySettings.AppendToPlayerLog(userNickName); } if (OtherModes.TimeModeOn) { float time = OtherModes.GetAdjustedMultiplier() * ComponentValue; if (time < TwitchPlaySettings.data.TimeModeMinimumTimeGained) { BombCommander.timerComponent.TimeRemaining = BombCommander.CurrentTimer + TwitchPlaySettings.data.TimeModeMinimumTimeGained; IRCConnection.Instance.SendMessage("Bomb time increased by the minimum {0} seconds!", TwitchPlaySettings.data.TimeModeMinimumTimeGained); } else { BombCommander.timerComponent.TimeRemaining = BombCommander.CurrentTimer + time; IRCConnection.Instance.SendMessage("Bomb time increased by {0} seconds!", Math.Round(time, 1)); } OtherModes.SetMultiplier(OtherModes.GetMultiplier() + TwitchPlaySettings.data.TimeModeSolveBonus); } }
public static void SetMultiplier([Group(1)] float multiplier) => OtherModes.SetMultiplier(multiplier);
protected override void OnMessageReceived(string userNickName, string userColorCode, string text) { Match match; int index; if (!text.StartsWith("!") || text.Equals("!")) { return; } text = text.Substring(1); if (IsAuthorizedDefuser(userNickName)) { if (text.RegexMatch(out match, "^notes(-?[0-9]+) (.+)$") && int.TryParse(match.Groups[1].Value, out index)) { string notes = match.Groups[2].Value; IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.NotesTaken, index--, notes); _notesDictionary[index] = notes; moduleCameras?.SetNotes(index, notes); return; } if (text.RegexMatch(out match, "^notes(-?[0-9]+)append (.+)", "^appendnotes(-?[0-9]+) (.+)") && int.TryParse(match.Groups[1].Value, out index)) { string notes = match.Groups[2].Value; IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.NotesAppended, index--, notes); if (!_notesDictionary.ContainsKey(index)) { _notesDictionary[index] = TwitchPlaySettings.data.NotesSpaceFree; } _notesDictionary[index] += " " + notes; moduleCameras?.AppendNotes(index, notes); return; } if (text.RegexMatch(out match, "^clearnotes(-?[0-9]+)$", "^notes(-?[0-9]+)clear$") && int.TryParse(match.Groups[1].Value, out index)) { IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.NoteSlotCleared, index--); _notesDictionary[index] = (OtherModes.ZenModeOn && index == 3) ? TwitchPlaySettings.data.ZenModeFreeSpace : TwitchPlaySettings.data.NotesSpaceFree; moduleCameras?.SetNotes(index, _notesDictionary[index]); return; } if (text.Equals("snooze", StringComparison.InvariantCultureIgnoreCase)) { if (GameRoom.Instance is ElevatorGameRoom) { return; //There is no alarm clock in the elevator room. } DropCurrentBomb(); _coroutineQueue.AddToQueue(AlarmClockHoldableHandler.Instance.RespondToCommand(userNickName, "alarmclock snooze")); return; } if (text.Equals("modules", StringComparison.InvariantCultureIgnoreCase)) { moduleCameras?.AttachToModules(ComponentHandles); return; } if (text.RegexMatch(out match, "^claims (.+)")) { OnMessageReceived(match.Groups[1].Value, userColorCode, "!claims"); return; } if (text.Equals("claims", StringComparison.InvariantCultureIgnoreCase)) { List <string> claimed = ( from handle in ComponentHandles where handle.PlayerName != null && handle.PlayerName.Equals(userNickName, StringComparison.InvariantCultureIgnoreCase) && !handle.Solved select string.Format(TwitchPlaySettings.data.OwnedModule, handle.Code, handle.HeaderText)).ToList(); if (claimed.Count > 0) { string message = string.Format(TwitchPlaySettings.data.OwnedModuleList, userNickName, string.Join(", ", claimed.ToArray(), 0, Math.Min(claimed.Count, 5))); if (claimed.Count > 5) { message += "..."; } IRCConnection.Instance.SendMessage(message); } else { IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.NoOwnedModules, userNickName); } return; } if (text.RegexMatch("^(?:claim ?|view ?|all ?){2,3}$")) { if (text.Contains("claim") && text.Contains("all")) { foreach (var handle in ComponentHandles) { if (handle == null || !GameRoom.Instance.IsCurrentBomb(handle.bombID)) { continue; } handle.AddToClaimQueue(userNickName, text.Contains("view")); } return; } } if (text.StartsWith("claim ", StringComparison.InvariantCultureIgnoreCase)) { var split = text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var claim in split.Skip(1)) { TwitchComponentHandle handle = ComponentHandles.FirstOrDefault(x => x.Code.Equals(claim, StringComparison.InvariantCultureIgnoreCase)); if (handle == null || !GameRoom.Instance.IsCurrentBomb(handle.bombID)) { continue; } handle.AddToClaimQueue(userNickName); } return; } if (text.RegexMatch("^(unclaim|release) ?all$")) { foreach (TwitchComponentHandle handle in ComponentHandles) { handle.RemoveFromClaimQueue(userNickName); } string[] moduleIDs = ComponentHandles.Where(x => !x.Solved && x.PlayerName != null && x.PlayerName.Equals(userNickName, StringComparison.InvariantCultureIgnoreCase)) .Select(x => x.Code).ToArray(); text = string.Format("unclaim {0}", string.Join(" ", moduleIDs)); } if (text.RegexMatch(out match, "^(?:unclaim|release) (.+)")) { var split = match.Groups[1].Value.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var claim in split) { TwitchComponentHandle handle = ComponentHandles.FirstOrDefault(x => x.Code.Equals(claim)); if (handle == null || !GameRoom.Instance.IsCurrentBomb(handle.bombID)) { continue; } handle.OnMessageReceived(userNickName, userColorCode, "unclaim"); } return; } if (text.Equals("unclaimed", StringComparison.InvariantCultureIgnoreCase)) { IEnumerable <string> unclaimed = ComponentHandles.Where(handle => !handle.Claimed && !handle.Solved && GameRoom.Instance.IsCurrentBomb(handle.bombID)).Shuffle().Take(3) .Select(handle => string.Format($"{handle.HeaderText} ({handle.Code})")).ToList(); if (unclaimed.Any()) { IRCConnection.Instance.SendMessage("Unclaimed Modules: {0}", unclaimed.Join(", ")); } else { IRCConnection.Instance.SendMessage("There are no more unclaimed modules."); } return; } if (text.Equals("unsolved", StringComparison.InvariantCultureIgnoreCase)) { IEnumerable <string> unsolved = ComponentHandles.Where(handle => !handle.Solved && GameRoom.Instance.IsCurrentBomb(handle.bombID)).Shuffle().Take(3) .Select(handle => string.Format("{0} ({1}) - {2}", handle.HeaderText, handle.Code, handle.PlayerName == null ? "Unclaimed" : "Claimed by " + handle.PlayerName)).ToList(); if (unsolved.Any()) { IRCConnection.Instance.SendMessage("Unsolved Modules: {0}", unsolved.Join(", ")); } else { IRCConnection.Instance.SendMessage("There are no unsolved modules, something went wrong as this message should never be displayed."); //this should never happen } return; } if (text.RegexMatch(out match, "^(?:find|search) (.+)")) { string[] queries = match.Groups[1].Value.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries); foreach (string query in queries) { string trimmed = query.Trim(); IEnumerable <string> modules = ComponentHandles.Where(handle => handle.HeaderText.ContainsIgnoreCase(trimmed) && GameRoom.Instance.IsCurrentBomb(handle.bombID)) .OrderByDescending(handle => handle.HeaderText.EqualsIgnoreCase(trimmed)).ThenBy(handle => handle.Solved).ThenBy(handle => handle.PlayerName != null).Take(3) .Select(handle => string.Format("{0} ({1}) - {2}", handle.HeaderText, handle.Code, handle.Solved ? "Solved" : (handle.PlayerName == null ? "Unclaimed" : "Claimed by " + handle.PlayerName) )).ToList(); if (modules.Any()) { IRCConnection.Instance.SendMessage("Modules: {0}", modules.Join(", ")); } else { IRCConnection.Instance.SendMessage($"Couldn't find any modules containing \"{trimmed}\"."); } } return; } if (text.RegexMatch(out match, "^(?:findplayer|playerfind|searchplayer|playersearch) (.+)")) { string[] queries = match.Groups[1].Value.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray(); foreach (string query in queries) { string trimmed = query.Trim(); IEnumerable <TwitchComponentHandle> modules = ComponentHandles.Where(handle => handle.HeaderText.ContainsIgnoreCase(trimmed) && GameRoom.Instance.IsCurrentBomb(handle.bombID)) .OrderByDescending(handle => handle.HeaderText.EqualsIgnoreCase(trimmed)).ThenBy(handle => handle.Solved).ToList(); IEnumerable <string> playerModules = modules.Where(handle => handle.PlayerName != null).OrderByDescending(handle => handle.HeaderText.EqualsIgnoreCase(trimmed)) .Select(handle => string.Format($"{handle.HeaderText} ({handle.Code}) - Claimed by {handle.PlayerName}")).ToList(); if (modules.Any()) { if (playerModules.Any()) { IRCConnection.Instance.SendMessage("Modules: {0}", playerModules.Join(", ")); } else { IRCConnection.Instance.SendMessage("None of the specified modules are claimed/have been solved."); } } else { IRCConnection.Instance.SendMessage($"Could not find any modules containing \"{trimmed}\"."); } } } if (text.RegexMatch(out match, "^(claim ?(?:any|van|mod) ?(?:view)?|view ?claim ?(?:any|van|mod))")) { var vanilla = match.Groups[1].Value.Contains("van"); var modded = match.Groups[1].Value.Contains("mod"); var view = match.Groups[1].Value.Contains("view"); var avoid = new[] { "Souvenir", "Forget Me Not", "Turn The Key", "Turn The Keys", "The Swan", "Forget Everything" }; var unclaimed = ComponentHandles .Where(handle => (vanilla ? !handle.IsMod : modded ? handle.IsMod : true) && !handle.Claimed && !handle.Solved && !avoid.Contains(handle.HeaderText) && GameRoom.Instance.IsCurrentBomb(handle.bombID)) .Shuffle().FirstOrDefault(); if (unclaimed != null) { text = unclaimed.Code + (view ? " claimview" : " claim"); } else { IRCConnection.Instance.SendMessage(string.Format("There are no more unclaimed{0} modules.", vanilla ? " vanilla" : modded ? " modded" : null)); } } if (text.RegexMatch(out match, "^(?:findsolved|solvedfind|searchsolved|solvedsearch) (.+)")) { string[] queries = match.Groups[1].Value.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray(); foreach (string query in queries) { string trimmed = query.Trim(); IEnumerable <BombCommander> commanders = BombCommanders.Where(handle => handle.SolvedModules.Keys.ToArray().Any(x => x.ContainsIgnoreCase(trimmed))).ToList(); IEnumerable <TwitchComponentHandle> modules = commanders.SelectMany(x => x.SolvedModules.Where(y => y.Key.ContainsIgnoreCase(trimmed))) .OrderByDescending(x => x.Key.EqualsIgnoreCase(trimmed)).SelectMany(x => x.Value).ToList(); IEnumerable <string> playerModules = modules.Where(handle => handle.PlayerName != null) .Select(handle => string.Format($"{handle.HeaderText} ({handle.Code}) - Claimed by {handle.PlayerName}", handle.HeaderText, handle.Code, "Claimed by " + handle.PlayerName)).ToList(); if (commanders.Any()) { if (playerModules.Any()) { IRCConnection.Instance.SendMessage("Modules: {0}", playerModules.Join(", ")); } else { IRCConnection.Instance.SendMessage("None of the specified modules have been solved."); } } else { IRCConnection.Instance.SendMessage($"Could not find any modules containing \"{trimmed}\"."); } } } if (text.RegexMatch(out match, "^((?:(?:find|search)|claim|view|all){2,4}) (.+)")) { bool validFind = match.Groups[1].Value.Contains("find") || match.Groups[1].Value.Contains("search"); bool validClaim = match.Groups[1].Value.Contains("claim"); if (!validFind || !validClaim) { return; } bool validView = match.Groups[1].Value.Contains("view"); bool validAll = match.Groups[1].Value.Contains("all"); string[] queries = match.Groups[2].Value.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries); int counter = 0; foreach (string query in queries) { if (counter == 2) { return; } string trimmed = query.Trim(); IEnumerable <string> modules = ComponentHandles.Where(handle => handle.HeaderText.ContainsIgnoreCase(trimmed) && GameRoom.Instance.IsCurrentBomb(handle.bombID) && !handle.Solved && !handle.Claimed) .OrderByDescending(handle => handle.HeaderText.EqualsIgnoreCase(trimmed)).Select(handle => $"{handle.Code}").ToList(); if (modules.Any()) { if (!validAll) { modules = modules.Take(1); } foreach (string module in modules) { TwitchComponentHandle handle = ComponentHandles.FirstOrDefault(x => x.Code.Equals(module)); if (handle == null || !GameRoom.Instance.IsCurrentBomb(handle.bombID)) { continue; } handle.AddToClaimQueue(userNickName, validView); } if (validAll) { counter++; } } else { IRCConnection.Instance.SendMessage($"Couldn't find any modules containing \"{trimmed}\"."); } } return; } if (text.Equals("newbomb", StringComparison.InvariantCultureIgnoreCase) && OtherModes.ZenModeOn) { TwitchPlaySettings.SetRewardBonus(0); foreach (var handle in ComponentHandles.Where(x => GameRoom.Instance.IsCurrentBomb(x.bombID))) { if (!handle.Solved) { handle.SolveSilently(); } } return; } } if (text.RegexMatch(out match, "^notes(-?[0-9]+)$") && int.TryParse(match.Groups[1].Value, out index)) { if (!_notesDictionary.ContainsKey(index - 1)) { _notesDictionary[index - 1] = TwitchPlaySettings.data.NotesSpaceFree; } IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.Notes, index, _notesDictionary[index - 1]); return; } switch (UserAccess.HighestAccessLevel(userNickName)) { case AccessLevel.Streamer: case AccessLevel.SuperUser: if (text.RegexMatch(out match, @"^setmultiplier ([0-9]+(?:\.[0-9]+)*)$")) { OtherModes.SetMultiplier(float.Parse(match.Groups[1].Value)); return; } if (text.Equals("solvebomb", StringComparison.InvariantCultureIgnoreCase)) { foreach (var handle in ComponentHandles.Where(x => GameRoom.Instance.IsCurrentBomb(x.bombID))) { if (!handle.Solved) { handle.SolveSilently(); } } return; } goto case AccessLevel.Admin; case AccessLevel.Admin: if (text.Equals("enablecamerawall", StringComparison.InvariantCultureIgnoreCase) || text.Equals("enablemodulewall", StringComparison.InvariantCultureIgnoreCase)) { moduleCameras.EnableWallOfCameras(); StartCoroutine(HideBombs()); } if (text.Equals("disablecamerawall", StringComparison.InvariantCultureIgnoreCase) || text.Equals("disablemodulewall", StringComparison.InvariantCultureIgnoreCase)) { moduleCameras.DisableWallOfCameras(); _hideBombs = false; } goto case AccessLevel.Mod; case AccessLevel.Mod: if (text.RegexMatch(out match, @"^assign (\S+) (.+)")) { var split = match.Groups[2].Value.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var assign in split) { TwitchComponentHandle handle = ComponentHandles.FirstOrDefault(x => x.Code.Equals(assign)); if (handle == null || !GameRoom.Instance.IsCurrentBomb(handle.bombID)) { continue; } handle.OnMessageReceived(userNickName, userColorCode, string.Format("assign {0}", match.Groups[1].Value)); } return; } if (text.RegexMatch("^bot ?unclaim( ?all)?$")) { userNickName = IRCConnection.Instance.UserNickName; foreach (TwitchComponentHandle handle in ComponentHandles) { handle.RemoveFromClaimQueue(userNickName); } string[] moduleIDs = ComponentHandles.Where(x => !x.Solved && x.PlayerName != null && x.PlayerName.Equals(userNickName, StringComparison.InvariantCultureIgnoreCase)) .Select(x => x.Code).ToArray(); foreach (var claim in moduleIDs) { TwitchComponentHandle handle = ComponentHandles.FirstOrDefault(x => x.Code.Equals(claim)); if (handle == null || !GameRoom.Instance.IsCurrentBomb(handle.bombID)) { continue; } handle.OnMessageReceived(userNickName, userColorCode, "unclaim"); } return; } if (text.Equals("filledgework", StringComparison.InvariantCultureIgnoreCase)) { foreach (var commander in BombCommanders) { commander.FillEdgework(_currentBomb != commander.twitchBombHandle.bombID); } return; } break; } GameRoom.Instance.RefreshBombID(ref _currentBomb); if (_currentBomb > -1) { //Check for !bomb messages, and pass them off to the currently held bomb. if (text.RegexMatch(out match, "^bomb (.+)")) { string internalCommand = match.Groups[1].Value; text = string.Format("bomb{0} {1}", _currentBomb + 1, internalCommand); } if (text.RegexMatch(out match, "^edgework$")) { text = string.Format("edgework{0}", _currentBomb + 1); } else { if (text.RegexMatch(out match, "^edgework (.+)")) { string internalCommand = match.Groups[1].Value; text = string.Format("edgework{0} {1}", _currentBomb + 1, internalCommand); } } } foreach (TwitchBombHandle handle in BombHandles) { if (handle == null) { continue; } IEnumerator onMessageReceived = handle.OnMessageReceived(userNickName, userColorCode, text); if (onMessageReceived == null) { continue; } if (_currentBomb != handle.bombID) { if (!GameRoom.Instance.IsCurrentBomb(handle.bombID)) { continue; } _coroutineQueue.AddToQueue(BombHandles[_currentBomb].HideMainUIWindow(), handle.bombID); _coroutineQueue.AddToQueue(handle.ShowMainUIWindow(), handle.bombID); _coroutineQueue.AddToQueue(BombCommanders[_currentBomb].LetGoBomb(), handle.bombID); _currentBomb = handle.bombID; } _coroutineQueue.AddToQueue(onMessageReceived, handle.bombID); } foreach (TwitchComponentHandle componentHandle in ComponentHandles) { if (!GameRoom.Instance.IsCurrentBomb(componentHandle.bombID)) { continue; } if (!text.StartsWith(componentHandle.Code + " ")) { continue; } IEnumerator onMessageReceived = componentHandle.OnMessageReceived(userNickName, userColorCode, text.Substring(componentHandle.Code.Length + 1)); if (onMessageReceived == null) { continue; } if (_currentBomb != componentHandle.bombID) { _coroutineQueue.AddToQueue(BombHandles[_currentBomb].HideMainUIWindow(), componentHandle.bombID); _coroutineQueue.AddToQueue(BombHandles[componentHandle.bombID].ShowMainUIWindow(), componentHandle.bombID); _coroutineQueue.AddToQueue(BombCommanders[_currentBomb].LetGoBomb(), componentHandle.bombID); _currentBomb = componentHandle.bombID; } _coroutineQueue.AddToQueue(onMessageReceived, componentHandle.bombID); } if (TwitchPlaySettings.data.BombCustomMessages.ContainsKey(text.ToLowerInvariant())) { IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.BombCustomMessages[text.ToLowerInvariant()]); } }