mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Scope creep my ass * why was this shit not pushed???? * gone... * fix that * review plus buildd * asfsafsafsafsafas * grug * burber * I'll fix this later * shrimply die * also this * it's snerf or snuthin * assaads * round snend * aaaa * fix this shit for real * actually, don't start GameRules until MapInit now that I think aboot it. * forgot u * don't actually need this part nullable * Deffer comp removal * one liner * do that too * chungus * Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?) * deferred removal :V * aaaaaaaaaaaaaaa * whhop * Whoop * better * landmine that I placed for myself then forgot about lmao * cleanup * FUCKING `!` * gotovo * amogus * please don't check by metadata I beg * waawsasfdfsasfa * sfafsasfafsas * fdsaasffsasfa * code * fix * fasasffasfasfsad * chungaas * I may be stupid * gra * graaaaaaaaaaaaaaaaa * comment * gra * clearing is not predicted and would require major refactors, so don't cache on client. * lame shit :P * last holes * nukeopsfsafsasafsfafsa * why was that shit public bruh * bubrbgwahrghfaka * dynamic * revert change that did nothing lmao
102 lines
4 KiB
C#
102 lines
4 KiB
C#
using Content.Shared.Access.Components;
|
|
using Content.Shared.Access.Systems;
|
|
using Content.Shared.Containers.ItemSlots;
|
|
using Robust.Shared.Containers;
|
|
|
|
namespace Content.Shared.PDA
|
|
{
|
|
public abstract partial class SharedPdaSystem : EntitySystem
|
|
{
|
|
[Dependency] protected ItemSlotsSystem ItemSlotsSystem = default!;
|
|
[Dependency] protected SharedAppearanceSystem Appearance = default!;
|
|
[Dependency] private SharedJobStatusSystem _jobStatus = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<PdaComponent, ComponentInit>(OnComponentInit);
|
|
SubscribeLocalEvent<PdaComponent, ComponentRemove>(OnComponentRemove);
|
|
|
|
SubscribeLocalEvent<PdaComponent, EntInsertedIntoContainerMessage>(OnItemInserted);
|
|
SubscribeLocalEvent<PdaComponent, EntRemovedFromContainerMessage>(OnItemRemoved);
|
|
|
|
SubscribeLocalEvent<PdaComponent, GetAdditionalAccessEvent>(OnGetAdditionalAccess);
|
|
}
|
|
protected virtual void OnComponentInit(EntityUid uid, PdaComponent pda, ComponentInit args)
|
|
{
|
|
if (pda.IdCard != null)
|
|
pda.IdSlot.StartingItem = pda.IdCard;
|
|
|
|
ItemSlotsSystem.AddItemSlot(uid, PdaComponent.PdaIdSlotId, pda.IdSlot);
|
|
ItemSlotsSystem.AddItemSlot(uid, PdaComponent.PdaPenSlotId, pda.PenSlot);
|
|
ItemSlotsSystem.AddItemSlot(uid, PdaComponent.PdaPaiSlotId, pda.PaiSlot);
|
|
|
|
UpdatePdaAppearance(uid, pda);
|
|
}
|
|
|
|
private void OnComponentRemove(EntityUid uid, PdaComponent pda, ComponentRemove args)
|
|
{
|
|
ItemSlotsSystem.RemoveItemSlot(uid, pda.IdSlot);
|
|
ItemSlotsSystem.RemoveItemSlot(uid, pda.PenSlot);
|
|
ItemSlotsSystem.RemoveItemSlot(uid, pda.PaiSlot);
|
|
}
|
|
|
|
protected virtual void OnItemInserted(EntityUid uid, PdaComponent pda, EntInsertedIntoContainerMessage args)
|
|
{
|
|
if (args.Container.ID == PdaComponent.PdaIdSlotId)
|
|
pda.ContainedId = args.Entity;
|
|
|
|
UpdatePdaAppearance(uid, pda);
|
|
UpdateJobStatus(uid);
|
|
}
|
|
|
|
protected virtual void OnItemRemoved(EntityUid uid, PdaComponent pda, EntRemovedFromContainerMessage args)
|
|
{
|
|
if (args.Container.ID == pda.IdSlot.ID)
|
|
pda.ContainedId = null;
|
|
|
|
UpdatePdaAppearance(uid, pda);
|
|
UpdateJobStatus(uid);
|
|
}
|
|
|
|
private void OnGetAdditionalAccess(EntityUid uid, PdaComponent component, ref GetAdditionalAccessEvent args)
|
|
{
|
|
if (component.ContainedId is { } id)
|
|
args.Entities.Add(id);
|
|
}
|
|
|
|
private void UpdatePdaAppearance(EntityUid uid, PdaComponent pda)
|
|
{
|
|
Appearance.SetData(uid, PdaVisuals.IdCardInserted, pda.ContainedId != null);
|
|
}
|
|
|
|
// update the status icon of the player that has the pda currently equipped
|
|
private void UpdateJobStatus(EntityUid uid)
|
|
{
|
|
// Only the player who has the pda currently equipped can insert or remove Ids
|
|
var parent = Transform(uid).ParentUid;
|
|
_jobStatus.UpdateStatus(parent);
|
|
}
|
|
|
|
public virtual void UpdatePdaUi(EntityUid uid, PdaComponent? pda = null)
|
|
{
|
|
// This does nothing yet while I finish up PDA prediction
|
|
// Overriden by the server
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the owner of a PDA to a given entity, with a given name.
|
|
/// </summary>
|
|
/// <param name="uid">Pda Entity</param>
|
|
/// <param name="pda">Pda Component</param>
|
|
/// <param name="owner">New entity owner of the PDA, this is probably an ID card</param>
|
|
/// <param name="ownerName">Name of the new owner, this is probably the name on the ID card</param>
|
|
public void SetOwner(EntityUid uid, PdaComponent pda, EntityUid owner, string ownerName)
|
|
{
|
|
pda.OwnerName = ownerName;
|
|
pda.PdaOwner = owner;
|
|
UpdatePdaUi(uid, pda);
|
|
}
|
|
}
|
|
}
|