forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from ss14-harmony/upstream20241204
Upstream20241204
- Loading branch information
Showing
42 changed files
with
135,182 additions
and
4,046 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Content.Shared/Storage/Components/StoreOnCollideComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Content.Shared.Storage.EntitySystems; | ||
using Content.Shared.Whitelist; | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared.Storage.Components; | ||
|
||
// Use where you want an entity to store other entities on collide | ||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(StoreOnCollideSystem))] | ||
public sealed partial class StoreOnCollideComponent : Component | ||
{ | ||
/// <summary> | ||
/// Entities that are allowed in the storage on collide | ||
/// </summary> | ||
[DataField] | ||
public EntityWhitelist? Whitelist; | ||
|
||
/// <summary> | ||
/// Should this storage lock on collide, provided they have a lock component? | ||
/// </summary> | ||
[DataField] | ||
public bool LockOnCollide; | ||
|
||
/// <summary> | ||
/// Should the behavior be disabled when the storage is first opened? | ||
/// </summary> | ||
[DataField] | ||
public bool DisableWhenFirstOpened; | ||
|
||
/// <summary> | ||
/// If the behavior is disabled or not | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public bool Disabled; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
Content.Shared/Storage/EntitySystems/StoreOnCollideSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Content.Shared.Lock; | ||
using Content.Shared.Storage.Components; | ||
using Content.Shared.Whitelist; | ||
using Robust.Shared.Network; | ||
using Robust.Shared.Physics.Events; | ||
using Robust.Shared.Timing; | ||
|
||
namespace Content.Shared.Storage.EntitySystems; | ||
|
||
internal sealed class StoreOnCollideSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedEntityStorageSystem _storage = default!; | ||
[Dependency] private readonly LockSystem _lock = default!; | ||
[Dependency] private readonly EntityWhitelistSystem _whitelist = default!; | ||
[Dependency] private readonly INetManager _netMan = default!; | ||
[Dependency] private readonly IGameTiming _gameTiming = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<StoreOnCollideComponent, StartCollideEvent>(OnCollide); | ||
SubscribeLocalEvent<StoreOnCollideComponent, StorageAfterOpenEvent>(AfterOpen); | ||
// TODO: Add support to stop colliding after throw, wands will need a WandComp | ||
} | ||
|
||
// We use Collide instead of Projectile to support different types of interactions | ||
private void OnCollide(Entity<StoreOnCollideComponent> ent, ref StartCollideEvent args) | ||
{ | ||
TryStoreTarget(ent, args.OtherEntity); | ||
|
||
TryLockStorage(ent); | ||
} | ||
|
||
private void AfterOpen(Entity<StoreOnCollideComponent> ent, ref StorageAfterOpenEvent args) | ||
{ | ||
var comp = ent.Comp; | ||
|
||
if (comp is { DisableWhenFirstOpened: true, Disabled: false }) | ||
comp.Disabled = true; | ||
} | ||
|
||
private void TryStoreTarget(Entity<StoreOnCollideComponent> ent, EntityUid target) | ||
{ | ||
var storageEnt = ent.Owner; | ||
var comp = ent.Comp; | ||
|
||
if (_netMan.IsClient || _gameTiming.ApplyingState) | ||
return; | ||
|
||
if (ent.Comp.Disabled || storageEnt == target || Transform(target).Anchored || _storage.IsOpen(storageEnt) || _whitelist.IsWhitelistFail(comp.Whitelist, target)) | ||
return; | ||
|
||
_storage.Insert(target, storageEnt); | ||
|
||
} | ||
|
||
private void TryLockStorage(Entity<StoreOnCollideComponent> ent) | ||
{ | ||
var storageEnt = ent.Owner; | ||
var comp = ent.Comp; | ||
|
||
if (_netMan.IsClient || _gameTiming.ApplyingState) | ||
return; | ||
|
||
if (ent.Comp.Disabled) | ||
return; | ||
|
||
if (comp.LockOnCollide && !_lock.IsLocked(storageEnt)) | ||
_lock.Lock(storageEnt, storageEnt); | ||
} | ||
} |
Oops, something went wrong.