Ejemplo n.º 1
0
    public void SwapAnimation(GameObject ball1, GameObject ball2, Action nextAnimation)
    {
        Vector3         pos1           = ball1.transform.position;
        Vector3         pos2           = ball2.transform.position;
        CountdownAction bothAnimations = new CountdownAction(2, nextAnimation);

        StartCoroutine(MoveToPosition(ball1, pos2, () => bothAnimations.DecreaseAndAct()));
        StartCoroutine(MoveToPosition(ball2, pos1, () => bothAnimations.DecreaseAndAct()));
    }
Ejemplo n.º 2
0
        public static ICommandResult Countdown(ICommandContext context, CountdownAction action, string name, [JoinRemainingParameters, DisplayName("event date/time"), HelpText("ex. \"1/1/11 1:11 PM\"")] DateTimeOffset?date = null)
        {
            IGuildChannel channel;

            switch (context)
            {
            case DiscordMessageContext message:
                channel = (IGuildChannel)message.Channel;
                break;

            case DiscordChannelDescriptionContext desc:
                channel = desc.Channel;
                break;

            default:
                return(new ErrorResult($"The `countdown` command is not valid in the context `{context.GetType().Name}`"));
            }

            context.Bot.Countdowns.Countdowns = context.Bot.Countdowns.Countdowns ?? new Dictionary <ulong, Dictionary <string, DateTimeOffset> >();
            var countdowns = context.Bot.Countdowns.Countdowns.GetValueOrDefault(channel.GuildId) ?? new Dictionary <string, DateTimeOffset>();

            switch (action)
            {
            case CountdownAction.Create:
            case CountdownAction.Add:
                if (countdowns.Select(x => x.Key.ToLower()).Contains(name.ToLower()))
                {
                    return(new ErrorResult($"The countdown with the name {name} already exists"));
                }
                break;

            case CountdownAction.Edit:
                if (!countdowns.Select(x => x.Key.ToLower()).Contains(name.ToLower()))
                {
                    return(new ErrorResult($"The countdown with the name {name} does not exist"));
                }
                break;

            case CountdownAction.Delete:
                if (!countdowns.Select(x => x.Key.ToLower()).Contains(name.ToLower()))
                {
                    return(new ErrorResult($"The countdown with the name {name} does not exist"));
                }
                countdowns = countdowns.Where(x => x.Key.ToLower() != name.ToLower()).ToDictionary(x => x.Key, x => x.Value);
                context.Bot.Countdowns.Countdowns[channel.GuildId] = countdowns;
                context.Bot.Countdowns.SaveConfig();
                return(new SuccessResult($"Successfully deleted countdown {name}"));
            }

            if (!date.HasValue)
            {
                return(new ErrorResult("Please provide a date and time when creating or editing a countdown"));
            }
            var existingCountdown = countdowns.Select(x => x.Key).FirstOrDefault(x => x.ToLower() == name.ToLower());

            if (existingCountdown != null)
            {
                countdowns[existingCountdown] = date.Value;
            }
            else
            {
                countdowns.Add(name, date.Value);
            }
            context.Bot.Countdowns.Countdowns[channel.GuildId] = countdowns;
            context.Bot.Countdowns.SaveConfig();

            return(GenerateCountdownResult(context, name, countdowns[name]));
        }