Felinids fit in duffelbags. (#515)

* - add: Felinids fit in duffelbags.

* - add: This is better.

* - add: Move to shared.
This commit is contained in:
Aviu00
2024-07-30 16:32:26 +00:00
committed by GitHub
parent 2b5838657d
commit 58574b8a70
13 changed files with 284 additions and 21 deletions

View File

@@ -5,6 +5,15 @@ namespace Content.Server._White.Carrying;
[RegisterComponent]
public sealed partial class CarriableComponent : Component
{
[DataField, ViewVariables(VVAccess.ReadWrite)]
public TimeSpan DoAfterLength = TimeSpan.FromSeconds(4);
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float WalkModifier = 0.7f;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float SprintModifier = 0.7f;
/// <summary>
/// Number of free hands required
/// to carry the entity
@@ -13,4 +22,4 @@ public sealed partial class CarriableComponent : Component
public int FreeHandsRequired = 2;
public CancellationTokenSource? CancelToken;
}
}

View File

@@ -207,9 +207,9 @@ public sealed class CarryingSystem : EntitySystem
args.Handled = true;
}
private void StartCarryDoAfter(EntityUid carrier, EntityUid carried, CarriableComponent component)
public void StartCarryDoAfter(EntityUid carrier, EntityUid carried, CarriableComponent component)
{
var length = TimeSpan.FromSeconds(6); // т.к. удалили систему разницы масс увеличу время с 3 до 6
var length = component.DoAfterLength; // т.к. удалили систему разницы масс увеличу время с 3 до 6
if (length >= TimeSpan.FromSeconds(9))
{
_popupSystem.PopupEntity(Loc.GetString("carry-too-heavy"), carried, carrier,
@@ -230,7 +230,11 @@ public sealed class CarryingSystem : EntitySystem
NeedHand = true
};
_doAfterSystem.TryStartDoAfter(args);
if(_doAfterSystem.TryStartDoAfter(args))
{
_popupSystem.PopupEntity(Loc.GetString("carry-start", ("carrier", carrier)), carried, carried,
Shared.Popups.PopupType.SmallCaution);
}
}
private void Carry(EntityUid carrier, EntityUid carried)
@@ -260,17 +264,22 @@ public sealed class CarryingSystem : EntitySystem
_actionBlockerSystem.UpdateCanMove(carried);
}
public void DropCarried(EntityUid carrier, EntityUid carried)
public void DropCarried(EntityUid carrier,
EntityUid carried,
bool attachToGridOrMap = true,
bool removeCanEscape = true)
{
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);
RemComp<CanEscapeInventoryComponent>(carried);
if (removeCanEscape)
RemComp<CanEscapeInventoryComponent>(carried);
_actionBlockerSystem.UpdateCanMove(carried);
_virtualItemSystem.DeleteInHandsMatching(carrier, carried);
_transform.AttachToGridOrMap(carried);
if (attachToGridOrMap)
_transform.AttachToGridOrMap(carried);
_movementSpeed.RefreshMovementSpeedModifiers(carrier);
}
@@ -302,4 +311,4 @@ public sealed class CarryingSystem : EntitySystem
return true;
}
}
}

View File

@@ -0,0 +1,168 @@
using Content.Server._White.Carrying;
using Content.Shared.Verbs;
using Content.Shared.Item;
using Content.Shared.Hands;
using Content.Server.Storage.EntitySystems;
using Content.Server.Item;
using Content.Server.Popups;
using Content.Server.Resist;
using Content.Shared._White.Item.PseudoItem;
using Content.Shared.Resist;
using Content.Shared.Storage;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
namespace Content.Server._White.Items.PseudoItem;
public sealed class PseudoItemSystem : SharedPseudoItemSystem
{
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly StorageSystem _storageSystem = default!;
[Dependency] private readonly ItemSystem _itemSystem = default!;
[Dependency] private readonly CarryingSystem _carrying = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PseudoItemComponent, EntGotRemovedFromContainerMessage>(OnEntRemoved);
SubscribeLocalEvent<PseudoItemComponent, DropAttemptEvent>(OnDropAttempt);
SubscribeLocalEvent<PseudoItemComponent, EscapeInventoryEvent>(OnEscape);
SubscribeLocalEvent<StorageComponent, GetVerbsEvent<AlternativeVerb>>(AddAltVerb);
SubscribeLocalEvent<StorageComponent, GetVerbsEvent<Verb>>(AddVerb);
SubscribeLocalEvent<StorageComponent, PseudoItemInteractEvent>(OnInteract);
}
private void OnInteract(Entity<StorageComponent> ent, ref PseudoItemInteractEvent args)
{
if (!TryComp(args.Used, out PseudoItemComponent? pseudoItem))
return;
if (!TryInsert(ent.Owner, args.Used, args.User, pseudoItem, ent.Comp))
return;
_carrying.DropCarried(args.User, args.Used, false, false);
}
private void OnEscape(Entity<PseudoItemComponent> ent, ref EscapeInventoryEvent args)
{
NoLongerInContainer(ent.Owner, ent.Comp);
}
private void AddAltVerb(Entity<StorageComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess)
return;
var user = args.User;
var (uid, comp) = ent;
if (!TryComp(user, out PseudoItemComponent? pseudoItem) || pseudoItem.Active)
return;
if (Transform(uid).ParentUid == user)
return;
AlternativeVerb verb = new()
{
Act = () =>
{
TryInsert(uid, user, user, pseudoItem, comp);
},
Text = Loc.GetString("action-name-insert-self"),
};
args.Verbs.Add(verb);
}
private void AddVerb(Entity<StorageComponent> ent, ref GetVerbsEvent<Verb> args)
{
if (!args.CanInteract || !args.CanAccess)
return;
var user = args.User;
var (uid, comp) = ent;
if (!TryComp(user, out CarryingComponent? carrying))
return;
var carried = carrying.Carried;
if (!TryComp(carried, out PseudoItemComponent? pseudoItem))
return;
Verb verb = new()
{
Act = () =>
{
if (TryInsert(uid, carried, user, pseudoItem, comp))
_carrying.DropCarried(user, carried, false, false);
},
Text = Loc.GetString("action-name-insert-other"),
};
args.Verbs.Add(verb);
}
private void OnEntRemoved(EntityUid uid, PseudoItemComponent component, EntGotRemovedFromContainerMessage args)
{
NoLongerInContainer(uid, component);
}
protected override void OnGettingPickedUp(Entity<PseudoItemComponent> ent, GettingPickedUpAttemptEvent args)
{
base.OnGettingPickedUp(ent, args);
if (args.User == args.Item)
return;
if (!TryComp(ent, out CarriableComponent? carriable))
_transform.AttachToGridOrMap(ent);
else if (_carrying.CanCarry(args.User, ent))
_carrying.StartCarryDoAfter(args.User, ent, carriable);
}
private void OnDropAttempt(EntityUid uid, PseudoItemComponent component, DropAttemptEvent args)
{
if (component.Active)
args.Cancel();
}
public bool TryInsert(EntityUid storageUid,
EntityUid toInsert,
EntityUid user,
PseudoItemComponent component,
StorageComponent? storage = null)
{
if (!Resolve(storageUid, ref storage))
return false;
var item = EnsureComp<ItemComponent>(toInsert);
_itemSystem.SetSize(toInsert, component.Size, item);
_itemSystem.SetShape(toInsert, component.Shape, item);
Dirty(toInsert, component);
if (!_storageSystem.Insert(storageUid, toInsert, out _, user, storage))
{
_popupSystem.PopupEntity(Loc.GetString("comp-storage-cant-insert"), user, user);
component.Active = false;
RemComp<ItemComponent>(toInsert);
return false;
}
component.Active = true;
EnsureComp<CanEscapeInventoryComponent>(toInsert);
return true;
}
private void NoLongerInContainer(EntityUid uid, PseudoItemComponent component)
{
if (!component.Active)
return;
RemCompDeferred<CanEscapeInventoryComponent>(uid);
RemCompDeferred<ItemComponent>(uid);
component.Active = false;
Dirty(uid, component);
}
}

View File

@@ -24,6 +24,7 @@ using Content.Shared._White.Antag;
using Content.Shared._White.BetrayalDagger;
using Content.Shared._White.Cult.Components;
using Content.Shared._White.Events;
using Content.Shared._White.Item.PseudoItem;
using Content.Shared._White.Wizard;
using Content.Shared._White.Wizard.Magic;
using Content.Shared.Actions;
@@ -854,6 +855,9 @@ public sealed class WizardSpellsSystem : EntitySystem
public bool CanCast(BaseActionEvent msg)
{
if (TryComp(msg.Performer, out PseudoItemComponent? pseudoItem) && pseudoItem.Active)
return false;
return !msg.Handled && CheckRequirements(msg.Action, msg.Performer) &&
!_statusEffectsSystem.HasStatusEffect(msg.Performer, "Incorporeal");
}