- 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

@@ -74,13 +74,22 @@ public sealed class CombatModeIndicatorsOverlay : Overlay
var isGunBolted = true;
if (_entMan.TryGetComponent(handEntity, out ChamberMagazineAmmoProviderComponent? chamber))
isGunBolted = chamber.BoltClosed ?? true;
// WD EDIT START
var isGunCycled = true;
if (_entMan.TryGetComponent(handEntity, out BallisticAmmoProviderComponent? ballistic) &&
ballistic.Entities.Count > 0)
{
var ent = ballistic.Entities[^1];
if (_entMan.TryGetComponent(ent, out CartridgeAmmoComponent? cartridge))
isGunCycled = !cartridge.Spent;
}
// WD EDIT END
var mousePos = mouseScreenPosition.Position;
var uiScale = (args.ViewportControl as Control)?.UIScale ?? 1f;
var limitedScale = uiScale > 1.25f ? 1.25f : uiScale;
var sight = isHandGunItem ? (isGunBolted ? _gunSight : _gunBoltSight) : _meleeSight;
var sight = isHandGunItem ? (isGunBolted && isGunCycled ? _gunSight : _gunBoltSight) : _meleeSight; // WD EDIT
DrawSight(sight, args.ScreenHandle, mousePos, limitedScale * Scale);
}

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);
}

View File

@@ -20,6 +20,7 @@ gun-ballistic-cycled-empty = Разряжено
gun-ballistic-transfer-invalid = { CAPITALIZE($ammoEntity) } нельзя поместить в { $targetEntity }!
gun-ballistic-transfer-empty = В { CAPITALIZE($entity) } пусто.
gun-ballistic-transfer-target-full = { CAPITALIZE($entity) } уже полностью заряжен.
gun-ballistic-not-cycled = Не перезаряжено
# CartridgeAmmo
gun-cartridge-spent = Он [color=red]израсходован[/color].