2023-08-24 21:05:56 +03:00
|
|
|
using Content.Server.Stack;
|
|
|
|
|
using Content.Shared.Stacks;
|
2022-06-01 19:59:58 +10:00
|
|
|
using Content.Shared.Weapons.Ranged.Components;
|
2023-05-27 14:15:15 +10:00
|
|
|
using Content.Shared.Weapons.Ranged.Events;
|
2022-06-01 19:59:58 +10:00
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
2022-09-29 15:51:59 +10:00
|
|
|
namespace Content.Server.Weapons.Ranged.Systems;
|
2022-06-01 19:59:58 +10:00
|
|
|
|
|
|
|
|
public sealed partial class GunSystem
|
|
|
|
|
{
|
2023-08-24 21:05:56 +03:00
|
|
|
[Dependency] private readonly StackSystem _stack = default!;
|
|
|
|
|
|
2023-05-27 14:15:15 +10:00
|
|
|
protected override void Cycle(EntityUid uid, BallisticAmmoProviderComponent component, MapCoordinates coordinates)
|
2022-06-01 19:59:58 +10:00
|
|
|
{
|
|
|
|
|
EntityUid? ent = null;
|
|
|
|
|
|
|
|
|
|
// TODO: Combine with TakeAmmo
|
|
|
|
|
if (component.Entities.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var existing = component.Entities[^1];
|
|
|
|
|
component.Entities.RemoveAt(component.Entities.Count - 1);
|
|
|
|
|
|
2023-12-27 21:30:03 -08:00
|
|
|
Containers.Remove(existing, component.Container);
|
2023-09-01 07:33:28 +10:00
|
|
|
EnsureShootable(existing);
|
2022-06-01 19:59:58 +10:00
|
|
|
}
|
|
|
|
|
else if (component.UnspawnedCount > 0)
|
|
|
|
|
{
|
|
|
|
|
component.UnspawnedCount--;
|
2023-09-28 16:20:29 -07:00
|
|
|
ent = Spawn(component.Proto, coordinates);
|
2023-09-01 07:33:28 +10:00
|
|
|
EnsureShootable(ent.Value);
|
2022-06-01 19:59:58 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ent != null)
|
|
|
|
|
EjectCartridge(ent.Value);
|
2023-05-27 14:15:15 +10:00
|
|
|
|
|
|
|
|
var cycledEvent = new GunCycledEvent();
|
|
|
|
|
RaiseLocalEvent(uid, ref cycledEvent);
|
2022-06-01 19:59:58 +10:00
|
|
|
}
|
2023-08-24 21:05:56 +03:00
|
|
|
|
|
|
|
|
protected override EntityUid GetStackEntity(EntityUid uid, StackComponent stack) // WD
|
|
|
|
|
{
|
|
|
|
|
return _stack.Split(uid, 1, Transform(uid).Coordinates, stack) ?? uid;
|
|
|
|
|
}
|
2022-06-01 19:59:58 +10:00
|
|
|
}
|