2022-12-19 22:36:08 -05:00
|
|
|
using System.Linq;
|
2022-06-28 10:41:08 -04:00
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Server.Popups;
|
2022-12-19 22:36:08 -05:00
|
|
|
using Content.Shared.Research.Prototypes;
|
2022-12-19 16:14:02 -05:00
|
|
|
using Content.Server.Research.Systems;
|
2022-12-25 16:22:23 -05:00
|
|
|
using Content.Shared.Research.Components;
|
2022-12-19 22:36:08 -05:00
|
|
|
using Robust.Shared.Prototypes;
|
2022-06-28 10:41:08 -04:00
|
|
|
|
|
|
|
|
namespace Content.Server.Research.Disk
|
|
|
|
|
{
|
|
|
|
|
public sealed class ResearchDiskSystem : EntitySystem
|
|
|
|
|
{
|
2022-12-19 22:36:08 -05:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
2022-06-28 10:41:08 -04:00
|
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
2022-12-19 16:14:02 -05:00
|
|
|
[Dependency] private readonly ResearchSystem _research = default!;
|
2022-06-28 10:41:08 -04:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<ResearchDiskComponent, AfterInteractEvent>(OnAfterInteract);
|
2022-12-19 22:36:08 -05:00
|
|
|
SubscribeLocalEvent<ResearchDiskComponent, MapInitEvent>(OnMapInit);
|
2022-06-28 10:41:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAfterInteract(EntityUid uid, ResearchDiskComponent component, AfterInteractEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!args.CanReach)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!TryComp<ResearchServerComponent>(args.Target, out var server))
|
|
|
|
|
return;
|
|
|
|
|
|
2023-05-15 16:17:30 -04:00
|
|
|
_research.ModifyServerPoints(args.Target.Value, component.Points, server);
|
2022-12-19 10:41:47 +13:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("research-disk-inserted", ("points", component.Points)), args.Target.Value, args.User);
|
2022-06-28 10:41:08 -04:00
|
|
|
EntityManager.QueueDeleteEntity(uid);
|
|
|
|
|
}
|
2022-12-19 22:36:08 -05:00
|
|
|
|
|
|
|
|
private void OnMapInit(EntityUid uid, ResearchDiskComponent component, MapInitEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!component.UnlockAllTech)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
component.Points = _prototype.EnumeratePrototypes<TechnologyPrototype>()
|
2023-05-15 16:17:30 -04:00
|
|
|
.Sum(tech => tech.Cost);
|
2022-12-19 22:36:08 -05:00
|
|
|
}
|
2022-06-28 10:41:08 -04:00
|
|
|
}
|
|
|
|
|
}
|