# Conflicts: # Content.IntegrationTests/Tests/PostMapInitTest.cs # Content.Server/Clothing/Systems/ChameleonClothingSystem.cs # Content.Server/PDA/PdaSystem.cs # Resources/Prototypes/Entities/Objects/Devices/pda.yml
117 lines
4.4 KiB
C#
117 lines
4.4 KiB
C#
using Content.Server.IdentityManagement;
|
||
using Content.Shared._Sunrise.Biocode;
|
||
using Content.Shared.Clothing.Components;
|
||
using Content.Shared.Clothing.EntitySystems;
|
||
using Content.Shared.IdentityManagement.Components;
|
||
using Content.Shared.Prototypes;
|
||
using Content.Shared.Verbs;
|
||
using Robust.Server.GameObjects;
|
||
using Robust.Shared.Player;
|
||
using Robust.Shared.Prototypes;
|
||
using Robust.Shared.Utility;
|
||
|
||
namespace Content.Server.Clothing.Systems;
|
||
|
||
public sealed class ChameleonClothingSystem : SharedChameleonClothingSystem
|
||
{
|
||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||
[Dependency] private readonly IComponentFactory _factory = default!;
|
||
[Dependency] private readonly IdentitySystem _identity = default!;
|
||
[Dependency] private readonly BiocodeSystem _biocodeSystem = default!;
|
||
|
||
public override void Initialize()
|
||
{
|
||
base.Initialize();
|
||
SubscribeLocalEvent<ChameleonClothingComponent, MapInitEvent>(OnMapInit);
|
||
SubscribeLocalEvent<ChameleonClothingComponent, GetVerbsEvent<InteractionVerb>>(OnVerb);
|
||
SubscribeLocalEvent<ChameleonClothingComponent, ChameleonPrototypeSelectedMessage>(OnSelected);
|
||
}
|
||
|
||
private void OnMapInit(EntityUid uid, ChameleonClothingComponent component, MapInitEvent args)
|
||
{
|
||
SetSelectedPrototype(uid, component.Default, true, component);
|
||
}
|
||
|
||
private void OnVerb(EntityUid uid, ChameleonClothingComponent component, GetVerbsEvent<InteractionVerb> args)
|
||
{
|
||
if (!args.CanAccess || !args.CanInteract) // || component.User != args.User // Sunrise-Edit: Не надо
|
||
return;
|
||
|
||
// Sunrise-Start
|
||
if (TryComp<BiocodeComponent>(uid, out var biocodedComponent))
|
||
{
|
||
if (!_biocodeSystem.CanUse(args.User, biocodedComponent.Factions))
|
||
return;
|
||
}
|
||
// Sunrise-End
|
||
|
||
args.Verbs.Add(new InteractionVerb()
|
||
{
|
||
Text = Loc.GetString("chameleon-component-verb-text"),
|
||
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/settings.svg.192dpi.png")),
|
||
Act = () => TryOpenUi(uid, args.User, component)
|
||
});
|
||
}
|
||
|
||
private void OnSelected(EntityUid uid, ChameleonClothingComponent component, ChameleonPrototypeSelectedMessage args)
|
||
{
|
||
SetSelectedPrototype(uid, args.SelectedId, component: component);
|
||
}
|
||
|
||
private void TryOpenUi(EntityUid uid, EntityUid user, ChameleonClothingComponent? component = null)
|
||
{
|
||
if (!Resolve(uid, ref component))
|
||
return;
|
||
if (!TryComp(user, out ActorComponent? actor))
|
||
return;
|
||
_uiSystem.TryToggleUi(uid, ChameleonUiKey.Key, actor.PlayerSession);
|
||
}
|
||
|
||
private void UpdateUi(EntityUid uid, ChameleonClothingComponent? component = null)
|
||
{
|
||
if (!Resolve(uid, ref component))
|
||
return;
|
||
|
||
var state = new ChameleonBoundUserInterfaceState(component.Slot, component.Default, component.RequireTag);
|
||
_uiSystem.SetUiState(uid, ChameleonUiKey.Key, state);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Change chameleon items name, description and sprite to mimic other entity prototype.
|
||
/// </summary>
|
||
public void SetSelectedPrototype(EntityUid uid, string? protoId, bool forceUpdate = false,
|
||
ChameleonClothingComponent? component = null)
|
||
{
|
||
if (!Resolve(uid, ref component, false))
|
||
return;
|
||
|
||
// check that wasn't already selected
|
||
// forceUpdate on component init ignores this check
|
||
if (component.Default == protoId && !forceUpdate)
|
||
return;
|
||
|
||
// make sure that it is valid change
|
||
if (string.IsNullOrEmpty(protoId) || !_proto.TryIndex(protoId, out EntityPrototype? proto))
|
||
return;
|
||
if (!IsValidTarget(proto, component.Slot, component.RequireTag))
|
||
return;
|
||
component.Default = protoId;
|
||
|
||
UpdateIdentityBlocker(uid, component, proto);
|
||
UpdateVisuals(uid, component);
|
||
UpdateUi(uid, component);
|
||
Dirty(uid, component);
|
||
}
|
||
|
||
private void UpdateIdentityBlocker(EntityUid uid, ChameleonClothingComponent component, EntityPrototype proto)
|
||
{
|
||
if (proto.HasComponent<IdentityBlockerComponent>(_factory))
|
||
EnsureComp<IdentityBlockerComponent>(uid);
|
||
else
|
||
RemComp<IdentityBlockerComponent>(uid);
|
||
|
||
if (component.User != null)
|
||
_identity.QueueIdentityUpdate(component.User.Value);
|
||
}
|
||
}
|