Exemplo n.º 1
0
        public void LeaveCommand(CommandArgs args)
        {
            CahPlayer cahPlayer = args.Player.GetCaHPlayer();

            if (cahPlayer == null)
            {
                args.Player.SendErrorMessage("You are not in the game!");
                return;
            }
            args.Player.ClearInterfaceAndKick();
            args.Player.SendInfoMessage("You have left the game!");
            if (cahPlayer.Spectating)
            {
                return;
            }

            CahGame.Leave(args.Player);
        }
Exemplo n.º 2
0
        public void SpectateCommand(CommandArgs args)
        {
            CahPlayer cahPlayer = args.Player.GetCaHPlayer();

            if (cahPlayer != null)
            {
                if (cahPlayer.Spectating)
                {
                    args.Player.SendErrorMessage("You are already spectating!");
                    return;
                }
                args.Player.Spectate(CahGame);
                Utils.CahBroadcast($"{args.Player.Name} switched to spectate mode!");
                return;
            }
            args.Player.SetData("cah", new CahPlayer(true));
            args.Player.SendInfoMessage("You are now spectating Cards against Humanity!");
        }
Exemplo n.º 3
0
        void OnLeave(LeaveEventArgs e)
        {
            TSPlayer ts = TShock.Players[e.Who];

            if (ts == null)
            {
                return;
            }

            CahPlayer cplr = TShock.Players[e.Who].GetCaHPlayer();

            if (cplr == null)
            {
                return;
            }

            ts.RemoveData("cah");

            CahGame.Leave(ts);
        }
Exemplo n.º 4
0
        public void JoinCommand(CommandArgs args)
        {
            CahPlayer cahPlayer = args.Player.GetCaHPlayer();

            if (cahPlayer != null && !cahPlayer.Spectating)
            {
                args.Player.SendErrorMessage("You are already in the game!");
                return;
            }
            if (CahGame.Locked)
            {
                args.Player.SendErrorMessage("The game is locked and you cannot join!");
                return;
            }
            if (Utils.GetCahPlayers().Count(c => !c.GetCaHPlayer().Spectating) >= CahGame.MaxPlayers)
            {
                args.Player.SendErrorMessage("The game is already full! If you want to spectate type /cah spectate.");
                return;
            }
            args.Player.SetData("cah", new CahPlayer());
            Utils.CahBroadcast($"{args.Player.Name} has joined the game!");
        }
Exemplo n.º 5
0
        public static void SendCaHGameInterface(this TSPlayer ts, CahGame cahGame)
        {
            string    Optionalmsg = "";
            CahPlayer cplr        = ts.GetCaHPlayer();

            if (cplr.Spectating)
            {
                Optionalmsg = "You are currently spectating and can't do anything.";
            }
            else if (cahGame.Judge == ts)
            {
                Optionalmsg = "You are the judge and cannot submit an answer for this round.";
            }
            else if (!cplr.Answered)
            {
                Optionalmsg = "Use /cah answer <answer>";
            }

            string message = string.Join("\r\n",
                                         new string[]
            {
                RepeatSpaces(100),
                RepeatLineBreaks(10),
                "Cards against humanity",
                Utils.LineSegment,
                $"Round {cahGame.Round}/{cahGame.MaxRounds} - ({cahGame.TimeLeft} seconds left to answer)",
                Utils.SplitStringToFitScreen("Question: " + cahGame.Question),
                Utils.LineSegment,
                "Given answers:",
                Utils.LineSegment,
                GetAnswers(cahGame.Judge, ts == cahGame.Judge),
                Utils.LineSegment,
                SplitStringToFitScreen(Optionalmsg),
                RepeatLineBreaks(50),
            });

            ts.SendData(PacketTypes.Status, message);
        }
Exemplo n.º 6
0
        public void AnswerCommand(CommandArgs args)
        {
            if (CahGame.gameState == GameState.NotStarted)
            {
                args.Player.SendErrorMessage("The game hasn't started yet!");
                return;
            }
            if (args.Parameters.Count == 0)
            {
                args.Player.SendErrorMessage("Invalid syntax! proper syntax: /cah answer <answer>");
                return;
            }
            CahPlayer cahPlayer = args.Player.GetCaHPlayer();

            if (cahPlayer == null)
            {
                args.Player.SendErrorMessage("You are not participating in the current game!");
                return;
            }
            if (CahGame.gameState != GameState.WaitingForAnswers)
            {
                args.Player.SendErrorMessage("The game is not waiting for answers at this moment!");
                return;
            }
            if (CahGame.Judge == args.Player)
            {
                args.Player.SendErrorMessage("You are the judge and cannot give an answer for this round!");
                return;
            }
            if (cahPlayer.Answered)
            {
                args.Player.SendErrorMessage("You have already given an answer for this round!");
                return;
            }
            cahPlayer.SetAnswer(string.Join(" ", args.Parameters));
            args.Player.SendInfoMessage("Your answer has been submitted!");
        }
Exemplo n.º 7
0
        void Cah(CommandArgs args)
        {
            if (!args.Player.IsLoggedIn)
            {
                args.Player.SendErrorMessage("You need to be logged in to use this command!");
                return;
            }
            CahPlayer   cplr    = args.Player.GetCaHPlayer();
            CommandArgs newArgs = null;

            if (args.Parameters.Count > 0)
            {
                newArgs = new CommandArgs(args.Message, args.Player, args.Parameters.GetRange(1, args.Parameters.Count - 1));
            }
            switch (args.Parameters.Count == 0 ? "help" : args.Parameters[0].ToLower())
            {
            case "start":
                if (!args.Player.HasPermission("cah.admin"))
                {
                    args.Player.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                StartCommand(newArgs);
                break;

            case "join":
                JoinCommand(newArgs);
                break;

            case "leave":
                LeaveCommand(newArgs);
                break;

            case "answer":
                if (cplr != null && cplr.Spectating)
                {
                    args.Player.SendErrorMessage("You are in spectate mode and cannot use this command!");
                    return;
                }
                AnswerCommand(newArgs);
                break;

            case "win":
                if (cplr != null && cplr.Spectating)
                {
                    args.Player.SendErrorMessage("You are in spectate mode and cannot use this command!");
                    return;
                }
                WinCommand(newArgs);
                break;

            case "stop":
                if (!args.Player.HasPermission("cah.admin"))
                {
                    args.Player.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                StopCommand(newArgs);
                break;

            case "lock":
                if (!args.Player.HasPermission("cah.admin"))
                {
                    args.Player.SendErrorMessage("You do not have permission to use this command!");
                    return;
                }
                LockCommand(newArgs);
                break;

            case "spectate":
                SpectateCommand(newArgs);
                break;

            default:
                args.Player.SendInfoMessage("~Cards against Humanity commands~");
                args.Player.SendInfoMessage("/cah join - join a cah game");
                args.Player.SendInfoMessage("/cah leave - leave a cah game");
                args.Player.SendInfoMessage("/cah answer <answer> - give your answer for the current round");
                args.Player.SendInfoMessage("/cah win <number> - choose which answer wins the round");
                args.Player.SendInfoMessage("/cah spectate - spectate the current game.");
                if (args.Player.HasPermission("cah.admin"))
                {
                    args.Player.SendInfoMessage("/cah start - start the game.");
                    args.Player.SendInfoMessage("/cah lock - toggle the ability to join the game.");
                    args.Player.SendInfoMessage("/cah stop - Stop the game.");
                }
                return;
            }
        }