Anomaly Locator (#15677)
This commit is contained in:
54
Content.Server/Pinpointer/ProximityBeeperComponent.cs
Normal file
54
Content.Server/Pinpointer/ProximityBeeperComponent.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
using Robust.Shared.Audio;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||||
|
|
||||||
|
namespace Content.Server.Pinpointer;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This is used for an item that beeps based on
|
||||||
|
/// proximity to a specified component.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent, Access(typeof(ProximityBeeperSystem))]
|
||||||
|
public sealed class ProximityBeeperComponent : Component
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not it's on.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("enabled")]
|
||||||
|
public bool Enabled;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The target component that is being searched for
|
||||||
|
/// </summary>
|
||||||
|
[DataField("component", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public string Component = default!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The farthest distance a target can be for the beep to occur
|
||||||
|
/// </summary>
|
||||||
|
[DataField("maximumDistance"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public float MaximumDistance = 10f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The maximum interval between beeps.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("maxBeepInterval"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public TimeSpan MaxBeepInterval = TimeSpan.FromSeconds(1.5f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The minimum interval between beeps.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("minBeepInterval"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public TimeSpan MinBeepInterval = TimeSpan.FromSeconds(0.25f);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When the next beep will occur
|
||||||
|
/// </summary>
|
||||||
|
[DataField("nextBeepTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public TimeSpan NextBeepTime;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The sound played when the locator beeps.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("beepSound")]
|
||||||
|
public SoundSpecifier? BeepSound;
|
||||||
|
}
|
||||||
167
Content.Server/Pinpointer/ProximityBeeperSystem.cs
Normal file
167
Content.Server/Pinpointer/ProximityBeeperSystem.cs
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
using Content.Server.PowerCell;
|
||||||
|
using Content.Shared.Interaction.Events;
|
||||||
|
using Content.Shared.Pinpointer;
|
||||||
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
|
namespace Content.Server.Pinpointer;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This handles logic and interaction relating to <see cref="ProximityBeeperComponent"/>
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ProximityBeeperSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
|
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
||||||
|
[Dependency] private readonly AudioSystem _audio = default!;
|
||||||
|
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
|
||||||
|
[Dependency] private readonly PowerCellSystem _powerCell = default!;
|
||||||
|
[Dependency] private readonly TransformSystem _transform = default!;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
SubscribeLocalEvent<ProximityBeeperComponent, UseInHandEvent>(OnUseInHand);
|
||||||
|
SubscribeLocalEvent<ProximityBeeperComponent, ComponentInit>(OnInit);
|
||||||
|
SubscribeLocalEvent<ProximityBeeperComponent, EntityUnpausedEvent>(OnUnpaused);
|
||||||
|
SubscribeLocalEvent<ProximityBeeperComponent, PowerCellSlotEmptyEvent>(OnPowerCellSlotEmpty);
|
||||||
|
}
|
||||||
|
private void OnUseInHand(EntityUid uid, ProximityBeeperComponent component, UseInHandEvent args)
|
||||||
|
{
|
||||||
|
if (args.Handled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
args.Handled = TryToggle(uid, component, args.User);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnInit(EntityUid uid, ProximityBeeperComponent component, ComponentInit args)
|
||||||
|
{
|
||||||
|
if (component.NextBeepTime < _timing.CurTime)
|
||||||
|
component.NextBeepTime = _timing.CurTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUnpaused(EntityUid uid, ProximityBeeperComponent component, ref EntityUnpausedEvent args)
|
||||||
|
{
|
||||||
|
component.NextBeepTime += args.PausedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPowerCellSlotEmpty(EntityUid uid, ProximityBeeperComponent component, ref PowerCellSlotEmptyEvent args)
|
||||||
|
{
|
||||||
|
if (component.Enabled)
|
||||||
|
TryDisable(uid, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Beeps the proximitybeeper as well as sets the time for the next beep
|
||||||
|
/// based on proximity to entities with the target component.
|
||||||
|
/// </summary>
|
||||||
|
public void UpdateBeep(EntityUid uid, ProximityBeeperComponent? component = null, bool playBeep = true)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!component.Enabled)
|
||||||
|
{
|
||||||
|
component.NextBeepTime += component.MinBeepInterval;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||||
|
var xform = xformQuery.GetComponent(uid);
|
||||||
|
var comp = EntityManager.ComponentFactory.GetRegistration(component.Component).Type;
|
||||||
|
float? closestDistance = null;
|
||||||
|
foreach (var targetXform in _entityLookup.GetComponentsInRange<TransformComponent>(xform.MapPosition, component.MaximumDistance))
|
||||||
|
{
|
||||||
|
// forgive me father, for i have sinned.
|
||||||
|
var ent = targetXform.Owner;
|
||||||
|
|
||||||
|
if (!HasComp(ent, comp))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var dist = (_transform.GetWorldPosition(xform, xformQuery) - _transform.GetWorldPosition(targetXform, xformQuery)).Length;
|
||||||
|
if (dist >= (closestDistance ?? float.MaxValue))
|
||||||
|
continue;
|
||||||
|
closestDistance = dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (closestDistance is not { } distance)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (playBeep)
|
||||||
|
_audio.PlayPvs(component.BeepSound, uid);
|
||||||
|
|
||||||
|
var scalingFactor = distance / component.MaximumDistance;
|
||||||
|
var interval = (component.MaxBeepInterval - component.MinBeepInterval) * scalingFactor + component.MinBeepInterval;
|
||||||
|
component.NextBeepTime += interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enables the proximity beeper
|
||||||
|
/// </summary>
|
||||||
|
public bool TryEnable(EntityUid uid, ProximityBeeperComponent? component = null, EntityUid? user = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
TryComp<PowerCellDrawComponent>(uid, out var draw);
|
||||||
|
|
||||||
|
if (!_powerCell.HasActivatableCharge(uid, battery: draw, user: user))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
component.Enabled = true;
|
||||||
|
_appearance.SetData(uid, ProximityBeeperVisuals.Enabled, true);
|
||||||
|
component.NextBeepTime = _timing.CurTime;
|
||||||
|
UpdateBeep(uid, component, false);
|
||||||
|
if (draw != null)
|
||||||
|
draw.Enabled = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disables the proximity beeper
|
||||||
|
/// </summary>
|
||||||
|
public bool TryDisable(EntityUid uid, ProximityBeeperComponent? component = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!component.Enabled)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
component.Enabled = false;
|
||||||
|
_appearance.SetData(uid, ProximityBeeperVisuals.Enabled, false);
|
||||||
|
if (TryComp<PowerCellDrawComponent>(uid, out var draw))
|
||||||
|
draw.Enabled = true;
|
||||||
|
UpdateBeep(uid, component);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// toggles the proximity beeper
|
||||||
|
/// </summary>
|
||||||
|
public bool TryToggle(EntityUid uid, ProximityBeeperComponent? component = null, EntityUid? user = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return component.Enabled
|
||||||
|
? TryDisable(uid, component)
|
||||||
|
: TryEnable(uid, component, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(float frameTime)
|
||||||
|
{
|
||||||
|
base.Update(frameTime);
|
||||||
|
|
||||||
|
var query = EntityQueryEnumerator<ProximityBeeperComponent>();
|
||||||
|
while (query.MoveNext(out var uid, out var beeper))
|
||||||
|
{
|
||||||
|
if (!beeper.Enabled)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (_timing.CurTime < beeper.NextBeepTime)
|
||||||
|
continue;
|
||||||
|
UpdateBeep(uid, beeper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Content.Shared/Pinpointer/SharedProximityBeeper.cs
Normal file
9
Content.Shared/Pinpointer/SharedProximityBeeper.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
|
namespace Content.Shared.Pinpointer;
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public enum ProximityBeeperVisuals : byte
|
||||||
|
{
|
||||||
|
Enabled
|
||||||
|
}
|
||||||
@@ -3,6 +3,11 @@
|
|||||||
copyright: "Created by Pól, converted to OGG and Mono by EmoGarbage"
|
copyright: "Created by Pól, converted to OGG and Mono by EmoGarbage"
|
||||||
source: "https://freesound.org/people/P%C3%B3l/sounds/385927/"
|
source: "https://freesound.org/people/P%C3%B3l/sounds/385927/"
|
||||||
|
|
||||||
|
- files: ["locator_beep.ogg"]
|
||||||
|
license: "CC0-1.0"
|
||||||
|
copyright: "Created by MATRIXXX_, converted to OGG, shortened, sped up, and pitched up by EmoGarbage404 (github)"
|
||||||
|
source: "https://freesound.org/people/MATRIXXX_/sounds/657947/"
|
||||||
|
|
||||||
- files: ["trayhit1.ogg"]
|
- files: ["trayhit1.ogg"]
|
||||||
license: "CC-BY-SA-3.0"
|
license: "CC-BY-SA-3.0"
|
||||||
copyright: "Time immemorial"
|
copyright: "Time immemorial"
|
||||||
|
|||||||
BIN
Resources/Audio/Items/locator_beep.ogg
Normal file
BIN
Resources/Audio/Items/locator_beep.ogg
Normal file
Binary file not shown.
@@ -521,6 +521,7 @@
|
|||||||
- ScanningModuleStockPart
|
- ScanningModuleStockPart
|
||||||
- NodeScanner
|
- NodeScanner
|
||||||
- AnomalyScanner
|
- AnomalyScanner
|
||||||
|
- AnomalyLocator
|
||||||
|
|
||||||
- type: technology
|
- type: technology
|
||||||
name: technologies-anomaly-technology
|
name: technologies-anomaly-technology
|
||||||
|
|||||||
@@ -20,3 +20,46 @@
|
|||||||
- type: GuideHelp
|
- type: GuideHelp
|
||||||
guides:
|
guides:
|
||||||
- ScannersAndVessels
|
- ScannersAndVessels
|
||||||
|
|
||||||
|
- type: entity
|
||||||
|
id: AnomalyLocator
|
||||||
|
parent: [ BaseItem, PowerCellSlotSmallItem ]
|
||||||
|
name: anomaly locator
|
||||||
|
description: A device designed to aid in the locating of anomalies. Did you check the gas miners?
|
||||||
|
components:
|
||||||
|
- type: Sprite
|
||||||
|
sprite: Objects/Specific/Research/anomalylocator.rsi
|
||||||
|
netsync: false
|
||||||
|
layers:
|
||||||
|
- state: icon
|
||||||
|
- state: screen
|
||||||
|
shader: unshaded
|
||||||
|
visible: false
|
||||||
|
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
||||||
|
- type: Appearance
|
||||||
|
- type: GenericVisualizer
|
||||||
|
visuals:
|
||||||
|
enum.ProximityBeeperVisuals.Enabled:
|
||||||
|
enum.PowerDeviceVisualLayers.Powered:
|
||||||
|
True: { visible: true }
|
||||||
|
False: { visible: false }
|
||||||
|
- type: PowerCellDraw
|
||||||
|
drawRate: 10
|
||||||
|
useRate: 0
|
||||||
|
- type: ProximityBeeper
|
||||||
|
component: Anomaly
|
||||||
|
beepSound:
|
||||||
|
path: "/Audio/Items/locator_beep.ogg"
|
||||||
|
params:
|
||||||
|
maxdistance: 1
|
||||||
|
volume: -8
|
||||||
|
|
||||||
|
- type: entity
|
||||||
|
id: AnomalyLocatorNoBattery
|
||||||
|
parent: AnomalyLocator
|
||||||
|
suffix: No Battery
|
||||||
|
components:
|
||||||
|
- type: ItemSlots
|
||||||
|
slots:
|
||||||
|
cell_slot:
|
||||||
|
name: power-cell-slot-component-slot-name-default
|
||||||
@@ -170,6 +170,7 @@
|
|||||||
- ConveyorBeltAssembly
|
- ConveyorBeltAssembly
|
||||||
- AppraisalTool
|
- AppraisalTool
|
||||||
- AnomalyScanner
|
- AnomalyScanner
|
||||||
|
- AnomalyLocator
|
||||||
- RCD
|
- RCD
|
||||||
- RCDAmmo
|
- RCDAmmo
|
||||||
- HydroponicsToolScythe
|
- HydroponicsToolScythe
|
||||||
|
|||||||
@@ -49,6 +49,14 @@
|
|||||||
Plastic: 200
|
Plastic: 200
|
||||||
Glass: 100
|
Glass: 100
|
||||||
|
|
||||||
|
- type: latheRecipe
|
||||||
|
id: AnomalyLocator
|
||||||
|
result: AnomalyLocatorNoBattery
|
||||||
|
completetime: 3
|
||||||
|
materials:
|
||||||
|
Steel: 400
|
||||||
|
Glass: 100
|
||||||
|
|
||||||
- type: latheRecipe
|
- type: latheRecipe
|
||||||
id: AnomalyScanner
|
id: AnomalyScanner
|
||||||
result: AnomalyScanner
|
result: AnomalyScanner
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 442 B |
Binary file not shown.
|
After Width: | Height: | Size: 307 B |
Binary file not shown.
|
After Width: | Height: | Size: 295 B |
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"license": "CC0-1.0",
|
||||||
|
"copyright": "Created by EmoGarbage404 (github) for Space Station 14.",
|
||||||
|
"size": {
|
||||||
|
"x": 32,
|
||||||
|
"y": 32
|
||||||
|
},
|
||||||
|
"states": [
|
||||||
|
{
|
||||||
|
"name": "icon"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "inhand-left",
|
||||||
|
"directions": 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "inhand-right",
|
||||||
|
"directions": 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "screen",
|
||||||
|
"delays": [
|
||||||
|
[
|
||||||
|
0.2,
|
||||||
|
0.2,
|
||||||
|
0.2,
|
||||||
|
0.2
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 223 B |
Reference in New Issue
Block a user