Skip to content

Commit

Permalink
Hotfix for Body Bags (#9155)
Browse files Browse the repository at this point in the history
* Oops

* Requested changes

* Renamed

* rename

Co-authored-by: metalgearsloth <[email protected]>
  • Loading branch information
Mirino97 and metalgearsloth authored Jun 27, 2022
1 parent e9d6156 commit a265cd8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 4 additions & 3 deletions Content.Server/Foldable/FoldableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public override void Initialize()

SubscribeLocalEvent<FoldableComponent, StorageOpenAttemptEvent>(OnFoldableOpenAttempt);
SubscribeLocalEvent<FoldableComponent, GetVerbsEvent<AlternativeVerb>>(AddFoldVerb);
SubscribeLocalEvent<FoldableComponent, InsertIntoEntityStorageAttemptEvent>(OnEntityStorageInsertAttempt);
SubscribeLocalEvent<FoldableComponent, StoreThisAttemptEvent>(OnStoreThisAttempt);

}

private void OnFoldableOpenAttempt(EntityUid uid, FoldableComponent component, StorageOpenAttemptEvent args)
Expand Down Expand Up @@ -87,9 +88,9 @@ public override void SetFolded(FoldableComponent component, bool folded)
strap.Enabled = !component.IsFolded;
}

public void OnEntityStorageInsertAttempt(EntityUid uid, FoldableComponent comp, InsertIntoEntityStorageAttemptEvent args)
public void OnStoreThisAttempt(EntityUid uid, FoldableComponent comp, StoreThisAttemptEvent args)
{
if (!comp.IsFolded)
if (comp.IsFolded)
args.Cancel();
}

Expand Down
15 changes: 12 additions & 3 deletions Content.Server/Storage/Components/EntityStorageComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,13 @@ public virtual bool CanFit(EntityUid entity)
// 4. items can always be eaten unless a previous law prevents it
// 5. if this is NOT AN ITEM, then mobs can always be eaten unless unless a previous law prevents it
// 6. if this is an item, then mobs must only be eaten if some other component prevents pick-up interactions while a mob is inside (e.g. foldable)

var attemptEvent = new InsertIntoEntityStorageAttemptEvent();
_entMan.EventBus.RaiseLocalEvent(entity, attemptEvent);
if (attemptEvent.Cancelled)
return false;

// checks

// TODO: Make the others sub to it.
var targetIsItem = _entMan.HasComponent<SharedItemComponent>(entity);
var targetIsMob = _entMan.HasComponent<SharedBodyComponent>(entity);
var storageIsItem = _entMan.HasComponent<SharedItemComponent>(Owner);
Expand All @@ -239,9 +238,14 @@ public virtual bool CanFit(EntityUid entity)
{
if (!storageIsItem)
allowedToEat = true;
else
{
var storeEv = new StoreThisAttemptEvent();
_entMan.EventBus.RaiseLocalEvent(Owner, storeEv);
allowedToEat = !storeEv.Cancelled;
}
}

_entMan.EventBus.RaiseLocalEvent(entity, allowedToEat);
return allowedToEat;
}

Expand Down Expand Up @@ -367,6 +371,11 @@ protected virtual IEnumerable<EntityUid> DetermineCollidingEntities()
public sealed class InsertIntoEntityStorageAttemptEvent : CancellableEntityEventArgs
{

}

public sealed class StoreThisAttemptEvent : CancellableEntityEventArgs
{

}
public sealed class StorageOpenAttemptEvent : CancellableEntityEventArgs
{
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Foldable/SharedFoldableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void OnFoldableInit(EntityUid uid, FoldableComponent component, Componen
public virtual void SetFolded(FoldableComponent component, bool folded)
{
component.IsFolded = folded;
component.Dirty();
Dirty(component);

if (TryComp(component.Owner, out AppearanceComponent? appearance))
appearance.SetData(FoldKey, folded);
Expand Down

0 comments on commit a265cd8

Please sign in to comment.