Exemplo n.º 1
0
        public void SetAttributeBaseValue(AttributeScriptableObject attribute, float value)
        {
            // If dictionary is stale, rebuild it
            var attributeCache = GetAttributeCache();

            if (!attributeCache.TryGetValue(attribute, out var index))
            {
                return;
            }
            var attributeValue = AttributeValues[index];

            attributeValue.BaseValue = value;
            AttributeValues[index]   = attributeValue;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the value of an attribute.  Note that the returned value is a copy of the struct, so modifying it
        /// does not modify the original attribute
        /// </summary>
        /// <param name="attribute">Attribute to get value for</param>
        /// <param name="value">Returned attribute</param>
        /// <returns>True if attribute was found, false otherwise.</returns>
        public bool GetAttributeValue(AttributeScriptableObject attribute, out AttributeValue value)
        {
            // If dictionary is stale, rebuild it
            var attributeCache = GetAttributeCache();


            // We use a cache to store the index of the attribute in the list, so we don't
            // have to iterate through it every time
            if (attributeCache.TryGetValue(attribute, out var index))
            {
                value = AttributeValues[index];
                return(true);
            }


            // No matching attribute found
            value = new AttributeValue();
            return(false);
        }
Exemplo n.º 3
0
    private void ClampAttributeToMax(AttributeScriptableObject Attribute1, AttributeScriptableObject Attribute2, List <AttributeValue> attributeValues, Dictionary <AttributeScriptableObject, int> attributeCacheDict)
    {
        if (attributeCacheDict.TryGetValue(Attribute1, out var primaryAttributeIndex) &&
            attributeCacheDict.TryGetValue(Attribute2, out var maxAttributeIndex))
        {
            var primaryAttribute = attributeValues[primaryAttributeIndex];
            var maxAttribute     = attributeValues[maxAttributeIndex];

            // Clamp current and base values
            if (primaryAttribute.CurrentValue > maxAttribute.CurrentValue)
            {
                primaryAttribute.CurrentValue = maxAttribute.CurrentValue;
            }
            if (primaryAttribute.BaseValue > maxAttribute.BaseValue)
            {
                primaryAttribute.BaseValue = maxAttribute.BaseValue;
            }
            attributeValues[primaryAttributeIndex] = primaryAttribute;
        }
    }
Exemplo n.º 4
0
        /// <summary>
        /// Sets value of an attribute.  Note that the out value is a copy of the struct, so modifying it
        /// does not modify the original attribute
        /// </summary>
        /// <param name="attribute">Attribute to set</param>
        /// <param name="modifierType">How to modify the attribute</param>
        /// <param name="value">Copy of newly modified attribute</param>
        /// <returns>True, if attribute was found.</returns>
        public bool UpdateAttributeModifiers(AttributeScriptableObject attribute, AttributeModifier modifier, out AttributeValue value)
        {
            // If dictionary is stale, rebuild it
            var attributeCache = GetAttributeCache();

            // We use a cache to store the index of the attribute in the list, so we don't
            // have to iterate through it every time
            if (attributeCache.TryGetValue(attribute, out var index))
            {
                // Get a copy of the attribute value struct
                value          = AttributeValues[index];
                value.Modifier = value.Modifier.Combine(modifier);

                // Structs are copied by value, so the modified attribute needs to be reassigned to the array
                AttributeValues[index] = value;
                return(true);
            }

            // No matching attribute found
            value = new AttributeValue();
            return(false);
        }