Исправление системы переноса гуманоидов

This commit is contained in:
Vigers Ray 2024-06-09 17:18:58 +03:00
parent 1a36d5bd7e
commit 599c3f6b05
11 changed files with 81 additions and 408 deletions

View file

@ -1,3 +1,5 @@
using Content.Server._Sunrise.Carrying;
using Content.Server.Carrying;
using Content.Server.Popups;
using Content.Shared.Storage.Components;
using Content.Shared.ActionBlocker;
@ -19,6 +21,7 @@ public sealed class EscapeInventorySystem : EntitySystem
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly CarryingSystem _carryingSystem = default!;
public override void Initialize()
{
@ -82,6 +85,14 @@ public sealed class EscapeInventorySystem : EntitySystem
if (args.Handled || args.Cancelled)
return;
// Sunrise-Start
if (TryComp<BeingCarriedComponent>(uid, out var carried))
{
_carryingSystem.DropCarried(carried.Carrier, uid);
return;
}
// Sunrise-End
_containerSystem.AttachParentToContainerOrGrid((uid, Transform(uid)));
args.Handled = true;
}

View file

@ -1,54 +1,48 @@
using System.Numerics;
using System.Threading;
using Content.Server.Carrying;
using Content.Server.DoAfter;
using Content.Server.Inventory;
using Content.Server.Resist;
using Content.Server.Popups;
using Content.Server.Item.PseudoItem;
using Content.Shared.Climbing;
using Content.Shared.Mobs;
using Content.Shared.DoAfter;
using Content.Shared.Buckle.Components;
using Content.Shared.Hands.Components;
using Content.Shared.Hands;
using Content.Shared.Stunnable;
using Content.Shared.Interaction.Events;
using Content.Shared.Verbs;
using Content.Shared.Climbing.Events;
using Content.Shared.Carrying;
using Content.Shared.Movement.Events;
using Content.Shared.Movement.Systems;
using Content.Shared.Pulling;
using Content.Shared.Standing;
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.Hands.Components;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory.VirtualItem;
using Content.Shared.Item;
using Content.Shared.Item.PseudoItem;
using Content.Shared.Mind.Components;
using Content.Shared.Throwing;
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.Popups;
using Content.Shared.Storage;
using Content.Shared.Movement.Systems;
using Content.Shared.Standing;
using Content.Shared.Stunnable;
using Content.Shared.Throwing;
using Content.Shared.Verbs;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics.Components;
namespace Content.Server.Carrying
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 _pulling = 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 PseudoItemSystem _pseudoItem = default!;
[Dependency] private readonly VirtualItemSystem _virtualItemSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
public override void Initialize()
{
@ -67,9 +61,18 @@ namespace Content.Server.Carrying
SubscribeLocalEvent<BeingCarriedComponent, StartClimbEvent>(OnStartClimb);
SubscribeLocalEvent<BeingCarriedComponent, BuckleChangeEvent>(OnBuckleChange);
SubscribeLocalEvent<CarriableComponent, CarryDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<CarryingComponent, GetVerbsEvent<InnateVerb>>(AddInsertCarriedVerb);
}
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)
{
@ -79,12 +82,15 @@ namespace Content.Server.Carrying
if (!CanCarry(args.User, uid, component))
return;
if (HasComp<CarryingComponent>(args.User))
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;
@ -118,8 +124,8 @@ namespace Content.Server.Carrying
args.ItemUid = virtItem.BlockingEntity;
// var multiplier = _contests.MassContest(uid, virtItem.BlockingEntity);
// args.ThrowStrength = 5f * multiplier;
var multiplier = MassContest(uid, virtItem.BlockingEntity);
args.ThrowStrength = 5f * multiplier;
}
private void OnParentChanged(EntityUid uid, CarryingComponent component, ref EntParentChangedMessage args)
@ -141,9 +147,6 @@ namespace Content.Server.Carrying
DropCarried(uid, component.Carried);
}
/// <summary>
/// позволяет человеку, которого несут, взаимодействовать только с тем, кто его несет, и с вещами, находящимися у него
/// </summary>
private void OnInteractionAttempt(EntityUid uid, BeingCarriedComponent component, InteractionAttemptEvent args)
{
if (args.Target == null)
@ -168,7 +171,7 @@ namespace Content.Server.Carrying
if (_actionBlockerSystem.CanInteract(uid, component.Carrier))
{
_escapeInventorySystem.AttemptEscape(uid, component.Carrier, escape);
_escapeInventorySystem.AttemptEscape(uid, component.Carrier, escape, MassContest(uid, component.Carrier));
}
}
@ -215,11 +218,16 @@ namespace Content.Server.Carrying
Carry(args.Args.User, uid);
args.Handled = true;
}
private void StartCarryDoAfter(EntityUid carrier, EntityUid carried, CarriableComponent component)
{
var length = GetPickupDuration(carrier, carried);
if (length >= TimeSpan.FromSeconds(9))
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;
@ -231,11 +239,12 @@ namespace Content.Server.Carrying
component.CancelToken = new CancellationTokenSource();
var ev = new CarryDoAfterEvent();
var args = new DoAfterArgs(EntityManager, carrier, length, ev, carried, target: carried)
var args = new DoAfterArgs(EntityManager ,carrier, length, ev, carried, target: carried)
{
BreakOnMove = true,
NeedHand = true
};
_doAfterSystem.TryStartDoAfter(args);
_popupSystem.PopupEntity(Loc.GetString("carry-started", ("carrier", carrier)), carried, carried);
@ -244,29 +253,19 @@ namespace Content.Server.Carrying
private void Carry(EntityUid carrier, EntityUid carried)
{
if (TryComp<PullableComponent>(carried, out var pullable))
{
if (pullable.Puller != null)
{
_pulling.TryStopPull(carried, pullable);
}
}
if (TryComp<CarryingComponent>(carried, out var carryComp))
DropCarried(carried, carryComp.Carried);
_pullingSystem.TryStopPull(carried, pullable, carrier);
Transform(carrier).AttachToGridOrMap();
Transform(carried).AttachToGridOrMap();
Transform(carried).Coordinates = Transform(carrier).Coordinates;
Transform(carried).AttachParent(Transform(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);
_virtualItemSystem.TrySpawnVirtualItemInHand(carried, carrier);
_virtualItemSystem.TrySpawnVirtualItemInHand(carried, carrier);
carryingComp.Carried = carried;
carriedComp.Carrier = carrier;
@ -275,27 +274,27 @@ namespace Content.Server.Carrying
public void DropCarried(EntityUid carrier, EntityUid carried)
{
RemComp<CarryingComponent>(carrier);
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);
Transform(carried).AttachToGridOrMap();
_standingState.Stand(carried);
_movementSpeed.RefreshMovementSpeedModifiers(carrier);
_virtualItemSystem.DeleteInHandsMatching(carrier, carried);
}
private void ApplyCarrySlowdown(EntityUid carrier, EntityUid carried)
{
// Carrying slowdown made static as a part of removing mass contests
// var massRatio = _contests.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 modifier = 0.7f; // 30% slowdown while carrying
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);
}
@ -314,9 +313,6 @@ namespace Content.Server.Carrying
if (HasComp<BeingCarriedComponent>(carrier) || HasComp<BeingCarriedComponent>(carried))
return false;
// if (_respirator.IsReceivingCPR(carried))
// return false;
if (!TryComp<HandsComponent>(carrier, out var hands))
return false;
@ -325,81 +321,5 @@ namespace Content.Server.Carrying
return true;
}
public override void Update(float frameTime)
{
var query = EntityQueryEnumerator<BeingCarriedComponent>();
while (query.MoveNext(out var carried, out var comp))
{
var carrier = comp.Carrier;
if (carrier is not { Valid: true } || carried is not { Valid: true })
continue;
if (Transform(carried).ParentUid != carrier)
{
DropCarried(carrier, carried);
continue;
}
var xform = Transform(carried);
if (!xform.LocalPosition.Equals(Vector2.Zero))
{
xform.LocalPosition = Vector2.Zero;
}
}
query.Dispose();
}
public TimeSpan GetPickupDuration(EntityUid carrier, EntityUid carried)
{
TimeSpan length = TimeSpan.FromSeconds(2.5);
// var mod = _contests.MassContest(carrier, carried);
// if (mod != 0)
// length /= mod;
return length;
}
public bool TryCarry(EntityUid carrier, EntityUid toCarry, CarriableComponent? carriedComp = null)
{
if (!Resolve(toCarry, ref carriedComp, false))
return false;
if (!CanCarry(carrier, toCarry, carriedComp))
return false;
if (HasComp<BeingCarriedComponent>(carrier) || HasComp<ItemComponent>(carrier))
return false;
if (GetPickupDuration(carrier, toCarry) > TimeSpan.FromSeconds(9))
return false;
Carry(carrier, toCarry);
return true;
}
private void AddInsertCarriedVerb(EntityUid uid, CarryingComponent component, GetVerbsEvent<InnateVerb> args)
{
var toInsert = args.Using;
if (toInsert is not { Valid: true } || !args.CanAccess || !TryComp<PseudoItemComponent>(toInsert, out var pseudoItem))
return;
if (!HasComp<StorageComponent>(args.Target))
return;
InnateVerb verb = new()
{
Act = () =>
{
DropCarried(uid, toInsert.Value);
_pseudoItem.TryInsert(args.Target, toInsert.Value, args.User, pseudoItem);
},
Text = Loc.GetString("action-name-insert-other", ("target", toInsert)),
Priority = 2
};
args.Verbs.Add(verb);
}
}
}

View file

@ -1,9 +0,0 @@
namespace Content.Server.Item.PseudoItem;
/// <summary>
/// Signifies that pseudo-item creatures can sleep inside the container to which this component was added.
/// </summary>
[RegisterComponent]
public sealed partial class AllowsSleepInsideComponent : Component
{
}

View file

@ -1,213 +0,0 @@
using Content.Server.Actions;
using Content.Server.Bed.Sleep;
using Content.Server.Carrying;
using Content.Server.DoAfter;
using Content.Server.Popups;
using Content.Server.Storage.EntitySystems;
using Content.Shared.Bed.Sleep;
using Content.Shared.DoAfter;
using Content.Shared.Hands;
using Content.Shared.IdentityManagement;
using Content.Shared.Item;
using Content.Shared.Item.PseudoItem;
using Content.Shared.Storage;
using Content.Shared.Tag;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
namespace Content.Server.Item.PseudoItem;
public sealed class PseudoItemSystem : EntitySystem
{
[Dependency] private readonly StorageSystem _storageSystem = default!;
[Dependency] private readonly ItemSystem _itemSystem = default!;
[Dependency] private readonly DoAfterSystem _doAfter = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
[Dependency] private readonly CarryingSystem _carrying = default!; // Frontier
[Dependency] private readonly ActionsSystem _actions = default!; // Frontier
[Dependency] private readonly PopupSystem _popup = default!; // Frontier
[ValidatePrototypeId<TagPrototype>]
private const string PreventTag = "PreventLabel";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PseudoItemComponent, GetVerbsEvent<InnateVerb>>(AddInsertVerb);
SubscribeLocalEvent<PseudoItemComponent, GetVerbsEvent<AlternativeVerb>>(AddInsertAltVerb);
SubscribeLocalEvent<PseudoItemComponent, EntGotRemovedFromContainerMessage>(OnEntRemoved);
SubscribeLocalEvent<PseudoItemComponent, GettingPickedUpAttemptEvent>(OnGettingPickedUpAttempt);
SubscribeLocalEvent<PseudoItemComponent, DropAttemptEvent>(OnDropAttempt);
SubscribeLocalEvent<PseudoItemComponent, PseudoItemInsertDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<PseudoItemComponent, ContainerGettingInsertedAttemptEvent>(OnInsertAttempt);
SubscribeLocalEvent<PseudoItemComponent, TryingToSleepEvent>(OnTrySleeping); // Frontier
}
private void AddInsertVerb(EntityUid uid, PseudoItemComponent component, GetVerbsEvent<InnateVerb> args)
{
if (!args.CanInteract || !args.CanAccess)
return;
if (component.Active)
return;
if (!TryComp<StorageComponent>(args.Target, out var targetStorage))
return;
if (Transform(args.Target).ParentUid == uid)
return;
InnateVerb verb = new()
{
Act = () =>
{
TryInsert(args.Target, uid, args.User, component, targetStorage);
},
Text = Loc.GetString("action-name-insert-self"),
Priority = 2
};
args.Verbs.Add(verb);
}
private void AddInsertAltVerb(EntityUid uid, PseudoItemComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess)
return;
if (args.User == args.Target)
return;
if (component.Active)
return;
if (args.Hands == null)
return;
if (!TryComp<StorageComponent>(args.Hands.ActiveHandEntity, out var targetStorage))
return;
AlternativeVerb verb = new()
{
Act = () =>
{
StartInsertDoAfter(args.User, uid, args.Hands.ActiveHandEntity.Value, component);
},
Text = Loc.GetString("action-name-insert-other", ("target", Identity.Entity(args.Target, EntityManager))),
Priority = 2
};
args.Verbs.Add(verb);
}
private void OnEntRemoved(EntityUid uid, PseudoItemComponent component, EntGotRemovedFromContainerMessage args)
{
if (!component.Active)
return;
RemComp<ItemComponent>(uid);
component.Active = false;
// Frontier
if (component.SleepAction is { Valid: true })
_actions.RemoveAction(uid, component.SleepAction);
}
private void OnGettingPickedUpAttempt(EntityUid uid, PseudoItemComponent component,
GettingPickedUpAttemptEvent args)
{
if (args.User == args.Item)
return;
// Frontier: prevent people from pushing each other from a bag
if (HasComp<ItemComponent>(args.User))
{
args.Cancel();
return;
}
// Frontier: try to carry the person when taking them out of a bag.
if (_carrying.TryCarry(args.User, uid))
{
args.Cancel();
return;
}
Transform(uid).AttachToGridOrMap();
args.Cancel();
}
private void OnDropAttempt(EntityUid uid, PseudoItemComponent component, DropAttemptEvent args)
{
if (component.Active)
args.Cancel();
}
private void OnDoAfter(EntityUid uid, PseudoItemComponent component, DoAfterEvent args)
{
if (args.Handled || args.Cancelled || args.Args.Used == null)
return;
args.Handled = TryInsert(args.Args.Used.Value, uid, args.User, component);
}
public bool TryInsert(EntityUid storageUid, EntityUid toInsert, EntityUid userUid, PseudoItemComponent component,
StorageComponent? storage = null)
{
if (!Resolve(storageUid, ref storage))
return false;
var item = EnsureComp<ItemComponent>(toInsert);
_tagSystem.TryAddTag(toInsert, PreventTag);
_itemSystem.SetSize(toInsert, component.Size, item);
_itemSystem.VisualsChanged(toInsert);
if (!_storageSystem.CanInsert(storageUid, toInsert, out _) ||
!_storageSystem.PlayerInsertEntityInWorld(storageUid, userUid, toInsert))
{
component.Active = false;
RemComp<ItemComponent>(toInsert);
return false;
}
_storageSystem.UpdateUI(storageUid);
_storageSystem.UpdateAppearance(storageUid);
// Frontier
if (HasComp<AllowsSleepInsideComponent>(storageUid))
_actions.AddAction(toInsert, ref component.SleepAction, SleepingSystem.SleepActionId, toInsert);
component.Active = true;
return true;
}
private void StartInsertDoAfter(EntityUid inserter, EntityUid toInsert, EntityUid storageEntity,
PseudoItemComponent? pseudoItem = null)
{
if (!Resolve(toInsert, ref pseudoItem))
return;
var ev = new PseudoItemInsertDoAfterEvent();
var args = new DoAfterArgs(EntityManager, inserter, 5f, ev, toInsert, toInsert, storageEntity)
{
BreakOnMove = true,
NeedHand = true
};
_doAfter.TryStartDoAfter(args);
}
private void OnInsertAttempt(EntityUid uid, PseudoItemComponent component,
ContainerGettingInsertedAttemptEvent args)
{
if (!component.Active)
return;
// This hopefully shouldn't trigger, but this is a failsafe just in case so we dont bluespace them cats
args.Cancel();
}
// Frontier - show a popup when a pseudo-item falls asleep inside a bag.
private void OnTrySleeping(EntityUid uid, PseudoItemComponent component, TryingToSleepEvent args)
{
var parent = Transform(uid).ParentUid;
if (!HasComp<SleepingComponent>(uid) && parent is { Valid: true } && HasComp<AllowsSleepInsideComponent>(parent))
_popup.PopupEntity(Loc.GetString("popup-sleep-in-bag", ("entity", uid)), uid);
}
}

View file

@ -1,3 +1,4 @@
using Content.Shared._Sunrise.Carrying;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;

View file

@ -1,7 +1,8 @@
using Content.Shared.Carrying;
using Content.Shared.Movement.Systems;
using Robust.Shared.GameStates;
namespace Content.Shared.Carrying
namespace Content.Shared._Sunrise.Carrying
{
public sealed class CarryingSlowdownSystem : EntitySystem
{

View file

@ -1,9 +0,0 @@
namespace Content.Shared._Sunrise.Cloning;
/// <summary>
/// Indicates that this Component should be transferred to the new entity when the entity is cloned (for example, using a cloner)
/// </summary>
public interface ITransferredByCloning
{
}

View file

@ -1,19 +0,0 @@
using Content.Shared._Sunrise.Cloning;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Item.PseudoItem;
/// <summary>
/// For entities that behave like an item under certain conditions,
/// but not under most conditions.
/// </summary>
[RegisterComponent]
public sealed partial class PseudoItemComponent : Component, ITransferredByCloning
{
[DataField("size", customTypeSerializer: typeof(PrototypeIdSerializer<ItemSizePrototype>))]
public string Size = "Huge";
public bool Active = false;
[DataField]
public EntityUid? SleepAction;
}

View file

@ -1,10 +0,0 @@
using Robust.Shared.Serialization;
using Content.Shared.DoAfter;
namespace Content.Shared.Item.PseudoItem;
[Serializable, NetSerializable]
public sealed partial class PseudoItemInsertDoAfterEvent : SimpleDoAfterEvent
{
}

View file

@ -92,7 +92,6 @@
horizontalRotation: 90
- type: HumanoidAppearance
species: Human
- type: Carriable
- type: SlowOnDamage
speedModifierThresholds:
60: 0.7
@ -245,6 +244,8 @@
id: BaseMobSpeciesOrganic
abstract: true
components:
- type: Carriable # Sunrise-edit
- type: CanEscapeInventory # Sunrise-edit
- type: Barotrauma
damage:
types:

View file

@ -298,9 +298,8 @@
deathPenalty: 0.01 # However they really ought to be living and intact, otherwise they're worth 100x less.
- type: TTS # Sunrise-TTS
- type: ContentEye
# VIXME VIGERS
# - type: Carriable # Sunrise-edit
# - type: CanEscapeInventory # Sunrise-edit
- type: Carriable # Sunrise-edit
- type: CanEscapeInventory # Sunrise-edit
- type: TypingIndicator
proto: robot
- type: Unrevivable