Make emitter use guncode (#13258)
This commit is contained in:
@@ -15,20 +15,12 @@ namespace Content.Server.Singularity.Components
|
|||||||
// Whether the power switch is on AND the machine has enough power (so is actively firing)
|
// Whether the power switch is on AND the machine has enough power (so is actively firing)
|
||||||
[ViewVariables] public bool IsPowered;
|
[ViewVariables] public bool IsPowered;
|
||||||
|
|
||||||
// For the "emitter fired" sound
|
|
||||||
public const float Variation = 0.25f;
|
|
||||||
public const float Volume = 0.5f;
|
|
||||||
public const float Distance = 6f;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// counts the number of consecutive shots fired.
|
/// counts the number of consecutive shots fired.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public int FireShotCounter;
|
public int FireShotCounter;
|
||||||
|
|
||||||
[DataField("fireSound")]
|
|
||||||
public SoundSpecifier FireSound = new SoundPathSpecifier("/Audio/Weapons/emitter.ogg");
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The entity that is spawned when the emitter fires.
|
/// The entity that is spawned when the emitter fires.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -6,16 +6,17 @@ using Content.Server.Power.EntitySystems;
|
|||||||
using Content.Server.Projectiles;
|
using Content.Server.Projectiles;
|
||||||
using Content.Server.Singularity.Components;
|
using Content.Server.Singularity.Components;
|
||||||
using Content.Server.Storage.Components;
|
using Content.Server.Storage.Components;
|
||||||
|
using Content.Server.Weapons.Ranged.Systems;
|
||||||
using Content.Shared.Database;
|
using Content.Shared.Database;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.Projectiles;
|
using Content.Shared.Projectiles;
|
||||||
using Content.Shared.Singularity.Components;
|
using Content.Shared.Singularity.Components;
|
||||||
|
using Content.Shared.Weapons.Ranged.Components;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Physics.Components;
|
using Robust.Shared.Physics.Components;
|
||||||
using Robust.Shared.Physics.Systems;
|
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using Timer = Robust.Shared.Timing.Timer;
|
using Timer = Robust.Shared.Timing.Timer;
|
||||||
@@ -28,10 +29,9 @@ namespace Content.Server.Singularity.EntitySystems
|
|||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
||||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||||
[Dependency] private readonly ProjectileSystem _projectile = default!;
|
[Dependency] private readonly ProjectileSystem _projectile = default!;
|
||||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
[Dependency] private readonly GunSystem _gun = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -207,33 +207,16 @@ namespace Content.Server.Singularity.EntitySystems
|
|||||||
private void Fire(EmitterComponent component)
|
private void Fire(EmitterComponent component)
|
||||||
{
|
{
|
||||||
var uid = component.Owner;
|
var uid = component.Owner;
|
||||||
var projectile = EntityManager.SpawnEntity(component.BoltType, EntityManager.GetComponent<TransformComponent>(uid).Coordinates);
|
if (!TryComp<GunComponent>(uid, out var guncomp))
|
||||||
|
|
||||||
if (!EntityManager.TryGetComponent<PhysicsComponent?>(projectile, out var physicsComponent))
|
|
||||||
{
|
|
||||||
Logger.Error("Emitter tried firing a bolt, but it was spawned without a PhysicsComponent");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
physicsComponent.BodyStatus = BodyStatus.InAir;
|
var xform = Transform(uid);
|
||||||
|
var ent = Spawn(component.BoltType, xform.Coordinates);
|
||||||
|
var proj = EnsureComp<ProjectileComponent>(ent);
|
||||||
|
_projectile.SetShooter(proj, uid);
|
||||||
|
|
||||||
if (!EntityManager.TryGetComponent<ProjectileComponent?>(projectile, out var projectileComponent))
|
var targetPos = new EntityCoordinates(uid, (0, -1));
|
||||||
{
|
_gun.Shoot(guncomp, ent, xform.Coordinates, targetPos);
|
||||||
Logger.Error("Emitter tried firing a bolt, but it was spawned without a ProjectileComponent");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_projectile.SetShooter(projectileComponent, component.Owner);
|
|
||||||
|
|
||||||
var worldRotation = Transform(uid).WorldRotation;
|
|
||||||
_physics.SetLinearVelocity(physicsComponent, worldRotation.ToWorldVec() * 20f);
|
|
||||||
Transform(projectile).WorldRotation = worldRotation;
|
|
||||||
|
|
||||||
// TODO: Move to projectile's code.
|
|
||||||
Timer.Spawn(3000, () => EntityManager.DeleteEntity(projectile));
|
|
||||||
|
|
||||||
_audio.PlayPvs(component.FireSound, component.Owner,
|
|
||||||
AudioParams.Default.WithVariation(EmitterComponent.Variation).WithVolume(EmitterComponent.Volume).WithMaxDistance(EmitterComponent.Distance));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateAppearance(EmitterComponent component)
|
private void UpdateAppearance(EmitterComponent component)
|
||||||
|
|||||||
@@ -222,6 +222,7 @@
|
|||||||
- state: projectile
|
- state: projectile
|
||||||
shader: unshaded
|
shader: unshaded
|
||||||
- type: Ammo
|
- type: Ammo
|
||||||
|
muzzleFlash: null
|
||||||
- type: Physics
|
- type: Physics
|
||||||
- type: Fixtures
|
- type: Fixtures
|
||||||
fixtures:
|
fixtures:
|
||||||
@@ -242,6 +243,8 @@
|
|||||||
- type: Tag
|
- type: Tag
|
||||||
tags:
|
tags:
|
||||||
- EmitterBolt
|
- EmitterBolt
|
||||||
|
- type: TimedDespawn
|
||||||
|
lifetime: 3
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: BulletKinetic
|
id: BulletKinetic
|
||||||
|
|||||||
@@ -34,6 +34,13 @@
|
|||||||
shader: unshaded
|
shader: unshaded
|
||||||
visible: false
|
visible: false
|
||||||
- type: Emitter
|
- type: Emitter
|
||||||
|
- type: Gun
|
||||||
|
fireRate: 10 #just has to be fast enough to keep up with upgrades
|
||||||
|
selectedMode: SemiAuto
|
||||||
|
availableModes:
|
||||||
|
- SemiAuto
|
||||||
|
soundGunshot:
|
||||||
|
path: /Audio/Weapons/emitter.ogg
|
||||||
- type: PowerConsumer
|
- type: PowerConsumer
|
||||||
voltage: Medium
|
voltage: Medium
|
||||||
- type: NodeContainer
|
- type: NodeContainer
|
||||||
|
|||||||
Reference in New Issue
Block a user