* init * мать масштаба тарабанил * fix * upd * upd * upd * upd * upd * console spam fix * hohohohohohohooooonkeeeeeeeeeeeeeerrrrrrrrrrrsssssssss........ * fix * fix * upd * upd * some fixes * fix * upd * upd translation for steal obj * teg translate * upd * fix locale + add advertisements * translate configurator * Fully translate * upd * Я манал это переводить, позже переведу * upd en-US * fix Linter * upd * fix * upd * fix * fix * fix * Возврат ПНТ * remove agent non silent equipment * add acid to uplink * carrySystem new popups * fix * fix * fix disease locale * add Disease Guide * upd locale * upd * Revert "Merge branch 'master' of https://github.com/space-wizards/space-station-14 into misc" This reverts commit 4130d241fc47fb80924c0dd3b9c9a2db85af8a25, reversing changes made to 30abf7341ecce404f61f64e2000ad327964fcb00. * Revert "Merge branch 'master' of https://github.com/space-wizards/space-station-14 into misc" This reverts commit 4e5a50d21c29be8482f31e49db253b1ed17a0ae4, reversing changes made to 449cd7bfd50f29eb653e68ba60e3f0b9310f0443. * Revert "Merge branch 'master' of https://github.com/space-wizards/space-station-14 into misc" This reverts commit a4679665ef441d4b63a92dc3c4e217e2cdedbc16, reversing changes made to a80ef96cfbbc3cc737045e41a2f063a0910bf1ce. * Revert "Merge branch 'master' of https://github.com/space-wizards/space-station-14 into misc" This reverts commit 94f585756bb27d10a1be7fab1f340d79b7c0a213, reversing changes made to 906d18a3f66eaed73f3a894d70971872904fad4e. * Revert "Merge branch 'master' of https://github.com/space-wizards/space-station-14 into misc" This reverts commit d0a7c6436ba5c175b0e00d69f495ba51f9aac645, reversing changes made to e7933332274b336af1fc2a960264bc546c95d208. # Conflicts: # Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml # Resources/Prototypes/Roles/Jobs/departments.yml * fix * upd * upd * Reapply "Merge branch 'master' of https://github.com/space-wizards/space-station-14 into misc" This reverts commit 042a3f112bbc32a622108475ac28081eb0bbbf9f. # Conflicts: # Content.Server/Dragon/DragonRiftSystem.cs # Content.Server/GameTicking/GameTicker.Spawning.cs # Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs # Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs # Content.Server/Spawners/EntitySystems/ContainerSpawnPointSystem.cs # Content.Server/Zombies/ZombieSystem.cs # Content.Server/_Sunrise/NPCSleep/NPCSleepSystem.cs # Resources/Changelog/Changelog.yml # Resources/Locale/en-US/_strings/store/uplink-catalog.ftl # Resources/Prototypes/Catalog/VendingMachines/Inventories/secdrobe.yml # Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml # Resources/Prototypes/Entities/Clothing/Head/helmets.yml # Resources/Prototypes/Entities/Mobs/Player/silicon.yml # Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml # Resources/Prototypes/Entities/Stations/base.yml # Resources/Prototypes/Loadouts/Jobs/Security/security_officer.yml # Resources/Prototypes/Loadouts/loadout_groups.yml # Resources/Prototypes/Maps/box.yml # Resources/Prototypes/Maps/core.yml # Resources/Prototypes/Maps/fland.yml # Resources/Prototypes/Maps/marathon.yml # Resources/Prototypes/Maps/meta.yml # Resources/Prototypes/Maps/packed.yml # Resources/Prototypes/Roles/Jobs/departments.yml # Resources/Prototypes/Store/categories.yml # Resources/ServerInfo/Guidebook/Engineering/PortableGenerator.xml # Resources/ServerInfo/Guidebook/Security/Defusal.xml # Resources/ServerInfo/Guidebook/Security/Forensics.xml # Resources/migration.yml * Reapply "Merge branch 'master' of https://github.com/space-wizards/space-station-14 into misc" This reverts commit 2860e1d217a71be0c29684e020b2278c3f08685f. # Conflicts: # Resources/Changelog/Changelog.yml * Reapply "Merge branch 'master' of https://github.com/space-wizards/space-station-14 into misc" This reverts commit 0dc7ea17e23d844ce93118db7812b844e36dda4f. # Conflicts: # Resources/Changelog/Changelog.yml # Resources/Prototypes/Hydroponics/randomMutations.yml * Reapply "Merge branch 'master' of https://github.com/space-wizards/space-station-14 into misc" This reverts commit 439926b3c60e95cc2e701d84a032b17471a7c18e. * Reapply "Merge branch 'master' of https://github.com/space-wizards/space-station-14 into misc" This reverts commit 14160ab99909bf6b6f996f415d9dcfd5d4addbba. # Conflicts: # Resources/Changelog/Changelog.yml * fix * upd * upd uplink * upd * fix linter
342 lines
14 KiB
C#
342 lines
14 KiB
C#
using System.Threading;
|
||
using Content.Server.Carrying;
|
||
using Content.Server.DoAfter;
|
||
using Content.Server.Popups;
|
||
using Content.Server.Resist;
|
||
using Content.Shared._Sunrise.Carrying;
|
||
using Content.Shared.ActionBlocker;
|
||
using Content.Shared.Buckle.Components;
|
||
using Content.Shared.Carrying;
|
||
using Content.Shared.Climbing.Events;
|
||
using Content.Shared.DoAfter;
|
||
using Content.Shared.Hands;
|
||
using Content.Shared.Popups;
|
||
using Content.Shared.Hands.Components;
|
||
using Content.Shared.Interaction;
|
||
using Content.Shared.Interaction.Events;
|
||
using Content.Shared.Inventory.VirtualItem;
|
||
using Content.Shared.Mobs;
|
||
using Content.Shared.Mobs.Systems;
|
||
using Content.Shared.Movement.Events;
|
||
using Content.Shared.Movement.Pulling.Components;
|
||
using Content.Shared.Movement.Pulling.Events;
|
||
using Content.Shared.Movement.Pulling.Systems;
|
||
using Content.Shared.Movement.Systems;
|
||
using Content.Shared.Standing;
|
||
using Content.Shared.Stunnable;
|
||
using Content.Shared.Throwing;
|
||
using Content.Shared.Verbs;
|
||
using Robust.Shared.Player;
|
||
using Robust.Shared.Map.Components;
|
||
using Robust.Shared.Physics.Components;
|
||
|
||
namespace Content.Server._Sunrise.Carrying
|
||
{
|
||
public sealed class CarryingSystem : EntitySystem
|
||
{
|
||
[Dependency] private readonly SharedVirtualItemSystem _virtualItemSystem = default!;
|
||
[Dependency] private readonly CarryingSlowdownSystem _slowdown = default!;
|
||
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
||
[Dependency] private readonly StandingStateSystem _standingState = default!;
|
||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||
[Dependency] private readonly PullingSystem _pullingSystem = default!;
|
||
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
||
[Dependency] private readonly EscapeInventorySystem _escapeInventorySystem = default!;
|
||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!;
|
||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||
[Dependency] private readonly ThrowingSystem _throwingSystem = default!;
|
||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||
|
||
public override void Initialize()
|
||
{
|
||
base.Initialize();
|
||
SubscribeLocalEvent<CarriableComponent, GetVerbsEvent<AlternativeVerb>>(AddCarryVerb);
|
||
SubscribeLocalEvent<CarryingComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
|
||
SubscribeLocalEvent<CarryingComponent, BeforeThrowEvent>(OnThrow);
|
||
SubscribeLocalEvent<CarryingComponent, EntParentChangedMessage>(OnParentChanged);
|
||
SubscribeLocalEvent<CarryingComponent, MobStateChangedEvent>(OnMobStateChanged);
|
||
SubscribeLocalEvent<BeingCarriedComponent, InteractionAttemptEvent>(OnInteractionAttempt);
|
||
SubscribeLocalEvent<BeingCarriedComponent, MoveInputEvent>(OnMoveInput);
|
||
SubscribeLocalEvent<BeingCarriedComponent, UpdateCanMoveEvent>(OnMoveAttempt);
|
||
SubscribeLocalEvent<BeingCarriedComponent, StandAttemptEvent>(OnStandAttempt);
|
||
SubscribeLocalEvent<BeingCarriedComponent, GettingInteractedWithAttemptEvent>(OnInteractedWith);
|
||
SubscribeLocalEvent<BeingCarriedComponent, PullAttemptEvent>(OnPullAttempt);
|
||
SubscribeLocalEvent<BeingCarriedComponent, StartClimbEvent>(OnStartClimb);
|
||
SubscribeLocalEvent<BeingCarriedComponent, BuckledEvent>(OnBuckleChange);
|
||
SubscribeLocalEvent<CarriableComponent, CarryDoAfterEvent>(OnDoAfter);
|
||
}
|
||
|
||
private float MassContest(EntityUid roller, EntityUid target, PhysicsComponent? rollerPhysics = null, PhysicsComponent? targetPhysics = null)
|
||
{
|
||
if (!Resolve(roller, ref rollerPhysics, false) || !Resolve(target, ref targetPhysics, false))
|
||
return 1f;
|
||
|
||
if (targetPhysics.FixturesMass == 0)
|
||
return 1f;
|
||
|
||
return rollerPhysics.FixturesMass / targetPhysics.FixturesMass;
|
||
}
|
||
|
||
private void AddCarryVerb(EntityUid uid, CarriableComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||
{
|
||
if (!args.CanInteract || !args.CanAccess)
|
||
return;
|
||
|
||
if (!CanCarry(args.User, uid, component))
|
||
return;
|
||
|
||
if (HasComp<CarryingComponent>(args.User)) // yeah not dealing with that
|
||
return;
|
||
|
||
if (HasComp<BeingCarriedComponent>(args.User) || HasComp<BeingCarriedComponent>(args.Target))
|
||
return;
|
||
|
||
if (!_interactionSystem.InRangeUnobstructed(args.User, uid, 0.75f))
|
||
return;
|
||
|
||
if (!_mobStateSystem.IsAlive(args.User))
|
||
return;
|
||
|
||
if (args.User == args.Target)
|
||
return;
|
||
|
||
AlternativeVerb verb = new()
|
||
{
|
||
Act = () =>
|
||
{
|
||
StartCarryDoAfter(args.User, uid, component);
|
||
},
|
||
Text = Loc.GetString("carry-verb"),
|
||
Priority = 2
|
||
};
|
||
args.Verbs.Add(verb);
|
||
}
|
||
|
||
private void OnVirtualItemDeleted(EntityUid uid, CarryingComponent component, VirtualItemDeletedEvent args)
|
||
{
|
||
if (!HasComp<CarriableComponent>(args.BlockingEntity))
|
||
return;
|
||
|
||
DropCarried(uid, args.BlockingEntity);
|
||
}
|
||
|
||
private void OnThrow(EntityUid uid, CarryingComponent component, BeforeThrowEvent args)
|
||
{
|
||
if (!TryComp<VirtualItemComponent>(args.ItemUid, out var virtItem) || !HasComp<CarriableComponent>(virtItem.BlockingEntity))
|
||
return;
|
||
|
||
var multiplier = MassContest(uid, virtItem.BlockingEntity);
|
||
|
||
_throwingSystem.TryThrow(virtItem.BlockingEntity, args.Direction, 3f * multiplier, uid);
|
||
}
|
||
|
||
private void OnParentChanged(EntityUid uid, CarryingComponent component, ref EntParentChangedMessage args)
|
||
{
|
||
var xform = Transform(uid);
|
||
|
||
if (xform.ParentUid == args.OldParent)
|
||
return;
|
||
|
||
// Do not drop the carried entity if the new parent is a grid
|
||
if (xform.ParentUid == xform.GridUid)
|
||
return;
|
||
|
||
DropCarried(uid, component.Carried);
|
||
}
|
||
|
||
private void OnMobStateChanged(EntityUid uid, CarryingComponent component, MobStateChangedEvent args)
|
||
{
|
||
DropCarried(uid, component.Carried);
|
||
}
|
||
|
||
private void OnInteractionAttempt(EntityUid uid, BeingCarriedComponent component, InteractionAttemptEvent args)
|
||
{
|
||
if (args.Target == null)
|
||
return;
|
||
|
||
var targetParent = Transform(args.Target.Value).ParentUid;
|
||
|
||
if (args.Target.Value != component.Carrier && targetParent != component.Carrier && targetParent != uid)
|
||
args.Cancelled = true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Try to escape via the escape inventory system.
|
||
/// </summary>
|
||
private void OnMoveInput(EntityUid uid, BeingCarriedComponent component, ref MoveInputEvent args)
|
||
{
|
||
if (!TryComp<CanEscapeInventoryComponent>(uid, out var escape))
|
||
return;
|
||
|
||
if (args.OldMovement == MoveButtons.None || args.OldMovement == MoveButtons.Walk)
|
||
return;
|
||
|
||
if (_actionBlockerSystem.CanInteract(uid, component.Carrier))
|
||
{
|
||
_escapeInventorySystem.AttemptEscape(uid, component.Carrier, escape, MassContest(component.Carrier, uid));
|
||
}
|
||
}
|
||
|
||
private void OnMoveAttempt(EntityUid uid, BeingCarriedComponent component, UpdateCanMoveEvent args)
|
||
{
|
||
args.Cancel();
|
||
}
|
||
|
||
private void OnStandAttempt(EntityUid uid, BeingCarriedComponent component, StandAttemptEvent args)
|
||
{
|
||
args.Cancel();
|
||
}
|
||
|
||
private void OnInteractedWith(EntityUid uid, BeingCarriedComponent component, GettingInteractedWithAttemptEvent args)
|
||
{
|
||
if (args.Uid != component.Carrier)
|
||
args.Cancelled = true;
|
||
}
|
||
|
||
private void OnPullAttempt(EntityUid uid, BeingCarriedComponent component, PullAttemptEvent args)
|
||
{
|
||
args.Cancelled = true;
|
||
}
|
||
|
||
private void OnStartClimb(EntityUid uid, BeingCarriedComponent component, ref StartClimbEvent args)
|
||
{
|
||
DropCarried(component.Carrier, uid);
|
||
}
|
||
|
||
private void OnBuckleChange(EntityUid uid, BeingCarriedComponent component, ref BuckledEvent args)
|
||
{
|
||
DropCarried(component.Carrier, uid);
|
||
}
|
||
|
||
private void OnDoAfter(EntityUid uid, CarriableComponent component, CarryDoAfterEvent args)
|
||
{
|
||
component.CancelToken = null;
|
||
if (args.Handled || args.Cancelled)
|
||
return;
|
||
|
||
if (!CanCarry(args.Args.User, uid, component))
|
||
return;
|
||
|
||
Carry(args.Args.User, uid);
|
||
args.Handled = true;
|
||
}
|
||
private void StartCarryDoAfter(EntityUid carrier, EntityUid carried, CarriableComponent component)
|
||
{
|
||
TimeSpan length = TimeSpan.FromSeconds(1);
|
||
|
||
var mod = MassContest(carrier, carried);
|
||
|
||
if (mod != 0)
|
||
length /= mod;
|
||
|
||
if (length >= TimeSpan.FromSeconds(5))
|
||
{
|
||
_popupSystem.PopupEntity(Loc.GetString("carry-too-heavy"), carried, carrier, Shared.Popups.PopupType.SmallCaution);
|
||
return;
|
||
}
|
||
|
||
if (!HasComp<KnockedDownComponent>(carried))
|
||
length *= 2f;
|
||
|
||
component.CancelToken = new CancellationTokenSource();
|
||
|
||
var ev = new CarryDoAfterEvent();
|
||
var args = new DoAfterArgs(EntityManager ,carrier, length, ev, carried, target: carried)
|
||
{
|
||
BreakOnMove = true,
|
||
NeedHand = true
|
||
};
|
||
|
||
_doAfterSystem.TryStartDoAfter(args);
|
||
|
||
|
||
ShowCarryPopup("carry-starting", Filter.Entities(carrier), PopupType.Medium, carrier, carried);
|
||
ShowCarryPopup("carry-started", Filter.Entities(carried), PopupType.Medium, carrier, carried);
|
||
ShowCarryPopup("carry-observed", Filter.PvsExcept(carrier).RemoveWhereAttachedEntity(e => e == carried), PopupType.MediumCaution, carrier, carried);
|
||
}
|
||
|
||
private void Carry(EntityUid carrier, EntityUid carried)
|
||
{
|
||
if (TryComp<PullableComponent>(carried, out var pullable))
|
||
_pullingSystem.TryStopPull(carried, pullable, carrier);
|
||
|
||
Transform(carrier).AttachToGridOrMap();
|
||
Transform(carried).Coordinates = Transform(carrier).Coordinates;
|
||
Transform(carried).AttachParent(carrier);
|
||
_virtualItemSystem.TrySpawnVirtualItemInHand(carried, carrier);
|
||
_virtualItemSystem.TrySpawnVirtualItemInHand(carried, carrier);
|
||
var carryingComp = EnsureComp<CarryingComponent>(carrier);
|
||
ApplyCarrySlowdown(carrier, carried);
|
||
var carriedComp = EnsureComp<BeingCarriedComponent>(carried);
|
||
EnsureComp<KnockedDownComponent>(carried);
|
||
|
||
carryingComp.Carried = carried;
|
||
carriedComp.Carrier = carrier;
|
||
|
||
_actionBlockerSystem.UpdateCanMove(carried);
|
||
}
|
||
|
||
public void DropCarried(EntityUid carrier, EntityUid carried)
|
||
{
|
||
RemComp<CarryingComponent>(carrier); // get rid of this first so we don't recusrively fire that event
|
||
RemComp<CarryingSlowdownComponent>(carrier);
|
||
RemComp<BeingCarriedComponent>(carried);
|
||
RemComp<KnockedDownComponent>(carried);
|
||
_actionBlockerSystem.UpdateCanMove(carried);
|
||
_virtualItemSystem.DeleteInHandsMatching(carrier, carried);
|
||
if (_entityManager.TryGetComponent<TransformComponent>(carried, out var transformComponent))
|
||
{
|
||
transformComponent.AttachToGridOrMap();
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine($"TransformComponent отсутствует у сущности {carried}.");
|
||
}
|
||
_standingState.Stand(carried);
|
||
_movementSpeed.RefreshMovementSpeedModifiers(carrier);
|
||
}
|
||
|
||
private void ApplyCarrySlowdown(EntityUid carrier, EntityUid carried)
|
||
{
|
||
var massRatio = MassContest(carrier, carried);
|
||
|
||
if (massRatio == 0)
|
||
massRatio = 1;
|
||
|
||
var massRatioSq = Math.Pow(massRatio, 2);
|
||
var modifier = (1 - (0.15 / massRatioSq));
|
||
modifier = Math.Max(0.1, modifier);
|
||
var slowdownComp = EnsureComp<CarryingSlowdownComponent>(carrier);
|
||
_slowdown.SetModifier(carrier, (float) modifier, (float) modifier, slowdownComp);
|
||
}
|
||
|
||
public bool CanCarry(EntityUid carrier, EntityUid carried, CarriableComponent? carriedComp = null)
|
||
{
|
||
if (!Resolve(carried, ref carriedComp, false))
|
||
return false;
|
||
|
||
if (carriedComp.CancelToken != null)
|
||
return false;
|
||
|
||
if (!HasComp<MapGridComponent>(Transform(carrier).ParentUid))
|
||
return false;
|
||
|
||
if (HasComp<BeingCarriedComponent>(carrier) || HasComp<BeingCarriedComponent>(carried))
|
||
return false;
|
||
|
||
if (!TryComp<HandsComponent>(carrier, out var hands))
|
||
return false;
|
||
|
||
if (hands.CountFreeHands() < carriedComp.FreeHandsRequired)
|
||
return false;
|
||
|
||
return true;
|
||
}
|
||
|
||
private void ShowCarryPopup(string locString, Filter filter, PopupType type, EntityUid carrier, EntityUid carried)
|
||
{
|
||
_popupSystem.PopupEntity(Loc.GetString(locString, ("carrier", carrier), ("target", carried)),carrier, filter, true, type);
|
||
}
|
||
}
|
||
}
|