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

@@ -195,7 +195,6 @@ namespace Content.Client
"ContainmentField", "ContainmentField",
"Emitter", "Emitter",
"SingularityGenerator", "SingularityGenerator",
"EmitterBoltComponent",
"ParticleProjectile", "ParticleProjectile",
"ParticleAcceleratorControlBox", "ParticleAcceleratorControlBox",
"ParticleAcceleratorEmitter", "ParticleAcceleratorEmitter",

View File

@@ -1,4 +1,5 @@
#nullable enable #nullable enable
using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Interactable; using Content.Server.GameObjects.Components.Interactable;
@@ -74,6 +75,10 @@ namespace Content.Server.GameObjects.Components
var physics = Owner.GetComponent<IPhysBody>(); var physics = Owner.GetComponent<IPhysBody>();
physics.BodyType = BodyType.Static; 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 (Owner.TryGetComponent(out PullableComponent? pullableComponent))
{ {
if (pullableComponent.Puller != null) 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; containmentFieldComponent.Parent = this;
newEnt.Transform.WorldRotation = dirVec.ToAngle(); newEnt.Transform.WorldRotation = dirVec.ToWorldAngle();
_fields.Add(newEnt); _fields.Add(newEnt);
currentOffset += dirVec; currentOffset += dirVec;

View File

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

View File

@@ -1,3 +1,4 @@
#nullable enable
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; 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.Power.PowerNetComponents;
using Content.Server.GameObjects.Components.Projectiles; using Content.Server.GameObjects.Components.Projectiles;
using Content.Server.Interfaces; using Content.Server.Interfaces;
using Content.Server.Utility; using Content.Shared.Audio;
using Content.Shared.GameObjects.Components.Singularity; using Content.Shared.GameObjects.Components.Singularity;
using Content.Shared.Interfaces; using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
@@ -48,6 +49,11 @@ namespace Content.Server.GameObjects.Components.Singularity
[ViewVariables] private bool _isPowered; [ViewVariables] private bool _isPowered;
[ViewVariables] private bool _isLocked; [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)] private int _fireShotCounter;
[ViewVariables(VVAccess.ReadWrite)] [DataField("fireSound")] private string _fireSound = "/Audio/Weapons/emitter.ogg"; [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"); Logger.Error($"EmitterComponent {Owner} created with no PowerConsumerComponent");
return; return;
} }
_powerConsumer.OnReceivedPowerChanged += OnReceivedPowerChanged; _powerConsumer.OnReceivedPowerChanged += OnReceivedPowerChanged;
} }
@@ -91,19 +98,26 @@ namespace Content.Server.GameObjects.Components.Singularity
{ {
if (_isLocked) 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; return;
} }
if (!_isOn) if (Owner.TryGetComponent(out PhysicsComponent? phys) && phys.Anchored)
{ {
SwitchOn(); if (!_isOn)
Owner.PopupMessage(eventArgs.User, Loc.GetString("{0:TheName} turns on.", Owner)); {
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 else
{ {
SwitchOff(); Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-not-anchored", ("target", Owner)));
Owner.PopupMessage(eventArgs.User, Loc.GetString("{0:TheName} turns off.", Owner));
} }
} }
@@ -120,18 +134,18 @@ namespace Content.Server.GameObjects.Components.Singularity
if (_isLocked) 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 else
{ {
Owner.PopupMessage(eventArgs.User, Loc.GetString("You unlock {0:TheName}.", Owner)); Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-unlock", ("target", Owner)));
} }
UpdateAppearance(); UpdateAppearance();
} }
else else
{ {
Owner.PopupMessage(eventArgs.User, Loc.GetString("Access denied.")); Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-access-denied"));
} }
return Task.FromResult(true); return Task.FromResult(true);
@@ -222,7 +236,7 @@ namespace Content.Server.GameObjects.Components.Singularity
if (!projectile.TryGetComponent<PhysicsComponent>(out var physicsComponent)) 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; return;
} }
@@ -238,13 +252,13 @@ namespace Content.Server.GameObjects.Components.Singularity
physicsComponent physicsComponent
.LinearVelocity = Owner.Transform.WorldRotation.ToWorldVec() * 20f; .LinearVelocity = Owner.Transform.WorldRotation.ToWorldVec() * 20f;
projectile.Transform.WorldRotation = Owner.Transform.WorldRotation; projectile.Transform.WorldRotation = Owner.Transform.WorldRotation;
// TODO: Move to projectile's code. // TODO: Move to projectile's code.
Timer.Spawn(3000, () => projectile.Delete()); 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() private void UpdateAppearance()

View File

@@ -0,0 +1,20 @@
### EmitterComponent
# Shows when attempting to turn the emitter on or off without proper access
comp-emitter-access-locked = The {$target} is access locked!
# Shows when attempting to lock or unlock the emitter without proper access
comp-emitter-access-denied = Access denied.
# Shows when locking/unlocking the emitter
comp-emitter-lock = You lock the {$target}.
comp-emitter-unlock = You unlock the {$target}.
# Shows when turning the emitter on/off
comp-emitter-turned-on = The {$target} turns on.
comp-emitter-turned-off = The {$target} turns off.
# Shows if the user attempts to activate the emitter while it's un-anchored.
comp-emitter-not-anchored = The {$target} isn't anchored to the ground!

View File

@@ -0,0 +1,4 @@
### Emitter entity prototype data.
ent-emitter = emitter
.desc = A machine that fires bolts of energy, used for powering containment fields at a safe distance.

View File

@@ -43182,76 +43182,82 @@ entities:
- uid: 4401 - uid: 4401
type: Emitter type: Emitter
components: components:
- rot: 4.371139006309477E-08 rad - pos: 45.5,-17.5
pos: 45.5,-17.5
parent: 853 parent: 853
type: Transform type: Transform
- uid: 4402 - uid: 4402
type: Emitter type: Emitter
components: components:
- rot: 4.371139006309477E-08 rad - pos: 49.5,-17.5
pos: 49.5,-17.5
parent: 853 parent: 853
type: Transform type: Transform
- uid: 4403 - uid: 4403
type: Emitter type: Emitter
components: components:
- rot: 4.371139006309477E-08 rad - pos: 53.5,-17.5
pos: 53.5,-17.5
parent: 853 parent: 853
type: Transform type: Transform
- uid: 4404 - uid: 4404
type: Emitter type: Emitter
components: components:
- pos: 56.5,-20.5 - rot: -1.5707963267948966 rad
pos: 56.5,-20.5
parent: 853 parent: 853
type: Transform type: Transform
- uid: 4405 - uid: 4405
type: Emitter type: Emitter
components: components:
- pos: 56.5,-24.5 - rot: -1.5707963267948966 rad
pos: 56.5,-24.5
parent: 853 parent: 853
type: Transform type: Transform
- uid: 4406 - uid: 4406
type: Emitter type: Emitter
components: components:
- pos: 56.5,-28.5 - rot: -1.5707963267948966 rad
pos: 56.5,-28.5
parent: 853 parent: 853
type: Transform type: Transform
- uid: 4407 - uid: 4407
type: Emitter type: Emitter
components: components:
- pos: 53.5,-31.5 - rot: 3.141592653589793 rad
pos: 53.5,-31.5
parent: 853 parent: 853
type: Transform type: Transform
- uid: 4408 - uid: 4408
type: Emitter type: Emitter
components: components:
- pos: 49.5,-31.5 - rot: 3.141592653589793 rad
pos: 49.5,-31.5
parent: 853 parent: 853
type: Transform type: Transform
- uid: 4409 - uid: 4409
type: Emitter type: Emitter
components: components:
- pos: 45.5,-31.5 - rot: 3.141592653589793 rad
pos: 45.5,-31.5
parent: 853 parent: 853
type: Transform type: Transform
- uid: 4410 - uid: 4410
type: Emitter type: Emitter
components: components:
- pos: 42.5,-28.5 - rot: 1.5707963267948966 rad
pos: 42.5,-28.5
parent: 853 parent: 853
type: Transform type: Transform
- uid: 4411 - uid: 4411
type: Emitter type: Emitter
components: components:
- pos: 42.5,-24.5 - rot: 1.5707963267948966 rad
pos: 42.5,-24.5
parent: 853 parent: 853
type: Transform type: Transform
- uid: 4412 - uid: 4412
type: Emitter type: Emitter
components: components:
- pos: 42.5,-20.5 - rot: 1.5707963267948966 rad
pos: 42.5,-20.5
parent: 853 parent: 853
type: Transform type: Transform
- uid: 4413 - uid: 4413

View File

@@ -8,7 +8,7 @@
- type: Clickable - type: Clickable
- type: InteractionOutline - type: InteractionOutline
- type: Physics - type: Physics
bodyType: Dynamic bodyType: Static
mass: 25 mass: 25
fixtures: fixtures:
- shape: - shape:

View File

@@ -8,7 +8,7 @@
- type: InteractionOutline - type: InteractionOutline
- type: Clickable - type: Clickable
- type: Physics - type: Physics
bodyType: Dynamic bodyType: Static
mass: 25 mass: 25
fixtures: fixtures:
- shape: - shape:

View File

@@ -1,6 +1,4 @@
- type: entity - type: entity
name: emitter
description: "A machine that fires bolts of energy, used for powering containment fields at a safe distance."
id: Emitter id: Emitter
placement: placement:
mode: SnapgridCenter mode: SnapgridCenter
@@ -8,12 +6,12 @@
- type: Clickable - type: Clickable
- type: InteractionOutline - type: InteractionOutline
- type: Physics - type: Physics
mass: 25 mass: 100
bodyType: Dynamic bodyType: Static
fixtures: fixtures:
- shape: - shape:
!type:PhysShapeAabb !type:PhysShapeAabb
bounds: "-0.5, -0.5, 0.5, 0.5" bounds: "-0.25, -0.25, 0.25, 0.25"
layer: layer:
- Impassable - Impassable
- MobImpassable - MobImpassable
@@ -43,6 +41,23 @@
nodes: nodes:
- !type:AdjacentNode - !type:AdjacentNode
nodeGroupID: MVPower nodeGroupID: MVPower
- type: Damageable
resistances: metallicResistances
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 200
behaviors:
- !type:PlaySoundBehavior
sound: /Audio/Effects/metalbreak.ogg
- !type:SpawnEntitiesBehavior
spawn:
SheetSteel1:
min: 5
max: 5
- !type:DoActsBehavior
acts: [ "Destruction" ]
- type: Anchorable - type: Anchorable
snap: true snap: true
- type: Pullable - type: Pullable
@@ -53,23 +68,3 @@
- type: AccessReader - type: AccessReader
access: [[ "Engineering" ]] access: [[ "Engineering" ]]
- type: entity
name: Emitter Bolt
description: "A bolt of energy."
id: EmitterBolt
parent: BulletBase
components:
- type: Sprite
sprite: Constructible/Power/Singularity/emitter.rsi
state: ''
layers:
- state: projectile
shader: unshaded
- type: Icon
sprite: Constructible/Power/Singularity/emitter.rsi
state: projectile
- type: EmitterBoltComponent
- type: Projectile
soundHit: /Audio/Weapons/Guns/Hits/bullet_hit.ogg
damages:
Heat: 20

View File

@@ -12,7 +12,7 @@
- type: InteractionOutline - type: InteractionOutline
- type: Clickable - type: Clickable
- type: Physics - type: Physics
bodyType: Dynamic bodyType: Static
mass: 25 mass: 25
fixtures: fixtures:
- shape: - shape:

View File

@@ -73,11 +73,29 @@
- type: StunnableProjectile - type: StunnableProjectile
paralyzeAmount: 2 paralyzeAmount: 2
# Energy projectiles
- type: entity - type: entity
name : taser name : taser bolt
id: BulletTaser id: BulletTaser
parent: BulletBase
abstract: true abstract: true
components: components:
- type: Sprite
directional: false
sprite: Objects/Weapons/Guns/Projectiles/spark.rsi
color: "#ffff33"
layers:
- state: spark
shader: unshaded
- type: Physics
fixtures:
- shape:
!type:PhysShapeAabb
bounds: "-0.2,-0.2,0.2,0.2"
hard: false
mask:
- Impassable
- MobImpassable
- type: Ammo - type: Ammo
isProjectile: true isProjectile: true
ammoVelocity: 20 ammoVelocity: 20
@@ -89,22 +107,35 @@
- type: StunnableProjectile - type: StunnableProjectile
stunAmount: 5 stunAmount: 5
knockdownAmount: 5 knockdownAmount: 5
- type: entity
name: emitter bolt
id: EmitterBolt
parent: BulletBase
abstract: true
components:
- type: Sprite - type: Sprite
noRot: false
sprite: Objects/Weapons/Guns/Projectiles/spark.rsi
color: "#ffff33" color: "#ffff33"
layers: sprite: Constructible/Power/Singularity/emitter.rsi
- state: spark state: 'projectile'
shader: unshaded
- type: Physics - type: Physics
bodyType: Dynamic
fixtures: fixtures:
- shape: - shape:
!type:PhysShapeAabb !type:PhysShapeAabb
bounds: "-0.2,-0.2,0.2,0.2" bounds: "-0.2,-0.2,0.2,0.2"
hard: false hard: false
layer: 32 layer:
mask: 30 - Impassable
- MobImpassable
mask:
- Opaque
- type: Projectile
soundHit: /Audio/Weapons/Guns/Hits/bullet_hit.ogg
damages:
Heat: 20
- type: Tag
tags:
- EmitterBolt
# Launcher projectiles (grenade / rocket) # Launcher projectiles (grenade / rocket)
- type: entity - type: entity

View File

@@ -45,3 +45,6 @@
- type: Tag - type: Tag
id: Write id: Write
- type: Tag
id: EmitterBolt