Singularity, Particle Accelerator & Radiation Collectors (#2169)

* basic radiation generator

* might need this

* thonk

* big thonk

* oop

* e

* werks

* sprite

* oopsy woopsy

* radiation

* clean up file

* makes it work, probably

* minor fixes

* resources

* progress on component

* this will no longer be necessary

* radiation go brrrr

* finally fix container issues

* out var

Co-authored-by: Remie Richards <remierichards@gmail.com>

* second out fix

* another out fix

Co-authored-by: Remie Richards <remierichards@gmail.com>

* switch case

* fix switch

* sound and improvements

* nullable

* basic containment field system

* ensure alignment

* fix beam placement logic

* field generation fully working

* fix potential crash

* working containment functionality

* extremely basic emitter functionality

* fix radiation panel naming

* emitter stuff

* oopsies

* fixes

* some fixes

* cleanup

* small fix and move emitter file

* add sprite resources for PA

* slight rework of the singulo
adds rads

* pushing for smugleaf :)

* added radiationpanels

* some fixes for the singulo

* containmentfield

* pa wip

* progress

* pa working

* emitter fix

* works :)

* ui works

* some work on ui & pa

* progress

* ui work & misc fixes

* GREYSCALE

* pa ui polish
containmentfieldgen rework

* singulo rework
added snapgrid

* getcomponent get out

* singulo rework
added collisiongroups underplating & passable

* yaml work:
- collision boxes
- singulo now unshaded

* no unlit

* misc changes

* pa wires

* add usability check

* nullable enable

* minor fix

* power need added

* reenables containment field energy drain
menu close button
singularity collider fix

* sprite replacement

* finished singulo pulling

* pjb fixes

* fixing sprites & minor adjustments

* decrease containmentfield power

* some yml adjustments

* unlit layers
singulogenerator

* singulogen

* everything works just not the powergetting on the pa
i wanna die

* Adds PA construction graphs, PA construction works

* Snap to grid parts when completing construction

* updated to newest master

* inb4 i work on power

* fixes upstream merge
adds power need to particleaccelerator

* properly implements power & apc power

* Emitters are now fancy.

* I have actually no idea how this happened.

* Give PA a wiring LayoutId

* PA is an acronym

* indicators
fixes hacking

* Singulo is a word you blasphemous IDE.

* Rewrite the PA.

* Fancy names for PA parts.

* Wiring fixes, strength wire cutting.

* fixes projectile & ignores components

* nullability errors

* fixes integration tests

Co-authored-by: unusualcrow <unusualcrow@protonmail.com>
Co-authored-by: L.E.D <10257081+unusualcrow@users.noreply.github.com>
Co-authored-by: Remie Richards <remierichards@gmail.com>
Co-authored-by: Víctor Aguilera Puerto <zddm@outlook.es>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
Paul Ritter
2020-10-28 19:19:47 +01:00
committed by GitHub
parent 74fe2609f5
commit 6a0aa9b72f
171 changed files with 4357 additions and 42 deletions

View File

@@ -0,0 +1,724 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
using Content.Server.GameObjects.Components.VendingMachines;
using Content.Server.Utility;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using static Content.Shared.GameObjects.Components.SharedWiresComponent;
using Timer = Robust.Shared.Timers.Timer;
namespace Content.Server.GameObjects.Components.PA
{
// This component is in control of the PA's logic because it's the one to contain the wires for hacking.
// And also it's the only PA component that meaningfully needs to work on its own.
/// <summary>
/// Is the computer thing people interact with to control the PA.
/// Also contains primary logic for actual PA behavior, part scanning, etc...
/// </summary>
[ComponentReference(typeof(IActivate))]
[RegisterComponent]
public class ParticleAcceleratorControlBoxComponent : ParticleAcceleratorPartComponent, IActivate, IWires
{
public override string Name => "ParticleAcceleratorControlBox";
[ViewVariables]
private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ParticleAcceleratorControlBoxUiKey.Key);
/// <summary>
/// Power receiver for the control console itself.
/// </summary>
[ViewVariables] private PowerReceiverComponent? _powerReceiverComponent;
[ViewVariables] private ParticleAcceleratorFuelChamberComponent? _partFuelChamber;
[ViewVariables] private ParticleAcceleratorEndCapComponent? _partEndCap;
[ViewVariables] private ParticleAcceleratorPowerBoxComponent? _partPowerBox;
[ViewVariables] private ParticleAcceleratorEmitterComponent? _partEmitterLeft;
[ViewVariables] private ParticleAcceleratorEmitterComponent? _partEmitterCenter;
[ViewVariables] private ParticleAcceleratorEmitterComponent? _partEmitterRight;
[ViewVariables] private ParticleAcceleratorPowerState _selectedStrength = ParticleAcceleratorPowerState.Standby;
[ViewVariables] private bool _isAssembled;
// Enabled: power switch is on
[ViewVariables] private bool _isEnabled;
// Powered: power switch is on AND the PA is actively firing (if not on standby)
[ViewVariables] private bool _isPowered;
[ViewVariables] private bool _wireInterfaceBlocked;
[ViewVariables] private bool _wirePowerBlocked;
[ViewVariables] private bool _wireLimiterCut;
[ViewVariables] private bool _wireStrengthCut;
[ViewVariables] private CancellationTokenSource? _fireCancelTokenSrc;
/// <summary>
/// Delay between consecutive PA shots.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] private TimeSpan _firingDelay;
[ViewVariables(VVAccess.ReadWrite)] private int _powerDrawBase;
[ViewVariables(VVAccess.ReadWrite)] private int _powerDrawMult;
[ViewVariables] private bool ConsolePowered => _powerReceiverComponent?.Powered ?? true;
public ParticleAcceleratorControlBoxComponent()
{
Master = this;
}
private ParticleAcceleratorPowerState MaxPower => _wireLimiterCut
? ParticleAcceleratorPowerState.Level3
: ParticleAcceleratorPowerState.Level2;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
// Fun fact:
// On /vg/station (can't check TG because lol they removed singulo),
// the PA emitter parts have var/fire_delay = 50.
// For anybody from the future not BYOND-initiated, that's 5 seconds.
// However, /obj/machinery/particle_accelerator/control_box/process(),
// which calls emit_particle() on the emitters,
// only gets called every *2* seconds, because of CarnMC timing.
// So the *actual* effective firing delay of the PA is 6 seconds, not 5 as listed in the code.
// So...
// I have reflected that here to be authentic.
serializer.DataField(ref _firingDelay, "fireDelay", TimeSpan.FromSeconds(6));
serializer.DataField(ref _powerDrawBase, "powerDrawBase", 500);
serializer.DataField(ref _powerDrawMult, "powerDrawMult", 1500);
}
public override void Initialize()
{
base.Initialize();
if (UserInterface != null)
{
UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;
}
if (!Owner.TryGetComponent(out _powerReceiverComponent))
{
Logger.Error("ParticleAcceleratorControlBox was created without PowerReceiverComponent");
return;
}
_powerReceiverComponent.OnPowerStateChanged += OnPowerStateChanged;
_powerReceiverComponent.Load = 250;
}
protected override void Startup()
{
base.Startup();
UpdateWireStatus();
}
// This is the power state for the PA control box itself.
// Keep in mind that the PA itself can keep firing as long as the HV cable under the power box has... power.
private void OnPowerStateChanged(object? sender, PowerStateEventArgs e)
{
UpdateAppearance();
if (!e.Powered)
{
UserInterface?.CloseAll();
}
}
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage obj)
{
if (!ConsolePowered)
{
return;
}
if (obj.Session.AttachedEntity == null ||
!ActionBlockerSystem.CanInteract(obj.Session.AttachedEntity))
{
return;
}
if (_wireInterfaceBlocked)
{
return;
}
switch (obj.Message)
{
case ParticleAcceleratorSetEnableMessage enableMessage:
if (enableMessage.Enabled)
{
SwitchOn();
}
else
{
SwitchOff();
}
break;
case ParticleAcceleratorSetPowerStateMessage stateMessage:
SetStrength(stateMessage.State);
break;
case ParticleAcceleratorRescanPartsMessage _:
RescanParts();
break;
}
UpdateUI();
}
public void UpdateUI()
{
var draw = 0;
var receive = 0;
if (_isEnabled)
{
draw = _partPowerBox!.PowerConsumerComponent!.DrawRate;
receive = _partPowerBox!.PowerConsumerComponent!.ReceivedPower;
}
var state = new ParticleAcceleratorUIState(
_isAssembled,
_isEnabled,
_selectedStrength,
draw,
receive,
_partEmitterLeft != null,
_partEmitterCenter != null,
_partEmitterRight != null,
_partPowerBox != null,
_partFuelChamber != null,
_partEndCap != null,
_wireInterfaceBlocked,
MaxPower,
_wirePowerBlocked);
UserInterface?.SetState(state);
}
void IActivate.Activate(ActivateEventArgs eventArgs)
{
if (!eventArgs.User.TryGetComponent(out IActorComponent? actor))
{
return;
}
if (Owner.TryGetComponent<WiresComponent>(out var wires) && wires.IsPanelOpen)
{
wires.OpenInterface(actor.playerSession);
}
else
{
if (!ConsolePowered)
{
return;
}
UserInterface?.Toggle(actor.playerSession);
UpdateUI();
}
}
public override void OnRemove()
{
UserInterface?.CloseAll();
base.OnRemove();
}
void IWires.RegisterWires(WiresComponent.WiresBuilder builder)
{
builder.CreateWire(ParticleAcceleratorControlBoxWires.Toggle);
builder.CreateWire(ParticleAcceleratorControlBoxWires.Strength);
builder.CreateWire(ParticleAcceleratorControlBoxWires.Interface);
builder.CreateWire(ParticleAcceleratorControlBoxWires.Limiter);
builder.CreateWire(ParticleAcceleratorControlBoxWires.Nothing);
}
public void WiresUpdate(WiresUpdateEventArgs args)
{
switch (args.Identifier)
{
case ParticleAcceleratorControlBoxWires.Toggle:
if (args.Action == WiresAction.Pulse)
{
if (_isEnabled)
{
SwitchOff();
}
else
{
SwitchOn();
}
}
else
{
_wirePowerBlocked = args.Action == WiresAction.Cut;
if (_isEnabled)
{
SwitchOff();
}
}
break;
case ParticleAcceleratorControlBoxWires.Strength:
if (args.Action == WiresAction.Pulse)
{
SetStrength(_selectedStrength + 1);
}
else
{
_wireStrengthCut = args.Action == WiresAction.Cut;
}
break;
case ParticleAcceleratorControlBoxWires.Interface:
if (args.Action == WiresAction.Pulse)
{
_wireInterfaceBlocked ^= true;
}
else
{
_wireInterfaceBlocked = args.Action == WiresAction.Cut;
}
break;
case ParticleAcceleratorControlBoxWires.Limiter:
if (args.Action == WiresAction.Pulse)
{
Owner.PopupMessageEveryone(Loc.GetString("The control box makes a whirring noise."));
}
else
{
_wireLimiterCut = args.Action == WiresAction.Cut;
if (_selectedStrength == ParticleAcceleratorPowerState.Level3 && !_wireLimiterCut)
{
// Yes, it's a feature that mending this wire WON'T WORK if the strength wire is also cut.
// Since that blocks SetStrength().
SetStrength(ParticleAcceleratorPowerState.Level2);
}
}
break;
}
UpdateUI();
UpdateWireStatus();
}
private void UpdateWireStatus()
{
if (!Owner.TryGetComponent(out WiresComponent? wires))
{
return;
}
var powerBlock = _wirePowerBlocked;
var keyboardLight = new StatusLightData(Color.Green,
_wireInterfaceBlocked
? StatusLightState.BlinkingFast
: StatusLightState.On,
"KEYB");
var powerLight = new StatusLightData(
Color.Yellow,
powerBlock ? StatusLightState.Off : StatusLightState.On,
"POWR");
var limiterLight = new StatusLightData(
_wireLimiterCut ? Color.Purple : Color.Teal,
StatusLightState.On,
"LIMT");
var strengthLight = new StatusLightData(
Color.Blue,
_wireStrengthCut ? StatusLightState.BlinkingSlow : StatusLightState.On,
"STRC");
wires.SetStatus(ParticleAcceleratorWireStatus.Keyboard, keyboardLight);
wires.SetStatus(ParticleAcceleratorWireStatus.Power, powerLight);
wires.SetStatus(ParticleAcceleratorWireStatus.Limiter, limiterLight);
wires.SetStatus(ParticleAcceleratorWireStatus.Strength, strengthLight);
}
public void RescanParts()
{
SwitchOff();
foreach (var part in AllParts())
{
part.Master = null;
}
_isAssembled = false;
_partFuelChamber = null;
_partEndCap = null;
_partPowerBox = null;
_partEmitterLeft = null;
_partEmitterCenter = null;
_partEmitterRight = null;
// Find fuel chamber first by scanning cardinals.
if (SnapGrid != null)
{
foreach (var maybeFuel in SnapGrid.GetCardinalNeighborCells())
{
if (maybeFuel.Owner.TryGetComponent(out _partFuelChamber))
{
break;
}
}
}
if (_partFuelChamber == null)
{
UpdateUI();
return;
}
// Align ourselves to match fuel chamber orientation.
// This means that if you mess up the orientation of the control box it's not a big deal,
// because the sprite is far from obvious about the orientation.
Owner.Transform.LocalRotation = _partFuelChamber.Owner.Transform.LocalRotation;
var offsetEndCap = RotateOffset((1, 1));
var offsetPowerBox = RotateOffset((1, -1));
var offsetEmitterLeft = RotateOffset((0, -2));
var offsetEmitterCenter = RotateOffset((1, -2));
var offsetEmitterRight = RotateOffset((2, -2));
ScanPart(offsetEndCap, out _partEndCap);
ScanPart(offsetPowerBox, out _partPowerBox);
if (!ScanPart(offsetEmitterCenter, out _partEmitterCenter) ||
_partEmitterCenter.Type != ParticleAcceleratorEmitterType.Center)
{
// if it's the wrong type we need to clear this to avoid shenanigans.
_partEmitterCenter = null;
}
if (ScanPart(offsetEmitterLeft, out _partEmitterLeft) &&
_partEmitterLeft.Type != ParticleAcceleratorEmitterType.Left)
{
_partEmitterLeft = null;
}
if (ScanPart(offsetEmitterRight, out _partEmitterRight) &&
_partEmitterRight.Type != ParticleAcceleratorEmitterType.Right)
{
_partEmitterRight = null;
}
_isAssembled = _partFuelChamber != null &&
_partPowerBox != null &&
_partEmitterCenter != null &&
_partEmitterLeft != null &&
_partEmitterRight != null &&
_partEndCap != null;
foreach (var part in AllParts())
{
part.Master = this;
}
UpdateUI();
Vector2i RotateOffset(in Vector2i vec)
{
var rot = new Angle(Owner.Transform.LocalRotation + Math.PI / 2);
return (Vector2i) rot.RotateVec(vec);
}
}
private bool ScanPart<T>(Vector2i offset, [NotNullWhen(true)] out T? part)
where T : ParticleAcceleratorPartComponent
{
foreach (var ent in SnapGrid!.GetOffset(offset))
{
if (ent.TryGetComponent(out part) && !part.Deleted)
{
return true;
}
}
part = default;
return false;
}
private IEnumerable<ParticleAcceleratorPartComponent> AllParts()
{
if (_partFuelChamber != null)
yield return _partFuelChamber;
if (_partEndCap != null)
yield return _partEndCap;
if (_partPowerBox != null)
yield return _partPowerBox;
if (_partEmitterLeft != null)
yield return _partEmitterLeft;
if (_partEmitterCenter != null)
yield return _partEmitterCenter;
if (_partEmitterRight != null)
yield return _partEmitterRight;
}
private void SwitchOn()
{
DebugTools.Assert(_isAssembled);
if (_isEnabled)
{
return;
}
_isEnabled = true;
UpdatePowerDraw();
// If we don't have power yet we'll turn on when we receive more power from the powernet.
// if we do we'll just go and turn on right now.
if (_partPowerBox!.PowerConsumerComponent!.ReceivedPower >= _partPowerBox.PowerConsumerComponent.DrawRate)
{
PowerOn();
}
UpdateUI();
}
private void UpdatePowerDraw()
{
_partPowerBox!.PowerConsumerComponent!.DrawRate = PowerDrawFor(_selectedStrength);
}
private void SwitchOff()
{
_isEnabled = false;
PowerOff();
UpdateUI();
}
private void PowerOn()
{
DebugTools.Assert(_isEnabled);
DebugTools.Assert(_isAssembled);
if (_isPowered)
{
return;
}
_isPowered = true;
UpdateFiring();
UpdatePartVisualStates();
UpdateUI();
}
private void PowerOff()
{
if (!_isPowered)
{
return;
}
_isPowered = false;
UpdateFiring();
UpdateUI();
UpdatePartVisualStates();
}
private void SetStrength(ParticleAcceleratorPowerState state)
{
if (_wireStrengthCut)
{
return;
}
state = (ParticleAcceleratorPowerState) MathHelper.Clamp(
(int) state,
(int) ParticleAcceleratorPowerState.Standby,
(int) MaxPower);
_selectedStrength = state;
UpdateAppearance();
UpdatePartVisualStates();
if (_isEnabled)
{
UpdatePowerDraw();
UpdateFiring();
}
}
private void UpdateAppearance()
{
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(ParticleAcceleratorVisuals.VisualState,
_powerReceiverComponent!.Powered
? (ParticleAcceleratorVisualState) _selectedStrength
: ParticleAcceleratorVisualState.Unpowered);
}
}
private void UpdateFiring()
{
if (!_isPowered || _selectedStrength == ParticleAcceleratorPowerState.Standby)
{
StopFiring();
}
else
{
StartFiring();
}
}
private void StartFiring()
{
EverythingIsWellToFire();
_fireCancelTokenSrc?.Cancel();
_fireCancelTokenSrc = new CancellationTokenSource();
var cancelToken = _fireCancelTokenSrc.Token;
Timer.SpawnRepeating(_firingDelay, Fire, cancelToken);
}
private void Fire()
{
EverythingIsWellToFire();
_partEmitterCenter!.Fire(_selectedStrength);
_partEmitterLeft!.Fire(_selectedStrength);
_partEmitterRight!.Fire(_selectedStrength);
}
[Conditional("DEBUG")]
private void EverythingIsWellToFire()
{
DebugTools.Assert(!Deleted);
DebugTools.Assert(_isPowered);
DebugTools.Assert(_selectedStrength != ParticleAcceleratorPowerState.Standby);
DebugTools.Assert(_isAssembled);
DebugTools.Assert(_partEmitterCenter != null);
DebugTools.Assert(_partEmitterLeft != null);
DebugTools.Assert(_partEmitterRight != null);
}
private void StopFiring()
{
_fireCancelTokenSrc?.Cancel();
_fireCancelTokenSrc = null;
}
private int PowerDrawFor(ParticleAcceleratorPowerState strength)
{
return strength switch
{
ParticleAcceleratorPowerState.Standby => 0,
ParticleAcceleratorPowerState.Level0 => 1,
ParticleAcceleratorPowerState.Level1 => 3,
ParticleAcceleratorPowerState.Level2 => 4,
ParticleAcceleratorPowerState.Level3 => 5,
_ => 0
} * _powerDrawMult + _powerDrawBase;
}
public void PowerBoxReceivedChanged(object? sender, ReceivedPowerChangedEventArgs eventArgs)
{
DebugTools.Assert(_isAssembled);
if (!_isEnabled)
{
return;
}
var isPowered = eventArgs.ReceivedPower >= eventArgs.DrawRate;
if (isPowered)
{
PowerOn();
}
else
{
PowerOff();
}
UpdateUI();
}
private void UpdatePartVisualStates()
{
// UpdatePartVisualState(ControlBox);
UpdatePartVisualState(_partFuelChamber);
UpdatePartVisualState(_partPowerBox);
UpdatePartVisualState(_partEmitterCenter);
UpdatePartVisualState(_partEmitterLeft);
UpdatePartVisualState(_partEmitterRight);
//no endcap because it has no powerlevel-sprites
}
private void UpdatePartVisualState(ParticleAcceleratorPartComponent? component)
{
if (component == null || !component.Owner.TryGetComponent<AppearanceComponent>(out var appearanceComponent))
{
return;
}
var state = _isPowered
? (ParticleAcceleratorVisualState) _selectedStrength
: ParticleAcceleratorVisualState.Unpowered;
appearanceComponent.SetData(ParticleAcceleratorVisuals.VisualState, state);
}
public override void Rotated()
{
// We rotate OURSELVES when scanning for parts, so don't actually run rescan on rotate.
// That would be silly.
}
public enum ParticleAcceleratorControlBoxWires
{
/// <summary>
/// Pulse toggles Power. Cut permanently turns off until Mend.
/// </summary>
Toggle,
/// <summary>
/// Pulsing increases level until at limit.
/// </summary>
Strength,
/// <summary>
/// Pulsing toggles Button-Disabled on UI. Cut disables, Mend enables.
/// </summary>
Interface,
/// <summary>
/// Pulsing will produce short message about whirring noise. Cutting increases the max level to 3. Mending reduces it back to 2.
/// </summary>
Limiter,
/// <summary>
/// Does Nothing
/// </summary>
Nothing
}
}
}

View File

@@ -0,0 +1,50 @@
using Content.Shared.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.PA
{
[RegisterComponent]
[ComponentReference(typeof(ParticleAcceleratorPartComponent))]
public class ParticleAcceleratorEmitterComponent : ParticleAcceleratorPartComponent
{
[Dependency] private IEntityManager _entityManager = null!;
public override string Name => "ParticleAcceleratorEmitter";
public ParticleAcceleratorEmitterType Type;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref Type, "emitterType", ParticleAcceleratorEmitterType.Center);
}
public void Fire(ParticleAcceleratorPowerState strength)
{
var projectile = _entityManager.SpawnEntity("ParticlesProjectile", Owner.Transform.Coordinates);
if (!projectile.TryGetComponent<ParticleProjectileComponent>(out var particleProjectileComponent))
{
Logger.Error("ParticleAcceleratorEmitter tried firing particles, but they was spawned without a ParticleProjectileComponent");
return;
}
particleProjectileComponent.Fire(strength, Owner.Transform.WorldRotation, Owner);
}
public override string ToString()
{
return base.ToString() + $" EmitterType:{Type}";
}
}
public enum ParticleAcceleratorEmitterType
{
Left,
Center,
Right
}
}

View File

@@ -0,0 +1,11 @@
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.PA
{
[RegisterComponent]
[ComponentReference(typeof(ParticleAcceleratorPartComponent))]
public class ParticleAcceleratorEndCapComponent : ParticleAcceleratorPartComponent
{
public override string Name => "ParticleAcceleratorEndCap";
}
}

View File

@@ -0,0 +1,11 @@
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.PA
{
[RegisterComponent]
[ComponentReference(typeof(ParticleAcceleratorPartComponent))]
public class ParticleAcceleratorFuelChamberComponent : ParticleAcceleratorPartComponent
{
public override string Name => "ParticleAcceleratorFuelChamber";
}
}

View File

@@ -0,0 +1,58 @@
#nullable enable
using Content.Server.Utility;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Log;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.PA
{
public abstract class ParticleAcceleratorPartComponent : Component
{
[ViewVariables] private PhysicsComponent? _collidableComponent;
[ViewVariables] public ParticleAcceleratorControlBoxComponent? Master;
[ViewVariables] protected SnapGridComponent? SnapGrid;
public override void Initialize()
{
base.Initialize();
// FIXME: this has to be an entity system, full stop.
if (!Owner.TryGetComponent(out _collidableComponent))
{
Logger.Error("ParticleAcceleratorPartComponent created with no CollidableComponent");
}
else
{
_collidableComponent.AnchoredChanged += OnAnchorChanged;
}
if (!Owner.TryGetComponent(out SnapGrid))
{
Logger.Error("ParticleAcceleratorControlBox was created without SnapGridComponent");
}
}
public void OnAnchorChanged()
{
RescanIfPossible();
}
public override void OnRemove()
{
base.OnRemove();
RescanIfPossible();
}
private void RescanIfPossible()
{
Master?.RescanParts();
}
public virtual void Rotated()
{
RescanIfPossible();
}
}
}

View File

@@ -0,0 +1,33 @@
#nullable enable
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.PA
{
[RegisterComponent]
[ComponentReference(typeof(ParticleAcceleratorPartComponent))]
public class ParticleAcceleratorPowerBoxComponent : ParticleAcceleratorPartComponent
{
public override string Name => "ParticleAcceleratorPowerBox";
[ViewVariables] public PowerConsumerComponent? PowerConsumerComponent;
public override void Initialize()
{
base.Initialize();
if (Owner.TryGetComponent(out PowerConsumerComponent))
{
PowerConsumerComponent.OnReceivedPowerChanged += PowerReceivedChanged;
return;
}
Logger.Error($"ParticleAcceleratorPowerBoxComponent Component initialized without PowerConsumerComponent.");
}
private void PowerReceivedChanged(object? sender, ReceivedPowerChangedEventArgs e)
{
Master?.PowerBoxReceivedChanged(sender, e);
}
}
}

View File

@@ -0,0 +1,94 @@
using System;
using Content.Server.GameObjects.Components.Projectiles;
using Content.Server.GameObjects.Components.Singularity;
using Content.Shared.GameObjects.Components;
using Content.Shared.Physics;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Timers;
namespace Content.Server.GameObjects.Components.PA
{
[RegisterComponent]
public class ParticleProjectileComponent : Component, ICollideBehavior
{
public override string Name => "ParticleProjectile";
private ParticleAcceleratorPowerState _state;
public void CollideWith(IEntity collidedWith)
{
if (collidedWith.TryGetComponent<SingularityComponent>(out var singularityComponent))
{
var multiplier = _state switch
{
ParticleAcceleratorPowerState.Standby => 0,
ParticleAcceleratorPowerState.Level0 => 1,
ParticleAcceleratorPowerState.Level1 => 3,
ParticleAcceleratorPowerState.Level2 => 6,
ParticleAcceleratorPowerState.Level3 => 10,
_ => 0
};
singularityComponent.Energy += 10 * multiplier;
Owner.Delete();
}else if (collidedWith.TryGetComponent<SingularityGeneratorComponent>(out var singularityGeneratorComponent)
)
{
singularityGeneratorComponent.Power += _state switch
{
ParticleAcceleratorPowerState.Standby => 0,
ParticleAcceleratorPowerState.Level0 => 1,
ParticleAcceleratorPowerState.Level1 => 2,
ParticleAcceleratorPowerState.Level2 => 4,
ParticleAcceleratorPowerState.Level3 => 8,
_ => 0
};
Owner.Delete();
}
}
public void Fire(ParticleAcceleratorPowerState state, Angle angle, IEntity firer)
{
_state = state;
if (!Owner.TryGetComponent<PhysicsComponent>(out var physicsComponent))
{
Logger.Error("ParticleProjectile tried firing, but it was spawned without a CollidableComponent");
return;
}
physicsComponent.Status = BodyStatus.InAir;
if (!Owner.TryGetComponent<ProjectileComponent>(out var projectileComponent))
{
Logger.Error("ParticleProjectile tried firing, but it was spawned without a ProjectileComponent");
return;
}
projectileComponent.IgnoreEntity(firer);
var suffix = state switch
{
ParticleAcceleratorPowerState.Level0 => "0",
ParticleAcceleratorPowerState.Level1 => "1",
ParticleAcceleratorPowerState.Level2 => "2",
ParticleAcceleratorPowerState.Level3 => "3",
_ => "0"
};
if (!Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
{
Logger.Error("ParticleProjectile tried firing, but it was spawned without a SpriteComponent");
return;
}
spriteComponent.LayerSetState(0, $"particle{suffix}");
physicsComponent
.EnsureController<BulletController>()
.LinearVelocity = angle.ToVec() * 20f;
Owner.Transform.LocalRotation = new Angle(angle + Angle.FromDegrees(180));
Timer.Spawn(3000, () => Owner.Delete());
}
}
}