Technology Disks (#13077)
* clean up a bunch of R&D code * don't store components * brug * speedrun some sloth review * technology disks * expand functionality, begin work on printer * disk printer ui * file * fix the rebase * disk console is finito * Update DiskConsoleSystem.cs
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
using Content.Shared.Research.Prototypes;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
|
||||
namespace Content.Shared.Research.Components
|
||||
{
|
||||
[NetworkedComponent()]
|
||||
public abstract class SharedTechnologyDatabaseComponent : Component
|
||||
{
|
||||
[DataField("technologies", customTypeSerializer: typeof(PrototypeIdListSerializer<TechnologyPrototype>))]
|
||||
public readonly List<string> TechnologyIds = new();
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a technology is unlocked on this database or not.
|
||||
/// </summary>
|
||||
/// <param name="technology">The technology to be checked</param>
|
||||
/// <returns>Whether it is unlocked or not</returns>
|
||||
public bool IsTechnologyUnlocked(string technologyId)
|
||||
{
|
||||
return TechnologyIds.Contains(technologyId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a technology can be unlocked on this database,
|
||||
/// taking parent technologies into account.
|
||||
/// </summary>
|
||||
/// <param name="technology">The technology to be checked</param>
|
||||
/// <returns>Whether it could be unlocked or not</returns>
|
||||
public bool CanUnlockTechnology(TechnologyPrototype technology)
|
||||
{
|
||||
if (IsTechnologyUnlocked(technology.ID)) return false;
|
||||
var protoMan = IoCManager.Resolve<IPrototypeManager>();
|
||||
foreach (var technologyId in technology.RequiredTechnologies)
|
||||
{
|
||||
protoMan.TryIndex(technologyId, out TechnologyPrototype? requiredTechnology);
|
||||
if (requiredTechnology == null)
|
||||
return false;
|
||||
|
||||
if (!IsTechnologyUnlocked(requiredTechnology.ID))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class TechnologyDatabaseState : ComponentState
|
||||
{
|
||||
public List<string> Technologies;
|
||||
public TechnologyDatabaseState(List<string> technologies)
|
||||
{
|
||||
Technologies = technologies;
|
||||
}
|
||||
|
||||
public TechnologyDatabaseState(List<TechnologyPrototype> technologies)
|
||||
{
|
||||
Technologies = new List<string>();
|
||||
foreach (var technology in technologies)
|
||||
{
|
||||
Technologies.Add(technology.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Content.Shared.Research.Prototypes;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
|
||||
namespace Content.Shared.Research.Components
|
||||
{
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class TechnologyDatabaseComponent : Component
|
||||
{
|
||||
[DataField("technologyIds", customTypeSerializer: typeof(PrototypeIdListSerializer<TechnologyPrototype>))]
|
||||
public List<string> TechnologyIds = new();
|
||||
|
||||
[DataField("recipeIds", customTypeSerializer: typeof(PrototypeIdListSerializer<LatheRecipePrototype>))]
|
||||
public List<string> RecipeIds = new();
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class TechnologyDatabaseState : ComponentState
|
||||
{
|
||||
public List<string> Technologies;
|
||||
public List<string> Recipes;
|
||||
|
||||
public TechnologyDatabaseState(List<string> technologies, List<string> recipes)
|
||||
{
|
||||
Technologies = technologies;
|
||||
Recipes = recipes;
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Content.Shared/Research/SharedDiskConsole.cs
Normal file
30
Content.Shared/Research/SharedDiskConsole.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Research;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum DiskConsoleUiKey : byte
|
||||
{
|
||||
Key
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class DiskConsoleBoundUserInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
public bool CanPrint;
|
||||
public int PointCost;
|
||||
public int ServerPoints;
|
||||
|
||||
public DiskConsoleBoundUserInterfaceState(int serverPoints, int pointCost, bool canPrint)
|
||||
{
|
||||
CanPrint = canPrint;
|
||||
PointCost = pointCost;
|
||||
ServerPoints = serverPoints;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class DiskConsolePrintDiskMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
|
||||
}
|
||||
75
Content.Shared/Research/Systems/SharedResearchSystem.cs
Normal file
75
Content.Shared/Research/Systems/SharedResearchSystem.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Content.Shared.Research.Components;
|
||||
using Content.Shared.Research.Prototypes;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Research.Systems;
|
||||
|
||||
public abstract class SharedResearchSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<TechnologyDatabaseComponent, ComponentGetState>(OnTechnologyGetState);
|
||||
SubscribeLocalEvent<TechnologyDatabaseComponent, ComponentHandleState>(OnTechnologyHandleState);
|
||||
}
|
||||
|
||||
private void OnTechnologyHandleState(EntityUid uid, TechnologyDatabaseComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not TechnologyDatabaseState state)
|
||||
return;
|
||||
component.TechnologyIds = new (state.Technologies);
|
||||
component.RecipeIds = new(state.Recipes);
|
||||
}
|
||||
|
||||
private void OnTechnologyGetState(EntityUid uid, TechnologyDatabaseComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new TechnologyDatabaseState(component.TechnologyIds, component.RecipeIds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a technology is unlocked on this database or not.
|
||||
/// </summary>
|
||||
/// <returns>Whether it is unlocked or not</returns>
|
||||
public bool IsTechnologyUnlocked(EntityUid uid, string technologyId, TechnologyDatabaseComponent? component = null)
|
||||
{
|
||||
return Resolve(uid, ref component) && component.TechnologyIds.Contains(technologyId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a technology is unlocked on this database or not.
|
||||
/// </summary>
|
||||
/// <returns>Whether it is unlocked or not</returns>
|
||||
public bool IsTechnologyUnlocked(EntityUid uid, TechnologyPrototype technologyId, TechnologyDatabaseComponent? component = null)
|
||||
{
|
||||
return Resolve(uid, ref component) && IsTechnologyUnlocked(uid, technologyId.ID, component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a technology can be unlocked on this database,
|
||||
/// taking parent technologies into account.
|
||||
/// </summary>
|
||||
/// <returns>Whether it could be unlocked or not</returns>
|
||||
public bool CanUnlockTechnology(EntityUid uid, TechnologyPrototype technology, TechnologyDatabaseComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return false;
|
||||
|
||||
if (IsTechnologyUnlocked(uid, technology.ID, component))
|
||||
return false;
|
||||
|
||||
foreach (var technologyId in technology.RequiredTechnologies)
|
||||
{
|
||||
_prototypeManager.TryIndex(technologyId, out TechnologyPrototype? requiredTechnology);
|
||||
if (requiredTechnology == null)
|
||||
return false;
|
||||
|
||||
if (!IsTechnologyUnlocked(uid, requiredTechnology.ID, component))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user