Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pseudo Code #2012

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Content.Shared.Nyanotrasen.Item.PseudoItem;

namespace Content.Client.Nyanotrasen.Item.PseudoItem;

public sealed class PseudoItemSystem : SharedPseudoItemSystem
{
}
199 changes: 109 additions & 90 deletions Content.Server/Nyanotrasen/Carrying/CarryingSystem.cs

Large diffs are not rendered by default.

This file was deleted.

170 changes: 20 additions & 150 deletions Content.Server/Nyanotrasen/Item/PseudoItem/PseudoItemSystem.cs
Original file line number Diff line number Diff line change
@@ -1,88 +1,50 @@
using Content.Server.Actions;
using Content.Server.Carrying;
using Content.Server.Carrying;
using Content.Server.DoAfter;
using Content.Server.Item;
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.Nyanotrasen.Item.PseudoItem;
using Content.Shared.Storage;
using Content.Shared.Tag;
using Content.Shared.Verbs;
using Robust.Shared.Containers;

namespace Content.Server.Item.PseudoItem;
namespace Content.Server.Nyanotrasen.Item.PseudoItem;

public sealed class PseudoItemSystem : EntitySystem
public sealed class PseudoItemSystem : SharedPseudoItemSystem
{
[Dependency] private readonly StorageSystem _storageSystem = default!;
[Dependency] private readonly ItemSystem _itemSystem = default!;
[Dependency] private readonly StorageSystem _storage = default!;
[Dependency] private readonly ItemSystem _item = 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";
[Dependency] private readonly CarryingSystem _carrying = default!;
[Dependency] private readonly PopupSystem _popup = default!;

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);
SubscribeLocalEvent<PseudoItemComponent, TryingToSleepEvent>(OnTrySleeping);
}

private void AddInsertAltVerb(EntityUid uid, PseudoItemComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess)
return;

if (args.User == args.Target)
if (component.Active)
return;

if (component.Active)
if (!TryComp<StorageComponent>(args.Using, out var targetStorage))
return;

if (args.Hands == null)
if (!CheckItemFits((uid, component), (args.Using.Value, targetStorage)))
return;

if (!TryComp<StorageComponent>(args.Hands.ActiveHandEntity, out var targetStorage))
if (args.Hands?.ActiveHandEntity == null)
return;

AlternativeVerb verb = new()
Expand All @@ -97,112 +59,20 @@ private void AddInsertAltVerb(EntityUid uid, PseudoItemComponent component, GetV
args.Verbs.Add(verb);
}

private void OnEntRemoved(EntityUid uid, PseudoItemComponent component, EntGotRemovedFromContainerMessage args)
protected override void OnGettingPickedUpAttempt(EntityUid uid, PseudoItemComponent component, GettingPickedUpAttemptEvent 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))
// Try to pick the entity up instead first
if (args.User != args.Item && _carrying.TryCarry(args.User, uid))
{
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();
// If could not pick up, just take it out onto the ground as per default
base.OnGettingPickedUpAttempt(uid, component, args);
}

// Frontier - show a popup when a pseudo-item falls asleep inside a bag.
// 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;
Expand Down
32 changes: 17 additions & 15 deletions Content.Server/_NF/SizeAttribute/SizeAttributeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Systems;
using Content.Shared._NF.SizeAttribute;
using Content.Shared.Item.PseudoItem;
using Content.Shared.Nyanotrasen.Item.PseudoItem;

namespace Content.Server.SizeAttribute
{
Expand All @@ -13,7 +13,6 @@ public sealed class SizeAttributeSystem : EntitySystem
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly FixtureSystem _fixtures = default!;
public override void Initialize()
{
base.Initialize();
Expand All @@ -22,32 +21,35 @@ public override void Initialize()

private void OnComponentInit(EntityUid uid, SizeAttributeComponent component, ComponentInit args)
{
if (component.Tall && TryComp<TallWhitelistComponent>(uid, out var tall))
if (component.Tall && TryComp<TallWhitelistComponent>(uid, out var tallComp))
{
Scale(uid, component, tall.Scale, tall.Density, tall.CosmeticOnly);
PseudoItem(uid, component, tall.PseudoItem);
Scale(uid, component, tallComp.Scale, tallComp.Density, tallComp.CosmeticOnly);
PseudoItem(uid, component, tallComp.PseudoItem, tallComp.Shape, tallComp.StoredOffset, tallComp.StoredRotation);
}
else if (component.Short && TryComp<ShortWhitelistComponent>(uid, out var smol))
else if (component.Short && TryComp<ShortWhitelistComponent>(uid, out var shortComp))
{
Scale(uid, component, smol.Scale, smol.Density, smol.CosmeticOnly);
PseudoItem(uid, component, smol.PseudoItem);
Scale(uid, component, shortComp.Scale, shortComp.Density, shortComp.CosmeticOnly);
PseudoItem(uid, component, shortComp.PseudoItem, shortComp.Shape, shortComp.StoredOffset, shortComp.StoredRotation);
}
}

private void PseudoItem(EntityUid uid, SizeAttributeComponent component, bool active)
private void PseudoItem(EntityUid uid, SizeAttributeComponent _, bool active, List<Box2i>? shape, Vector2i? storedOffset, float storedRotation)
{
if (active)
{
if (TryComp<PseudoItemComponent>(uid, out var pseudoI))
return;
var pseudoI = _entityManager.EnsureComponent<PseudoItemComponent>(uid);

_entityManager.AddComponent<PseudoItemComponent>(uid);
pseudoI.StoredRotation = storedRotation;
pseudoI.StoredOffset = storedOffset ?? new(0, 17);
pseudoI.Shape = shape ?? new List<Box2i>
{
new Box2i(0, 0, 1, 4),
new Box2i(0, 2, 3, 4),
new Box2i(4, 0, 5, 4)
};
}
else
{
if (!TryComp<PseudoItemComponent>(uid, out var pseudoI))
return;

_entityManager.RemoveComponent<PseudoItemComponent>(uid);
}
}
Expand Down
5 changes: 3 additions & 2 deletions Content.Shared/Item/ItemComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.Hands.Components;
using Content.Shared.Nyanotrasen.Item.PseudoItem;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
Expand All @@ -12,11 +13,11 @@ namespace Content.Shared.Item;
/// </summary>
[RegisterComponent]
[NetworkedComponent]
[Access(typeof(SharedItemSystem)), AutoGenerateComponentState(true)]
[Access(typeof(SharedItemSystem), typeof(SharedPseudoItemSystem)), AutoGenerateComponentState(true)] // DeltaV - Gave PseudoItem access
public sealed partial class ItemComponent : Component
{
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
[Access(typeof(SharedItemSystem))]
[Access(typeof(SharedItemSystem), typeof(SharedPseudoItemSystem))] // DeltaV - Gave PseudoItem access
public ProtoId<ItemSizePrototype> Size = "Small";

[Access(typeof(SharedItemSystem))]
Expand Down
19 changes: 0 additions & 19 deletions Content.Shared/Nyanotrasen/Item/Components/PseudoItemComponent.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Shared.Nyanotrasen.Item.PseudoItem;

/// <summary>
/// Signifies that pseudo-item creatures can sleep inside the container to which this component is applied.
/// </summary>
[RegisterComponent]
public sealed partial class AllowsSleepInsideComponent : Component
{
}
36 changes: 36 additions & 0 deletions Content.Shared/Nyanotrasen/Item/PseudoItem/PseudoItemComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Content.Shared.Item;
using Robust.Shared.Prototypes;

namespace Content.Shared.Nyanotrasen.Item.PseudoItem;

/// <summary>
/// For entities that behave like an item under certain conditions,
/// but not under most conditions.
/// </summary>
[RegisterComponent, AutoGenerateComponentState]
public sealed partial class PseudoItemComponent : Component
{
[DataField("size")]
public ProtoId<ItemSizePrototype> Size = "Huge";

/// <summary>
/// An optional override for the shape of the item within the grid storage.
/// If null, a default shape will be used based on <see cref="Size"/>.
/// </summary>
[DataField, AutoNetworkedField]
public List<Box2i>? Shape;

[DataField, AutoNetworkedField]
public Vector2i StoredOffset;

[DataField, AutoNetworkedField] // Frontier
public float StoredRotation; // Frontier

public bool Active = false;

/// <summary>
/// Action for sleeping while inside a container with <see cref="AllowsSleepInsideComponent"/>.
/// </summary>
[DataField]
public EntityUid? SleepAction;
}
Loading
Loading