Generalized Store System (#10201)

This commit is contained in:
Nemanja
2022-08-17 00:34:25 -04:00
committed by GitHub
parent 1b50928d50
commit 2152914acc
68 changed files with 2493 additions and 1568 deletions

View File

@@ -2,29 +2,28 @@ using Content.Server.Instruments;
using Content.Server.Light.Components;
using Content.Server.Light.EntitySystems;
using Content.Server.Light.Events;
using Content.Server.Traitor.Uplink;
using Content.Server.Traitor.Uplink.Account;
using Content.Server.Traitor.Uplink.Components;
using Content.Server.PDA.Ringer;
using Content.Server.Station.Components;
using Content.Server.Store.Components;
using Content.Server.Store.Systems;
using Content.Server.Station.Systems;
using Content.Server.UserInterface;
using Content.Shared.PDA;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Content.Server.Mind.Components;
using Content.Server.Traitor;
namespace Content.Server.PDA
{
public sealed class PDASystem : SharedPDASystem
{
[Dependency] private readonly UplinkSystem _uplinkSystem = default!;
[Dependency] private readonly UplinkAccountsSystem _uplinkAccounts = default!;
[Dependency] private readonly UnpoweredFlashlightSystem _unpoweredFlashlight = default!;
[Dependency] private readonly RingerSystem _ringerSystem = default!;
[Dependency] private readonly InstrumentSystem _instrumentSystem = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly StoreSystem _storeSystem = default!;
public override void Initialize()
{
@@ -32,8 +31,8 @@ namespace Content.Server.PDA
SubscribeLocalEvent<PDAComponent, LightToggleEvent>(OnLightToggle);
SubscribeLocalEvent<PDAComponent, AfterActivatableUIOpenEvent>(AfterUIOpen);
SubscribeLocalEvent<PDAComponent, UplinkInitEvent>(OnUplinkInit);
SubscribeLocalEvent<PDAComponent, UplinkRemovedEvent>(OnUplinkRemoved);
SubscribeLocalEvent<PDAComponent, StoreAddedEvent>(OnUplinkInit);
SubscribeLocalEvent<PDAComponent, StoreRemovedEvent>(OnUplinkRemoved);
SubscribeLocalEvent<PDAComponent, GridModifiedEvent>(OnGridChanged);
}
@@ -74,12 +73,12 @@ namespace Content.Server.PDA
UpdatePDAUserInterface(pda);
}
private void OnUplinkInit(EntityUid uid, PDAComponent pda, UplinkInitEvent args)
private void OnUplinkInit(EntityUid uid, PDAComponent pda, StoreAddedEvent args)
{
UpdatePDAUserInterface(pda);
}
private void OnUplinkRemoved(EntityUid uid, PDAComponent pda, UplinkRemovedEvent args)
private void OnUplinkRemoved(EntityUid uid, PDAComponent pda, StoreRemovedEvent args)
{
UpdatePDAUserInterface(pda);
}
@@ -111,7 +110,7 @@ namespace Content.Server.PDA
// players. This should really use a sort of key-code entry system that selects an account which is not directly tied to
// a player entity.
if (!HasComp<UplinkComponent>(pda.Owner))
if (!TryComp<StoreComponent>(pda.Owner, out var storeComponent))
return;
var uplinkState = new PDAUpdateState(pda.FlashlightOn, pda.PenSlot.HasItem, ownerInfo, pda.StationName, true, hasInstrument);
@@ -121,7 +120,8 @@ namespace Content.Server.PDA
if (session.AttachedEntity is not EntityUid { Valid: true } user)
continue;
if (_uplinkAccounts.HasAccount(user))
if (storeComponent.AccountOwner == user || (TryComp<MindComponent>(session.AttachedEntity, out var mindcomp) && mindcomp.Mind != null &&
mindcomp.Mind.HasRole<TraitorRole>()))
ui.SetState(uplinkState, session);
}
}
@@ -143,8 +143,9 @@ namespace Content.Server.PDA
case PDAShowUplinkMessage _:
{
if (EntityManager.TryGetComponent(pda.Owner, out UplinkComponent? uplink))
_uplinkSystem.ToggleUplinkUI(uplink, msg.Session);
if (msg.Session.AttachedEntity != null &&
TryComp<StoreComponent>(pda.Owner, out var store))
_storeSystem.ToggleUi(msg.Session.AttachedEntity.Value, store);
break;
}
case PDAShowRingtoneMessage _:
@@ -170,8 +171,13 @@ namespace Content.Server.PDA
private void AfterUIOpen(EntityUid uid, PDAComponent pda, AfterActivatableUIOpenEvent args)
{
//TODO: this is awful
// A new user opened the UI --> Check if they are a traitor and should get a user specific UI state override.
if (!HasComp<UplinkComponent>(pda.Owner) || !_uplinkAccounts.HasAccount(args.User))
if (!TryComp<StoreComponent>(pda.Owner, out var storeComp))
return;
if (storeComp.AccountOwner != args.User &&
!(TryComp<MindComponent>(args.User, out var mindcomp) && mindcomp.Mind != null && mindcomp.Mind.HasRole<TraitorRole>()))
return;
if (!_uiSystem.TryGetUi(pda.Owner, PDAUiKey.Key, out var ui))