Example #1
0
        /// <summary>
        /// Indicates if this PropertyManager can cover the Requirement a given amount of times.
        /// </summary>
        /// <param name="containerProperty">The Property containing the given requirement to check</param>
        /// <param name="requirement">The Requirement to check if can be covered.</param>
        /// <param name="times">The amount of times the requirement will have to be met.</param>
        /// <param name="remainingValueToCover">The remaining value of the Requirement that can not be currently covered by this PropertyManager.</param>
        /// <returns>True if it contains an property with a value higher or equal than the one in the requirement/PropertyUpdate n times</returns>
        public bool CanCover(Property containerProperty, Requirement requirement, int times, out float remainingValueToCover)
        {
            remainingValueToCover = requirement.minValue * times;

            if (times <= 0)
            {
                Debug.LogWarning($"   - Attention: Checking if the PropertyManager of '{owner}' can cover the requirement '{requirement.ToString()}' {times} times!.\n");
            }
            //else Debug.Log($"   - Checking if the PropertyManager of '{ownerMapElement}' can cover the requirement '{requirement.ToString()}' {times} times. Amount of value to gain: {missingValueToCoverInThisPropertyManager}\n");


            foreach (PropertyOwnership ownedProperty in propertyOwnerships)
            {
                if (requirement.GetProperty(containerProperty) != ownedProperty.property)
                {
                    continue;
                }

                remainingValueToCover -= ownedProperty.value;

                if (remainingValueToCover <= 0) // No value is missing, so the requirement can be covered
                {
                    // Debug.Log($"   - The PropertyManager of '{ownerMapElement}' can cover the requirement '{requirement.ToString()}' {times} times. Remaining amount of value to gain: {missingValueToCoverInThisPropertyManager}\n");
                    return(true);
                }
            }

            // Debug.Log($"   - The PropertyManager of '{ownerMapElement}' can NOT cover the requirement '{requirement.ToString()}' {times} times. Remaining amount of value to gain: {missingValueToCoverInThisPropertyManager}\n");
            return(false);
        }