From 1b691264f3fb6c3a4487897ca927e8cbbe51af15 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Tue, 29 Sep 2020 16:05:29 +0200 Subject: [PATCH] Improve "give AA ID". Renamed to "grant full access" (same as in SS13). Now tries to upgrade an ID the user has equipped and automatically equips if necessary. --- Content.Client/Sandbox/SandboxManager.cs | 2 +- .../Components/PDA/PDAComponent.cs | 2 +- Content.Server/Sandbox/SandboxManager.cs | 68 +++++++++++++++++-- 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/Content.Client/Sandbox/SandboxManager.cs b/Content.Client/Sandbox/SandboxManager.cs index 5eb42e92c8..bc36ba957c 100644 --- a/Content.Client/Sandbox/SandboxManager.cs +++ b/Content.Client/Sandbox/SandboxManager.cs @@ -51,7 +51,7 @@ namespace Content.Client.Sandbox SpawnTilesButton = new Button { Text = Loc.GetString("Spawn Tiles") }; vBox.AddChild(SpawnTilesButton); - GiveFullAccessButton = new Button { Text = Loc.GetString("Give AA Id") }; + GiveFullAccessButton = new Button { Text = Loc.GetString("Grant Full Access") }; vBox.AddChild(GiveFullAccessButton); GiveAghostButton = new Button { Text = Loc.GetString("Ghost") }; diff --git a/Content.Server/GameObjects/Components/PDA/PDAComponent.cs b/Content.Server/GameObjects/Components/PDA/PDAComponent.cs index 379b56a8df..b25fc1b2f1 100644 --- a/Content.Server/GameObjects/Components/PDA/PDAComponent.cs +++ b/Content.Server/GameObjects/Components/PDA/PDAComponent.cs @@ -216,7 +216,7 @@ namespace Content.Server.GameObjects.Components.PDA UpdatePDAUserInterface(); } - private void InsertIdCard(IdCardComponent card) + public void InsertIdCard(IdCardComponent card) { _idSlot.Insert(card.Owner); ContainedID = card; diff --git a/Content.Server/Sandbox/SandboxManager.cs b/Content.Server/Sandbox/SandboxManager.cs index 192f7bfe0c..4516b17a00 100644 --- a/Content.Server/Sandbox/SandboxManager.cs +++ b/Content.Server/Sandbox/SandboxManager.cs @@ -1,9 +1,14 @@ +using System.Linq; +using Content.Server.GameObjects.Components.Access; using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.Items.Storage; +using Content.Server.GameObjects.Components.PDA; using Content.Server.GameTicking; using Content.Server.Interfaces.GameTicking; +using Content.Shared.Access; using Content.Shared.Sandbox; using Robust.Server.Console; +using Robust.Server.GameObjects; using Robust.Server.Interfaces.Console; using Robust.Server.Interfaces.Placement; using Robust.Server.Interfaces.Player; @@ -12,7 +17,9 @@ using Robust.Shared.Enums; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Network; using Robust.Shared.IoC; +using Robust.Shared.Prototypes; using Robust.Shared.ViewVariables; +using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines; namespace Content.Server.Sandbox { @@ -103,18 +110,67 @@ namespace Content.Server.Sandbox private void SandboxGiveAccessReceived(MsgSandboxGiveAccess message) { - if(!IsSandboxEnabled) + if (!IsSandboxEnabled) { return; } var player = _playerManager.GetSessionByChannel(message.MsgChannel); - if(player.AttachedEntity.TryGetComponent(out var hands)) + if (player.AttachedEntity == null) { - ; - hands.PutInHandOrDrop( - _entityManager.SpawnEntity("CaptainIDCard", - player.AttachedEntity.Transform.Coordinates).GetComponent()); + return; + } + + var allAccess = IoCManager.Resolve() + .EnumeratePrototypes() + .Select(p => p.ID).ToArray(); + + if (player.AttachedEntity.TryGetComponent(out InventoryComponent inv) + && inv.TryGetSlotItem(Slots.IDCARD, out ItemComponent wornItem)) + { + if (wornItem.Owner.HasComponent()) + { + UpgradeId(wornItem.Owner); + } + else if (wornItem.Owner.TryGetComponent(out PDAComponent pda)) + { + if (pda.ContainedID == null) + { + pda.InsertIdCard(CreateFreshId().GetComponent()); + } + else + { + UpgradeId(pda.ContainedID.Owner); + } + } + } + else if (player.AttachedEntity.TryGetComponent(out var hands)) + { + var card = CreateFreshId(); + if (!player.AttachedEntity.TryGetComponent(out inv) || !inv.Equip(Slots.IDCARD, card)) + { + hands.PutInHandOrDrop(card.GetComponent()); + } + } + + void UpgradeId(IEntity id) + { + var access = id.GetComponent(); + access.SetTags(allAccess); + + if (id.TryGetComponent(out SpriteComponent sprite)) + { + sprite.LayerSetState(0, "gold"); + } + } + + IEntity CreateFreshId() + { + var card = _entityManager.SpawnEntity("CaptainIDCard", player.AttachedEntity.Transform.Coordinates); + UpgradeId(card); + + card.GetComponent().FullName = player.AttachedEntity.Name; + return card; } }