2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Research.Prototypes;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2019-09-03 22:51:19 +02:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Serialization;
|
2022-11-03 02:41:12 +01:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
2019-09-03 22:51:19 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Research.Components
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2022-11-03 02:41:12 +01:00
|
|
|
public abstract class SharedTechnologyDatabaseComponent : Component
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
2022-11-03 02:41:12 +01:00
|
|
|
[DataField("technologies", customTypeSerializer: typeof(PrototypeIdListSerializer<TechnologyPrototype>))]
|
|
|
|
|
public readonly List<string> TechnologyIds = new();
|
2019-09-03 22:51:19 +02:00
|
|
|
|
|
|
|
|
/// <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>
|
2022-11-03 02:41:12 +01:00
|
|
|
public bool IsTechnologyUnlocked(string technologyId)
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
2022-11-03 02:41:12 +01:00
|
|
|
return TechnologyIds.Contains(technologyId);
|
2019-09-03 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2022-11-03 02:41:12 +01:00
|
|
|
if (IsTechnologyUnlocked(technology.ID)) return false;
|
2019-09-03 22:51:19 +02:00
|
|
|
var protoMan = IoCManager.Resolve<IPrototypeManager>();
|
|
|
|
|
foreach (var technologyId in technology.RequiredTechnologies)
|
|
|
|
|
{
|
2021-02-27 04:12:09 +01:00
|
|
|
protoMan.TryIndex(technologyId, out TechnologyPrototype? requiredTechnology);
|
2019-09-03 22:51:19 +02:00
|
|
|
if (requiredTechnology == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-11-03 02:41:12 +01:00
|
|
|
if (!IsTechnologyUnlocked(requiredTechnology.ID))
|
2019-09-03 22:51:19 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class TechnologyDatabaseState : ComponentState
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
|
|
|
|
public List<string> Technologies;
|
2021-07-12 01:32:10 -07:00
|
|
|
public TechnologyDatabaseState(List<string> technologies)
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
2019-09-06 15:25:07 +02:00
|
|
|
Technologies = technologies;
|
2019-09-03 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-12 01:32:10 -07:00
|
|
|
public TechnologyDatabaseState(List<TechnologyPrototype> technologies)
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
|
|
|
|
Technologies = new List<string>();
|
|
|
|
|
foreach (var technology in technologies)
|
|
|
|
|
{
|
|
|
|
|
Technologies.Add(technology.ID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|