# 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
586 lines
21 KiB
C#
586 lines
21 KiB
C#
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.Buckle.Components;
|
|
using Content.Shared.Climbing.Components;
|
|
using Content.Shared.Climbing.Events;
|
|
using Content.Shared.Damage.Systems;
|
|
using Content.Shared.DoAfter;
|
|
using Content.Shared.DragDrop;
|
|
using Content.Shared.Hands.Components;
|
|
using Content.Shared.IdentityManagement;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Movement.Events;
|
|
using Content.Shared.Physics;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Stunnable;
|
|
using Content.Shared.Verbs;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Physics.Collision.Shapes;
|
|
using Robust.Shared.Physics.Components;
|
|
using Robust.Shared.Physics.Controllers;
|
|
using Robust.Shared.Physics.Events;
|
|
using Robust.Shared.Physics.Systems;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Climbing.Systems;
|
|
|
|
public sealed partial class ClimbSystem : VirtualController
|
|
{
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
|
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
|
[Dependency] private readonly FixtureSystem _fixtureSystem = default!;
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
|
[Dependency] private readonly SharedContainerSystem _containers = default!;
|
|
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
|
[Dependency] private readonly SharedStunSystem _stunSystem = default!;
|
|
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
|
|
|
|
private const string ClimbingFixtureName = "climb";
|
|
private const int ClimbingCollisionGroup = (int) (CollisionGroup.TableLayer | CollisionGroup.LowImpassable);
|
|
|
|
private EntityQuery<ClimbableComponent> _climbableQuery;
|
|
private EntityQuery<FixturesComponent> _fixturesQuery;
|
|
private EntityQuery<TransformComponent> _xformQuery;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
_climbableQuery = GetEntityQuery<ClimbableComponent>();
|
|
_fixturesQuery = GetEntityQuery<FixturesComponent>();
|
|
_xformQuery = GetEntityQuery<TransformComponent>();
|
|
|
|
SubscribeLocalEvent<ClimbingComponent, UpdateCanMoveEvent>(OnMoveAttempt);
|
|
SubscribeLocalEvent<ClimbingComponent, EntParentChangedMessage>(OnParentChange);
|
|
SubscribeLocalEvent<ClimbingComponent, ClimbDoAfterEvent>(OnDoAfter);
|
|
SubscribeLocalEvent<ClimbingComponent, EndCollideEvent>(OnClimbEndCollide);
|
|
SubscribeLocalEvent<ClimbingComponent, BuckledEvent>(OnBuckled);
|
|
SubscribeLocalEvent<ClimbingComponent, EntGotInsertedIntoContainerMessage>(OnStored);
|
|
|
|
SubscribeLocalEvent<ClimbableComponent, CanDropTargetEvent>(OnCanDragDropOn);
|
|
SubscribeLocalEvent<ClimbableComponent, GetVerbsEvent<AlternativeVerb>>(AddClimbableVerb);
|
|
SubscribeLocalEvent<ClimbableComponent, DragDropTargetEvent>(OnClimbableDragDrop);
|
|
|
|
SubscribeLocalEvent<GlassTableComponent, ClimbedOnEvent>(OnGlassClimbed);
|
|
}
|
|
|
|
public override void UpdateBeforeSolve(bool prediction, float frameTime)
|
|
{
|
|
base.UpdateBeforeSolve(prediction, frameTime);
|
|
|
|
var query = EntityQueryEnumerator<ClimbingComponent>();
|
|
var curTime = _timing.CurTime;
|
|
|
|
// Move anything still climb in the specified direction.
|
|
while (query.MoveNext(out var uid, out var comp))
|
|
{
|
|
if (comp.NextTransition == null)
|
|
continue;
|
|
|
|
if (comp.NextTransition < curTime)
|
|
{
|
|
FinishTransition(uid, comp);
|
|
continue;
|
|
}
|
|
|
|
var xform = _xformQuery.GetComponent(uid);
|
|
_xformSystem.SetLocalPosition(uid, xform.LocalPosition + comp.Direction * frameTime, xform);
|
|
}
|
|
}
|
|
|
|
private void FinishTransition(EntityUid uid, ClimbingComponent comp)
|
|
{
|
|
// TODO: Validate climb here
|
|
comp.NextTransition = null;
|
|
_actionBlockerSystem.UpdateCanMove(uid);
|
|
Dirty(uid, comp);
|
|
|
|
// Stop if necessary.
|
|
if (!_fixturesQuery.TryGetComponent(uid, out var fixtures) ||
|
|
!IsClimbing(uid, fixtures))
|
|
{
|
|
StopClimb(uid, comp);
|
|
return;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns true if entity currently has a valid vault.
|
|
/// </summary>
|
|
public bool IsClimbing(EntityUid uid, FixturesComponent? fixturesComp = null) // Sunrise-Edit
|
|
{
|
|
if (!_fixturesQuery.Resolve(uid, ref fixturesComp) || !fixturesComp.Fixtures.TryGetValue(ClimbingFixtureName, out var climbFixture))
|
|
return false;
|
|
|
|
foreach (var contact in climbFixture.Contacts.Values)
|
|
{
|
|
var other = uid == contact.EntityA ? contact.EntityB : contact.EntityA;
|
|
|
|
if (HasComp<ClimbableComponent>(other))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private void OnMoveAttempt(EntityUid uid, ClimbingComponent component, UpdateCanMoveEvent args)
|
|
{
|
|
// Can't move when transition.
|
|
if (component.NextTransition != null)
|
|
args.Cancel();
|
|
}
|
|
|
|
private void OnParentChange(EntityUid uid, ClimbingComponent component, ref EntParentChangedMessage args)
|
|
{
|
|
if (component.NextTransition != null)
|
|
{
|
|
FinishTransition(uid, component);
|
|
}
|
|
}
|
|
|
|
private void OnCanDragDropOn(EntityUid uid, ClimbableComponent component, ref CanDropTargetEvent args)
|
|
{
|
|
if (args.Handled || !component.Vaultable)
|
|
return;
|
|
|
|
// If already climbing then don't show outlines.
|
|
if (TryComp(args.Dragged, out ClimbingComponent? climbing) && climbing.IsClimbing)
|
|
return;
|
|
|
|
var canVault = args.User == args.Dragged
|
|
? CanVault(component, args.User, uid, out _)
|
|
: CanVault(component, args.User, args.Dragged, uid, out _);
|
|
|
|
args.CanDrop = canVault;
|
|
|
|
if (!HasComp<HandsComponent>(args.User))
|
|
args.CanDrop = false;
|
|
|
|
args.Handled = true;
|
|
}
|
|
|
|
private void AddClimbableVerb(EntityUid uid, ClimbableComponent component, GetVerbsEvent<AlternativeVerb> args)
|
|
{
|
|
if (!args.CanAccess || !args.CanInteract || !_actionBlockerSystem.CanMove(args.User) || !component.Vaultable)
|
|
return;
|
|
|
|
if (!TryComp(args.User, out ClimbingComponent? climbingComponent) || climbingComponent.IsClimbing || !climbingComponent.CanClimb)
|
|
return;
|
|
|
|
// TODO VERBS ICON add a climbing icon?
|
|
args.Verbs.Add(new AlternativeVerb
|
|
{
|
|
Act = () => TryClimb(args.User, args.User, args.Target, out _, component),
|
|
Text = Loc.GetString("comp-climbable-verb-climb")
|
|
});
|
|
}
|
|
|
|
private void OnClimbableDragDrop(EntityUid uid, ClimbableComponent component, ref DragDropTargetEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
TryClimb(args.User, args.Dragged, uid, out _, component);
|
|
}
|
|
|
|
public bool TryClimb(
|
|
EntityUid user,
|
|
EntityUid entityToMove,
|
|
EntityUid climbable,
|
|
out DoAfterId? id,
|
|
ClimbableComponent? comp = null,
|
|
ClimbingComponent? climbing = null)
|
|
{
|
|
id = null;
|
|
|
|
if (!Resolve(climbable, ref comp) || !Resolve(entityToMove, ref climbing, false))
|
|
return false;
|
|
|
|
var canVault = user == entityToMove
|
|
? CanVault(comp, user, climbable, out var reason)
|
|
: CanVault(comp, user, entityToMove, climbable, out reason);
|
|
if (!canVault)
|
|
{
|
|
_popupSystem.PopupClient(reason, user, user);
|
|
return false;
|
|
}
|
|
|
|
// Note, IsClimbing does not mean a DoAfter is active, it means the target has already finished a DoAfter and
|
|
// is currently on top of something..
|
|
if (climbing.IsClimbing)
|
|
return true;
|
|
|
|
var ev = new AttemptClimbEvent(user, entityToMove, climbable);
|
|
RaiseLocalEvent(climbable, ref ev);
|
|
if (ev.Cancelled)
|
|
return false;
|
|
|
|
var args = new DoAfterArgs(EntityManager, user, comp.ClimbDelay, new ClimbDoAfterEvent(),
|
|
entityToMove,
|
|
target: climbable,
|
|
used: entityToMove)
|
|
{
|
|
BreakOnMove = true,
|
|
BreakOnDamage = true,
|
|
DuplicateCondition = DuplicateConditions.SameTool | DuplicateConditions.SameTarget
|
|
};
|
|
|
|
_audio.PlayPredicted(comp.StartClimbSound, climbable, user);
|
|
var success = _doAfterSystem.TryStartDoAfter(args, out id);
|
|
|
|
if (success)
|
|
climbing.DoAfter = id;
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
private void OnDoAfter(EntityUid uid, ClimbingComponent component, ClimbDoAfterEvent args)
|
|
{
|
|
component.DoAfter = null;
|
|
|
|
if (args.Handled || args.Cancelled || args.Args.Target == null || args.Args.Used == null)
|
|
return;
|
|
|
|
if (_containers.IsEntityInContainer(uid))
|
|
{
|
|
args.Handled = true;
|
|
return;
|
|
}
|
|
|
|
Climb(uid, args.Args.User, args.Args.Target.Value, climbing: component);
|
|
args.Handled = true;
|
|
}
|
|
|
|
public void Climb(EntityUid uid, EntityUid user, EntityUid climbable, bool silent = false, ClimbingComponent? climbing = null,
|
|
PhysicsComponent? physics = null, FixturesComponent? fixtures = null, ClimbableComponent? comp = null)
|
|
{
|
|
if (!Resolve(uid, ref climbing, ref physics, ref fixtures, false))
|
|
return;
|
|
|
|
if (!Resolve(climbable, ref comp, false))
|
|
return;
|
|
|
|
var selfEvent = new SelfBeforeClimbEvent(uid, user, (climbable, comp));
|
|
RaiseLocalEvent(uid, selfEvent);
|
|
|
|
if (selfEvent.Cancelled)
|
|
return;
|
|
|
|
var targetEvent = new TargetBeforeClimbEvent(uid, user, (climbable, comp));
|
|
RaiseLocalEvent(climbable, targetEvent);
|
|
|
|
if (targetEvent.Cancelled)
|
|
return;
|
|
|
|
if (!ReplaceFixtures(uid, climbing, fixtures))
|
|
return;
|
|
|
|
var xform = _xformQuery.GetComponent(uid);
|
|
var (worldPos, worldRot) = _xformSystem.GetWorldPositionRotation(xform);
|
|
var worldDirection = _xformSystem.GetWorldPosition(climbable) - worldPos;
|
|
var distance = worldDirection.Length();
|
|
var parentRot = worldRot - xform.LocalRotation;
|
|
// Need direction relative to climber's parent.
|
|
var localDirection = (-parentRot).RotateVec(worldDirection);
|
|
|
|
// On top of it already so just do it in place.
|
|
if (localDirection.LengthSquared() < 0.01f)
|
|
{
|
|
climbing.NextTransition = null;
|
|
}
|
|
// VirtualController over to the thing.
|
|
else
|
|
{
|
|
var climbDuration = TimeSpan.FromSeconds(distance / climbing.TransitionRate);
|
|
climbing.NextTransition = _timing.CurTime + climbDuration;
|
|
|
|
climbing.Direction = localDirection.Normalized() * climbing.TransitionRate;
|
|
_actionBlockerSystem.UpdateCanMove(uid);
|
|
}
|
|
|
|
climbing.IsClimbing = true;
|
|
Dirty(uid, climbing);
|
|
|
|
_audio.PlayPredicted(comp.FinishClimbSound, climbable, user);
|
|
|
|
var startEv = new StartClimbEvent(climbable);
|
|
var climbedEv = new ClimbedOnEvent(uid, user);
|
|
RaiseLocalEvent(uid, ref startEv);
|
|
RaiseLocalEvent(climbable, ref climbedEv);
|
|
|
|
if (silent)
|
|
return;
|
|
|
|
string selfMessage;
|
|
string othersMessage;
|
|
|
|
if (user == uid)
|
|
{
|
|
othersMessage = Loc.GetString("comp-climbable-user-climbs-other",
|
|
("user", Identity.Entity(uid, EntityManager)),
|
|
("climbable", climbable));
|
|
|
|
selfMessage = Loc.GetString("comp-climbable-user-climbs", ("climbable", climbable));
|
|
}
|
|
else
|
|
{
|
|
othersMessage = Loc.GetString("comp-climbable-user-climbs-force-other",
|
|
("user", Identity.Entity(user, EntityManager)),
|
|
("moved-user", Identity.Entity(uid, EntityManager)), ("climbable", climbable));
|
|
|
|
selfMessage = Loc.GetString("comp-climbable-user-climbs-force", ("moved-user", Identity.Entity(uid, EntityManager)),
|
|
("climbable", climbable));
|
|
}
|
|
|
|
_popupSystem.PopupPredicted(selfMessage, othersMessage, uid, user);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Replaces the current fixtures with non-climbing collidable versions so that climb end can be detected
|
|
/// </summary>
|
|
/// <returns>Returns whether adding the new fixtures was successful</returns>
|
|
private bool ReplaceFixtures(EntityUid uid, ClimbingComponent climbingComp, FixturesComponent fixturesComp)
|
|
{
|
|
// Swap fixtures
|
|
foreach (var (name, fixture) in fixturesComp.Fixtures)
|
|
{
|
|
if (climbingComp.DisabledFixtureMasks.ContainsKey(name)
|
|
|| fixture.Hard == false
|
|
|| (fixture.CollisionMask & ClimbingCollisionGroup) == 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
climbingComp.DisabledFixtureMasks.Add(name, fixture.CollisionMask & ClimbingCollisionGroup);
|
|
_physics.SetCollisionMask(uid, name, fixture, fixture.CollisionMask & ~ClimbingCollisionGroup, fixturesComp);
|
|
}
|
|
|
|
if (!_fixtureSystem.TryCreateFixture(
|
|
uid,
|
|
new PhysShapeCircle(0.35f),
|
|
ClimbingFixtureName,
|
|
collisionLayer: (int) CollisionGroup.None,
|
|
collisionMask: ClimbingCollisionGroup,
|
|
hard: false,
|
|
manager: fixturesComp))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void OnClimbEndCollide(EntityUid uid, ClimbingComponent component, ref EndCollideEvent args)
|
|
{
|
|
if (args.OurFixtureId != ClimbingFixtureName
|
|
|| !component.IsClimbing
|
|
|| component.NextTransition != null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var contact in args.OurFixture.Contacts.Values)
|
|
{
|
|
if (!contact.IsTouching)
|
|
continue;
|
|
|
|
var otherEnt = contact.OtherEnt(uid);
|
|
var (otherFixtureId, otherFixture) = contact.OtherFixture(uid);
|
|
|
|
// TODO: Remove this on engine.
|
|
if (args.OtherEntity == otherEnt && args.OtherFixtureId == otherFixtureId)
|
|
continue;
|
|
|
|
if (otherFixture is { Hard: true } &&
|
|
_climbableQuery.HasComp(otherEnt))
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
// TODO: Is this even needed anymore?
|
|
foreach (var otherFixture in args.OurFixture.Contacts.Keys)
|
|
{
|
|
// If it's the other fixture then ignore em
|
|
if (otherFixture == args.OtherFixture)
|
|
continue;
|
|
|
|
// If still colliding with a climbable, do not stop climbing
|
|
if (HasComp<ClimbableComponent>(otherFixture.Owner))
|
|
return;
|
|
}
|
|
|
|
StopClimb(uid, component);
|
|
}
|
|
|
|
private void StopClimb(EntityUid uid, ClimbingComponent? climbing = null, FixturesComponent? fixtures = null)
|
|
{
|
|
if (!Resolve(uid, ref climbing, ref fixtures, false))
|
|
return;
|
|
|
|
foreach (var (name, fixtureMask) in climbing.DisabledFixtureMasks)
|
|
{
|
|
if (!fixtures.Fixtures.TryGetValue(name, out var fixture))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
_physics.SetCollisionMask(uid, name, fixture, fixture.CollisionMask | fixtureMask, fixtures);
|
|
}
|
|
|
|
climbing.DisabledFixtureMasks.Clear();
|
|
_fixtureSystem.DestroyFixture(uid, ClimbingFixtureName, manager: fixtures);
|
|
climbing.IsClimbing = false;
|
|
climbing.NextTransition = null;
|
|
var ev = new EndClimbEvent();
|
|
RaiseLocalEvent(uid, ref ev);
|
|
Dirty(uid, climbing);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if the user can vault the target
|
|
/// </summary>
|
|
/// <param name="component">The component of the entity that is being vaulted</param>
|
|
/// <param name="user">The entity that wants to vault</param>
|
|
/// <param name="target">The object that is being vaulted</param>
|
|
/// <param name="reason">The reason why it cant be dropped</param>
|
|
public bool CanVault(ClimbableComponent component, EntityUid user, EntityUid target, out string reason)
|
|
{
|
|
if (!component.Vaultable)
|
|
{
|
|
reason = string.Empty;
|
|
return false;
|
|
}
|
|
|
|
if (!_actionBlockerSystem.CanInteract(user, target))
|
|
{
|
|
reason = Loc.GetString("comp-climbable-cant-interact");
|
|
return false;
|
|
}
|
|
|
|
if (!TryComp<ClimbingComponent>(user, out var climbingComp)
|
|
|| !climbingComp.CanClimb)
|
|
{
|
|
reason = Loc.GetString("comp-climbable-cant-climb");
|
|
return false;
|
|
}
|
|
|
|
if (!_interactionSystem.InRangeUnobstructed(user, target, component.Range))
|
|
{
|
|
reason = Loc.GetString("comp-climbable-cant-reach");
|
|
return false;
|
|
}
|
|
|
|
if (_containers.IsEntityInContainer(user))
|
|
{
|
|
reason = Loc.GetString("comp-climbable-cant-reach");
|
|
return false;
|
|
}
|
|
|
|
reason = string.Empty;
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if the user can vault the dragged entity onto the the target
|
|
/// </summary>
|
|
/// <param name="component">The climbable component of the object being vaulted onto</param>
|
|
/// <param name="user">The user that wants to vault the entity</param>
|
|
/// <param name="dragged">The entity that is being vaulted</param>
|
|
/// <param name="target">The object that is being vaulted onto</param>
|
|
/// <param name="reason">The reason why it cant be dropped</param>
|
|
/// <returns></returns>
|
|
public bool CanVault(ClimbableComponent component, EntityUid user, EntityUid dragged, EntityUid target,
|
|
out string reason)
|
|
{
|
|
if (!_actionBlockerSystem.CanInteract(user, dragged) || !_actionBlockerSystem.CanInteract(user, target))
|
|
{
|
|
reason = Loc.GetString("comp-climbable-cant-interact");
|
|
return false;
|
|
}
|
|
|
|
if (!HasComp<ClimbingComponent>(dragged))
|
|
{
|
|
reason = Loc.GetString("comp-climbable-target-cant-climb", ("moved-user", Identity.Entity(dragged, EntityManager)));
|
|
return false;
|
|
}
|
|
|
|
bool Ignored(EntityUid entity) => entity == target || entity == user || entity == dragged;
|
|
|
|
if (!_interactionSystem.InRangeUnobstructed(user, target, component.Range, predicate: Ignored)
|
|
|| !_interactionSystem.InRangeUnobstructed(user, dragged, component.Range, predicate: Ignored))
|
|
{
|
|
reason = Loc.GetString("comp-climbable-cant-reach");
|
|
return false;
|
|
}
|
|
|
|
if (_containers.IsEntityInContainer(user) || _containers.IsEntityInContainer(dragged))
|
|
{
|
|
reason = Loc.GetString("comp-climbable-cant-reach");
|
|
return false;
|
|
}
|
|
|
|
reason = string.Empty;
|
|
return true;
|
|
}
|
|
|
|
public void ForciblySetClimbing(EntityUid uid, EntityUid climbable, ClimbingComponent? component = null)
|
|
{
|
|
Climb(uid, uid, climbable, true, component);
|
|
}
|
|
|
|
private void OnBuckled(EntityUid uid, ClimbingComponent component, ref BuckledEvent args)
|
|
{
|
|
StopOrCancelClimb(uid, component);
|
|
}
|
|
|
|
private void OnStored(EntityUid uid, ClimbingComponent component, ref EntGotInsertedIntoContainerMessage args)
|
|
{
|
|
StopOrCancelClimb(uid, component);
|
|
}
|
|
|
|
private void StopOrCancelClimb(EntityUid uid, ClimbingComponent component)
|
|
{
|
|
if (component.IsClimbing)
|
|
{
|
|
StopClimb(uid, component);
|
|
return;
|
|
}
|
|
|
|
if (component.DoAfter != null)
|
|
{
|
|
_doAfterSystem.Cancel(component.DoAfter);
|
|
component.DoAfter = null;
|
|
}
|
|
}
|
|
|
|
private void OnGlassClimbed(EntityUid uid, GlassTableComponent component, ref ClimbedOnEvent args)
|
|
{
|
|
if (TryComp<PhysicsComponent>(args.Climber, out var physics) && physics.Mass <= component.MassLimit)
|
|
return;
|
|
|
|
_damageableSystem.TryChangeDamage(args.Climber, component.ClimberDamage, origin: args.Climber);
|
|
_damageableSystem.TryChangeDamage(uid, component.TableDamage, origin: args.Climber);
|
|
_stunSystem.TryUpdateParalyzeDuration(args.Climber, TimeSpan.FromSeconds(component.StunTime));
|
|
|
|
// Not shown to the user, since they already get a 'you climb on the glass table' popup
|
|
_popupSystem.PopupEntity(
|
|
Loc.GetString("glass-table-shattered-others", ("table", uid), ("climber", Identity.Entity(args.Climber, EntityManager))), args.Climber,
|
|
Filter.PvsExcept(args.Climber), true);
|
|
}
|
|
|
|
[Serializable, NetSerializable]
|
|
private sealed partial class ClimbDoAfterEvent : SimpleDoAfterEvent
|
|
{
|
|
}
|
|
}
|