Fix various issues with the emitter (#3329)

Co-authored-by: cyclowns <cyclowns@protonmail.ch>
This commit is contained in:
mirrorcult
2021-03-14 15:02:22 -07:00
committed by GitHub
parent c73ef7c9af
commit e81db48cd1
15 changed files with 147 additions and 86 deletions

View File

@@ -1,4 +1,5 @@
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Interactable;
@@ -74,6 +75,10 @@ namespace Content.Server.GameObjects.Components
var physics = Owner.GetComponent<IPhysBody>();
physics.BodyType = BodyType.Static;
// Snap rotation to cardinal (multiple of 90)
var rot = Owner.Transform.LocalRotation;
Owner.Transform.LocalRotation = Math.Round(rot / (Math.PI / 2)) * (Math.PI / 2);
if (Owner.TryGetComponent(out PullableComponent? pullableComponent))
{
if (pullableComponent.Puller != null)

View File

@@ -1,10 +0,0 @@
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Projectiles
{
[RegisterComponent]
public class EmitterBoltComponent : Component
{
public override string Name => "EmitterBoltComponent";
}
}

View File

@@ -62,7 +62,7 @@ namespace Content.Server.GameObjects.Components.Singularity
}
containmentFieldComponent.Parent = this;
newEnt.Transform.WorldRotation = dirVec.ToAngle();
newEnt.Transform.WorldRotation = dirVec.ToWorldAngle();
_fields.Add(newEnt);
currentOffset += dirVec;

View File

@@ -2,8 +2,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server.GameObjects.Components.Projectiles;
using Content.Server.Utility;
using Content.Shared.GameObjects.Components.Tag;
using Content.Shared.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -85,11 +84,7 @@ namespace Content.Server.GameObjects.Components.Singularity
private void OnAnchoredChanged()
{
if(_collidableComponent?.Anchored == true)
{
Owner.SnapToGrid();
}
else
if(_collidableComponent?.Anchored != true)
{
_connection1?.Item2.Dispose();
_connection2?.Item2.Dispose();
@@ -186,8 +181,7 @@ namespace Content.Server.GameObjects.Components.Singularity
void IStartCollide.CollideWith(IPhysBody ourBody, IPhysBody otherBody, in Manifold manifold)
{
if (otherBody.Entity.HasComponent<EmitterBoltComponent>())
{
if(otherBody.Entity.HasTag("EmitterBolt")) {
ReceivePower(4);
}
}

View File

@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Threading;
using System.Threading.Tasks;
@@ -5,7 +6,7 @@ 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.Audio;
using Content.Shared.GameObjects.Components.Singularity;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
@@ -48,6 +49,11 @@ namespace Content.Server.GameObjects.Components.Singularity
[ViewVariables] private bool _isPowered;
[ViewVariables] private bool _isLocked;
// For the "emitter fired" sound
private const float Variation = 0.25f;
private const float Volume = 0.5f;
private const float Distance = 3f;
[ViewVariables(VVAccess.ReadWrite)] private int _fireShotCounter;
[ViewVariables(VVAccess.ReadWrite)] [DataField("fireSound")] private string _fireSound = "/Audio/Weapons/emitter.ogg";
@@ -67,6 +73,7 @@ namespace Content.Server.GameObjects.Components.Singularity
Logger.Error($"EmitterComponent {Owner} created with no PowerConsumerComponent");
return;
}
_powerConsumer.OnReceivedPowerChanged += OnReceivedPowerChanged;
}
@@ -91,19 +98,26 @@ namespace Content.Server.GameObjects.Components.Singularity
{
if (_isLocked)
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("{0:TheName} is access locked!", Owner));
Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-access-locked", ("target", Owner)));
return;
}
if (!_isOn)
if (Owner.TryGetComponent(out PhysicsComponent? phys) && phys.Anchored)
{
SwitchOn();
Owner.PopupMessage(eventArgs.User, Loc.GetString("{0:TheName} turns on.", Owner));
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
{
SwitchOff();
Owner.PopupMessage(eventArgs.User, Loc.GetString("{0:TheName} turns off.", Owner));
Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-not-anchored", ("target", Owner)));
}
}
@@ -120,18 +134,18 @@ namespace Content.Server.GameObjects.Components.Singularity
if (_isLocked)
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("You lock {0:TheName}.", Owner));
Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-lock", ("target", Owner)));
}
else
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("You unlock {0:TheName}.", Owner));
Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-unlock", ("target", Owner)));
}
UpdateAppearance();
}
else
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("Access denied."));
Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-access-denied"));
}
return Task.FromResult(true);
@@ -222,7 +236,7 @@ namespace Content.Server.GameObjects.Components.Singularity
if (!projectile.TryGetComponent<PhysicsComponent>(out var physicsComponent))
{
Logger.Error("Emitter tried firing a bolt, but it was spawned without a CollidableComponent");
Logger.Error("Emitter tried firing a bolt, but it was spawned without a PhysicsComponent");
return;
}
@@ -238,13 +252,13 @@ namespace Content.Server.GameObjects.Components.Singularity
physicsComponent
.LinearVelocity = Owner.Transform.WorldRotation.ToWorldVec() * 20f;
projectile.Transform.WorldRotation = Owner.Transform.WorldRotation;
// TODO: Move to projectile's code.
Timer.Spawn(3000, () => projectile.Delete());
EntitySystem.Get<AudioSystem>().PlayFromEntity(_fireSound, Owner);
EntitySystem.Get<AudioSystem>().PlayFromEntity(_fireSound, Owner,
AudioHelpers.WithVariation(Variation).WithVolume(Volume).WithMaxDistance(Distance));
}
private void UpdateAppearance()