Exemplo n.º 1
0
        /// <summary>
        /// Removes the given character's bodypart.
        /// </summary>
        /// <param name="db">The database where characters and transformations are stored.</param>
        /// <param name="context">The context of the command.</param>
        /// <param name="character">The character to shift.</param>
        /// <param name="bodyPart">The bodypart to remove.</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> RemoveBodypartAsync
        (
            [NotNull] GlobalInfoContext db,
            [NotNull] ICommandContext context,
            [NotNull] Character character,
            Bodypart bodyPart,
            Chirality chirality = Chirality.Center
        )
        {
            var discordUser = await context.Guild.GetUserAsync((ulong)character.Owner.DiscordID);

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

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

            if (!character.TryGetAppearanceComponent(bodyPart, chirality, out var component))
            {
                return(ShiftBodypartResult.FromError(CommandError.ObjectNotFound, "The character doesn't have that bodypart."));
            }

            character.CurrentAppearance.Components.Remove(component);
            await db.SaveChangesAsync();

            string removeMessage = this.DescriptionBuilder.BuildRemoveMessage(character, component);

            return(ShiftBodypartResult.FromSuccess(removeMessage));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Shifts the given character's bodypart to the given species.
        /// </summary>
        /// <param name="db">The database where characters and transformations are stored.</param>
        /// <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="species">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
        (
            [NotNull] GlobalInfoContext db,
            [NotNull] ICommandContext context,
            [NotNull] Character character,
            Bodypart bodyPart,
            [NotNull] string species,
            Chirality chirality = Chirality.Center
        )
        {
            var discordUser = await context.Guild.GetUserAsync((ulong)character.Owner.DiscordID);

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

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

            var getSpeciesResult = await GetSpeciesByNameAsync(db, species);

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

            var getTFResult = await GetTransformationByPartAndSpeciesAsync(db, bodyPart, getSpeciesResult.Entity);

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

            string shiftMessage;
            var    transformation = getTFResult.Entity;

            if (!character.TryGetAppearanceComponent(bodyPart, chirality, out var currentComponent))
            {
                currentComponent = AppearanceComponent.CreateFrom(transformation, chirality);
                character.CurrentAppearance.Components.Add(currentComponent);

                shiftMessage = this.DescriptionBuilder.BuildGrowMessage(character, currentComponent);
            }
            else
            {
                if (currentComponent.Transformation.Species.Name.Equals(transformation.Species.Name))
                {
                    return(ShiftBodypartResult.FromError(CommandError.Unsuccessful, "The user's bodypart is already that form."));
                }

                currentComponent.Transformation = transformation;

                shiftMessage = this.DescriptionBuilder.BuildShiftMessage(character, currentComponent);
            }

            await db.SaveChangesAsync();

            return(ShiftBodypartResult.FromSuccess(shiftMessage));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds the given bodypart to the given character.
        /// </summary>
        /// <param name="db">The database where characters and transformations are stored.</param>
        /// <param name="context">The context of the command.</param>
        /// <param name="character">The character to shift.</param>
        /// <param name="bodyPart">The bodypart to add.</param>
        /// <param name="species">The species of the part to add..</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> AddBodypartAsync
        (
            [NotNull] GlobalInfoContext db,
            [NotNull] ICommandContext context,
            [NotNull] Character character,
            Bodypart bodyPart,
            [NotNull] string species,
            Chirality chirality = Chirality.Center
        )
        {
            var discordUser = await context.Guild.GetUserAsync((ulong)character.Owner.DiscordID);

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

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

            if (character.HasComponent(bodyPart, chirality))
            {
                return(ShiftBodypartResult.FromError(CommandError.ObjectNotFound, "The character already has that bodypart."));
            }

            var getSpeciesResult = await GetSpeciesByNameAsync(db, species);

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

            var getTFResult = await GetTransformationByPartAndSpeciesAsync(db, bodyPart, getSpeciesResult.Entity);

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

            var transformation = getTFResult.Entity;

            var component = AppearanceComponent.CreateFrom(transformation, chirality);

            character.CurrentAppearance.Components.Add(component);
            await db.SaveChangesAsync();

            string growMessage = this.DescriptionBuilder.BuildGrowMessage(character, component);

            return(ShiftBodypartResult.FromSuccess(growMessage));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Shifts the colour of the given bodypart's pattern on the given character to the given colour.
        /// </summary>
        /// <param name="db">The database.</param>
        /// <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="patternColour">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> ShiftPatternColourAsync
        (
            [NotNull] GlobalInfoContext db,
            [NotNull] ICommandContext context,
            [NotNull] Character character,
            Bodypart bodyPart,
            [NotNull] Colour patternColour,
            Chirality chirality = Chirality.Center
        )
        {
            var discordUser = await context.Guild.GetUserAsync((ulong)character.Owner.DiscordID);

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

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

            if (!character.TryGetAppearanceComponent(bodyPart, chirality, out var currentComponent))
            {
                return(ShiftBodypartResult.FromError(CommandError.ObjectNotFound, "The character doesn't have that bodypart."));
            }

            if (!currentComponent.Pattern.HasValue)
            {
                return(ShiftBodypartResult.FromError(CommandError.ObjectNotFound, "The bodypart doesn't have a pattern."));
            }

            if (currentComponent.PatternColour == patternColour)
            {
                return(ShiftBodypartResult.FromError(CommandError.Unsuccessful, "The pattern is already that colour."));
            }

            var originalColour = currentComponent.PatternColour;

            currentComponent.PatternColour = patternColour;

            await db.SaveChangesAsync();

            // ReSharper disable once AssignNullToNotNullAttribute - Having a pattern implies having a pattern colour
            string shiftMessage = this.DescriptionBuilder.BuildPatternColourShiftMessage(character, originalColour, currentComponent);

            return(ShiftBodypartResult.FromSuccess(shiftMessage));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Shifts the pattern of the given bodypart on the given character to the given pattern with the given colour.
        /// </summary>
        /// <param name="db">The database.</param>
        /// <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="pattern">The pattern to shift the bodypart into.</param>
        /// <param name="patternColour">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> ShiftBodypartPatternAsync
        (
            [NotNull] GlobalInfoContext db,
            [NotNull] ICommandContext context,
            [NotNull] Character character,
            Bodypart bodyPart,
            Pattern pattern,
            [NotNull] Colour patternColour,
            Chirality chirality = Chirality.Center
        )
        {
            var discordUser = await context.Guild.GetUserAsync((ulong)character.Owner.DiscordID);

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

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

            if (!character.TryGetAppearanceComponent(bodyPart, chirality, out var currentComponent))
            {
                return(ShiftBodypartResult.FromError(CommandError.ObjectNotFound, "The character doesn't have that bodypart."));
            }

            if (currentComponent.Pattern == pattern)
            {
                return(ShiftBodypartResult.FromError(CommandError.Unsuccessful, "The character already has that pattern."));
            }

            var originalPattern = currentComponent.Pattern;
            var originalColour  = currentComponent.BaseColour;

            currentComponent.Pattern       = pattern;
            currentComponent.PatternColour = patternColour;

            await db.SaveChangesAsync();

            string shiftMessage = this.DescriptionBuilder.BuildPatternShiftMessage(character, originalPattern, originalColour, currentComponent);

            return(ShiftBodypartResult.FromSuccess(shiftMessage));
        }