Пример #1
0
    /// <summary>
    /// Shifts the colour of the given bodypart on the given character to the given colour.
    /// </summary>
    /// <param name="invokingUser">The user that's performing the action.</param>
    /// <param name="character">The character to shift.</param>
    /// <param name="bodyPart">The bodypart to shift.</param>
    /// <param name="colour">The colour to shift it into.</param>
    /// <param name="chirality">The chirality of the bodypart.</param>
    /// <param name="ct">The cancellation token in use.</param>
    /// <returns>A shifting result which may or may not have succeeded.</returns>
    public async Task <Result <ShiftBodypartResult> > ShiftBodypartColourAsync
    (
        Snowflake invokingUser,
        Character character,
        Bodypart bodyPart,
        Colour colour,
        Chirality chirality  = Chirality.Center,
        CancellationToken ct = default
    )
    {
        var canTransformResult = await CanUserTransformUserAsync
                                 (
            character.Server.DiscordID,
            invokingUser,
            character.Owner.DiscordID,
            ct
                                 );

        if (!canTransformResult.IsSuccess)
        {
            return(Result <ShiftBodypartResult> .FromError(canTransformResult));
        }

        if (bodyPart.IsChiral() && chirality == Chirality.Center)
        {
            return(new UserError
                   (
                       $"Please specify if it's the left or right {bodyPart.Humanize().ToLower()}."
                   ));
        }

        var getCurrentAppearance = await GetOrCreateCurrentAppearanceAsync(character, ct);

        if (!getCurrentAppearance.IsSuccess)
        {
            return(Result <ShiftBodypartResult> .FromError(getCurrentAppearance));
        }

        var appearance = getCurrentAppearance.Entity;

        var colourShifter = new ColourShifter(appearance, colour, _descriptionBuilder);
        var shiftResult   = await colourShifter.ShiftAsync(bodyPart, chirality);

        if (shiftResult.IsSuccess)
        {
            await _database.SaveChangesAsync(ct);
        }

        return(shiftResult);
    }
Пример #2
0
        /// <summary>
        /// Shifts the colour of the given bodypart on the given character to the given colour.
        /// </summary>
        /// <param name="context">The command context.</param>
        /// <param name="character">The character to shift.</param>
        /// <param name="bodyPart">The bodypart to shift.</param>
        /// <param name="colour">The colour to shift it into.</param>
        /// <param name="chirality">The chirality of the bodypart.</param>
        /// <returns>A shifting result which may or may not have succeeded.</returns>
        public async Task <ShiftBodypartResult> ShiftBodypartColourAsync
        (
            ICommandContext context,
            Character character,
            Bodypart bodyPart,
            Colour colour,
            Chirality chirality = Chirality.Center
        )
        {
            var discordUser = await context.Guild.GetUserAsync((ulong)character.Owner.DiscordID);

            var canTransformResult = await CanUserTransformUserAsync(context.Guild, context.User, discordUser);

            if (!canTransformResult.IsSuccess)
            {
                return(ShiftBodypartResult.FromError(canTransformResult));
            }

            if (bodyPart.IsChiral() && chirality == Chirality.Center)
            {
                return(ShiftBodypartResult.FromError
                       (
                           $"Please specify if it's the left or right {bodyPart.Humanize().ToLower()}."
                       ));
            }

            var getCurrentAppearance = await GetOrCreateCurrentAppearanceAsync(character);

            if (!getCurrentAppearance.IsSuccess)
            {
                return(ShiftBodypartResult.FromError(getCurrentAppearance));
            }

            var appearance = getCurrentAppearance.Entity;

            var colourShifter = new ColourShifter(appearance, colour, _descriptionBuilder);
            var shiftResult   = await colourShifter.ShiftAsync(bodyPart, chirality);

            if (shiftResult.IsSuccess)
            {
                await _database.SaveChangesAsync();
            }

            return(shiftResult);
        }