Beispiel #1
0
        public AppearanceComponent GetAppearanceComponent(Bodypart bodypart, Chirality chirality)
        {
            if (bodypart.IsChiral() && chirality == Chirality.Center)
            {
                throw new ArgumentException("A chiral bodypart must have its chirality specified.", nameof(bodypart));
            }

            if (!bodypart.IsChiral() && chirality != Chirality.Center)
            {
                throw new ArgumentException("A nonchiral transformation cannot have chirality.", nameof(bodypart));
            }

            if (bodypart.IsComposite())
            {
                throw new ArgumentException("The bodypart must not be a composite part.");
            }

            return(this.Components.First(c => c.Bodypart == bodypart && c.Chirality == chirality));
        }
    /// <inheritdoc />
    public async Task <Result <ShiftBodypartResult> > RemoveAsync(Bodypart bodypart, Chirality chirality)
    {
        if (bodypart.IsChiral() && chirality == Chirality.Center)
        {
            return(new UserError("Please specify left or right when removing one-sided bodyparts."));
        }

        if (bodypart.IsComposite())
        {
            return(await RemoveCompositeBodypartAsync(bodypart));
        }

        return(await RemoveBodypartAsync(bodypart, chirality));
    }
Beispiel #3
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);
    }
        /// <inheritdoc />
        public async Task <ShiftBodypartResult> ShiftAsync(Bodypart bodypart, Chirality chirality)
        {
            if (bodypart.IsChiral() && chirality == Chirality.Center)
            {
                return(ShiftBodypartResult.FromError("Please specify left or right when shifting one-sided bodyparts."));
            }

            if (bodypart.IsComposite())
            {
                return(await ShiftCompositeBodypartAsync(bodypart));
            }

            return(await ShiftBodypartAsync(bodypart, chirality));
        }
Beispiel #5
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);
        }