예제 #1
0
        public async Task <bool> Setup(BattleCommand cmd, Say e, string args)
        {
            command = cmd.Create();

            Creator  = e;
            question = command.Arm(battle, e, args);
            if (question == null)
            {
                return(false);
            }
            winCount = battle.Users.Values.Count(x => command.GetRunPermissions(battle, x.Name) >= BattleCommand.RunPermission.Vote && !cmd.IsSpectator(battle, x.Name, x)) / 2 + 1;
            if (winCount <= 0)
            {
                winCount = 1;
            }

            if (!await Vote(e, true))
            {
                await battle.SayBattle($"Poll: {question} [!y=0/{winCount}, !n=0/{winCount}]");
            }
            else
            {
                return(false);
            }

            return(true);
        }
예제 #2
0
        public async Task <bool> Vote(Say e, bool vote)
        {
            if (e == null)
            {
                return(false);
            }
            string reason;

            if (command.GetRunPermissions(battle, e.User, out reason) >= BattleCommand.RunPermission.Vote && !Ended)
            {
                if (command.IsSpectator(battle, e.User, null))
                {
                    return(false);
                }

                userVotes[e.User] = vote;

                var yes = userVotes.Count(x => x.Value == true);
                var no  = userVotes.Count(x => x.Value == false);
                await battle.SayBattle(string.Format("Poll: {0} [!y={1}/{3}, !n={2}/{3}]", question, yes, no, winCount));

                if (await CheckEnd(false))
                {
                    return(true);
                }
            }
            else
            {
                await battle.Respond(e, reason);

                return(false);
            }
            return(false);
        }
예제 #3
0
 public override RunPermission GetRunPermissions(ServerBattle battle, string userName, out string reason)
 {
     if (commandToRun == null)
     {
         return(base.GetRunPermissions(battle, userName, out reason) >= RunPermission.Vote ? RunPermission.Vote : RunPermission.None);
     }
     return(commandToRun.GetRunPermissions(battle, userName, out reason));
 }
예제 #4
0
        public async Task <bool> Vote(Say e, bool vote)
        {
            string reason;

            if (command.GetRunPermissions(battle, e.User, out reason) >= BattleCommand.RunPermission.Vote && !ended)
            {
                if (command.IsSpectator(battle, e.User, null))
                {
                    return(false);
                }

                userVotes[e.User] = vote;
                var yes = userVotes.Count(x => x.Value == true);
                var no  = userVotes.Count(x => x.Value == false);

                if (yes >= winCount)
                {
                    ended = true;
                }

                await battle.SayBattle(string.Format("Poll: {0} [!y={1}/{3}, !n={2}/{3}]", question, yes, no, winCount));

                if (yes >= winCount)
                {
                    ended = true;
                    await battle.SayBattle($"Poll: {question} [END:SUCCESS]");

                    if (command.Access == BattleCommand.AccessType.NotIngame && battle.spring.IsRunning)
                    {
                        return(true);
                    }
                    if (command.Access == BattleCommand.AccessType.Ingame && !battle.spring.IsRunning)
                    {
                        return(true);
                    }
                    await command.ExecuteArmed(battle, Creator);

                    return(true);
                }
                else if (no >= winCount)
                {
                    await End();

                    return(true);
                }
            }
            else
            {
                await battle.Respond(e, reason);

                return(false);
            }
            return(false);
        }
예제 #5
0
 public override string Arm(ServerBattle battle, Say e, string arguments = null)
 {
     if (string.IsNullOrEmpty(arguments))
     {
         battle.Respond(e, "Pick a command to poll, e.g. !poll map tabula");
         return null;
     }
     var parts = arguments.Split(new[] { ' ' }, 2);
     var commandName = parts[0] ?? "";
     var commandArgs = parts.Length > 1 ? parts[1] : null;
     commandToRun = battle.GetCommandByName(commandName);
     if (commandToRun.GetRunPermissions(battle, e.User) >= RunPermission.Vote)
     {
         return commandToRun.Arm(battle, e, commandArgs);
     }
     battle.Respond(e, "You cannot poll this");
     return null;
 }
        public async Task<bool> Setup(BattleCommand cmd, Say e, string args)
        {
            command = cmd.Create();

            Creator = e;
            question = command.Arm(battle, e, args);
            if (question == null) return false;
            winCount = battle.Users.Values.Count(x => command.GetRunPermissions(battle, x.Name) >= BattleCommand.RunPermission.Vote && !cmd.IsSpectator(battle, x.Name, x)) / 2 + 1;
            if (winCount <= 0) winCount = 1;

            if (winCount <= 0) winCount = (battle.NonSpectatorCount / 2 + 1);
            if (winCount <= 0) winCount = 1;

            if (!await Vote(e, true)) await battle.SayBattle($"Poll: {question} [!y=0/{winCount}, !n=0/{winCount}]");
            else return false;

            return true;
        }
예제 #7
0
        public override string Arm(ServerBattle battle, Say e, string arguments = null)
        {
            if (string.IsNullOrEmpty(arguments))
            {
                battle.Respond(e, "Pick a command to poll, e.g. !poll map tabula");
                return(null);
            }
            var parts       = arguments.Split(new[] { ' ' }, 2);
            var commandName = parts[0] ?? "";
            var commandArgs = parts.Length > 1 ? parts[1] : null;

            commandToRun = battle.GetCommandByName(commandName);
            if (commandToRun.GetRunPermissions(battle, e.User) >= RunPermission.Vote && commandToRun.Access != AccessType.NoCheck)
            {
                return(commandToRun.Arm(battle, e, commandArgs));
            }
            battle.Respond(e, "You cannot poll this");
            return(null);
        }
예제 #8
0
        public override string Arm(ServerBattle battle, Say e, string arguments = null)
        {
            if (string.IsNullOrEmpty(arguments))
            {
                battle.Respond(e, "Pick a command to poll, e.g. !poll map tabula");
                return(null);
            }
            var parts       = arguments.Split(new[] { ' ' }, 2);
            var commandName = parts[0] ?? "";
            var commandArgs = parts.Length > 1 ? parts[1] : null;

            commandToRun = battle.GetCommandByName(commandName);
            string reason;

            if (commandToRun.GetRunPermissions(battle, e.User, out reason) >= RunPermission.Vote && commandToRun.Access != AccessType.NoCheck && commandToRun.Access != AccessType.Admin && !(commandToRun.Access == AccessType.NotIngameNotAutohost && battle.IsAutohost))
            {
                return(commandToRun.Arm(battle, e, commandArgs));
            }
            battle.Respond(e, reason);
            return(null);
        }