fish-station/Content.Shared/Medical/SuitSensors/SharedSuitSensorSystem.cs
Vigers Ray 2da8b9f545 Merge remote-tracking branch 'space-wizards/master'
# Conflicts:
#	.github/CODEOWNERS
#	.github/PULL_REQUEST_TEMPLATE.md
#	Content.Client/Changelog/ChangelogTab.xaml.cs
#	Content.Client/Chemistry/UI/ChemMasterWindow.xaml
#	Content.Client/Entry/EntryPoint.cs
#	Content.Client/GameTicking/Managers/ClientGameTicker.cs
#	Content.Client/Launcher/LauncherConnectingGui.xaml
#	Content.Client/Lobby/LobbyState.cs
#	Content.Client/Lobby/UI/LobbyGui.xaml
#	Content.Client/Paper/UI/PaperWindow.xaml.cs
#	Content.Client/StationRecords/GeneralStationRecordConsoleWindow.xaml.cs
#	Content.Client/Stylesheets/StyleNano.cs
#	Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml
#	Content.Client/UserInterface/Systems/Ghost/Widgets/GhostGui.xaml.cs
#	Content.Client/UserInterface/Systems/MenuBar/Widgets/GameTopMenuBar.xaml
#	Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs
#	Content.IntegrationTests/Tests/PostMapInitTest.cs
#	Content.IntegrationTests/Tests/Power/StationPowerTests.cs
#	Content.Packaging/ServerPackaging.cs
#	Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs
#	Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs
#	Content.Server/Atmos/TileAtmosphere.cs
#	Content.Server/Bible/BibleSystem.cs
#	Content.Server/Chat/Systems/ChatSystem.cs
#	Content.Server/Content.Server.csproj
#	Content.Server/Discord/DiscordLink/DiscordLink.cs
#	Content.Server/GameTicking/GameTicker.LobbyBackground.cs
#	Content.Server/GameTicking/GameTicker.Spawning.cs
#	Content.Server/Ghost/GhostSystem.cs
#	Content.Server/Kitchen/Components/MicrowaveComponent.cs
#	Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs
#	Content.Server/Mech/Systems/MechSystem.cs
#	Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs
#	Content.Server/Medical/DefibrillatorSystem.cs
#	Content.Server/Medical/HealthAnalyzerSystem.cs
#	Content.Server/Radio/EntitySystems/HeadsetSystem.cs
#	Content.Server/Remotes/DoorRemoteSystem.cs
#	Content.Server/RoundEnd/RoundEndSystem.cs
#	Content.Server/Shuttles/Systems/DockingSystem.Shuttle.cs
#	Content.Server/Silicons/Borgs/BorgSystem.Transponder.cs
#	Content.Server/Tips/TipsSystem.cs
#	Content.Server/Traitor/Uplink/UplinkSystem.cs
#	Content.Server/Weapons/Ranged/Systems/GunSystem.cs
#	Content.Server/Zombies/ZombieSystem.Transform.cs
#	Content.Server/Zombies/ZombieSystem.cs
#	Content.Shared/Bed/BedSystem.cs
#	Content.Shared/Blocking/BlockingSystem.User.cs
#	Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs
#	Content.Shared/Chat/SharedSuicideSystem.cs
#	Content.Shared/Chemistry/Components/HyposprayComponent.cs
#	Content.Shared/Chemistry/EntitySystems/HypospraySystem.cs
#	Content.Shared/Chemistry/EntitySystems/ScoopableSolutionSystem.cs
#	Content.Shared/Chemistry/EntitySystems/SolutionTransferSystem.cs
#	Content.Shared/Chemistry/Events/HyposprayEvents.cs
#	Content.Shared/Content.Shared.csproj
#	Content.Shared/Damage/Systems/DamageableSystem.cs
#	Content.Shared/Friction/TileFrictionController.cs
#	Content.Shared/GameTicking/SharedGameTicker.cs
#	Content.Shared/Interaction/InteractHand.cs
#	Content.Shared/Lock/LockSystem.cs
#	Content.Shared/Medical/Healing/HealingSystem.cs
#	Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs
#	Content.Shared/Nutrition/EntitySystems/HungerSystem.cs
#	Content.Shared/Silicons/StationAi/SharedStationAiSystem.Airlock.cs
#	Content.Shared/Throwing/ThrowingSystem.cs
#	Content.Shared/Trigger/Systems/TriggerOnHitscanSystem.cs
#	Content.Shared/Weapons/Hitscan/Systems/HitscanBasicDamageSystem.cs
#	Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs
#	Content.Shared/Weapons/Ranged/Components/BatteryWeaponFireModesComponent.cs
#	Content.Shared/Weapons/Ranged/Components/HitscanBatteryAmmoProviderComponent.cs
#	Content.Shared/Weapons/Ranged/Systems/BatteryWeaponFireModesSystem.cs
#	Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs
#	Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Battery.cs
#	Content.Shared/Zombies/ZombieComponent.cs
#	Content.Shared/_Sunrise/Lobby/LobbyBackgroundPrototype.cs
#	README.md
#	Resources/Locale/en-US/_strings/borg/borg.ftl
#	Resources/Locale/en-US/_strings/chemistry/components/hypospray-component.ftl
#	Resources/Locale/en-US/_strings/chemistry/components/injector-component.ftl
#	Resources/Locale/en-US/_strings/commands/pauseatmos-command.ftl
#	Resources/Locale/en-US/_strings/commands/quick-inspect-command.ftl
#	Resources/Locale/en-US/_strings/commands/show-wallmounts-command.ftl
#	Resources/Locale/en-US/_strings/commands/substepatmos-command.ftl
#	Resources/Locale/en-US/_strings/fluids/components/equip-spray-component.ftl
#	Resources/Locale/en-US/_strings/game-ticking/game-presets/preset-revolutionary.ftl
#	Resources/Locale/en-US/_strings/job/job-names.ftl
#	Resources/Locale/en-US/_strings/lobby/lobby-state-background.ftl
#	Resources/Locale/en-US/_strings/reagents/meta/medicine.ftl
#	Resources/Locale/en-US/_strings/reagents/meta/physical-desc.ftl
#	Resources/Locale/en-US/_strings/silicons/borg-module.ftl
#	Resources/Locale/en-US/_strings/store/changeling-catalog.ftl
#	Resources/Locale/en-US/_strings/store/currency.ftl
#	Resources/Locale/en-US/_strings/store/store.ftl
#	Resources/Locale/en-US/_strings/store/uplink-catalog.ftl
#	Resources/Prototypes/Body/Organs/slime.yml
#	Resources/Prototypes/Catalog/Fills/Backpacks/backpack.yml
#	Resources/Prototypes/Catalog/Fills/Backpacks/duffelbag.yml
#	Resources/Prototypes/Catalog/Fills/Boxes/ammunition.yml
#	Resources/Prototypes/Catalog/Fills/Boxes/emergency.yml
#	Resources/Prototypes/Catalog/Fills/Crates/antag.yml
#	Resources/Prototypes/Catalog/Fills/Crates/armory.yml
#	Resources/Prototypes/Catalog/Fills/Crates/botany.yml
#	Resources/Prototypes/Catalog/Fills/Crates/fun.yml
#	Resources/Prototypes/Catalog/Fills/Crates/medical.yml
#	Resources/Prototypes/Catalog/Fills/Crates/salvage.yml
#	Resources/Prototypes/Catalog/Fills/Crates/security.yml
#	Resources/Prototypes/Catalog/Fills/Crates/service.yml
#	Resources/Prototypes/Catalog/Fills/Crates/syndicate.yml
#	Resources/Prototypes/Catalog/Fills/Items/belt.yml
#	Resources/Prototypes/Catalog/Fills/Items/briefcases.yml
#	Resources/Prototypes/Catalog/Fills/Items/firstaidkits.yml
#	Resources/Prototypes/Catalog/Fills/Items/toolboxes.yml
#	Resources/Prototypes/Catalog/Fills/Lockers/dressers.yml
#	Resources/Prototypes/Catalog/Fills/Lockers/heads.yml
#	Resources/Prototypes/Catalog/Fills/Lockers/security.yml
#	Resources/Prototypes/Catalog/VendingMachines/Inventories/theater.yml
#	Resources/Prototypes/Catalog/uplink_catalog.yml
#	Resources/Prototypes/Entities/Clothing/Back/backpacks.yml
#	Resources/Prototypes/Entities/Clothing/Shoes/magboots.yml
#	Resources/Prototypes/Entities/Debugging/debug_sweps.yml
#	Resources/Prototypes/Entities/Debugging/stress_test.yml
#	Resources/Prototypes/Entities/Markers/Spawners/Random/anomaly.yml
#	Resources/Prototypes/Entities/Markers/Spawners/Random/toy.yml
#	Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml
#	Resources/Prototypes/Entities/Mobs/Cyborgs/xenoborgs.yml
#	Resources/Prototypes/Entities/Mobs/NPCs/animals.yml
#	Resources/Prototypes/Entities/Mobs/NPCs/carp.yml
#	Resources/Prototypes/Entities/Objects/Devices/base_handheld.yml
#	Resources/Prototypes/Entities/Objects/Fun/Instruments/instruments_misc.yml
#	Resources/Prototypes/Entities/Objects/Fun/dice_bag.yml
#	Resources/Prototypes/Entities/Objects/Fun/snap_pops.yml
#	Resources/Prototypes/Entities/Objects/Materials/Sheets/other.yml
#	Resources/Prototypes/Entities/Objects/Materials/parts.yml
#	Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml
#	Resources/Prototypes/Entities/Objects/Misc/subdermal_implants.yml
#	Resources/Prototypes/Entities/Objects/Shields/shields.yml
#	Resources/Prototypes/Entities/Objects/Specific/Chapel/bibles.yml
#	Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml
#	Resources/Prototypes/Entities/Objects/Specific/Medical/hypospray.yml
#	Resources/Prototypes/Entities/Objects/Specific/Medical/surgery.yml
#	Resources/Prototypes/Entities/Objects/Specific/Robotics/borg_modules.yml
#	Resources/Prototypes/Entities/Objects/Specific/Robotics/mmi.yml
#	Resources/Prototypes/Entities/Objects/Specific/Service/barber.yml
#	Resources/Prototypes/Entities/Objects/Tools/glowstick.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Boxes/antimateriel.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Boxes/magnum.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/heavy_rifle.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/light_rifle.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/magnum.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/pistol.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/rifle.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/shotgun.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/light_rifle.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/magnum.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/pistol.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/rifle.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Projectiles/grenade.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/magnum.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/pistol.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/rifle_light.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/explosives.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/LMGs/lmgs.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/hitscan.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Melee/knife.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Throwable/grenades.yml
#	Resources/Prototypes/Entities/Structures/Furniture/dresser.yml
#	Resources/Prototypes/Entities/Structures/Machines/lathe.yml
#	Resources/Prototypes/Entities/Structures/Shuttles/cannons.yml
#	Resources/Prototypes/Entities/Structures/Walls/walls.yml
#	Resources/Prototypes/GameRules/roundstart.yml
#	Resources/Prototypes/GameRules/unknown_shuttles.yml
#	Resources/Prototypes/InventoryTemplates/aghost_inventory_template.yml
#	Resources/Prototypes/Loadouts/Jobs/Security/security_officer.yml
#	Resources/Prototypes/Loadouts/loadout_groups.yml
#	Resources/Prototypes/Loadouts/role_loadouts.yml
#	Resources/Prototypes/Maps/Pools/default.yml
#	Resources/Prototypes/Maps/amber.yml
#	Resources/Prototypes/Maps/oasis.yml
#	Resources/Prototypes/Maps/reach.yml
#	Resources/Prototypes/Objectives/objectiveGroups.yml
#	Resources/Prototypes/Reagents/Consumable/Drink/alcohol.yml
#	Resources/Prototypes/Reagents/medicine.yml
#	Resources/Prototypes/Reagents/narcotics.yml
#	Resources/Prototypes/Reagents/toxins.yml
#	Resources/Prototypes/Recipes/Reactions/medicine.yml
#	Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml
#	Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml
#	Resources/Prototypes/Roles/Jobs/Security/security_officer.yml
#	Resources/Prototypes/Roles/Jobs/Security/warden.yml
#	Resources/Prototypes/Roles/Jobs/Wildcards/zookeeper.yml
#	Resources/Prototypes/Roles/play_time_trackers.yml
#	Resources/Prototypes/Shuttles/shuttle_incoming_event.yml
#	Resources/Prototypes/Species/species_weights.yml
#	Resources/Prototypes/Store/presets.yml
#	Resources/Prototypes/ai_factions.yml
#	Resources/Prototypes/borg_types.yml
#	Resources/Prototypes/explosion.yml
#	Resources/Prototypes/game_presets.yml
#	Resources/Prototypes/lobbyscreens.yml
#	Resources/Prototypes/silicon-laws.yml
#	Resources/Textures/Clothing/Back/Duffels/syndicate.rsi/icon-med.png
#	Resources/Textures/Clothing/Back/Duffels/syndicate.rsi/meta.json
#	Resources/Textures/Objects/Specific/Mech/mecha.rsi/meta.json
#	Resources/Textures/Objects/Specific/Mech/mecha.rsi/ripley-broken.png
#	Resources/Textures/Objects/Specific/Mech/mecha.rsi/ripley-empty.png
#	Resources/Textures/Objects/Specific/Mech/mecha.rsi/ripley-open.png
#	Resources/Textures/Objects/Specific/Mech/mecha.rsi/ripley.png
#	Resources/Textures/Objects/Specific/Mech/ripley_construction.rsi/ripley_chassis.png
#	Resources/Textures/Objects/Specific/Mech/ripley_construction.rsi/ripley_harness+o.png
#	Resources/Textures/Objects/Specific/Mech/ripley_construction.rsi/ripley_harness.png
#	Resources/Textures/Objects/Specific/Medical/hypospray.rsi/meta.json
#	Resources/Textures/Objects/Specific/Medical/medical.rsi/meta.json
#	Resources/Textures/Objects/Weapons/Guns/Projectiles/projectiles.rsi/meta.json
#	Resources/Textures/Objects/Weapons/Guns/Projectiles/projectiles2.rsi/meta.json
#	Resources/Textures/Structures/Storage/canister.rsi/meta.json
#	Resources/Textures/Structures/Storage/tanks.rsi/meta.json
#	Resources/migration.yml
#	RobustToolbox
#	SECURITY.md
#	SpaceStation14.sln
2025-12-26 04:19:27 +01:00

501 lines
20 KiB
C#

using System.Numerics;
using Content.Shared.Access.Systems;
using Content.Shared.ActionBlocker;
using Content.Shared.Clothing;
using Content.Shared.Damage.Components;
using Content.Shared.DeviceNetwork;
using Content.Shared.DoAfter;
using Content.Shared.Emp;
using Content.Shared.Examine;
using Content.Shared.GameTicking;
using Content.Shared.Interaction;
using Content.Shared.Inventory;
using Content.Shared.Medical.SuitSensor;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
using Content.Shared.Station;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Shared.Medical.SuitSensors;
public abstract class SharedSuitSensorSystem : EntitySystem
{
[Dependency] private readonly SharedStationSystem _stationSystem = default!;
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly SharedIdCardSystem _idCardSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IGameTiming _timing = default!;
private EntityQuery<SuitSensorComponent> _sensorQuery;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SuitSensorComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<PlayerSpawnCompleteEvent>(OnPlayerSpawn);
SubscribeLocalEvent<SuitSensorComponent, ClothingGotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<SuitSensorComponent, ClothingGotUnequippedEvent>(OnUnequipped);
SubscribeLocalEvent<SuitSensorComponent, EmpPulseEvent>(OnEmpPulse);
SubscribeLocalEvent<SuitSensorComponent, EmpDisabledRemovedEvent>(OnEmpFinished);
SubscribeLocalEvent<SuitSensorComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<SuitSensorComponent, GetVerbsEvent<Verb>>(OnVerb);
SubscribeLocalEvent<SuitSensorComponent, EntGotInsertedIntoContainerMessage>(OnInsert);
SubscribeLocalEvent<SuitSensorComponent, EntGotRemovedFromContainerMessage>(OnRemove);
SubscribeLocalEvent<SuitSensorComponent, SuitSensorChangeDoAfterEvent>(OnSuitSensorDoAfter);
_sensorQuery = GetEntityQuery<SuitSensorComponent>();
}
/// <summary>
/// Checks whether the sensor is assigned to a station or not
/// and tries to assign an unassigned sensor to a station if it's currently on a grid.
/// </summary>
/// <returns>True if the sensor is assigned to a station or assigning it was successful. False otherwise.</returns>
public bool CheckSensorAssignedStation(Entity<SuitSensorComponent> sensor)
{
if (!sensor.Comp.StationId.HasValue && Transform(sensor.Owner).GridUid == null)
return false;
sensor.Comp.StationId = _stationSystem.GetOwningStation(sensor.Owner);
Dirty(sensor);
return sensor.Comp.StationId.HasValue;
}
private void OnMapInit(Entity<SuitSensorComponent> ent, ref MapInitEvent args)
{
// Fallback
ent.Comp.StationId ??= _stationSystem.GetOwningStation(ent.Owner);
// generate random mode
if (ent.Comp.RandomMode)
{
//make the sensor mode favor higher levels, except coords.
var modesDist = new[]
{
SuitSensorMode.SensorOff,
SuitSensorMode.SensorBinary, SuitSensorMode.SensorBinary,
SuitSensorMode.SensorVitals, SuitSensorMode.SensorVitals, SuitSensorMode.SensorVitals,
SuitSensorMode.SensorCords, SuitSensorMode.SensorCords
};
ent.Comp.Mode = _random.Pick(modesDist);
}
ent.Comp.NextUpdate = _timing.CurTime;
Dirty(ent);
}
private void OnPlayerSpawn(PlayerSpawnCompleteEvent ev)
{
// If the player spawns in arrivals then the grid underneath them may not be appropriate.
// in which case we'll just use the station spawn code told us they are attached to and set all of their
// sensors.
RecursiveSensor(ev.Mob, ev.Station);
}
private void RecursiveSensor(EntityUid uid, EntityUid stationUid)
{
var xform = Transform(uid);
var enumerator = xform.ChildEnumerator;
while (enumerator.MoveNext(out var child))
{
if (_sensorQuery.TryComp(child, out var sensor))
{
sensor.StationId = stationUid;
Dirty(child, sensor);
}
RecursiveSensor(child, stationUid);
}
}
private void OnEquipped(Entity<SuitSensorComponent> ent, ref ClothingGotEquippedEvent args)
{
ent.Comp.User = args.Wearer;
Dirty(ent);
}
private void OnUnequipped(Entity<SuitSensorComponent> ent, ref ClothingGotUnequippedEvent args)
{
ent.Comp.User = null;
Dirty(ent);
}
private void OnEmpPulse(Entity<SuitSensorComponent> ent, ref EmpPulseEvent args)
{
args.Affected = true;
args.Disabled = true;
ent.Comp.PreviousMode = ent.Comp.Mode;
SetSensor(ent.AsNullable(), SuitSensorMode.SensorOff, null);
ent.Comp.PreviousControlsLocked = ent.Comp.ControlsLocked;
ent.Comp.ControlsLocked = true;
// SetSensor already calls Dirty
}
private void OnEmpFinished(Entity<SuitSensorComponent> ent, ref EmpDisabledRemovedEvent args)
{
SetSensor(ent.AsNullable(), ent.Comp.PreviousMode, null);
ent.Comp.ControlsLocked = ent.Comp.PreviousControlsLocked;
}
private void OnExamine(Entity<SuitSensorComponent> ent, ref ExaminedEvent args)
{
if (!args.IsInDetailsRange)
return;
string msg;
switch (ent.Comp.Mode)
{
case SuitSensorMode.SensorOff:
msg = "suit-sensor-examine-off";
break;
case SuitSensorMode.SensorBinary:
msg = "suit-sensor-examine-binary";
break;
case SuitSensorMode.SensorVitals:
msg = "suit-sensor-examine-vitals";
break;
case SuitSensorMode.SensorCords:
msg = "suit-sensor-examine-cords";
break;
default:
return;
}
args.PushMarkup(Loc.GetString(msg));
}
private void OnVerb(Entity<SuitSensorComponent> ent, ref GetVerbsEvent<Verb> args)
{
// check if user can change sensor
if (ent.Comp.ControlsLocked)
return;
// standard interaction checks
if (!args.CanInteract || args.Hands == null)
return;
if (!_interactionSystem.InRangeUnobstructed(args.User, args.Target))
return;
// check if target is incapacitated (cuffed, dead, etc)
if (ent.Comp.User != null && args.User != ent.Comp.User && _actionBlocker.CanInteract(ent.Comp.User.Value, null))
return;
args.Verbs.UnionWith(new[]
{
CreateVerb(ent, args.User, SuitSensorMode.SensorOff),
CreateVerb(ent, args.User, SuitSensorMode.SensorBinary),
CreateVerb(ent, args.User, SuitSensorMode.SensorVitals),
CreateVerb(ent, args.User, SuitSensorMode.SensorCords)
});
}
private void OnInsert(Entity<SuitSensorComponent> ent, ref EntGotInsertedIntoContainerMessage args)
{
if (args.Container.ID != ent.Comp.ActivationContainer)
return;
ent.Comp.User = args.Container.Owner;
Dirty(ent);
}
private void OnRemove(Entity<SuitSensorComponent> ent, ref EntGotRemovedFromContainerMessage args)
{
if (args.Container.ID != ent.Comp.ActivationContainer)
return;
ent.Comp.User = null;
Dirty(ent);
}
private Verb CreateVerb(Entity<SuitSensorComponent> ent, EntityUid userUid, SuitSensorMode mode)
{
return new Verb()
{
Text = GetModeName(mode),
Disabled = ent.Comp.Mode == mode,
Priority = -(int)mode, // sort them in descending order
Category = VerbCategory.SetSensor,
Act = () => TrySetSensor(ent.AsNullable(), mode, userUid)
};
}
public string GetModeName(SuitSensorMode mode)
{
string name;
switch (mode)
{
case SuitSensorMode.SensorOff:
name = "suit-sensor-mode-off";
break;
case SuitSensorMode.SensorBinary:
name = "suit-sensor-mode-binary";
break;
case SuitSensorMode.SensorVitals:
name = "suit-sensor-mode-vitals";
break;
case SuitSensorMode.SensorCords:
name = "suit-sensor-mode-cords";
break;
default:
return "";
}
return Loc.GetString(name);
}
/// <summary>
/// Attempts to set <see cref="SuitSensorComponent"/> mode of the entity to the selected in params.
/// Works instantly if the user is the player wearing the sensors and will start a DoAfter otherwise.
/// </summary>
/// <param name="sensors">Entity and its component that should be changed.</param>
/// <param name="mode">Selected mode</param>
/// <param name="userUid">userUid, when not equal to the <see cref="SuitSensorComponent.User"/>, creates doafter</param>
public bool TrySetSensor(Entity<SuitSensorComponent?> sensors, SuitSensorMode mode, EntityUid userUid)
{
if (!Resolve(sensors, ref sensors.Comp, false))
return false;
if (sensors.Comp.User == null || userUid == sensors.Comp.User)
SetSensor(sensors, mode, userUid);
else
{
var doAfterEvent = new SuitSensorChangeDoAfterEvent(mode);
var doAfterArgs = new DoAfterArgs(EntityManager, userUid, sensors.Comp.SensorsTime, doAfterEvent, sensors)
{
BreakOnMove = true,
BreakOnDamage = true
};
_doAfterSystem.TryStartDoAfter(doAfterArgs);
}
return true;
}
private void OnSuitSensorDoAfter(Entity<SuitSensorComponent> sensors, ref SuitSensorChangeDoAfterEvent args)
{
if (args.Handled || args.Cancelled)
return;
SetSensor(sensors.AsNullable(), args.Mode, args.User);
}
/// <summary>
/// Sets mode of the <see cref="SuitSensorComponent"/> of the chosen entity.
/// Makes popup when <param name="userUid"> not null
/// </summary>
/// <param name="sensors">Entity and it's component that should be changed</param>
/// <param name="mode">Selected mode</param>
/// <param name="userUid">uid, required for the popup</param>
public void SetSensor(Entity<SuitSensorComponent?> sensors, SuitSensorMode mode, EntityUid? userUid = null)
{
if (!Resolve(sensors, ref sensors.Comp, false))
return;
sensors.Comp.Mode = mode;
Dirty(sensors);
if (userUid != null)
{
var msg = Loc.GetString("suit-sensor-mode-state", ("mode", GetModeName(mode)));
_popupSystem.PopupClient(msg, sensors, userUid.Value);
}
}
/// <summary>
/// Set all suit sensors on the equipment someone is wearing to the specified mode.
/// </summary>
public void SetAllSensors(EntityUid target, SuitSensorMode mode, SlotFlags slots = SlotFlags.All)
{
// iterate over all inventory slots
var slotEnumerator = _inventory.GetSlotEnumerator(target, slots);
while (slotEnumerator.NextItem(out var item, out _))
{
if (TryComp<SuitSensorComponent>(item, out var sensorComp))
SetSensor((item, sensorComp), mode);
}
}
/// <summary>
/// Attempts to get full <see cref="SuitSensorStatus"/> from the <see cref="SuitSensorComponent"/>
/// </summary>
/// <param name="uid">Entity to get status</param>
/// <returns>Full <see cref="SuitSensorStatus"/> of the chosen uid</returns>
public SuitSensorStatus? GetSensorState(Entity<SuitSensorComponent?, TransformComponent?> ent)
{
if (!Resolve(ent, ref ent.Comp1, ref ent.Comp2, false))
return null;
var sensor = ent.Comp1;
var transform = ent.Comp2;
// check if sensor is enabled and worn by user
if (sensor.Mode == SuitSensorMode.SensorOff || sensor.User == null || !HasComp<MobStateComponent>(sensor.User) || transform.GridUid == null)
return null;
// Sunrise-Start
var sensorTransform = Transform(ent);
var sensorMapId = sensorTransform.MapID;
// Sunrise-End
// try to get mobs id from ID slot
var userName = Loc.GetString("suit-sensor-component-unknown-name");
var userJob = Loc.GetString("suit-sensor-component-unknown-job");
var userJobIcon = "JobIconNoId";
var userJobDepartments = new List<string>();
if (_idCardSystem.TryFindIdCard(sensor.User.Value, out var card))
{
if (card.Comp.FullName != null)
userName = card.Comp.FullName;
if (card.Comp.LocalizedJobTitle != null)
userJob = card.Comp.LocalizedJobTitle;
userJobIcon = card.Comp.JobIcon;
foreach (var department in card.Comp.JobDepartments)
userJobDepartments.Add(Loc.GetString(_proto.Index(department).Name));
}
// get health mob state
var isAlive = false;
if (TryComp(sensor.User.Value, out MobStateComponent? mobState))
isAlive = !_mobStateSystem.IsDead(sensor.User.Value, mobState);
// get mob total damage
var totalDamage = 0;
if (TryComp<DamageableComponent>(sensor.User.Value, out var damageable))
totalDamage = damageable.TotalDamage.Int();
// Get mob total damage crit threshold
int? totalDamageThreshold = null;
if (_mobThresholdSystem.TryGetThresholdForState(sensor.User.Value, MobState.Critical, out var critThreshold))
totalDamageThreshold = critThreshold.Value.Int();
// finally, form suit sensor status
var status = new SuitSensorStatus(GetNetEntity(sensor.User.Value), GetNetEntity(ent.Owner), userName, userJob, userJobIcon, userJobDepartments, sensorMapId); // Sunrise-Edit
switch (sensor.Mode)
{
case SuitSensorMode.SensorBinary:
status.IsAlive = isAlive;
break;
case SuitSensorMode.SensorVitals:
status.IsAlive = isAlive;
status.TotalDamage = totalDamage;
status.TotalDamageThreshold = totalDamageThreshold;
break;
case SuitSensorMode.SensorCords:
status.IsAlive = isAlive;
status.TotalDamage = totalDamage;
status.TotalDamageThreshold = totalDamageThreshold;
EntityCoordinates coordinates;
var xformQuery = GetEntityQuery<TransformComponent>();
if (transform.GridUid != null)
{
coordinates = new EntityCoordinates(transform.GridUid.Value,
Vector2.Transform(_transform.GetWorldPosition(transform, xformQuery),
_transform.GetInvWorldMatrix(xformQuery.GetComponent(transform.GridUid.Value), xformQuery)));
}
else if (transform.MapUid != null)
{
coordinates = new EntityCoordinates(transform.MapUid.Value,
_transform.GetWorldPosition(transform, xformQuery));
}
else
{
coordinates = EntityCoordinates.Invalid;
}
status.Coordinates = GetNetCoordinates(coordinates);
break;
}
return status;
}
/// <summary>
/// Create a device network package from the suit sensors status.
/// </summary>
public NetworkPayload SuitSensorToPacket(SuitSensorStatus status)
{
var payload = new NetworkPayload()
{
[DeviceNetworkConstants.Command] = DeviceNetworkConstants.CmdUpdatedState,
[SuitSensorConstants.NET_NAME] = status.Name,
[SuitSensorConstants.NET_JOB] = status.Job,
[SuitSensorConstants.NET_JOB_ICON] = status.JobIcon,
[SuitSensorConstants.NET_JOB_DEPARTMENTS] = status.JobDepartments,
[SuitSensorConstants.NET_IS_ALIVE] = status.IsAlive,
[SuitSensorConstants.NET_SUIT_SENSOR_UID] = status.SuitSensorUid,
[SuitSensorConstants.NET_OWNER_UID] = status.OwnerUid,
};
if (status.TotalDamage != null)
payload.Add(SuitSensorConstants.NET_TOTAL_DAMAGE, status.TotalDamage);
if (status.TotalDamageThreshold != null)
payload.Add(SuitSensorConstants.NET_TOTAL_DAMAGE_THRESHOLD, status.TotalDamageThreshold);
if (status.Coordinates != null)
payload.Add(SuitSensorConstants.NET_COORDINATES, status.Coordinates);
// Sunrise-Start
if (status.MapId != null)
payload.Add(SuitSensorConstants.MAP_ID, status.MapId);
// Sunrise-End
return payload;
}
/// <summary>
/// Try to create the suit sensors status from the device network message.
/// </summary>
public SuitSensorStatus? PacketToSuitSensor(NetworkPayload payload)
{
// check command
if (!payload.TryGetValue(DeviceNetworkConstants.Command, out string? command))
return null;
if (command != DeviceNetworkConstants.CmdUpdatedState)
return null;
// check name, job and alive
if (!payload.TryGetValue(SuitSensorConstants.NET_NAME, out string? name)) return null;
if (!payload.TryGetValue(SuitSensorConstants.NET_JOB, out string? job)) return null;
if (!payload.TryGetValue(SuitSensorConstants.NET_JOB_ICON, out string? jobIcon)) return null;
if (!payload.TryGetValue(SuitSensorConstants.NET_JOB_DEPARTMENTS, out List<string>? jobDepartments)) return null;
if (!payload.TryGetValue(SuitSensorConstants.NET_IS_ALIVE, out bool? isAlive)) return null;
if (!payload.TryGetValue(SuitSensorConstants.NET_SUIT_SENSOR_UID, out NetEntity suitSensorUid)) return null;
if (!payload.TryGetValue(SuitSensorConstants.NET_OWNER_UID, out NetEntity ownerUid)) return null;
// try get total damage and cords (optionals)
payload.TryGetValue(SuitSensorConstants.NET_TOTAL_DAMAGE, out int? totalDamage);
payload.TryGetValue(SuitSensorConstants.NET_TOTAL_DAMAGE_THRESHOLD, out int? totalDamageThreshold);
payload.TryGetValue(SuitSensorConstants.NET_COORDINATES, out NetCoordinates? coords);
payload.TryGetValue(SuitSensorConstants.MAP_ID, out MapId? mapId); // Sunrise-Edit
var status = new SuitSensorStatus(ownerUid, suitSensorUid, name, job, jobIcon, jobDepartments, mapId) // Sunrise-Edit
{
IsAlive = isAlive.Value,
TotalDamage = totalDamage,
TotalDamageThreshold = totalDamageThreshold,
Coordinates = coords,
MapId = mapId, // Sunrise-Edit
};
return status;
}
}