Files
tbd-station-14/Content.Shared/GameObjects/Components/Research/SharedLatheComponent.cs
Víctor Aguilera Puerto ba8b495ec0 Adds Research, unlockable technologies, Protolathes... (#264)
* Work on Research so far
More work on UI...
Fix ResearchClient and Protolathe UI stuff.
Fix infinite select -> request state -> select -> ... loop
Add UI to ResearchClient, etc.
Technology Database states, and a bit of work on the research console ui
A bit of work on Research Console UI
Protolathe sync
Stuff that actually does things
Protolathe databases yay
Alright got my motivation back
Yeah, no. It's almost 3 AM already
Fix serialization bug again
More work on stuff
Stuff
Adds files for most new components/systems.

* Protolathes actually work now

* Research. Just Research.

* Adds icons from Eris.

* Address reviews

* Change LatheMenu resize behaviour

* Update Content.Client/GameObjects/Components/Research/ResearchConsoleBoundUserInterface.cs

Co-Authored-By: Pieter-Jan Briers <pieterjan.briers@gmail.com>

* Update Content.Client/Research/ResearchConsoleMenu.cs

Co-Authored-By: Pieter-Jan Briers <pieterjan.briers@gmail.com>

* Move IoC Resolve out of for loop

* Address review

* Localize stuff
2019-09-03 22:51:19 +02:00

140 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using Content.Shared.Materials;
using Content.Shared.Research;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components.Research
{
public class SharedLatheComponent : Component
{
public override string Name => "Lathe";
public override uint? NetID => ContentNetIDs.LATHE;
#pragma warning disable CS0649
[Dependency]
protected IPrototypeManager _prototypeManager;
#pragma warning restore
public bool CanProduce(LatheRecipePrototype recipe, int quantity = 1)
{
if (!Owner.TryGetComponent(out SharedMaterialStorageComponent storage)
|| !Owner.TryGetComponent(out SharedLatheDatabaseComponent database)) return false;
if (!database.Contains(recipe)) return false;
foreach (var (material, amount) in recipe.RequiredMaterials)
{
if (storage[material] <= (amount * quantity)) return false;
}
return true;
}
public bool CanProduce(string ID, int quantity = 1)
{
return _prototypeManager.TryIndex(ID, out LatheRecipePrototype recipe) && CanProduce(recipe, quantity);
}
/// <summary>
/// Sent to the server to sync material storage and the recipe queue.
/// </summary>
[Serializable, NetSerializable]
public class LatheSyncRequestMessage : BoundUserInterfaceMessage
{
public LatheSyncRequestMessage()
{
}
}
/// <summary>
/// Sent to the server to sync the lathe's technology database with the research server.
/// </summary>
[Serializable, NetSerializable]
public class LatheServerSyncMessage : BoundUserInterfaceMessage
{
public LatheServerSyncMessage()
{
}
}
/// <summary>
/// Sent to the server to open the ResearchClient UI.
/// </summary>
[Serializable, NetSerializable]
public class LatheServerSelectionMessage : BoundUserInterfaceMessage
{
public LatheServerSelectionMessage()
{
}
}
/// <summary>
/// Sent to the client when the lathe is producing a recipe.
/// </summary>
[Serializable, NetSerializable]
public class LatheProducingRecipeMessage : BoundUserInterfaceMessage
{
public readonly string ID;
public LatheProducingRecipeMessage(string id)
{
ID = id;
}
}
/// <summary>
/// Sent to the client when the lathe stopped/finished producing a recipe.
/// </summary>
[Serializable, NetSerializable]
public class LatheStoppedProducingRecipeMessage : BoundUserInterfaceMessage
{
public LatheStoppedProducingRecipeMessage()
{
}
}
/// <summary>
/// Sent to the client to let it know about the recipe queue.
/// </summary>
[Serializable, NetSerializable]
public class LatheFullQueueMessage : BoundUserInterfaceMessage
{
public readonly Queue<string> Recipes;
public LatheFullQueueMessage(Queue<string> recipes)
{
Recipes = recipes;
}
}
/// <summary>
/// Sent to the server when a client queues a new recipe.
/// </summary>
[Serializable, NetSerializable]
public class LatheQueueRecipeMessage : BoundUserInterfaceMessage
{
public readonly string ID;
public readonly int Quantity;
public LatheQueueRecipeMessage(string id, int quantity)
{
ID = id;
Quantity = quantity;
}
}
[NetSerializable, Serializable]
public enum LatheUiKey
{
Key,
}
}
}