Esempio n. 1
0
        /// <summary>
        /// Gets the requirement as a tuple of an attribute and the corresponding value.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="requirement">The requirement.</param>
        /// <returns>The requirement as a tuple of an attribute and the corresponding value.</returns>
        /// <remarks>
        /// Some requirements are depending on item level, drop level and item options.
        /// </remarks>
        public static (AttributeDefinition, int) GetRequirement(this Item item, AttributeRequirement requirement)
        {
            if (RequirementAttributeMapping.TryGetValue(requirement.Attribute, out var totalAttribute))
            {
                var multiplier = 3;
                if (totalAttribute == Stats.TotalEnergy)
                {
                    multiplier = 4;

                    // Summoner Books are calculated differently. They are in group 5 (staffs) and are the only items in the group which can have skill.
                    if (item.Definition.Skill != null && item.Definition.Group == 5)
                    {
                        return(totalAttribute, item.CalculateBookEnergyRequirement(requirement.MinimumValue));
                    }
                }

                var value = item.CalculateRequirement(requirement.MinimumValue, multiplier);
                if (value > 0 && totalAttribute == Stats.TotalStrength)
                {
                    var itemOption = item.ItemOptions.FirstOrDefault(o => o.ItemOption.OptionType == ItemOptionTypes.Option);
                    if (itemOption != null)
                    {
                        value += itemOption.Level * 4;
                    }
                }

                return(totalAttribute, value);
            }

            return(requirement.Attribute, requirement.MinimumValue);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the required value of the <see cref="AttributeRequirement"/>.
        /// </summary>
        /// <param name="attacker">The attacker.</param>
        /// <param name="attributeRequirement">The attribute requirement, e.g. of a skill.</param>
        /// <returns>The required value.</returns>
        public static int GetRequiredValue(this IAttacker attacker, AttributeRequirement attributeRequirement)
        {
            var modifier = 1.0f;

            if (ReductionModifiers.TryGetValue(attributeRequirement.Attribute, out var reductionAttribute))
            {
                modifier -= attacker.Attributes[reductionAttribute];
            }

            return((int)(attributeRequirement.MinimumValue * modifier));
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the requirement as a tuple of an attribute and the corresponding value.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="requirement">The requirement.</param>
        /// <returns>The requirement as a tuple of an attribute and the corresponding value.</returns>
        /// <remarks>
        /// Some requirements are depending on item level, drop level and item options.
        /// </remarks>
        public static (AttributeDefinition, int) GetRequirement(this Item item, AttributeRequirement requirement)
        {
            requirement.ThrowNotInitializedProperty(requirement.Attribute is null, nameof(requirement.Attribute));

            if (RequirementAttributeMapping.TryGetValue(requirement.Attribute, out var totalAttribute))
            {
                if (!item.IsWearable())
                {
                    return(totalAttribute, requirement.MinimumValue);
                }

                var multiplier = 3;
                if (totalAttribute == Stats.TotalEnergy)
                {
                    multiplier = 4;

                    // Summoner Books are calculated differently. They are in group 5 (staffs) and are the only items in the group which can have skill.
                    if (item.Definition?.Skill != null && item.Definition.Group == 5)
                    {
                        return(totalAttribute, item.CalculateBookEnergyRequirement(requirement.MinimumValue));
                    }
                }

                var value = item.CalculateRequirement(requirement.MinimumValue, multiplier);
                if (value > 0 && totalAttribute == Stats.TotalStrength)
                {
                    var itemOption = item.ItemOptions.FirstOrDefault(o => o.ItemOption?.OptionType == ItemOptionTypes.Option);
                    if (itemOption != null)
                    {
                        value += itemOption.Level * 4;
                    }
                }

                if (RequirementReductionAttributeMapping.TryGetValue(requirement.Attribute, out var reductionAttribute) &&
                    item.ItemOptions.FirstOrDefault(o =>
                                                    o.ItemOption?.PowerUpDefinition?.TargetAttribute == reductionAttribute ||
                                                    (o.ItemOption?.LevelDependentOptions.Any(l => l.PowerUpDefinition?.TargetAttribute == reductionAttribute) ?? false))
                    is { } reductionOption)
                {
                    var optionOfLevelPowerUp = reductionOption.ItemOption !.LevelDependentOptions
                                               .FirstOrDefault(o => o.Level == reductionOption.Level)?.PowerUpDefinition
                                               ?? reductionOption.ItemOption.PowerUpDefinition;
                    if (optionOfLevelPowerUp?.Boost?.ConstantValue is { } reduction)
                    {
                        value -= (int)reduction.Value;
                    }
                }

                return(totalAttribute, value);
            }

            return(requirement.Attribute, requirement.MinimumValue);
        }
Esempio n. 4
0
        private static bool CanPlayerEnterRoom(Character.Models.Character player, Models.Room foundRoom, ItemRequirement itemReq = null, AttributeRequirement attrReq = null)
        {
            if (itemReq != null)
            {
                foreach (var item in player.CarriedItems)
                {
                    if (item.ItemName == itemReq.RelevantItem.ItemName)
                    {
                        return(true);
                    }
                }

                Console.WriteLine($"You need: <{itemReq.RequirementName}> to enter {foundRoom.RoomName}. \n", Color.DarkGoldenrod);
            }

            if (attrReq != null)
            {
                if (PlayerAttributeComparer.ComparePlayerTraitsToAttributeRequirement(player, attrReq))
                {
                    return(true);
                }
                Console.WriteLine($"You need: <{attrReq.RequirementName}> to enter {foundRoom.RoomName}. \n", Color.DarkGoldenrod);
            }

            return(false);
        }
        public static bool ComparePlayerTraitsToAttributeRequirement(Character.Models.Character player, AttributeRequirement requirement)
        {
            switch (requirement.RelevantCharacterAttribute)
            {
            case AttributeStrings.Defense:
                return(player.Attributes.Defense >= requirement.MinimumAttributeValue);

            case AttributeStrings.Dexterity:
                return(player.Attributes.Dexterity >= requirement.MinimumAttributeValue);

            case AttributeStrings.Luck:
                return(player.Attributes.Luck >= requirement.MinimumAttributeValue);

            case AttributeStrings.Stamina:
                return(player.Attributes.Stamina >= requirement.MinimumAttributeValue);

            case AttributeStrings.Strength:
                return(player.Attributes.Strength >= requirement.MinimumAttributeValue);

            case AttributeStrings.Wisdom:
                return(player.Attributes.Wisdom >= requirement.MinimumAttributeValue);
            }

            return(false);
        }