using System.Collections.Generic; using Content.Shared.GameObjects.Components.Research; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; namespace Content.Server.GameObjects.Components.Research { [RegisterComponent] [ComponentReference(typeof(SharedMaterialStorageComponent))] public class MaterialStorageComponent : SharedMaterialStorageComponent { protected override Dictionary Storage { get; set; } = new Dictionary(); /// /// How much material the storage can store in total. /// public int StorageLimit => _storageLimit; private int _storageLimit; public override ComponentState GetComponentState() { return new MaterialStorageState(Storage); } /// /// Checks if the storage can take a volume of material without surpassing its own limits. /// /// The volume of material /// public bool CanTakeAmount(int amount) { return CurrentAmount + amount <= StorageLimit; } /// /// Checks if it can insert a material. /// /// Material ID /// How much to insert /// Whether it can insert the material or not. public bool CanInsertMaterial(string ID, int amount) { return (CanTakeAmount(amount) || StorageLimit < 0) && (!Storage.ContainsKey(ID) || Storage[ID] + amount >= 0); } /// /// Inserts material into the storage. /// /// Material ID /// How much to insert /// Whether it inserted it or not. public bool InsertMaterial(string ID, int amount) { if (!CanInsertMaterial(ID, amount)) return false; if (!Storage.ContainsKey(ID)) Storage.Add(ID, 0); Storage[ID] += amount; Dirty(); return true; } /// /// Removes material from the storage. /// /// Material ID /// How much to remove /// Whether it removed it or not. public bool RemoveMaterial(string ID, int amount) { return InsertMaterial(ID, -amount); } public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); serializer.DataField(ref _storageLimit, "StorageLimit", -1); } } }