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

@@ -1,6 +1,7 @@
using Content.Shared.APC; using Content.Shared.APC;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.State;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Maths; using Robust.Shared.Maths;
@@ -22,6 +23,9 @@ namespace Content.Client.Power.APC
var sprite = IoCManager.Resolve<IEntityManager>().GetComponent<ISpriteComponent>(entity); var sprite = IoCManager.Resolve<IEntityManager>().GetComponent<ISpriteComponent>(entity);
sprite.LayerMapSet(Layers.Panel, sprite.AddLayerState("apc0"));
sprite.LayerSetShader(Layers.Panel, "unshaded");
sprite.LayerMapSet(Layers.ChargeState, sprite.AddLayerState("apco3-0")); sprite.LayerMapSet(Layers.ChargeState, sprite.AddLayerState("apco3-0"));
sprite.LayerSetShader(Layers.ChargeState, "unshaded"); sprite.LayerSetShader(Layers.ChargeState, "unshaded");
@@ -45,9 +49,21 @@ namespace Content.Client.Power.APC
var ent = IoCManager.Resolve<IEntityManager>(); var ent = IoCManager.Resolve<IEntityManager>();
var sprite = ent.GetComponent<ISpriteComponent>(component.Owner); var sprite = ent.GetComponent<ISpriteComponent>(component.Owner);
if (component.TryGetData<ApcChargeState>(ApcVisuals.ChargeState, out var state)) if (component.TryGetData<ApcPanelState>(ApcVisuals.PanelState, out var panelState))
{ {
switch (state) switch (panelState)
{
case ApcPanelState.Closed:
sprite.LayerSetState(Layers.Panel, "apc0");
break;
case ApcPanelState.Open:
sprite.LayerSetState(Layers.Panel, "apcframe");
break;
}
}
if (component.TryGetData<ApcChargeState>(ApcVisuals.ChargeState, out var chargeState))
{
switch (chargeState)
{ {
case ApcChargeState.Lack: case ApcChargeState.Lack:
sprite.LayerSetState(Layers.ChargeState, "apco3-0"); sprite.LayerSetState(Layers.ChargeState, "apco3-0");
@@ -65,7 +81,7 @@ namespace Content.Client.Power.APC
if (ent.TryGetComponent(component.Owner, out SharedPointLightComponent? light)) if (ent.TryGetComponent(component.Owner, out SharedPointLightComponent? light))
{ {
light.Color = state switch light.Color = chargeState switch
{ {
ApcChargeState.Lack => LackColor, ApcChargeState.Lack => LackColor,
ApcChargeState.Charging => ChargingColor, ApcChargeState.Charging => ChargingColor,
@@ -88,6 +104,7 @@ namespace Content.Client.Power.APC
Equipment, Equipment,
Lighting, Lighting,
Environment, Environment,
Panel,
} }
} }
} }

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; namespace Content.Server.Power.Components;
[RegisterComponent] [RegisterComponent]
[Access(typeof(ApcSystem))]
public sealed class ApcComponent : BaseApcNetComponent public sealed class ApcComponent : BaseApcNetComponent
{ {
[DataField("onReceiveMessageSound")] [DataField("onReceiveMessageSound")]
@@ -16,6 +15,13 @@ public sealed class ApcComponent : BaseApcNetComponent
public ApcChargeState LastChargeState; public ApcChargeState LastChargeState;
public TimeSpan LastChargeStateTime; public TimeSpan LastChargeStateTime;
/// <summary>
/// Is the panel open for this entity's APC?
/// </summary>
[ViewVariables]
[DataField("open")]
public bool IsApcOpen { get; set; }
[ViewVariables] [ViewVariables]
public ApcExternalPowerState LastExternalState; public ApcExternalPowerState LastExternalState;
public TimeSpan LastUiUpdate; public TimeSpan LastUiUpdate;
@@ -38,4 +44,11 @@ public sealed class ApcComponent : BaseApcNetComponent
{ {
apcNet.RemoveApc(this); 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.Popups;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Server.Tools;
using Content.Server.Wires;
using Content.Shared.Access.Components; using Content.Shared.Access.Components;
using Content.Shared.Access.Systems; using Content.Shared.Access.Systems;
using Content.Shared.APC; using Content.Shared.APC;
using Content.Shared.Emag.Systems; using Content.Shared.Emag.Systems;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Tools.Components;
using Content.Shared.Wires;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.Audio;
@@ -20,6 +26,9 @@ namespace Content.Server.Power.EntitySystems
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!; [Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly ToolSystem _toolSystem = default!;
private const float ScrewTime = 2f;
public override void Initialize() public override void Initialize()
{ {
@@ -31,6 +40,10 @@ namespace Content.Server.Power.EntitySystems
SubscribeLocalEvent<ApcComponent, ChargeChangedEvent>(OnBatteryChargeChanged); SubscribeLocalEvent<ApcComponent, ChargeChangedEvent>(OnBatteryChargeChanged);
SubscribeLocalEvent<ApcComponent, ApcToggleMainBreakerMessage>(OnToggleMainBreaker); SubscribeLocalEvent<ApcComponent, ApcToggleMainBreakerMessage>(OnToggleMainBreaker);
SubscribeLocalEvent<ApcComponent, GotEmaggedEvent>(OnEmagged); 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. // 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)) if (!Resolve(uid, ref apc, ref battery))
return; return;
if (TryComp(uid, out AppearanceComponent? appearance))
{
UpdatePanelAppearance(uid, appearance, apc);
}
var newState = CalcChargeState(uid, apc, battery); var newState = CalcChargeState(uid, apc, battery);
if (newState != apc.LastChargeState && apc.LastChargeStateTime + ApcComponent.VisualsChangeDelay < _gameTiming.CurTime) if (newState != apc.LastChargeState && apc.LastChargeStateTime + ApcComponent.VisualsChangeDelay < _gameTiming.CurTime)
{ {
apc.LastChargeState = newState; apc.LastChargeState = newState;
apc.LastChargeStateTime = _gameTiming.CurTime; apc.LastChargeStateTime = _gameTiming.CurTime;
if (TryComp(uid, out AppearanceComponent? appearance)) if (appearance != null)
{ {
appearance.SetData(ApcVisuals.ChargeState, newState); appearance.SetData(ApcVisuals.ChargeState, newState);
} }
@@ -168,5 +186,69 @@ namespace Content.Server.Power.EntitySystems
return ApcExternalPowerState.Good; 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"));
}
} }
} }

View File

@@ -1,11 +1,32 @@
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
namespace Content.Shared.APC namespace Content.Shared.APC
{ {
[Serializable, NetSerializable] [Serializable, NetSerializable]
public enum ApcVisuals public enum ApcVisuals
{ {
ChargeState /// <summary>
/// APC lights/HUD.
/// </summary>
ChargeState,
/// <summary>
/// APC frame.
/// </summary>
PanelState
}
[Serializable, NetSerializable]
public enum ApcPanelState
{
/// <summary>
/// APC is closed.
/// </summary>
Closed,
/// <summary>
/// APC opened.
/// </summary>
Open
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -1 +1,3 @@
apc-component-insufficient-access = Insufficient access! apc-component-insufficient-access = Insufficient access!
apc-component-on-examine-panel-open = The [color=lightgray]APC electronics panel[/color] is [color=red]open[/color].
apc-component-on-examine-panel-closed = The [color=lightgray]APC electronics panel[/color] is [color=darkgreen]closed[/color].

View File

@@ -0,0 +1,5 @@
# APC
construction-examine-condition-apc-open = First, screw open the APC.
construction-examine-condition-apc-close = First, screw shut the APC.
construction-step-condition-apc-open = The APC electronics panel must be screwed open.
construction-step-condition-apc-close = The APC electronics panel must be screwed shut.

View File

@@ -5,6 +5,7 @@
name: APC electronics name: APC electronics
description: Circuit used in APC construction. description: Circuit used in APC construction.
components: components:
- type: ApcElectronics
- type: Sprite - type: Sprite
sprite: Objects/Misc/module.rsi sprite: Objects/Misc/module.rsi
state: charger_APC state: charger_APC

View File

@@ -93,6 +93,61 @@
acts: [ "Destruction" ] acts: [ "Destruction" ]
- type: StationInfiniteBatteryTarget - type: StationInfiniteBatteryTarget
# APC under construction
- type: entity
noSpawn: true
id: APCFrame
name: APC frame
description: A control terminal for the area's electrical systems, lacking the electronics.
placement:
mode: SnapgridCenter
components:
- type: Clickable
- type: InteractionOutline
- type: Transform
anchored: true
- type: Sprite
drawdepth: WallMountedItems
netsync: false
sprite: Structures/Power/apc.rsi
state: apcframe
- type: Construction
graph: APC
node: apcFrame
- type: WallMount
- type: Damageable
damageContainer: Inorganic
damageModifierSet: Metallic
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 200
behaviors: #excess damage, don't spawn entities.
- !type:DoActsBehavior
acts: [ "Destruction" ]
- trigger:
!type:DamageTrigger
damage: 50
behaviors:
- !type:SpawnEntitiesBehavior
spawn:
SheetSteel1:
min: 1
max: 1
- !type:DoActsBehavior
acts: [ "Destruction" ]
# Constructed APC
- type: entity
parent: BaseAPC
id: APCConstructed
suffix: Open
components:
- type: Apc
voltage: Apc
open: true
# APCs in use # APCs in use
- type: entity - type: entity
parent: BaseAPC parent: BaseAPC

View File

@@ -1,13 +1,43 @@
- type: constructionGraph - type: constructionGraph
id: APC id: APC
start: start start: start
graph: graph:
- node: start - node: start
edges: edges:
- to: apc - to: apcFrame
steps: steps:
- material: Steel - material: Steel
amount: 3 amount: 3
- node: apcFrame
entity: APCFrame
edges:
- to: apc
steps:
- component: ApcElectronics
name: "APC electronics"
doAfter: 2
- to: start
completed:
- !type:GivePrototype
prototype: SheetSteel1
amount: 3
- !type:DeleteEntity {}
steps:
- tool: Screwing
doAfter: 2
- node: apc - node: apc
entity: BaseAPC entity: APCConstructed
edges:
- to: apcFrame
completed:
- !type:GivePrototype
prototype: APCElectronics
amount: 1
conditions:
- !type:ApcPanel
open: true
steps:
- tool: Prying
doAfter: 4

View File

@@ -10,6 +10,9 @@
{ {
"name": "broken" "name": "broken"
}, },
{
"name": "apcframe"
},
{ {
"name": "sparks-unlit", "name": "sparks-unlit",
"delays": [ "delays": [