public static bool CanEquip(this Item equipmentItem, ICharacterData character, short level)
        {
            if (equipmentItem == null ||
                !equipmentItem.IsEquipment() ||
                character == null)
            {
                return(false);
            }

            var isPass = true;
            var attributeAmountsDict    = character.GetAttributes(true, false);
            var requireAttributeAmounts = equipmentItem.CacheRequireAttributeAmounts;

            foreach (var requireAttributeAmount in requireAttributeAmounts)
            {
                if (!attributeAmountsDict.ContainsKey(requireAttributeAmount.Key) ||
                    attributeAmountsDict[requireAttributeAmount.Key] < requireAttributeAmount.Value)
                {
                    isPass = false;
                    break;
                }
            }

            if (equipmentItem.requirement.character != null && equipmentItem.requirement.character != character.GetDatabase())
            {
                isPass = false;
            }

            return(character.Level >= equipmentItem.requirement.level && isPass);
        }
Exemple #2
0
        public static bool CanEquip(this Item equipmentItem, ICharacterData character, short level)
        {
            if (equipmentItem == null ||
                !equipmentItem.IsEquipment() ||
                character == null)
            {
                return(false);
            }

            // Check is it pass attribute requirement or not
            Dictionary <Attribute, short> attributeAmountsDict    = character.GetAttributes(true, false);
            Dictionary <Attribute, short> requireAttributeAmounts = equipmentItem.CacheRequireAttributeAmounts;

            foreach (KeyValuePair <Attribute, short> requireAttributeAmount in requireAttributeAmounts)
            {
                if (!attributeAmountsDict.ContainsKey(requireAttributeAmount.Key) ||
                    attributeAmountsDict[requireAttributeAmount.Key] < requireAttributeAmount.Value)
                {
                    return(false);
                }
            }

            // Check another requirements
            if (equipmentItem.requirement.character != null && equipmentItem.requirement.character != character.GetDatabase())
            {
                return(false);
            }

            return(character.Level >= equipmentItem.requirement.level);
        }
    public static void GetAllStats(this ICharacterData data,
                                   out CharacterStats resultStats,
                                   Dictionary <Attribute, short> resultAttributes,
                                   Dictionary <DamageElement, float> resultResistances,
                                   Dictionary <DamageElement, MinMaxFloat> resultIncreaseDamages,
                                   Dictionary <Skill, short> resultSkills,
                                   Dictionary <EquipmentSet, int> resultEquipmentSets,
                                   out int resultMaxHp,
                                   out int resultMaxMp,
                                   out int resultMaxStamina,
                                   out int resultMaxFood,
                                   out int resultMaxWater,
                                   out float resultTotalItemWeight,
                                   out float resultAtkSpeed,
                                   out float resultMoveSpeed)
    {
        resultStats = new CharacterStats();
        resultAttributes.Clear();
        resultResistances.Clear();
        resultIncreaseDamages.Clear();
        resultSkills.Clear();
        resultEquipmentSets.Clear();

        GetEquipmentSetBonus(data, out resultStats, resultAttributes, resultResistances, resultIncreaseDamages, resultSkills, resultEquipmentSets);
        resultStats           = resultStats + data.GetStats();
        resultAttributes      = GameDataHelpers.CombineAttributes(resultAttributes, data.GetAttributes());
        resultResistances     = GameDataHelpers.CombineResistances(resultResistances, data.GetResistances());
        resultIncreaseDamages = GameDataHelpers.CombineDamages(resultIncreaseDamages, data.GetIncreaseDamages());
        resultSkills          = GameDataHelpers.CombineSkills(resultSkills, data.GetSkills());
        // Sum with other stats
        resultMaxHp           = (int)resultStats.hp;
        resultMaxMp           = (int)resultStats.mp;
        resultMaxStamina      = (int)resultStats.stamina;
        resultMaxFood         = (int)resultStats.food;
        resultMaxWater        = (int)resultStats.water;
        resultTotalItemWeight = GameInstance.Singleton.GameplayRule.GetTotalWeight(data);
        resultAtkSpeed        = resultStats.atkSpeed;
        resultMoveSpeed       = resultStats.moveSpeed;
        // Validate max amount
        foreach (Attribute attribute in new List <Attribute>(resultAttributes.Keys))
        {
            if (attribute.maxAmount > 0 && resultAttributes[attribute] > attribute.maxAmount)
            {
                resultAttributes[attribute] = attribute.maxAmount;
            }
        }
    }
        public static float GetEffectivenessDamage(Dictionary <Attribute, float> effectivenessAttributes, ICharacterData character)
        {
            var damageEffectiveness = 0f;

            if (effectivenessAttributes != null && character != null)
            {
                var characterAttributes = character.GetAttributes();
                foreach (var characterAttribute in characterAttributes)
                {
                    var attribute = characterAttribute.Key;
                    if (attribute != null && effectivenessAttributes.ContainsKey(attribute))
                    {
                        damageEffectiveness += effectivenessAttributes[attribute] * characterAttribute.Value;
                    }
                }
            }
            return(damageEffectiveness);
        }