Example #1
0
    /// <summary>
    /// Shifts the given character's bodypart to the given species.
    /// </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="speciesName">The species to shift the bodypart 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> > ShiftBodypartAsync
    (
        Snowflake invokingUser,
        Character character,
        Bodypart bodyPart,
        string speciesName,
        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));
        }

        var getSpeciesResult = await GetSpeciesByNameAsync(speciesName, ct);

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

        var species = getSpeciesResult.Entity;

        var getCurrentAppearance = await GetOrCreateCurrentAppearanceAsync(character, ct);

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

        var appearance = getCurrentAppearance.Entity;

        var speciesShifter = new SpeciesShifter(appearance, species, this, _descriptionBuilder);
        var shiftResult    = await speciesShifter.ShiftAsync(bodyPart, chirality);

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

        return(shiftResult);
    }
Example #2
0
        /// <summary>
        /// Shifts the given character's bodypart to the given species.
        /// </summary>
        /// <param name="context">The context of the command.</param>
        /// <param name="character">The character to shift.</param>
        /// <param name="bodyPart">The bodypart to shift.</param>
        /// <param name="speciesName">The species to shift the bodypart 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> ShiftBodypartAsync
        (
            ICommandContext context,
            Character character,
            Bodypart bodyPart,
            string speciesName,
            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));
            }

            var getSpeciesResult = await GetSpeciesByNameAsync(speciesName);

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

            var species = getSpeciesResult.Entity;

            var getCurrentAppearance = await GetOrCreateCurrentAppearanceAsync(character);

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

            var appearance = getCurrentAppearance.Entity;

            var speciesShifter = new SpeciesShifter(appearance, species, this, _descriptionBuilder);
            var shiftResult    = await speciesShifter.ShiftAsync(bodyPart, chirality);

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

            return(shiftResult);
        }