public override void use(ClientPlayerInfo p, string message) { LevelPlaylist playlist = new LevelPlaylist(); playlist.CopyFrom(G.Sys.GameManager_.LevelPlaylist_); if (G.Sys.GameManager_.ModeID_ == GameModeID.Trackmogrify) { MessageUtilities.sendMessage(p, "You can't manage the playlist in trackmogrify"); return; } if (playlist.Count_ == 0) { MessageUtilities.sendMessage(p, "The playlist is empty !"); return; } if (GeneralUtilities.isOnGamemode()) { shuffleOnGame(playlist); } else { shuffleOnLobby(playlist); } G.Sys.GameManager_.LevelPlaylist_.SetIndex(0); G.Sys.GameManager_.NextLevelName_ = G.Sys.GameManager_.LevelPlaylist_.Playlist_[0].levelNameAndPath_.levelName_; G.Sys.GameManager_.NextLevelPath_ = G.Sys.GameManager_.LevelPlaylist_.Playlist_[0].levelNameAndPath_.levelPath_; MessageUtilities.sendMessage(p, "Playlist shuffled !"); }
public override void use(ClientPlayerInfo p, string message) { LevelPlaylist playlist = new LevelPlaylist(); playlist.CopyFrom(G.Sys.GameManager_.LevelPlaylist_); if (G.Sys.GameManager_.ModeID_ == GameModeID.Trackmogrify) { MessageUtilities.sendMessage(p, "You can't manage the playlist in trackmogrify"); return; } if (playlist.Count_ == 0) { MessageUtilities.sendMessage(p, "The playlist is empty !"); return; } var item = playlist.Playlist_[G.Sys.GameManager_.LevelPlaylist_.Index_]; playlist.Playlist_.Clear(); G.Sys.GameManager_.LevelPlaylist_.Clear(); G.Sys.GameManager_.LevelPlaylist_.Add(item); G.Sys.GameManager_.NextLevelName_ = item.levelNameAndPath_.levelName_; G.Sys.GameManager_.NextLevelPath_ = item.levelNameAndPath_.levelPath_; G.Sys.GameManager_.LevelPlaylist_.SetIndex(0); MessageUtilities.sendMessage(p, "Playlist cleared !"); }
public override void use(ClientPlayerInfo p, string message) { if (message == "") { help(p); return; } if (G.Sys.GameManager_.ModeID_ == GameModeID.Trackmogrify) { MessageUtilities.sendMessage(p, "You can't manage the playlist in trackmogrify"); return; } int id = 0; int.TryParse(message, out id); if (id < 0) { MessageUtilities.sendMessage(p, "The id must be >= 0"); return; } int index = G.Sys.GameManager_.LevelPlaylist_.Index_; int playListSize = G.Sys.GameManager_.LevelPlaylist_.Playlist_.Count - index - 1; if (id >= playListSize) { MessageUtilities.sendMessage(p, "The playlist has only " + playListSize + " maps."); return; } LevelPlaylist playlist = new LevelPlaylist(); playlist.CopyFrom(G.Sys.GameManager_.LevelPlaylist_); var currentPlaylist = playlist.Playlist_; currentPlaylist.RemoveAt(index + id + 1); G.Sys.GameManager_.LevelPlaylist_.Clear(); foreach (var lvl in currentPlaylist) { G.Sys.GameManager_.LevelPlaylist_.Add(lvl); } G.Sys.GameManager_.LevelPlaylist_.SetIndex(index); MessageUtilities.sendMessage(p, "Map removed !"); }
public override void use(ClientPlayerInfo p, string message) { if (message == "") { help(p); return; } if (useVote && !p.IsLocal_) // host can always force play, never uses vote. { Cmd.all.getCommand <VoteHandler.VoteCMD>("vote").forceNextUse(); Cmd.all.getCommand <VoteHandler.VoteCMD>("vote").use(p, "y play " + message); return; } if (G.Sys.GameManager_.ModeID_ == GameModeID.Trackmogrify) { MessageUtilities.sendMessage(p, "You can't manage the playlist in trackmogrify."); return; } FilteredPlaylist filterer = new FilteredPlaylist(GeneralUtilities.getAllLevelsAndModes()); if (!p.IsLocal_) { filterer.AddFiltersFromString(playFilter); } MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(p)); GeneralUtilities.sendFailures(GeneralUtilities.addFiltersToPlaylist(filterer, p, message, true), 4); MessageUtilities.popMessageOptions(); var list = filterer.Calculate().levelList; if (list.Count == 0) { MessageUtilities.sendMessage(p, "Can't find a level with the filter '" + message + "'."); return; } LevelPlaylist playlist = new LevelPlaylist(); playlist.CopyFrom(G.Sys.GameManager_.LevelPlaylist_); var currentPlaylist = playlist.Playlist_; AutoCmd autoCmd = Cmd.all.getCommand <AutoCmd>("auto"); int origIndex = G.Sys.GameManager_.LevelPlaylist_.Index_; int index = autoCmd.getInsertIndex(); var maxPerRoundLocal = 0; if (p.IsLocal_ || maxPerRound <= 0) { maxPerRoundLocal = int.MaxValue; } else { maxPerRoundLocal = maxPerRound; } var maxPerCmdLocal = 0; if (p.IsLocal_ || maxPerCmd <= 0) { maxPerCmdLocal = int.MaxValue; } else { maxPerCmdLocal = maxPerCmd; } var countCmd = 0; var countRound = 0; playerVotesThisRound.TryGetValue(GeneralUtilities.getUniquePlayerString(p), out countRound); string lvlsStr = ""; foreach (var lvl in list) { if (countRound + 1 > maxPerRoundLocal) { MessageUtilities.sendMessage(p, $"You have reached the maximum amount of maps you can add per round ({maxPerRound})"); break; } if (countCmd + 1 > maxPerCmdLocal) { MessageUtilities.sendMessage(p, "You have reached the maximum amount of maps you can add per " + GeneralUtilities.formatCmd("!play") + $" ({maxPerCmd})"); break; } countRound++; countCmd++; if (countCmd <= 10) { lvlsStr += lvl.levelNameAndPath_.levelName_ + ", "; } currentPlaylist.Insert(index + countCmd - 1, lvl); } playerVotesThisRound[GeneralUtilities.getUniquePlayerString(p)] = countRound; if (countCmd > 0) { G.Sys.GameManager_.LevelPlaylist_.Clear(); foreach (var lvl in currentPlaylist) { G.Sys.GameManager_.LevelPlaylist_.Add(lvl); } G.Sys.GameManager_.LevelPlaylist_.SetIndex(origIndex); lvlsStr = lvlsStr.Substring(0, lvlsStr.Count() - 2); if (countCmd > 10) { lvlsStr = lvlsStr + $" and {countCmd - 10} more"; } if (p.IsLocal_) { MessageUtilities.sendMessage(p, "Level(s) " + lvlsStr + " added to the playlist !"); } else { MessageUtilities.sendMessage("Level(s) " + lvlsStr + " added to the playlist by " + p.GetChatName() + "!"); } } }
public override void use(ClientPlayerInfo p, string message) { if (message == "") { help(p); return; } if (G.Sys.GameManager_.ModeID_ == GameModeID.Trackmogrify) { MessageUtilities.sendMessage(p, "You can't manage the playlist in trackmogrify"); return; } Match match = Regex.Match(message, cmdPattern); if (!match.Success) { help(p); MessageUtilities.sendMessage(p, "For example, !dels 0 5"); } string id1s = match.Groups[1].Value; string id2s = match.Groups[2].Value; Console.WriteLine($"{id1s}"); Console.WriteLine($"{id2s}"); int id1 = 0; int id2 = 0; int.TryParse(id1s, out id1); int.TryParse(id2s, out id2); if (id1 < 0 || id2 < 0) { MessageUtilities.sendMessage(p, "The indices must be positive numbers or 0."); return; } else if (id1 > id2) { MessageUtilities.sendMessage(p, "indexStart must be <= indexEnd."); } int index = G.Sys.GameManager_.LevelPlaylist_.Index_; int playListSize = G.Sys.GameManager_.LevelPlaylist_.Playlist_.Count - index - 1; if (id2 >= playListSize) { MessageUtilities.sendMessage(p, "The playlist has only " + playListSize + " maps."); return; } LevelPlaylist playlist = new LevelPlaylist(); playlist.CopyFrom(G.Sys.GameManager_.LevelPlaylist_); var currentPlaylist = playlist.Playlist_; for (int id = id1; id <= id2; id++) { currentPlaylist.RemoveAt(index + id1 + 1); } G.Sys.GameManager_.LevelPlaylist_.Clear(); foreach (var lvl in currentPlaylist) { G.Sys.GameManager_.LevelPlaylist_.Add(lvl); } G.Sys.GameManager_.LevelPlaylist_.SetIndex(index); MessageUtilities.sendMessage(p, $"{id2 - id1 + 1} maps removed !"); }
public bool savePlaylist(LevelPlaylist selectedPlaylist, string name) { // playlists are attached to game objects // when a new level loads, all existing game objects are destroyed so we cannot properly save them // instead, we make a new one and copy the old playlist into the new object. LevelPlaylist list = LevelPlaylist.Create(true); list.CopyFrom(selectedPlaylist); list.IsCustom_ = true; selectedPlaylist = list; switch (name) { case "current": { if (canUseCurrentPlaylist) { G.Sys.GameManager_.LevelPlaylist_.CopyFrom(selectedPlaylist); G.Sys.GameManager_.LevelPlaylist_.SetIndex(0); GeneralUtilities.updateGameManagerCurrentLevel(); StaticTargetedEvent <Events.ServerToClient.SetLevelName.Data> .Broadcast(RPCMode.All, G.Sys.GameManager_.CreateSetLevelNameEventData()); return(true); } else { return(false); } } case "upcoming": { if (canUseCurrentPlaylist) { var currentPlaylist = G.Sys.GameManager_.LevelPlaylist_; if (currentPlaylist.Count_ > currentPlaylist.Index_ + 1) { currentPlaylist.Playlist_.RemoveRange(currentPlaylist.Index_ + 1, currentPlaylist.Count_ - currentPlaylist.Index_ - 1); } foreach (LevelPlaylist.ModeAndLevelInfo level in selectedPlaylist.Playlist_) { currentPlaylist.Add(level); } currentPlaylist.IsCustom_ = true; GeneralUtilities.updateGameManagerCurrentLevel(); StaticTargetedEvent <Events.ServerToClient.SetLevelName.Data> .Broadcast(RPCMode.All, G.Sys.GameManager_.CreateSetLevelNameEventData()); return(true); } else { return(false); } } case "active": { return(true); } default: { selectedPlaylist.Name_ = name; selectedPlaylist.Save(); return(true); } } }
public override void use(ClientPlayerInfo p, string message) { if (!doForceNextUse) { if (!votesAllowed) { MessageUtilities.sendMessage(p, "Votes are disabled."); return; } } else { doForceNextUse = false; } bool voteValue; bool isInfo; string voteType; string parameter; var matchShortcut = Regex.Match(message, parent.voteCmdShortcutPattern); var shortcutVoteType = matchShortcut.Groups[1].Value.ToLower(); if (matchShortcut.Success && voteThresholds.ContainsKey(shortcutVoteType)) { voteValue = true; isInfo = false; voteType = shortcutVoteType; parameter = matchShortcut.Groups[2].Value; } else { var match = Regex.Match(message, parent.voteCmdPattern); if (!match.Success) { help(p); return; } string voteValueS = match.Groups[1].Value.ToLower(); voteValue = false; isInfo = false; if (voteValueS == "yes" || voteValueS == "y" || voteValueS == "1" || voteValueS == "true" || voteValueS == "t") { voteValue = true; } else if (voteValueS == "no" || voteValueS == "n" || voteValueS == "0" || voteValueS == "false" || voteValueS == "f") { voteValue = false; } else if (voteValueS == "info" || voteValueS == "i") { isInfo = true; } else { MessageUtilities.sendMessage(p, "Invalid <voteType>, or invalid [yes/no] You can use yes/no, y/n, 1/0, true/false, and t/f."); MessageUtilities.sendMessage(p, "You can use [info/i] to get info."); MessageUtilities.sendMessage(p, "<voteType>s: skip, stop, play"); return; } voteType = match.Groups[2].Value.ToLower(); parameter = match.Groups[3].Value; } if (!voteThresholds.ContainsKey(voteType)) { MessageUtilities.sendMessage(p, $"Invalid <voteType>. ({voteType})"); help(p); return; } AutoCmd autoCommand = parent.list.getCommand <AutoCmd>("auto"); AutoSpecCmd autoSpecCommand = parent.list.getCommand <AutoSpecCmd>("autospec"); int playerOffset = (autoCommand.autoMode && autoSpecCommand.autoSpecMode) ? -1 : 0; int numPlayers = G.Sys.PlayerManager_.PlayerList_.Count + playerOffset; if (isInfo) { MessageUtilities.sendMessage(p, $"Info for {voteType}:"); MessageUtilities.sendMessage(p, $"Pass threshold: {Convert.ToInt32(Math.Floor(voteThresholds[voteType]*100))}%"); int value = parent.votes[voteType].Count; MessageUtilities.sendMessage(p, $"Votes: {value}/{Convert.ToInt32(Math.Ceiling(voteThresholds[voteType] * Convert.ToDouble(numPlayers)))}"); return; } if (voteType == "skip") { if (GeneralUtilities.isOnLobby()) { MessageUtilities.sendMessage(p, "You can't vote to skip in the lobby!"); return; } if (votedSkip) { MessageUtilities.sendMessage(p, "Vote skip already succeeded."); return; } List <string> votes = parent.votes[voteType]; int value = votes.Count; string playerVoteId = GeneralUtilities.getUniquePlayerString(p); if (voteValue) { if (votes.Contains(playerVoteId)) { MessageUtilities.sendMessage($"{p.Username_} has already voted to skip {G.Sys.GameManager_.LevelName_}."); return; } votes.Add(playerVoteId); value = votes.Count; MessageUtilities.sendMessage($"{p.Username_} voted to skip {G.Sys.GameManager_.LevelName_}."); if (Convert.ToDouble(value) / Convert.ToDouble(numPlayers) < voteThresholds[voteType]) { MessageUtilities.sendMessage($"Votes: {value}/{Convert.ToInt32(Math.Ceiling(voteThresholds[voteType] * Convert.ToDouble(numPlayers)))}"); } else { votedSkip = true; MessageUtilities.sendMessage("Vote skip succeeded! Skipping map..."); parent.advanceLevel(); } } else { votes.Remove(playerVoteId); value = votes.Count; MessageUtilities.sendMessage($"{p.Username_} unvoted to skip {G.Sys.GameManager_.LevelName_}."); MessageUtilities.sendMessage($"Votes: {value}/{Convert.ToInt32(Math.Ceiling(voteThresholds[voteType] * Convert.ToDouble(numPlayers)))}"); return; } } else if (voteType == "stop") { if (GeneralUtilities.isOnLobby()) { MessageUtilities.sendMessage(p, "You can't vote to stop the countdown in the lobby!"); return; } List <string> votes = parent.votes[voteType]; int value = votes.Count; string playerVoteId = GeneralUtilities.getUniquePlayerString(p); if (voteValue) { if (votes.Contains(playerVoteId)) { MessageUtilities.sendMessage($"{p.Username_} has already voted to stop the countdown."); return; } votes.Add(playerVoteId); value = votes.Count; MessageUtilities.sendMessage($"{p.Username_} voted to stop the countdown."); if (Convert.ToDouble(value) / Convert.ToDouble(numPlayers) < voteThresholds[voteType]) { MessageUtilities.sendMessage($"Votes: {value}/{Convert.ToInt32(Math.Ceiling(voteThresholds[voteType] * Convert.ToDouble(numPlayers)))}"); } else { parent.votes[voteType].Clear(); CountdownCmd command = parent.list.getCommand <CountdownCmd>("countdown"); command.stopCountdown(); MessageUtilities.sendMessage("Vote stop succeeded! Stopping countdown..."); } } else { votes.Remove(playerVoteId); value = votes.Count; MessageUtilities.sendMessage($"{p.Username_} unvoted to stop the countdown."); MessageUtilities.sendMessage($"Votes: {value}/{Convert.ToInt32(Math.Ceiling(voteThresholds[voteType] * Convert.ToDouble(numPlayers)))}"); return; } } else if (voteType == "play") { if (GeneralUtilities.isOnLobby()) { MessageUtilities.sendMessage(p, "You can't vote for the next level in the lobby."); return; } if (G.Sys.GameManager_.ModeID_ == GameModeID.Trackmogrify) { MessageUtilities.sendMessage(p, "You can't vote for levels in trackmogrify."); return; } string levelName = parameter; FilteredPlaylist filterer = new FilteredPlaylist(GeneralUtilities.getAllLevelsAndModes()); if (!p.IsLocal_) { PlayCmd playCmd = Cmd.all.getCommand <PlayCmd>("play"); filterer.AddFiltersFromString(playCmd.playFilter); } MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(p)); GeneralUtilities.sendFailures(GeneralUtilities.addFiltersToPlaylist(filterer, p, levelName, true), 4); MessageUtilities.popMessageOptions(); List <LevelPlaylist.ModeAndLevelInfo> lvls = filterer.Calculate().levelList; List <LevelResultsSortInfo> levelResults = new List <LevelResultsSortInfo>(); double threshold = voteThresholds["play"]; LevelPlaylist playlist = new LevelPlaylist(); playlist.CopyFrom(G.Sys.GameManager_.LevelPlaylist_); var currentPlaylist = playlist.Playlist_; AutoCmd autoCmd = Cmd.all.getCommand <AutoCmd>("auto"); int origIndex = G.Sys.GameManager_.LevelPlaylist_.Index_; int index = autoCmd.getInsertIndex(); int addCount = 0; foreach (LevelPlaylist.ModeAndLevelInfo lvl in lvls) { string id = $"{lvl.mode_}:{lvl.levelNameAndPath_.levelName_}:{lvl.levelNameAndPath_.levelPath_}"; List <string> votes; if (!parent.votes.TryGetValue(id, out votes)) { if (voteValue) { votes = new List <string>(); parent.votes[id] = votes; } else { //MessageUtilities.sendMessage($"{p.Username_} unvoted for these maps."); levelResults.Add(new LevelResultsSortInfo(lvl, 0, numPlayers, threshold, -1)); continue; } } string playerVoteId = GeneralUtilities.getUniquePlayerString(p); if (!voteValue) { votes.Remove(playerVoteId); if (votes.Count == 0) { parent.votes.Remove(id); } //MessageUtilities.sendMessage($"{p.Username_} unvoted for these maps."); levelResults.Add(new LevelResultsSortInfo(lvl, votes.Count, numPlayers, threshold, -1)); continue; } else { if (votes.Contains(playerVoteId)) { //MessageUtilities.sendMessage($"{p.Username_} has already voted for these maps."); levelResults.Add(new LevelResultsSortInfo(lvl, votes.Count, numPlayers, threshold, 0)); //return; continue; } else { votes.Add(playerVoteId); levelResults.Add(new LevelResultsSortInfo(lvl, votes.Count, numPlayers, threshold, 1)); if (Convert.ToDouble(votes.Count) / Convert.ToDouble(numPlayers) >= threshold) { currentPlaylist.Insert(index + addCount, lvl); parent.votes.Remove(id); addCount++; } } } } G.Sys.GameManager_.LevelPlaylist_.Clear(); foreach (var lvl in currentPlaylist) { G.Sys.GameManager_.LevelPlaylist_.Add(lvl); } G.Sys.GameManager_.LevelPlaylist_.SetIndex(origIndex); var playersThreshold = Convert.ToInt32(Math.Ceiling(voteThresholds[voteType] * Convert.ToDouble(numPlayers))); if (lvls.Count == 0) { MessageUtilities.sendMessage(p, "Can't find any levels with the filter '" + levelName + "'."); } string newMessage; int count; newMessage = ""; count = 0; foreach (LevelResultsSortInfo level in levelResults) { if (level.voteState == -1) { if (++count <= 10) { newMessage = newMessage + level.level.levelNameAndPath_.levelName_ + $"({level.votes}/{playersThreshold}), "; } } } if (count != 0) { if (count > 10) { MessageUtilities.sendMessage($"{p.Username_} unvoted for {newMessage} and {count - 10} more."); } else { MessageUtilities.sendMessage($"{p.Username_} unvoted for {newMessage}."); } } newMessage = ""; count = 0; foreach (LevelResultsSortInfo level in levelResults) { if (level.voteState >= 0) { if (++count <= 10) { newMessage = newMessage + level.level.levelNameAndPath_.levelName_ + $"({level.votes}/{playersThreshold}), "; } } } if (count != 0) { if (count > 10) { MessageUtilities.sendMessage($"{p.Username_} voted for {newMessage} and {count - 10} more."); } else { MessageUtilities.sendMessage($"{p.Username_} voted for {newMessage}."); } } newMessage = ""; count = 0; foreach (LevelResultsSortInfo level in levelResults) { if (level.success) { if (++count <= 10) { newMessage = newMessage + level.level.levelNameAndPath_.levelName_ + ", "; } } } if (count != 0) { if (count > 10) { MessageUtilities.sendMessage(newMessage + $"and {count - 10} more added."); } else { MessageUtilities.sendMessage(newMessage + "added."); } } } }