From 6f6f259e1226355e53ef4abf22fd214b8b573100 Mon Sep 17 00:00:00 2001
From: Aviu00 <93730715+Aviu00@users.noreply.github.com>
Date: Sat, 6 Apr 2024 21:31:09 +0900
Subject: [PATCH] - add: Better cycling. (#272)
---
.../CombatMode/CombatModeIndicatorsOverlay.cs | 13 ++++++++++--
.../BallisticAmmoProviderComponent.cs | 11 ----------
.../Systems/SharedGunSystem.Ballistic.cs | 20 ++++++++++---------
Resources/Locale/ru-RU/weapons/ranged/gun.ftl | 1 +
4 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/Content.Client/CombatMode/CombatModeIndicatorsOverlay.cs b/Content.Client/CombatMode/CombatModeIndicatorsOverlay.cs
index b2bdf2893d..938bea04f4 100644
--- a/Content.Client/CombatMode/CombatModeIndicatorsOverlay.cs
+++ b/Content.Client/CombatMode/CombatModeIndicatorsOverlay.cs
@@ -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);
}
diff --git a/Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs b/Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs
index 59d7a0d66e..e29785f7a4 100644
--- a/Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs
+++ b/Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs
@@ -44,17 +44,6 @@ public sealed partial class BallisticAmmoProviderComponent : Component
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public bool Cycleable = true;
- ///
- /// Is the firearm currently cycled?
- /// It cannot fire if is it not cycled.
- /// Must be manually cycled if it is not cycled.
- ///
- [ViewVariables(VVAccess.ReadWrite), DataField]
- [AutoNetworkedField]
- public bool? Cycled = true;
-
- public bool IsCycled => Cycled is true or null;
-
///
/// Automatically cycles the firearm after firing a round
///
diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs
index b33f36110f..3a112c9916 100644
--- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs
+++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs
@@ -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);
}
diff --git a/Resources/Locale/ru-RU/weapons/ranged/gun.ftl b/Resources/Locale/ru-RU/weapons/ranged/gun.ftl
index ba33dfa6cd..bb4143194e 100644
--- a/Resources/Locale/ru-RU/weapons/ranged/gun.ftl
+++ b/Resources/Locale/ru-RU/weapons/ranged/gun.ftl
@@ -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].