Exemplo n.º 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);
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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());
        }
Exemplo n.º 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());
        }
Exemplo n.º 6
0
 public ConstructionMaterialStorage(ConstructionMaterial capacity)
 {
     this.capacity = capacity;
 }
Exemplo n.º 7
0
 public static ConstructionMaterial Max(ConstructionMaterial a, ConstructionMaterial b) => a > b ? a : b;
Exemplo n.º 8
0
 public static ConstructionMaterial Min(ConstructionMaterial a, ConstructionMaterial b) => a < b ? a : b;