Make emitter use guncode (#13258)

This commit is contained in:
Nemanja
2023-01-01 18:54:47 -05:00
committed by GitHub
parent e6097d0301
commit 4a7c0b94b2
4 changed files with 21 additions and 36 deletions

View File

@@ -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)
[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>
/// counts the number of consecutive shots fired.
/// </summary>
[ViewVariables]
public int FireShotCounter;
[DataField("fireSound")]
public SoundSpecifier FireSound = new SoundPathSpecifier("/Audio/Weapons/emitter.ogg");
/// <summary>
/// The entity that is spawned when the emitter fires.
/// </summary>

View File

@@ -6,16 +6,17 @@ using Content.Server.Power.EntitySystems;
using Content.Server.Projectiles;
using Content.Server.Singularity.Components;
using Content.Server.Storage.Components;
using Content.Server.Weapons.Ranged.Systems;
using Content.Shared.Database;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Projectiles;
using Content.Shared.Singularity.Components;
using Content.Shared.Weapons.Ranged.Components;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using Timer = Robust.Shared.Timing.Timer;
@@ -28,10 +29,9 @@ namespace Content.Server.Singularity.EntitySystems
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly ProjectileSystem _projectile = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly GunSystem _gun = default!;
public override void Initialize()
{
@@ -207,33 +207,16 @@ namespace Content.Server.Singularity.EntitySystems
private void Fire(EmitterComponent component)
{
var uid = component.Owner;
var projectile = EntityManager.SpawnEntity(component.BoltType, EntityManager.GetComponent<TransformComponent>(uid).Coordinates);
if (!EntityManager.TryGetComponent<PhysicsComponent?>(projectile, out var physicsComponent))
{
Logger.Error("Emitter tried firing a bolt, but it was spawned without a PhysicsComponent");
if (!TryComp<GunComponent>(uid, out var guncomp))
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))
{
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));
var targetPos = new EntityCoordinates(uid, (0, -1));
_gun.Shoot(guncomp, ent, xform.Coordinates, targetPos);
}
private void UpdateAppearance(EmitterComponent component)

View File

@@ -222,6 +222,7 @@
- state: projectile
shader: unshaded
- type: Ammo
muzzleFlash: null
- type: Physics
- type: Fixtures
fixtures:
@@ -242,6 +243,8 @@
- type: Tag
tags:
- EmitterBolt
- type: TimedDespawn
lifetime: 3
- type: entity
id: BulletKinetic

View File

@@ -34,6 +34,13 @@
shader: unshaded
visible: false
- 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
voltage: Medium
- type: NodeContainer