private void AwardStrikes(string userNickName, int strikeCount) { BombCommander BombCommander = BombMessageResponder.Instance.BombCommanders[0]; int strikePenalty = -5; strikePenalty = TwitchPlaySettings.data.EnableRewardMultipleStrikes ? (strikeCount * strikePenalty) : (Math.Min(strikePenalty, strikeCount * strikePenalty)); IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.AwardHoldableStrike, HoldableCommander.ID, strikeCount == 1 ? "a" : strikeCount.ToString(), strikeCount == 1 ? "" : "s", strikePenalty, userNickName, string.IsNullOrEmpty(StrikeMessage) ? "" : " caused by " + StrikeMessage); if (strikeCount <= 0) { return; } string RecordMessageTone = $"Holdable ID: {HoldableCommander.ID} | Player: {userNickName} | Strike"; TwitchPlaySettings.AppendToSolveStrikeLog(RecordMessageTone, TwitchPlaySettings.data.EnableRewardMultipleStrikes ? strikeCount : 1); int originalReward = TwitchPlaySettings.GetRewardBonus(); int currentReward = Convert.ToInt32(originalReward * TwitchPlaySettings.data.AwardDropMultiplierOnStrike); TwitchPlaySettings.SetRewardBonus(currentReward); if (currentReward != originalReward) { IRCConnection.Instance.SendMessage($"Reward {(currentReward > 0 ? "reduced" : "increased")} to {currentReward} points."); } if (OtherModes.TimeModeOn) { bool multiDropped = OtherModes.DropMultiplier(); float multiplier = OtherModes.GetMultiplier(); string tempMessage; if (multiDropped) { tempMessage = "Multiplier reduced to " + Math.Round(multiplier, 1) + " and time"; } else { tempMessage = $"Multiplier set at {TwitchPlaySettings.data.TimeModeMinMultiplier}, cannot be further reduced. Time"; } if (BombCommander.CurrentTimer < (TwitchPlaySettings.data.TimeModeMinimumTimeLost / TwitchPlaySettings.data.TimeModeTimerStrikePenalty)) { BombCommander.timerComponent.TimeRemaining = BombCommander.CurrentTimer - TwitchPlaySettings.data.TimeModeMinimumTimeLost; tempMessage = tempMessage + $" reduced by {TwitchPlaySettings.data.TimeModeMinimumTimeLost} seconds."; } else { float timeReducer = BombCommander.CurrentTimer * TwitchPlaySettings.data.TimeModeTimerStrikePenalty; double easyText = Math.Round(timeReducer, 1); BombCommander.timerComponent.TimeRemaining = BombCommander.CurrentTimer - timeReducer; tempMessage = tempMessage + $" reduced by {Math.Round(TwitchPlaySettings.data.TimeModeTimerStrikePenalty * 100, 1)}%. ({easyText} seconds)"; } IRCConnection.Instance.SendMessage(tempMessage); BombCommander.StrikeCount = 0; BombMessageResponder.moduleCameras?.UpdateStrikes(); } Leaderboard.Instance?.AddScore(userNickName, strikePenalty); Leaderboard.Instance?.AddStrike(userNickName, strikeCount); StrikeMessage = string.Empty; }
public TwitchPlaysProperties() { AddProperty("TimeMode", new Property(() => OtherModes.TimeModeOn, x => OtherModes.TimeModeOn = (bool)x)); AddProperty("ZenMode", new Property(() => OtherModes.ZenModeOn, x => OtherModes.ZenModeOn = (bool)x)); AddProperty("TimeModeTimeLimit", new Property(() => TwitchPlaySettings.data.TimeModeStartingTime, SetTimeModeTimeLimit)); AddProperty("ircConnectionSendMessage", new Property(null, x => IRCConnection.Instance.SendMessage((string)x))); AddProperty("Reward", new Property(() => TwitchPlaySettings.GetRewardBonus(), x => TwitchPlaySettings.SetRewardBonus((int)x))); AddProperty("CauseFakeStrike", new Property(null, CauseFakeStrike)); }
private void AwardStrikes(string userNickName, ICommandResponseNotifier responseNotifier, int strikeCount) { string headerText = BombComponent.GetModuleDisplayName(); int strikePenalty = modInfo.strikePenalty * (TwitchPlaySettings.data.EnableRewardMultipleStrikes ? strikeCount : 1); IRCConnection.SendMessage(TwitchPlaySettings.data.AwardStrike, Code, strikeCount == 1 ? "a" : strikeCount.ToString(), strikeCount == 1 ? "" : "s", 0, userNickName, string.IsNullOrEmpty(StrikeMessage) ? "" : " caused by " + StrikeMessage, headerText, strikePenalty); if (strikeCount <= 0) { return; } string RecordMessageTone = $"Module ID: {Code} | Player: {userNickName} | Module Name: {headerText} | Strike"; TwitchPlaySettings.AppendToSolveStrikeLog(RecordMessageTone, TwitchPlaySettings.data.EnableRewardMultipleStrikes ? strikeCount : 1); int currentReward = TwitchPlaySettings.GetRewardBonus(); currentReward = Convert.ToInt32(currentReward * .80); TwitchPlaySettings.SetRewardBonus(currentReward); IRCConnection.SendMessage("Reward reduced to " + currentReward + " points."); if (OtherModes.timedModeOn) { bool multiDropped = OtherModes.dropMultiplier(); float multiplier = OtherModes.getMultiplier(); string tempMessage; if (multiDropped) { tempMessage = "Multiplier reduced to " + Math.Round(multiplier, 1) + " and time"; } else { tempMessage = "Mutliplier set at 1, cannot be further reduced. Time"; } if (BombCommander.CurrentTimer < 60) { BombCommander.timerComponent.TimeRemaining = BombCommander.CurrentTimer - 15; tempMessage = tempMessage + " reduced by 15 seconds."; } else { float timeReducer = BombCommander.CurrentTimer * .25f; double easyText = Math.Round(timeReducer, 1); BombCommander.timerComponent.TimeRemaining = BombCommander.CurrentTimer - timeReducer; tempMessage = tempMessage + " reduced by 25%. (" + easyText + " seconds)"; } IRCConnection.SendMessage(tempMessage); } if (responseNotifier != null) { responseNotifier.ProcessResponse(CommandResponse.EndErrorSubtractScore, strikePenalty); responseNotifier.ProcessResponse(CommandResponse.EndError, strikeCount); } else { ComponentHandle.leaderboard.AddScore(userNickName, strikePenalty); ComponentHandle.leaderboard.AddStrike(userNickName, strikeCount); } if (OtherModes.timedModeOn) { BombCommander.StrikeCount = 0; BombMessageResponder.moduleCameras.UpdateStrikes(); } StrikeMessage = string.Empty; }
private void AwardStrikes(string userNickName, int strikeCount) { string headerText = UnsupportedModule ? modInfo.moduleDisplayName : BombComponent.GetModuleDisplayName(); int strikePenalty = modInfo.strikePenalty * (TwitchPlaySettings.data.EnableRewardMultipleStrikes ? strikeCount : 1); if (OtherModes.ZenModeOn) { strikePenalty = (int)(strikePenalty * 0.20f); } IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.AwardStrike, Code, strikeCount == 1 ? "a" : strikeCount.ToString(), strikeCount == 1 ? "" : "s", 0, userNickName, string.IsNullOrEmpty(StrikeMessage) ? "" : " caused by " + StrikeMessage, headerText, strikePenalty); if (strikeCount <= 0) { return; } string RecordMessageTone = $"Module ID: {Code} | Player: {userNickName} | Module Name: {headerText} | Strike"; TwitchPlaySettings.AppendToSolveStrikeLog(RecordMessageTone, TwitchPlaySettings.data.EnableRewardMultipleStrikes ? strikeCount : 1); int originalReward = TwitchPlaySettings.GetRewardBonus(); int currentReward = Convert.ToInt32(originalReward * TwitchPlaySettings.data.AwardDropMultiplierOnStrike); TwitchPlaySettings.SetRewardBonus(currentReward); if (currentReward != originalReward) { IRCConnection.Instance.SendMessage($"Reward {(currentReward > 0 ? "reduced" : "increased")} to {currentReward} points."); } if (OtherModes.TimeModeOn) { float originalMultiplier = OtherModes.GetAdjustedMultiplier(); bool multiDropped = OtherModes.DropMultiplier(); float multiplier = OtherModes.GetAdjustedMultiplier(); string tempMessage; if (multiDropped) { if (Mathf.Abs(originalMultiplier - multiplier) >= 0.1) { tempMessage = "Multiplier reduced to " + Math.Round(multiplier, 1) + " and time"; } else { tempMessage = "Time"; } } else { tempMessage = $"Multiplier set at {TwitchPlaySettings.data.TimeModeMinMultiplier}, cannot be further reduced. Time"; } if (BombCommander.CurrentTimer < (TwitchPlaySettings.data.TimeModeMinimumTimeLost / TwitchPlaySettings.data.TimeModeTimerStrikePenalty)) { BombCommander.timerComponent.TimeRemaining = BombCommander.CurrentTimer - TwitchPlaySettings.data.TimeModeMinimumTimeLost; tempMessage = tempMessage + $" reduced by {TwitchPlaySettings.data.TimeModeMinimumTimeLost} seconds."; } else { float timeReducer = BombCommander.CurrentTimer * TwitchPlaySettings.data.TimeModeTimerStrikePenalty; double easyText = Math.Round(timeReducer, 1); BombCommander.timerComponent.TimeRemaining = BombCommander.CurrentTimer - timeReducer; tempMessage = tempMessage + $" reduced by {Math.Round(TwitchPlaySettings.data.TimeModeTimerStrikePenalty * 100, 1)}%. ({easyText} seconds)"; } IRCConnection.Instance.SendMessage(tempMessage); BombCommander.StrikeCount = 0; BombMessageResponder.moduleCameras.UpdateStrikes(); } if (OtherModes.ZenModeOn) { BombCommander.StrikeLimit += strikeCount; } Leaderboard.Instance.AddScore(userNickName, strikePenalty); Leaderboard.Instance.AddStrike(userNickName, strikeCount); StrikeMessage = string.Empty; }
protected override void OnMessageReceived(string userNickName, string userColorCode, string text) { if (!text.StartsWith("!") || text.Equals("!")) { return; } text = text.Substring(1); string[] split = text.ToLowerInvariant().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string textAfter = split.Skip(1).Join(); if (text.Equals("cancel", StringComparison.InvariantCultureIgnoreCase)) { if (!IsAuthorizedDefuser(userNickName)) { return; } _coroutineCanceller.SetCancel(); return; } else if (text.Equals("stop", StringComparison.InvariantCultureIgnoreCase)) { if (!IsAuthorizedDefuser(userNickName)) { return; } _coroutineCanceller.SetCancel(); _coroutineQueue.CancelFutureSubcoroutines(); return; } else if (text.Equals("manual", StringComparison.InvariantCultureIgnoreCase) || text.Equals("help", StringComparison.InvariantCultureIgnoreCase)) { _ircConnection.SendMessage("!{0} manual [link to module {0}'s manual] | Go to {1} to get the vanilla manual for KTaNE", UnityEngine.Random.Range(1, 100), TwitchPlaysService.urlHelper.VanillaManual); _ircConnection.SendMessage("!{0} help [commands for module {0}] | Go to {1} to get the command reference for TP:KTaNE (multiple pages, see the menu on the right)", UnityEngine.Random.Range(1, 100), TwitchPlaysService.urlHelper.CommandReference); return; } else if (text.StartsWith("bonusscore", StringComparison.InvariantCultureIgnoreCase)) { if (!IsAuthorizedDefuser(userNickName)) { return; } if (split.Length < 3) { return; } string playerrewarded = split[1]; if (!int.TryParse(split[2], out int scorerewarded)) { return; } if (UserAccess.HasAccess(userNickName, AccessLevel.SuperUser, true)) { _ircConnection.SendMessage(TwitchPlaySettings.data.GiveBonusPoints, split[1], split[2], userNickName); Color usedColor = new Color(.31f, .31f, .31f); leaderboard.AddScore(playerrewarded, usedColor, scorerewarded); } return; } else if (text.StartsWith("reward", StringComparison.InvariantCultureIgnoreCase)) { if (!IsAuthorizedDefuser(userNickName)) { return; } if (UserAccess.HasAccess(userNickName, AccessLevel.SuperUser, true)) { moduleCountBonus = Int32.Parse(split[1]); TwitchPlaySettings.SetRewardBonus(moduleCountBonus); } } else if (text.Equals("timemode", StringComparison.InvariantCultureIgnoreCase)) { if (UserAccess.HasAccess(userNickName, AccessLevel.Mod, true)) { OtherModes.toggleTimedMode(); _ircConnection.SendMessage(OtherModes.timedModeCheck() ? "Time Mode Enabled" : "Time Mode Disabled"); } } else if (text.StartsWith("rank", StringComparison.InvariantCultureIgnoreCase)) { Leaderboard.LeaderboardEntry entry = null; if (split.Length > 1) { int desiredRank; switch (split.Length) { case 3 when split[1].Equals("solo", StringComparison.InvariantCultureIgnoreCase) && int.TryParse(split[2], out desiredRank):
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()]); } }
public override IEnumerator ReportBombStatus() { if (_gameroom.GetType() == _factoryStaticModeType) { IEnumerator baseIEnumerator = base.ReportBombStatus(); while (baseIEnumerator.MoveNext()) { yield return(baseIEnumerator.Current); } yield break; } InitializeOnLightsOn = false; TwitchBombHandle bombHandle = BombMessageResponder.Instance.BombHandles[0]; bombHandle.nameText.text = _infiniteMode ? "Infinite bombs incoming" : $"{BombCount} bombs incoming"; yield return(new WaitUntil(() => GetBomb != null || bombHandle.bombCommander.Bomb.HasDetonated)); if (bombHandle.bombCommander.Bomb.HasDetonated && !_zenMode) { yield break; } float currentBombTimer = bombHandle.bombCommander.timerComponent.TimeRemaining + 5; int currentBombID = 1; while (GetBomb != null) { int reward = TwitchPlaySettings.GetRewardBonus(); UnityEngine.Object currentBomb = GetBomb; TimerComponent timerComponent = bombHandle.bombCommander.timerComponent; yield return(new WaitUntil(() => timerComponent.IsActive)); if (Math.Abs(currentBombTimer - bombHandle.bombCommander.timerComponent.TimeRemaining) > 1f) { yield return(null); InitializeGameModes(true); } bombHandle.nameText.text = $"Bomb {currentBombID} of {(_infiniteMode ? "∞" : BombCount.ToString())}"; IRCConnection.Instance.SendMessage("Bomb {0} of {1} is now live.", currentBombID++, _infiniteMode ? "∞" : BombCount.ToString()); if (OtherModes.ZenModeOn && IRCConnection.Instance.State == IRCConnectionState.Connected && TwitchPlaySettings.data.EnableFactoryZenModeCameraWall) { BombMessageResponder.Instance.OnMessageReceived("Bomb Factory", "!enablecamerawall"); BombMessageResponder.Instance.OnMessageReceived("Bomb Factory", "!modules"); BombMessageResponder.Instance.OnMessageReceived("Bomb Factory", "!modules"); } else { BombMessageResponder.Instance.OnMessageReceived("Bomb Factory", "!disablecamerawall"); } if (TwitchPlaySettings.data.EnableAutomaticEdgework) { bombHandle.bombCommander.FillEdgework(); } else { bombHandle.edgeworkText.text = TwitchPlaySettings.data.BlankBombEdgework; } if (OtherModes.ZenModeOn) { bombHandle.bombCommander.StrikeLimit += bombHandle.bombCommander.StrikeCount; } IEnumerator bombHold = bombHandle.OnMessageReceived("Bomb Factory", "red", "bomb hold"); while (bombHold.MoveNext()) { yield return(bombHold.Current); } Bomb bomb1 = (Bomb)_internalBombProperty.GetValue(currentBomb, null); yield return(new WaitUntil(() => { bool result = bomb1.HasDetonated || bomb1.IsSolved() || !BombMessageResponder.BombActive; if (!result || OtherModes.TimeModeOn) { currentBombTimer = bomb1.GetTimer().TimeRemaining; } return result; })); if (!BombMessageResponder.BombActive) { yield break; } IRCConnection.Instance.SendMessage(BombMessageResponder.Instance.GetBombResult(false)); TwitchPlaySettings.SetRewardBonus(reward); foreach (TwitchComponentHandle handle in BombMessageResponder.Instance.ComponentHandles) { //If the camera is still attached to the bomb component when the bomb gets destroyed, then THAT camera is destroyed as wel. BombMessageResponder.moduleCameras.DetachFromModule(handle.bombComponent); } if (TwitchPlaySettings.data.EnableFactoryAutomaticNextBomb) { bombHold = bombHandle.OnMessageReceived("Bomb Factory", "red", "bomb drop"); while (bombHold.MoveNext()) { yield return(bombHold.Current); } } while (currentBomb == GetBomb) { yield return(new WaitForSeconds(0.10f)); if (currentBomb != GetBomb || !TwitchPlaySettings.data.EnableFactoryAutomaticNextBomb) { continue; } bombHold = bombHandle.OnMessageReceived("Bomb Factory", "red", "bomb hold"); while (bombHold.MoveNext()) { yield return(bombHold.Current); } yield return(new WaitForSeconds(0.10f)); bombHold = bombHandle.OnMessageReceived("Bomb Factory", "red", "bomb drop"); while (bombHold.MoveNext()) { yield return(bombHold.Current); } } bombHandle.StartCoroutine(DestroyBomb(currentBomb)); if (GetBomb == null) { continue; } Bomb bomb = (Bomb)_internalBombProperty.GetValue(GetBomb, null); InitializeBomb(bomb); } }