APC construction updated, uses electronics (#10987)

* APC construction and deconstruction
Construction action GivePrototype

* APC needs screwing + sprites

* apc framework, working construction recipe

* Energy swords hot

* APC changes

* APC construction/deconstruction

* removed comments

* Revert "Energy swords hot"

This reverts commit 75228483abb3cc6252118b319bc8949d5198362d.

* Renamed function for clarity

* Fixed the last step not showing in the construction menu

* Some fixes

* Update Content.Server/Power/EntitySystems/ApcSystem.cs

Co-authored-by: Jacob Tong <10494922+ShadowCommander@users.noreply.github.com>

* Update Content.Server/Construction/Completions/GivePrototype.cs

Co-authored-by: Jacob Tong <10494922+ShadowCommander@users.noreply.github.com>

* Update Resources/Prototypes/Entities/Structures/Power/apc.yml

Co-authored-by: Jacob Tong <10494922+ShadowCommander@users.noreply.github.com>

* Update Resources/Prototypes/Entities/Structures/Power/apc.yml

Co-authored-by: Jacob Tong <10494922+ShadowCommander@users.noreply.github.com>

* Update Content.Server/Power/Components/ApcElectronicsComponent.cs

Co-authored-by: Jacob Tong <10494922+ShadowCommander@users.noreply.github.com>

* Update Content.Client/Power/APC/ApcVisualizer.cs

Co-authored-by: Jacob Tong <10494922+ShadowCommander@users.noreply.github.com>

Co-authored-by: CommieFlowers <rasmus.cedergren@hotmail.com>
Co-authored-by: Jacob Tong <10494922+ShadowCommander@users.noreply.github.com>
This commit is contained in:
rolfero
2022-09-10 05:27:41 +02:00
committed by GitHub
parent e1a0de3bcf
commit d7b31865ff
13 changed files with 346 additions and 11 deletions

View File

@@ -0,0 +1,44 @@
using Content.Server.Stack;
using Content.Shared.Construction;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Prototypes;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Construction.Completions
{
[UsedImplicitly]
[DataDefinition]
public sealed class GivePrototype : IGraphAction
{
[DataField("prototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
public string Prototype { get; private set; } = string.Empty;
[DataField("amount")]
public int Amount { get; private set; } = 1;
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
{
if (string.IsNullOrEmpty(Prototype))
return;
var coordinates = entityManager.GetComponent<TransformComponent>(userUid ?? uid).Coordinates;
if (EntityPrototypeHelpers.HasComponent<StackComponent>(Prototype))
{
var stackEnt = entityManager.SpawnEntity(Prototype, coordinates);
var stack = entityManager.GetComponent<StackComponent>(stackEnt);
entityManager.EntitySysManager.GetEntitySystem<StackSystem>().SetCount(stackEnt, Amount, stack);
entityManager.EntitySysManager.GetEntitySystem<SharedHandsSystem>().PickupOrDrop(userUid, stackEnt);
}
else
{
for (var i = 0; i < Amount; i++)
{
var item = entityManager.SpawnEntity(Prototype, coordinates);
entityManager.EntitySysManager.GetEntitySystem<SharedHandsSystem>().PickupOrDrop(userUid, item);
}
}
}
}
}

View File

@@ -0,0 +1,51 @@
using Content.Server.Power.Components;
using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations;
namespace Content.Server.Construction.Conditions
{
[UsedImplicitly]
[DataDefinition]
public sealed class ApcPanel : IGraphCondition
{
[DataField("open")] public bool Open { get; private set; } = true;
public bool Condition(EntityUid uid, IEntityManager entityManager)
{
if (!entityManager.TryGetComponent(uid, out ApcComponent? apc))
return true;
return apc.IsApcOpen == Open;
}
public bool DoExamine(ExaminedEvent args)
{
var entity = args.Examined;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ApcComponent? apc)) return false;
switch (Open)
{
case true when !apc.IsApcOpen:
args.PushMarkup(Loc.GetString("construction-examine-condition-apc-open"));
return true;
case false when apc.IsApcOpen:
args.PushMarkup(Loc.GetString("construction-examine-condition-apc-close"));
return true;
}
return false;
}
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
{
yield return new ConstructionGuideEntry()
{
Localization = Open
? "construction-step-condition-apc-open"
: "construction-step-condition-apc-close"
};
}
}
}

View File

@@ -6,7 +6,6 @@ using Robust.Shared.Audio;
namespace Content.Server.Power.Components;
[RegisterComponent]
[Access(typeof(ApcSystem))]
public sealed class ApcComponent : BaseApcNetComponent
{
[DataField("onReceiveMessageSound")]
@@ -16,6 +15,13 @@ public sealed class ApcComponent : BaseApcNetComponent
public ApcChargeState LastChargeState;
public TimeSpan LastChargeStateTime;
/// <summary>
/// Is the panel open for this entity's APC?
/// </summary>
[ViewVariables]
[DataField("open")]
public bool IsApcOpen { get; set; }
[ViewVariables]
public ApcExternalPowerState LastExternalState;
public TimeSpan LastUiUpdate;
@@ -38,4 +44,11 @@ public sealed class ApcComponent : BaseApcNetComponent
{
apcNet.RemoveApc(this);
}
[DataField("screwdriverOpenSound")]
public SoundSpecifier ScrewdriverOpenSound = new SoundPathSpecifier("/Audio/Machines/screwdriveropen.ogg");
[DataField("screwdriverCloseSound")]
public SoundSpecifier ScrewdriverCloseSound = new SoundPathSpecifier("/Audio/Machines/screwdriverclose.ogg");
}

View File

@@ -0,0 +1,11 @@
using Robust.Shared.GameStates;
namespace Content.Server.Power.Components
{
[RegisterComponent]
/// <summary>
/// This object is an APC electronics, used for constructing APCs
/// </summary>
public sealed class ApcElectronicsComponent : Component
{ }
}

View File

@@ -1,10 +1,16 @@
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Tools;
using Content.Server.Wires;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.APC;
using Content.Shared.Emag.Systems;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Tools.Components;
using Content.Shared.Wires;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
@@ -20,6 +26,9 @@ namespace Content.Server.Power.EntitySystems
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly ToolSystem _toolSystem = default!;
private const float ScrewTime = 2f;
public override void Initialize()
{
@@ -31,6 +40,10 @@ namespace Content.Server.Power.EntitySystems
SubscribeLocalEvent<ApcComponent, ChargeChangedEvent>(OnBatteryChargeChanged);
SubscribeLocalEvent<ApcComponent, ApcToggleMainBreakerMessage>(OnToggleMainBreaker);
SubscribeLocalEvent<ApcComponent, GotEmaggedEvent>(OnEmagged);
SubscribeLocalEvent<ApcToolFinishedEvent>(OnToolFinished);
SubscribeLocalEvent<ApcComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<ApcComponent, ExaminedEvent>(OnExamine);
}
// Change the APC's state only when the battery state changes, or when it's first created.
@@ -88,13 +101,18 @@ namespace Content.Server.Power.EntitySystems
if (!Resolve(uid, ref apc, ref battery))
return;
if (TryComp(uid, out AppearanceComponent? appearance))
{
UpdatePanelAppearance(uid, appearance, apc);
}
var newState = CalcChargeState(uid, apc, battery);
if (newState != apc.LastChargeState && apc.LastChargeStateTime + ApcComponent.VisualsChangeDelay < _gameTiming.CurTime)
{
apc.LastChargeState = newState;
apc.LastChargeStateTime = _gameTiming.CurTime;
if (TryComp(uid, out AppearanceComponent? appearance))
if (appearance != null)
{
appearance.SetData(ApcVisuals.ChargeState, newState);
}
@@ -168,5 +186,69 @@ namespace Content.Server.Power.EntitySystems
return ApcExternalPowerState.Good;
}
public static ApcPanelState GetPanelState(ApcComponent apc)
{
if (apc.IsApcOpen)
return ApcPanelState.Open;
else
return ApcPanelState.Closed;
}
private void OnInteractUsing(EntityUid uid, ApcComponent component, InteractUsingEvent args)
{
if (!EntityManager.TryGetComponent(args.Used, out ToolComponent? tool))
return;
if (_toolSystem.UseTool(args.Used, args.User, uid, 0f, ScrewTime, new string[] { "Screwing" }, doAfterCompleteEvent: new ApcToolFinishedEvent(uid), toolComponent: tool))
{
args.Handled = true;
}
}
private void OnToolFinished(ApcToolFinishedEvent args)
{
if (!EntityManager.TryGetComponent(args.Target, out ApcComponent? component))
return;
component.IsApcOpen = !component.IsApcOpen;
if (TryComp(args.Target, out AppearanceComponent? appearance))
{
UpdatePanelAppearance(args.Target, appearance);
}
if (component.IsApcOpen)
{
SoundSystem.Play(component.ScrewdriverOpenSound.GetSound(), Filter.Pvs(args.Target), args.Target);
}
else
{
SoundSystem.Play(component.ScrewdriverCloseSound.GetSound(), Filter.Pvs(args.Target), args.Target);
}
}
private void UpdatePanelAppearance(EntityUid uid, AppearanceComponent? appearance = null, ApcComponent? apc = null)
{
if (!Resolve(uid, ref appearance, ref apc, false))
return;
appearance.SetData(ApcVisuals.PanelState, GetPanelState(apc));
}
private sealed class ApcToolFinishedEvent : EntityEventArgs
{
public EntityUid Target { get; }
public ApcToolFinishedEvent(EntityUid target)
{
Target = target;
}
}
private void OnExamine(EntityUid uid, ApcComponent component, ExaminedEvent args)
{
args.PushMarkup(Loc.GetString(component.IsApcOpen
? "apc-component-on-examine-panel-open"
: "apc-component-on-examine-panel-closed"));
}
}
}