- add: Better cycling. (#272)

This commit is contained in:
Aviu00
2024-04-06 21:31:09 +09:00
committed by GitHub
parent 883623e448
commit 6f6f259e12
4 changed files with 23 additions and 22 deletions

View File

@@ -44,17 +44,6 @@ public sealed partial class BallisticAmmoProviderComponent : Component
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public bool Cycleable = true;
/// <summary>
/// Is the firearm currently cycled?
/// It cannot fire if is it not cycled.
/// Must be manually cycled if it is not cycled.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField]
[AutoNetworkedField]
public bool? Cycled = true;
public bool IsCycled => Cycled is true or null;
/// <summary>
/// Automatically cycles the firearm after firing a round
/// </summary>

View File

@@ -209,7 +209,6 @@ public abstract partial class SharedGunSystem
var shots = GetBallisticShots(component);
Cycle(uid, component, coordinates);
component.Cycled = true;
var text = Loc.GetString(shots == 0 ? "gun-ballistic-cycled-empty" : "gun-ballistic-cycled");
@@ -247,9 +246,6 @@ public abstract partial class SharedGunSystem
private void OnBallisticTakeAmmo(EntityUid uid, BallisticAmmoProviderComponent component, TakeAmmoEvent args)
{
if (!component.IsCycled)
return;
for (var i = 0; i < args.Shots; i++)
{
EntityUid entity;
@@ -258,12 +254,21 @@ public abstract partial class SharedGunSystem
{
entity = component.Entities[^1];
if (TryComp(entity, out CartridgeAmmoComponent? cartridge) && cartridge.Spent) // WD EDIT
{
args.Reason = Loc.GetString("gun-ballistic-not-cycled");
break;
}
args.Ammo.Add((entity, EnsureShootable(entity)));
if (component.AutoCycle && (!TryComp(entity, out CartridgeAmmoComponent? cartridge) || !cartridge.Spent)) // WD EDIT
if (component.AutoCycle) // WD EDIT
{
component.Entities.RemoveAt(component.Entities.Count - 1);
Containers.Remove(entity, component.Container);
}
else
break;
}
else if (component.UnspawnedCount > 0)
{
@@ -274,14 +279,11 @@ public abstract partial class SharedGunSystem
{
component.Entities.Add(entity);
Containers.Insert(entity, component.Container);
break;
}
}
}
//un-cycle the firearm
if (!component.AutoCycle)
component.Cycled = false;
UpdateBallisticAppearance(uid, component);
Dirty(uid, component);
}