Skip to content

Commit

Permalink
Drop items contained in bags when a person dies
Browse files Browse the repository at this point in the history
  • Loading branch information
Simyon264 committed Nov 8, 2024
1 parent b3137c5 commit 53f8919
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ private void OnMobStateChanged(EntityUid uid, SuspicionPlayerComponent component
if (args.NewMobState != MobState.Dead) // Someone died.
return;

DropAllItemsOnEntity(args.Target);

var query = EntityQueryEnumerator<SuspicionRuleComponent, GameRuleComponent>();
while (query.MoveNext(out var ruleId, out var sus, out var gameRule))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using Content.Shared.FixedPoint;
using Content.Shared.Humanoid;
using Content.Shared.Implants.Components;
using Content.Shared.Inventory;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
using Content.Shared.Roles;
using Content.Shared.Storage;
using Content.Shared.Store.Components;
using Robust.Shared.Map;
using Robust.Shared.Physics.Components;
Expand Down Expand Up @@ -120,6 +122,32 @@ private void AddTcToPlayer(EntityUid player, int amount, bool displayMessage = t
return result;
}

public void DropAllItemsOnEntity(EntityUid entity)
{
if (!TryComp(entity, out InventoryComponent? inventory))
return;

var slots = _inventory.GetSlotEnumerator(new Entity<InventoryComponent?>(entity, inventory), SlotFlags.All);
var targetPos = _transformSystem.GetWorldPosition(entity);

while (slots.MoveNext(out var slot))
{
foreach (var rootContainerEnt in slot.ContainedEntities)
{
if (!TryComp(rootContainerEnt, out StorageComponent? storage))
continue;

var dumpQueue = new Queue<EntityUid>(storage.Container.ContainedEntities);

foreach (var item in dumpQueue)
{
var transform = Transform(item);
_transformSystem.SetWorldPositionRotation(item, targetPos + _random.NextVector2Box() / 4, _random.NextAngle(), transform);
}
}
}
}

public void AddKeyToRadio(EntityUid entity, string keyProto)
{
if (!_inventory.TryGetSlotEntity(entity, "ears", out var headset))
Expand Down
2 changes: 2 additions & 0 deletions Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using Robust.Server.Player;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;

namespace Content.Server._SSS.SuspicionGameRule;
Expand Down Expand Up @@ -60,6 +61,7 @@ public sealed partial class SuspicionRuleSystem : GameRuleSystem<SuspicionRuleCo
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly ContainerSystem _containerSystem = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly IRobustRandom _random = default!;

private readonly SoundSpecifier _traitorStartSound = new SoundPathSpecifier("/Audio/Ambience/Antag/traitor_start.ogg");

Expand Down

0 comments on commit 53f8919

Please sign in to comment.