Files
tbd-station-14/Content.Server/GameObjects/Components/Research/MaterialStorageComponent.cs
Víctor Aguilera Puerto fe0414eda7 Lathes (#207)
* Recipe stuff.

* Lathe GUI and stuff

* god dammit

* Lathe menu works, yay.

* EventArgs henk

* Some work

* SS14 -> Robust

* More SS14 -> Robust

* Lathe materials

* Lathe works, Lathe GUI, Queue GUI, etc

too many changes to name them here

* Remove materials button, add ViewVariables and update lathe on connect

* Add Autolathe RSI

* Adds new recipes, fixes a few bugs.

* Remove unused ScrollContainers

* Use same delegate for spawn.

* Removes client-side LatheComponent in favor of BoundUserInterface

* Remove GetMaterial and TryGetMaterial

* Use auto-properties in a few places.

* Adds LatheDatabase, and a bunch of other changes

* Remove useless log.

* Remove lathetype from prototypes.

* Turns Storage, Lathe and Database into autoproperties

* Remove Hacked property from LatheRecipePrototype

* Remove unneeded dependency injection from components

* Refactors LatheDatabaseComponent to use ComponentState

* Refactors MaterialStorageComponent to use ComponentState

* Oopsie

* Another oopsie

* Last oopsie, I hope

* Fix missing Close call.
2019-04-26 15:51:05 +02:00

84 lines
2.7 KiB
C#

using System.Collections.Generic;
using Content.Shared.GameObjects.Components.Research;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Research
{
public class MaterialStorageComponent : SharedMaterialStorageComponent
{
protected override Dictionary<string, int> Storage { get; set; } = new Dictionary<string, int>();
/// <summary>
/// How much material the storage can store in total.
/// </summary>
public int StorageLimit => _storageLimit;
private int _storageLimit;
public override ComponentState GetComponentState()
{
return new MaterialStorageState(Storage);
}
/// <summary>
/// Checks if the storage can take a volume of material without surpassing its own limits.
/// </summary>
/// <param name="amount">The volume of material</param>
/// <returns></returns>
public bool CanTakeAmount(int amount)
{
return CurrentAmount + amount <= StorageLimit;
}
/// <summary>
/// Checks if it can insert a material.
/// </summary>
/// <param name="ID">Material ID</param>
/// <param name="amount">How much to insert</param>
/// <returns>Whether it can insert the material or not.</returns>
public bool CanInsertMaterial(string ID, int amount)
{
return (CanTakeAmount(amount) || StorageLimit < 0) && (!Storage.ContainsKey(ID) || Storage[ID] + amount >= 0);
}
/// <summary>
/// Inserts material into the storage.
/// </summary>
/// <param name="ID">Material ID</param>
/// <param name="amount">How much to insert</param>
/// <returns>Whether it inserted it or not.</returns>
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;
}
/// <summary>
/// Removes material from the storage.
/// </summary>
/// <param name="ID">Material ID</param>
/// <param name="amount">How much to remove</param>
/// <returns>Whether it removed it or not.</returns>
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);
}
}
}