# 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
568 lines
20 KiB
C#
568 lines
20 KiB
C#
using System.Linq;
|
|
using Content.Shared.Access.Components;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.Actions;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Destructible;
|
|
using Content.Shared.DoAfter;
|
|
using Content.Shared.Mobs;
|
|
using Content.Shared.DragDrop;
|
|
using Content.Shared.Emag.Components;
|
|
using Content.Shared.Emag.Systems;
|
|
using Content.Shared.FixedPoint;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Interaction.Components;
|
|
using Content.Shared.Interaction.Events;
|
|
using Content.Shared.Mech.Components;
|
|
using Content.Shared.Mech.Equipment.Components;
|
|
using Content.Shared.Movement.Components;
|
|
using Content.Shared.Movement.Systems;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Storage.Components;
|
|
using Content.Shared.Weapons.Melee;
|
|
using Content.Shared.Weapons.Ranged.Events;
|
|
using Content.Shared.Whitelist;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.Timing;
|
|
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
|
|
using Content.Shared._Sunrise.Paint;
|
|
using Content.Shared.Humanoid;
|
|
using Content.Shared.SubFloor;
|
|
using Content.Shared.Nutrition.EntitySystems;
|
|
|
|
namespace Content.Shared.Mech.EntitySystems;
|
|
|
|
/// <summary>
|
|
/// Handles all of the interactions, UI handling, and items shennanigans for <see cref="MechComponent"/>
|
|
/// </summary>
|
|
public abstract partial class SharedMechSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly INetManager _net = default!;
|
|
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
|
|
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
|
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
|
|
[Dependency] private readonly SharedMoverController _mover = default!;
|
|
[Dependency] private readonly SharedPointLightSystem _pointLight = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
|
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
|
|
[Dependency] private readonly OpenableSystem _openable = default!;
|
|
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<MechComponent, MechToggleEquipmentEvent>(OnToggleEquipmentAction);
|
|
SubscribeLocalEvent<MechComponent, MechEjectPilotEvent>(OnEjectPilotEvent);
|
|
SubscribeLocalEvent<MechComponent, MechToggleLightsEvent>(OnToggleLightsEvent);
|
|
SubscribeLocalEvent<MechComponent, UserActivateInWorldEvent>(RelayInteractionEvent);
|
|
SubscribeLocalEvent<MechComponent, ComponentStartup>(OnStartup);
|
|
SubscribeLocalEvent<MechComponent, MobStateChangedEvent>(OnMobState);
|
|
SubscribeLocalEvent<MechComponent, EntityStorageIntoContainerAttemptEvent>(OnEntityStorageDump);
|
|
SubscribeLocalEvent<MechComponent, GetAdditionalAccessEvent>(OnGetAdditionalAccess);
|
|
SubscribeLocalEvent<MechComponent, DragDropTargetEvent>(OnDragDrop);
|
|
SubscribeLocalEvent<MechComponent, CanDropTargetEvent>(OnCanDragDrop);
|
|
SubscribeLocalEvent<MechComponent, GotEmaggedEvent>(OnEmagged);
|
|
SubscribeLocalEvent<MechPilotComponent, GetMeleeWeaponEvent>(OnGetMeleeWeapon);
|
|
SubscribeLocalEvent<MechPilotComponent, CanAttackFromContainerEvent>(OnCanAttackFromContainer);
|
|
SubscribeLocalEvent<MechPilotComponent, AttackAttemptEvent>(OnAttackAttempt);
|
|
|
|
InitializeRelay();
|
|
}
|
|
|
|
private void OnToggleEquipmentAction(EntityUid uid, MechComponent component, MechToggleEquipmentEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
args.Handled = true;
|
|
CycleEquipment(uid);
|
|
}
|
|
|
|
private void OnEjectPilotEvent(EntityUid uid, MechComponent component, MechEjectPilotEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
args.Handled = true;
|
|
TryEject(uid, component);
|
|
}
|
|
|
|
private void OnToggleLightsEvent(EntityUid uid, MechComponent component, MechToggleLightsEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
ToggleLights(uid, component);
|
|
|
|
args.Handled = true;
|
|
}
|
|
|
|
private void RelayInteractionEvent(EntityUid uid, MechComponent component, UserActivateInWorldEvent args)
|
|
{
|
|
var pilot = component.PilotSlot.ContainedEntity;
|
|
if (pilot == null)
|
|
return;
|
|
|
|
// TODO why is this being blocked?
|
|
if (!_timing.IsFirstTimePredicted)
|
|
return;
|
|
|
|
if (component.CurrentSelectedEquipment != null)
|
|
{
|
|
RaiseLocalEvent(component.CurrentSelectedEquipment.Value, args);
|
|
}
|
|
}
|
|
|
|
private void OnStartup(EntityUid uid, MechComponent component, ComponentStartup args)
|
|
{
|
|
component.PilotSlot = _container.EnsureContainer<ContainerSlot>(uid, component.PilotSlotId);
|
|
component.EquipmentContainer = _container.EnsureContainer<Container>(uid, component.EquipmentContainerId);
|
|
component.BatterySlot = _container.EnsureContainer<ContainerSlot>(uid, component.BatterySlotId);
|
|
UpdateAppearance(uid, component);
|
|
}
|
|
|
|
private void OnMobState(EntityUid uid, MechComponent component, MobStateChangedEvent args)
|
|
{
|
|
if (args.NewMobState == MobState.Critical)
|
|
{
|
|
BreakMech(uid, component);
|
|
}
|
|
if (args.NewMobState == MobState.Alive)
|
|
{
|
|
component.Broken = false;
|
|
UpdateAppearance(uid, component);
|
|
}
|
|
}
|
|
|
|
private void OnEntityStorageDump(Entity<MechComponent> entity, ref EntityStorageIntoContainerAttemptEvent args)
|
|
{
|
|
// There's no reason we should dump into /any/ of the mech's containers.
|
|
args.Cancelled = true;
|
|
}
|
|
|
|
private void OnGetAdditionalAccess(EntityUid uid, MechComponent component, ref GetAdditionalAccessEvent args)
|
|
{
|
|
var pilot = component.PilotSlot.ContainedEntity;
|
|
if (pilot == null)
|
|
return;
|
|
|
|
args.Entities.Add(pilot.Value);
|
|
}
|
|
|
|
private void SetupUser(EntityUid mech, EntityUid pilot, MechComponent? component = null)
|
|
{
|
|
if (!Resolve(mech, ref component))
|
|
return;
|
|
|
|
var rider = EnsureComp<MechPilotComponent>(pilot);
|
|
|
|
// Warning: this bypasses most normal interaction blocking components on the user, like drone laws and the like.
|
|
var irelay = EnsureComp<InteractionRelayComponent>(pilot);
|
|
|
|
_mover.SetRelay(pilot, mech);
|
|
_interaction.SetRelay(pilot, mech, irelay);
|
|
rider.Mech = mech;
|
|
Dirty(pilot, rider);
|
|
|
|
if (_net.IsClient)
|
|
return;
|
|
|
|
_actions.AddAction(pilot, ref component.MechCycleActionEntity, component.MechCycleAction, mech);
|
|
_actions.AddAction(pilot, ref component.MechUiActionEntity, component.MechUiAction, mech);
|
|
_actions.AddAction(pilot, ref component.MechLightsActionEntity, component.MechLightsAction, mech);
|
|
_actions.AddAction(pilot, ref component.MechEjectActionEntity, component.MechEjectAction, mech);
|
|
}
|
|
|
|
private void RemoveUser(EntityUid mech, EntityUid pilot)
|
|
{
|
|
if (!RemComp<MechPilotComponent>(pilot))
|
|
return;
|
|
RemComp<RelayInputMoverComponent>(pilot);
|
|
RemComp<InteractionRelayComponent>(pilot);
|
|
|
|
_actions.RemoveProvidedActions(pilot, mech);
|
|
}
|
|
|
|
public void ToggleLights(EntityUid uid, MechComponent component)
|
|
{
|
|
if (_pointLight.TryGetLight(uid, out var pointLightComponent))
|
|
{
|
|
component.Lights = !component.Lights;
|
|
_pointLight.SetEnabled(uid, component.Lights, pointLightComponent);
|
|
_actions.SetToggled(component.MechLightsActionEntity, component.Lights);
|
|
var ev = new MechSayEvent(uid, component.Lights ? component.MessageEnableLight : component.MessageDisableLight);
|
|
RaiseLocalEvent(uid, ref ev, true);
|
|
Dirty(uid, component);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Destroys the mech, removing the user and ejecting anything contained.
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="component"></param>
|
|
public virtual void BreakMech(EntityUid uid, MechComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
TryEject(uid, component);
|
|
var equipment = new List<EntityUid>(component.EquipmentContainer.ContainedEntities);
|
|
foreach (var ent in equipment)
|
|
{
|
|
RemoveEquipment(uid, ent, component, forced: true);
|
|
}
|
|
|
|
component.Broken = true;
|
|
UpdateAppearance(uid, component);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cycles through the currently selected equipment.
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="component"></param>
|
|
public void CycleEquipment(EntityUid uid, MechComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
var allEquipment = component.EquipmentContainer.ContainedEntities.ToList();
|
|
|
|
var equipmentIndex = -1;
|
|
if (component.CurrentSelectedEquipment != null)
|
|
{
|
|
bool StartIndex(EntityUid u) => u == component.CurrentSelectedEquipment;
|
|
equipmentIndex = allEquipment.FindIndex(StartIndex);
|
|
}
|
|
|
|
equipmentIndex++;
|
|
component.CurrentSelectedEquipment = equipmentIndex >= allEquipment.Count
|
|
? null
|
|
: allEquipment[equipmentIndex];
|
|
|
|
var popupString = component.CurrentSelectedEquipment != null
|
|
? Loc.GetString("mech-equipment-select-popup", ("item", component.CurrentSelectedEquipment))
|
|
: Loc.GetString("mech-equipment-select-none-popup");
|
|
|
|
if (_net.IsServer)
|
|
_popup.PopupEntity(popupString, uid);
|
|
|
|
var sayEv = new MechSayEvent(uid, component.MessageCycleEquipment);
|
|
RaiseLocalEvent(uid, ref sayEv, true);
|
|
|
|
Dirty(uid, component);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserts an equipment item into the mech.
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="toInsert"></param>
|
|
/// <param name="component"></param>
|
|
/// <param name="equipmentComponent"></param>
|
|
public void InsertEquipment(EntityUid uid, EntityUid toInsert, MechComponent? component = null,
|
|
MechEquipmentComponent? equipmentComponent = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
if (!Resolve(toInsert, ref equipmentComponent))
|
|
return;
|
|
|
|
if (component.EquipmentContainer.ContainedEntities.Count >= component.MaxEquipmentAmount)
|
|
return;
|
|
|
|
if (_whitelistSystem.IsWhitelistFail(component.EquipmentWhitelist, toInsert))
|
|
return;
|
|
|
|
equipmentComponent.EquipmentOwner = uid;
|
|
_container.Insert(toInsert, component.EquipmentContainer);
|
|
var ev = new MechEquipmentInsertedEvent(uid);
|
|
RaiseLocalEvent(toInsert, ref ev);
|
|
UpdateUserInterface(uid, component);
|
|
var sayEv = new MechSayEvent(uid, component.MessageInsertEquipment);
|
|
RaiseLocalEvent(uid, ref sayEv, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes an equipment item from a mech.
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="toRemove"></param>
|
|
/// <param name="component"></param>
|
|
/// <param name="equipmentComponent"></param>
|
|
/// <param name="forced">
|
|
/// Whether or not the removal can be cancelled, and if non-mech equipment should be ejected.
|
|
/// </param>
|
|
public void RemoveEquipment(EntityUid uid, EntityUid toRemove, MechComponent? component = null,
|
|
MechEquipmentComponent? equipmentComponent = null, bool forced = false)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
// When forced, we also want to handle the possibility that the "equipment" isn't actually equipment.
|
|
// This /shouldn't/ be possible thanks to OnEntityStorageDump, but there's been quite a few regressions
|
|
// with entities being hardlock stuck inside mechs.
|
|
if (!Resolve(toRemove, ref equipmentComponent) && !forced)
|
|
return;
|
|
|
|
if (!forced)
|
|
{
|
|
var attemptev = new AttemptRemoveMechEquipmentEvent();
|
|
RaiseLocalEvent(toRemove, ref attemptev);
|
|
if (attemptev.Cancelled)
|
|
return;
|
|
}
|
|
|
|
var ev = new MechEquipmentRemovedEvent(uid);
|
|
RaiseLocalEvent(toRemove, ref ev);
|
|
|
|
if (component.CurrentSelectedEquipment == toRemove)
|
|
CycleEquipment(uid, component);
|
|
|
|
if (forced && equipmentComponent != null)
|
|
equipmentComponent.EquipmentOwner = null;
|
|
|
|
_container.Remove(toRemove, component.EquipmentContainer);
|
|
UpdateUserInterface(uid, component);
|
|
var sayEv = new MechSayEvent(uid, component.MessageRemoveEquipment);
|
|
RaiseLocalEvent(uid, ref sayEv, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempts to change the amount of energy in the mech.
|
|
/// TODO: Power cells are predicted now, so no need to duplicate the charge level
|
|
/// </summary>
|
|
/// <param name="uid">The mech itself</param>
|
|
/// <param name="delta">The change in energy</param>
|
|
/// <param name="component"></param>
|
|
/// <returns>If the energy was successfully changed.</returns>
|
|
public virtual bool TryChangeEnergy(EntityUid uid, FixedPoint2 delta, MechComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return false;
|
|
|
|
if (component.Energy + delta < 0)
|
|
return false;
|
|
|
|
component.Energy = FixedPoint2.Clamp(component.Energy + delta, 0, component.MaxEnergy);
|
|
Dirty(uid, component);
|
|
UpdateUserInterface(uid, component);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the integrity of the mech.
|
|
/// </summary>
|
|
/// <param name="uid">The mech itself</param>
|
|
/// <param name="value">The value the integrity will be set at</param>
|
|
/// <param name="component"></param>
|
|
public void SetIntegrity(EntityUid uid, FixedPoint2 value, MechComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
component.Integrity = FixedPoint2.Clamp(value, 0, component.MaxIntegrity);
|
|
|
|
if (component.Integrity <= 0)
|
|
{
|
|
BreakMech(uid, component);
|
|
}
|
|
else if (component.Broken)
|
|
{
|
|
component.Broken = false;
|
|
UpdateAppearance(uid, component);
|
|
}
|
|
|
|
Dirty(uid, component);
|
|
UpdateUserInterface(uid, component);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if the pilot is present
|
|
/// </summary>
|
|
/// <param name="component"></param>
|
|
/// <returns>Whether or not the pilot is present</returns>
|
|
public bool IsEmpty(MechComponent component)
|
|
{
|
|
return component.PilotSlot.ContainedEntity == null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if an entity can be inserted into the mech.
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="toInsert"></param>
|
|
/// <param name="component"></param>
|
|
/// <returns></returns>
|
|
public bool CanInsert(EntityUid uid, EntityUid toInsert, MechComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return false;
|
|
|
|
return IsEmpty(component) && _actionBlocker.CanMove(toInsert);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates the user interface
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This is defined here so that UI updates can be accessed from shared.
|
|
/// </remarks>
|
|
public virtual void UpdateUserInterface(EntityUid uid, MechComponent? component = null)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempts to insert a pilot into the mech.
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="toInsert"></param>
|
|
/// <param name="component"></param>
|
|
/// <returns>Whether or not the entity was inserted</returns>
|
|
public bool TryInsert(EntityUid uid, EntityUid? toInsert, MechComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return false;
|
|
|
|
if (toInsert == null || component.PilotSlot.ContainedEntity == toInsert)
|
|
return false;
|
|
|
|
if (!CanInsert(uid, toInsert.Value, component))
|
|
return false;
|
|
|
|
SetupUser(uid, toInsert.Value);
|
|
var ev = new MechSayEvent(uid, component.MessageHello);
|
|
RaiseLocalEvent(uid, ref ev, true);
|
|
_container.Insert(toInsert.Value, component.PilotSlot);
|
|
UpdateAppearance(uid, component);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempts to eject the current pilot from the mech
|
|
/// </summary>
|
|
/// <param name="uid"></param>
|
|
/// <param name="component"></param>
|
|
/// <returns>Whether or not the pilot was ejected.</returns>
|
|
public bool TryEject(EntityUid uid, MechComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return false;
|
|
|
|
if (component.PilotSlot.ContainedEntity == null)
|
|
return false;
|
|
|
|
if (HasComp<NoRotateOnMoveComponent>(uid))
|
|
{
|
|
RemComp<NoRotateOnMoveComponent>(uid);
|
|
}
|
|
|
|
var pilot = component.PilotSlot.ContainedEntity.Value;
|
|
|
|
RemoveUser(uid, pilot);
|
|
_container.RemoveEntity(uid, pilot);
|
|
UpdateAppearance(uid, component);
|
|
var sayEv = new MechSayEvent(uid, component.MessageGoodbye);
|
|
RaiseLocalEvent(uid, ref sayEv, true);
|
|
return true;
|
|
}
|
|
|
|
private void OnGetMeleeWeapon(EntityUid uid, MechPilotComponent component, GetMeleeWeaponEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
if (!TryComp<MechComponent>(component.Mech, out var mech))
|
|
return;
|
|
|
|
var weapon = mech.CurrentSelectedEquipment ?? component.Mech;
|
|
args.Weapon = weapon;
|
|
args.Handled = true;
|
|
}
|
|
|
|
private void OnCanAttackFromContainer(EntityUid uid, MechPilotComponent component, CanAttackFromContainerEvent args)
|
|
{
|
|
args.CanAttack = true;
|
|
}
|
|
|
|
private void OnAttackAttempt(EntityUid uid, MechPilotComponent component, AttackAttemptEvent args)
|
|
{
|
|
if (args.Target == component.Mech)
|
|
args.Cancel();
|
|
}
|
|
|
|
public void UpdateAppearance(EntityUid uid, MechComponent? component = null,
|
|
AppearanceComponent? appearance = null)
|
|
{
|
|
if (!Resolve(uid, ref component, ref appearance, false))
|
|
return;
|
|
|
|
_appearance.SetData(uid, MechVisuals.Open, IsEmpty(component), appearance);
|
|
_appearance.SetData(uid, MechVisuals.Broken, component.Broken, appearance);
|
|
}
|
|
|
|
private void OnDragDrop(EntityUid uid, MechComponent component, ref DragDropTargetEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
args.Handled = true;
|
|
|
|
var doAfterEventArgs = new DoAfterArgs(EntityManager, args.Dragged, component.EntryDelay, new MechEntryEvent(), uid, target: uid)
|
|
{
|
|
BreakOnMove = true,
|
|
};
|
|
|
|
_doAfter.TryStartDoAfter(doAfterEventArgs);
|
|
}
|
|
|
|
private void OnCanDragDrop(EntityUid uid, MechComponent component, ref CanDropTargetEvent args)
|
|
{
|
|
args.Handled = true;
|
|
|
|
args.CanDrop |= !component.Broken && CanInsert(uid, args.Dragged, component);
|
|
}
|
|
|
|
private void OnEmagged(EntityUid uid, MechComponent component, ref GotEmaggedEvent args)
|
|
{
|
|
if (!component.BreakOnEmag)
|
|
return;
|
|
args.Handled = true;
|
|
component.EquipmentWhitelist = null;
|
|
Dirty(uid, component);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Event raised when the battery is successfully removed from the mech,
|
|
/// on both success and failure
|
|
/// </summary>
|
|
[Serializable, NetSerializable]
|
|
public sealed partial class RemoveBatteryEvent : SimpleDoAfterEvent
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Event raised when a person removes someone from a mech,
|
|
/// on both success and failure
|
|
/// </summary>
|
|
[Serializable, NetSerializable]
|
|
public sealed partial class MechExitEvent : SimpleDoAfterEvent
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Event raised when a person enters a mech, on both success and failure
|
|
/// </summary>
|
|
[Serializable, NetSerializable]
|
|
public sealed partial class MechEntryEvent : SimpleDoAfterEvent
|
|
{
|
|
}
|
|
|