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:
@@ -541,7 +541,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
var list = new List<KeyValuePair<Slots, EntityUid>>();
|
||||
foreach (var (slot, container) in _slotContainers)
|
||||
{
|
||||
if (container.ContainedEntity != null)
|
||||
if (container != null && container.ContainedEntity != null)
|
||||
{
|
||||
list.Add(new KeyValuePair<Slots, EntityUid>(slot, container.ContainedEntity.Uid));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
@@ -33,6 +34,8 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
public int ReceivedPower { get => _receivedPower; set => SetReceivedPower(value); }
|
||||
private int _receivedPower;
|
||||
|
||||
public event EventHandler<ReceivedPowerChangedEventArgs> OnReceivedPowerChanged;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
@@ -60,7 +63,9 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
private void SetReceivedPower(int newReceivedPower)
|
||||
{
|
||||
Debug.Assert(newReceivedPower >= 0 && newReceivedPower <= DrawRate);
|
||||
if(_receivedPower == newReceivedPower) return;
|
||||
_receivedPower = newReceivedPower;
|
||||
OnReceivedPowerChanged?.Invoke(this, new ReceivedPowerChangedEventArgs(_drawRate, _receivedPower));
|
||||
}
|
||||
|
||||
private void SetPriority(Priority newPriority)
|
||||
@@ -75,4 +80,16 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
First,
|
||||
Last,
|
||||
}
|
||||
|
||||
public class ReceivedPowerChangedEventArgs : EventArgs
|
||||
{
|
||||
public readonly int DrawRate;
|
||||
public readonly int ReceivedPower;
|
||||
|
||||
public ReceivedPowerChangedEventArgs(int drawRate, int receivedPower)
|
||||
{
|
||||
DrawRate = drawRate;
|
||||
ReceivedPower = receivedPower;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.Components.Doors;
|
||||
using Content.Shared.GameObjects.Components.Singularity;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Timer = Robust.Shared.Timers.Timer;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class RadiationCollectorComponent : PowerSupplierComponent, IInteractHand, IRadiationAct
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
public override string Name => "RadiationCollector";
|
||||
private bool _enabled;
|
||||
private TimeSpan _coolDownEnd;
|
||||
|
||||
private PhysicsComponent _collidableComponent;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
if (!Owner.TryGetComponent(out _collidableComponent))
|
||||
{
|
||||
Logger.Error("RadiationCollectorComponent created with no CollidableComponent");
|
||||
return;
|
||||
}
|
||||
_collidableComponent.AnchoredChanged += OnAnchoredChanged;
|
||||
}
|
||||
|
||||
private void OnAnchoredChanged()
|
||||
{
|
||||
if(_collidableComponent.Anchored) Owner.SnapToGrid();
|
||||
}
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
var curTime = _gameTiming.CurTime;
|
||||
|
||||
if(curTime < _coolDownEnd)
|
||||
return true;
|
||||
|
||||
if (!_enabled)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("The collector turns on."));
|
||||
EnableCollection();
|
||||
}
|
||||
else
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("The collector turns off."));
|
||||
DisableCollection();
|
||||
}
|
||||
|
||||
_coolDownEnd = curTime + TimeSpan.FromSeconds(0.81f);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EnableCollection()
|
||||
{
|
||||
_enabled = true;
|
||||
SetAppearance(RadiationCollectorVisualState.Activating);
|
||||
}
|
||||
|
||||
void DisableCollection()
|
||||
{
|
||||
_enabled = false;
|
||||
SetAppearance(RadiationCollectorVisualState.Deactivating);
|
||||
}
|
||||
|
||||
public void RadiationAct(float frameTime, SharedRadiationPulseComponent radiation)
|
||||
{
|
||||
if (!_enabled) return;
|
||||
|
||||
SupplyRate = (int) (frameTime * radiation.RadsPerSecond * 3000f);
|
||||
}
|
||||
|
||||
protected void SetAppearance(RadiationCollectorVisualState state)
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
{
|
||||
appearance.SetData(RadiationCollectorVisuals.VisualState, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Content.Server.GameObjects.Components.Singularity;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Projectiles
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class EmitterBoltComponent : Component
|
||||
{
|
||||
public override string Name => "EmitterBoltComponent";
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,8 @@ namespace Content.Server.GameObjects.Components.Projectiles
|
||||
Dirty();
|
||||
}
|
||||
|
||||
private bool _internalDeleteOnCollide;
|
||||
|
||||
/// <summary>
|
||||
/// Applies the damage when our projectile collides with its victim
|
||||
/// </summary>
|
||||
@@ -74,12 +76,12 @@ namespace Content.Server.GameObjects.Components.Projectiles
|
||||
// This is so entities that shouldn't get a collision are ignored.
|
||||
if (entity.TryGetComponent(out IPhysicsComponent otherPhysics) && otherPhysics.Hard == false)
|
||||
{
|
||||
_deleteOnCollide = false;
|
||||
_internalDeleteOnCollide = false;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_deleteOnCollide = true;
|
||||
_internalDeleteOnCollide = true;
|
||||
}
|
||||
|
||||
if (_soundHitSpecies != null && entity.HasComponent<IDamageableComponent>())
|
||||
@@ -112,7 +114,7 @@ namespace Content.Server.GameObjects.Components.Projectiles
|
||||
|
||||
void ICollideBehavior.PostCollide(int collideCount)
|
||||
{
|
||||
if (collideCount > 0 && DeleteOnCollide) Owner.Delete();
|
||||
if (collideCount > 0 && DeleteOnCollide && _internalDeleteOnCollide) Owner.Delete();
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Singularity
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class ContainmentFieldComponent : Component, ICollideBehavior
|
||||
{
|
||||
public override string Name => "ContainmentField";
|
||||
public ContainmentFieldConnection? Parent;
|
||||
|
||||
public void CollideWith(IEntity collidedWith)
|
||||
{
|
||||
if (Parent == null)
|
||||
{
|
||||
Owner.Delete();
|
||||
return;
|
||||
}
|
||||
|
||||
Parent.TryRepell(Owner, collidedWith);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Timer = Robust.Shared.Timers.Timer;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Singularity
|
||||
{
|
||||
public class ContainmentFieldConnection : IDisposable
|
||||
{
|
||||
public readonly ContainmentFieldGeneratorComponent Generator1;
|
||||
public readonly ContainmentFieldGeneratorComponent Generator2;
|
||||
private List<IEntity> _fields = new List<IEntity>();
|
||||
private int _sharedEnergyPool;
|
||||
private CancellationTokenSource _powerDecreaseCancellationTokenSource = new CancellationTokenSource();
|
||||
public int SharedEnergyPool
|
||||
{
|
||||
get => _sharedEnergyPool;
|
||||
set
|
||||
{
|
||||
_sharedEnergyPool = Math.Clamp(value, 0, 10);
|
||||
if (_sharedEnergyPool == 0)
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ContainmentFieldConnection(ContainmentFieldGeneratorComponent generator1, ContainmentFieldGeneratorComponent generator2)
|
||||
{
|
||||
Generator1 = generator1;
|
||||
Generator2 = generator2;
|
||||
|
||||
//generateFields
|
||||
var pos1 = generator1.Owner.Transform.Coordinates;
|
||||
var pos2 = generator2.Owner.Transform.Coordinates;
|
||||
if (pos1 == pos2)
|
||||
{
|
||||
Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
var delta = (pos2 - pos1).Position;
|
||||
var dirVec = delta.Normalized;
|
||||
var stopDist = delta.Length;
|
||||
var currentOffset = dirVec;
|
||||
while (currentOffset.Length < stopDist)
|
||||
{
|
||||
var currentCoords = pos1.Offset(currentOffset);
|
||||
var newEnt = entityManager.SpawnEntity("ContainmentField", currentCoords);
|
||||
if (!newEnt.TryGetComponent<ContainmentFieldComponent>(out var containmentFieldComponent))
|
||||
{
|
||||
Logger.Error("While creating Fields in ContainmentFieldConnection, a ContainmentField without a ContainmentFieldComponent was created. Deleting newly spawned ContainmentField...");
|
||||
newEnt.Delete();
|
||||
continue;
|
||||
}
|
||||
|
||||
containmentFieldComponent.Parent = this;
|
||||
newEnt.Transform.WorldRotation = dirVec.ToAngle();
|
||||
|
||||
_fields.Add(newEnt);
|
||||
currentOffset += dirVec;
|
||||
}
|
||||
|
||||
|
||||
Timer.SpawnRepeating(1000, () => { SharedEnergyPool--;}, _powerDecreaseCancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
public bool CanRepell(IEntity toRepell)
|
||||
{
|
||||
var powerNeeded = 1;
|
||||
if (toRepell.TryGetComponent<SingularityComponent>(out var singularityComponent))
|
||||
{
|
||||
powerNeeded += 2*singularityComponent.Level;
|
||||
}
|
||||
|
||||
return _sharedEnergyPool > powerNeeded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to repell a Entity. This deletes the connection if the repelling fails!
|
||||
/// </summary>
|
||||
/// <param name="repellFrom">Entity to repell from. Should be a field, otherwise return will be false.</param>
|
||||
/// <param name="toRepell">Entity to repell.</param>
|
||||
public void TryRepell(IEntity repellFrom, IEntity toRepell)
|
||||
{
|
||||
if (!_fields.Contains(repellFrom) || !toRepell.TryGetComponent<IPhysicsComponent>(out var collidableComponent)) return;
|
||||
|
||||
var speed = 5;
|
||||
var containmentFieldRepellController = collidableComponent.EnsureController<ContainmentFieldRepellController>();
|
||||
|
||||
if (!CanRepell(toRepell))
|
||||
{
|
||||
Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Math.Abs(repellFrom.Transform.WorldRotation.Degrees + 90f) < 0.1f ||
|
||||
Math.Abs(repellFrom.Transform.WorldRotation.Degrees - 90f) < 0.1f)
|
||||
{
|
||||
if (repellFrom.Transform.WorldPosition.X.CompareTo(toRepell.Transform.WorldPosition.X) > 0)
|
||||
{
|
||||
containmentFieldRepellController.Repell(Direction.West, speed);
|
||||
}
|
||||
else
|
||||
{
|
||||
containmentFieldRepellController.Repell(Direction.East, speed);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (repellFrom.Transform.WorldPosition.Y.CompareTo(toRepell.Transform.WorldPosition.Y) > 0)
|
||||
{
|
||||
containmentFieldRepellController.Repell(Direction.South, speed);
|
||||
}
|
||||
else
|
||||
{
|
||||
containmentFieldRepellController.Repell(Direction.North, speed);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_powerDecreaseCancellationTokenSource.Cancel();
|
||||
foreach (var field in _fields)
|
||||
{
|
||||
field.Delete();
|
||||
}
|
||||
_fields.Clear();
|
||||
|
||||
Generator1.RemoveConnection(this);
|
||||
Generator2.RemoveConnection(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Projectiles;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Physics;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Physics;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Singularity
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class ContainmentFieldGeneratorComponent : Component, ICollideBehavior
|
||||
{
|
||||
[Dependency] private IPhysicsManager _physicsManager = null!;
|
||||
[Dependency] private IEntityManager _entityManager = null!;
|
||||
|
||||
public override string Name => "ContainmentFieldGenerator";
|
||||
|
||||
private int _powerBuffer;
|
||||
|
||||
[ViewVariables]
|
||||
public int PowerBuffer
|
||||
{
|
||||
get => _powerBuffer;
|
||||
set => _powerBuffer = Math.Clamp(value, 0, 6);
|
||||
}
|
||||
|
||||
public void ReceivePower(int power)
|
||||
{
|
||||
var totalPower = power + PowerBuffer;
|
||||
var powerPerConnection = totalPower / 2;
|
||||
var newBuffer = totalPower % 2;
|
||||
TryPowerConnection(ref _connection1, ref newBuffer, powerPerConnection);
|
||||
TryPowerConnection(ref _connection2, ref newBuffer, powerPerConnection);
|
||||
|
||||
PowerBuffer = newBuffer;
|
||||
}
|
||||
|
||||
private void TryPowerConnection(ref Tuple<Direction, ContainmentFieldConnection>? connectionProperty, ref int powerBuffer, int powerPerConnection)
|
||||
{
|
||||
if (connectionProperty != null)
|
||||
{
|
||||
connectionProperty.Item2.SharedEnergyPool += powerPerConnection;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (TryGenerateFieldConnection(ref connectionProperty))
|
||||
{
|
||||
connectionProperty.Item2.SharedEnergyPool += powerPerConnection;
|
||||
}
|
||||
else
|
||||
{
|
||||
powerBuffer += powerPerConnection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PhysicsComponent? _collidableComponent;
|
||||
|
||||
private Tuple<Direction, ContainmentFieldConnection>? _connection1;
|
||||
private Tuple<Direction, ContainmentFieldConnection>? _connection2;
|
||||
|
||||
public bool CanRepell(IEntity toRepell) => _connection1?.Item2?.CanRepell(toRepell) == true ||
|
||||
_connection2?.Item2?.CanRepell(toRepell) == true;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
if (!Owner.TryGetComponent(out _collidableComponent))
|
||||
{
|
||||
Logger.Error("ContainmentFieldGeneratorComponent created with no CollidableComponent");
|
||||
return;
|
||||
}
|
||||
_collidableComponent.AnchoredChanged += OnAnchoredChanged;
|
||||
}
|
||||
|
||||
|
||||
private void OnAnchoredChanged()
|
||||
{
|
||||
if(_collidableComponent?.Anchored == true)
|
||||
{
|
||||
Owner.SnapToGrid();
|
||||
}
|
||||
else
|
||||
{
|
||||
_connection1?.Item2.Dispose();
|
||||
_connection2?.Item2.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsConnectedWith(ContainmentFieldGeneratorComponent comp)
|
||||
{
|
||||
|
||||
return comp == this || _connection1?.Item2.Generator1 == comp || _connection1?.Item2.Generator2 == comp ||
|
||||
_connection2?.Item2.Generator1 == comp || _connection2?.Item2.Generator2 == comp;
|
||||
}
|
||||
|
||||
public bool HasFreeConnections()
|
||||
{
|
||||
return _connection1 == null || _connection2 == null;
|
||||
}
|
||||
|
||||
private bool TryGenerateFieldConnection([NotNullWhen(true)] ref Tuple<Direction, ContainmentFieldConnection>? propertyFieldTuple)
|
||||
{
|
||||
if (propertyFieldTuple != null) return false;
|
||||
if(_collidableComponent?.Anchored == false) return false;
|
||||
|
||||
foreach (var direction in new[] {Direction.North, Direction.East, Direction.South, Direction.West})
|
||||
{
|
||||
if (_connection1?.Item1 == direction || _connection2?.Item1 == direction) continue;
|
||||
|
||||
var dirVec = direction.ToVec();
|
||||
var ray = new CollisionRay(Owner.Transform.WorldPosition, dirVec, (int) CollisionGroup.MobMask);
|
||||
var rawRayCastResults = _physicsManager.IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
|
||||
|
||||
var rayCastResults = rawRayCastResults as RayCastResults[] ?? rawRayCastResults.ToArray();
|
||||
if(!rayCastResults.Any()) continue;
|
||||
|
||||
RayCastResults? closestResult = null;
|
||||
var smallestDist = 4.5f;
|
||||
foreach (var res in rayCastResults)
|
||||
{
|
||||
if (res.Distance > smallestDist) continue;
|
||||
|
||||
smallestDist = res.Distance;
|
||||
closestResult = res;
|
||||
}
|
||||
if(closestResult == null) continue;
|
||||
var ent = closestResult.Value.HitEntity;
|
||||
if (!ent.TryGetComponent<ContainmentFieldGeneratorComponent>(out var fieldGeneratorComponent) ||
|
||||
fieldGeneratorComponent.Owner == Owner ||
|
||||
!fieldGeneratorComponent.HasFreeConnections() ||
|
||||
IsConnectedWith(fieldGeneratorComponent) ||
|
||||
!ent.TryGetComponent<PhysicsComponent>(out var collidableComponent) ||
|
||||
!collidableComponent.Anchored)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var connection = new ContainmentFieldConnection(this, fieldGeneratorComponent);
|
||||
propertyFieldTuple = new Tuple<Direction, ContainmentFieldConnection>(direction, connection);
|
||||
if (fieldGeneratorComponent._connection1 == null)
|
||||
{
|
||||
fieldGeneratorComponent._connection1 = new Tuple<Direction, ContainmentFieldConnection>(direction.GetOpposite(), connection);
|
||||
}
|
||||
else if (fieldGeneratorComponent._connection2 == null)
|
||||
{
|
||||
fieldGeneratorComponent._connection2 = new Tuple<Direction, ContainmentFieldConnection>(direction.GetOpposite(), connection);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error("When trying to connect two Containmentfieldgenerators, the second one already had two connection but the check didn't catch it");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RemoveConnection(ContainmentFieldConnection? connection)
|
||||
{
|
||||
if (_connection1?.Item2 == connection)
|
||||
{
|
||||
_connection1 = null;
|
||||
}else if (_connection2?.Item2 == connection)
|
||||
{
|
||||
_connection2 = null;
|
||||
}
|
||||
else if(connection != null)
|
||||
{
|
||||
Logger.Error("RemoveConnection called on Containmentfieldgenerator with a connection that can't be found in its connections.");
|
||||
}
|
||||
}
|
||||
|
||||
public void CollideWith(IEntity collidedWith)
|
||||
{
|
||||
if(collidedWith.HasComponent<EmitterBoltComponent>())
|
||||
{
|
||||
ReceivePower(4);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
_connection1?.Item2.Dispose();
|
||||
_connection2?.Item2.Dispose();
|
||||
base.OnRemove();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.Access;
|
||||
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
|
||||
using Content.Server.GameObjects.Components.Projectiles;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects.Components.Singularity;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.ComponentDependencies;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Timer = Robust.Shared.Timers.Timer;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Singularity
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public class EmitterComponent : Component, IActivate, IInteractUsing
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
|
||||
[ComponentDependency] private AppearanceComponent? _appearance;
|
||||
[ComponentDependency] private AccessReader? _accessReader;
|
||||
|
||||
public override string Name => "Emitter";
|
||||
|
||||
private CancellationTokenSource? _timerCancel;
|
||||
|
||||
private PhysicsComponent _collidableComponent = default!;
|
||||
private PowerConsumerComponent _powerConsumer = default!;
|
||||
|
||||
// whether the power switch is in "on"
|
||||
[ViewVariables] private bool _isOn;
|
||||
// Whether the power switch is on AND the machine has enough power (so is actively firing)
|
||||
[ViewVariables] private bool _isPowered;
|
||||
[ViewVariables] private bool _isLocked;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] private int _fireShotCounter;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] private string _fireSound = default!;
|
||||
[ViewVariables(VVAccess.ReadWrite)] private string _boltType = default!;
|
||||
[ViewVariables(VVAccess.ReadWrite)] private int _powerUseActive;
|
||||
[ViewVariables(VVAccess.ReadWrite)] private int _fireBurstSize;
|
||||
[ViewVariables(VVAccess.ReadWrite)] private TimeSpan _fireInterval;
|
||||
[ViewVariables(VVAccess.ReadWrite)] private TimeSpan _fireBurstDelayMin;
|
||||
[ViewVariables(VVAccess.ReadWrite)] private TimeSpan _fireBurstDelayMax;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _fireBurstDelayMin, "fireBurstDelayMin", TimeSpan.FromSeconds(2));
|
||||
serializer.DataField(ref _fireBurstDelayMax, "fireBurstDelayMax", TimeSpan.FromSeconds(10));
|
||||
serializer.DataField(ref _fireInterval, "fireInterval", TimeSpan.FromSeconds(2));
|
||||
serializer.DataField(ref _fireBurstSize, "fireBurstSize", 3);
|
||||
serializer.DataField(ref _powerUseActive, "powerUseActive", 500);
|
||||
serializer.DataField(ref _boltType, "boltType", "EmitterBolt");
|
||||
serializer.DataField(ref _fireSound, "fireSound", "/Audio/Weapons/emitter.ogg");
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (!Owner.TryGetComponent(out _collidableComponent!))
|
||||
{
|
||||
Logger.Error($"EmitterComponent {Owner} created with no CollidableComponent");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Owner.TryGetComponent(out _powerConsumer!))
|
||||
{
|
||||
Logger.Error($"EmitterComponent {Owner} created with no PowerConsumerComponent");
|
||||
return;
|
||||
}
|
||||
|
||||
_collidableComponent.AnchoredChanged += OnAnchoredChanged;
|
||||
_powerConsumer.OnReceivedPowerChanged += OnReceivedPowerChanged;
|
||||
}
|
||||
|
||||
private void OnReceivedPowerChanged(object? sender, ReceivedPowerChangedEventArgs e)
|
||||
{
|
||||
if (!_isOn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.ReceivedPower < e.DrawRate)
|
||||
{
|
||||
PowerOff();
|
||||
}
|
||||
else
|
||||
{
|
||||
PowerOn();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnchoredChanged()
|
||||
{
|
||||
if (_collidableComponent.Anchored)
|
||||
Owner.SnapToGrid();
|
||||
}
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if (_isLocked)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("{0:TheName} is access locked!", Owner));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_isOn)
|
||||
{
|
||||
SwitchOn();
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("{0:TheName} turns on.", Owner));
|
||||
}
|
||||
else
|
||||
{
|
||||
SwitchOff();
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("{0:TheName} turns off.", Owner));
|
||||
}
|
||||
}
|
||||
|
||||
Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (_accessReader == null || !eventArgs.Using.TryGetComponent(out IAccess? access))
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
if (_accessReader.IsAllowed(access))
|
||||
{
|
||||
_isLocked ^= true;
|
||||
|
||||
if (_isLocked)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("You lock {0:TheName}.", Owner));
|
||||
}
|
||||
else
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("You unlock {0:TheName}.", Owner));
|
||||
}
|
||||
|
||||
UpdateAppearance();
|
||||
}
|
||||
else
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("Access denied."));
|
||||
}
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
private void SwitchOff()
|
||||
{
|
||||
_isOn = false;
|
||||
_powerConsumer.DrawRate = 0;
|
||||
PowerOff();
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
private void SwitchOn()
|
||||
{
|
||||
_isOn = true;
|
||||
_powerConsumer.DrawRate = _powerUseActive;
|
||||
// Do not directly PowerOn().
|
||||
// OnReceivedPowerChanged will get fired due to DrawRate change which will turn it on.
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
private void PowerOff()
|
||||
{
|
||||
if (!_isPowered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isPowered = false;
|
||||
|
||||
// Must be set while emitter powered.
|
||||
DebugTools.AssertNotNull(_timerCancel);
|
||||
_timerCancel!.Cancel();
|
||||
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
private void PowerOn()
|
||||
{
|
||||
if (_isPowered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isPowered = true;
|
||||
|
||||
_fireShotCounter = 0;
|
||||
_timerCancel = new CancellationTokenSource();
|
||||
|
||||
Timer.Spawn(_fireBurstDelayMax, ShotTimerCallback, _timerCancel.Token);
|
||||
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
private void ShotTimerCallback()
|
||||
{
|
||||
// Any power-off condition should result in the timer for this method being cancelled
|
||||
// and thus not firing
|
||||
DebugTools.Assert(_isPowered);
|
||||
DebugTools.Assert(_isOn);
|
||||
DebugTools.Assert(_powerConsumer.DrawRate <= _powerConsumer.ReceivedPower);
|
||||
|
||||
Fire();
|
||||
|
||||
TimeSpan delay;
|
||||
if (_fireShotCounter < _fireBurstSize)
|
||||
{
|
||||
_fireShotCounter += 1;
|
||||
delay = _fireInterval;
|
||||
}
|
||||
else
|
||||
{
|
||||
_fireShotCounter = 0;
|
||||
var diff = _fireBurstDelayMax - _fireBurstDelayMin;
|
||||
// TIL you can do TimeSpan * double.
|
||||
delay = _fireBurstDelayMin + _robustRandom.NextFloat() * diff;
|
||||
}
|
||||
|
||||
// Must be set while emitter powered.
|
||||
DebugTools.AssertNotNull(_timerCancel);
|
||||
Timer.Spawn(delay, ShotTimerCallback, _timerCancel!.Token);
|
||||
}
|
||||
|
||||
private void Fire()
|
||||
{
|
||||
var projectile = _entityManager.SpawnEntity(_boltType, Owner.Transform.Coordinates);
|
||||
|
||||
if (!projectile.TryGetComponent<PhysicsComponent>(out var physicsComponent))
|
||||
{
|
||||
Logger.Error("Emitter tried firing a bolt, but it was spawned without a CollidableComponent");
|
||||
return;
|
||||
}
|
||||
|
||||
physicsComponent.Status = BodyStatus.InAir;
|
||||
|
||||
if (!projectile.TryGetComponent<ProjectileComponent>(out var projectileComponent))
|
||||
{
|
||||
Logger.Error("Emitter tried firing a bolt, but it was spawned without a ProjectileComponent");
|
||||
return;
|
||||
}
|
||||
|
||||
projectileComponent.IgnoreEntity(Owner);
|
||||
|
||||
physicsComponent
|
||||
.EnsureController<BulletController>()
|
||||
.LinearVelocity = Owner.Transform.WorldRotation.ToVec() * 20f;
|
||||
|
||||
projectile.Transform.LocalRotation = Owner.Transform.WorldRotation;
|
||||
|
||||
// TODO: Move to projectile's code.
|
||||
Timer.Spawn(3000, () => projectile.Delete());
|
||||
|
||||
EntitySystem.Get<AudioSystem>().PlayFromEntity(_fireSound, Owner);
|
||||
}
|
||||
|
||||
private void UpdateAppearance()
|
||||
{
|
||||
if (_appearance == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EmitterVisualState state;
|
||||
if (_isPowered)
|
||||
{
|
||||
state = EmitterVisualState.On;
|
||||
}
|
||||
else if (_isOn)
|
||||
{
|
||||
state = EmitterVisualState.Underpowered;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = EmitterVisualState.Off;
|
||||
}
|
||||
|
||||
_appearance.SetData(EmitterVisuals.VisualState, state);
|
||||
_appearance.SetData(EmitterVisuals.Locked, _isLocked);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.StationEvents;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.EntitySystemMessages;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects.Components.Map;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Timers;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Singularity
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class SingularityComponent : Component, ICollideBehavior
|
||||
{
|
||||
[Dependency] private IEntityManager _entityManager = null!;
|
||||
[Dependency] private IMapManager _mapManager = null!;
|
||||
[Dependency] private IRobustRandom _random = null!;
|
||||
|
||||
|
||||
public override uint? NetID => ContentNetIDs.SINGULARITY;
|
||||
|
||||
public override string Name => "Singularity";
|
||||
|
||||
public int Energy
|
||||
{
|
||||
get => _energy;
|
||||
set
|
||||
{
|
||||
if (value == _energy) return;
|
||||
|
||||
_energy = value;
|
||||
if (_energy <= 0)
|
||||
{
|
||||
if(_singularityController != null) _singularityController.LinearVelocity = Vector2.Zero;
|
||||
_spriteComponent?.LayerSetVisible(0, false);
|
||||
|
||||
Owner.Delete();
|
||||
return;
|
||||
}
|
||||
|
||||
Level = _energy switch
|
||||
{
|
||||
var n when n >= 1500 => 6,
|
||||
var n when n >= 1000 => 5,
|
||||
var n when n >= 600 => 4,
|
||||
var n when n >= 300 => 3,
|
||||
var n when n >= 200 => 2,
|
||||
var n when n < 200 => 1,
|
||||
_ => 1
|
||||
};
|
||||
}
|
||||
}
|
||||
private int _energy = 180;
|
||||
|
||||
public int Level
|
||||
{
|
||||
get => _level;
|
||||
set
|
||||
{
|
||||
if (value == _level) return;
|
||||
if (value < 0) value = 0;
|
||||
if (value > 6) value = 6;
|
||||
|
||||
_level = value;
|
||||
|
||||
if(_radiationPulseComponent != null) _radiationPulseComponent.RadsPerSecond = 10 * value;
|
||||
|
||||
_spriteComponent?.LayerSetRSI(0, "Effects/Singularity/singularity_" + _level + ".rsi");
|
||||
_spriteComponent?.LayerSetState(0, "singularity_" + _level);
|
||||
|
||||
if(_collidableComponent != null && _collidableComponent.PhysicsShapes.Any() && _collidableComponent.PhysicsShapes[0] is PhysShapeCircle circle)
|
||||
{
|
||||
circle.Radius = _level - 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
private int _level;
|
||||
|
||||
public int EnergyDrain =>
|
||||
Level switch
|
||||
{
|
||||
6 => 20,
|
||||
5 => 15,
|
||||
4 => 10,
|
||||
3 => 5,
|
||||
2 => 2,
|
||||
1 => 1,
|
||||
_ => 0
|
||||
};
|
||||
|
||||
private SingularityController? _singularityController;
|
||||
private PhysicsComponent? _collidableComponent;
|
||||
private SpriteComponent? _spriteComponent;
|
||||
private RadiationPulseComponent? _radiationPulseComponent;
|
||||
private AudioSystem _audioSystem = null!;
|
||||
private AudioSystem.AudioSourceServer? _playingSound;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_audioSystem = EntitySystem.Get<AudioSystem>();
|
||||
var audioParams = AudioParams.Default;
|
||||
audioParams.Loop = true;
|
||||
audioParams.MaxDistance = 20f;
|
||||
audioParams.Volume = 5;
|
||||
_audioSystem.PlayFromEntity("/Audio/Effects/singularity_form.ogg", Owner);
|
||||
Timer.Spawn(5200,() => _playingSound = _audioSystem.PlayFromEntity("/Audio/Effects/singularity.ogg", Owner, audioParams));
|
||||
|
||||
|
||||
if (!Owner.TryGetComponent(out _collidableComponent))
|
||||
{
|
||||
Logger.Error("SingularityComponent was spawned without CollidableComponent");
|
||||
}
|
||||
else
|
||||
{
|
||||
_collidableComponent.Hard = false;
|
||||
}
|
||||
|
||||
if (!Owner.TryGetComponent(out _spriteComponent))
|
||||
{
|
||||
Logger.Error("SingularityComponent was spawned without SpriteComponent");
|
||||
}
|
||||
|
||||
_singularityController = _collidableComponent?.EnsureController<SingularityController>();
|
||||
if(_singularityController!=null)_singularityController.ControlledComponent = _collidableComponent;
|
||||
|
||||
if (!Owner.TryGetComponent(out _radiationPulseComponent))
|
||||
{
|
||||
Logger.Error("SingularityComponent was spawned without RadiationPulseComponent");
|
||||
}
|
||||
|
||||
Level = 1;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
Energy -= EnergyDrain;
|
||||
|
||||
if(Level == 1) return;
|
||||
//pushing
|
||||
var pushVector = new Vector2((_random.Next(-10, 10)), _random.Next(-10, 10));
|
||||
while (pushVector.X == 0 && pushVector.Y == 0)
|
||||
{
|
||||
pushVector = new Vector2((_random.Next(-10, 10)), _random.Next(-10, 10));
|
||||
}
|
||||
_singularityController?.Push(pushVector.Normalized, 2);
|
||||
}
|
||||
|
||||
List<IEntity> _previousPulledEntites = new List<IEntity>();
|
||||
public void PullUpdate()
|
||||
{
|
||||
foreach (var previousPulledEntity in _previousPulledEntites)
|
||||
{
|
||||
if(previousPulledEntity.Deleted) continue;
|
||||
if (!previousPulledEntity.TryGetComponent<PhysicsComponent>(out var collidableComponent)) continue;
|
||||
var controller = collidableComponent.EnsureController<SingularityPullController>();
|
||||
controller.StopPull();
|
||||
}
|
||||
_previousPulledEntites.Clear();
|
||||
|
||||
var entitiesToPull = _entityManager.GetEntitiesInRange(Owner.Transform.Coordinates, Level * 10);
|
||||
foreach (var entity in entitiesToPull)
|
||||
{
|
||||
if (!entity.TryGetComponent<PhysicsComponent>(out var collidableComponent)) continue;
|
||||
var controller = collidableComponent.EnsureController<SingularityPullController>();
|
||||
if(Owner.Transform.Coordinates.EntityId != entity.Transform.Coordinates.EntityId) continue;
|
||||
var vec = (Owner.Transform.Coordinates - entity.Transform.Coordinates).Position;
|
||||
if (vec == Vector2.Zero) continue;
|
||||
|
||||
var speed = 10 / vec.Length * Level;
|
||||
|
||||
controller.Pull(vec.Normalized, speed);
|
||||
_previousPulledEntites.Add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
void ICollideBehavior.CollideWith(IEntity entity)
|
||||
{
|
||||
if (_collidableComponent == null) return; //how did it even collide then? :D
|
||||
|
||||
if (entity.TryGetComponent<IMapGridComponent>(out var mapGridComponent))
|
||||
{
|
||||
foreach (var tile in mapGridComponent.Grid.GetTilesIntersecting(((IPhysBody) _collidableComponent).WorldAABB))
|
||||
{
|
||||
mapGridComponent.Grid.SetTile(tile.GridIndices, Tile.Empty);
|
||||
Energy++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.HasComponent<ContainmentFieldComponent>() || (entity.TryGetComponent<ContainmentFieldGeneratorComponent>(out var component) && component.CanRepell(Owner)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ContainerHelpers.IsInContainer(entity)) return;
|
||||
|
||||
entity.Delete();
|
||||
Energy++;
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
_playingSound?.Stop();
|
||||
_audioSystem.PlayAtCoords("/Audio/Effects/singularity_collapse.ogg", Owner.Transform.Coordinates);
|
||||
base.OnRemove();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Singularity
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class SingularityGeneratorComponent : Component
|
||||
{
|
||||
public override string Name => "SingularityGenerator";
|
||||
|
||||
private int _power;
|
||||
|
||||
public int Power
|
||||
{
|
||||
get => _power;
|
||||
set
|
||||
{
|
||||
if(_power == value) return;
|
||||
|
||||
_power = value;
|
||||
if (_power > 15)
|
||||
{
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
entityManager.SpawnEntity("Singularity", Owner.Transform.Coordinates);
|
||||
//dont delete ourselves, just wait to get eaten
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,6 +373,14 @@ namespace Content.Server.GameObjects.Components
|
||||
UserInterface?.Open(session);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes all wire UIs.
|
||||
/// </summary>
|
||||
public void CloseAll()
|
||||
{
|
||||
UserInterface?.CloseAll();
|
||||
}
|
||||
|
||||
private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg)
|
||||
{
|
||||
var message = serverMsg.Message;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.PA;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.Transform;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
|
||||
namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ParticleAcceleratorPartSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
EntityManager.EventBus.SubscribeEvent<RotateEvent>(EventSource.Local, this, RotateEvent);
|
||||
}
|
||||
|
||||
private static void RotateEvent(RotateEvent ev)
|
||||
{
|
||||
if (ev.Sender.TryGetComponent(out ParticleAcceleratorPartComponent? part))
|
||||
{
|
||||
part.Rotated();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Content.Server.GameObjects.Components.Singularity;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
|
||||
namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
public class SingularitySystem : EntitySystem
|
||||
{
|
||||
private float curTimeSingulo;
|
||||
private float curTimePull;
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
curTimeSingulo += frameTime;
|
||||
curTimePull += frameTime;
|
||||
|
||||
var shouldUpdate = curTimeSingulo >= 1f;
|
||||
var shouldPull = curTimePull >= 0.2f;
|
||||
if (!shouldUpdate && !shouldPull) return;
|
||||
var singulos = ComponentManager.EntityQuery<SingularityComponent>();
|
||||
|
||||
if (curTimeSingulo >= 1f)
|
||||
{
|
||||
curTimeSingulo -= 1f;
|
||||
foreach (var singulo in singulos)
|
||||
{
|
||||
singulo.Update();
|
||||
}
|
||||
}
|
||||
|
||||
if (curTimePull >= 0.5f)
|
||||
{
|
||||
curTimePull -= 0.5f;
|
||||
foreach (var singulo in singulos)
|
||||
{
|
||||
singulo.PullUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user