예제 #1
0
        /// <summary>
        /// Changes the maximum storage capacity.
        /// </summary>
        /// <param name="newCapacity">The new capacity</param>
        /// <returns>The amount of overflow if the current value needs to be adjusted.</returns>
        public ConstructionMaterial ChangeMaxStorage(ConstructionMaterial newCapacity)
        {
            if (currentValue <= newCapacity)
            {
                capacity = newCapacity;
                return(new ConstructionMaterial());
            }

            var overflow = currentValue - newCapacity;

            currentValue = newCapacity;
            return(overflow);
        }
예제 #2
0
        public void Store(ConstructionMaterial material)
        {
            material = constructionMaterialBaseStorage.Store(material);

            using (var storages = constructionMaterialStorages.GetEnumerator())
            {
                while (material > ConstructionMaterial.Zero && storages.MoveNext())
                {
                    Debug.Assert(storages.Current != null, "storages.Current != null");
                    material = storages.Current.Store(material);
                }
            }
        }
예제 #3
0
        public bool TryConsume(ConstructionMaterial material)
        {
            if (material > ConstructionMaterialAvailable)
            {
                return(false);
            }

            material = constructionMaterialBaseStorage.Consume(material);
            foreach (var storage in constructionMaterialStorages)
            {
                material = storage.Consume(material);
            }

            return(true);
        }
예제 #4
0
        public ConstructionMaterial Store(ConstructionMaterial value)
        {
            if (value < new ConstructionMaterial())
            {
                return(-Consume(-value));
            }

            if (currentValue + value > capacity)
            {
                value       -= capacity - currentValue;
                currentValue = capacity;
                return(value);
            }

            currentValue += value;
            return(new ConstructionMaterial());
        }
예제 #5
0
        public ConstructionMaterial Consume(ConstructionMaterial value)
        {
            if (value < new ConstructionMaterial())
            {
                return(-Store(-value));
            }

            if (currentValue - value < new ConstructionMaterial())
            {
                value       -= currentValue;
                currentValue = new ConstructionMaterial();
                return(value);
            }

            currentValue -= value;
            return(new ConstructionMaterial());
        }
예제 #6
0
 public ConstructionMaterialStorage(ConstructionMaterial capacity)
 {
     this.capacity = capacity;
 }
예제 #7
0
 public static ConstructionMaterial Max(ConstructionMaterial a, ConstructionMaterial b) => a > b ? a : b;
예제 #8
0
 public static ConstructionMaterial Min(ConstructionMaterial a, ConstructionMaterial b) => a < b ? a : b;