Merge branch 'master' into replace-sounds-with-sound-specifier
# Conflicts: # Content.Server/Actions/Actions/DisarmAction.cs # Content.Server/Actions/Actions/ScreamAction.cs # Content.Server/Arcade/Components/SpaceVillainArcadeComponent.cs # Content.Server/Damage/Components/DamageOnHighSpeedImpactComponent.cs # Content.Server/Explosion/Components/FlashExplosiveComponent.cs # Content.Server/Physics/Controllers/MoverController.cs # Content.Server/Portal/Components/PortalComponent.cs # Content.Server/Portal/Components/TeleporterComponent.cs # Content.Server/Projectiles/Components/ProjectileComponent.cs # Content.Server/Singularity/Components/EmitterComponent.cs # Content.Server/Sound/EmitSoundSystem.cs # Content.Server/Stunnable/Components/StunbatonComponent.cs # Content.Server/Tools/Components/MultitoolComponent.cs # Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs # Content.Shared/Gravity/GravityComponent.cs # Content.Shared/Light/Component/SharedExpendableLightComponent.cs # Content.Shared/Maps/ContentTileDefinition.cs # Content.Shared/Slippery/SlipperyComponent.cs # Content.Shared/Standing/StandingStateComponent.cs # Resources/Prototypes/Entities/Objects/Fun/bike_horn.yml
This commit is contained in:
@@ -1,25 +1,11 @@
|
||||
#nullable enable
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
namespace Content.Server.Singularity.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class ContainmentFieldComponent : Component, IStartCollide
|
||||
public class ContainmentFieldComponent : Component
|
||||
{
|
||||
public override string Name => "ContainmentField";
|
||||
public ContainmentFieldConnection? Parent;
|
||||
|
||||
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold)
|
||||
{
|
||||
if (Parent == null)
|
||||
{
|
||||
Owner.QueueDelete();
|
||||
return;
|
||||
}
|
||||
|
||||
Parent.TryRepell(Owner, otherFixture.Body.Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,19 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Singularity.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class ContainmentFieldGeneratorComponent : Component, IStartCollide
|
||||
public class ContainmentFieldGeneratorComponent : Component
|
||||
{
|
||||
public override string Name => "ContainmentFieldGenerator";
|
||||
|
||||
@@ -101,7 +97,7 @@ namespace Content.Server.Singularity.Components
|
||||
|
||||
var dirVec = direction.ToVec();
|
||||
var ray = new CollisionRay(Owner.Transform.WorldPosition, dirVec, (int) CollisionGroup.MobMask);
|
||||
var rawRayCastResults = EntitySystem.Get<SharedBroadPhaseSystem>().IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
|
||||
var rawRayCastResults = EntitySystem.Get<SharedBroadphaseSystem>().IntersectRay(Owner.Transform.MapID, ray, 4.5f, Owner, false);
|
||||
|
||||
var rayCastResults = rawRayCastResults as RayCastResults[] ?? rawRayCastResults.ToArray();
|
||||
if(!rayCastResults.Any()) continue;
|
||||
@@ -166,13 +162,6 @@ namespace Content.Server.Singularity.Components
|
||||
}
|
||||
}
|
||||
|
||||
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold)
|
||||
{
|
||||
if (otherFixture.Body.Owner.HasTag("EmitterBolt")) {
|
||||
ReceivePower(6);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateConnectionLights()
|
||||
{
|
||||
if (_pointLightComponent != null)
|
||||
|
||||
@@ -1,261 +1,47 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Access.Components;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Projectiles.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Notification;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Timer = Robust.Shared.Timing.Timer;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Content.Server.Singularity.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public class EmitterComponent : Component, IActivate, IInteractUsing
|
||||
public class EmitterComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
|
||||
[ComponentDependency] private readonly AppearanceComponent? _appearance = default;
|
||||
[ComponentDependency] private readonly AccessReader? _accessReader = default;
|
||||
[ComponentDependency] public readonly AppearanceComponent? Appearance = default;
|
||||
[ComponentDependency] public readonly AccessReader? AccessReader = default;
|
||||
[ComponentDependency] public readonly PowerConsumerComponent? PowerConsumer = default;
|
||||
|
||||
public override string Name => "Emitter";
|
||||
|
||||
private CancellationTokenSource? _timerCancel;
|
||||
|
||||
private PowerConsumerComponent _powerConsumer = default!;
|
||||
public CancellationTokenSource? TimerCancel;
|
||||
|
||||
// whether the power switch is in "on"
|
||||
[ViewVariables] public bool IsOn { get; private set; }
|
||||
[ViewVariables] public 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] public bool IsPowered;
|
||||
[ViewVariables] public bool IsLocked;
|
||||
|
||||
// For the "emitter fired" sound
|
||||
private const float Variation = 0.25f;
|
||||
private const float Volume = 0.5f;
|
||||
private const float Distance = 3f;
|
||||
public const float Variation = 0.25f;
|
||||
public const float Volume = 0.5f;
|
||||
public const float Distance = 3f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] private int _fireShotCounter;
|
||||
[ViewVariables] public int FireShotCounter;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("fireSound")] private SoundSpecifier _fireSound = new SoundPathSpecifier("/Audio/Weapons/emitter.ogg");
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("boltType")] private string _boltType = "EmitterBolt";
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("powerUseActive")] private int _powerUseActive = 500;
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("fireBurstSize")] private int _fireBurstSize = 3;
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("fireInterval")] private TimeSpan _fireInterval = TimeSpan.FromSeconds(2);
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("fireBurstDelayMin")] private TimeSpan _fireBurstDelayMin = TimeSpan.FromSeconds(2);
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("fireBurstDelayMax")] private TimeSpan _fireBurstDelayMax = TimeSpan.FromSeconds(10);
|
||||
[ViewVariables] [DataField("fireSound")] public string FireSound = "/Audio/Weapons/emitter.ogg";
|
||||
[ViewVariables] [DataField("boltType")] public string BoltType = "EmitterBolt";
|
||||
[ViewVariables] [DataField("powerUseActive")] public int PowerUseActive = 500;
|
||||
[ViewVariables] [DataField("fireBurstSize")] public int FireBurstSize = 3;
|
||||
[ViewVariables] [DataField("fireInterval")] public TimeSpan FireInterval = TimeSpan.FromSeconds(2);
|
||||
[ViewVariables] [DataField("fireBurstDelayMin")] public TimeSpan FireBurstDelayMin = TimeSpan.FromSeconds(2);
|
||||
[ViewVariables] [DataField("fireBurstDelayMax")] public TimeSpan FireBurstDelayMax = TimeSpan.FromSeconds(10);
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if (_isLocked)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-access-locked", ("target", Owner)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out PhysicsComponent? phys) && phys.BodyType == BodyType.Static)
|
||||
{
|
||||
if (!IsOn)
|
||||
{
|
||||
SwitchOn();
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-turned-on", ("target", Owner)));
|
||||
}
|
||||
else
|
||||
{
|
||||
SwitchOff();
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-turned-off", ("target", Owner)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-not-anchored", ("target", 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("comp-emitter-lock", ("target", Owner)));
|
||||
}
|
||||
else
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-unlock", ("target", Owner)));
|
||||
}
|
||||
|
||||
UpdateAppearance();
|
||||
}
|
||||
else
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-access-denied"));
|
||||
}
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public void SwitchOff()
|
||||
{
|
||||
IsOn = false;
|
||||
_powerConsumer.DrawRate = 0;
|
||||
PowerOff();
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public 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();
|
||||
}
|
||||
|
||||
public void PowerOff()
|
||||
{
|
||||
if (!_isPowered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isPowered = false;
|
||||
|
||||
// Must be set while emitter powered.
|
||||
DebugTools.AssertNotNull(_timerCancel);
|
||||
_timerCancel!.Cancel();
|
||||
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public 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 = Owner.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 PhysicsComponent");
|
||||
return;
|
||||
}
|
||||
|
||||
physicsComponent.BodyStatus = 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
|
||||
.LinearVelocity = Owner.Transform.WorldRotation.ToWorldVec() * 20f;
|
||||
projectile.Transform.WorldRotation = Owner.Transform.WorldRotation;
|
||||
|
||||
// TODO: Move to projectile's code.
|
||||
Timer.Spawn(3000, () => projectile.Delete());
|
||||
|
||||
if(_fireSound.TryGetSound(out var fireSound))
|
||||
SoundSystem.Play(Filter.Pvs(Owner), fireSound, Owner,
|
||||
AudioHelpers.WithVariation(Variation).WithVolume(Volume).WithMaxDistance(Distance));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Interaction;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#nullable enable
|
||||
using Content.Shared.Singularity;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Content.Shared.Sound;
|
||||
@@ -17,7 +16,7 @@ namespace Content.Server.Singularity.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedSingularityComponent))]
|
||||
public class ServerSingularityComponent : SharedSingularityComponent, IStartCollide
|
||||
public class ServerSingularityComponent : SharedSingularityComponent
|
||||
{
|
||||
private SharedSingularitySystem _singularitySystem = default!;
|
||||
|
||||
@@ -102,46 +101,6 @@ namespace Content.Server.Singularity.Components
|
||||
Energy -= EnergyDrain * seconds;
|
||||
}
|
||||
|
||||
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold)
|
||||
{
|
||||
// If we're being deleted by another singularity, this call is probably for that singularity.
|
||||
// Even if not, just don't bother.
|
||||
if (BeingDeletedByAnotherSingularity)
|
||||
return;
|
||||
|
||||
var otherEntity = otherFixture.Body.Owner;
|
||||
|
||||
if (otherEntity.TryGetComponent<IMapGridComponent>(out var mapGridComponent))
|
||||
{
|
||||
foreach (var tile in mapGridComponent.Grid.GetTilesIntersecting(ourFixture.Body.GetWorldAABB()))
|
||||
{
|
||||
mapGridComponent.Grid.SetTile(tile.GridIndices, Robust.Shared.Map.Tile.Empty);
|
||||
Energy++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (otherEntity.HasComponent<ContainmentFieldComponent>() ||
|
||||
(otherEntity.TryGetComponent<ContainmentFieldGeneratorComponent>(out var component) && component.CanRepell(Owner)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (otherEntity.IsInContainer())
|
||||
return;
|
||||
|
||||
// Singularity priority management / etc.
|
||||
if (otherEntity.TryGetComponent<ServerSingularityComponent>(out var otherSingulo))
|
||||
otherSingulo.BeingDeletedByAnotherSingularity = true;
|
||||
|
||||
otherEntity.QueueDelete();
|
||||
|
||||
if (otherEntity.TryGetComponent<SinguloFoodComponent>(out var singuloFood))
|
||||
Energy += singuloFood.Energy;
|
||||
else
|
||||
Energy++;
|
||||
}
|
||||
|
||||
protected override void OnRemove()
|
||||
{
|
||||
_playingSound?.Stop();
|
||||
|
||||
Reference in New Issue
Block a user